<?php session_start();

require_once __DIR__."/includes/headerincludes.php";
require_once __DIR__."/includes/dbconfig.php";
require_once __DIR__."/functions/allfunctions.php";



if(empty($_SESSION["itemarrayinventory"]))
{
    $itemarray = array();
}
else
{
  $itemarray = $_SESSION["itemarrayinventory"];
}

if(empty($_SESSION["MEMBER_ID"]) && empty($_SESSION["TYPE"]) && empty($_SESSION["DEPT"]) && empty($_SESSION["FIRST_NAME"]) && empty($_SESSION["ACCESS_TYPE"]))
{
  $itemarray = array();
  $memberid = "";
  $type = "";
  $firstname = "";
  $dept = "";
  $accesstype = "";
}
else
{
  $memberid = $_SESSION['MEMBER_ID'];
  $type = $_SESSION['TYPE'];
  $firstname = $_SESSION['FIRST_NAME'];
  $dept = $_SESSION['DEPT'];
  $accesstype = $_SESSION['ACCESS_TYPE'];


}




//before we store information of our member, we need to start first the session


	//create a new function to check if the session variable member_id is on set
	function logged_in() {
		return isset($_SESSION['MEMBER_ID']);

	}
	//this function if session member is not set then it will be redirected to index.php
	function confirm_logged_in() {
		if (!logged_in()) {

?>
			<script type="text/javascript">
				window.location = "pages/login.php";
			</script>
<?php
		}
	}
	confirm_logged_in();

if($type != "Admin")
{
?>
<script type="text/javascript">
  window.location = "index.php";
</script>

<?php
}
?>
<!DOCTYPE html>
<head>
    <title>GBG Enterprise - Dashboard</title>

