adding branches to rating
This commit is contained in:
parent
c6d83786d4
commit
c8388831c1
@ -27,6 +27,9 @@ $translations = [
|
||||
'ratings' => 'Ratings',
|
||||
'staff_rating' => 'Staff Rating',
|
||||
'service_rating' => 'Service Rating',
|
||||
'branch_links' => 'Branch Links',
|
||||
'copy_link' => 'Copy Link',
|
||||
'link_copied' => 'Copied!',
|
||||
'rating' => 'Rating',
|
||||
'comment' => 'Comment',
|
||||
'rating_type' => 'Type',
|
||||
@ -301,6 +304,9 @@ $translations = [
|
||||
'ratings' => 'التقييمات',
|
||||
'staff_rating' => 'تقييم الموظفين',
|
||||
'service_rating' => 'تقييم الخدمة',
|
||||
'branch_links' => 'روابط الفروع',
|
||||
'copy_link' => 'نسخ الرابط',
|
||||
'link_copied' => 'تم النسخ!',
|
||||
'rating' => 'التقييم',
|
||||
'comment' => 'تعليق',
|
||||
'rating_type' => 'النوع',
|
||||
|
||||
128
ratings.php
128
ratings.php
@ -17,21 +17,32 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
|
||||
$from_date = $_GET['from_date'] ?? date('Y-m-01');
|
||||
$to_date = $_GET['to_date'] ?? date('Y-m-t');
|
||||
$type_filter = $_GET['type'] ?? 'all';
|
||||
$branch_filter = $_GET['branch_id'] ?? 'all';
|
||||
|
||||
$where = "WHERE DATE(created_at) BETWEEN ? AND ?";
|
||||
$where = "WHERE DATE(ratings.created_at) BETWEEN ? AND ?";
|
||||
$params = [$from_date, $to_date];
|
||||
|
||||
if ($type_filter !== 'all') {
|
||||
$where .= " AND rating_type = ?";
|
||||
$where .= " AND ratings.rating_type = ?";
|
||||
$params[] = $type_filter;
|
||||
}
|
||||
|
||||
if ($branch_filter !== 'all') {
|
||||
$where .= " AND ratings.branch_id = ?";
|
||||
$params[] = $branch_filter;
|
||||
}
|
||||
|
||||
// Fetch branches for filter and modal
|
||||
$branches_stmt = db()->query("SELECT id, name_en, name_ar FROM branches ORDER BY name_en");
|
||||
$all_branches = $branches_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Summary Stats
|
||||
$stmt = db()->prepare("
|
||||
SELECT
|
||||
COUNT(*) as total_ratings,
|
||||
AVG(rating_value) as avg_rating
|
||||
AVG(ratings.rating_value) as avg_rating
|
||||
FROM ratings
|
||||
LEFT JOIN branches b ON ratings.branch_id = b.id
|
||||
$where
|
||||
");
|
||||
$stmt->execute($params);
|
||||
@ -42,10 +53,11 @@ $avg_rating = round($stats['avg_rating'] ?: 0, 1);
|
||||
|
||||
// Detail Records
|
||||
$stmt = db()->prepare("
|
||||
SELECT *
|
||||
SELECT ratings.*, b.name_en AS branch_name_en, b.name_ar AS branch_name_ar
|
||||
FROM ratings
|
||||
LEFT JOIN branches b ON ratings.branch_id = b.id
|
||||
$where
|
||||
ORDER BY created_at DESC
|
||||
ORDER BY ratings.created_at DESC
|
||||
");
|
||||
$stmt->execute($params);
|
||||
$ratings = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
@ -70,9 +82,9 @@ $ratings = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
<h1 class="h3 mb-0 text-gray-800"><?= __('ratings') ?></h1>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<a href="rate.php" target="_blank" class="btn btn-sm btn-outline-info"><i class="bi bi-box-arrow-up-right"></i> <?= __('rate_us') ?></a>
|
||||
<a href="staff_rating.php" target="_blank" class="btn btn-sm btn-outline-primary"><i class="bi bi-box-arrow-up-right"></i> <?= __('staff_rating') ?></a>
|
||||
<a href="service_rating.php" target="_blank" class="btn btn-sm btn-outline-primary"><i class="bi bi-box-arrow-up-right"></i> <?= __('service_rating') ?></a>
|
||||
<button type="button" class="btn btn-sm btn-outline-info" data-bs-toggle="modal" data-bs-target="#branchLinksModal">
|
||||
<i class="bi bi-link-45deg"></i> <?= __('branch_links') ?? 'Branch Links' ?>
|
||||
</button>
|
||||
<form method="POST" class="d-inline" onsubmit="return confirm('<?= __('confirm_clear_ratings') ?>');">
|
||||
<input type="hidden" name="action" value="clear_ratings">
|
||||
<button type="submit" class="btn btn-sm btn-danger ms-2"><i class="bi bi-trash"></i> <?= __('clear_ratings') ?></button>
|
||||
@ -84,14 +96,25 @@ $ratings = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
<div class="card shadow-sm mb-4">
|
||||
<div class="card-body">
|
||||
<form method="GET" class="row gx-3 gy-2 align-items-center">
|
||||
<div class="col-sm-3">
|
||||
<div class="col-sm-2">
|
||||
<label class="visually-hidden"><?= __('from_date') ?></label>
|
||||
<input type="date" class="form-control" name="from_date" value="<?= htmlspecialchars($from_date) ?>">
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<div class="col-sm-2">
|
||||
<label class="visually-hidden"><?= __('to_date') ?></label>
|
||||
<input type="date" class="form-control" name="to_date" value="<?= htmlspecialchars($to_date) ?>">
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<label class="visually-hidden"><?= __('branch') ?></label>
|
||||
<select class="form-select" name="branch_id">
|
||||
<option value="all" <?= $branch_filter == 'all' ? 'selected' : '' ?>><?= __('all_branches') ?></option>
|
||||
<?php foreach($all_branches as $br): ?>
|
||||
<option value="<?= $br['id'] ?>" <?= $branch_filter == $br['id'] ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars(is_arabic() ? $br['name_ar'] : $br['name_en']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<label class="visually-hidden"><?= __('rating_type') ?></label>
|
||||
<select class="form-select" name="type">
|
||||
@ -100,7 +123,7 @@ $ratings = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
<option value="service" <?= $type_filter == 'service' ? 'selected' : '' ?>><?= __('service') ?></option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<div class="col-sm-2">
|
||||
<button type="submit" class="btn btn-primary w-100"><i class="bi bi-search"></i> <?= __('filter') ?></button>
|
||||
</div>
|
||||
</form>
|
||||
@ -155,6 +178,7 @@ $ratings = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th><?= __('date') ?></th>
|
||||
<th><?= __('branch') ?></th>
|
||||
<th><?= __('rating_type') ?></th>
|
||||
<th><?= __('rating') ?></th>
|
||||
<th><?= __('comment') ?></th>
|
||||
@ -163,12 +187,13 @@ $ratings = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
<tbody>
|
||||
<?php if (empty($ratings)): ?>
|
||||
<tr>
|
||||
<td colspan="4" class="text-center text-muted"><?= __('no_data_available') ?? 'No data available' ?></td>
|
||||
<td colspan="5" class="text-center text-muted"><?= __('no_data_available') ?? 'No data available' ?></td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($ratings as $r): ?>
|
||||
<tr>
|
||||
<td><?= date('Y-m-d H:i', strtotime($r['created_at'])) ?></td>
|
||||
<td><?= htmlspecialchars(is_arabic() ? ($r['branch_name_ar'] ?? '-') : ($r['branch_name_en'] ?? '-')) ?></td>
|
||||
<td>
|
||||
<?php if ($r['rating_type'] === 'staff'): ?>
|
||||
<span class="badge bg-info text-dark"><?= __('staff') ?></span>
|
||||
@ -193,4 +218,81 @@ $ratings = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
</div>
|
||||
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
<!-- Branch Links Modal -->
|
||||
<div class="modal fade" id="branchLinksModal" tabindex="-1" aria-labelledby="branchLinksModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="branchLinksModalLabel"><i class="bi bi-link-45deg"></i> <?= __('branch_links') ?? 'Branch Links' ?></h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p class="text-muted small mb-4"><?= is_arabic() ? 'انسخ الرابط الخاص بكل فرع لمشاركته مع العملاء. سيتم تسجيل التقييمات تلقائياً تحت الفرع الصحيح.' : 'Copy the unique link for each branch to share with customers. Ratings will automatically be recorded under the correct branch.' ?></p>
|
||||
<div class="list-group">
|
||||
<?php
|
||||
$base_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]" . dirname($_SERVER['PHP_SELF']);
|
||||
if (empty($all_branches)): ?>
|
||||
<div class="list-group-item text-muted text-center py-4">No branches found.</div>
|
||||
<?php else: ?>
|
||||
<?php foreach($all_branches as $br):
|
||||
$br_name = is_arabic() ? $br['name_ar'] : $br['name_en'];
|
||||
$br_link = $base_url . "/rate.php?branch_id=" . $br['id'];
|
||||
?>
|
||||
<div class="list-group-item d-flex justify-content-between align-items-center py-3">
|
||||
<div class="me-3" style="word-break: break-all;">
|
||||
<h6 class="mb-1 fw-bold"><?= htmlspecialchars($br_name) ?></h6>
|
||||
<a href="<?= htmlspecialchars($br_link) ?>" target="_blank" class="text-decoration-none small text-primary"><?= htmlspecialchars($br_link) ?></a>
|
||||
</div>
|
||||
<button class="btn btn-sm btn-outline-secondary text-nowrap" onclick="copyToClipboard('<?= $br_link ?>', this)">
|
||||
<i class="bi bi-clipboard"></i> <span class="d-none d-sm-inline"><?= __('copy_link') ?? 'Copy Link' ?></span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function copyToClipboard(text, btn) {
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(text).then(function() {
|
||||
let originalHtml = btn.innerHTML;
|
||||
btn.innerHTML = '<i class="bi bi-check2"></i> <span class="d-none d-sm-inline"><?= __('link_copied') ?? 'Copied!' ?></span>';
|
||||
btn.classList.remove('btn-outline-secondary');
|
||||
btn.classList.add('btn-success', 'text-white');
|
||||
setTimeout(function() {
|
||||
btn.innerHTML = originalHtml;
|
||||
btn.classList.remove('btn-success', 'text-white');
|
||||
btn.classList.add('btn-outline-secondary');
|
||||
}, 2000);
|
||||
});
|
||||
} else {
|
||||
// Fallback for older browsers / http
|
||||
let textArea = document.createElement("textarea");
|
||||
textArea.value = text;
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
let originalHtml = btn.innerHTML;
|
||||
btn.innerHTML = '<i class="bi bi-check2"></i> <span class="d-none d-sm-inline"><?= __('link_copied') ?? 'Copied!' ?></span>';
|
||||
btn.classList.remove('btn-outline-secondary');
|
||||
btn.classList.add('btn-success', 'text-white');
|
||||
setTimeout(function() {
|
||||
btn.innerHTML = originalHtml;
|
||||
btn.classList.remove('btn-success', 'text-white');
|
||||
btn.classList.add('btn-outline-secondary');
|
||||
}, 2000);
|
||||
} catch (err) {
|
||||
console.error('Unable to copy', err);
|
||||
}
|
||||
document.body.removeChild(textArea);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user