From 0b22cc2f02b48d92a73eaeeee8feb4e86bc63e11 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Tue, 3 Mar 2026 17:12:24 +0000 Subject: [PATCH] fixing errors --- db/config.php | 12 ++++++++++-- includes/lang.php | 31 ++++++++++++++++++++----------- receipt.php | 5 +++-- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/db/config.php b/db/config.php index 670e00a..c74b43b 100644 --- a/db/config.php +++ b/db/config.php @@ -18,7 +18,15 @@ function db() { } function check_permission($page = null, $user_id = null) { - if (!$user_id) $user_id = $_SESSION['user_id'] ?? null; + // Safely access session + if (!$user_id) { + if (isset($_SESSION) && isset($_SESSION['user_id'])) { + $user_id = $_SESSION['user_id']; + } else { + $user_id = null; + } + } + if (!$page) $page = basename($_SERVER['PHP_SELF']); if (!$user_id) return ['view' => 0, 'add' => 0, 'edit' => 0, 'delete' => 0]; @@ -67,4 +75,4 @@ function set_setting($key, $value) { function has_permission($action, $page = null, $user_id = null) { $perms = check_permission($page, $user_id); return !empty($perms[$action]); -} +} \ No newline at end of file diff --git a/includes/lang.php b/includes/lang.php index 802ecf0..baa365f 100644 --- a/includes/lang.php +++ b/includes/lang.php @@ -3,19 +3,28 @@ if (session_status() === PHP_SESSION_NONE) { session_start(); } +/** + * Load environment variables from the root .env file (if present) + */ function load_dotenv_lang(): void { static $loaded = false; if ($loaded) return; $envPath = realpath(__DIR__ . '/../../.env'); // executor/.env if ($envPath && is_readable($envPath)) { - $lines = @file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: []; - foreach ($lines as $line) { - if ($line[0] === '#' || trim($line) === '') continue; - if (!str_contains($line, '=')) continue; - [$k, $v] = array_map('trim', explode('=', $line, 2)); - $v = trim($v, "' "); - if ($k !== '' && (getenv($k) === false || getenv($k) === '')) { - putenv("{$k}={$v}"); + $lines = @file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + if ($lines !== false) { + foreach ($lines as $line) { + $line = trim($line); + if ($line === '' || $line[0] === '#') continue; + if (!str_contains($line, '=')) continue; + [$k, $v] = array_map('trim', explode('=', $line, 2)); + if ($k === '') continue; + $v = trim($v, "' "); + if (getenv($k) === false || getenv($k) === '') { + putenv("{$k}={$v}"); + $_ENV[$k] = $v; + $_SERVER[$k] = $v; + } } } $loaded = true; @@ -132,7 +141,7 @@ $translations = [ 'company_profile' => 'Settings', 'user_profile' => 'User Profile', 'logo' => 'Logo', - 'favicon' => 'Aيقونة الموقع', + 'favicon' => 'أيقونة الموقع', 'email' => 'Email', 'address_en' => 'Address (EN)', 'address_ar' => 'Address (AR)', @@ -377,7 +386,7 @@ $translations = [ 'update_status' => 'تحديث الحالة', 'update' => 'تحديث', 'remaining_amount' => 'المبلغ المتبقي', - 'add_payment' => 'إضافة دفعة', + 'add_payment' => 'إإضافة دفعة', 'payment_method' => 'طريقة الدفع', 'customer_details' => 'تفاصيل العميل', 'order_date' => 'تاريخ الطلب', @@ -514,4 +523,4 @@ function branch_url($new_branch_id) { $params = $_GET; $params['switch_branch'] = $new_branch_id; return '?' . http_build_query($params); -} +} \ No newline at end of file diff --git a/receipt.php b/receipt.php index 05b45ec..a99e81d 100644 --- a/receipt.php +++ b/receipt.php @@ -1,8 +1,9 @@ - \ No newline at end of file +