File "productList.php"

Full Path: /home/krishnamexports/public_html/panel/partials/productList.php
File size: 5.13 KB
MIME-type: text/x-php; charset=us-ascii
Charset: utf-8

<?php

if(isset($_SESSION['errorMsg'])){ echo $_SESSION['errorMsg']; unset($_SESSION['errorMsg']);}

?>	

<div class="col-md-12 grid-margin stretch-card">

      

      <div class="card">

        <div class="card-body">

          <h4 class="card-title">Product List</h4>    

          <div class="table-responsive">

            <table class="table table-striped" id="example">

              <thead>

                <tr>

                  <th width="10%">S.No.</th>

                  <th width="10%">Image</th>

                  <th width="12%">Category</th>

                  <th width="13%">Subcategory</th>

                  <th width="10%">Name</th>

                  <th width="30%">Skucode</th>

                  <th width="30%">Weight</th>

                  <th width="30%">Price</th>

                  <th width="30%">Selling Price</th>

                  <th width="30%">Delivery Chr.</th>                  

                  <th width="10%">Status</th>

                  <th width="20%">Action</th>

                </tr>

              </thead>

              <tbody>
				<?php
                $i = 1;						  
                $sqlEmployee = mysqli_query($cn, "select * from `tbl_product` where `status` IN(0,1) order by `name`");
                while($sqlEmployeeData = mysqli_fetch_array($sqlEmployee))
				{
					$sqlCategory = mysqli_query($cn, "select * from `tbl_category` where id='".$sqlEmployeeData['category_id']."'");
					$sqlCategoryData = mysqli_fetch_array($sqlCategory);					
					$sqlSubCategory = mysqli_query($cn, "select * from `tbl_subcategory` where id='".$sqlEmployeeData['subcategory_id']."'");
					$sqlSubCategoryData = mysqli_fetch_array($sqlSubCategory);															
					$productImage = explode("$",$sqlEmployeeData['image']); 
					
					/*$name      = $sqlEmployeeData['name'];//$_GET['name'];
					$tableName = "tbl_product";//$_GET['tableName']; 
					if(!empty($name))
					{
						$slug = preg_replace("/-$/","",preg_replace('/[^a-z0-9]+/i', "-", strtolower($name)));
						$query = "SELECT COUNT(*) AS NumHits FROM $tableName WHERE  slug_url  LIKE '$slug%'";
						$result = mysqli_query($cn, $query);
						$row    = mysqli_fetch_array($result);
						$numHits = $row['NumHits'];
						$slug = ($numHits > 0) ? ($slug . '-' . $numHits) : $slug;
						mysqli_query($cn, "update `tbl_product` set `slug_url`='".$slug."' where `id`='".$sqlEmployeeData['id']."'");
					}*/
                	?>

                    <tr>

                        <td><?php echo $i++;?></td>

                        <td><img src="../products/<?php echo $productImage[0];?>" height="150" width="200"></td>

                        <td><?php echo $sqlCategoryData['name'];?></td>

                        <td><?php echo $sqlSubCategoryData['name'];?></td>

                        <td><?php echo $sqlEmployeeData['name'];?></td>

                        <td><?php echo $sqlEmployeeData['skucode'];?></td>

                        <td><?php echo $sqlEmployeeData['weight'];?></td>

                        <td><?php echo $sqlEmployeeData['orignalprice'];?></td>

                        <td><?php echo $sqlEmployeeData['price'];?></td>

                        <td><?php echo $sqlEmployeeData['delivery_charge'];?></td>                                                                       

                        <td style="text-align:center;">

                              <?php

							  if($sqlEmployeeData['status']==1){?>

							  <a href="home.php?pages=productList&status=<?php echo $sqlEmployeeData['id'];?>&val=0">YES</a>

							  <?php }else{?>

                              <a href="home.php?pages=productList&status=<?php echo $sqlEmployeeData['id'];?>&val=1">NO</a>

                              <?php }?>

                              </td>

                        <td>

                        	<a href="home.php?pages=product&edit_id=<?php echo $sqlEmployeeData['id'];?>" class="btn btn-outline-success btn-sm">Edit</a> 

                            <a href="home.php?pages=productList&delete_id=<?php echo $sqlEmployeeData['id'];?>" class="btn btn-outline-danger btn-sm" onclick="return deleteConfirm();">Delete</a>

						</td>

                    </tr>

                  <?php } ?>

              </tbody>

            </table>

          </div>

        </div>

      </div>

</div>

<?php

if(isset($_GET['delete_id']))

{

	$id      = $_GET['delete_id'];

	$sql     = mysqli_query($cn, "update `tbl_product` SET `status`=2 where id='$id'");

	if($sql)

	{

		$_SESSION['errorMsg'] = '<div class="alert alert-success"><strong>Success!</strong> Product Deleted Successfully.</div>';

	}

	else

	{

		$_SESSION['errorMsg'] = "error: " . $sql . "<br>" . mysqli_error($conn);	

	}

	header("location:home.php?pages=productList");

}



if(isset($_GET['status']))

{

	$id      = $_GET['status'];

	$val     = $_GET['val'];

	$sql     = mysqli_query($cn,"update `tbl_product` SET `status`='".$val."' where id='".$id."'");			     

	$_SESSION['errorMsg'] = '<div class="alert alert-success"><strong>Success!</strong> Product Status Updated Successfully.</div>';

	header("location:home.php?pages=productList");

}

if(isset($_SESSION['errorMsg'])){ echo $_SESSION['errorMsg'];}

?>