« Back to History
role_redirect.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php function role_redirect_get_map($company_id) { $file = __DIR__ . "/../../storage/cache/role_redirects_{$company_id}.json"; if (file_exists($file)) { $map = json_decode(file_get_contents($file), true); if (is_array($map)) { return $map; } } return []; } function role_redirect_get_path($role, $company_id) { $role = strtolower(trim($role)); $map = role_redirect_get_map($company_id); if (isset($map[$role])) { return $map[$role]; } return '/erp/index.php'; // fallback } function role_redirect_rebuild_cache($pdo, $company_id) { $stmt = $pdo->prepare(" SELECT role, redirect_path FROM role_redirects WHERE company_id = :cid AND is_active = 1 "); $stmt->execute(['cid' => $company_id]); $map = []; while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $map[strtolower($row['role'])] = $row['redirect_path']; } $file = __DIR__ . "/../../storage/cache/role_redirects_{$company_id}.json"; if (!is_dir(dirname($file))) { mkdir(dirname($file), 0777, true); } file_put_contents($file, json_encode($map, JSON_PRETTY_PRINT)); }