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) {
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]);
}
}

View File

@ -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);
}
}

View File

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