<!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/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"> Delivery Methods</li>
        </ul>
        <!-- /.breadcrumb --> 
      </div>
      <div class="page-content">
        <div class="page-header">
          <h1>Enable/Disable Delivery Method </h1>
        </div>
        <!-- /.page-header -->
        <div class="space-10"></div><br>
        <div class="row">
          <div class="col-xs-12">
            <div class="">
              <div class="widget-body">
                <div class="">
                  <!-- div.table-responsive --> 
                  <!-- div.dataTables_borderWrap -->
                  <div class="table-responsive">
                    <table class="table table-striped table-bordered table-hover">
                      <thead>
                        <tr>
                          <th>#</th>
                          <th>Method Name</th>
                          <th>Enable/Disable</th>
                          <th>Delivery Days</th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php
						$sql = mysqli_query($conn, "SELECT * FROM delivery_methods ORDER BY order_id");
						$x = 0;
						while ($row = mysqli_fetch_array($sql)) {
							$x++;
						?>
                        <tr>
                          <td><?php echo $x; ?>.</td>
                          <td><?php echo $row['method_name']; ?></td>
                          <td align="center">
							<label>
								<input type="checkbox" class="ace chk_btn" data-id="<?php echo $row['id']; ?>" <?php if($row['enable_method'] == 1) { echo 'checked'; } ?>>
								<span class="lbl"></span>
							</label>
						  </td>
                          <td align="center"><div class="form-inline"><input type="text" value="<?php echo $row['delivery_days']; ?>" class="form-control" style="width:150px" id="delType_<?php echo $row['id']; ?>"> &nbsp;&nbsp;<a href="javascript:void(0)" title="Edit" class="btn_update" data-id="<?php echo $row['id']; ?>"><span class="fa fa-pencil"></span></a></div></td>
                        </tr>
                        <?php } ?>
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
            </div>
            <!-- PAGE CONTENT ENDS --> 
          </div>
          <!-- /.col --> 
        </div>
        <!-- /.row --> 
      </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.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>
<!-- 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()});
			})
		});
	}
	
});

$('.chk_btn').click(function() {
	var id = $(this).attr('data-id');
	
	if($(this).is(":checked")) {
	  $.post( "connection/delivery_methods_fun.php", { delType_enable: "data", del_id : id}, function( data ) {
		if (data.msgType != 1) {
		  swal("", "Something went wrong! Please Try Again", "warning");
		}
      }, "json");
	
	} else if($(this).is(":not(:checked)")) {
      $.post( "connection/delivery_methods_fun.php", { delType_disable: "data", del_id : id}, function( data ) {
		if (data.msgType != 1) {
		  swal("", "Something went wrong! Please Try Again", "warning");
		}
      }, "json");
	}
});

$(".btn_update").click(function(){ 
  var id = $(this).attr('data-id');
  var day = $('#delType_'+id).val();
  
      $.post( "connection/delivery_methods_fun.php", { update_del_days: "data", del_id : id, no_of_days: day}, function( data ) {
		if (data.msgType == 1) {
			swal("", "Successfully Updated!", "success");
		
		} else {
		  swal("", "Something went wrong! Please Try Again", "warning");
		}
      }, "json");

});
</script>
</body>
</html>