Settings
Google OAuth 2.0 Settings
These credentials are required for Google Login. You can get them from the Google Cloud Console.
The authorized redirect URI is:
prepare('UPDATE settings SET setting_value = ? WHERE setting_key = ?'); $stmt->execute([$google_client_id, 'google_client_id']); $stmt->execute([$google_client_secret, 'google_client_secret']); $success_message = 'Google settings updated successfully!'; } catch (PDOException $e) { $error_message = 'Database error updating Google settings: ' . $e->getMessage(); } } // Handle Permissions form submission if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save_permissions'])) { if (!can($_SESSION['user_role_id'], 'permission', 'update')) { header('Location: index.php?error=access_denied'); exit; } try { $pdo->beginTransaction(); $permissions = $_POST['permissions'] ?? []; $stmt_roles = $pdo->query('SELECT id FROM roles'); $db_roles_ids = $stmt_roles->fetchAll(PDO::FETCH_COLUMN); $delete_stmt = $pdo->prepare('DELETE FROM role_permissions WHERE role_id = ?'); $insert_stmt = $pdo->prepare('INSERT INTO role_permissions (role_id, resource, action, fields) VALUES (?, ?, ?, ?)'); foreach ($db_roles_ids as $role_id) { $delete_stmt->execute([$role_id]); if (isset($permissions[$role_id])) { foreach (['asset', 'user', 'category', 'location', 'role', 'permission'] as $resource) { foreach (['create', 'read', 'update', 'delete'] as $action) { if (isset($permissions[$role_id][$resource][$action]['enabled']) && $permissions[$role_id][$resource][$action]['enabled'] == '1') { $fields = (in_array($action, ['read', 'update', 'create'])) ? ($permissions[$role_id][$resource][$action]['fields'] ?? '*') : null; if (empty($fields)) $fields = '*'; $insert_stmt->execute([$role_id, $resource, $action, $fields]); } } } } } $pdo->commit(); $success_message = 'Permissions updated successfully!'; } catch (PDOException $e) { if ($pdo->inTransaction()) $pdo->rollBack(); $error_message = 'Database error: ' . $e->getMessage(); } } // Fetch data for display $google_settings = []; if ($is_super_admin) { try { $stmt = $pdo->query("SELECT setting_key, setting_value FROM settings WHERE setting_key IN ('google_client_id', 'google_client_secret')"); $google_settings_raw = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($google_settings_raw as $row) { $google_settings[$row['setting_key']] = $row['setting_value']; } } catch (PDOException $e) { $error_message = "Database error fetching Google settings: " . $e->getMessage(); } } try { $roles_stmt = $pdo->query('SELECT * FROM roles ORDER BY name'); $roles = $roles_stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { $error_message = "Database error fetching roles: " . $e->getMessage(); $roles = []; } $resources = ['asset', 'user', 'category', 'location', 'role', 'permission']; $actions = ['create', 'read', 'update', 'delete']; function get_permissions() { try { $pdo_func = db(); $stmt = $pdo_func->query('SELECT * FROM role_permissions ORDER BY role_id, resource, action'); return $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { return ['error' => 'Database error: ' . $e->getMessage()]; } } $permissions_from_db = get_permissions(); $grouped_permissions = []; if (!isset($permissions_from_db['error'])) { foreach ($permissions_from_db as $p) { $grouped_permissions[$p['role_id']][$p['resource']][$p['action']] = $p['fields']; } } ?>
These credentials are required for Google Login. You can get them from the Google Cloud Console.
The authorized redirect URI is: