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']; } ?>