<?php include "common/user_log.php"; ?>

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Sampathbay</title>
  <!-- Place favicon.ico in the root directory -->
   <link rel="shortcut icon" type="image/x-icon" href="../img/S_favicon.ico"> 
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.5 -->
  <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="dist/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="dist/css/ionicons.min.css">
  <!-- daterange picker -->
  <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
  <!-- iCheck for checkboxes and radio inputs -->
  <link rel="stylesheet" href="plugins/iCheck/all.css">
  <!-- Bootstrap Color Picker -->
  <link rel="stylesheet" href="plugins/colorpicker/bootstrap-colorpicker.min.css">
  <!-- Bootstrap time Picker -->
  <link rel="stylesheet" href="plugins/timepicker/bootstrap-timepicker.min.css">
  <!-- Select2 -->
  <link rel="stylesheet" href="plugins/select2/select2.min.css">
  <!-- DataTables -->
  <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
  <!-- AdminLTE Skins. Choose a skin from the css/skins
     folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
  <link rel="stylesheet" href="bootstrap-sweetalert/lib/sweet-alert.css" />

  <link href="assets/editor.css" type="text/css" rel="stylesheet" />
  <!-- combo -->
  <style type="text/css">
    #form1 p {}

    #apDiv1 {
      position: absolute;
      width: 200px;
      height: 23px;
      z-index: 1;
      left: 164px;
      top: 420px;
    }

    #cke_editor1 {
      display: none;
    }

    #cke_editor2 {
      display: none;
    }
  </style>


  <!--GET SUBCATAGORIES FROM A CATAGORY-->
</head>

