<?php    include_once('../config/db.php');  include_once('../config/check.php'); 

if (filter_has_var(INPUT_POST, "submit")) 
  try{    
          
          $date =                        htmlspecialchars (strtoupper($_POST['date']));
          $date =                        date("Y-m-d", strtotime($date));
          $user =                        htmlspecialchars ( strtoupper($_POST['user']));     
          $branch =                       htmlspecialchars ( strtoupper($_POST['branch']));              
                                  
          $sql = 'INSERT INTO sys_user_guard(date,user,branch,uid) VALUES (:date,:user,:branch,:uid)';
          $stmt = $conn->prepare($sql)->execute(['date'=> $date,'user'=>$user,'branch'=>$branch,'uid'=>$uid  ]);

          header("location:userlink.php");                                   
      } catch(Exception $e) { echo 'Message: ' .$e->getMessage();}

?>

<!DOCTYPE html>
<html>
<head>
<?php include_once('../inc/slink.php');   ?>  
</head>
<body  <?php include_once('../inc/snav.php');   ?> 
<div class="wrapper">

  <!-- Main Header -->
    <header class="main-header">

    <!-- Logo -->
       <?php include_once('../inc/sbrand.php');   ?>

    <!-- Header Navbar -->
    <?php include_once('../inc/snavbar.php');   ?>

  </header>
 
  <!-- Left side column. contains the logo and sidebar -->
    <aside class="main-sidebar">

    <!-- sidebar: style can be found in sidebar.less -->
     <?php include_once('../inc/smenuc.php');   ?>
    <!-- /.sidebar -->
  </aside>

  <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
       <section class="content-header" >
       
         <p style="color:green; font-size:20px;font-weight:bold; " > <i class="fa fa-chain" ></i> Link Users </p>
         
         <ol class="breadcrumb">
          
          <!-- <li> <a href="#" > <button class="btn  btn-sm btn-default " > <i class="fa fa-user-plus "></i> VIEW ALL BUSINESS PARTNER </button>    </a></li> -->
                   
        </ol>
      </section>



        <section class="content container-fluid" style="padding-top:0px;" >
            <div class="box box-success box-xs">
                <div class="box-body">
                    <div class="row">
                        <form class="form-horizontal "  action="" method="post"  >
                                                                                                   
                                            <div class="col-sm-3">
                                                <label> Date   </label>
                                                <input type="text" class="form-control datepicker" name="date"   autocomplete="off">
                                            </div> 
                                            <div class="col-sm-3">
                                                <label> Select Users   </label>
                                                <select class="form-control js-example-basic-single"  required=""  name="user"  >
                                                  <?php $stmt = $conn->prepare("SELECT * FROM sys_user  ");
                                                  $stmt->execute(); foreach ($stmt as $row) {?>
                                                       <option> </option>
                                                     <option value="<?php echo $row['id']; ?>"><?php
                                                        echo $row['fname'].''.$row['mname'].''.$row['lname'] ; ?></option> <?php } ?>
                                                </select>
                                            </div> 
                                            <div class="col-sm-3">
                                                <label> Select Shops/Store   </label>
                                                <select class="form-control js-example-basic-single"  required=""  name="branch"  >
                                                  <?php $stmt = $conn->prepare("SELECT * FROM admbranch ");
                                                  $stmt->execute(); foreach ($stmt as $row) {?>
                                                       <option> </option>
                                                     <option value="<?php echo $row['id']; ?>"><?php
                                                        echo $row['name']; ?></option> <?php } ?>
                                                </select>
                                            </div> 
                                                                                        
                                           
                                            <!-- submit button -->
                                            <div class="col-md-3">
                                    
                                              <div class="form-group"  style="padding:2rem;" >                              
                                                  <!-- <div class=" col-sm-10" style="padding:0.5rem;"> -->
                                                          <button type="submit"  name="submit" class="btn btn-md btn-success btn-block "  >  <i class="fa fa-user-plus"></i>  Link users  </button>
                                                         <!-- </div> -->
                                              </div> 
                                            </div>
                        </form>
                    </div>
                </div>
            </div>

             
            <div class="box box-success box-xs">
                <div class="box-body">
                    <div class="row">
                        <div class="col-md-12">
                          <table id="customer_data" class="table display compact  table-condesed table-small table-responsive ">
                                      <thead>
                                          <tr style="height: 0px;" class="bg-default" >                  
                                          <th >  </th>                    
                                          <th > Date  </th>                    
                                          <th > Full Name</th>
                                          <th > Username   </th>                
                                          <th > Shop/store  </th>
                                          <!-- <th > Status </th> -->
                                          </tr>
                                      </thead>
                          </table>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Bank Reconcile 
        <section  >
        <div class="box box-default box-xs">
            <div class="box-body">
                <div class="row">           
                                                            
                            <div class="box-body">                                                              
                                  
                                    
                            </div>
                        
                </div>
            </div>
        </div>
        </section>
           End Bank reconcile -->



    </div>
  <!-- /.content-wrapper -->
  
    <!-- Main Footer -->
    <footer class="main-footer">
        <?php  include_once('../inc/sfooter.php'); ?>
    </footer>
  
</div>
                         


<!-- REQUIRED JS SCRIPTS -->
<?php include_once('../inc/slinkjs.php') ?>

</body>
</html>

<script type="text/javascript" language="javascript" >

 
$('#customer_data').DataTable( {
    
    pageLength : 5,
    ajax: {
        url: '../filter/company/linkuser.php'
    }
} );

codeListTable = $("#customer_data").DataTable();
        new $.fn.dataTable.Buttons( codeListTable, {
            buttons: [
          
                {
                extend:    'excel',
                text:      '<i class="fa fa-files-o"></i> Excel',
                titleAttr: 'Excel',
                className: 'btn btn-default btn-sm',
                exportOptions: {
                    columns: ':visible'
                }
                },
                {
                extend:    'pdf',
                text:      '<i class="fa fa-file-pdf-o"></i> PDF',
                titleAttr: 'PDF',
                className: 'btn btn-default btn-sm',
                exportOptions: {
                    columns: ':visible'
                }
                },               
                {
                extend:    'print',
                text:      '<i class="fa fa-print"></i> Print',
                titleAttr: 'Print',
                className: 'btn btn-default btn-sm',
                exportOptions: {
                    columns: ':visible'
                }
                },  
            ]
        } );
        codeListTable.buttons().container().appendTo('#mybtn');    
        // $(".dataTables_filter").detach().appendTo("#mysearchbox");
        // $(".dataTables_length").detach().appendTo("#mylength");

</script>
