<?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="plugins/sweetalert/sweetalert.css" />
</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 -->

          </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>Staff Members</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">

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

        <form action="javascript:void(0);" id="form_submit">
          <div class="box box-info">
            <div class="box-header with-border">
              <h3 class="box-title">Staff Members Details</h3>
            </div>
            <div class="box-body">
              <div class="row">
                <div class="col-md-6">

                  <div class="form-group">
                    <label>Name:<font color="#FF0000"><strong>*</strong></font></label>
                    <input type="text" class="form-control" name="s_name" placeholder="Enter ..." autocomplete="off" required>
                  </div>

                  <div class="form-group">
                    <label>Designation:</label>
                    <input type="text" class="form-control" name="desig" id="desig" placeholder="Enter ..." autocomplete="off">
                  </div>

                  <div class="form-group">
                    <label>NIC No:<font color="#FF0000"><strong>*</strong></font></label>
                    <input type="text" class="form-control" name="nic_no" id="nic_no" placeholder="Enter ..." autocomplete="off" required>
                  </div>

                </div>
                <div class="col-md-6">

                  <div class="form-group">
                    <label>Address:</label>
                    <input type="text" class="form-control" name="address" id="address" placeholder="Enter ..." autocomplete="off">
                  </div>

                  <div class="form-group">
                    <label>Contact No:<font color="#FF0000"><strong>*</strong></font></label>
                    <input type="text" class="form-control" name="tel_no" id="tel_no" placeholder="Enter ..." autocomplete="off" required>
                  </div>

                  <div class="form-group">
                    <label>Email:</label>
                    <input type="email" class="form-control" name="email" id="email" placeholder="Enter ..." autocomplete="off">
                  </div>

                </div>
              </div>
              <!-- /.box-body -->
              <div class="box-footer">
                <input type="submit" class="btn btn-primary" name="btn_staff_add" value="SUBMIT" />
              </div>
            </div>
          </div>
        </form>

        <!-- /.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-responsive">
            <table id="example1" class="table table-bordered table-striped">
              <thead>
                <tr>
                  <th>ID</th>
                  <th>Name</th>
                  <th>Designation</th>
                  <th>NIC No</th>
                  <th>Address</th>
                  <th>Contact No</th>
                  <th>Email</th>
                  <th>Edit</th>
                  <th>Remove</th>
                </tr>
              </thead>
              <tbody>
                <?php
                $sql = "SELECT * FROM staff_members";
                $stmt = mysqli_query($conn, $sql);

                $xx = 0;
                while ($row = mysqli_fetch_array($stmt)) {
                  $xx++; ?>
                  <tr>
                    <td><?php echo $xx; ?>.</td>
                    <td><?php echo $row['name']; ?></td>
                    <td><?php echo $row['designation']; ?></td>
                    <td><?php echo $row['nic_no']; ?></td>
                    <td><?php echo $row['address']; ?></td>
                    <td><?php echo $row['contact_no']; ?></td>
                    <td><?php echo $row['email']; ?></td>
                    <td>
                      <button class="btn btn-info btn-sm btn_up" data-toggle="modal" data-target="#edit_data" value="<?php echo $row['id']; ?>"><span class="glyphicon glyphicon-pencil"></span> &nbsp;EDIT </button>
                    </td>
                    <td><button value="<?php echo $row['id']; ?>" class="btn btn-danger btn-sm btn_dell">
                        <span class="glyphicon glyphicon-trash"></span> &nbsp;DELETE </button></td>
                  </tr>
                <?php  } ?>
              </tbody>
            </table>
          </div>
          <!-- /.box-body -->
        </div>
      </section>
    </div>
    <!-- /.End table -->
    <!-- ************************************************* -->

    <div class="modal fade" id="edit_data" 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 Staff Member</h4>
          </div>
          <div class="modal-body">

            <form action="javascript:void(0);" id="form_update">
              <input type="hidden" name="id_up" id="id_up">

              <div class="form-group">
                <label>Name:<font color="#FF0000"><strong>*</strong></font></label>
                <input type="text" class="form-control" name="s_name_up" id="s_name_up" placeholder="Enter ..." autocomplete="off" required>
              </div>

              <div class="form-group">
                <label>Designation:</label>
                <input type="text" class="form-control" name="desig_up" id="desig_up" placeholder="Enter ..." autocomplete="off">
              </div>

              <div class="form-group">
                <label>NIC No:<font color="#FF0000"><strong>*</strong></font></label>
                <input type="text" class="form-control" name="nic_no_up" id="nic_no_up" placeholder="Enter ..." autocomplete="off" required>
              </div>

              <div class="form-group">
                <label>Address:</label>
                <input type="text" class="form-control" name="address_up" id="address_up" placeholder="Enter ..." autocomplete="off">
              </div>

              <div class="form-group">
                <label>Contact No:<font color="#FF0000"><strong>*</strong></font></label>
                <input type="text" class="form-control" name="tel_no_up" id="tel_no_up" placeholder="Enter ..." autocomplete="off" required>
              </div>

              <div class="form-group">
                <label>Email:</label>
                <input type="email" class="form-control" name="email_up" id="email_up" placeholder="Enter ..." autocomplete="off">
              </div>

              <!-- /.box-body -->
              <div class="box-footer">
                <button class="btn btn-danger">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>

    <!-- /.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>&copy; 2019 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 -->

  <!-- jQuery 2.1.4 -->
  <script src="plugins/jQuery/jQuery-2.1.4.min.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="plugins/sweetalert/sweetalert.min.js"></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'
      });


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

  <script>
    //$(document).ready(function(){

    /**************************** Insert Acc ****************************/

    $("#form_submit").on('submit', (function(e) {
      e.preventDefault();
      $.ajax({
        url: "function/staff_members_fun.php",
        type: "POST",
        data: new FormData(this),
        contentType: false,
        cache: false,
        processData: false,
        beforeSend: function() {},
        success: function(data) {
          if (data === '') {
            swal("Oops...", "Something went wrong!", "warning");

          } else {
            if (data === 'error') {
              swal("SQL Error!", "Please Try Again!", "warning");

            } else if (data === 'exist') {
              swal("", "NIC No Already Exist", "warning");

            } else if (data === 'empty') {
              swal("", "Please Enter Required Details.", "warning");

            } else if (data === 'success') {
              swal({
                  title: "",
                  text: "Successfully Added!",
                  type: "success",
                  confirmButtonText: "OK"
                },
                function(isConfirm) {
                  if (isConfirm) {
                    window.location.href = "staff_members.php";
                  }
                });
            }
          }
        },
        error: function(e) {
          alert("err2");
        }
      });
    }));

    /********************************* Edit ******************************/

    $("#form_update").on('submit', (function(e) {
      e.preventDefault();
      $.ajax({
        url: "function/staff_members_fun.php",
        type: "POST",
        data: new FormData(this),
        contentType: false,
        cache: false,
        processData: false,
        beforeSend: function() {},
        success: function(data) {
          if (data === '') {
            swal("Oops...", "Something went wrong!", "warning");

          } else {
            if (data === 'error') {
              swal("SQL Error!", "Please Try Again!", "warning");

            } else if (data === 'exist') {
              swal("", "NIC No Already Exist", "warning");

            } else if (data === 'empty') {
              swal("", "Please Enter Required Details.", "warning");

            } else if (data === 'success') {
              swal({
                  title: "",
                  text: "Successfully Updated!",
                  type: "success",
                  confirmButtonText: "OK"
                },
                function(isConfirm) {
                  if (isConfirm) {
                    window.location.href = "staff_members.php";
                  }
                });
            }
          }
        },
        error: function(e) {
          alert("err2");
        }
      });
    }));

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

    $(".btn_dell").click(function() {
      var row_id = $(this).val();
      swal({
          title: "Are you sure?",
          text: "",
          type: "warning",
          showCancelButton: true,
          confirmButtonClass: "btn-danger",
          confirmButtonText: "Yes, delete it!",
          cancelButtonText: "No, cancel!",
          closeOnConfirm: false,
          closeOnCancel: true
        },
        function(isConfirm) {
          if (isConfirm) {
            $.post("function/staff_members_fun.php", {
              remove_data: "data",
              id: row_id
            }, function(data) {
              if (data.msgType === 1) {
                swal({
                    title: "",
                    text: "Successfully Deleted!",
                    type: "success",
                    confirmButtonText: "OK"
                  },
                  function(isConfirm) {
                    if (isConfirm) {
                      window.location.href = "staff_members.php";
                    }
                  });

              } else if (data.msgType === 3) {
                swal("", "Data Already Exist!", "warning");

              } else {
                swal("Oops...", "Something went wrong!", "warning");
              }
            }, "json");
          } else {
            //swal("Cancelled", "", "error");
          }
        });

    });

    //});

    /**************************** Load Form Data ***********************/

    $(".btn_up").click(function() {
      var id = $(this).val();
      $("#id_up").val(id);

      $.post("function/staff_members_fun.php", {
        get_dataset: "data",
        id: id
      }, function(data) {
        $("#s_name_up").val(data.name);
        $("#desig_up").val(data.designation);
        $("#address_up").val(data.address);
        $("#nic_no_up").val(data.nic_no);
        $("#tel_no_up").val(data.contact_no);
        $("#email_up").val(data.email);

      }, "json");
    });
  </script>
</body>

</html>