-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_panel.php
34 lines (28 loc) · 1.15 KB
/
admin_panel.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
<?php
session_start();
include 'config.php'; // Contains your database connection information
// Check if the admin is logged in, if not, redirect to the login page
if (!isset($_SESSION['admin_id']) || !isset($_SESSION['admin_type'])) {
echo json_encode(['error' => 'Not logged in']);
exit();
}
// Retrieve sorting and searching parameters
$sortOrder = isset($_GET['sort']) && $_GET['sort'] === 'oldest' ? 'ASC' : 'DESC';
$searchTerm = isset($_GET['search']) ? '%'.$_GET['search'].'%' : '%';
// Prepare and execute the SQL statement with sorting and searching
$query = "SELECT query_id, create_date, name, department, query_type, image_video, website_link, description, status FROM Queries WHERE (name LIKE ? OR department LIKE ? OR query_type LIKE ?) ORDER BY create_date $sortOrder";
if ($stmt = $conn->prepare($query)) {
$stmt->bind_param("sss", $searchTerm, $searchTerm, $searchTerm);
$stmt->execute();
$result = $stmt->get_result();
// Fetch the results
$queries = [];
while ($row = $result->fetch_assoc()) {
$queries[] = $row;
}
$stmt->close();
}
$conn->close();
// Return the data as JSON
echo json_encode($queries);
?>