<?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));
        
            $name =                   htmlspecialchars ( $_POST['name']);
            $code =                   htmlspecialchars ( $_POST['code']);
            $address =                htmlspecialchars ( $_POST['address']);
            $location =               htmlspecialchars ( $_POST['location']);
            $phone =                  htmlspecialchars ( $_POST['phone']);
            $email =                  htmlspecialchars ( $_POST['email']);
            // $email =                  htmlspecialchars ( $_POST['status']);

            $sql = 'INSERT INTO branches(name,code,location,address,phone,email) 
                                   VALUES (:name,:code,:location,:address,:phone,:email )';
            $conn->prepare($sql)->execute([ 'name' => $name,'code'=>$code,'location'=>$location,
                                            'address'=>$address,'phone'=>$phone,'email'=>$email ]);
            header("location:branch.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" class="listheader" >  </i> Add Branch   </h1>
        <ol class="breadcrumb">
               </ol>
    </section>

    <section class="content container-fluid"> 
        <div class="box box-default 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"   autocomplete="off" class="form-control datepicker" name="date"   required=""   > 
                                        </div>                                             
                                                                                                                                        
                                        <div class="col-md-6">
                                            <label > Name  </label>                          
                                            <input type="text" class="form-control" name="name" required="" autocomplete="off" >
                                        </div> 
                                        <div class="col-md-3">
                                            <label > Code  </label>                          
                                            <input type="text" class="form-control" name="code" required="" autocomplete="off" >
                                        </div> 
                                        <div class="col-md-3">
                                            <label > Location  </label>                          
                                            <input type="text" class="form-control" name="location" required="" autocomplete="off" >
                                        </div> 
                                        <div class="col-md-3">
                                            <label > Address  </label>                          
                                            <input type="text" class="form-control" name="address" required="" autocomplete="off" >
                                        </div> 
                                      
                                        <div class="col-sm-3"> 
                                            <label > Branch Phone  </label>  
                                                <input type="text"  name="phone" value="" autocomplete="off" class="form-control"   required=""   > 
                                        </div> 
                                        <div class="col-sm-3">   
                                                <label class=""> Email adress </label>              
                                                    <input type="email" class="form-control " name="email"  autocomplete="off">   
                                        </div>
                                        <div class="col-sm-3">
                                            <label>  Status  </label>  
                                            <select class="form-control" name="status">
                                                <option value=1> Active </option>
                                                <option value=2 > Inactive </option>
                                            </select>                             
                                            
                                        </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 subbtn">  <i class="fa fa-plus"></i>  Add Branch  </button> </div>
                            </div> 
                    </form>               
                </div>
            </div>
        </div>
                                
    </section>

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

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

</body>
</html>