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

          $branch =                      htmlspecialchars ( strtoupper($_POST['branch']));     
          $region =                      htmlspecialchars ( strtoupper($_POST['region']));     
          $payrollcountry =              htmlspecialchars ( strtoupper($_POST['payrollcountry']));     
          $name =                        htmlspecialchars ( strtoupper($_POST['name']));     
          $code =                        htmlspecialchars ( strtoupper($_POST['code']));           
          $description =                 htmlspecialchars ( strtoupper($_POST['description']));          
                          
          $sql = 'INSERT INTO admcentre (date,branch,region,payrollcountry,name,code,description,uid) VALUES (:date,:branch,:region,:payrollcountry,:name,:code,:description,:uid)';
          $stmt = $conn->prepare($sql)->execute(['date'=> $date,'branch'=> $branch,'region'=> $region,'payrollcountry'=> $payrollcountry,'name'=>$name,'code'=>$code,'description'=>$description ,'uid'=>$uid  ]);

          header("location:admcentre.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-user-plus" ></i> Add Centers/Projects </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="">
                                                       
                                             
                                            <div class="col-sm-2">
                                                <label> Date   </label>
                                                <input type="text" class="form-control datepicker" name="date"   autocomplete="off">
                                            </div> 
                                            <div class="col-sm-2">
                                                <label> Select Branch   </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> 
                                            <div class="col-sm-2">
                                                <label> Select Region   </label>
                                                <select class="form-control js-example-basic-single "  required=""  name="region"  >
                                                  <?php $stmt = $conn->prepare("SELECT * FROM admregion ");
                                                  $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> Select payroll used   </label>
                                                <select class="form-control js-example-basic-single "  required=""  name="payrollcountry" >
                                                  <?php $stmt = $conn->prepare("SELECT * FROM payrollcountry ");
                                                  $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> Name   </label>
                                                <input type="text" class="form-control " name="name"   autocomplete="off">
                                            </div> 
                                            <div class="col-sm-2">
                                                <label> Code   </label>
                                                <input type="text" class="form-control " name="code"   autocomplete="off">
                                            </div> 
                                           
                                            <div class="col-sm-12">
                                                <label> Description  </label>
                                                <textarea  class="form-control " name="description"   autocomplete="off" ></textarea>
                                                
                                            </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">  <i class="fa fa-user-plus"></i>  Add Centre </button> </div>
                                </div> 
                        </form>
                    </div>
                </div>
            </div>

        </section>
    </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>
