145 lines
7.5 KiB
PHP
145 lines
7.5 KiB
PHP
<?php
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
session_start();
|
|
}
|
|
if (!isset($_SESSION["lang"]) && !isset($_GET["lang"])) {
|
|
$_SESSION["lang"] = "ar";
|
|
}
|
|
require_once __DIR__ . "/db/config.php";
|
|
require_once __DIR__ . '/includes/lang.php';
|
|
|
|
$success = false;
|
|
$error = '';
|
|
|
|
$branch_id_get = isset($_GET['branch_id']) ? (int)$_GET['branch_id'] : null;
|
|
$info = null;
|
|
|
|
if ($branch_id_get) {
|
|
$stmt = db()->prepare("SELECT b.id AS branch_id, b.name_en AS branch_name_en, b.name_ar AS branch_name_ar, c.id AS company_id, c.name_en AS comp_name_en, c.name_ar AS comp_name_ar, c.logo FROM branches b JOIN companies c ON b.company_id = c.id WHERE b.id = ?");
|
|
$stmt->execute([$branch_id_get]);
|
|
$info = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
if (empty($info)) {
|
|
$stmt = db()->query("SELECT b.id AS branch_id, b.name_en AS branch_name_en, b.name_ar AS branch_name_ar, c.id AS company_id, c.name_en AS comp_name_en, c.name_ar AS comp_name_ar, c.logo FROM branches b JOIN companies c ON b.company_id = c.id LIMIT 1");
|
|
$info = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
$branch_id = $info['branch_id'] ?? null;
|
|
$company_id = $info['company_id'] ?? null;
|
|
$company_name = $_SESSION['lang'] === 'ar' ? ($info['comp_name_ar'] ?? '') : ($info['comp_name_en'] ?? '');
|
|
$branch_name = $_SESSION['lang'] === 'ar' ? ($info['branch_name_ar'] ?? '') : ($info['branch_name_en'] ?? '');
|
|
$logo = $info['logo'] ?? null;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$rating = (int)($_POST['rating'] ?? 0);
|
|
$comment = $_POST['comment'] ?? '';
|
|
|
|
if ($rating < 1 || $rating > 5) {
|
|
$error = __('provide_valid_rating');
|
|
} else {
|
|
$stmt = db()->prepare("INSERT INTO ratings (branch_id, company_id, rating_type, rating_value, comment) VALUES (?, ?, 'staff', ?, ?)");
|
|
if ($stmt->execute([$branch_id, $company_id, $rating, $comment])) {
|
|
$success = true;
|
|
} else {
|
|
$error = __('error_saving_rating');
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="<?= $_SESSION['lang'] ?>" dir="<?= $_SESSION['lang'] === 'ar' ? 'rtl' : 'ltr' ?>">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?= __('staff_rating') ?></title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
|
|
<style>
|
|
body { background-color: #f8f9fc; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; display: flex; flex-direction: column; min-height: 100vh; }
|
|
.rating-card { max-width: 500px; margin: 40px auto; border-radius: 15px; border: none; box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.15); padding: 30px; background: white; }
|
|
.stars { display: flex; flex-direction: row-reverse; justify-content: center; margin-bottom: 20px; }
|
|
.stars input { display: none; }
|
|
.stars label { font-size: 2.5rem; color: #ddd; cursor: pointer; transition: color 0.2s; padding: 0 5px; }
|
|
.stars label:hover, .stars label:hover ~ label, .stars input:checked ~ label { color: #f6c23e; }
|
|
.btn-submit { border-radius: 30px; padding: 10px 30px; font-weight: 600; }
|
|
.main-content { flex: 1; }
|
|
.footer { background-color: white; border-top: 1px solid #eaecf4; padding: 1.5rem 0; color: #858796; text-align: center; }
|
|
<?php if ($_SESSION['lang'] === 'ar'): ?>
|
|
.stars { flex-direction: row; } /* RTL fix for stars order */
|
|
.stars label:hover ~ label, .stars input:checked ~ label { color: #ddd; }
|
|
.stars label:hover, .stars label:hover ~ label, .stars input:checked, .stars input:checked ~ label { color: #f6c23e !important; }
|
|
<?php endif; ?>
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="main-content">
|
|
<div class="container py-5">
|
|
|
|
<div class="text-end mb-3">
|
|
<?php if ($_SESSION['lang'] === 'ar'): ?>
|
|
<a href="?lang=en<?= isset($_GET['branch_id']) ? '&branch_id=' . (int)$_GET['branch_id'] : '' ?>" class="text-decoration-none btn btn-sm btn-outline-secondary">English</a>
|
|
<?php else: ?>
|
|
<a href="?lang=ar<?= isset($_GET['branch_id']) ? '&branch_id=' . (int)$_GET['branch_id'] : '' ?>" class="text-decoration-none btn btn-sm btn-outline-secondary">العربية</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="rating-card text-center">
|
|
<?php if ($logo): ?>
|
|
<img src="<?= htmlspecialchars($logo) ?>" alt="<?= htmlspecialchars($company_name) ?>" class="mb-3" style="max-height: 80px; max-width: 100%; object-fit: contain;">
|
|
<?php endif; ?>
|
|
<h4 class="mb-1 fw-bold"><?= htmlspecialchars($company_name) ?></h4>
|
|
<?php if ($branch_name): ?>
|
|
<p class="text-muted mb-4 small"><i class="bi bi-geo-alt-fill text-danger me-1"></i><?= htmlspecialchars($branch_name) ?></p>
|
|
<?php endif; ?>
|
|
|
|
<h2 class="mb-4 text-primary border-top pt-4"><?= __('staff_rating') ?></h2>
|
|
|
|
<?php if ($success): ?>
|
|
<div class="alert alert-success">
|
|
<i class="bi bi-check-circle-fill"></i> <?= __('rating_submitted') ?>
|
|
</div>
|
|
<a href="staff_rating.php<?= isset($_GET['branch_id']) ? '?branch_id=' . (int)$_GET['branch_id'] : '' ?>" class="btn btn-outline-primary mt-3"><?= __('submit_another') ?></a>
|
|
<?php else: ?>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger"><?= htmlspecialchars($error) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST">
|
|
<p class="text-muted mb-2"><?= __('how_rate_staff') ?></p>
|
|
<div class="stars">
|
|
<input type="radio" id="star5" name="rating" value="5" required />
|
|
<label for="star5" title="5 stars"><i class="bi bi-star-fill"></i></label>
|
|
<input type="radio" id="star4" name="rating" value="4" />
|
|
<label for="star4" title="4 stars"><i class="bi bi-star-fill"></i></label>
|
|
<input type="radio" id="star3" name="rating" value="3" />
|
|
<label for="star3" title="3 stars"><i class="bi bi-star-fill"></i></label>
|
|
<input type="radio" id="star2" name="rating" value="2" />
|
|
<label for="star2" title="2 stars"><i class="bi bi-star-fill"></i></label>
|
|
<input type="radio" id="star1" name="rating" value="1" />
|
|
<label for="star1" title="1 star"><i class="bi bi-star-fill"></i></label>
|
|
</div>
|
|
|
|
<div class="mb-4 text-start">
|
|
<label for="comment" class="form-label"><?= __('comment') ?> (<?= __('optional') ?>)</label>
|
|
<textarea class="form-control" id="comment" name="comment" rows="3" placeholder="<?= __('comment_placeholder') ?>"></textarea>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary btn-submit w-100"><?= __('submit_rating') ?></button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<footer class="footer">
|
|
<div class="container">
|
|
<span>© <?= date('Y') ?> <?= htmlspecialchars($company_name) ?>. <?= __('all_rights_reserved') ?></span>
|
|
</div>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|