fixing errors

This commit is contained in:
Flatlogic Bot 2026-03-03 17:12:24 +00:00
parent a251e37178
commit 0b22cc2f02
3 changed files with 33 additions and 15 deletions

View File

@ -18,7 +18,15 @@ function db() {
} }
function check_permission($page = null, $user_id = null) { 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 (!$page) $page = basename($_SERVER['PHP_SELF']);
if (!$user_id) return ['view' => 0, 'add' => 0, 'edit' => 0, 'delete' => 0]; 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) { function has_permission($action, $page = null, $user_id = null) {
$perms = check_permission($page, $user_id); $perms = check_permission($page, $user_id);
return !empty($perms[$action]); return !empty($perms[$action]);
} }

View File

@ -3,19 +3,28 @@ if (session_status() === PHP_SESSION_NONE) {
session_start(); session_start();
} }
/**
* Load environment variables from the root .env file (if present)
*/
function load_dotenv_lang(): void { function load_dotenv_lang(): void {
static $loaded = false; static $loaded = false;
if ($loaded) return; if ($loaded) return;
$envPath = realpath(__DIR__ . '/../../.env'); // executor/.env $envPath = realpath(__DIR__ . '/../../.env'); // executor/.env
if ($envPath && is_readable($envPath)) { if ($envPath && is_readable($envPath)) {
$lines = @file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: []; $lines = @file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) { if ($lines !== false) {
if ($line[0] === '#' || trim($line) === '') continue; foreach ($lines as $line) {
if (!str_contains($line, '=')) continue; $line = trim($line);
[$k, $v] = array_map('trim', explode('=', $line, 2)); if ($line === '' || $line[0] === '#') continue;
$v = trim($v, "' "); if (!str_contains($line, '=')) continue;
if ($k !== '' && (getenv($k) === false || getenv($k) === '')) { [$k, $v] = array_map('trim', explode('=', $line, 2));
putenv("{$k}={$v}"); if ($k === '') continue;
$v = trim($v, "' ");
if (getenv($k) === false || getenv($k) === '') {
putenv("{$k}={$v}");
$_ENV[$k] = $v;
$_SERVER[$k] = $v;
}
} }
} }
$loaded = true; $loaded = true;
@ -132,7 +141,7 @@ $translations = [
'company_profile' => 'Settings', 'company_profile' => 'Settings',
'user_profile' => 'User Profile', 'user_profile' => 'User Profile',
'logo' => 'Logo', 'logo' => 'Logo',
'favicon' => 'Aيقونة الموقع', 'favicon' => 'أيقونة الموقع',
'email' => 'Email', 'email' => 'Email',
'address_en' => 'Address (EN)', 'address_en' => 'Address (EN)',
'address_ar' => 'Address (AR)', 'address_ar' => 'Address (AR)',
@ -377,7 +386,7 @@ $translations = [
'update_status' => 'تحديث الحالة', 'update_status' => 'تحديث الحالة',
'update' => 'تحديث', 'update' => 'تحديث',
'remaining_amount' => 'المبلغ المتبقي', 'remaining_amount' => 'المبلغ المتبقي',
'add_payment' => ضافة دفعة', 'add_payment' => إضافة دفعة',
'payment_method' => 'طريقة الدفع', 'payment_method' => 'طريقة الدفع',
'customer_details' => 'تفاصيل العميل', 'customer_details' => 'تفاصيل العميل',
'order_date' => 'تاريخ الطلب', 'order_date' => 'تاريخ الطلب',
@ -514,4 +523,4 @@ function branch_url($new_branch_id) {
$params = $_GET; $params = $_GET;
$params['switch_branch'] = $new_branch_id; $params['switch_branch'] = $new_branch_id;
return '?' . http_build_query($params); return '?' . http_build_query($params);
} }

View File

@ -1,8 +1,9 @@
<?php <?php
require_once __DIR__ . '/db/config.php'; require_once __DIR__ . '/db/config.php';
if ($_SESSION['role'] === 'limited_viewer') { die('Access Denied'); }
require_once __DIR__ . '/includes/lang.php'; require_once __DIR__ . '/includes/lang.php';
if (($_SESSION['role'] ?? 'cashier') === 'limited_viewer') { die('Access Denied'); }
$order_id = $_GET['id'] ?? null; $order_id = $_GET['id'] ?? null;
if (!$order_id) { if (!$order_id) {
die("Order ID is required"); die("Order ID is required");
@ -342,4 +343,4 @@ $display_ctr = $company['ctr_no'];
} }
</script> </script>
</body> </body>
</html> </html>