
<?php 
  session_start();
  if (!isset($_SESSION['username'])) {
    $_SESSION['msg'] = "To access this page, Login is required";
    header('location: login.php');
  }
  if (isset($_GET['logout'])) {
    session_destroy();
    unset($_SESSION['username']);
    header("location: login.php");
  }
?>


<?php 

  include"inc/config.php";
   $errors = array(); // initialize variables
    $id = ""; $category="";    $category_name= ""; $image= ""; $price_1= "";  $quantity_1=""; 
  $id = 0; 
  $update = false;

  if (isset($_GET['edit'])) { 
    $id = $_GET['edit'];
  $record = mysqli_query($db, "SELECT * FROM products WHERE id= $id ");


    if (count($record) == 1 ) {
    $n = mysqli_fetch_array($record);
     $id = $n['id'];  $category = $n['category'];  $name = $n['name'];  $size = $n['size'];  $price = $n['price']; 
      $price_1 = $n['price_1'];  $description = $n['description'];  $quantity = $n['quantity'];   $image = $n['image']; 
    }

  }

if (isset($_POST['update'])) {
$id = $_POST['id']; $category = $_POST['category']; $name = $_POST['name']; $size = $_POST['size']; $price= $_POST['price'];
 $quantity= $_POST['quantity']; $quantity_1= $_POST['quantity_1'];


$x = $n['quantity']  ;

$y = $_POST['quantity_1'] ;

$quantity = $x + $y ;

 $username=$_SESSION['username'];


// if (empty($a)) {  echo "Variable 'a' is empty.<br>";}

$sql_1 = "UPDATE products SET quantity  = '$quantity' WHERE id =$id";


$sql = "INSERT INTO products_add_logs (code, image, category,  name, size,  quantity,  price,  session ) 
    VALUES ('code', '$image', '$category', '$name',  '$size', '$y', '$price', '$username')";



 if  (($db->query($sql)) AND ($db->query($sql_1))   ) {
 echo "<script type= 'text/javascript'>alert('$y items added succcessfully into [$name] records.');</script>";
 echo "<script type='text/javascript'>location.href = 'index.php?link=002products';</script>";
}
else{echo "<script type= 'text/javascript'>alert('Error!!! Unable to add items in [$name] records.');</script>";}

}


?>


<!DOCTYPE>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
 body { font-family: helvetica, sans-serif; }
* {  box-sizing: border-box;}
body {  margin: 0;}

.top-aa{ padding:15px; text-align: left; width: 100%; font-size: x-small; color: #848482; margin-bottom: 1%;}

.wrapper{ background:whitesmoke;  width:100%; border: 0px solid #a1a1a1;  margin:auto; resize: none;     overflow:hidden; }

.column-a {  float: left;  width:18%;  padding: 0px; height: 90%; background:white ;border-top: 2px solid whitesmoke;  overflow-x: auto; scrollbar-width: thin; }

.column-b { float: left; width: 82%;  padding: 15px; overflow-x: auto; scrollbar-width: thin; height: 90%; }


/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}

@media screen and (max-width:600px) {
  .column-a { width: 100%; height: auto; }
  .column-b {  width: 100%; height:auto; } }

</style>
</head>
<body>


<div class="row">

<div class="wrapper">

  <nav> <?php include "header.php"; ?></nav>


  <div class="column-a"><?php include "menu.php"; ?>  </div>
  
  <div class="column-b">

<div class="top-aa">
<a href="index.php" style="color: black; text-decoration: none; font-weight: bold;"> Home </a>
<a href="index.php?link=002products" style="color: black; text-decoration: none; ">// Manage Products</a>
<a>// Add product Quantities</a>
</div>

<?php include ("products-add.php"); ?>

</div>





<?php include ("footer.php"); ?>
</div>
</div>
</body>
</html>
