diff --git a/admin.php b/admin.php index 325a4e2..d154764 100644 --- a/admin.php +++ b/admin.php @@ -2,17 +2,6 @@ $title = 'dashboard'; require_once __DIR__ . '/includes/header.php'; -// Handle WhatsApp Settings Save -if ($is_super && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save_whatsapp_settings'])) { - set_setting('whatsapp_enabled', $_POST['whatsapp_enabled'] ?? '0'); - set_setting('wablas_token', $_POST['wablas_token'] ?? ''); - set_setting('wablas_server', $_POST['wablas_server'] ?? ''); - set_setting('msg_order_created_ar', $_POST['msg_order_created_ar'] ?? ''); - set_setting('msg_order_ready_ar', $_POST['msg_order_ready_ar'] ?? ''); - set_setting('msg_payment_ar', $_POST['msg_payment_ar'] ?? ''); - $success_msg = is_arabic() ? 'تم حفظ الإعدادات بنجاح' : 'Settings saved successfully'; -} - // Helper functions for status colors if (!function_exists('getStatusColor')) { function getStatusColor($status) { @@ -292,59 +281,8 @@ if (!$is_limited) { }); } - - -
-
-
-
- -
- -
-
-
-
-
- > - -
-
-
- - -
-
- - -
-
- - - Tags: {customer_name}, {order_number}, {order_details}, {total_price} -
-
- - - Tags: {customer_name}, {order_number} -
-
- - - Tags: {customer_name}, {order_number}, {amount}, {remaining_balance} -
-
- -
-
-
-
-
- +?> \ No newline at end of file diff --git a/api/checkout.php b/api/checkout.php index 1b16cf4..7a4bcdf 100644 --- a/api/checkout.php +++ b/api/checkout.php @@ -19,6 +19,35 @@ $payment_method = $input['payment_method'] ?? null; $branch_id = $_SESSION['branch_id']; $user_id = $_SESSION['user_id']; +// Check if branch_id is 'all' (happens when super_admin views all branches) +if ($branch_id === 'all') { + // We need a specific branch_id to save an order. + // If we're in "all" mode, we'll try to get the user's primary branch or just the first available branch. + try { + $pdo = db(); + $stmt_u = $pdo->prepare("SELECT branch_id FROM users WHERE id = ?"); + $stmt_u->execute([$user_id]); + $u_branch = $stmt_u->fetchColumn(); + + if ($u_branch && $u_branch != 'all') { + $branch_id = $u_branch; + } else { + // Fallback to first branch in user_branches + $stmt_ub = $pdo->prepare("SELECT branch_id FROM user_branches WHERE user_id = ? LIMIT 1"); + $stmt_ub->execute([$user_id]); + $ub_branch = $stmt_ub->fetchColumn(); + if ($ub_branch) { + $branch_id = $ub_branch; + } else { + // Last resort: first branch in system + $branch_id = $pdo->query("SELECT id FROM branches LIMIT 1")->fetchColumn(); + } + } + } catch (Exception $e) { + // Silently continue, might fail at insert + } +} + if (empty($items)) { echo json_encode(['success' => false, 'error' => 'Cart is empty']); exit; @@ -157,4 +186,4 @@ try { } catch (Exception $e) { if (isset($pdo)) $pdo->rollBack(); echo json_encode(['success' => false, 'error' => $e->getMessage()]); -} +} \ No newline at end of file diff --git a/api/update_setting.php b/api/update_setting.php new file mode 100644 index 0000000..9c9db12 --- /dev/null +++ b/api/update_setting.php @@ -0,0 +1,39 @@ + false, 'error' => 'Unauthorized']); + exit; +} + +if ($_SERVER['REQUEST_METHOD'] !== 'POST') { + http_response_code(405); + echo json_encode(['success' => false, 'error' => 'Method not allowed']); + exit; +} + +$key = $_POST['key'] ?? ''; +$value = $_POST['value'] ?? ''; + +if (empty($key)) { + echo json_encode(['success' => false, 'error' => 'Missing key']); + exit; +} + +// Basic security check to ensure we only update allowed settings +$allowed_keys = ['whatsapp_enabled', 'wablas_token', 'wablas_server', 'wablas_security_key']; +if (!in_array($key, $allowed_keys)) { + echo json_encode(['success' => false, 'error' => 'Invalid key']); + exit; +} + +try { + set_setting($key, $value); + echo json_encode(['success' => true]); +} catch (Exception $e) { + echo json_encode(['success' => false, 'error' => $e->getMessage()]); +} \ No newline at end of file diff --git a/company_profile.php b/company_profile.php index 76754e4..dd357a0 100644 --- a/company_profile.php +++ b/company_profile.php @@ -12,53 +12,68 @@ if ($current_role !== 'super_admin') { $success = ''; $error = ''; +$is_super = ($current_role === 'super_admin'); // Get company data $stmt = db()->query("SELECT * FROM companies LIMIT 1"); $company = $stmt->fetch(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { - $name_en = $_POST['name_en'] ?? ''; - $name_ar = $_POST['name_ar'] ?? ''; - $email = $_POST['email'] ?? ''; - $phone = $_POST['phone'] ?? ''; - $address_en = $_POST['address_en'] ?? ''; - $address_ar = $_POST['address_ar'] ?? ''; - $vat_number = $_POST['vat_no'] ?? ''; // Keep for compatibility - $ctr_no = $_POST['ctr_no'] ?? ''; - $vat_no = $_POST['vat_no'] ?? ''; + if (isset($_POST['save_company_profile'])) { + $name_en = $_POST['name_en'] ?? ''; + $name_ar = $_POST['name_ar'] ?? ''; + $email = $_POST['email'] ?? ''; + $phone = $_POST['phone'] ?? ''; + $address_en = $_POST['address_en'] ?? ''; + $address_ar = $_POST['address_ar'] ?? ''; + $vat_number = $_POST['vat_no'] ?? ''; // Keep for compatibility + $ctr_no = $_POST['ctr_no'] ?? ''; + $vat_no = $_POST['vat_no'] ?? ''; - // Handle Logo Upload - $logo = $company['logo']; - if (isset($_FILES['logo']) && $_FILES['logo']['error'] === UPLOAD_ERR_OK) { - $ext = pathinfo($_FILES['logo']['name'], PATHINFO_EXTENSION); - $filename = 'logo_' . time() . '.' . $ext; - $target = 'assets/images/company/' . $filename; - if (move_uploaded_file($_FILES['logo']['tmp_name'], $target)) { - $logo = $target; + // Handle Logo Upload + $logo = $company['logo']; + if (isset($_FILES['logo']) && $_FILES['logo']['error'] === UPLOAD_ERR_OK) { + $ext = pathinfo($_FILES['logo']['name'], PATHINFO_EXTENSION); + $filename = 'logo_' . time() . '.' . $ext; + $target = 'assets/images/company/' . $filename; + if (move_uploaded_file($_FILES['logo']['tmp_name'], $target)) { + $logo = $target; + } + } + + // Handle Favicon Upload + $favicon = $company['favicon']; + if (isset($_FILES['favicon']) && $_FILES['favicon']['error'] === UPLOAD_ERR_OK) { + $ext = pathinfo($_FILES['favicon']['name'], PATHINFO_EXTENSION); + $filename = 'favicon_' . time() . '.' . $ext; + $target = 'assets/images/company/' . $filename; + if (move_uploaded_file($_FILES['favicon']['tmp_name'], $target)) { + $favicon = $target; + } + } + + try { + $stmt = db()->prepare("UPDATE companies SET name_en = ?, name_ar = ?, logo = ?, favicon = ?, email = ?, phone = ?, address_en = ?, address_ar = ?, vat_number = ?, ctr_no = ?, vat_no = ? WHERE id = ?"); + $stmt->execute([$name_en, $name_ar, $logo, $favicon, $email, $phone, $address_en, $address_ar, $vat_number, $ctr_no, $vat_no, $company['id']]); + $success = __('success_update'); + // Refresh data + $stmt = db()->query("SELECT * FROM companies LIMIT 1"); + $company = $stmt->fetch(); + } catch (Exception $e) { + $error = __('error_update') . ' ' . $e->getMessage(); } } - // Handle Favicon Upload - $favicon = $company['favicon']; - if (isset($_FILES['favicon']) && $_FILES['favicon']['error'] === UPLOAD_ERR_OK) { - $ext = pathinfo($_FILES['favicon']['name'], PATHINFO_EXTENSION); - $filename = 'favicon_' . time() . '.' . $ext; - $target = 'assets/images/company/' . $filename; - if (move_uploaded_file($_FILES['favicon']['tmp_name'], $target)) { - $favicon = $target; - } - } - - try { - $stmt = db()->prepare("UPDATE companies SET name_en = ?, name_ar = ?, logo = ?, favicon = ?, email = ?, phone = ?, address_en = ?, address_ar = ?, vat_number = ?, ctr_no = ?, vat_no = ? WHERE id = ?"); - $stmt->execute([$name_en, $name_ar, $logo, $favicon, $email, $phone, $address_en, $address_ar, $vat_number, $ctr_no, $vat_no, $company['id']]); - $success = __('success_update'); - // Refresh data - $stmt = db()->query("SELECT * FROM companies LIMIT 1"); - $company = $stmt->fetch(); - } catch (Exception $e) { - $error = __('error_update') . ' ' . $e->getMessage(); + // Handle WhatsApp Settings Save + if ($is_super && isset($_POST['save_whatsapp_settings'])) { + set_setting('whatsapp_enabled', $_POST['whatsapp_enabled'] ?? '0'); + set_setting('wablas_token', $_POST['wablas_token'] ?? ''); + set_setting('wablas_server', $_POST['wablas_server'] ?? ''); + set_setting('wablas_security_key', $_POST['wablas_security_key'] ?? ''); + set_setting('msg_order_created_ar', $_POST['msg_order_created_ar'] ?? ''); + set_setting('msg_order_ready_ar', $_POST['msg_order_ready_ar'] ?? ''); + set_setting('msg_payment_ar', $_POST['msg_payment_ar'] ?? ''); + $success = is_arabic() ? 'تم حفظ إعدادات الواتساب بنجاح' : 'WhatsApp settings saved successfully'; } } @@ -76,16 +91,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
-
+
+
- +
- +
@@ -131,9 +147,59 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- +
+ +
+
+
+
+
+
+ > + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + + Tags: {customer_name}, {order_number}, {order_details}, {total_price} +
+
+ + + Tags: {customer_name}, {order_number} +
+
+ + + Tags: {customer_name}, {order_number}, {amount}, {remaining_balance} +
+
+ +
+
+
+
+ + \ No newline at end of file diff --git a/includes/header.php b/includes/header.php index 469234a..c882caa 100644 --- a/includes/header.php +++ b/includes/header.php @@ -200,6 +200,20 @@ if ($current_user_id && $current_page !== 'login.php' && $current_page !== 'logo .dropdown-toggle { cursor: pointer; } + + .whatsapp-toggle-btn { + transition: all 0.3s; + border: 2px solid #e9ecef; + background: #fff; + } + .whatsapp-toggle-btn.active { + border-color: #25D366; + color: #25D366; + background: rgba(37, 211, 102, 0.1); + } + .whatsapp-toggle-btn:not(.active) { + color: #6c757d; + } @@ -303,7 +317,7 @@ if ($current_user_id && $current_page !== 'login.php' && $current_page !== 'logo @@ -327,6 +341,57 @@ if ($current_user_id && $current_page !== 'login.php' && $current_page !== 'logo

+ + + + + + + 1 || $current_role === 'super_admin'): ?>