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



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

            $staffnum =              htmlspecialchars ( $_POST['staffnum']);
            $name =                  htmlspecialchars ( $_POST['name']);
            $idno =                  htmlspecialchars ( $_POST['idno']);
            $phone =                 htmlspecialchars ( $_POST['phone']);
            $email =                 htmlspecialchars ( $_POST['email']);
            $department =            htmlspecialchars ( $_POST['department']);
            $address =               htmlspecialchars ( $_POST['address']);
            
$sql = 'INSERT INTO crmsagent (empdate,staffnum,name,idno,phone,email,department,address) VALUES(:empdate,:staffnum,:name,:idno,:phone,:email,:dep,:address )';
$conn->prepare($sql)->execute([  'empdate' => $empdate,'staffnum' => $staffnum,'name' => $name , 'idno' => $idno,'phone' => $phone ,'email' => $email , 'dep' => $department,'address'=>$address    ]);

        header("location:crmsagent.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/smenu.php');   ?>
    <!-- /.sidebar -->
  </aside>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">

    <section class="content-header">
      <h1>  <i class="fa fa-plus-circle" >  </i> Add Sales Agent   </h1>
        <ol class="breadcrumb">
          <li><a href="#"><i class="fa fa-dashboard"></i> </a></li>
          <li><a href="#"> </a></li>
          <li class="active"> </li>
          <li><a href="crmsagentl.php" class="btn btn-default btn-sm"> <i class="fa fa-bars"></i> View All Sales Order </a></li>
        </ol>
    </section>


  <section class="content container-fluid"> 
        <div class="box box-success box-xs">
            <div class="box-body">
                <div class="row">
                <form class="form-horizontal add_form "  action="" method="post"  >
                                     <div class="col-sm-12">                       
                                            <div class="col-sm-3"> 
                                                <label > Date  </label>  
                                                <input type="date"   autocomplete="off" class="form-control datepicker" name="empdate"   required=""   > 
                                            </div>                                             
                                            <div class="col-sm-3"> 
                                                <label > Staff/Payroll Number  </label>  
                                                    <input type="text"  name="staffnum" value="" autocomplete="off" class="form-control"   required=""   > 
                                            </div> 
                                                                                                    
                                            <div class="col-md-6">
                                                <label > Sales Agent Name  </label>                          
                                                <input type="text" class="form-control" name="name" required="" autocomplete="off" >
                                            </div> 
                                    </div>                           
                                        
                                    <div class="col-md-12"> 
                                        <div class="col-sm-3"> 
                                           <label > ID / Passport Number  </label>  
                                              <input type="text"  name="idno"  autocomplete="off" class="form-control"   required=""   > 
                                        </div>                                                           
                                        <div class="col-sm-3"> 
                                                <label > Phone </label>  
                                                <input type="text" class="form-control" name="phone"   required="" autocomplete="off"> 
                                        </div>                                    
                                        <div class="col-sm-6">   
                                                <div class="">
                                                <label class=""> Email </label>              
                                                    <input type="email" class="form-control " name="email"  autocomplete="off">
                                                </div>
                                        </div>
                                    </div>
                                 
                                     <div class="col-md-12">
                                             

                                             <div class="col-sm-3"> 
                                               <label > Department </label>  
                                                    <select class="form-control   "  required="" name="department" style="width:100%" >
                                                        <?php $stmt = $conn->prepare("SELECT * FROM hrdepartment  ");
                                                        $stmt->execute(); foreach ($stmt as $row) {?>
                                                                
                                                                <option value="<?php echo $row['id']; ?>"><?php
                                                                    echo $row['name']; ?></option> <?php } ?>
                                                    </select>                                         
                                             </div>                                        
                                             <div class="col-sm-6">   
                                                 <div class="">
                                                    <label class=""> Address </label>              
                                                       <input type="text" class="form-control " name="address"  required="" autocomplete="off">
                                                  </div>
                                             </div>
                                     </div>  

                            <!-- submit button -->
                            <div class="form-group">                              
                                <div class="col-sm-offset-4 col-sm-10" style="padding:0.5rem;">
                                        <button type="submit"  name="submit" class="btn btn-success col-md-3">  <i class="fa fa-plus"></i>  Add Sales Agent  </button> </div>
                            </div> 
                    </form>               

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

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

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

</body>
</html>