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

   $storeID =  $_SESSION['storeid'] ;


if (filter_has_var(INPUT_POST, "submit")) 
try{    
       $date =            htmlspecialchars (strtoupper($_POST['date']));
       $date =            date("Y-m-d", strtotime($date));

        // $branch_id =                htmlspecialchars ( $_POST['branch_id']);  
        // $group_id =                htmlspecialchars ( $_POST['group']);  
       $fname =                     htmlspecialchars ( $_POST['fname']);   
       $mname =                     htmlspecialchars ( $_POST['mname']);   
       $lname =                     htmlspecialchars ( $_POST['lname']);  
       $idno =                      htmlspecialchars ( $_POST['idno']);   
       $phone =                     htmlspecialchars ( $_POST['phone']); 
       $email =                     htmlspecialchars ( $_POST['email']); 
           
     
      $sql = 'INSERT INTO clients(date,fname,mname,lname,idno,phone,email,uid )  
                          VALUES(:date,:fname,:mname,:lname,:idno,:phone,:email,:uid )';
      $stmt = $conn->prepare($sql)->execute([ 'date'=>$date,'fname'=>$fname,'mname'=>$mname,'lname'=>$lname,
                                              'idno'=>$idno,'phone'=>$phone,'email'=>$email,'uid'=>$uid ]);

                                              $inserted = $conn->lastInsertId(); 
                                              
                                              if($inserted>0)
                                                 {
                                                    $msg = true;
                                                  // $Lerror='<div class="alert alert-success alert-dismissable" style="margin-top:5px;"><i class="fa fa-key"></i><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><b> Customer added Succefully  </b></div>';  
                                                   
                                                  }else
                                                   {
                                                     header("location:client.php");
                                                  }
     

       
             if(isset($msg))
            {
             
                $_SESSION['message'] = "Successfully Added";
                header('Location:client.php');
                exit(0);
            }
            else
            {
                $_SESSION['message'] = "Not Imported";
                header('Location:client.php');
                exit(0);
            }

  
  } 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/smenu.php');   ?>
    <!-- /.sidebar -->
  </aside>

  <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
       <section class="content-header" >
       
         <p  class="listheader"  > <i class="fa fa-user-plus " ></i> Add Visitor </p>
     
         <ol class="breadcrumb">
          
          <li> <a href="client" > <button class="btn  btn-sm btn-default " > <i class="fa fa-bars "></i> VIEW ALL CUSTOMERS </button>    </a></li>
                   
        </ol>
      </section>



        <section class="content container-fluid" style="padding-top:0px;" >
            <div class="box box-default box-xs">
                <div class="box-body">

                <div>
                         <?php
                         if(isset($_SESSION['message']))
                         { 
                         ?>

                         <div class="alert alert-success alert-dismissible">                         
                              <h4><i class="icon fa fa-check"></i> <?php echo $_SESSION['message'];  unset($_SESSION['message']);  ?>  </h4>
                                   
                         </div>

                       <?php }  ?>
                    </div>

                        <form class="form-horizontal "  action="" method="post"  >
                                <div class="">
                                              
                                            <div class="col-sm-3">
                                                <label> Date   </label>
                                                 <input type="text"   autocomplete="off" class="form-control datepicker" name="date"   required=""   > 
                 
                                                <!-- <input type="text" class="form-control " name="name"   autocomplete="off"> -->
                                            </div>   
                                            <div class="col-sm-3">
                                                <label> First Name    </label>
                                                <input type="text" class="form-control " name="fname"   autocomplete="off">
                                            </div>    
                                            <div class="col-sm-3">
                                                <label> Middle Name    </label>
                                                <input type="text" class="form-control " name="mname"   autocomplete="off">
                                            </div>   
                                            <div class="col-sm-3">
                                                <label> Last Name    </label>
                                                <input type="text" class="form-control " name="lname"   autocomplete="off">
                                            </div>               

                                           <div class="col-sm-3">
                                                <label> ID/Passport No </label>
                                                <input type="text" class="form-control " name="idno"  autocomplete="off">   
                                            </div>
                                            <div class="col-sm-3">
                                                <label> Phone number </label>
                                                <input type="text" class="form-control " name="phone"  autocomplete="off">   
                                            </div>
                                            <div class="col-sm-3">
                                                <label> Email Address </label>
                                                <input type="text" class="form-control " name="email"  autocomplete="off">   
                                            </div>
                                              <!-- <div class="col-sm-3">
                                                  <label> National ID </label>
                                                  <input type="text" class="form-control " name="nationalid"  autocomplete="off">   
                                              </div> -->
                                                                                       
                                            <!-- <div class="col-sm-3">
                                                <label> Address  </label>
                                                <input type="text" class="form-control " name="address"  autocomplete="off">   
                                            </div>
                                            <div class="col-sm-3">
                                                <label> Location  </label>
                                                <input type="text" class="form-control " name="location"  autocomplete="off">   
                                            </div> -->
                                            
                                        
                                </div>
                        <!-- submit button -->
                                <div class="form-group">                              
                                    <div class="col-sm-offset-4 col-sm-10" style="padding:2rem;">
                                            <button type="submit"  name="submit" class="btn btn-success col-md-3 subbtn">  <i class="fa fa-user-plus"></i>  Add Visitors  </button> </div>
                                </div> 
                        </form>
                </div>
            </div>

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


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

</body>
</html>

<script>
  
  setInterval(function(){ $(".alert").fadeOut(); }, 1000);


</script>