Fixed MAJOR bugs, currently at a semi-stable state
This commit is contained in:
62
index.php
62
index.php
@ -2,52 +2,64 @@
|
||||
// Main entry point for the application
|
||||
require_once 'config/config.php';
|
||||
|
||||
// Parse the URL
|
||||
// Parse the URL - no need to remove base path since we're at document root
|
||||
$request = $_SERVER['REQUEST_URI'];
|
||||
$basePath = '/tinkertickets'; // Adjust based on your installation path
|
||||
$request = str_replace($basePath, '', $request);
|
||||
|
||||
// Create database connection
|
||||
$conn = new mysqli(
|
||||
$GLOBALS['config']['DB_HOST'],
|
||||
$GLOBALS['config']['DB_USER'],
|
||||
$GLOBALS['config']['DB_PASS'],
|
||||
$GLOBALS['config']['DB_NAME']
|
||||
);
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
// Simple router
|
||||
switch (true) {
|
||||
case $request == '/' || $request == '':
|
||||
case $requestPath == '/' || $requestPath == '':
|
||||
require_once 'controllers/DashboardController.php';
|
||||
$controller = new DashboardController($conn);
|
||||
$controller->index();
|
||||
break;
|
||||
|
||||
case preg_match('/^\/ticket\?id=(\d+)$/', $request, $matches) ||
|
||||
preg_match('/^\/ticket\/(\d+)$/', $request, $matches):
|
||||
case preg_match('/^\/ticket\/(\d+)$/', $requestPath, $matches):
|
||||
require_once 'controllers/TicketController.php';
|
||||
$controller = new TicketController($conn);
|
||||
$controller->view($matches[1]);
|
||||
break;
|
||||
|
||||
case $request == '/ticket/create':
|
||||
case $requestPath == '/ticket/create':
|
||||
require_once 'controllers/TicketController.php';
|
||||
$controller = new TicketController($conn);
|
||||
$controller->create();
|
||||
break;
|
||||
|
||||
case preg_match('/^\/ticket\/(\d+)\/update$/', $request, $matches):
|
||||
require_once 'controllers/TicketController.php';
|
||||
$controller = new TicketController($conn);
|
||||
$controller->update($matches[1]);
|
||||
// API Routes - these handle their own database connections
|
||||
case $requestPath == '/api/update_ticket.php':
|
||||
require_once 'api/update_ticket.php';
|
||||
break;
|
||||
|
||||
case preg_match('/^\/ticket\/(\d+)\/comment$/', $request, $matches):
|
||||
require_once 'controllers/CommentController.php';
|
||||
$controller = new CommentController($conn);
|
||||
$controller->addComment($matches[1]);
|
||||
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");
|
||||
@ -55,4 +67,8 @@ switch (true) {
|
||||
break;
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
// Close database connection if it was opened
|
||||
if (isset($conn)) {
|
||||
$conn->close();
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user