</head>

      <body id="page-top">

    <!-- Page Wrapper -->
    <div id="wrapper">

        <!-- Sidebar -->
        <ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" id="accordionSidebar">

            <!-- Sidebar - Brand -->
            <a class="sidebar-brand d-flex align-items-center justify-content-center" href="index.php">
                <div class="sidebar-brand-icon">
                    <img src="img/gbg.jpg" alt="Company Logo" class="img-thumbnail">
                </div>
                <div class="sidebar-brand-text mx-3">GBG Enterprise</div>
            </a>

            <!-- Divider -->
            <hr class="sidebar-divider my-0">

            <!-- Nav Item - Dashboard -->
            <li class="nav-item active">
                <a class="nav-link" href="index.php">
                    <i class="fas fa-fw fa-tachometer-alt"></i>
                    <span>Dashboard</span></a>
            </li>



            <!-- Nav Item - Pages Collapse Menu -->
            <?php echo sidebar(); ?>


            <!-- Divider -->
       <!--     <hr class="sidebar-divider">-->



            <!-- Divider -->
            <hr class="sidebar-divider d-none d-md-block">



        </ul>
        <!-- End of Sidebar -->

        <!-- Content Wrapper -->
        <div id="content-wrapper" class="d-flex flex-column">

            <!-- Main Content -->
            <div id="content">

                <!-- Topbar -->
                <nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">

                    <!-- Sidebar Toggle (Topbar) -->
                    <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
                        <i class="fa fa-bars"></i>
                    </button>


                    <!-- Topbar Navbar -->
                    <ul class="navbar-nav ml-auto">




                        <!-- Nav Item - User Information -->
                       <?php echo logindetails(); ?>

                    </ul>

                </nav>
                <!-- End of Topbar -->

                <!-- Begin Page Content -->
                <div class="container-fluid">


                    <!-- Content Row -->
                    <div class="row gy-5">



				<!--Image Content Row -->

						<div class="row gy-5">
							<div class="col-lg-12">
								<div class="card border-left-info shadow h-100 py-2">
									<div class="card-body">
										<div class="row no-gutters align-items-center">
											<div class="col mr-2">
												<div class="text-sm font-weight-bold text-info text-uppercase mb-4">Sytem Backup and Restore</div>
												<div class="row  align-items-center">
													<div class="card-body">


                            <div class="form-group row bagform1 ">
                                        <div class="col-sm-3">
                                          <p>BACKUP:</p>
                                        </div>
                                        <div class="col-sm-3">
                                          <p class="h5 custemail">
                                             <button type="button" class="btn btn-success btn-sm  submitbackup">Backup</button>
                                          </p>
                                        </div>



                          </div>


                          <div class="form-group row bagform1 ">

                                      <div class="col-sm-3">
                                        <p>Restore:</p>
                                      </div>
                                      <div class="col-sm-5">
                                        <p class="h5 custemail">
                                        <!--    <input type="text" class="form-control dbname" name="dbname" required  placeholder="Enter Database Name" aria-label="Product color" aria-describedby="basic-addon2" value="" > -->
                                                                                                  <select name="dbname" class="dbname">
                                                                <option value="" selected="selected">-----</option>
                                                            <?php
                                                                 foreach(glob(dirname(__FILE__) . '/backup/*') as $filename){
                                                                 $filename = basename($filename);
                                                                 echo "<option value='" . $filename . "'>".$filename."</option>";
                                                              }
                                                          ?>

                                                          </select>
                                        </p>
                                      </div>
                                      <div class="col-sm-2">
                                        <p class="h5 custemail">

                                           <button type="button" class="btn btn-success btn-sm  submitrestore">Restore</button>
                                        </p>
                                      </div>



                        </div>
														</div>



													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
					</div>




                <!-- /.container-fluid -->

            </div>
            <!-- End of Main Content -->

            <!-- Footer -->
            <footer class="sticky-footer bg-white">
                <div class="container my-auto ">
                    <div class="copyright text-center my-auto">
                        <span>Copyright &copy; GBG 2020</span>
                    </div>
                </div>
            </footer>
            <!-- End of Footer -->

        </div>
        <!-- End of Content Wrapper -->

    </div>
    <!-- End of Page Wrapper -->

    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
        <i class="fas fa-angle-up"></i>
    </a>

   <!-- Logout Modal-->
   <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
        aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
                <div class="modal-footer">
                    <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                    <a class="btn btn-primary" href="../gbgv2/destroy.php">Logout</a>
                </div>
            </div>
        </div>
    </div>




    <div class="modal fade" id="DisableAccModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
         aria-hidden="true">
         <div class="modal-dialog" role="document">
             <div class="modal-content">
                 <div class="modal-header">
                     <h5 class="modal-title" id="exampleModalLabel">Reject</h5>
                     <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                         <span aria-hidden="true">×</span>
                     </button>
                 </div>
                 <div class="modal-body">Are you sure you want to deactivate this account?</div>
                 <div class="modal-footer">
 			<!-- 	<form class="user rejectdata" name="rejectdata"  id="rejectdata"> -->
 			<!--			<textarea class="form-control reason" id="reason" rows="3"></textarea> -->
 					<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
 					 <input class="useridval" type="hidden" id="useridval" name="useridval" value="<?php echo $qid; ?>">
                     <button type="button" class="btn btn-primary deactivateuseracc" href="#" >Deactivate</button>

                 </div>
             </div>
         </div>
     </div>




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








          $('.min').datepicker({
                   autoHide: true,
                       format: "yyyy-mm-dd"

                   });
          $('.max').datepicker({
                 autoHide: true,
                     format: "yyyy-mm-dd"

                 });

          $('.min, .max').change(function () {
                  table.draw();

                 });

                 $( ".min" ).keyup(function() {
                   //alert( "Handler for .keyup() called." );
                   table.draw();
                 });

                 $( ".max" ).keyup(function() {
                   //alert( "Handler for .keyup() called." );
                   table.draw();
                 });


                 $.fn.dataTable.ext.search.push(
                     function (settings, data, dataIndex) {
                         var min = $('.min').val();
                         var max = $('.max').val();
                         //alert(min);
                         //alert(max);
                         //var startDate = new Date(data[0]);
                         if ( settings.nTable.id !== 'PaymentDataTable' ) {
                           return true;
                         }
                         var startDate = data[1];
                         //alert(startDate);
                         if (min == "" && max == "") {  return true; }
                         if (min == "" && startDate <= max) {   return true;}
                         if(max == "" && startDate >= min) {  return true;}
                         if (startDate <= max && startDate >= min) { return true; }
                         return false;

                     }
                 );

   $('.submitbackup').on('click', function(){
     var arr = $('.dbname :selected').text();



var datastring = "";
datastring = datastring + "checklistdata="+arr;
//alert(datastring);




      $.ajax({
       type: "GET",
       url: "backup.php",
       data: datastring,
       success: function (data) {
           //alert("Payment Status Updated");
           window.location = "system.php";
           alert(data);
       }
     });


});


$('.submitrestore').on('click', function(){
   var arr = $('.dbname :selected').text();

//alert(arr);

var datastring = "";
datastring = datastring + "dbname="+arr;
//alert(datastring);




   $.ajax({
    type: "GET",
    url: "restore.php",
    data: datastring,
    success: function (data) {
        //alert("Payment Status Updated");
        window.location = "system.php";
        alert(data);
    }
  });


});



});
</script>


  </body>
</html>
