<?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'); ?>

    <!-- - - - - - - - - - - - - -->
    <!-- end of TOP NAVIGATION   -->
    <!-- - - - - - - - - - - - - -->
    <!-- PAGE TITLE -->
    <?php
    if(isset($_GET['del']))
      {
        $id = mysqli_real_escape_string($link,$_GET['del']);
        $sel = mysqli_query($link,"select * from tbl_product where pro_id=$id");
        $arr = mysqli_fetch_assoc($sel);
        $image = $arr['pro_image'];
        $image2 = $arr['pro_image2'];
        $id = $_GET['del'];
        if(mysqli_query($link,"DELETE FROM `tbl_product` WHERE pro_id=$id"))
        {
          unlink("../product-image/$image");
          unlink("../product-image/$image2");
          echo "<script>window.location.href='show-product.php';</script>";
        }
    }
    ?>
    <?php
    extract($_POST);
    if(isset($Add))
    {
      $hid = $_POST['hid'];
         if(mysqli_query($link,"update tbl_product set status='$Add' where pro_id='$hid'"))
          {
            $msg= "<p style='color:green;'>Product Add Home Page!!!!</p>";
          }
    }
     if(isset($Remove))
    {
      $hid = $_POST['hid'];
      if(mysqli_query($link,"update tbl_product set status='$Remove' where pro_id='$hid'"))
      {
        $msg= "<p style='color:red;'>product Remove!!!!</p>";
      }
    }
    ?>
     <?php
    extract($_POST);
    if(isset($gal_rem))
    {
        $hid = $_POST['hid'];  
        if($_POST['gal_rem']=="Gallery"){
         if(mysqli_query($link,"update tbl_product set status_gal='$gal_rem' where pro_id='$hid'"))
          {
            $msg= "<p style='color:white;'>Product Add Gallery Page!!!!</p>";
          }
      }else
      {
        if(mysqli_query($link,"update tbl_product set status_gal='$gal_rem' where pro_id='$hid'"))
          {
            $msg= "<p style='color:white;'>Product Add Gallery Page!!!!</p>";
          }
      }
    }
    ?>
    <section id="page-title" class="row">
      <div class="col-md-8">
        <h1>Show Product</h1>
        <p class="lead">Update your Product</strong>.</p>
      </div>
      <div class="col-md-4">
      </div>
    </section>
    <!-- / PAGE TITLE -->
    <div class="container-fluid">
      <div class="row">
        <div class="col-md-4">
          <section class="panel tasks-widget"></section>
        </div>
        <div class="col-md-4">
          <div class="panel-body"> <form method="post">
             <div class="form-group text-center"><a href="add-products.php" class="btn btn-primary">Add New Product</a>&nbsp;<!-- --></div>
          </form>
          </div>
        </div>
        <div class="col-md-4">
          <section class="panel tasks-widget"></section>
        </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 Services</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;">Product Name</th>
                <th style="color:black;">Category Name</th>
                <th style="color:black;">Image</th>
                <th style="color:black;">Imagr Over</th>
                 <th style="color:black;">More-Image</th> 
                <th style="color:black;">Add Home </th> 
                <!-- <th style="color:black;">Gallery</th> -->
                <th style="color:black;">Date</th>
                <th style="color:black;">Action</th>
              </tr>
              <?php
                $sn=0;
                $ReadSql = "select * from tbl_product  ";
                $sel = mysqli_query($link,$ReadSql);
              while($arr = mysqli_fetch_assoc($sel))
              {
                $cate_id=$arr['pro_category'];
                $sel1 = mysqli_query($link,"select * from tbl_category where cat_id=$cate_id");
                $arr1 = mysqli_fetch_assoc($sel1);
                $sn++;
              ?>
              <tr id="<?=$arr['pro_id'];?>">
                  <td><?=$sn?></td>
                  <td><?=$arr['pro_name'];?></td>
                  <td><?=$arr1['cate_name'];?></td>
                  <td><img src="../product-image/<?=$arr['pro_image'];?>" alt="<?=$arr['pro_image'];?>" style="width:100px; height:100px;"></td>
                  <td><img src="../product-image/<?=$arr['pro_image2'];?>" alt="<?=$arr['pro_image2'];?>" style="width:100px; height:100px; "></td>
                  <td><a href="product-image.php?pro_id=<?=$arr['pro_id'];?>" class="btn btn-success">Add Image</a></td>  
                 <td>
                    <?php
                    if($arr['status']=="Home")
                    {
                    ?>
                    <form method="post">
                      <input type="hidden" name="hid" value="<?=$arr['pro_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['pro_id'];?>">
                      <input type="submit" name="Add" value="Home" class="btn btn-success">
                    </form>
                    <?php
                    }
                    ?>
                  </td>
                 <!-- <td>
                    <?php
                    if($arr['status_gal']=="Gallery")
                    {
                    ?>
                    <form method="post">
                      <input type="hidden" name="hid" value="<?=$arr['pro_id'];?>">
                      <input type="submit" name="gal_rem" value="Remove" class="btn btn-danger">
                    </form>
                    <?php
                    }
                    else
                    {
                    ?>
                    <form method="post">
                      <input type="hidden" name="hid" value="<?=$arr['pro_id'];?>">
                      <input type="submit" name="gal_rem" value="Gallery" class="btn btn-success">
                    </form>
                    <?php
                    }
                    ?>
                  </td> -->
                  <td><?=$arr['pro_date']?></td>
                  <td><a class="btn btn-success"  href="add-products.php?edit=<?=$arr['pro_id']?>">Edit</a>&nbsp;<a class="btn btn-danger" href="?del=<?=$arr['pro_id']?>">Delete</a></td>
              </tr>
              <?php
              }
              ?>
          </tbody>
            </table>
          </section>
        </div>
      </div>
    </div>
    <!-- / container-fluid -->
 <?php include('site-footer.php'); ?>
