From cbac17cdd4559b7ba5a5ca60267ea4ef92a452d2 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Tue, 10 Mar 2026 07:51:01 +0000 Subject: [PATCH] editing admin/rating --- admin/ratings.php | 268 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 237 insertions(+), 31 deletions(-) diff --git a/admin/ratings.php b/admin/ratings.php index c6a3185..41df72d 100644 --- a/admin/ratings.php +++ b/admin/ratings.php @@ -2,24 +2,34 @@ require_once __DIR__ . "/../includes/functions.php"; require_once __DIR__ . "/../db/config.php"; require_permission("ratings_view"); -require_once __DIR__ . '/../db/config.php'; $pdo = db(); $message = ''; +$tab = $_GET['tab'] ?? 'staff'; // Handle Add Rating (Manual) if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'add_rating') { - $user_id = (int)$_POST['user_id']; - $order_id = !empty($_POST['order_id']) ? (int)$_POST['order_id'] : null; $rating = (int)$_POST['rating']; $comment = trim($_POST['comment']); + $order_id = !empty($_POST['order_id']) ? (int)$_POST['order_id'] : null; - try { - $stmt = $pdo->prepare("INSERT INTO staff_ratings (user_id, order_id, rating, comment) VALUES (?, ?, ?, ?)"); - $stmt->execute([$user_id, $order_id, $rating, $comment]); - $message = '
Rating added successfully!
'; - } catch (PDOException $e) { - $message = '
Database error: ' . $e->getMessage() . '
'; + if ($tab === 'service') { + try { + $stmt = $pdo->prepare("INSERT INTO service_ratings (rating, comment) VALUES (?, ?)"); + $stmt->execute([$rating, $comment]); + $message = '
Service rating added successfully!
'; + } catch (PDOException $e) { + $message = '
Database error: ' . $e->getMessage() . '
'; + } + } else { + $user_id = (int)$_POST['user_id']; + try { + $stmt = $pdo->prepare("INSERT INTO staff_ratings (user_id, order_id, rating, comment) VALUES (?, ?, ?, ?)"); + $stmt->execute([$user_id, $order_id, $rating, $comment]); + $message = '
Rating added successfully!
'; + } catch (PDOException $e) { + $message = '
Database error: ' . $e->getMessage() . '
'; + } } } @@ -30,8 +40,9 @@ if (isset($_GET['delete'])) { } else { try { $id = $_GET['delete']; - $pdo->prepare("DELETE FROM staff_ratings WHERE id = ?")->execute([$id]); - header("Location: ratings.php?deleted=1"); + $table = ($tab === 'service') ? 'service_ratings' : 'staff_ratings'; + $pdo->prepare("DELETE FROM $table WHERE id = ?")->execute([$id]); + header("Location: ratings.php?tab=" . urlencode($tab) . "&deleted=1"); exit; } catch (PDOException $e) { $message = '
Error deleting rating: ' . $e->getMessage() . '
'; @@ -45,40 +56,220 @@ if (isset($_GET['deleted'])) { $staff = $pdo->query("SELECT id, full_name, username FROM users WHERE is_ratable = 1 ORDER BY full_name ASC")->fetchAll(); -$query = "SELECT r.*, u.full_name as staff_name, u.username as staff_username - FROM staff_ratings r - JOIN users u ON r.user_id = u.id - ORDER BY r.created_at DESC"; -$ratings_pagination = paginate_query($pdo, $query); -$ratings = $ratings_pagination['data']; +// Fetch summaries +if ($tab === 'staff') { + $whereParams = []; + $whereSql = ""; + if ($filter_staff) { + $whereSql .= " AND r.user_id = ?"; + $whereParams[] = $filter_staff; + } + if ($filter_start) { + $whereSql .= " AND DATE(r.created_at) >= ?"; + $whereParams[] = $filter_start; + } + if ($filter_end) { + $whereSql .= " AND DATE(r.created_at) <= ?"; + $whereParams[] = $filter_end; + } + + $summaryQuery = " + SELECT u.id, u.full_name, u.username, u.profile_pic, + AVG(r.rating) as avg_rating, COUNT(r.id) as total_ratings + FROM users u + JOIN staff_ratings r ON u.id = r.user_id + WHERE 1=1 $whereSql + GROUP BY u.id + ORDER BY avg_rating DESC + "; + $stmt = $pdo->prepare($summaryQuery); + $stmt->execute($whereParams); + $summaries = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $query = "SELECT r.*, u.full_name as staff_name, u.username as staff_username, u.profile_pic + FROM staff_ratings r + JOIN users u ON r.user_id = u.id + WHERE 1=1 $whereSql + ORDER BY r.created_at DESC"; + $ratings_pagination = paginate_query($pdo, $query, $whereParams); + $ratings = $ratings_pagination['data']; +} else { + $whereParams = []; + $whereSql = ""; + if ($filter_start) { + $whereSql .= " AND DATE(created_at) >= ?"; + $whereParams[] = $filter_start; + } + if ($filter_end) { + $whereSql .= " AND DATE(created_at) <= ?"; + $whereParams[] = $filter_end; + } + + $serviceSummaryQuery = "SELECT AVG(rating) as avg_rating, COUNT(id) as total_ratings FROM service_ratings WHERE 1=1 $whereSql"; + $stmt = $pdo->prepare($serviceSummaryQuery); + $stmt->execute($whereParams); + $serviceSummary = $stmt->fetch(PDO::FETCH_ASSOC); + + $query = "SELECT * FROM service_ratings WHERE 1=1 $whereSql ORDER BY created_at DESC"; + $ratings_pagination = paginate_query($pdo, $query, $whereParams); + $ratings = $ratings_pagination['data']; +} include 'includes/header.php'; ?>
-

Staff Ratings

- +

Ratings & Feedback

+
+ + Open Public Rating Page + + +
-
+ + + +
+
+
+ + + +
+ + +
+ + +
+ + +
+ +
+ + +
+ +
+
+ + + + + + +
+
+
+
+
+ + + +
+ +

No staff members have been rated yet.

+
+ +
+ +
+
+
+ + Staff + +
+ +
+ +
+ +
+
+ ' : ''; + } + ?> + () +
+

ratings

+
+
+
+ +
+ + +
+
+
+
+ +

Overall Service

+
+ 0): ?> + / 5.0 + + N/A + +
+
+ Based on reviews +
+
+
+
+
+ + +
+
+
+
- + $tab]); ?>
- + - + @@ -89,9 +280,20 @@ include 'includes/header.php';
+ + - + + + - + @@ -118,7 +322,7 @@ include 'includes/header.php';
- + $tab]); ?>
@@ -134,6 +338,7 @@ include 'includes/header.php';
DateStaff MemberStaff Member Rating CommentOrder IDOrder ID Actions
-
+
+ + + +
+ +
+ + +
@@ -100,17 +302,19 @@ include 'includes/header.php';
- +
No ratings found.No ratings found.