<?php 
  if (!isset($_SESSION['username'])) {
    $_SESSION['msg'] = "To access this page, Login is required";
    header('location: login.php');
  }  ?>
<!DOCTYPE>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
  box-sizing: border-box;
}

body {
  margin: 0;
}
.top-top {float: left; font-size: x-small;color:#848482; width: 100%; padding: 10px; margin-bottom: 1%;}

.column-products {  float: left;  width: 100%;  padding: 15px;  overflow-x: auto; scrollbar-width: thin; background: white; }

.search-a { float: left; width: 50%; padding: 10px; display: none;}
.search-b { float: left; width: 100%; padding: 15px; background: white;}


.product-image { float: left; width: 70%; height: 3em; }


td {  padding:8px;border-bottom: 1px solid #ddd !important; font-size: xx-small; }

th {  padding:10px;border: 1px solid #ddd !important; background:#7CB9E8; color: white; opacity: .8;text-align: left;  font-size: x-small;
 border-spacing: 1;}

table { margin: auto; border-spacing: 1; width:100%;  overflow-x: auto;  background: white;}

.no-results{float: left; margin-left: 5%; color: red; font-size: small;}

table i { margin-right: 3%; }

pre { font-family: "Nunito", sans-serif; color: #585652; font-size: x-small; white-space: pre-wrap; word-break: keep-all; text-align: justify;}

.btn-delete {background: white; border:  1px solid red; color: red; padding: 4px; font-size: x-small;}
.btn-edit {background: white; border:  1px solid forestgreen; color: green; padding: 4px 15px; font-size: x-small;}

.btn-offer {background: white; border:  1px solid #7CB9E8; padding: 4px 15px;  color:#7CB9E8; font-size: x-small; }
.offer{ background:none; border: 1px solid  #7CB9E8; font-weight: bold; color:#7CB9E8; padding: 5px; border-radius: 3px;  }

.stock-out{ background: white; padding:6px; float: left; color: red; }

.low-stock { background:orange; color: white; padding: 6px; float: left; }

.btn-edit:hover{background:#dde; border:  1px solid none;  padding: 5px 15px; opacity: .6}
.btn-delete:hover{background:#dde; border:  1px solid red; padding: 5px ; opacity: .6;}
.btn-offer:hover{background:#dde; border:  1px solid red;  padding: 5px 15px;   opacity: .6;}

input[type=search-products], select{ width: 100%;  padding: 8px;  border: 1px solid #ccc;  border-radius: 5px; background: white;  margin: auto; color: #7CB9E8;margin-top: 3%; font-weight: bold; font-size: x-small; }

input[type=search]:focus {  border:none; padding: 7px; }

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

@media screen and (max-width:600px) {
  .column-products {  width: 100%;   }

.search-a , .search-b { float: left; width: 100%; }
   }

</style>
</head>
<body>


<div class="row">

<div class="top-top">
<a href="index.php" style="color: black; text-decoration: none; font-weight: bold;"> Home </a>
<a>// Manage products</a>
</div>


<nav class="search-a">
<form method="post" >
 

<select  name="category" >
<option>
   <?php include ("inc/config.php");
$sql = "SELECT * FROM categories ";
if($result = $conn->query($sql)){
if($result->num_rows > 0){
while($row = $result->fetch_array()){



echo "\n" . $row['Category_name'] . ""; ?>
</option>
<option><?php }} } ?> </option>

</select>
</form>
</nav>

<nav class="search-b">
 <?php include 'manage-items-search.php'; ?> 
</nav>

<div class="column-products">

<?php    
    
include "inc/config.php";    
    
$sql = "SELECT * FROM products order by Id DESC ";   
$result = mysqli_query($conn,$sql);    
 
?> 

 <table>    
<tr> 
 <th>#</th> 
  <th>Product Image</th>
  <th>Category</th>
  <th>Name</th>
  <th>Size</th>
  <th>Status</th>
  <th>Quantity</th>
  <th>Price </th>
  <th>Offer Price</th>
  <th>Product Description</th>
  <th>Recorded by</th>
  <th>Time</th>
  <th>Edit record</th>
  <th>Offer Update</th>
  <th>Add Stock</th>
  <th>Remove Record</th>
</tr>  


  <?php while($row = mysqli_fetch_object($result)){  ?>  
 <tr> 
<td><?php echo $row->id;?></td>
<td><img src="../product-images/<?php echo $row->image;?>" class="product-image"> </td>
<td><?php echo $row->category;?></td>
<td><?php echo $row->name;?></td>
<td><?php echo $row->size;?></td>
<td><?php   $a = $row->quantity; if ($a == 0) { echo "<a class='stock-out'>stock out</a>"; } else{ echo " <a class='low-stock'> Low </a> ";} ?></td>

<td><?php echo $row->quantity;?></td>

<td><?php echo $row->price;?></td>

<td>
<?php  $a = $row->price_1;  

if ($a > 0) { echo "<a class='offer'> $a/=  </a> ";}
 else { echo "<a>  -  </a> ";}


?>
  
</td>


<td> <pre> <?php echo substr(($row->description), 0, 20); ?> .....</pre> </td>


<td><?php echo $row->session;?></td>
<td style="color:#848482; font-weight: bold;" ><?php echo date_format( new DateTime($row->time),"d,M, Y \t H:m:s");?></td>

<td> 
<button class="btn-edit" onclick="location.href = 'edit-products.php?edit=<?php echo $row->id;?>'; return false;" >Edit</button>
</td>



<td>
<button class="btn-offer" onclick="location.href = 'product-offers.php?edit=<?php echo $row->id;?>'; return false;" >Update</button>
</td>

<td> 
<button class="btn-edit" onclick="location.href = 'add-add-products.php?edit=<?php echo $row->id;?>'; return false;" >Add</button>
</td>

<td> <button class="btn-delete"
 onclick="location.href = 'del-products.php?id=<?php echo $row->id;?>'; return false;"  >Remove</button> 
</td>

    <?php }?></tr>
        </table>
</div>
 </body>  
</div>


</div>

</body>
</html>
