Files
pagedev.pl/index.php
2026-01-29 21:08:01 +01:00

157 lines
3.8 KiB
PHP

<?php
session_start();
// Autoloader dla klas
spl_autoload_register(function ($class) {
$paths = [
__DIR__ . '/controllers/' . $class . '.php',
__DIR__ . '/models/' . $class . '.php'
];
foreach ($paths as $path) {
if (file_exists($path)) {
require_once $path;
return;
}
}
});
// Pobieranie ścieżki z URL (odporne na root i podkatalog)
$requestUri = $_SERVER['REQUEST_URI'];
$uriPath = parse_url($requestUri, PHP_URL_PATH) ?? '/';
$basePath = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
if ($basePath && $basePath !== '.' && strpos($uriPath, $basePath) === 0) {
$uriPath = substr($uriPath, strlen($basePath));
}
$path = trim($uriPath, '/');
// Debug - usuń po naprawie
// error_log("REQUEST_URI: " . $requestUri);
// error_log("Base Path: " . $basePath);
// error_log("Path: " . $path);
// Mapowanie przyjaznych URLi na akcje
$routes = [
'' => 'login',
'logowanie' => 'login',
'uwierzytelnianie' => 'authenticate',
'weryfikacja' => 'verify',
'weryfikuj-kod' => 'verify-code',
'panel' => 'dashboard',
'dashboard' => 'dashboard',
'pulpit' => 'dashboard',
'wyloguj-sie' => 'logout',
'inicjalizacja' => 'init',
'notatnik' => 'notes',
'notatki' => 'notes',
'notatka/nowa' => 'note-create',
'notatka/edytuj' => 'note-edit',
'notatka/zapisz' => 'note-save',
'notatka/usun' => 'note-delete',
'kalendarz' => 'calendar',
'wydarzenie/nowe' => 'event-create',
'wydarzenie/edytuj' => 'event-edit',
'wydarzenie/zapisz' => 'event-save',
'wydarzenie/usun' => 'event-delete',
];
// Obsługa starych URLi z parametrem action dla kompatybilności
if (isset($_GET['action'])) {
$action = $_GET['action'];
} else {
$action = $routes[$path] ?? 'login';
}
switch ($action) {
case 'init':
$controller = new InitController();
$controller->index();
break;
case 'login':
$controller = new LoginController();
$controller->index();
break;
case 'authenticate':
$controller = new LoginController();
$controller->authenticate();
break;
case 'verify':
$controller = new LoginController();
$controller->verify();
break;
case 'verify-code':
$controller = new LoginController();
$controller->verifyCode();
break;
case 'dashboard':
$controller = new DashboardController();
$controller->index();
break;
case 'notes':
$controller = new NotesController();
$controller->index();
break;
case 'note-create':
$controller = new NotesController();
$controller->create();
break;
case 'note-edit':
$controller = new NotesController();
$controller->edit();
break;
case 'note-save':
$controller = new NotesController();
$controller->save();
break;
case 'note-delete':
$controller = new NotesController();
$controller->delete();
break;
case 'calendar':
$controller = new CalendarController();
$controller->index();
break;
case 'event-create':
$controller = new CalendarController();
$controller->create();
break;
case 'event-edit':
$controller = new CalendarController();
$controller->edit();
break;
case 'event-save':
$controller = new CalendarController();
$controller->save();
break;
case 'event-delete':
$controller = new CalendarController();
$controller->delete();
break;
case 'logout':
session_destroy();
header('Location: /logowanie');
exit;
break;
default:
header('Location: /logowanie');
exit;
}