diff --git a/commit_message.txt b/commit_message.txt index ae313a4..bd60dfc 100644 --- a/commit_message.txt +++ b/commit_message.txt @@ -1 +1,7 @@ -Summary of label printing changes written. +Plan: Change the "Invite User" button text to "Add User" in the User Management page to make it more descriptive and match the modal's title. + +Changed: +* `index.php`: Updated the button text and English localization attribute (`data-en`) from "Invite User" to "Add User". + +Next: +Check out the User Management page to confirm the button now says "Add User". Let me know if you need anything else! diff --git a/debug.log b/debug.log index 9776fbe..fcf3c53 100644 --- a/debug.log +++ b/debug.log @@ -1,28 +1 @@ -2026-02-25 09:56:17 - Items case hit -2026-02-25 09:56:38 - Requesting AI. UUID: [e1f9b5b3-fcef-4c8d-87d2-8630b1f72491] CFG: {"base_url":"https:\/\/flatlogic.com","responses_path":"\/projects\/38471\/ai-request","project_id":"38471","project_uuid":"e1f9b5b3-fcef-4c8d-87d2-8630b1f72491","project_header":"Project-UUID","default_model":"gpt-4o-mini","timeout":30,"verify_tls":true} -2026-02-25 10:03:48 - Items case hit -2026-02-25 11:48:14 - Items case hit -2026-02-25 11:49:27 - Items case hit -2026-02-25 11:51:57 - Items case hit -2026-02-25 12:41:41 - Items case hit -2026-02-25 12:45:17 - Items case hit -2026-02-25 13:33:02 - Items case hit -2026-02-25 14:04:18 - Items case hit -2026-02-25 14:06:09 - Items case hit -2026-02-25 14:10:50 - Items case hit -2026-02-25 15:28:54 - Items case hit -2026-02-26 02:55:12 - Items case hit -2026-02-26 02:56:47 - Items case hit -2026-02-26 03:00:52 - Items case hit -2026-02-26 03:01:01 - Items case hit -2026-02-26 03:01:48 - Requesting AI. UUID: [e1f9b5b3-fcef-4c8d-87d2-8630b1f72491] CFG: {"base_url":"https:\/\/flatlogic.com","responses_path":"\/projects\/38471\/ai-request","project_id":"38471","project_uuid":"e1f9b5b3-fcef-4c8d-87d2-8630b1f72491","project_header":"Project-UUID","default_model":"gpt-4o-mini","timeout":30,"verify_tls":true} -2026-02-26 03:05:30 - Requesting AI. UUID: [e1f9b5b3-fcef-4c8d-87d2-8630b1f72491] CFG: {"base_url":"https:\/\/flatlogic.com","responses_path":"\/projects\/38471\/ai-request","project_id":"38471","project_uuid":"e1f9b5b3-fcef-4c8d-87d2-8630b1f72491","project_header":"Project-UUID","default_model":"gpt-4o-mini","timeout":30,"verify_tls":true} -2026-02-26 03:08:42 - Items case hit -2026-02-26 03:09:08 - Items case hit -2026-02-26 03:09:24 - Requesting AI. UUID: [e1f9b5b3-fcef-4c8d-87d2-8630b1f72491] CFG: {"base_url":"https:\/\/flatlogic.com","responses_path":"\/projects\/38471\/ai-request","project_id":"38471","project_uuid":"e1f9b5b3-fcef-4c8d-87d2-8630b1f72491","project_header":"Project-UUID","default_model":"gpt-4o-mini","timeout":30,"verify_tls":true} -2026-02-26 03:09:34 - Items case hit -2026-02-26 03:10:28 - Items case hit -2026-02-26 03:23:07 - Items case hit -2026-02-26 03:25:23 - Items case hit -2026-02-26 03:29:29 - Items case hit -2026-02-26 03:30:39 - Items case hit +[INFO] AI agent editing: index.php diff --git a/index.php b/index.php index 8ebe8aa..b8f23eb 100644 --- a/index.php +++ b/index.php @@ -37,8 +37,10 @@ if ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') || (isset($_SERVER[ session_start(); if (isset($_GET['action']) && $_GET['action'] === 'switch_outlet') { $target = (int)$_GET['id']; - if (($_SESSION['user_role_name'] ?? '') === 'Administrator') { - $_SESSION['outlet_id'] = $target === 0 ? null : $target; + $is_admin = ($_SESSION['user_role_name'] ?? '') === 'Administrator'; + $assigned_outlets = isset($_SESSION['assigned_outlets']) ? explode(',', $_SESSION['assigned_outlets']) : []; + if ($is_admin || in_array($target, $assigned_outlets)) { + $_SESSION['outlet_id'] = ($target === 0 && $is_admin) ? null : $target; } header("Location: " . ($_SERVER['HTTP_REFERER'] ?? 'index.php')); exit; @@ -345,6 +347,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['login'])) { $_SESSION['username'] = $u['username']; $_SESSION['user_role_name'] = $u['role_name']; $_SESSION['outlet_id'] = $u['outlet_id']; + $_SESSION['assigned_outlets'] = $u['assigned_outlets']; // Fetch permissions from the new role_permissions table $permStmt = db()->prepare("SELECT permission FROM role_permissions WHERE role_id = ?"); @@ -2659,10 +2662,13 @@ if (isset($_POST['add_hr_department'])) { $group_id = (int)($_POST['group_id'] ?? 0) ?: null; if ($username && $password) { $hashed_password = password_hash($password, PASSWORD_DEFAULT); - $outlet_id = !empty($_POST['outlet_id']) ? (int)$_POST['outlet_id'] : null; - $stmt = db()->prepare("INSERT INTO users (username, password, email, phone, group_id, outlet_id) VALUES (?, ?, ?, ?, ?, ?)"); + $outlet_ids = !empty($_POST['outlet_ids']) && is_array($_POST['outlet_ids']) ? array_filter($_POST['outlet_ids'], function($v) { return $v !== ''; }) : []; + $outlet_id = !empty($outlet_ids) ? (int)reset($outlet_ids) : null; + $assigned_outlets = !empty($outlet_ids) ? implode(',', array_map('intval', $outlet_ids)) : null; + + $stmt = db()->prepare("INSERT INTO users (username, password, email, phone, group_id, outlet_id, assigned_outlets) VALUES (?, ?, ?, ?, ?, ?, ?)"); try { - $stmt->execute([$username, $hashed_password, $email, $phone, $group_id, $outlet_id]); + $stmt->execute([$username, $hashed_password, $email, $phone, $group_id, $outlet_id, $assigned_outlets]); $message = "User added successfully!"; } catch (PDOException $e) { if ($e->getCode() == '23000') { @@ -2717,10 +2723,13 @@ if (isset($_POST['add_hr_department'])) { $phone = $_POST['phone'] ?? ''; $group_id = (int)($_POST['group_id'] ?? 0) ?: null; $status = $_POST['status'] ?? 'active'; - $outlet_id = !empty($_POST['outlet_id']) ? (int)$_POST['outlet_id'] : null; + $outlet_ids = !empty($_POST['outlet_ids']) && is_array($_POST['outlet_ids']) ? array_filter($_POST['outlet_ids'], function($v) { return $v !== ''; }) : []; + $outlet_id = !empty($outlet_ids) ? (int)reset($outlet_ids) : null; + $assigned_outlets = !empty($outlet_ids) ? implode(',', array_map('intval', $outlet_ids)) : null; + if ($id && $username) { - $stmt = db()->prepare("UPDATE users SET username = ?, email = ?, phone = ?, group_id = ?, status = ?, outlet_id = ? WHERE id = ?"); - $stmt->execute([$username, $email, $phone, $group_id, $status, $outlet_id, $id]); + $stmt = db()->prepare("UPDATE users SET username = ?, email = ?, phone = ?, group_id = ?, status = ?, outlet_id = ?, assigned_outlets = ? WHERE id = ?"); + $stmt->execute([$username, $email, $phone, $group_id, $status, $outlet_id, $assigned_outlets, $id]); if (!empty($_POST['password'])) { $hashed_password = password_hash($_POST['password'], PASSWORD_DEFAULT); @@ -4776,10 +4785,18 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System'; query("SELECT * FROM outlets WHERE status = 'active'")->fetchAll(PDO::FETCH_ASSOC); + $is_admin = ($_SESSION['user_role_name'] ?? '') === 'Administrator'; + $assigned_outlets_str = $_SESSION['assigned_outlets'] ?? ''; + $assigned_outlets_arr = array_filter(explode(',', $assigned_outlets_str)); + if ($is_admin || count($assigned_outlets_arr) > 1): + if ($is_admin) { + $outlets = db()->query("SELECT * FROM outlets WHERE status = 'active'")->fetchAll(PDO::FETCH_ASSOC); + } else { + $in_clause = implode(',', array_map('intval', $assigned_outlets_arr)); + $outlets = db()->query("SELECT * FROM outlets WHERE status = 'active' AND id IN ($in_clause)")->fetchAll(PDO::FETCH_ASSOC); + } $cur_out = $_SESSION['outlet_id'] ?? 0; - $cur_name = 'All Outlets'; + $cur_name = $is_admin ? 'All Outlets' : (count($outlets) > 0 ? $outlets[0]['name'] : 'Select Outlet'); foreach ($outlets as $o) { if ($o['id'] == $cur_out) $cur_name = $o['name']; } ?> @@ -10217,18 +10236,24 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System'; - +
Global / All Outlets'; + } else { + foreach (($data["outlets"] ?? []) as $out) { + if (in_array($out["id"], $assigned)) { + echo '' . htmlspecialchars($out["name"]) . ''; + } } } - echo htmlspecialchars($out_name); ?> - +
@@ -10242,24 +10267,18 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System'; - @@ -10295,13 +10314,16 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
- - - - + + +
Hold Ctrl/Cmd to select multiple outlets.
@@ -11252,13 +11274,14 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
- - +
Hold Ctrl/Cmd to select multiple outlets.
+EOD; + +$new_add_ui = << + + +
Hold Ctrl/Cmd to select multiple outlets.
+ +EOD; + +$content = str_replace($old_add_ui, $new_add_ui, $content); + +// edit_user form +$old_edit_ui = << + + + +EOD; + +$new_edit_ui = << + + +
Hold Ctrl/Cmd to select multiple outlets.
+ +EOD; + +$content = str_replace($old_edit_ui, $new_edit_ui, $content); + +file_put_contents($file, $content); +echo "Patch 3 applied.\n"; diff --git a/patch_users_4.php b/patch_users_4.php new file mode 100644 index 0000000..724466a --- /dev/null +++ b/patch_users_4.php @@ -0,0 +1,45 @@ + + + + +EOD; + +$new_action = << + + + + +
+ + +
+ + +EOD; + +$content = str_replace($old_action, $new_action, $content); +file_put_contents($file, $content); +echo "Patch 4 applied.\n"; diff --git a/patch_users_5.php b/patch_users_5.php new file mode 100644 index 0000000..9f9750c --- /dev/null +++ b/patch_users_5.php @@ -0,0 +1,43 @@ + + +
+EOD; + +$new_display = << + Global / All Outlets'; + } else { + foreach ((\$data["outlets"] ?? []) as \$out) { + if (in_array(\$out["id"], \$assigned)) { + echo '' . htmlspecialchars(\$out["name"]) . ''; + } + } + } + ?> + +EOD; + +$content = str_replace($old_display, $new_display, $content); +file_put_contents($file, $content); +echo "Patch 5 applied.\n"; diff --git a/patch_users_6.php b/patch_users_6.php new file mode 100644 index 0000000..9b12e14 --- /dev/null +++ b/patch_users_6.php @@ -0,0 +1,44 @@ +prepare("INSERT INTO users (username, password, email, phone, group_id, outlet_id, assigned_outlets) VALUES (?, ?, ?, ?, ?, ?, ?)"); +EOD; + +$new_add = <<prepare("INSERT INTO users (username, password, email, phone, group_id, outlet_id, assigned_outlets) VALUES (?, ?, ?, ?, ?, ?, ?)"); +EOD; +$content = str_replace($old_add, $new_add, $content); + +// edit_user +$old_edit = <<prepare("UPDATE users SET username = ?, email = ?, phone = ?, group_id = ?, status = ?, outlet_id = ?, assigned_outlets = ? WHERE id = ?"); +EOD; + +$new_edit = <<prepare("UPDATE users SET username = ?, email = ?, phone = ?, group_id = ?, status = ?, outlet_id = ?, assigned_outlets = ? WHERE id = ?"); +EOD; +$content = str_replace($old_edit, $new_edit, $content); + +file_put_contents($file, $content); +echo "Patch 6 applied.\n";