39728-vm/profile.php
2026-04-20 06:12:47 +00:00

90 lines
4.2 KiB
PHP

<?php
require_once __DIR__ . '/includes/app.php';
$user = require_auth();
$pageTitle = current_lang() === 'ar' ? 'الملف الشخصي' : 'Profile';
$activeNav = 'profile';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'update_profile') {
$name_ar = trim($_POST['name_ar'] ?? '');
$name_en = trim($_POST['name_en'] ?? '');
$password = $_POST['password'] ?? '';
if (empty($name_ar) || empty($name_en)) {
set_flash('danger', tr('الرجاء إدخال الاسم باللغتين', 'Please provide names in both languages'));
} else {
$update_sql = "UPDATE users SET name_ar = ?, name_en = ?";
$params = [$name_ar, $name_en];
if (!empty($password)) {
$update_sql .= ", password = ?";
$params[] = password_hash($password, PASSWORD_DEFAULT);
}
$update_sql .= " WHERE id = ?";
$params[] = $user['id'];
$stmt = db()->prepare($update_sql);
if ($stmt->execute($params)) {
// Update session data
$_SESSION['auth_user']['name_ar'] = $name_ar;
$_SESSION['auth_user']['name_en'] = $name_en;
set_flash('success', tr('تم تحديث الملف الشخصي بنجاح', 'Profile updated successfully'));
redirect_to('profile.php');
} else {
set_flash('danger', tr('حدث خطأ أثناء التحديث', 'Error updating profile'));
}
}
}
require_once __DIR__ . '/includes/header.php';
?>
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card shadow-sm border-0 rounded-4">
<div class="card-header bg-white text-center py-4 border-0">
<div class="mb-3">
<i class="bi bi-person-circle text-primary" style="font-size: 4rem;"></i>
</div>
<h4 class="mb-0 fw-bold"><?= h($pageTitle) ?></h4>
<p class="text-muted small mt-1"><?= h(role_label($user['role'])) ?> · <?= h(branch_label($user['branch_code'])) ?></p>
</div>
<div class="card-body p-4 pt-0">
<form method="post">
<input type="hidden" name="action" value="update_profile">
<div class="mb-3">
<label class="form-label text-muted small fw-bold"><?= h(tr('اسم المستخدم', 'Username')) ?></label>
<input type="text" class="form-control bg-light" value="<?= h($user['username']) ?>" readonly>
</div>
<div class="row mb-3">
<div class="col-md-6">
<label class="form-label text-muted small fw-bold"><?= h(tr('الاسم (عربي) *', 'Name (AR) *')) ?></label>
<input type="text" name="name_ar" class="form-control" value="<?= h($user['name_ar']) ?>" required>
</div>
<div class="col-md-6 mt-3 mt-md-0">
<label class="form-label text-muted small fw-bold"><?= h(tr('الاسم (إنجليزي) *', 'Name (EN) *')) ?></label>
<input type="text" name="name_en" class="form-control" value="<?= h($user['name_en']) ?>" required>
</div>
</div>
<div class="mb-4">
<label class="form-label text-muted small fw-bold"><?= h(tr('كلمة المرور الجديدة', 'New Password')) ?></label>
<input type="password" name="password" class="form-control" placeholder="<?= h(tr('اتركه فارغاً إذا لم ترغب بالتغيير', 'Leave blank to keep unchanged')) ?>">
</div>
<div class="d-grid mt-4">
<button type="submit" class="btn btn-primary py-2 fw-bold">
<i class="bi bi-save me-1"></i> <?= h(tr('حفظ التغييرات', 'Save Changes')) ?>
</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php require_once __DIR__ . '/includes/footer.php'; ?>