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

//if (filter_has_var(INPUT_POST, "edit")) 
//try{
    $id = $_POST['edit']; 
    if($id == '')
          {   header("location:hrdepartment");   }

else  {              
      $stmt = $conn->prepare("SELECT * FROM invwarehouse  WHERE id=?");
      $stmt->execute([$id]); $details = $stmt->fetch();                
      }

//} catch(Exception $e) { echo 'Message: ' .$e->getMessage();} 

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

  $sql = "UPDATE  invwarehouse  SET date=:date,name=:name, code=:code, location=:loc, description=:desc  WHERE id=:id" ;
  $conn->prepare($sql)->execute([ 'date' => $date , 'name' => $name,'code' => $code, 'loc' => $location,'desc' => $desc ,'id'=>$cid ]);

  header("location:invwarehousel.php");
} catch(Exception $e) { echo 'Message: ' .$e->getMessage();}


  
?>

<!DOCTYPE html>
<html>
<head>
<?php include_once('inc/link.php');   ?>  
</head>
<body <?php include_once('inc/nav.php');  ?>>
<div class="wrapper">

  <!-- Main Header -->
    <header class="main-header">

    <!-- Logo -->
       <?php include_once('inc/brand.php');   ?>

    <!-- Header Navbar -->
    <?php include_once('inc/navbar.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" style="padding-bottom:0px;">
            <p style="color:green; font-size:20px; text-allign:centre ;font-weight:bold; " > <i class="fa fa-building" ></i> EDIT WAREHOUSE  </p>
                
                <ol class="breadcrumb">

                <li><a href="invwarehousel.php" class="btn btn-default btn-sm"> <i class="fa fa-bars"></i> MANAGE EMPLOYEE  </a></li>
                
                </ol>
        </section>

<!-- Main content -->

  <section class="content container-fluid" style="padding-top:0PX;"> 
        <div class="box box-default box-xs">
            <div class="box-body">
                <div class="row">
                    <form class="form-horizontal add_form "  action="" method="post"  >
                                            
                            <div class="col-sm-3"> 
                                <label > Date added  </label>  
                                <input type="hidden"   autocomplete="off" class="form-control " name="cid"  value="<?php  echo $details["id"]?>"   required=""   > 
                                <input type="text"   autocomplete="off" class="form-control datepickere" name="date"  value="<?php  echo $details["date"]?>"   required=""   > 
                            </div>                                             
                            <div class="col-sm-3"> 
                                <label > Warehouse Name  </label>  
                                    <input type="text"  name="name"  autocomplete="off" class="form-control"  value="<?php echo $details["name"]?>"    required=""   > 
                            </div> 
                                                                                    
                            <div class="col-md-3">
                                <label > Warehouse Code  </label>                          
                                <input type="text" class="form-control" name="code" required="" autocomplete="off"  value="<?php  echo $details["code"]?>"  >
                            </div>                                             
                            <div class="col-md-3">
                                <label > Warehouse Location  </label>                          
                                <input type="text" class="form-control" name="location" required="" autocomplete="off" value="<?php  echo $details["location"]?>"  >
                            </div>                                            
                                                
                            <div class="col-sm-12">   
                                    <div class="">
                                    <label class="">  Warehouse description </label>    
                                        <textarea type="text" class="form-control " name="description"  autocomplete="off" ><?php  echo $details["description"]?></textarea> 
                                    </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-default col-md-3">  <i class="fa fa-plus"></i>  Edit warehouse  </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/linkjs.php') ?>

</body>
</html>