<?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));

          
      $group_id =                htmlspecialchars ( $_POST['group']);  
      $name =                htmlspecialchars ( $_POST['name']);     
           
      $system_id =               htmlspecialchars ( strtoupper($_POST['systemid']));
      $client_id =               htmlspecialchars ( strtoupper($_POST['nationalid']));
      $currency =               htmlspecialchars ( strtoupper($_POST['currency']));
      $phone =               htmlspecialchars ( strtoupper($_POST['phone']));
      $email =               htmlspecialchars ( $_POST['email']);

      $branch =              htmlspecialchars  ( $_POST['branch']);
      $website =             htmlspecialchars  ( $_POST['website']);
      $address =             htmlspecialchars ( $_POST['address']);
      $location =            htmlspecialchars ( $_POST['location']);
     
                   
      $sql = 'INSERT INTO clients (group_id,name,phone,email,address,system_id,client_id )  
                          VALUES (:group_id,:name,:phone,:email,:address,:system_id,:client_id )';
      $stmt = $conn->prepare($sql)->execute([ 'group_id'=>$group_id,'name'=>$name,'phone'=>$phone,
       'email'=>$email,'address'=>$address,'system_id'=> $system_id,'client_id'=>$client_id
                                  ]);

                                              $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-file-o" ></i> Add Client </p>
     
         <ol class="breadcrumb">
          
          <li> <a href="allclient" > <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> Group   </label>
                                                <select class="form-control js-example-basic-single   "  required=""  name="group"  >
                                                  <?php $stmt = $conn->prepare("SELECT * FROM groups   ");
                                                  $stmt->execute(); foreach ($stmt as $row) {?>
                                                       <option> </option>
                                                     <option value="<?php echo $row['id']; ?>"><?php
                                                        echo $row['name']; ?></option> <?php } ?>
                                                </select>
                                            </div>   
                                            
                                            <!-- <div class="col-sm-2">
                                                <label> Date    </label>
                                                <input type="text" class="form-control datepicker" name="date"   autocomplete="off">
                                            </div>                   -->
                                                               
                                            <div class="col-sm-6">
                                                <label> Client_Full_Name    </label>
                                                <input type="text" class="form-control " name="name"   autocomplete="off">
                                            </div>                    

                                           <div class="col-sm-3">
                                                <label> System ID </label>
                                                <input type="text" class="form-control " name="systemid"  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 Client  </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>