<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<title>Sudila Printers</title>
<meta name="description" content="overview &amp; stats" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<!-- bootstrap & fontawesome -->
<link rel="stylesheet" href="assets/css/bootstrap.min.css" />
<link rel="stylesheet" href="assets/font-awesome/4.5.0/css/font-awesome.min.css" />
<!-- page specific plugin styles -->
<!-- text fonts -->
<link rel="stylesheet" href="assets/css/fonts.googleapis.com.css" />
<!-- ace styles -->
<link rel="stylesheet" href="assets/css/chosen.min.css" />
<link rel="stylesheet" href="assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />
<!--[if lte IE 9]>
    <link rel="stylesheet" href="assets/css/ace-part2.min.css" class="ace-main-stylesheet" />
<![endif]-->
<link rel="stylesheet" href="assets/css/ace-skins.min.css" />
<link rel="stylesheet" href="assets/css/ace-rtl.min.css" />
<!--[if lte IE 9]>
  <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
<![endif]-->
<!-- inline styles related to this page -->
<!-- ace settings handler -->
<script src="assets/js/ace-extra.min.js"></script>
<!-- HTML5shiv and Respond.js for IE8 to support HTML5 elements and media queries -->
<!--[if lte IE 8]>
    <script src="assets/js/html5shiv.min.js"></script>
    <script src="assets/js/respond.min.js"></script>
<![endif]-->
</head>
<body class="no-skin">
<?php include 'common/navbar.php'; ?>
<div class="main-container ace-save-state" id="main-container">
  <?php include 'common/sidebar.php'; ?>
  <div class="main-content">
    <div class="main-content-inner">
      <div class="breadcrumbs ace-save-state" id="breadcrumbs">
        <ul class="breadcrumb">
          <li> <i class="ace-icon fa fa-home home-icon"></i> <a href="home">Home</a> </li>
          <li class="active">Promotion Banners</li>
        </ul>
        <!-- /.breadcrumb --> 
      </div>
      <div class="page-content">
        <div class="page-header">
          <h1> Add Promotion Banners</h1>
        </div>
		
		<?php $sql_bn = mysqli_query($conn, "SELECT * FROM prom_banner");
		if(mysqli_num_rows($sql_bn) == 0) {
			$banner_1 = $banner_2 = '';
		
		} else {
			$row_bn = mysqli_fetch_assoc($sql_bn);
			$banner_1 = $row_bn['banner_1'];
			$banner_2 = $row_bn['banner_2'];
		}
		?>
        <!-- /.page-header -->
        <div class="row">
          <div class="col-xs-12"> 
            <!-- PAGE CONTENT BEGINS -->
            <div class="widget-box">
              <div class="widget-body">
                <div class="widget-main">
                  <!-- Content -->
				  <h4 class="blue">Banner 01</h4> <hr style="margin-top:0">
				  <form id="form_submit" method="post">
					  <div class="form-group">
						<label>Select Image:<sup class="red">*</sup></label>
						<input class="form-control" type="file" id="id-input-file-1" accept="image/*" required name="file_name1"/>
						<small class="text-danger">Image Size: 540px*160px</small>
						<span class="help-block"></span>
					  </div>
					  <div class="form-group">
						<button class="btn btn-primary btn-sm"> SUBMIT</button>
					  </div>
				  </form>
				  <?php if(!empty($banner_1)) { ?>
				  <img src="../image/bg-images/<?php echo $banner_1; ?>" width="50%" class="img-responsive"><br>
				  <button title="Remove" class="btn btn-danger btn-sm btn_remove1"> <i class="ace-icon fa fa-trash-o"> </i> &nbsp;Remove</button>
				  <?php } ?>
                  <!-- End Content --> 
                </div>
              </div>
            </div>
            <!-- /End .widget-box --> 
          </div>
        </div>
        <div class="space-10"></div>
        <div class="row">
          <div class="col-xs-12"> 
            <!-- PAGE CONTENT BEGINS -->
            <div class="widget-box">
              <div class="widget-body">
                <div class="widget-main">
				<h4 class="blue">Banner 02</h4> <hr style="margin-top:0">
                  <!-- Content -->
				  <form id="form_update" method="post">
					  <div class="form-group">
						<label>Select Image:<sup class="red">*</sup></label>
						<input class="form-control" type="file" id="id-input-file-2" accept="image/*" required name="file_name2"/>
						<small class="text-danger">Image Size: 540px*160px</small>
						<span class="help-block"></span>
					  </div>
					  <div class="form-group">
						<button class="btn btn-primary btn-sm"> SUBMIT</button>
					  </div>
				  </form>
				  <?php if(!empty($banner_2)) { ?>
				  <img src="../image/bg-images/<?php echo $banner_2; ?>" width="50%" class="img-responsive"><br>
				  <button title="Remove" class="btn btn-danger btn-sm btn_remove2"> <i class="ace-icon fa fa-trash-o"> </i> &nbsp;Remove</button>
				  <?php } ?>
                  <!-- End Content --> 
                </div>
              </div>
            </div>
            <!-- /End .widget-box --> 
          </div>
        </div>
      </div>
      <!-- /.page-content --> 
    </div>
  </div>
  <!-- /.main-content -->
  <?php include 'common/footer.php'; ?>
