-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
159 lines (136 loc) · 4.32 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
include("./db/db.php");
include("./headers/header.php");
// Delete a product
if (isset($_GET['delete_id'])) {
$delete_id = $_GET['delete_id'];
// Delete the product from the database
$db = new mysqli($hostname, $username, $password, $mzuni_db);
if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}
$delete_query = "DELETE FROM product WHERE product_id = $delete_id";
if ($db->query($delete_query) === TRUE) {
echo '<p>Product deleted successfully.</p>';
} else {
echo '<p>Error deleting product: ' . $db->error . '</p>';
}
// Close the database connection
$db->close();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Mzuni Tuck shop Product Listing</title>
<link id="theme" rel="stylesheet" href="theme-light.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<style>
.container {
margin-top: 50px;
}
.search-form {
margin-bottom: 20px;
display: flex;
align-items: center;
}
.search-form label {
margin-right: 10px;
}
.search-form input {
flex-grow: 1;
}
.table-container {
overflow-x: auto;
}
</style>
</head>
<body>
<div class="container">
<h2 class>Product List</h2>
<div class="row justify-content-between">
<div class="col-auto">
<a href="add_product_form.php" class="btn btn-primary">Add Product</a>
</div>
<div class="col-auto">
<form class="form-inline search-form">
<div class="form-group">
<label for="search-input"></label>
<input type="text" class="form-control" id="search-input" placeholder="Search">
</div>
</form>
</div>
<div class="col-auto">
<label for="theme-selector"></label>
<select id="theme-selector">
<option value="theme-light">Light</option>
<option value="theme-dark">Dark</option>
</select>
</div>
</div>
<div class="table-container">
<?php
$db = new mysqli($hostname, $username, $password, $mzuni_db);
if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}
$query = "SELECT * FROM product";
$result = $db->query($query);
if ($result->num_rows > 0) {
echo '<table class="table table-striped">';
echo '<thead>';
echo '<tr>';
echo '<th>Product Name</th>';
echo '<th>Description</th>';
echo '<th>Price (MKW)</th>';
echo '<th>Quantity</th>';
echo '<th>Actions</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
while ($row = $result->fetch_assoc()) {
echo '<tr>';
echo '<td>' . $row["product_name"] . '</td>';
echo '<td>' . $row["description"] . '</td>';
echo '<td>' . $row["price"] . '</td>';
echo '<td>' . $row["quantity"] . '</td>';
echo '<td>';
echo '<a href="edit_product_form.php?edit_id=' . $row["product_id"] . '">Edit</a>';
echo ' | ';
echo '<a href="index.php?delete_id=' . $row["product_id"] . '" onclick="return confirm(\'Are you sure you want to delete this product?\')">Delete</a>';
echo '</td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
} else {
echo '<p>No products found.</p>';
}
$db->close();
?>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function () {
// Search functionality
$('#search-input').on('input', function () {
var searchText = $(this).val().toLowerCase();
$('tbody tr').each(function () {
var productName = $(this).find('td:first').text().toLowerCase();
if (productName.includes(searchText)) {
$(this).show();
} else {
$(this).hide();
}
});
});
// Theme selection functionality
$('#theme-selector').on('change', function() {
var selectedTheme = $(this).val();
$('#theme').attr('href', selectedTheme + '.css');
});
});
</script>
</body>
</html>