-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.php
More file actions
190 lines (160 loc) · 6.13 KB
/
client.php
File metadata and controls
190 lines (160 loc) · 6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
session_start();
// Check if the session variable is set
if(isset($_SESSION["username"])) {
$username = $_SESSION["username"];
} else {
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1
header("Pragma: no-cache"); // HTTP 1.0
header("Expires: 0"); // Proxies
session_unset();
session_destroy();
header('Location: index.php');
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Client Dashboard | Gym Portal</title>
<link rel="stylesheet" href="./css/client.css?v=<?php echo time(); ?>">
<style>
</style>
<script>
function toggleReviewForm(id) {
let form = document.getElementById('review-form-' + id);
if (form.style.display === 'flex') {
form.style.display = 'none';
} else {
form.style.display = 'flex';
}
}
</script>
</head>
<body>
<div class="client-dashboard">
<?php
echo '<h1 class="client-title">Welcome, ' . htmlspecialchars($username) . '!</ h1>';
?>
<form action="logout.php" method="POST">
<button type="submit">Logout</button>
</form>
<h2 style="text-align:center; color:#2d3a4b; margin-bottom:18px;">Our Instructors</h2>
<div class="instructors-grid">
<?php
include "db.php";
$sql = "SELECT
r.review_id,
r.rating,
r.comment,
-- Reviewer's name
reviewer.first_name AS reviewer_first_name,
reviewer.last_name AS reviewer_last_name,
-- Instructor's name
instructor_user.first_name AS instructor_first_name,
instructor_user.last_name AS instructor_last_name,
i.bio,
i.photo,
i.specialties,
i.instructor_id
FROM instructors i
-- Join to get instructor info
LEFT JOIN reviews r ON r.instructor_id = i.instructor_id
LEFT JOIN users instructor_user ON i.instructor_id = instructor_user.user_id
-- Join to get reviewer info
LEFT JOIN users reviewer ON r.user_id = reviewer.user_id
LIMIT 8
"
;
$stmt = $conn->prepare($sql);
$stmt->execute();
$results = $stmt->get_result();
$instructors = [];
while($row = $results->fetch_assoc()) {
$instructors[$row['instructor_first_name'] . ' ' . $row['instructor_last_name']][] = $row;
}
foreach($instructors as $instructor_name => $reviews) {
$instructor = $reviews[0];
$random_number = rand();
echo '
<div class="instructor-card">
<img class="instructor-photo" src="uploads/'.htmlspecialchars($instructor['photo']).'" alt="Instructor '. htmlspecialchars($instructor['instructor_first_name']) .'">
<div class="instructor-name">'. htmlspecialchars($instructor_name) .'</div>
<div class="instructor-specialty">'. htmlspecialchars($instructor['specialties']) .'</div>
<div class="reviews-title">Client Reviews</div>
';
if(empty($reviews[0]['review_id'])) {
echo '
<div class="no-review">
No Reviews Yet.
</div>
<form method="GET" action="booking.php">
<input type="hidden" name="instructor_id" value="'. htmlspecialchars($instructor['instructor_id']).'">
<button type="submit" class="book-btn">Book Session</button>
</form>
<button class="review-btn" onclick="toggleReviewForm('.$random_number.')">Leave Review</button>
<form method="POST" action="submit_review.php" class="review-form" id="review-form-'.$random_number.'">
<input type="hidden" name="instructor_id" value="'.htmlspecialchars($instructor['instructor_id']).'">
<textarea name="comment" placeholder="Write your review..."></textarea>
<button type="submit">Submit</button>
</form>
</div>
';
} else {
$reviewCount = 0;
foreach($reviews as $review){
if(!empty($review['review_id'])){
echo '
<div class="review">
<span class="review-client">- '.htmlspecialchars($review['reviewer_first_name']).'</span>
"'. htmlspecialchars($review['comment']).'"
</div>
';
$reviewCount++;
if($reviewCount >= 2) break;
}
}
echo '
<form method="GET" action="booking.php">
<input type="hidden" name="instructor_id" value="'. htmlspecialchars($instructor['instructor_id']).'">
<button type="submit" class="book-btn">Book Session</button>
</form>
';
echo '<button class="review-btn" onclick="toggleReviewForm('.$random_number.')">Leave Review</button>
<form method="POST" action="submit_review.php" class="review-form" id="review-form-'.htmlspecialchars($random_number).'">
<input type="hidden" name="instructor_id" value="'. htmlspecialchars($instructor['instructor_id']).'">
<textarea name="comment" placeholder="Write your review..." required></textarea>
<button type="submit">Submit</button>
</form>
</div>
';
}
}
?>
<!-- <div class="instructor-card">
<img class="instructor-photo" src="https://randomuser.me/api/portraits/men/32.jpg" alt="Instructor John">
<div class="instructor-name">John Carter</div>
<div class="instructor-specialty">Strength & Conditioning</div>
<div class="reviews-title">Client Reviews</div>
<div class="review">
<span class="review-client">- Mike</span>
"John's workouts are intense but effective. Highly recommend!"
</div>
<div class="review">
<span class="review-client">- Sarah</span>
"Very motivating and knowledgeable trainer."
</div>
<button class="book-btn">Book Session</button>
<button class="review-btn" onclick="toggleReviewForm(1)">Leave Review</button>
<form class="review-form" id="review-form-1">
<textarea placeholder="Write your review..."></textarea>
<button type="submit">Submit</button>
</form>
</div> -->
<!-- Instructor 2 -->
<!-- Instructor 3 -->
<!-- Instructor 4 -->
</div>
</div>
</body>
</html>