81 lines
3.2 KiB
PHP
81 lines
3.2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/header.php';
|
|
|
|
if (isLoggedIn()) {
|
|
redirect('index.php');
|
|
}
|
|
|
|
$error = '';
|
|
|
|
// Fetch charity settings
|
|
$stmt = db()->query("SELECT * FROM charity_settings WHERE id = 1");
|
|
$charity = $stmt->fetch();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$username = trim($_POST['username'] ?? '');
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if ($username && $password) {
|
|
$stmt = db()->prepare("SELECT * FROM users WHERE username = ?");
|
|
$stmt->execute([$username]);
|
|
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($user && password_verify($password, $user['password'])) {
|
|
$_SESSION['user_id'] = $user['id'];
|
|
$_SESSION['username'] = $user['username'];
|
|
$_SESSION['full_name'] = $user['full_name'];
|
|
$_SESSION['user_role'] = $user['role'];
|
|
|
|
// Set permissions in session immediately
|
|
$_SESSION['can_view'] = $user['can_view'] ?? 1;
|
|
$_SESSION['can_add'] = $user['can_add'] ?? 0;
|
|
$_SESSION['can_edit'] = $user['can_edit'] ?? 0;
|
|
$_SESSION['can_delete'] = $user['can_delete'] ?? 0;
|
|
|
|
redirect('index.php');
|
|
} else {
|
|
$error = 'اسم المستخدم أو كلمة المرور غير صحيحة';
|
|
}
|
|
} else {
|
|
$error = 'يرجى إدخال جميع الحقول المطلوبة';
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="row justify-content-center align-items-center" style="min-height: 80vh;">
|
|
<div class="col-md-4">
|
|
<div class="card p-4 shadow-sm border-0">
|
|
<div class="text-center mb-4">
|
|
<?php if ($charity['charity_logo']): ?>
|
|
<img src="<?= htmlspecialchars($charity['charity_logo']) ?>" alt="Logo" class="mb-3" style="max-height: 100px;">
|
|
<?php endif; ?>
|
|
<h3 class="fw-bold"><?= htmlspecialchars($charity['charity_name'] ?? 'تسجيل الدخول') ?></h3>
|
|
<p class="text-muted">نظام المراسلات</p>
|
|
</div>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger text-center"><?= $error ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST">
|
|
<div class="mb-3">
|
|
<label for="username" class="form-label">اسم المستخدم</label>
|
|
<input type="text" class="form-control" id="username" name="username" required autocomplete="username">
|
|
</div>
|
|
<div class="mb-3">
|
|
<div class="d-flex justify-content-between">
|
|
<label for="password" class="form-label">كلمة المرور</label>
|
|
<a href="forgot_password.php" class="text-decoration-none small text-primary">نسيت كلمة المرور؟</a>
|
|
</div>
|
|
<input type="password" class="form-control" id="password" name="password" required autocomplete="current-password">
|
|
</div>
|
|
<div class="d-grid mt-4">
|
|
<button type="submit" class="btn btn-dark btn-lg">دخول</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|