-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiamond_filter.php
More file actions
342 lines (322 loc) · 16.2 KB
/
diamond_filter.php
File metadata and controls
342 lines (322 loc) · 16.2 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<?php
// diamond_filter.php
include 'header.php';
include 'sidebar.php';
// --- Fetch data for filter dropdowns ---
$customers_result = $conn->query("SELECT id, customer_name, contact_no FROM customers WHERE status='Enable' ORDER BY customer_name");
$customers_data = [];
while ($row = $customers_result->fetch_assoc()) {
$customers_data[] = $row;
}
// Determine current customer when logged in as customer
$current_customer_id = '';
$current_customer_name = '';
if (isset($_SESSION['role']) && $_SESSION['role'] === 'customer') {
// $_SESSION['userid'] should contain the customer's id or name from login
$sessId = $_SESSION['userid'] ?? '';
// try to match by id first
foreach ($customers_data as $c) {
if ($sessId !== '' && is_numeric($sessId) && $c['id'] == $sessId) {
$current_customer_id = $c['id'];
$current_customer_name = $c['customer_name'];
break;
}
// fallback match by name
if ($sessId !== '' && !is_numeric($sessId) && strcasecmp($c['customer_name'], $sessId) === 0) {
$current_customer_id = $c['id'];
$current_customer_name = $c['customer_name'];
break;
}
}
}
$shapes = $conn->query("SELECT shape_name FROM shapes WHERE status='Enable' ORDER BY shape_name");
$colors = $conn->query("SELECT color_name FROM colors WHERE status='Enable' ORDER BY color_name");
$clarities = $conn->query("SELECT clarity_name FROM clarities WHERE status='Enable' ORDER BY clarity_name");
$cuts = $conn->query("SELECT cut_name FROM cuts WHERE status='Enable' ORDER BY cut_name");
// --- Filtering Logic ---
$sql = "SELECT * FROM diamonds WHERE 1=1";
$params = [];
$types = '';
if (!empty($_GET['shape'])) {
$sql .= " AND shape = ?";
$params[] = $_GET['shape'];
$types .= 's';
}
if (!empty($_GET['color'])) {
$sql .= " AND color = ?";
$params[] = $_GET['color'];
$types .= 's';
}
if (!empty($_GET['clarity'])) {
$sql .= " AND clarity = ?";
$params[] = $_GET['clarity'];
$types .= 's';
}
if (!empty($_GET['cut'])) {
$sql .= " AND cut = ?";
$params[] = $_GET['cut'];
$types .= 's';
}
if (!empty($_GET['size_from'])) {
$sql .= " AND size >= ?";
$params[] = $_GET['size_from'];
$types .= 'd';
}
if (!empty($_GET['size_to'])) {
$sql .= " AND size <= ?";
$params[] = $_GET['size_to'];
$types .= 'd';
}
$sql .= " AND status = 'Available' ORDER BY id DESC";
$stmt = $conn->prepare($sql);
if (!empty($params)) {
$stmt->bind_param($types, ...$params);
}
$stmt->execute();
$result = $stmt->get_result();
?>
<style>
/* Custom styles for radio and checkbox */
.custom-radio input,
.custom-checkbox input {
display: none;
}
.custom-radio label,
.custom-checkbox label {
display: inline-flex;
align-items: center;
cursor: pointer;
color: #4a5568;
}
.custom-radio label:before,
.custom-checkbox label:before {
content: '';
display: inline-block;
width: 18px;
height: 18px;
margin-right: 0.5rem;
border: 2px solid #cbd5e0;
background-color: white;
}
.custom-radio label:before {
border-radius: 50%;
}
.custom-checkbox label:before {
border-radius: 4px;
}
.custom-radio input:checked+label:before {
background-color: #ec4899;
border-color: #ec4899;
box-shadow: inset 0 0 0 3px white;
}
.custom-checkbox input:checked+label:before {
background-color: #ec4899;
border-color: #ec4899;
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e");
}
</style>
<!-- Main Content -->
<div class="bg-white p-8 rounded-lg shadow-md w-full">
<h4 class="text-2xl font-bold text-gray-700 mb-6">Customer Details</h4>
<!-- Filter Form -->
<form action="diamond_filter.php" method="GET">
<div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-8">
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Customer Contact</label>
<select name="customer_contact" id="customer_contact"
class="shadow border rounded w-full py-2 px-3 text-gray-700" <?php echo (isset($_SESSION['role']) && $_SESSION['role'] === 'customer') ? 'disabled' : ''; ?>>
<option value="">Select an option</option>
<?php foreach ($customers_data as $customer) {
$sel = ($current_customer_id && $current_customer_id == $customer['id']) ? ' selected' : '';
echo "<option value='" . $customer['id'] . "' data-name='" . $customer['customer_name'] . "'" . $sel . ">" . $customer['contact_no'] . "</option>";
} ?>
</select>
</div>
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Customer Name</label>
<input type="text" name="customer_name" id="customer_name"
class="shadow border rounded w-full py-2 px-3 text-gray-700 bg-gray-100" readonly value="<?php echo htmlspecialchars($current_customer_name); ?>">
</div>
<script>
(function() {
var contactSelect = document.getElementById('customer_contact');
var nameInput = document.getElementById('customer_name');
// If the select is disabled (customer logged in), don't add listener or allow changes
if (contactSelect.disabled) {
// ensure name is already set server-side; nothing to do
return;
}
contactSelect.addEventListener('change', function() {
var sel = this.options[this.selectedIndex];
var name = sel ? (sel.getAttribute('data-name') || '') : '';
nameInput.value = name;
});
})();
</script>
<!-- Other filters -->
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Shape</label>
<select name="shape" class="shadow border rounded w-full py-2 px-3 text-gray-700">
<option value="">All</option>
<?php mysqli_data_seek($shapes, 0);
while ($row = $shapes->fetch_assoc())
echo "<option value='" . $row['shape_name'] . "' " . ((!empty($_GET['shape']) && $_GET['shape'] == $row['shape_name']) ? 'selected' : '') . ">" . $row['shape_name'] . "</option>"; ?>
</select>
</div>
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Color</label>
<select name="color" class="shadow border rounded w-full py-2 px-3 text-gray-700">
<option value="">All</option>
<?php mysqli_data_seek($colors, 0);
while ($row = $colors->fetch_assoc())
echo "<option value='" . $row['color_name'] . "' " . ((!empty($_GET['color']) && $_GET['color'] == $row['color_name']) ? 'selected' : '') . ">" . $row['color_name'] . "</option>"; ?>
</select>
</div>
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Clarity</label>
<select name="clarity" class="shadow border rounded w-full py-2 px-3 text-gray-700">
<option value="">All</option>
<?php mysqli_data_seek($clarities, 0);
while ($row = $clarities->fetch_assoc())
echo "<option value='" . $row['clarity_name'] . "' " . ((!empty($_GET['clarity']) && $_GET['clarity'] == $row['clarity_name']) ? 'selected' : '') . ">" . $row['clarity_name'] . "</option>"; ?>
</select>
</div>
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Cut</label>
<select name="cut" class="shadow border rounded w-full py-2 px-3 text-gray-700">
<option value="">All</option>
<?php mysqli_data_seek($cuts, 0);
while ($row = $cuts->fetch_assoc())
echo "<option value='" . $row['cut_name'] . "' " . ((!empty($_GET['cut']) && $_GET['cut'] == $row['cut_name']) ? 'selected' : '') . ">" . $row['cut_name'] . "</option>"; ?>
</select>
</div>
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Size From</label>
<input type="number" step="0.01" name="size_from"
value="<?php echo isset($_GET['size_from']) ? htmlspecialchars($_GET['size_from']) : ''; ?>"
class="shadow border rounded w-full py-2 px-3 text-gray-700">
</div>
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Size To</label>
<input type="number" step="0.01" name="size_to"
value="<?php echo isset($_GET['size_to']) ? htmlspecialchars($_GET['size_to']) : ''; ?>"
class="shadow border rounded w-full py-2 px-3 text-gray-700">
</div>
</div>
<div class="flex justify-end"><button type="submit"
class="bg-pink-600 hover:bg-pink-700 text-white font-bold py-2 px-6 rounded">Filter</button></div>
</form>
<hr class="my-8">
<!-- Results Table & Action Form -->
<form action="diamond_filter_action.php" method="POST">
<div class="overflow-x-auto">
<table class="min-w-full bg-white">
<thead class="bg-gray-200 text-gray-600 uppercase text-sm leading-normal">
<tr>
<th class="py-3 px-6 text-left"><input type="checkbox" id="select_all"></th>
<th class="py-3 px-6 text-left">SRNO</th>
<th class="py-3 px-6 text-left">Stock</th>
<th class="py-3 px-6 text-left">Shape</th>
<th class="py-3 px-6 text-left">Size</th>
<th class="py-3 px-6 text-left">Color</th>
<th class="py-3 px-6 text-left">Clarity</th>
<th class="py-3 px-6 text-center">Actions</th>
</tr>
</thead>
<tbody class="text-gray-600 text-sm font-light">
<?php
if ($result && $result->num_rows > 0) {
$sr_no = 1;
while ($row = $result->fetch_assoc()) {
echo "<tr class='border-b border-gray-200 hover:bg-gray-100'>";
echo "<td class='py-3 px-6 text-left'><input type='checkbox' name='diamond_ids[]' value='" . $row['id'] . "' class='diamond_checkbox'></td>";
echo "<td class='py-3 px-6 text-left'>" . $sr_no++ . "</td>";
echo "<td class='py-3 px-6 text-left font-semibold'>" . htmlspecialchars($row["stock_no"]) . "</td>";
echo "<td class='py-3 px-6 text-left'>" . htmlspecialchars($row["shape"]) . "</td>";
echo "<td class='py-3 px-6 text-left'>" . htmlspecialchars($row["size"]) . "</td>";
echo "<td class='py-3 px-6 text-left'>" . htmlspecialchars($row["color"]) . "</td>";
echo "<td class='py-3 px-6 text-left'>" . htmlspecialchars($row["clarity"]) . "</td>";
echo "<td class='py-3 px-6 text-center'><div class='flex items-center justify-center gap-2'><button type='button' class='bg-blue-500 text-white py-1 px-3 rounded text-xs'>Long</button><button type='button' class='bg-gray-500 text-white py-1 px-3 rounded text-xs'>Short</button></div></td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='8' class='text-center py-4'>No diamonds match the filter criteria.</td></tr>";
}
?>
</tbody>
</table>
</div>
<!-- Configurations & Action Button -->
<div class="mt-8 p-6 bg-gray-50 rounded-lg">
<h5 class="text-xl font-bold text-gray-700 mb-4">CONFIGURATIONS</h5>
<div class="space-y-4">
<div class="flex items-center">
<strong class="w-40">SHOW VIDEO</strong>
<div class="custom-radio flex items-center gap-4">
<input type="radio" id="video_yes" name="show_video" value="YES" checked><label
for="video_yes">Yes</label>
<input type="radio" id="video_no" name="show_video" value="NO"><label for="video_no">No</label>
</div>
</div>
<div class="flex items-center">
<strong class="w-40">SHOW IMAGES</strong>
<div class="custom-radio flex items-center gap-4">
<input type="radio" id="images_yes" name="show_images" value="YES" checked><label
for="images_yes">Yes</label>
<input type="radio" id="images_no" name="show_images" value="NO"><label
for="images_no">No</label>
</div>
</div>
<div class="flex items-center">
<strong class="w-40">SHOW DATA SHEET</strong>
<div class="custom-radio flex items-center gap-4">
<input type="radio" id="sheet_yes" name="show_sheet" value="YES" checked><label
for="sheet_yes">Yes</label>
<input type="radio" id="sheet_no" name="show_sheet" value="NO"><label for="sheet_no">No</label>
</div>
</div>
<div class="flex items-center">
<strong class="w-40">SHOW CERTIFICATE</strong>
<div class="custom-radio flex items-center gap-4">
<input type="radio" id="cert_yes" name="show_certificate" value="YES" checked><label
for="cert_yes">Yes</label>
<input type="radio" id="cert_no" name="show_certificate" value="NO"><label
for="cert_no">No</label>
</div>
</div>
<div class="flex items-center">
<strong class="w-40">SHARE LINK</strong>
<div class="custom-checkbox flex items-center gap-4">
<input type="checkbox" id="link_long" name="share_link[]" value="Long" checked><label
for="link_long">Long</label>
<input type="checkbox" id="link_short" name="share_link[]" value="Short"><label
for="link_short">Short</label>
</div>
</div>
</div>
<div class="mt-6 text-center">
<input type="hidden" name="customer_id_for_action" id="customer_id_for_action">
<button type="submit"
class="bg-pink-600 hover:bg-pink-700 text-white font-bold py-3 px-8 rounded-lg">Share &
Download</button>
</div>
</div>
</form>
</div>
<script>
document.getElementById('select_all').addEventListener('click', function (event) {
document.querySelectorAll('.diamond_checkbox').forEach(checkbox => checkbox.checked = event.target.checked);
});
const customerSelect = document.getElementById('customer_contact');
const customerNameInput = document.getElementById('customer_name');
const customerIdForActionInput = document.getElementById('customer_id_for_action');
customerSelect.addEventListener('change', function () {
const selectedOption = this.options[this.selectedIndex];
customerNameInput.value = selectedOption.dataset.name || '';
customerIdForActionInput.value = this.value; // Pass customer ID to the action form
});
</script>
<?php
$conn->close();
include 'footer.php';
?>