<?php
include "db/db.php";
session_start();
$log = htmlspecialchars(trim($_SESSION['user']), ENT_QUOTES, 'UTF-8');
$emp_id = htmlspecialchars(trim($_SESSION['emp_id']), ENT_QUOTES, 'UTF-8');
if (empty($log)) {

  $redirectUrl = "index.php";
  echo "<script type=\"text/javascript\">";
  echo "window.location.href = '$redirectUrl'";
  echo "</script>";
} else {

  $sqlu = "SELECT * FROM details_of_users WHERE user='$log' and val='1'";
  $resultu = mysqli_query($conn, $sqlu);
  $countu = mysqli_num_rows($resultu);

  if ($countu == 1) {

    $sqlc = "SELECT * FROM details_of_users where user='$log'";
    $resultc = mysqli_query($conn, $sqlc);
    while ($rowc = mysqli_fetch_array($resultc)) {
      $name = $rowc['user'];
    }
  } else {
    $redirectUrl = "index.php";
    echo "<script type=\"text/javascript\">";
    echo "window.location.href = '$redirectUrl'";
    echo "</script>";
  }
}
?>
<!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">
  <!-- 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" />

</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>
              <a style="cursor: pointer;" class="btn_order_status">Order Status</a>
            </li>
            <li>
              <a href="http://smsserver.textorigins.com/" target="blank"> SMS </a>
            </li>
            <li>
              <a href="http://smartgsm.lk:2095/" target="blank"> Email </a>
            </li>
            <li>
              <a href="../index"> Website </a>
            </li>
            <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
                    <small></small>
                  </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">
        <!-- Main content -->



        <!-- ==============================1============================= -->

        <div class="row">
          <div class="col-xs-12">
            <h4 class="widget-title lighter smaller"> Sampathbay </h4><br>

            <?php $xx = 1;

            $box = array('bg-blue', 'bg-maroon', 'bg-olive', 'bg-purple', 'bg-orange', 'bg-aqua', ' bg-red', 'bg-yellow', 'bg-green');
            $yy = 0;
            $sql_ct = mysqli_query($conn, "SELECT * FROM user_priv_q WHERE emp_id='$emp_id' AND user='$log' GROUP BY cat_id ORDER BY cat_oid ASC");
            while ($row_ct = mysqli_fetch_array($sql_ct)) {;
              $main_cat = $row_ct['cat_id']; ?>
              <button style="margin-bottom: 10px; text-align: left;" type="button" class="btn btn-block" data-toggle="collapse" data-target="#demo<?php echo $xx; ?>"><?php echo $row_ct['category']; ?> +</button>
              <div id="demo<?php echo $xx; ?>" class="collapse <?php if ($xx == 1) {
                                                                  echo 'in';
                                                                } ?>">
                <?php

                $sql_menu = mysqli_query($conn, "SELECT * FROM user_priv_q WHERE emp_id='$emp_id' AND user='$log' AND cat_id='$main_cat' ORDER BY menu_oid ASC");

                while ($row_menu = mysqli_fetch_array($sql_menu)) { ?>

                  <div class="col-lg-3 col-xs-12">
                    <div class="small-box <?php echo $box[$yy]; ?>">
                      <div class="inner">
                        <h3><?php echo $row_menu['menu']; ?></h3>
                        <p><?php echo $row_menu['menu']; ?></p>
                      </div>
                      <div class="icon">
                        <i class="ion ion-ios-list"></i>
                      </div>
                      <a href="<?php echo $row_menu['url']; ?>?menu=<?php echo $row_menu['menu_id']; ?>" target="_parent" class="small-box-footer">
                        View <i class="fa fa-arrow-circle-right"></i>
                      </a>
                    </div>
                  </div>


                <?php
                  $yy = $yy + 1;

                  if ($yy >= 9) {
                    //echo $yy == 0;
                    /*echo "<script type=\"text/javascript\">";
							echo "alert('$yy')";
							echo "</script>";*/

                    $yy = 0;
                  }
                } ?>
              </div>
            <?php $xx = $xx + 1;
            } ?>
          </div>
        </div>

      </section>
      <!-- /.row -->
    </div><!-- /.row -->
    <!-- ============================1=============================== -->
    <!-- /.col -->

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


  <div class="row">


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

  </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 -->


      </form>
    </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>
  <!-- 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="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.2/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>
  <!-- Page script -->
  <script>
    $(function() {
      //Initialize Select2 Elements
      $(".select2").select2();

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

      //Date range picker
      $('#reservation').daterangepicker();
      //Date range picker with time picker
      $('#reservationtime').daterangepicker({
        timePicker: true,
        timePickerIncrement: 30,
        format: 'MM/DD/YYYY h:mm A'
      });
      //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'), moment().endOf('month')],
            'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
          },
          startDate: moment().subtract(29, 'days'),
          endDate: moment()
        },
        function(start, end) {
          $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.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'
      });

      //Colorpicker
      $(".my-colorpicker1").colorpicker();
      //color picker with addon
      $(".my-colorpicker2").colorpicker();

      //Timepicker
      $(".timepicker").timepicker({
        showInputs: false
      });
    });
  </script>

  <script type="text/javascript">
    $(document).ready(function() {

      $('.btn_order_status').click(function() {
        var row_id = $(this).attr('row_id');
        swal({
          title: "Enter Your Order Number!",
          text: "Order Number:",
          type: "input",
          inputType: "text",
          showCancelButton: true,
          closeOnConfirm: false,
          inputPlaceholder: "Password......"
        }, function(inputValue) {

          if (inputValue === false) return false;

          if (inputValue != "") {
            //alert(inputValue);
            $.post('../connection/order_status_fun.php', {
              'order_status_fun': 'data',
              inv_no: inputValue
            }, function(e) {

              //alert(e.order_status);
              if (e.order_status == 0) {
                swal("Pending!", "Your order is pending for the administration action", "warning");
              }
              if (e.order_status == 1) {
                swal("Accepted!", "Your order has been Accepted! Shipping progress on going :) ", "success");
              }
              if (e.order_status == 2) {
                swal("Rejected!", "Your order has been Rejected!", "error");
              }
              if (e.order_status == 3) {
                swal("Shipped!", "Your order has been Shipped!", "success");
              }
              if (e.order_status == 4) {
                swal("Receiver Accepted!", "Your order has been Accepted by order recipient!", "success");
              }
              if (e.order_status == 5) {
                swal("Not Reachable!", "Order Recipient has not reachable", "warning");
              }
              if (e.order_status == 6) {
                swal("Receiver Rejected!", "Your order has been Rejected by order recipient!", "error");
              }
              if (e.order_status == 'error') {
                swal("Oops!", "Something is wrong with your Order Number", "warning");
              }
            }, "json");
          }

          if (inputValue === "") {
            swal.showInputError("You need to write something!");
            return false;
          }
          //swal("Nice!", "You wrote: " + inputValue, "success");
        });

      });

    });
  </script>
</body>

</html>