<?php
session_start();
include("config.php"); 
include("encryption.php");

if (isset($_SESSION["loginToken"])) {
    $token = decrypt($_SESSION["loginToken"]);
    $query1 = "SELECT * FROM `tbl_qisysconnect` WHERE `token` = '$token'";
	$result1 = $con->query($query1);
	$count = mysqli_num_rows($result1);
	if($count == 0){
	    header('Location:index.php');
	    exit();
	}
}else{
    header('Location:index.php');
	exit();
}

$get_all_date = mysqli_query($con,"SELECT * FROM tbl_login");
$get_all_date_num = mysqli_num_rows($get_all_date);
$date = date("Y-m-d");
$date=date("Y-m-d", strtotime($date. ' +1 day'));

if ($get_all_date_num > 0) {
  while ($row = mysqli_fetch_assoc($get_all_date)) {
    $id = $row['Usr_id']; 
    $expire_date= $row['expDate'];
    $update_status = mysqli_query($con,"UPDATE tbl_login SET status='Deactive' WHERE DATE(expDate) < '$date' AND Usr_id='$id'");
  }
}

$get_all_date2 = mysqli_query($con,"SELECT * FROM tbl_login2");
$get_all_date_num2 = mysqli_num_rows($get_all_date2);
if ($get_all_date_num2 > 0) {
  while ($row2 = mysqli_fetch_assoc($get_all_date2)) {
    $id2 = $row['Usr_id'];
    $expire_date2= $row2['expDate'];
    $update_status2 = mysqli_query($con,"UPDATE tbl_login2 SET status='Deactive' WHERE DATE(expDate) < '$date' AND Usr_id='$id2'");
  }
}

// $get_all_date3 = mysqli_query($con,"SELECT * FROM tbl_login3");
// $get_all_date_num3 = mysqli_num_rows($get_all_date3);
// if ($get_all_date_num3 > 0) {
//   while ($row3 = mysqli_fetch_assoc($get_all_date3)) {
//     $id3 = $row3['Usr_id'];
//     $expire_date3= $row['expDate'];
//     $update_status3 = mysqli_query($con,"UPDATE tbl_login3 SET status='Deactive' WHERE DATE(expDate) < '$date' AND Usr_id='$id3'");
//   }
// }
// session_start(); 
// if (!$_SESSION['superadmin']) {
//   header('location:index.php');
// }
?>
<!DOCTYPE html>
<style type="text/css">
</style>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>SUPER ADMIN</title>
  <!-- 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.7 -->
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.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">

   <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
   <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->

<!-- Google Font -->
<!-- <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic"> -->
<link href="https://fonts.googleapis.com/css?family=PT+Serif&display=swap" rel="stylesheet">
<style type="text/css">
  body{
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 14px;
  }
  li{
    font-size: 13px!important;
  }
</style>
</head>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
<body class="hold-transition skin-blue sidebar-mini">
  <div class="wrapper">

    <header class="main-header">
      <!-- Logo -->
      <a href="dashboard.php" class="logo">
        <!-- mini logo for sidebar mini 50x50 pixels -->
        <span class="logo-mini"><b>PUMP</b></span>
        <!-- logo for regular state and mobile devices -->
        <span class="logo-lg"><b>Pump Manager</b></span>
      </a>
      <!-- Header Navbar: style can be found in header.less -->
      <nav class="navbar navbar-static-top">
        <!-- Sidebar toggle button-->
        <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </a>

        <div class="navbar-custom-menu">
          <ul class="nav navbar-nav">
            
            <li>  <a href=""><?php $date = date('d-M-Y'); 
            $day = date('l');
            echo $day.'&nbsp;'.$date;?></a></li>
            <li class="dropdown user user-menu">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                <img src="dist/img/qi.png" class="user-image" alt="User Image">
                <span class="hidden-xs">Super Admin</span>
              </a>
              <ul class="dropdown-menu">
                <!-- User image -->
                <li class="user-header">
                  <img src="dist/img/qi.png" class="" alt="User Image">

                  <p>
                    Super Admin
                    <small>Member since Nov. 2019</small>
                  </p>
                </li>
                <!-- Menu Body -->

                <!-- Menu Footer-->
                <li class="user-footer">
                  <!--<div class="pull-left">-->
                  <!--  <a href="#" class="btn btn-default btn-flat">Profile</a>-->
                  <!--</div>-->
                  <div class="pull-right">
                    <a href="logout.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>

    <aside class="main-sidebar">
      <section class="sidebar">
        <form action="#" method="get" class="sidebar-form">
          <div class="input-group">
            <input type="text" name="q" class="form-control" placeholder="Search...">
            <span class="input-group-btn">
              <button type="submit" name="search" id="search-btn" class="btn btn-flat"><i class="fa fa-search"></i>
              </button>
            </span>
          </div>
        </form>
        <ul class="sidebar-menu" data-widget="tree">
          <li><a href="data.php"><i class="fa fa-circle-o text-aqua"></i>CLIENT DATA</a></li>
          <!--<li><a href="data2.php"><i class="fa fa-circle-o text-red"></i>24 HR CLIENT DATA</a></li>-->
          <!-- <li><a href="data3.php"><i class="fa fa-circle-o text-green"></i>CREDIT CLIENT DATA</a></li> -->
          <li><a href="clientdatabase.php"><i class="fa fa-circle-o text-aqua"></i>CLIENT DATABASE</a></li>
          <!--<li><a href="clientdatabase2.php"><i class="fa fa-circle-o text-red"></i>24 HR CLIENT DATABASE</a></li>-->
          <!-- <li><a href="clientdatabase3.php"><i class="fa fa-circle-o text-green"></i>CREDIT CLIENT DATABASE</a></li> -->
          <li><a href="feature.php"><i class="fa fa-circle-o text-yellow"></i>FEATURES</a></li>
          <!--<li><a href="clientpermission.php"><i class="fa fa-circle-o text-gray"></i>CLIENT PERMISSION</a></li>-->
          <li><a href="run-query.php"><i class="fa fa-circle-o text-blue"></i>RUN QUERRY</a></li>
          <li><a href="flushdata.php"><i class="fa fa-circle-o text-red"></i>FLUSH DATA</a></li>
        </ul>
      </aside>