<?php include('partials/menu.php'); ?>
<!--main content section starts here-->
<div class="main-content">
  <div class="wrapper">
    <h1>Manage Category</h1>
    <br></br><br>
    <?php
    if (isset($_SESSION['add'])) {
      echo $_SESSION['add'];//displaying session msg
      unset($_SESSION['add']);//REMOVING SESSION MSG
      // code...
    }
    if (isset($_SESSION['remove'])) {
      echo $_SESSION['remove'];//displaying session msg
      unset($_SESSION['remove']);//REMOVING SESSION MSG
      // code...
    }
    if (isset($_SESSION['delete'])) {
      echo $_SESSION['delete'];//displaying session msg
      unset($_SESSION['delete']);//REMOVING SESSION MSG
      // code...
    }
    if (isset($_SESSION['NO-Category-FOUND'])) {
      echo $_SESSION['NO-Category-FOUND'];//displaying session msg
      unset($_SESSION['NO-Category-FOUND']);//REMOVING SESSION MSG
      // code...
    }
    if (isset($_SESSION['update-category'])) {
      echo $_SESSION['update-category'];//displaying session msg
      unset($_SESSION['update-category']);//REMOVING SESSION MSG
      // code...
    }
    if (isset($_SESSION['upload'])) {
      echo $_SESSION['upload'];//displaying session msg
      unset($_SESSION['upload']);//REMOVING SESSION MSG
      // code...
    }
    if (isset($_SESSION['update-failed'])) {
      echo $_SESSION['update-failed'];//displaying session msg
      unset($_SESSION['update-failed']);//REMOVING SESSION MSG
      // code...
    }
     ?>
     <br><br>
    <!--btn to add admin-->
    <a href="<?php echo SITEURL; ?>backend/add-category.php" class="btnprimary">Add Category</a>
    <br></br><br>
    <table class="full">
      <tr>
        <th>S.N</th>
        <th>Title</th>
         <th>Active</th>
        <th>Actions</th>
      </tr>
      <?php
        //query to get all categories from db
        $sql = "SELECT * FROM tbl_category";

        //execute the query
        $res = mysqli_query($conn, $sql);

        //count rows to know if the data is available
        $count = mysqli_num_rows($res);
        //create a serial num
        $sn = 1;
        //check whether we have data in the db
        if ($count>0) {
          // we have data in the db
          //getthe data and display
          while($row=mysqli_fetch_assoc($res)){
            $id = $row['id'];
            $title = $row['title'];

            $active = $row['status'];

            ?>
            <tr>
              <td><?php echo $sn++ ?></td>
              <td><?php echo $title ?></td>


              <td><?php echo $active ?></td>
              <td>
               <a href="<?php echo SITEURL; ?>backend/update-category.php?id=<?php echo $id; ?>" class="btnsecondary">Update Category</a>
               <a href="<?php echo SITEURL; ?>backend/delete-category.php?id=<?php echo $id;?>" class='btndanger'>Delete Category</a>

              </td>
            </tr>
            <?php
          }
        }else{
          //we dont have data
          //we will display the msg inside the table
          ?>
          <tr>
            <td colspan='6'>
              <div class='error'>No Category Added.</div>
            </td>
          </tr>
          <?php
        }
       ?>

    </table>

  </div>

</div>
<!--main content section ends here-->
<?php include('partials/footer.php'); ?>
