connect_error) { die("Connection failed: " . $conn->connect_error); } } // Simple router switch (true) { case $requestPath == '/' || $requestPath == '': require_once 'controllers/DashboardController.php'; $controller = new DashboardController($conn); $controller->index(); break; case preg_match('/^\/ticket\/(\d+)$/', $requestPath, $matches): require_once 'controllers/TicketController.php'; $controller = new TicketController($conn); $controller->view($matches[1]); break; case $requestPath == '/ticket/create': require_once 'controllers/TicketController.php'; $controller = new TicketController($conn); $controller->create(); break; // API Routes - these handle their own database connections case $requestPath == '/api/update_ticket.php': require_once 'api/update_ticket.php'; break; case $requestPath == '/api/add_comment.php': require_once 'api/add_comment.php'; break; // Legacy support for old URLs case $requestPath == '/dashboard.php': header("Location: /"); exit; case preg_match('/^\/ticket\.php/', $requestPath) && isset($_GET['id']): header("Location: /ticket/" . $_GET['id']); exit; default: // 404 Not Found header("HTTP/1.0 404 Not Found"); echo '404 Page Not Found'; break; } // Close database connection if it was opened if (isset($conn)) { $conn->close(); } ?>