Mini Shell
<!DOCTYPE html>
<html lang="en">
<head>
<?php include('include/head_admin.php');
$page_id = '4';
if (isset($_GET['type']) && $_GET['type'] != '') {
$type = get_safe_value($con, $_GET['type']);
if ($type == 'status') {
$operation = get_safe_value($con, $_GET['operation']);
$id = get_safe_value($con, $_GET['id']);
if ($operation == 'active') {
$status = '1';
} else {
$status = '0';
}
$update_status_sql = "update product set status='$status' where id='$id'";
mysqli_query($con, $update_status_sql);
}
if ($type == 'delete') {
$id = get_safe_value($con, $_GET['id']);
$select_sql = "SELECT image FROM product WHERE id='$id'";
$result = mysqli_query($con, $select_sql);
if ($result) {
$row = mysqli_fetch_assoc($result);
$filename = $row['image'];
// Step 2: Delete record from the database
$delete_sql = "DELETE FROM product WHERE id='$id'";
mysqli_query($con, $delete_sql);
// Step 3: Unlink the image file from the storage
$uploadsDirectory = '../media/product/';
$filePath = $uploadsDirectory . $filename;
// Check if the file exists before attempting to delete it
if (file_exists($filePath)) {
unlink($filePath); // Delete the file
echo "product and image file deleted successfully";
header('location:product-all.php');
} else {
echo "Image file not found in the storage";
}
}
}
}
$sql = "select * from product ";
$res = mysqli_query($con, $sql);
?>
</head>
<body>
<!--== MAIN CONTRAINER ==-->
<?php include('include/header_admin.php'); ?>
<!--== BODY CONTNAINER ==-->
<div class="container-fluid sb2">
<div class="row">
<?php include('include/sidebar_admin.php'); ?>
<div class="sb2-2">
<div class="sb2-2-2">
<ul>
<li><a href="index.php"><i class="fa fa-home" aria-hidden="true"></i> Home</a>
</li>
<li class="active-bre"><a href="product-all">Product</a>
</li>
</ul>
</div>
<div class="sb2-2-1">
<h2>All Products</h2>
<!-- <p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p> -->
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Category</th>
<th>Image</th>
<!-- <th>Pdf</th> -->
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
while ($row = mysqli_fetch_assoc($res)) {
$image = json_decode($row['image']);
?>
<tr>
<td><?php echo $i++ ?></td>
<td><?php echo $row['name'] ?></td>
<td>
<?php
$cat_id = $row['category'];
$sqqll = mysqli_fetch_assoc(mysqli_query($con,"SELECT * FROM `category` WHERE `id`='$cat_id'"));
echo $sqqll['name'];
?>
</td>
<td><?php
echo "<a target='_blank' href='" . "../media/product/" . $image[0] . "'><img width='100px' src='" . "../media/product/" . $image[0] . "'/></a>";
?></td>
<!-- <td><?php
echo "<a target='_blank' href='" . "../media/product/" . $image[1] . "'>View PDF</a>";
?></td> -->
<td><a href="product-add.php?id=<?php echo $row['id']; ?>" class="sb2-2-1-edit"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>
</td>
<td><a href="?type=delete&id=<?php echo $row['id'] ?>" class="sb2-2-1-edit"><i class="fa fa-trash-o" aria-hidden="true"></i></a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php include('include/footer_admin.php'); ?>
<?php include('include/foot_admin.php'); ?>
</body>
</html>