</div>
<!-- /.main-container -->
<!-- basic scripts --> 
<!--[if !IE]> -->
<script src="assets/js/jquery-2.1.4.min.js"></script>
<!-- <![endif]--> 
<!--[if IE]>
<script src="assets/js/jquery-1.11.3.min.js"></script>
<![endif]--> 
<script type="text/javascript">
	if('ontouchstart' in document.documentElement) document.write("<script src='assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
</script> 
<script src="assets/js/bootstrap.min.js"></script> 
<!-- page specific plugin scripts --> 
<!--[if lte IE 8]>
  <script src="assets/js/excanvas.min.js"></script>
<![endif]-->
<script src="assets/js/jquery.dataTables.min.js"></script>
<script src="assets/js/jquery-typeahead.js"></script>
<script src="assets/js/jquery.dataTables.bootstrap.min.js"></script>
<!-- ace scripts -->
<script src="assets/js/ace-elements.min.js"></script>
<script src="assets/js/chosen.jquery.min.js"></script>
<script src="assets/js/ace.min.js"></script>
<script src="assets/jquery.validate.min.js"></script>
<link rel="stylesheet" href="bootstrap-sweetalert/lib/sweet-alert.css" />
<script src="bootstrap-sweetalert/lib/sweet-alert.min.js"></script>
<script src="assets/js/bootstrap-tag.min.js"></script>
<!-- inline scripts related to this page --> 
<script type="text/javascript">
jQuery(function ($) {
	//initiate dataTables plugin
	var myTable =
	$('#dynamic-table')
	//.wrap("<div class='dataTables_borderWrap' />")   //if you are applying horizontal scrolling (sScrollX)
	.DataTable({
		bAutoWidth: false,
		"aaSorting": [],
	});
	
	if(!ace.vars['touch']) {
		$('.chosen-select').chosen({allow_single_deselect:true}); 
		//resize the chosen on window resize

		$(window)
		.off('resize.chosen')
		.on('resize.chosen', function() {
			$('.chosen-select').each(function() {
				 var $this = $(this);
				 $this.next().css({'width': $this.parent().width()});
			})
		}).trigger('resize.chosen');
		//resize chosen on sidebar collapse/expand
		$(document).on('settings.ace.chosen', function(e, event_name, event_val) {
			if(event_name != 'sidebar_collapsed') return;
			$('.chosen-select').each(function() {
				 var $this = $(this);
				 $this.next().css({'width': $this.parent().width()});
			})
		});
	}
	
	$('#id-input-file-1 , #id-input-file-2').ace_file_input({
		no_file:'No File ...',
		btn_choose:'Choose',
		btn_change:'Change',
		droppable:false,
		onchange:null,
		thumbnail:false, //| true | large
		whitelist:'png|jpg|jpeg',
		blacklist:'exe|php|html',
		onchange:'',
	});
});

$('document').ready(function()
{
	$.validator.setDefaults({ ignore: ":hidden:not(select)" }); //for all select
   $("#form_submit").validate({
	   ignore: [],
	 errorPlacement : function(error, element) {
		$(element).closest('.form-group').find('.help-block').html(error.html());
	 },
	 highlight : function(element) {
		$(element).closest('.form-group').removeClass('has-success').addClass('has-error');
	 },
	 unhighlight: function(element, errorClass, validClass) {
		$(element).closest('.form-group').removeClass('has-error');
		$(element).closest('.form-group').find('.help-block').html('');
	 },
		  submitHandler: submitForm
	});
	function submitForm(){
		//disable the default form submission
		event.preventDefault();
		//grab all form data  
		var formData = new FormData($('#form_submit')[0]);
		
	   $.ajax({
			  url: 'connection/prom_banner_conn',
			  type: 'POST',
			  data: formData,
			  async: false,
			  cache: false,
			  contentType: false,
			  processData: false,
		 })
		 .done(function(data){
			  if ( data === 'success' ) {
				swal({
				  title: "",
				  text: "Successfully Added!",
				  type: "success",
				  confirmButtonText: "OK"
					},
					function (isConfirm) {
				  if (isConfirm) {
					  window.location.href = "promotion_banner";
				  }
				});
			  
			  } else if(data ==='error2') {
				  swal("", "Error While uploading file on the server. Please Try Again!", "warning");
			  
			  } else if(data ==='error3') {
				  swal("", "Invaild File Type! Please Try Again!", "warning");
			  
			  } else if(data ==='exist') {
				  swal("", "File Name Already Exists! Please Try Again!", "warning");
			  
			  } else {
				  swal("", "Something went wrong! Please Try Again!", "warning");
			  }
		 })
		 .fail(function(){
			  swal("", "Something went wrong! Please Try Again!", "warning");
		 });
	}
});

$("#form_update").validate({
 errorPlacement : function(error, element) {
	$(element).closest('.form-group').find('.help-block').html(error.html());
 },
 highlight : function(element) {
	$(element).closest('.form-group').removeClass('has-success').addClass('has-error');
 },
 unhighlight: function(element, errorClass, validClass) {
	$(element).closest('.form-group').removeClass('has-error');
	$(element).closest('.form-group').find('.help-block').html('');
 },
	  submitHandler: editForm
});
function editForm(){
	//disable the default form submission
	event.preventDefault();
	//grab all form data  
	var formData = new FormData($('#form_update')[0]);
   $.ajax({
		  url: 'connection/prom_banner_conn',
		  type: 'POST',
		  data: formData,
		  async: false,
		  cache: false,
		  contentType: false,
		  processData: false,
	 })
	 .done(function(data){
		  if ( data === 'success' ) {
			swal({
			  title: "",
			  text: "Successfully Added!",
			  type: "success",
			  confirmButtonText: "OK"
				},
				function (isConfirm) {
			  if (isConfirm) {
				  window.location.href = "promotion_banner";
			  }
			});
		  
		  } else if(data ==='error2') {
			  swal("", "Error While uploading file on the server. Please Try Again!", "warning");
		  
		  } else if(data ==='error3') {
			  swal("", "Invaild File Type! Please Try Again!", "warning");
		  
		  } else if(data ==='exist') {
			  swal("", "File Name Already Exists! Please Try Again!", "warning");
		  
		  } else {
			  swal("", "Something went wrong! Please Try Again!", "warning");
		  }
	 })
	 .fail(function(){
		  swal("", "Something went wrong! Please Try Again!", "warning");
	 });
}

/******************* Remove **********************/

$(".btn_remove1").click(function(){
	swal({
	  title: "",
	  text: "Are you sure you want to delete this?",
	  type: "warning",
	  showCancelButton: true,
	  confirmButtonClass: "btn-danger",
	  confirmButtonText: "Yes, delete it!",
	  cancelButtonText: "No, cancel!",
	  closeOnConfirm: false,
	  closeOnCancel: true
	},
	function(isConfirm) {
	  if (isConfirm) {
		$.post( "connection/prom_banner_conn", {remove_data_bn1: "data"}, function( data ) {
			if (data.msgType === 1) {
			  swal({
				title: "",
				text: "Successfully Deleted!",
				type: "success",
				confirmButtonText: "OK"
				  },
				  function (isConfirm) {
				if (isConfirm) {
					window.location.href = "promotion_banner";
				}
			  });
			
			} else{
			  swal("", "Something went wrong! Please Try Again!", "warning");
			}
		}, "json");
	  }
	});
});

$(".btn_remove2").click(function(){
	swal({
	  title: "",
	  text: "Are you sure you want to delete this?",
	  type: "warning",
	  showCancelButton: true,
	  confirmButtonClass: "btn-danger",
	  confirmButtonText: "Yes, delete it!",
	  cancelButtonText: "No, cancel!",
	  closeOnConfirm: false,
	  closeOnCancel: true
	},
	function(isConfirm) {
	  if (isConfirm) {
		$.post( "connection/prom_banner_conn", {remove_data_bn2: "data"}, function( data ) {
			if (data.msgType === 1) {
			  swal({
				title: "",
				text: "Successfully Deleted!",
				type: "success",
				confirmButtonText: "OK"
				  },
				  function (isConfirm) {
				if (isConfirm) {
					window.location.href = "promotion_banner";
				}
			  });
			
			} else{
			  swal("", "Something went wrong! Please Try Again!", "warning");
			}
		}, "json");
	  }
	});
});

</script>
</body>
</html>