39728-vm/login.php
2026-04-19 02:30:10 +00:00

111 lines
6.5 KiB
PHP

<?php
require_once __DIR__ . '/includes/app.php';
if (current_user()) {
redirect_to('index.php');
}
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = trim((string) ($_POST['username'] ?? ''));
$password = trim((string) ($_POST['password'] ?? ''));
if ($username === '' || $password === '') {
$error = tr('أدخل اسم المستخدم وكلمة المرور.', 'Enter username and password.');
} elseif (!login_attempt($username, $password)) {
$error = tr('بيانات الدخول غير صحيحة. استخدم أحد الحسابات التجريبية بالأسفل.', 'Invalid credentials. Use one of the demo accounts below.');
} else {
set_flash('success', tr('تم تسجيل الدخول بنجاح.', 'Signed in successfully.'));
redirect_to('index.php');
}
}
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
$projectName = $_SERVER['PROJECT_NAME'] ?? app_name();
$assetVersion = date('YmdHi');
$accounts = demo_users();
?>
<!doctype html>
<html lang="<?= h(current_lang()) ?>" dir="<?= is_rtl() ? 'rtl' : 'ltr' ?>">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?= h(tr('تسجيل الدخول', 'Sign in')) ?> · <?= h($projectName) ?></title>
<?php if ($projectDescription): ?>
<meta name="description" content='<?= h($projectDescription) ?>' />
<meta property="og:description" content="<?= h($projectDescription) ?>" />
<meta property="twitter:description" content="<?= h($projectDescription) ?>" />
<?php else: ?>
<meta name="description" content="<?= h(tr('تسجيل الدخول إلى مساحة مبيعات حلوى الريامي متعددة الفروع.', 'Sign in to the multi-branch Al Riyami Sweets sales workspace.')) ?>" />
<?php endif; ?>
<?php if ($projectImageUrl): ?>
<meta property="og:image" content="<?= h($projectImageUrl) ?>" />
<meta property="twitter:image" content="<?= h($projectImageUrl) ?>" />
<?php endif; ?>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link rel="stylesheet" href="assets/css/custom.css?v=<?= h($assetVersion) ?>">
</head>
<body class="auth-body">
<main class="auth-shell container-fluid">
<div class="row g-4 align-items-stretch justify-content-center">
<div class="col-lg-5">
<section class="auth-panel h-100">
<div class="eyebrow mb-3"><?= h(tr('MVP جاهز للاستخدام', 'MVP ready to use')) ?></div>
<h1 class="auth-title"><?= h(tr('حلوى الريامي', 'Al Riyami Sweets')) ?></h1>
<p class="auth-subtitle"><?= h(tr('تسجيل دخول ثنائي اللغة مع أدوار منفصلة للمالك ومدير الفرع والكاشير.', 'Bilingual role-based access for owner, branch manager, and cashier.')) ?></p>
<div class="mini-grid mt-4">
<div class="stat-chip"><strong>3</strong><span><?= h(tr('أدوار', 'roles')) ?></span></div>
<div class="stat-chip"><strong>3</strong><span><?= h(tr('فروع', 'branches')) ?></span></div>
<div class="stat-chip"><strong>2</strong><span><?= h(tr('لغات', 'languages')) ?></span></div>
</div>
<div class="alert alert-light border mt-4 mb-0">
<div class="fw-semibold mb-1"><?= h(tr('أول قيمة عملية', 'First practical value')) ?></div>
<div class="small text-muted"><?= h(tr('ابدأ ببيع POS سريع، ثم راجع المبيعات والمخزون والتقارير من نفس الواجهة.', 'Start with a fast POS sale, then review sales, stock, and reports from one workspace.')) ?></div>
</div>
</section>
</div>
<div class="col-lg-4">
<section class="auth-panel h-100">
<div class="d-flex justify-content-between align-items-center mb-3">
<h2 class="h4 mb-0"><?= h(tr('تسجيل الدخول', 'Sign in')) ?></h2>
<div class="language-switcher">
<a class="btn btn-sm <?= current_lang() === 'ar' ? 'btn-dark' : 'btn-outline-secondary' ?>" href="<?= h(url_for('login.php', ['lang' => 'ar'])) ?>">AR</a>
<a class="btn btn-sm <?= current_lang() === 'en' ? 'btn-dark' : 'btn-outline-secondary' ?>" href="<?= h(url_for('login.php', ['lang' => 'en'])) ?>">EN</a>
</div>
</div>
<?php if ($error !== ''): ?>
<div class="alert alert-warning"><?= h($error) ?></div>
<?php endif; ?>
<form method="post" class="d-grid gap-3">
<div>
<label class="form-label" for="username"><?= h(tr('اسم المستخدم', 'Username')) ?></label>
<input id="username" name="username" class="form-control form-control-lg" autocomplete="username" required>
</div>
<div>
<label class="form-label" for="password"><?= h(tr('كلمة المرور', 'Password')) ?></label>
<input id="password" name="password" type="password" class="form-control form-control-lg" autocomplete="current-password" required>
</div>
<button class="btn btn-dark btn-lg" type="submit"><?= h(tr('دخول إلى التطبيق', 'Enter app')) ?></button>
</form>
<div class="divider-label"><?= h(tr('حسابات تجريبية', 'Demo accounts')) ?></div>
<div class="d-grid gap-2">
<?php foreach ($accounts as $account): ?>
<button type="button"
class="btn btn-outline-secondary text-start demo-account"
data-username="<?= h($account['username']) ?>"
data-password="<?= h($account['password']) ?>">
<div class="fw-semibold"><?= h(current_lang() === 'ar' ? $account['name_ar'] : $account['name_en']) ?></div>
<div class="small text-muted"><?= h(role_label($account['role'])) ?> · <?= h(branch_label($account['branch_code'])) ?></div>
</button>
<?php endforeach; ?>
</div>
</section>
</div>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script src="assets/js/main.js?v=<?= h($assetVersion) ?>"></script>
</body>
</html>