<?php include('site-header.php'); ?>
  <!-- end of LOGO CONTAINER -->
  <!-- - - - - - - - - - - - - -->
  <!-- start of SIDEBAR        -->
  <!-- - - - - - - - - - - - - -->
  <?php include('left-nevigation.php'); ?>
  
  <!-- - - - - - - - - - - - - -->
  <!-- end of SIDEBAR          -->
  <!-- - - - - - - - - - - - - -->
  <main id="playground">
    <!-- - - - - - - - - - - - - -->
    <!-- start of TOP NAVIGATION -->
    <!-- - - - - - - - - - - - - -->
 <?php include('site-top-header.php'); ?>
    <?php
    if(isset($_GET['del']))
      {
      $id  = mysqli_real_escape_string($link,$_GET['del']);
      $sel = mysqli_query($link,"select * from tbl_category where cat_id=$id");
      $arr = mysqli_fetch_assoc($sel);
        $image = $arr['category_image'];
        $id = $_GET['del'];
        if(mysqli_query($link,"DELETE FROM `tbl_category` WHERE cat_id=$id"))
        {
          $prosel = mysqli_query($link,"select * from tbl_product where pro_category=$id");
          while($pro_arr = mysqli_fetch_assoc($prosel))
          {
            $delimage = $pro_arr['pro_image'];
            if(mysqli_query($link,"delete from tbl_product where pro_category=$id"))
            {
              unlink("../product-image/$delimage");
            }
          }
          unlink("../uploaded/$image");
          echo "<script>window.location.href='update-category.php';</script>";
        }
    }
    ?>
<!--  -->
<?php
    extract($_POST);
    if(isset($Add))
    {
      $hid = $_POST['hid'];
      $cour = mysqli_query($link,"select * from tbl_category where home_status='Home'");
         if(mysqli_query($link,"update tbl_category set home_status='$Add' where cat_id='$hid'"))
          {
            $msg= "<p style='color:white;'>Category Add Home Page!!!!</p>";
          }
    }
     if(isset($Remove))
    {
      $hid = $_POST['hid'];
      if(mysqli_query($link,"update tbl_category set home_status='$Remove' where cat_id='$hid'"))
      {
        $msg= "<p style='color:white;'>Category Remove!!!!</p>";
      }
    }
    ?>
<div class="container-fluid textsss">
    <section id="page-title" class="row">
      <div class="col-md-8">
        <h1>Category</h1>
        <p class="lead">Update your product category below</strong>.</p>
      </div>
      <div class="col-md-4">
      </div>
    </section>
    <!-- / PAGE TITLE -->
    <div class="container-fluid">
      <div><?=@$msg;?></div>
      <div class="row">
        <div class="col-md-4">
        <div class="panel-body"> 
             <div class="form-group text-center">
                <a href="add-edit-category.php" class="btn btn-primary">Add New Category</a>
              </div>
          </div>
        </div>
        <div class="col-md-4">
          
        </div>
        <div class="col-md-4">
          <section class="panel tasks-widget"></section>
          <div class="panel-body"> 
             <div class="form-group text-center">
                <a href="category-banner.php" class="btn btn-primary"> Add banner </a>
              </div>
          </div>
          
        </div>
      </div>
      <!-- / row -->
      <div class="row">
        <div class="col-md-12">
          <section class="panel panel-primary">
            <header class="panel-heading">
              <h3 class="panel-title">Existing Categories</h3>
            </header>
                <table class="table table-hover table-responsive" width="100%">
                <tbody>
                  <tr>
                    <th scope="row" style="color:black;">S. No</th>
                    <th style="color:black;">Category Name</th>
                     <th style="color:black;">Image</th> 
                     <th style="color: black">Best Sale</th>
                    <th style="color:black;">Home Product</th> 
                    <th style="color:black;">Action</th>
                  </tr>
                  <?php
                  $sn=0;
                  $sel = mysqli_query($link,"select * from tbl_category");
                  while($arr = mysqli_fetch_assoc($sel))
                  {
                    $sn++;
                  ?>
                  <tr>
                      <td><?=$sn?></td>
                      <td><?=$arr['cate_name']?></td>
                      <td><img src="../category-image/<?=$arr['category_image'];?>" alt="<?=$arr['category_image'];?>" height="100px" width="100px"></td> 
                      <td><a href="category-best.php?cat_id=<?=$arr['cat_id']?>" class="btn btn-success"> Best </a></td>
                      <td>
                          <?php
                          if($arr['home_status']=="Home")
                          {
                          ?>
                          <form method="post">
                            <input type="hidden" name="hid" value="<?=$arr['cat_id'];?>">
                            <input type="submit" name="Remove" value="Remove" class="btn btn-danger">
                          </form>
                          <?php
                          }
                          else
                          {
                          ?>
                          <form method="post">
                            <input type="hidden" name="hid" value="<?=$arr['cat_id'];?>">
                            <input type="submit" name="Add" value="Home" class="btn btn-success">
                          </form>
                          <?php
                          }
                          ?>
                        </td> 
                      <td><a class="btn btn-success"  href="edit-category.php?edit=<?=$arr['cat_id'];?>">Edit</a>&nbsp;<a class="btn btn-danger" href="?del=<?=$arr['cat_id'];?>">Delete</a></td>
                  </tr>
                  <?php
                  }
                  ?>
              </tbody>
            </table> 
          </section>
        </div>
      </div>
    </div>
</div>
    <!-- / container-fluid -->
 <?php include('site-footer.php'); ?>
