2025-05-16 20:02:49 -04:00
|
|
|
<?php
|
|
|
|
|
// Main entry point for the application
|
|
|
|
|
require_once 'config/config.php';
|
|
|
|
|
|
2025-09-05 11:08:56 -04:00
|
|
|
// Parse the URL - no need to remove base path since we're at document root
|
2025-05-16 20:02:49 -04:00
|
|
|
$request = $_SERVER['REQUEST_URI'];
|
|
|
|
|
|
2025-09-05 11:08:56 -04:00
|
|
|
// Remove query string for routing (but keep it available)
|
|
|
|
|
$requestPath = strtok($request, '?');
|
|
|
|
|
|
|
|
|
|
// Create database connection for non-API routes
|
|
|
|
|
if (!str_starts_with($requestPath, '/api/')) {
|
|
|
|
|
$conn = new mysqli(
|
|
|
|
|
$GLOBALS['config']['DB_HOST'],
|
|
|
|
|
$GLOBALS['config']['DB_USER'],
|
|
|
|
|
$GLOBALS['config']['DB_PASS'],
|
|
|
|
|
$GLOBALS['config']['DB_NAME']
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($conn->connect_error) {
|
|
|
|
|
die("Connection failed: " . $conn->connect_error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-16 20:02:49 -04:00
|
|
|
|
|
|
|
|
// Simple router
|
|
|
|
|
switch (true) {
|
2025-09-05 11:08:56 -04:00
|
|
|
case $requestPath == '/' || $requestPath == '':
|
2025-05-16 20:02:49 -04:00
|
|
|
require_once 'controllers/DashboardController.php';
|
|
|
|
|
$controller = new DashboardController($conn);
|
|
|
|
|
$controller->index();
|
|
|
|
|
break;
|
|
|
|
|
|
2025-09-05 11:08:56 -04:00
|
|
|
case preg_match('/^\/ticket\/(\d+)$/', $requestPath, $matches):
|
2025-05-16 20:02:49 -04:00
|
|
|
require_once 'controllers/TicketController.php';
|
|
|
|
|
$controller = new TicketController($conn);
|
|
|
|
|
$controller->view($matches[1]);
|
|
|
|
|
break;
|
|
|
|
|
|
2025-09-05 11:08:56 -04:00
|
|
|
case $requestPath == '/ticket/create':
|
2025-05-16 20:02:49 -04:00
|
|
|
require_once 'controllers/TicketController.php';
|
|
|
|
|
$controller = new TicketController($conn);
|
|
|
|
|
$controller->create();
|
|
|
|
|
break;
|
|
|
|
|
|
2025-09-05 11:08:56 -04:00
|
|
|
// API Routes - these handle their own database connections
|
|
|
|
|
case $requestPath == '/api/update_ticket.php':
|
|
|
|
|
require_once 'api/update_ticket.php';
|
2025-05-16 20:02:49 -04:00
|
|
|
break;
|
|
|
|
|
|
2025-09-05 11:08:56 -04:00
|
|
|
case $requestPath == '/api/add_comment.php':
|
|
|
|
|
require_once 'api/add_comment.php';
|
2025-05-16 20:02:49 -04:00
|
|
|
break;
|
|
|
|
|
|
2025-09-05 11:08:56 -04:00
|
|
|
// 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;
|
|
|
|
|
|
2025-05-16 20:02:49 -04:00
|
|
|
default:
|
|
|
|
|
// 404 Not Found
|
|
|
|
|
header("HTTP/1.0 404 Not Found");
|
|
|
|
|
echo '404 Page Not Found';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-05 11:08:56 -04:00
|
|
|
// Close database connection if it was opened
|
|
|
|
|
if (isset($conn)) {
|
|
|
|
|
$conn->close();
|
|
|
|
|
}
|
|
|
|
|
?>
|