-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared_links.php
More file actions
102 lines (95 loc) · 5.71 KB
/
shared_links.php
File metadata and controls
102 lines (95 loc) · 5.71 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
<?php
// shared_links.php
include 'header.php';
include 'sidebar.php';
// --- Search Logic ---
$search_term = isset($_GET['search']) ? trim($_GET['search']) : '';
// Base SQL query with a JOIN to get customer name
$sql = "SELECT sl.*, c.customer_name
FROM shared_links sl
JOIN customers c ON sl.customer_id = c.id";
if (!empty($search_term)) {
$search_like = "%" . $search_term . "%";
// Add a WHERE clause to search by customer name
$sql .= " WHERE c.customer_name LIKE ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $search_like);
$stmt->execute();
$result = $stmt->get_result();
} else {
// If no search term, fetch all results
$sql .= " ORDER BY sl.date_time DESC"; // Order by most recent
$result = $conn->query($sql);
}
?>
<!-- Main Content -->
<div class="bg-white p-8 rounded-lg shadow-md w-full">
<div class="flex justify-between items-center mb-6">
<h4 class="text-2xl font-bold text-gray-700">Shared Links</h4>
<!-- Search Form -->
<form action="shared_links.php" method="GET" class="flex items-center">
<label for="search" class="mr-2 text-gray-600">Search:</label>
<input type="text" name="search" id="search" value="<?php echo htmlspecialchars($search_term); ?>"
class="shadow-sm border rounded py-2 px-3 text-gray-700 focus:outline-none focus:ring-2 focus:ring-pink-500"
placeholder="Search by customer...">
<button type="submit" class="ml-2 bg-pink-600 hover:bg-pink-700 text-white font-bold py-2 px-4 rounded">
<i class="fas fa-search"></i>
</button>
</form>
</div>
<!-- Data Table -->
<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">SRNO</th>
<th class="py-3 px-6 text-left">Customer</th>
<th class="py-3 px-6 text-center">Video</th>
<th class="py-3 px-6 text-center">Image</th>
<th class="py-3 px-6 text-center">Sheet</th>
<th class="py-3 px-6 text-center">Certificate</th>
<th class="py-3 px-6 text-center">Status</th>
<th class="py-3 px-6 text-left">Date Time</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()) {
// Determine status color
$status_color = $row['status'] == 'ENABLED' ? 'bg-green-200 text-green-800' : 'bg-red-200 text-red-800';
$video_badge = $row['video'] == 'YES' ? 'bg-green-200 text-green-800' : 'bg-red-200 text-red-800';
$image_badge = $row['image'] == 'YES' ? 'bg-green-200 text-green-800' : 'bg-red-200 text-red-800';
$sheet_badge = $row['sheet'] == 'YES' ? 'bg-green-200 text-green-800' : 'bg-red-200 text-red-800';
$certificate_badge = $row['certificate'] == 'YES' ? 'bg-green-200 text-green-800' : 'bg-red-200 text-red-800';
echo "<tr class='border-b border-gray-200 hover:bg-gray-100'>";
echo "<td class='py-3 px-6 text-left whitespace-nowrap'>" . $sr_no++ . "</td>";
echo "<td class='py-3 px-6 text-left'>" . htmlspecialchars($row["customer_name"]) . "</td>";
echo "<td class='py-3 px-6 text-center'><span class='py-1 px-3 rounded-full text-xs " . $video_badge . "'>" . htmlspecialchars($row["video"]) . "</span></td>";
echo "<td class='py-3 px-6 text-center'><span class='py-1 px-3 rounded-full text-xs " . $image_badge . "'>" . htmlspecialchars($row["image"]) . "</span></td>";
echo "<td class='py-3 px-6 text-center'><span class='py-1 px-3 rounded-full text-xs " . $sheet_badge . "'>" . htmlspecialchars($row["sheet"]) . "</span></td>";
echo "<td class='py-3 px-6 text-center'><span class='py-1 px-3 rounded-full text-xs " . $certificate_badge . "'>" . htmlspecialchars($row["certificate"]) . "</span></td>";
echo "<td class='py-3 px-6 text-center'><span class='py-1 px-3 rounded-full text-xs " . $status_color . "'>" . htmlspecialchars($row["status"]) . "</span></td>";
echo "<td class='py-3 px-6 text-left'>" . date("d/m/Y h:i A", strtotime($row["date_time"])) . "</td>";
echo "<td class='py-3 px-6 text-center'>";
echo "<div class='flex item-center justify-center'>";
echo "<a href='shared_links_edit.php?id=" . $row['id'] . "' class='w-4 mr-2 transform hover:text-purple-500 hover:scale-110'><i class='fas fa-pencil-alt'></i></a>";
echo "<a href='shared_links_delete.php?id=" . $row['id'] . "' onclick='return confirm(\"Are you sure you want to delete this link?\");' class='w-4 mr-2 transform hover:text-red-500 hover:scale-110'><i class='fas fa-trash-alt'></i></a>";
echo "</div>";
echo "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='9' class='text-center py-4'>No shared links found.</td></tr>";
}
$conn->close();
?>
</tbody>
</table>
</div>
</div>
<?php
include 'footer.php';
?>