class DB {
private static $conn;
public static function connect() {
if (!self::$conn) {
$cfg = require __DIR__.'/../config/database.php';
self::$conn = new PDO(
"mysql:host={$cfg['host']};dbname={$cfg['db']}",
$cfg['user'],
$cfg['pass'],
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
}
return self::$conn;
}
}
class Guard {
public static function auth() {
if (!isset($_SESSION['user'])) {
header('Location: /login.php'); exit;
}
}
public static function role(array $roles) {
if (!in_array($_SESSION['user']['role'], $roles)) {
http_response_code(403); exit('Forbidden');
}
}
public static function branch($branchId) {
if ($_SESSION['user']['role'] !== 'SUPER_ADMIN'
&& $_SESSION['user']['branch_id'] != $branchId) {
exit('Branch Isolation Violation');
}
}
}
class Audit {
public static function log($action, $entity, $entityId) {
$db = DB::connect();
$db->prepare("
INSERT INTO audit_trail
(user_id, branch_id, action, entity_type, entity_id, ip_address, user_agent)
VALUES (?,?,?,?,?,?,?)
")->execute([
$_SESSION['user']['id'] ?? null,
$_SESSION['user']['branch_id'] ?? null,
$action,
$entity,
$entityId,
$_SERVER['REMOTE_ADDR'],
$_SERVER['HTTP_USER_AGENT']
]);
}
}
| ( ! ) Fatal error: Uncaught Error: Class "Guard" not found in E:\Program_Files\wamp64\www\cctv\19.12.25\modules\approvals\submit.php on line 6 |
| ( ! ) Error: Class "Guard" not found in E:\Program_Files\wamp64\www\cctv\19.12.25\modules\approvals\submit.php on line 6 |
| Call Stack |
| # | Time | Memory | Function | Location |
| 1 | 0.0025 | 368768 | {main}( ) | ...\submit.php:0 |