39728-vm/login.php
2026-04-19 07:41:01 +00:00

249 lines
13 KiB
PHP

<?php
require_once __DIR__ . '/includes/app.php';
if (current_user()) {
redirect_to('index.php');
}
$error = '';
$flash = pull_flash();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['action']) && $_POST['action'] === 'reset_password') {
$reset_username = trim((string) ($_POST['reset_username'] ?? ''));
if ($reset_username !== '') {
// Mock sending reset link
set_flash('success', tr('تم إرسال رابط إعادة تعيين كلمة المرور إلى بريدك الإلكتروني (تجريبي).', 'Password reset link has been sent to your email (Demo).'));
}
redirect_to('login.php');
}
$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 sales workspace.')) ?>" />
<?php endif; ?>
<?php if ($projectImageUrl): ?>
<meta property="og:image" content="<?= h($projectImageUrl) ?>" />
<meta property="twitter:image" content="<?= h($projectImageUrl) ?>" />
<?php endif; ?>
<?php if (get_setting('company_favicon')): ?>
<link rel="icon" href="<?= h(get_setting('company_favicon')) ?>">
<?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) ?>">
<style>
body {
background-color: #f8f9fa;
display: flex;
align-items: center;
min-height: 100vh;
padding: 2rem 0;
}
.auth-card {
border-radius: 20px;
box-shadow: 0 20px 40px rgba(0,0,0,0.08);
background: #fff;
overflow: hidden;
border: none;
}
.auth-sidebar {
background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%);
color: white;
padding: 3rem;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.auth-form-container {
padding: 4rem 3rem;
}
.company-logo {
max-height: 90px;
border-radius: 12px;
margin-bottom: 1.5rem;
box-shadow: 0 4px 12px rgba(0,0,0,0.05);
padding: 10px;
background: #fff;
}
.demo-account {
border-radius: 12px;
transition: all 0.2s;
}
.demo-account:hover {
background-color: #f8f9fa;
transform: translateY(-2px);
border-color: #dee2e6 !important;
}
.stat-chip {
background: rgba(255,255,255,0.1);
border: 1px solid rgba(255,255,255,0.2);
}
</style>
</head>
<body>
<main class="container">
<div class="row justify-content-center">
<div class="col-xl-10">
<div class="card auth-card">
<div class="row g-0 align-items-stretch">
<div class="col-lg-5 auth-sidebar d-none d-lg-flex">
<div>
<div class="eyebrow text-white-50 mb-3"><?= h(tr('مرحباً بك مجدداً', 'Welcome Back')) ?></div>
<h2 class="display-6 fw-bold mb-4"><?= h(current_lang() === 'ar' ? get_setting('company_name_ar', 'نظام إدارة') : get_setting('company_name_en', 'Management System')) ?></h2>
<p class="lead opacity-75"><?= h(tr('نظام متكامل لتسجيل المبيعات، وإدارة المخزون، والتقارير في واجهة واحدة.', 'Integrated system for logging sales, managing inventory, and reports in one interface.')) ?></p>
<div class="mini-grid mt-5 gap-3 d-flex flex-wrap">
<div class="stat-chip text-white px-3 py-2 rounded"><strong>3</strong> <span><?= h(tr('أدوار', 'Roles')) ?></span></div>
<div class="stat-chip text-white px-3 py-2 rounded"><strong>3</strong> <span><?= h(tr('فروع', 'Branches')) ?></span></div>
<div class="stat-chip text-white px-3 py-2 rounded"><strong>2</strong> <span><?= h(tr('لغات', 'Languages')) ?></span></div>
</div>
</div>
<div class="mt-5 pt-5 border-top border-light border-opacity-25 text-white-50 small">
&copy; <?= date('Y') ?> <?= h($projectName) ?>
</div>
</div>
<div class="col-lg-7 auth-form-container">
<div class="d-flex justify-content-between align-items-center mb-4">
<div class="language-switcher">
<a class="btn btn-sm <?= current_lang() === 'ar' ? 'btn-primary' : 'btn-light text-dark' ?> rounded-pill px-3" href="<?= h(url_for('login.php', ['lang' => 'ar'])) ?>">AR</a>
<a class="btn btn-sm <?= current_lang() === 'en' ? 'btn-primary' : 'btn-light text-dark' ?> rounded-pill px-3" href="<?= h(url_for('login.php', ['lang' => 'en'])) ?>">EN</a>
</div>
</div>
<div class="text-center mb-5">
<?php if (get_setting('company_logo')): ?>
<img src="<?= h(get_setting('company_logo')) ?>" alt="Logo" class="company-logo">
<?php else: ?>
<div class="company-logo mx-auto bg-primary bg-opacity-10 text-primary d-flex align-items-center justify-content-center" style="width: 90px; height: 90px; font-size: 2.5rem; font-weight: bold;">
<?= h(mb_substr(current_lang() === 'ar' ? get_setting('company_name_ar', 'نظام') : get_setting('company_name_en', 'System'), 0, 1)) ?>
</div>
<?php endif; ?>
<h3 class="fw-bold mb-1"><?= h(tr('تسجيل الدخول', 'Sign in to your account')) ?></h3>
<p class="text-muted"><?= h(tr('أدخل بيانات الاعتماد الخاصة بك للوصول', 'Enter your credentials to access your account')) ?></p>
</div>
<?php if ($flash): ?>
<div class="alert alert-<?= h($flash['type'] === 'error' ? 'danger' : $flash['type']) ?> alert-dismissible fade show rounded-3" role="alert">
<?= h($flash['message']) ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<?php if ($error !== ''): ?>
<div class="alert alert-danger alert-dismissible fade show rounded-3" role="alert">
<?= h($error) ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<form method="post" class="mb-5">
<div class="mb-3">
<label class="form-label fw-semibold" for="username"><?= h(tr('اسم المستخدم', 'Username')) ?></label>
<input id="username" name="username" class="form-control form-control-lg rounded-3 bg-light border-0" autocomplete="username" required>
</div>
<div class="mb-4">
<div class="d-flex justify-content-between align-items-center mb-1">
<label class="form-label fw-semibold mb-0" for="password"><?= h(tr('كلمة المرور', 'Password')) ?></label>
<a href="#" class="text-decoration-none small text-primary fw-medium" data-bs-toggle="modal" data-bs-target="#resetPasswordModal"><?= h(tr('نسيت كلمة المرور؟', 'Forgot password?')) ?></a>
</div>
<input id="password" name="password" type="password" class="form-control form-control-lg rounded-3 bg-light border-0" autocomplete="current-password" required>
</div>
<button class="btn btn-primary btn-lg w-100 rounded-3 shadow-sm fw-semibold" type="submit"><?= h(tr('دخول', 'Sign in')) ?></button>
</form>
<div class="position-relative mb-4">
<hr class="text-muted opacity-25">
<span class="position-absolute top-50 start-50 translate-middle bg-white px-3 small text-muted fw-medium"><?= h(tr('حسابات تجريبية سريعة', 'Quick demo access')) ?></span>
</div>
<div class="row g-2">
<?php foreach ($accounts as $account): ?>
<div class="col-12 col-md-4">
<button type="button"
class="btn btn-outline-secondary border-1 w-100 p-3 text-start demo-account h-100"
data-username="<?= h($account['username']) ?>"
data-password="<?= h($account['password']) ?>">
<div class="fw-bold mb-1 text-dark text-truncate"><?= h(current_lang() === 'ar' ? $account['name_ar'] : $account['name_en']) ?></div>
<div class="small text-muted" style="font-size: 0.75rem;"><?= h(role_label($account['role'])) ?></div>
</button>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<!-- Reset Password Modal -->
<div class="modal fade" id="resetPasswordModal" tabindex="-1" aria-labelledby="resetPasswordModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content border-0 shadow-lg rounded-4">
<div class="modal-header border-bottom-0 pb-0 pt-4 px-4">
<h5 class="modal-title fw-bold" id="resetPasswordModalLabel"><?= h(tr('استعادة كلمة المرور', 'Reset Password')) ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form method="post">
<input type="hidden" name="action" value="reset_password">
<div class="modal-body px-4 py-4">
<p class="text-muted mb-4"><?= h(tr('أدخل اسم المستخدم أو البريد الإلكتروني وسنقوم بإرسال رابط لإعادة تعيين كلمة المرور الخاصة بك.', 'Enter your username or email and we will send you a link to reset your password.')) ?></p>
<div class="mb-3">
<label for="reset_username" class="form-label fw-semibold"><?= h(tr('البريد الإلكتروني / اسم المستخدم', 'Email / Username')) ?></label>
<input type="text" class="form-control form-control-lg bg-light border-0 rounded-3" id="reset_username" name="reset_username" required>
</div>
</div>
<div class="modal-footer border-top-0 pt-0 pb-4 px-4">
<button type="button" class="btn btn-light rounded-3 px-4" data-bs-dismiss="modal"><?= h(tr('إلغاء', 'Cancel')) ?></button>
<button type="submit" class="btn btn-primary rounded-3 px-4 fw-semibold"><?= h(tr('إرسال الرابط', 'Send Link')) ?></button>
</div>
</form>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.demo-account').forEach(btn => {
btn.addEventListener('click', () => {
document.getElementById('username').value = btn.dataset.username;
document.getElementById('password').value = btn.dataset.password;
btn.closest('form')?.submit() || document.querySelector('form').submit();
});
});
});
</script>
</body>
</html>