Ticket

Ticket connect_error) { die(“Connection failed: ” . $conn->connect_error); } session_start(); function redirect($url) { header(“Location: $url”); exit(); } // Function to check user roles function checkUserRole($requiredRole) { if (!isset($_SESSION[‘user’]) || $_SESSION[‘user’][‘role’] != $requiredRole) { die(“Unauthorized access”); } } // Function to get tickets based on user role function getTickets() { global $conn; $userRole = $_SESSION[‘user’][‘role’]; $userId = $_SESSION[‘user’][‘id’]; if ($userRole == ‘Administrator’) { $sql = “SELECT * FROM tickets ORDER BY open_date”; } elseif ($userRole == ‘Moderator’) { $sql = “SELECT * FROM tickets WHERE location_id IN (SELECT location_id FROM user_permissions WHERE user_id = $userId) ORDER BY open_date”; } else { $sql = “SELECT * FROM tickets WHERE user_id = $userId ORDER BY open_date”; } $result = $conn->query($sql); if ($result->num_rows > 0) { return $result->fetch_all(MYSQLI_ASSOC); } else { return []; } } // Function to get reports function getReports($startDate, $endDate, $locationId) { global $conn; $sql = “SELECT * FROM tickets WHERE location_id = $locationId AND open_date BETWEEN ‘$startDate’ AND ‘$endDate'”; $result = $conn->query($sql); if ($result->num_rows > 0) { return $result->fetch_all(MYSQLI_ASSOC); } else { return []; } } // Example usage: // checkUserRole(‘Administrator’); // Check if the user has Administrator role // $tickets = getTickets(); // Get tickets based on user role // $reports = getReports(‘2023-01-01’, ‘2023-12-31’, 1); // Get reports for a location and date range ?>