feat: add timezone setting to admin panel

This commit is contained in:
Flatlogic Bot 2026-03-14 05:20:34 +00:00
parent 486d54348f
commit a361ed7269
3 changed files with 31 additions and 5 deletions

View File

@ -14,6 +14,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$companyPhone = trim($_POST['company_phone'] ?? ''); $companyPhone = trim($_POST['company_phone'] ?? '');
$companyAddress = trim($_POST['company_address'] ?? ''); $companyAddress = trim($_POST['company_address'] ?? '');
$platformCharge = trim($_POST['platform_charge_percentage'] ?? '0'); $platformCharge = trim($_POST['platform_charge_percentage'] ?? '0');
$timezone = trim($_POST['timezone'] ?? 'UTC');
$updates = [ $updates = [
'company_name' => $companyName, 'company_name' => $companyName,
@ -21,6 +22,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
'company_phone' => $companyPhone, 'company_phone' => $companyPhone,
'company_address' => $companyAddress, 'company_address' => $companyAddress,
'platform_charge_percentage' => $platformCharge, 'platform_charge_percentage' => $platformCharge,
'timezone' => $timezone,
'terms_en' => trim($_POST['terms_en'] ?? ''), 'terms_en' => trim($_POST['terms_en'] ?? ''),
'terms_ar' => trim($_POST['terms_ar'] ?? ''), 'terms_ar' => trim($_POST['terms_ar'] ?? ''),
'privacy_en' => trim($_POST['privacy_en'] ?? ''), 'privacy_en' => trim($_POST['privacy_en'] ?? ''),
@ -80,6 +82,7 @@ $currentEmail = $settings['company_email'] ?? '';
$currentPhone = $settings['company_phone'] ?? ''; $currentPhone = $settings['company_phone'] ?? '';
$currentAddress = $settings['company_address'] ?? ''; $currentAddress = $settings['company_address'] ?? '';
$currentPlatformCharge = $settings['platform_charge_percentage'] ?? '0'; $currentPlatformCharge = $settings['platform_charge_percentage'] ?? '0';
$currentTimezone = $settings['timezone'] ?? 'UTC';
$currentLogo = $settings['logo_path'] ?? ''; $currentLogo = $settings['logo_path'] ?? '';
$currentFavicon = $settings['favicon_path'] ?? ''; $currentFavicon = $settings['favicon_path'] ?? '';
$currentTermsEn = $settings['terms_en'] ?? ''; $currentTermsEn = $settings['terms_en'] ?? '';
@ -163,6 +166,18 @@ render_header('Company Profile', 'admin', true);
<div class="form-text">Percentage applied as a platform fee.</div> <div class="form-text">Percentage applied as a platform fee.</div>
</div> </div>
<div class="col-md-6">
<label class="form-label fw-bold"><?= e(t('timezone')) ?></label>
<select name="timezone" class="form-select">
<?php foreach (DateTimeZone::listIdentifiers() as $tz): ?>
<option value="<?= e($tz) ?>" <?= $tz === $currentTimezone ? 'selected' : '' ?>>
<?= e($tz) ?>
</option>
<?php endforeach; ?>
</select>
<div class="form-text">System Timezone</div>
</div>
<div class="col-md-12"> <div class="col-md-12">
<hr class="my-2"> <hr class="my-2">
</div> </div>

View File

@ -14,9 +14,10 @@ try {
('company_address', '123 Transport St, City, Country'), ('company_address', '123 Transport St, City, Country'),
('platform_charge_percentage', '0'), ('platform_charge_percentage', '0'),
('logo_path', ''), ('logo_path', ''),
('favicon_path', ''); ('favicon_path', ''),
('timezone', 'UTC');
"); ");
echo "Settings table created/updated.\n"; echo "Settings table created/updated.\n";
} catch (Exception $e) { } catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n"; echo "Error: " . $e->getMessage() . "\n";
} }

View File

@ -254,7 +254,8 @@ $translations = [
'reset_password_title' => 'Reset Password', 'reset_password_title' => 'Reset Password',
'reset_password_subtitle' => 'Enter your email to receive a reset link', 'reset_password_subtitle' => 'Enter your email to receive a reset link',
'send_reset_link' => 'Send Reset Link', 'send_reset_link' => 'Send Reset Link',
'back_to_login' => 'Back to Login' 'back_to_login' => 'Back to Login',
'timezone' => 'Timezone',
), ),
"ar" => array ( "ar" => array (
'app_name' => 'CargoLink', 'app_name' => 'CargoLink',
@ -497,7 +498,8 @@ $translations = [
'reset_password_title' => 'إعادة تعيين كلمة المرور', 'reset_password_title' => 'إعادة تعيين كلمة المرور',
'reset_password_subtitle' => 'أدخل بريدك الإلكتروني لتلقي رابط إعادة التعيين', 'reset_password_subtitle' => 'أدخل بريدك الإلكتروني لتلقي رابط إعادة التعيين',
'send_reset_link' => 'إرسال رابط إعادة التعيين', 'send_reset_link' => 'إرسال رابط إعادة التعيين',
'back_to_login' => 'العودة لتسجيل الدخول' 'back_to_login' => 'العودة لتسجيل الدخول',
'timezone' => 'المنطقة الزمنية',
) )
]; ];
@ -711,4 +713,12 @@ function has_permission(string $permissionSlug, ?int $userId = null): bool
function format_currency(float $amount): string function format_currency(float $amount): string
{ {
return number_format($amount, 3) . ' OMR'; return number_format($amount, 3) . ' OMR';
} }
// Set timezone from settings
try {
$tz = get_setting('timezone', 'UTC');
if ($tz && in_array($tz, DateTimeZone::listIdentifiers())) {
date_default_timezone_set($tz);
}
} catch (Throwable $e) {}