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

.search-a { float: left; width: 50%; padding: 10px; }
.search-b { float: left; width: 50%; padding: 10px; }


.product-image { float: left; width: 100%; height: 4em; }


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%; }

.btn-delete {background: white; border:  1px solid red; color: red; padding: 4px;}
.btn-delete a { color: red; text-decoration: none; font-size: x-small;}

.btn-edit {background: white; border:  1px solid forestgreen;  padding: 4px 15px;}
.btn-edit a { color:black; text-decoration: none; font-size: x-small;}

.btn-offer {background: white; border:  1px solid #7CB9E8;  padding: 4px;}
.btn-offer a { color:#7CB9E8; font-weight: bold; text-decoration: none; font-size: x-small;}


.btn-edit:hover{background:#dde; border:  1px solid none;  padding: 5px; ;opacity: .6}
.btn-delete:hover{background:#dde; border:  1px solid red;  padding: 5px; opacity: .6;}
.btn-reset:hover{background:#dde; border:  1px solid red;  padding: 5px; 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: 50%; }
   }

</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" >
  <label> </label>

<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">
<form method="post" >
  <label> </label>
<input type="search-products" name="name" placeholder="Search e.g fork-jembe" required="autofocus">
</form>
</nav>

<div class="column-products">

 <?php  require_once "inc/config.php";
 $sql = "SELECT * FROM products order by Id DESC";
   if($result = $mysqli->query($sql)){
   if($result->num_rows > 0){
   echo "<table class='table'>";
   echo "<thead>";
   echo "<tr class='t1'>";
    echo "<th>Product ID</th>";  
   echo "<th>Image name</th>";
   echo "<th>Category</th>";
   echo "<th>Product Name</th>";
    echo "<th>Product size </th>";
  echo "<th>Quantity </th>";
    echo "<th>Price</th>";
      echo "<th>Price -1</th>";
   echo "<th>Description</th>";
     echo "<th>uploaded by</th>";
    echo "<th>Time Uploaded</th>";
    echo "<th>Edit Record</th>";
    echo "<th> Offers</th>";
  echo "<th>Remove Record</th>";
     echo "</tr>";
   echo "</thead>";
   echo "<tbody>";
    while($row = $result->fetch_array()){
   echo "<tr>";
  echo "<td>" . $row['Id'] . "</td>";
echo "<td><img class='product-image'  src='../product-images/".$row['Image_name']."' ></td>";
   echo "<td>" . $row['Category'] . "</td>";
    echo "<td>" . $row['P_name'] . "</td>";
     echo "<td>" . $row['P_size'] . "</td>";
      echo "<td>" . $row['Quantity'] . "</td>";
       echo "<td>" . $row['P_price'] . "</td>";
  echo "<td>" . $row['Price_1'] . "</td>";
        echo "<td>" . $row['Description'] . "</td>";
         echo "<td>" . $row['Session'] . "</td>";


  echo "<td>" . date_format( new DateTime ($row['Time'] ),"d M, Y H: m: s"). "</td>";

echo "<td><button class='btn-edit'><a href='edit-products.php?edit=". $row['Id'] ."' title='Edit record' data-toggle='tooltip'>Edit </a></button>"."</td>";

echo "<td><button class='btn-offer'><a href='product-offers.php?edit=". $row['Id'] ."' title='Edit ' data-toggle='tooltip'>Update</a></button>"."</td>";

echo "<td><button class='btn-delete'><a href='del-products.php?id=". $row['Id'] ."' title='delete Record' data-toggle='tooltip'>Remove</a></button>" ."</td>";



  echo "</tr>";
         }
    echo "</tbody>";                            
    echo "</table>";
   // Free result set
       $result->free();
            } else{ echo "<p class='no-results'><em>Opps! no records.</em></p>";}
  
   } else{ echo "ERROR: Could not able to execute $sql. " . $mysqli->error;}
   // Close connection
       $mysqli->close();?>
</div>
 </body>  
</div>


</div>

</body>
</html>
