diff --git a/admin/users.php b/admin/users.php index 5658438..7d030b3 100644 --- a/admin/users.php +++ b/admin/users.php @@ -18,6 +18,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $is_ratable = isset($_POST['is_ratable']) ? 1 : 0; $commission_rate = (float)($_POST['commission_rate'] ?? 0); $id = isset($_POST['id']) ? (int)$_POST['id'] : null; + $selected_outlets = $_POST['outlets'] ?? []; $profile_pic = null; if ($id) { @@ -43,6 +44,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $message = '
Username is required.
'; } else { try { + $pdo->beginTransaction(); if ($action === 'edit_user' && $id) { if (!has_permission('users_edit') && !has_permission('users_add')) { $message = '
Access Denied: You do not have permission to edit users.
'; @@ -58,6 +60,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $stmt = $pdo->prepare($sql); $stmt->execute($params); + + // Update outlets + $pdo->prepare("DELETE FROM user_outlets WHERE user_id = ?")->execute([$id]); + if (!empty($selected_outlets)) { + $stmt = $pdo->prepare("INSERT INTO user_outlets (user_id, outlet_id) VALUES (?, ?)"); + foreach ($selected_outlets as $outlet_id) { + $stmt->execute([$id, (int)$outlet_id]); + } + } + $message = '
User updated successfully!
'; } } elseif ($action === 'add_user') { @@ -67,10 +79,22 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $password = password_hash($_POST['password'] ?: '123456', PASSWORD_DEFAULT); $stmt = $pdo->prepare("INSERT INTO users (username, password, full_name, full_name_ar, email, group_id, is_active, is_ratable, profile_pic, commission_rate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([$username, $password, $full_name, $full_name_ar, $email, $group_id, $is_active, $is_ratable, $profile_pic, $commission_rate]); + $new_user_id = $pdo->lastInsertId(); + + // Update outlets + if (!empty($selected_outlets)) { + $stmt = $pdo->prepare("INSERT INTO user_outlets (user_id, outlet_id) VALUES (?, ?)"); + foreach ($selected_outlets as $outlet_id) { + $stmt->execute([$new_user_id, (int)$outlet_id]); + } + } + $message = '
User created successfully!
'; } } + $pdo->commit(); } catch (PDOException $e) { + $pdo->rollBack(); if ($e->getCode() == 23000) { $message = '
Username or Email already exists.
'; } else { @@ -98,6 +122,7 @@ if (isset($_GET['delete'])) { } $groups = $pdo->query("SELECT * FROM user_groups ORDER BY name ASC")->fetchAll(); +$all_outlets = $pdo->query("SELECT * FROM outlets ORDER BY name ASC")->fetchAll(); $query = "SELECT u.*, g.name as group_name FROM users u @@ -106,6 +131,13 @@ $query = "SELECT u.*, g.name as group_name $users_pagination = paginate_query($pdo, $query); $users = $users_pagination['data']; +// Fetch outlets for each user +foreach ($users as &$user) { + $stmt = $pdo->prepare("SELECT outlet_id FROM user_outlets WHERE user_id = ?"); + $stmt->execute([$user['id']]); + $user['outlets'] = $stmt->fetchAll(PDO::FETCH_COLUMN); +} + include 'includes/header.php'; ?> @@ -258,6 +290,22 @@ include 'includes/header.php'; + +
+ +
+ +
+ + +
+ +
+ Select outlets this user has access to. +
+
@@ -307,6 +355,9 @@ function prepareAddForm() { document.getElementById('userPassword').required = true; document.getElementById('userImagePreviewContainer').style.display = 'none'; document.getElementById('userCommissionRate').value = '0.0'; + + // Uncheck all outlets + document.querySelectorAll('.outlet-checkbox').forEach(cb => cb.checked = false); } function prepareEditForm(user) { @@ -326,6 +377,11 @@ function prepareEditForm(user) { document.getElementById('pwdLabel').style.display = 'none'; document.getElementById('pwdHint').style.display = 'block'; + // Set outlets + document.querySelectorAll('.outlet-checkbox').forEach(cb => { + cb.checked = user.outlets && user.outlets.includes(cb.value); + }); + if (user.profile_pic) { const preview = document.getElementById('userImagePreview'); preview.src = '../' + user.profile_pic; @@ -377,4 +433,4 @@ document.getElementById('btnTranslate').addEventListener('click', function() { - \ No newline at end of file + diff --git a/pos.php b/pos.php index e9dc924..481e50b 100644 --- a/pos.php +++ b/pos.php @@ -96,7 +96,7 @@ if (!$loyalty_settings) { .product-card:active { transform: scale(0.95); } .product-card:hover { border-color: #0d6efd !important; box-shadow: 0 4px 12px rgba(0,0,0,0.08) !important; } - .category-btn { text-align: left; border: none; background: none; padding: 12px 10px; width: 100%; display: block; border-radius: 12px; color: #64748b; font-weight: 700; transition: all 0.2s; } + .category-btn { text-align: left; border: none; background: none; padding: 10px 12px; width: 100%; display: flex; align-items: center; gap: 10px; border-radius: 12px; color: #64748b; font-weight: 700; transition: all 0.2s; } .category-btn:hover { background-color: #f1f5f9; color: #0f172a; } .category-btn.active { background-color: #0d6efd; color: white; box-shadow: 0 4px 6px -1px rgba(13, 110, 253, 0.3); } .search-dropdown { position: absolute; width: 100%; z-index: 1000; max-height: 200px; overflow-y: auto; display: none; } @@ -150,16 +150,18 @@ if (!$loyalty_settings) {
+ 1): ?> + Kitchen Orders @@ -187,19 +189,19 @@ if (!$loyalty_settings) {
-
- -
@@ -208,11 +210,24 @@ if (!$loyalty_settings) {
-
- - - - +
+
+
+ + + + +
+
+ 1): ?> +
+ +
+
@@ -258,21 +273,21 @@ if (!$loyalty_settings) {
-
+
> - + > - + > - +
- +