<body class="hold-transition skin-blue sidebar-mini">
  <div class="wrapper">

    <header class="main-header">
      <!-- Logo -->
      <a href="home.php" class="logo">
        <!-- mini logo for sidebar mini 50x50 pixels -->
        <span class="logo-mini"><img src="img/logo_mini.png" width="50"></span>
        <!-- logo for regular state and mobile devices -->
        <span class="logo-lg"><b><img src="img/logo.png" width="200"></b></span>
      </a>
      <!-- Header Navbar: style can be found in header.less -->
      <nav class="navbar navbar-static-top" role="navigation">
        <!-- Sidebar toggle button-->
        <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="logo-lg">
            &nbsp;&nbsp;<font face="Lucida Sans Unicode, Lucida Grande, sans-serif">Sampathbay</font></span>
        </a>

        <div class="navbar-custom-menu">
          <ul class="nav navbar-nav">

            <!-- User Account: style can be found in dropdown.less -->
            <li class="dropdown user user-menu">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                <img src="dist/img/user2-160x160.png" class="user-image" alt="User Image">
                <span class="hidden-xs"><?php echo $name; ?></span>
              </a>
              <ul class="dropdown-menu">
                <!-- User image -->
                <li class="user-header">
                  <img src="dist/img/user2-160x160.png" class="img-circle" alt="User Image">
                  <p>
                    Sampathbay

                  </p>
                </li>
                <!-- Menu Body -->

                <!-- Menu Footer-->
                <li class="user-footer">
                  <div class="pull-left">

                  </div>
                  <div class="pull-right">
                    <a href="distroy.php" class="btn btn-default btn-flat">Sign out</a>
                  </div>
                </li>
              </ul>
            </li>
            <!-- Control Sidebar Toggle Button -->
            <li>
              <a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a>
            </li>
          </ul>
        </div>
      </nav>
    </header>
    <!-- Left side column. contains the logo and sidebar -->
    <aside class="main-sidebar">
      <!-- sidebar: style can be found in sidebar.less -->
      <section class="sidebar">
        <!-- Sidebar user panel -->

        <?php include "common/sidebar.php"; ?>

      </section>
      <!-- /.sidebar -->
    </aside>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
      <!-- Content Header (Page header) -->
      <section class="content-header">
        <h1>
          Add Item Name
          <small>Preview</small>
        </h1>

        <ol class="breadcrumb">
          <li><a href="home.php"><i class="fa fa-home"></i> Home</a></li>
        </ol>
      </section>

      <!-- Main content -->
      <section class="content">

        <!-- ************************************************* -->


        <div class="box box-info">
          <div class="box-header with-border">
            <h3 class="box-title">Item Details</h3>
          </div>

          <div class="box-body">
            <input type="hidden" name="menu" id="menu" value="<?php echo $menu; ?>"  readonly>

            <form id="itm_form" action="javascript:void(0);">

              <!-- text area input -->
              <div class="form-group">
                <label>Select Category:<font color="#FF0000"><strong>*</strong></font></label>
                <!-- <select class="form-control select2" name="cat_id" id="main_cats" style="width: 100%;"><option>Test</option></select> -->
                <select class="form-control" name="cat_main" id="cat_main">
                  <option>Select Main Category...</option>
                </select>
                <span id="cat_val_msg" style="color: red; display: none">*Select Main Category</span>
              </div>

              <!-- text area input -->
              <div class="form-group">
                <label>Select Sub Category:<font color="#FF0000"><strong>*</strong></font></label>
                <!-- <select class="form-control select2" name="cat_id" id="main_cats" style="width: 100%;"><option>Test</option></select> -->
                <select class="form-control" name="sub_cat[]" id="sub_cat" multiple="multiple">
                  <option value="empty">Select Sub Category...</option>
                </select>
                <span id="subcat_val_msg" style="color: red; display: none">*Select Sub Category</span>
              </div>

              <!-- text input -->
              <div class="form-group">
                <label>Item Code:<font color="#FF0000"><strong>*</strong></font></label>
                <input type="text" class="form-control" id="itm_code" name="item_code" placeholder="Enter ...">
                <span id="val_code" style="color: red; display: none">*Enter Item Code</span>
                <span id="val_code_on" style="color: red; display: none">*Invalid Item Code</span>
              </div>


              <!-- text input -->
              <div class="form-group">
                <label>Name:<font color="#FF0000"><strong>*</strong></font></label>
                <input type="text" class="form-control" id="itm_name" name="item_name" placeholder="Enter ...">
                <span id="val_name" style="color: red; display: none">*Enter Item Name</span>
              </div>



              <!-- text input -->
              <div class="form-group">
                <label>Price:<font color="#FF0000"><strong>*</strong></font></label>
                <input type="text" class="form-control" id="itm_price" name="price" placeholder="Enter ...">
                <span id="val_price" style="color: red; display: none">*Enter Item Price</span>
              </div>

              <div class="form-group">
                <label>Tag Text :</label> (Recommend character count is 5)
                <input type="text" class="form-control" id="tag_text" name="tag_text" placeholder="Enter ...">
              </div>

              <!-- text input -->
              <div class="form-group">
                <label>Short Description:</label>
                <input type="text" class="form-control" id="itm_discrip" name="discription" placeholder="Enter ...">
              </div>

              <div class="form-group">
                <div class="form-group">
                  <label>Description</label>
                  <!-- <textarea class="form-control" name="des" rows="15" id="editor1" required></textarea> -->
                  <textarea id="txtEditor_itm"></textarea>

                  <textarea style="display: none;" id="txt_itm" name="des"></textarea>
                </div>
              </div>

              <!-- Image Upload -->
              <div class="form-group">
                <label>Image<font color="#FF0000"><strong>* 240*240 And Size less than 100kb</strong></font></label>
                <input type="file" class="form-control" id="itm_img" name="itm_img">
                <span id="val_img" style="color: red; display: none">*Enter Item Image</span>
              </div>

              <div class="form-group">
                <input type="checkbox" value="" name="featue_pro"><label style="margin-left: 5px">Special Deals</label>
              </div>

              <div class="form-group">
                <input type="checkbox" value="" name="new_pro"><label style="margin-left: 5px">New Product </label>
              </div>

              <div class="form-group">
                <input type="checkbox" value="" name="ex_delivery"><label style="margin-left: 5px">Same day Delivery </label>
              </div>

              <div class="form-group">
                <input type="checkbox" value="" name="soled_out"><label style="margin-left: 5px">Soled Out</label>
              </div>

              <div class="form-group">
                <input type="checkbox" value="" name="home_page"><label style="margin-left: 5px">Home Page</label>
              </div>

              <div class="form-group">
                <input type="checkbox" value="" name="int_delivery"><label style="margin-left: 5px">International Delivery</label>
              </div>

              <div class="form-group">
                <input type="checkbox" value="" name="same_delivery"><label style="margin-left: 5px">Today Offer</label>
              </div>

              <div class="form-group">
                <button type="submit" id="btn_sub" class="btn btn-primary" disabled="">Submit</button>
              </div>
            </form>
          </div>
        </div>






        <!-- /.table -->

        <!-- <div class="box box-info">
          <div class="box-header">
            <h3 class="box-title">Details Edit / Remove</h3>
          </div> -->
          <!-- /.box-header -->
          <!-- <div class="box-body">
            <table id="example1" class="table table-bordered table-striped">
              <thead>
                <tr>
                  <th>ID</th>
                  <th>Category</th>
                  <th>Sub Category</th>
                  <th>Item Code</th>
                  <th>Name</th>
                  <th>Price</th>
                  <th>Description</th>
                  <th>Image</th>
                  <th>Edit</th>
                  <th>Add Images</th>
                  <th>Remove</th>
                </tr>
              </thead>
              <tbody>
                <?php
                //$sql = "SELECT * FROM items ORDER BY id DESC ";
                //$result = mysqli_query($conn, $sql);

                //$xx = 0;
                //while ($row = mysqli_fetch_array($result)) {
                  //$xx = $xx + 1 ?>
                  <tr>
                    <td><?php //echo $xx; ?>.</td>

                    <td><?php

                        //$sql6 = "SELECT * FROM  cat WHERE id='" . $row['cat_id'] . "'";
                        //$result6 = mysqli_query($conn, $sql6);
                        //while ($row6 = mysqli_fetch_array($result6)) {
                        //  echo $cat = $row6['cat'];
                        //}
                        ?></td>
                    <td><?php

                        //$sql66 = "SELECT * FROM  sub_cat WHERE id='" . $row['sub_cat_id'] . "'";
                       // $result66 = mysqli_query($conn, $sql66);
                        //while ($row66 = mysqli_fetch_array($result66)) {

                         // echo $sub_cat = $row66['sub_cat'];
                        //}
                        ?></td>

                    <td><?php //echo $row['item_code']; ?></td>
                    <td><?php //echo $row['item_name']; ?></td>
                    <td><?php //echo $row['price']; ?></td>
                    <td><?php //echo $row['discription']; ?></td>
                    <td><img src="upload/item/<?php //echo $row['item_code']; ?>/<?php //echo $row['f_img']; ?>" width="100"></td>

                    <td><button value="<?php //echo $row['id']; ?>" data-toggle="modal" data-target="#myModal" class="btn btn-info btn-sm btn_up">
                        <span class="glyphicon glyphicon-pencil"></span> Edit </button></td>
                    <td>
                      <a type="button" href="add_item_images.php?id=<?php //echo $row['id']; ?>" class="btn btn-sm btn-success btn_add_img"><span class="glyphicon glyphicon-plus"></span>Add Images</a>
                    </td>
                    <td><button value="<?php //echo $row['item_code']; ?>" class="btn btn-danger btn-sm btn_del">
                        <span class="glyphicon glyphicon-trash"></span> Remove </button></td>
                  </tr>
                <?php  //} ?>
              </tbody>
            </table>
          </div> -->
          <!-- /.box-body -->
        <!-- </div>

      </section>

    </div> -->
    <!-- /.End table -->
    <!-- ************************************************* -->

    <!-- /.col -->
  </div><!-- /.row -->
  </div><!-- /.box-body -->



  <div class="row">



  </div>
  <!-- /.col (right) -->


  </div>
  <footer class="main-footer">
    <div class="pull-right hidden-xs">

    </div> <strong>Copyright &copy; Sampathbay</strong> All rights reserved.
  </footer>

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Create the tabs -->
    <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
      <li><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
      <li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i class="fa fa-gears"></i></a></li>
    </ul>
    <!-- Tab panes -->
    <div class="tab-content">
      <!-- Home tab content -->
      <div class="tab-pane" id="control-sidebar-home-tab">





      </div><!-- /.tab-pane -->


    </div><!-- /.tab-pane -->
    </div>
  </aside><!-- /.control-sidebar -->
  <!-- Add the sidebar's background. This div must be placed
       immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>
  </div><!-- ./wrapper -->





  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title" id="test_id">Edit Item</h4>
        </div>
        <div class="modal-body">
          <form id="itm_update_form" action="javascript:void(0);">
            <div class="form-group">
              <label>Select Category:<font color="#FF0000"><strong>*</strong></font></label>
              <!-- <select class="form-control select2" name="cat_id" id="main_cats" style="width: 100%;"><option>Test</option></select> -->
              <select class="form-control" id="up_cat_main" name="up_cat_main">
                <option>Select Main Catagory...</option>
              </select>
              <span id="up_cat_val_msg" style="color: red; display: none">*Select Main Category name</span>
            </div>
            <div class="form-group">
              <input type="text" style="display: none" name="id_holder" id="id_holder"></input>
              <label>Select Sub Category:<font color="#FF0000"><strong>*</strong></font></label>
              <!-- <select class="form-control select2" name="cat_id" id="main_cats" style="width: 100%;"><option>Test</option></select> -->
              <select class="form-control" name="up_sub_cat[]" id="up_sub_cat" multiple="multiple">
                <option value="empty">Select Sub Category...</option>
              </select>
              <span id="up_subcat_val_msg" style="color: red; display: none">*Select Sub Category</span>
            </div>
            <!-- text input -->
            <div class="form-group">
              <label>Item Code:<font color="#FF0000"><strong>*</strong></font></label>
              <input type="text" class="form-control" id="up_itm_code" name="up_item_code" placeholder="Enter ...">
              <span id="up_val_code" style="color: red; display: none">*Enter Item Code</span>
            </div>


            <!-- text input -->
            <div class="form-group">
              <label>Name:<font color="#FF0000"><strong>*</strong></font></label>
              <input type="text" class="form-control" id="up_itm_name" name="up_item_name" placeholder="Enter ...">
              <span id="up_val_name" style="color: red; display: none">*Enter Item Name</span>
            </div>

            <!-- text input -->
            <div class="form-group col-md-6">
              <label>Price:<font color="#FF0000"><strong>*</strong></font></label>
              <input type="text" class="form-control" id="up_itm_price" name="up_price" placeholder="Enter ...">
              <span id="up_val_price" style="color: red; display: none">*Enter Item Price</span>
            </div>

            <div class="form-group col-md-6">
              <label>Original Price:<font color="#FF0000"><strong>*</strong></font></label>
              <input type="text" class="form-control" id="itm_ori_price" name="itm_ori_price" placeholder="Enter ...">
            </div>

            <div class="form-group">
              <label>Tag Text :</label> (Recommend character count is 5)
              <input type="text" class="form-control" id="up_tag_text" name="up_tag_text" placeholder="Enter ...">
            </div>

            <!-- text input -->
            <div class="form-group">
              <label>Short Description:</label>
              <input type="text" class="form-control" id="up_itm_discrip" name="up_discription" placeholder="Enter ...">
            </div>
            <div class="form-group">
              <div class="form-group">
                <label>Description</label>
                <textarea class="form-control" id="txtEditor_itm_up"></textarea>
                <textarea style="display: none;" id="txt_itm_up" name="des2"></textarea>
              </div>

            </div>

            <!-- Image Upload -->
            <div class="form-group">
              <label>Image<font color="#FF0000"><strong>* 240*240 And Size less than 100kb</strong></font></label>
              <input type="file" class="form-control" id="up_itm_img" name="up_itm_img">
              <div style="align:center;">
                <img id="up_itm_img_dis" style="height: 150px; width: auto;">
              </div>
            </div>

            <div class="form-group">
              <input type="checkbox" id="up_featue_pro" value="" name="up_featue_pro"><label style="margin-left: 5px">Special Deals</label>
            </div>

            <div class="form-group">
              <input type="checkbox" id="up_new_pro" value="" name="up_new_pro"><label style="margin-left: 5px">New Product</label>
            </div>

            <div class="form-group">
              <input type="checkbox" value="" id="up_ex_delivery" name="up_ex_delivery"><label style="margin-left: 5px">Same Day Delivery </label>
            </div>

            <div class="form-group">
              <input type="checkbox" value="" id="up_soled_out" name="up_soled_out"><label style="margin-left: 5px">Soled Out</label>
            </div>

            <div class="form-group">
              <input type="checkbox" value="" id="up_home_page" name="up_home_page"><label style="margin-left: 5px">Home Page</label>
            </div>

            <div class="form-group">
              <input type="checkbox" value="" id="up_int_delivery" name="up_int_delivery"><label style="margin-left: 5px">International Delivery</label>
            </div>

            <div class="form-group">
              <input type="checkbox" value="" name="up_same_delivery" id="up_same_delivery"><label style="margin-left: 5px">Today Offer</label>
            </div>

            <div class="form-group">
              <button type="submit" class="btn btn-primary" id="update_item">Update</button>
            </div>

          </form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>

      </div>

    </div>
  </div>

  <!-- jQuery 2.1.4 -->
  <script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
  <script src="https://cdn.ckeditor.com/4.4.3/standard/ckeditor.js"></script>
  <!-- Bootstrap 3.3.5 -->
  <script src="bootstrap/js/bootstrap.min.js"></script>
  <!-- Select2 -->
  <script src="plugins/select2/select2.full.min.js"></script>
  <!-- DataTables -->
  <script src="plugins/datatables/jquery.dataTables.min.js"></script>
  <script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
  <!-- InputMask -->
  <script src="plugins/input-mask/jquery.inputmask.js"></script>
  <script src="plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
  <script src="plugins/input-mask/jquery.inputmask.extensions.js"></script>
  <!-- date-range-picker -->
  <script src="plugins/daterangepicker/moment.min.js"></script>
  <script src="plugins/daterangepicker/daterangepicker.js"></script>
  <!-- bootstrap color picker -->
  <script src="plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
  <!-- bootstrap time picker -->
  <script src="plugins/timepicker/bootstrap-timepicker.min.js"></script>
  <!-- SlimScroll 1.3.0 -->
  <script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
  <!-- iCheck 1.0.1 -->
  <script src="plugins/iCheck/icheck.min.js"></script>
  <!-- FastClick -->
  <script src="plugins/fastclick/fastclick.min.js"></script>
  <!-- AdminLTE App -->
  <script src="dist/js/app.min.js"></script>
  <!-- AdminLTE for demo purposes -->
  <script src="dist/js/demo.js"></script>
  <script src="bootstrap-sweetalert/lib/sweet-alert.min.js"></script>
  <!-- <script src="input-mask/input-mask.min.js"></script> -->

  <script src="assets/editor.js"></script>
  <script>
    $(document).ready(function() {
      $("#txtEditor_itm").Editor();
      $("#txtEditor_itm_up").Editor();
    });
  </script>


  <!-- Page script -->

  <script>
    /*$(function () {
        //Initialize Select2 Elements
        $(".select2").select2();

        //Datemask dd/mm/yyyy
        $("#datemask").inputmask("dd/mm/yyyy", {"placeholder": "yyyy-mm-dd"});
        //Datemask2 mm/dd/yyyy
        $("#datemask2").inputmask("mm/dd/yyyy", {"placeholder": "yyyy-mm-dd"});
        //Money Euro
        $("[data-mask]").inputmask();

        //Date range picker
        $('#reservation').daterangepicker();
        //Date range picker with time picker
       $('#reservationtime').daterangepicker({timePicker: false, timePickerIncrement: 30, format: 'YYYY-MM-DD'});
        //Date range as a button
        $('#daterange-btn').daterangepicker(
            {
              ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month')]
              },
              startDate: moment().subtract(29, 'days'),
           
            },
        function (start) {
          $('#reportrange span').html(start.format('MMMM D, YYYY'));
        }
        );

        //iCheck for checkbox and radio inputs
        $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
          checkboxClass: 'icheckbox_minimal-blue',
          radioClass: 'iradio_minimal-blue'
        });
        //Red color scheme for iCheck
        $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
          checkboxClass: 'icheckbox_minimal-red',
          radioClass: 'iradio_minimal-red'
        });
        //Flat red color scheme for iCheck
        $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
          checkboxClass: 'icheckbox_flat-green',
          radioClass: 'iradio_flat-green'
        });

        
      });*/

    function data_load() {
      $.post('function/sub_cat.php', {
        'load_subcat': 'data'
      }, function(data) {
        $("#cat_main").html(data);
      });

    }

    function load_subcat(id) {
      $.post('function/add_items_back.php', {
        'load_subcat': 'data',
        id: id
      }, function(data) {
        $("#sub_cat").html(data);
      });
    }

    function item_delete(id) {
      $.post('function/add_items_back.php', {
        'delete_item': 'data',
        id: id
      }, function(data) {
        if (data = "ok") {
          swal({
              title: "Deleted!",
              text: "Successfully Deleted!",
              type: "success",
              confirmButtonText: "OK"
            },
            function(isConfirm) {
              if (isConfirm) {
                window.location.href = "add_items.php";
              }
            });
        } else {
          swal("Oops...", "Something went wrong!", "warning");
        }
      });
    }

    function escapeHtml(text) {
      var map = {
        '&': '&amp;',
        '<': '&lt;',
        '>': '&gt;',
        '"': '&quot;',
        "'": '&#039;'
      };

      return text.replace(/[&<>"']/g, function(m) {
        return map[m];
      });
    }

    function update_load_data(id) {
      $.post("function/add_items_back.php", {
        'load_item_up': "data",
        id: id
      }, function(data) {

        load_up_main_cat(data.cat_id);
        load_up_sub_cat(data.item_code, data.cat_id);
        //alert(data.sub_cat_id);
        $('#up_itm_code').val(data.item_code);
        $('#up_itm_name').val(data.item_name);
        $('#up_itm_price').val(data.price);
        $('#itm_ori_price').val(data.ori_price);
        $('#up_tag_text').val(data.tag_text);
        $('#up_itm_discrip').val(data.discription);
        //$('#txtEditor_itm_up').val(data.description_more);
        $('#txtEditor_itm_up').Editor("setText", data.description_m);
        $("#up_itm_img_dis").attr("src", "upload/item/" + data.item_code + "/" + data.f_img);
        //CKEDITOR.instances['txtEditor_itm_up'].setData(data.description_more);

        if (data.featue_pro == 1) {
          $('#up_featue_pro').prop('checked', true);
        }

        if (data.new_pro == 1) {
          $('#up_new_pro').prop('checked', true);
        }

        if (data.ex_delivery == 1) {
          $('#up_ex_delivery').prop('checked', true);
        }

        if (data.soled_out == 1) {
          $('#up_soled_out').prop('checked', true);
        }

        if (data.home_page == 1) {
          $('#up_home_page').prop('checked', true);
        }

        if (data.int_delivery == 1) {
          $('#up_int_delivery').prop('checked', true);
        }

        if (data.same_delivery == 1) {
          $('#up_same_delivery').prop('checked', true);
        }

      }, "json");
    }




    function load_up_main_cat(id) {
      $.post('function/add_items_back.php', {
        'load_up_main_cat': 'data',
        id: id
      }, function(data) {
        $("#up_cat_main").html(data);
      });
    }

    function load_up_sub_cat(id, mid) {
      $.post('function/add_items_back.php', {
        'load_up_sub_cat': 'data',
        id: id,
        mid: mid
      }, function(data) {
        $("#up_sub_cat").html(data);
      });
    }

    function load_subcat_up(id) {
      $.post('function/add_items_back.php', {
        'load_subcat': 'data',
        id: id
      }, function(data) {
        $("#up_sub_cat").html(data);
      });
    }



    ////////////////////////////////////// validation ///////////////////////////////////////////////////////////

    function clear_validation_masg() {
      $('#cat_val_msg').fadeOut();
      $('#subcat_val_msg').fadeOut();
      $('#val_name').fadeOut();
      $('#val_code').fadeOut();
      $('#val_price').fadeOut();
      $('#val_img').fadeOut();

    }


    //display for error msg when load validate_item function
    function display_error_msg() {

      if ($('#cat_main').val() === 'empty') {
        $('#cat_val_msg').fadeIn();
      }
      if ($('#sub_cat').val() === 'empty') {
        $('#subcat_val_msg').fadeIn();
      }
      if ($('#itm_name').val() === '') {
        $('#val_name').fadeIn();
      }
      if ($('#itm_code').val() === '') {
        $('#val_code').fadeIn();
      }
      if ($('#itm_price').val() === '') {
        $('#val_price').fadeIn();
      }
      if ($('#itm_price').val() === '') {
        $('#val_price').fadeIn();
      }
      if ($('#itm_img').val() === '') {
        $('#val_img').fadeIn();
      }


    }

    var validate_both = true;

    function validate_both_fun() {
      if ($('#cat_main').val() === 'empty') {
        validate_both = false;
        $('#cat_val_msg').fadeIn();
        display_error_msg();
        scrollTo(0, 0);
      } else {
        if ($('#sub_cat').val() === 'empty') {
          validate_both = false;
          $('#subcat_val_msg').fadeIn();
          display_error_msg();
          scrollTo(0, 0);
        } else {
          if ($('#itm_code').val() === '') {
            validate_both = false;
            $('#val_code').fadeIn();
            display_error_msg();
            scrollTo(0, 0);
          } else {
            if ($('#itm_name').val() === '') {
              validate_both = false;
              $('#val_name').fadeIn();
              display_error_msg();
              scrollTo(0, 0);
            } else {
              if ($('#itm_price').val() === '') {
                validate_both = false;
                $('#val_price').fadeIn();
                display_error_msg();
                scrollTo(0, 0);
              } else {
                if ($('#itm_img').val() === '') {
                  validate_both = false;
                  $('#val_img').fadeIn();
                  display_error_msg();
                  scrollTo(0, 0);
                } else {
                  validate_both = true;
                  clear_validation_masg();
                }
              }
            }
          }
        }
      }
    }

    ///////////////////////////////////////// update Validation ///////////////////////////////////////////////

    function up_clear_validation_masg() {
      $('#up_cat_val_msg').fadeOut();
      $('#up_subcat_val_msg').fadeOut();
      $('#up_val_name').fadeOut();
      $('#up_val_code').fadeOut();
      $('#up_val_price').fadeOut();
      $('#up_val_img').fadeOut();

    }


    //display for error msg when load validate_item function
    function up_display_error_msg() {

      if ($('#up_cat_main').val() === 'empty') {
        $('#up_cat_val_msg').fadeIn();
      }
      if ($('#up_sub_cat').val() === 'empty') {
        $('#up_subcat_val_msg').fadeIn();
      }
      if ($('#up_itm_name').val() === '') {
        $('#up_val_name').fadeIn();
      }
      if ($('#up_itm_code').val() === '') {
        $('#up_val_code').fadeIn();
      }
      if ($('#up_itm_price').val() === '') {
        $('#up_val_price').fadeIn();
      }
      if ($('#up_itm_price').val() === '') {
        $('#up_val_price').fadeIn();
      }
      if ($('#up_itm_img').val() === '') {
        $('#up_val_img').fadeIn();
      }


    }

    var up_validate_both = true;

    function up_validate_both_fun() {
      if ($('#up_cat_main').val() === 'empty') {
        up_validate_both = false;
        $('#up_cat_val_msg').fadeIn();
        up_display_error_msg();
        scrollTo(0, 0);
      } else {
        if ($('#up_sub_cat').val() === 'empty') {
          up_validate_both = false;
          $('#up_subcat_val_msg').fadeIn();
          up_display_error_msg();
          scrollTo(0, 0);
        } else {
          if ($('#up_itm_code').val() === '') {
            up_validate_both = false;
            $('#up_val_code').fadeIn();
            up_display_error_msg();
            scrollTo(0, 0);
          } else {
            if ($('#up_itm_name').val() === '') {
              up_validate_both = false;
              $('#up_val_name').fadeIn();
              up_display_error_msg();
              scrollTo(0, 0);
            } else {
              if ($('#up_itm_price').val() === '') {
                up_validate_both = false;
                $('#up_val_price').fadeIn();
                up_display_error_msg();
                scrollTo(0, 0);
              } else {
                up_validate_both = true;
                up_clear_validation_masg();
              }
            }
          }
        }
      }
    }


    ///////////////////////////////////////// end validation //////////////////////////////////////////////////////

    $(document).ready(function() {
      data_load();

      $("#cat_main").change(function() {
        var val = $(this).val();
        load_subcat(val);
      })

      $("#up_cat_main").change(function() {
        var val = $(this).val();
        load_subcat_up(val);
      })

      $("#itm_form").on('submit', (function(e) {

        $('#txt_itm').val($('#txtEditor_itm').Editor("getText"));

        validate_both_fun();
        if (validate_both) {
          for (instance in CKEDITOR.instances) {
            CKEDITOR.instances[instance].updateElement();
          }
          e.preventDefault();
          $.ajax({
            url: "function/ajax_image_upload.php",
            type: "POST",
            data: new FormData(this),
            contentType: false,
            cache: false,
            processData: false,
            beforeSend: function() {
              //$("#preview").fadeOut();
              //$("#err").fadeOut();
            },
            success: function(data) {
              if (data == 'inserted') {
                swal({
                    title: "Added!",
                    text: "Successfully Added!",
                    type: "success",
                    confirmButtonText: "OK"
                  },
                  function(isConfirm) {
                    if (isConfirm) {
                      window.location.href = "add_items.php";
                    }
                  });
              } else if (data == 'sqlerror') {
                swal("Oops...", "SQL Error!", "warning");
              } else if (data == 'uploaderror') {
                swal("Oops...", "Something wrong with Image!", "warning");
              } else if (data == 'invalid') {
                swal("Oops...", "Invalid image Type!", "warning");
              } else {
                swal("Oops...", "Something went wrong!", "warning");
              }

            },
            error: function(e) {
              //$("#err").html(e).fadeIn();
              alert("err2");
            }
          });
        }

        //alert("Done");
      }));

      $('#itm_code').keyup(function() {

        var code = $(this).val();

        $.post("function/itm_code_validation.php", {
          code_validation: 'data',
          code: code
        }, function(e) {

          if (e == 0) {
            $("#itm_code").css("border", "1px solid red");
            $("#val_code_on").fadeIn();
            $(':input[type="submit"]').prop('disabled', true);
          }
          if (e == 1) {
            $("#itm_code").css("border", "1px solid #d5d5d5");
            $("#val_code_on").fadeOut();
            $(':input[type="submit"]').prop('disabled', false);
          }

        }, "json");

      });

      $("#itm_update_form").on('submit', (function(e) {


        $('#txt_itm_up').val($('#txtEditor_itm_up').Editor("getText"));

        up_validate_both_fun();
        if (up_validate_both) {
          for (instance in CKEDITOR.instances) {
            CKEDITOR.instances[instance].updateElement();
          }
          e.preventDefault();
          $.ajax({
            url: "function/ajax_image_upload.php",
            type: "POST",
            data: new FormData(this),
            contentType: false,
            cache: false,
            processData: false,
            beforeSend: function() {
              //$("#preview").fadeOut();
              //$("#err").fadeOut();
            },
            success: function(data) {
              if (data == 'inserted') {
                swal({
                    title: "Updated!",
                    text: "Successfully Updated!",
                    type: "success",
                    confirmButtonText: "OK"
                  },
                  function(isConfirm) {
                    if (isConfirm) {
                      window.location.href = "add_items.php";
                    }
                  });
              } else if (data == 'sqlerror') {
                swal("Oops...", "SQL Error!", "warning");
              } else if (data == 'uploaderror') {
                swal("Oops...", "Something wrong with Image!", "warning");
              } else if (data == 'invalid') {
                swal("Oops...", "Invalid image Type!", "warning");
              } else {
                swal("Oops...", "Something went wrong!", "warning");
              }

            },
            error: function(e) {
              //$("#err").html(e).fadeIn();
              alert("err2");
            }
          });
        }

        //alert("Done");
      }));


      $(".btn_del").click(function() {
        var x = $(this).val();
        swal({
            title: "Are you sure?",
            text: "Your may not be able to recover!",
            type: "warning",
            showCancelButton: true,
            confirmButtonClass: "btn-danger",
            confirmButtonText: "Yes, delete it!",
            closeOnConfirm: false
          },
          function() {
            item_delete(x);
          }
        );
      });

      $(".btn_up").click(function() {
        $("#id_holder").val($(this).val());
        update_load_data($(this).val());
      });

    });
  </script>

  <script>
    $(function() {
      $("#example1").DataTable();
      $('#example2').DataTable({
        "paging": true,
        "lengthChange": false,
        "searching": false,
        "ordering": true,
        "info": true,
        "autoWidth": false
      });
    });
  </script>
</body>

</html>


(S) DIC SARASAVI COMPACT E/S/T