- Handler funkce extrahovany z API souboru do api/admin/handlers/ - config.php rozdeleny na helpers.php (funkce) a constants.php (konstanty) - require_once odstranen z class souboru (AuditLog, JWTAuth, LeaveNotification) - vendor/autoload.php presunuto do config.php bootstrap - totp-handlers.php: pridany use deklarace pro TwoFactorAuth - phpstan.neon: bootstrapFiles, scanDirectories, dynamicConstantNames - Opraveny chybejici routing bloky v totp.php a session.php Vysledek: phpcs 0 errors 0 warnings, PHPStan 0 errors, ESLint 0 errors Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
81 lines
2.9 KiB
PHP
81 lines
2.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* BOHA Automation - Leave Requests API
|
|
*
|
|
* Endpoints:
|
|
* GET /api/admin/leave-requests.php - Get own leave requests
|
|
* GET /api/admin/leave-requests.php?action=pending - Get all pending requests (approver)
|
|
* GET /api/admin/leave-requests.php?action=all - Get all requests with filters (approver)
|
|
* POST /api/admin/leave-requests.php - Submit new leave request
|
|
* POST /api/admin/leave-requests.php?action=cancel - Cancel own pending request
|
|
* POST /api/admin/leave-requests.php?action=approve - Approve a request (approver)
|
|
* POST /api/admin/leave-requests.php?action=reject - Reject a request (approver)
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once dirname(__DIR__) . '/config.php';
|
|
require_once dirname(__DIR__) . '/includes/JWTAuth.php';
|
|
require_once dirname(__DIR__) . '/includes/AuditLog.php';
|
|
require_once dirname(__DIR__) . '/includes/AttendanceHelpers.php';
|
|
require_once dirname(__DIR__) . '/includes/Mailer.php';
|
|
require_once dirname(__DIR__) . '/includes/LeaveNotification.php';
|
|
require_once __DIR__ . '/handlers/leave-requests-handlers.php';
|
|
|
|
// Set headers
|
|
setCorsHeaders();
|
|
setSecurityHeaders();
|
|
setNoCacheHeaders();
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
// Require authentication
|
|
$authData = JWTAuth::requireAuth();
|
|
AuditLog::setUser($authData['user_id'], $authData['user']['username'] ?? 'unknown');
|
|
|
|
$method = $_SERVER['REQUEST_METHOD'];
|
|
$action = $_GET['action'] ?? '';
|
|
|
|
try {
|
|
$pdo = db();
|
|
$userId = $authData['user_id'];
|
|
|
|
switch ($method) {
|
|
case 'GET':
|
|
if ($action === 'pending') {
|
|
requirePermission($authData, 'attendance.approve');
|
|
handleGetPending($pdo);
|
|
} elseif ($action === 'all') {
|
|
requirePermission($authData, 'attendance.approve');
|
|
handleGetAll($pdo);
|
|
} else {
|
|
handleGetMyRequests($pdo, $userId);
|
|
}
|
|
break;
|
|
|
|
case 'POST':
|
|
if ($action === 'cancel') {
|
|
handleCancelRequest($pdo, $userId);
|
|
} elseif ($action === 'approve') {
|
|
requirePermission($authData, 'attendance.approve');
|
|
handleApproveRequest($pdo, $userId, $authData);
|
|
} elseif ($action === 'reject') {
|
|
requirePermission($authData, 'attendance.approve');
|
|
handleRejectRequest($pdo, $userId, $authData);
|
|
} else {
|
|
handleSubmitRequest($pdo, $userId);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
errorResponse('Nepodporovaná metoda', 405);
|
|
}
|
|
} catch (PDOException $e) {
|
|
error_log('Leave requests API error: ' . $e->getMessage());
|
|
errorResponse('Chyba databáze', 500);
|
|
}
|
|
|
|
// ============================================================================
|
|
// Helper Functions
|
|
// ============================================================================
|