-
Notifications
You must be signed in to change notification settings - Fork 0
/
moviepage.php
357 lines (281 loc) · 9.56 KB
/
moviepage.php
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<html>
<head>
<meta charset="utf-8">
<title>handkerchief</title>
<link rel="stylesheet" type="text/css" href="main.css">
<style>
#poster
{
width: 240px;
float: left;
margin: 10px 0px;
margin-right: 15px;
}
#poster img
{
width: 240px;
height: 340px;
}
#details
{
float: left;
margin-left: 28px;
}
#details #name
{
font-size: 42px;
font-weight: bold;
display: block;
margin: 20px 0px;
color: #1034a6;
}
#details p
{
font-size: 17px;
margin-bottom: -12px;
}
#rating
{
float: left;
margin-top: 36px;
}
#rating #slider-container
{
margin-top: 24px;
}
#rating p #heart
{
font-size: 36px;
color: red;
}
#rating p #value
{
font-size: 28px;
color: #1034a6;
}
#rating #userrating
{
color: #1034a6;
font-size: 18px;
}
#rating #slider
{
vertical-align: text-top;
}
#rating #slider:hover
{
cursor: pointer;
}
#rating a
{
text-decoration: none;
}
#shows {padding-top: 40px;}
#date
{
display: block;
font-weight: bold;
font-size: 18px;
margin-bottom: 4px;
}
.show
{
margin: 10px 20px 50px 0px;
background-color: white;
color: green;
height: 36px;
font-size: 16px;
border: 1px solid grey;
border-radius: 1px;
cursor: pointer;
border-radius: 10px;
font-family: verdana;
}
.show:hover
{
color: white;
background-color: green;
}
</style>
</head>
<body>
<?php
include 'db.php';
session_start();
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$_SESSION["url"] = filter_var($url, FILTER_VALIDATE_URL);
$username = @$_SESSION["username"];
?>
<div id="header">
<div id="logo">
<a href='index.php'>handkerchief</a>
</div>
<div id="login">
<?php
$userId = 0;
$hasUserRated = 0;
if(@$username) {
$userId = @$_SESSION["userid"];
echo "
<a>Profile</a>
<div id='menu'>
<span id='username'>$username</span>
<a href='bookedtickets.php'>Booked Tickets</a>
<a href='logout.php'>Logout</a>
</div>";
}
else {
echo "<a href='login.php'>Login</a>";
}
?>
</div>
</div>
<div id="main">
<?php
$movieId = $_GET["movieId"];
//Extracting movie details from the table movie
$sql = "SELECT name, language, genre, age_certificate, release_date, format, runtime, poster FROM movie WHERE movie_id=$movieId";
if($result = mysqli_query($conn, $sql)) {
$row = mysqli_fetch_assoc($result);
$name = $row['name'];
$language = $row['language'];
$genre = $row['genre'];
$age_certificate = $row['age_certificate'];
$release_date = date_create($row['release_date']);
$release_date = date_format($release_date, "jS F Y");
$format = $row['format'];
$runtime = $row['runtime'];
$poster = $row['poster'];
}
else {
echo "<p>ERROR: Failed to execute query $sql ".mysqli_error($conn)."</p>";
}
//Extracting average movie rating from the table movie_rating
$sql = "SELECT AVG(rating) AS avg, COUNT(rating) AS votes FROM movie_rating WHERE movie_id=$movieId ";
if($result = mysqli_query($conn, $sql)) {
$row = mysqli_fetch_assoc($result);
$rating = round($row['avg']);
$number_of_votes = $row['votes'];
}
else {
echo "<p>ERROR: Failed to execute query $sql ".mysqli_error($conn)."</p>";
}
//Inserting the computed average movie rating into the table movie
$sql = "UPDATE movie SET rating=$rating WHERE movie_id=$movieId";
if(!mysqli_query($conn, $sql)) {
echo "<p>ERROR: Failed to execute query $sql ".mysqli_error($conn)."</p>";
}
//Extracting the user rating for the movie
$sql = "SELECT rating FROM movie_rating WHERE user_id=$userId AND movie_id=$movieId";
if($result = mysqli_query($conn, $sql)) {
$row = mysqli_fetch_assoc($result);
$user_rating = $row['rating'];
if($user_rating != 0) {
$hasUserRated = true;
}
else {
$hasUserRated = false;
}
}
else {
echo "<p>ERROR: Failed to execute query $sql ".mysqli_error($conn)."</p>";
}
?>
<div id='poster'><img src='<?php echo $poster ?>'></div>
<div id='details'>
<?php
echo "
<p id='name'>$name</p>
<p>$language $format<p>
<p>$genre ($age_certificate)</p>
<p>$release_date</p>
<p>$runtime mins</p>";
?>
<div id='rating'>
<p><span id='heart'>♥</span> <span id='value'><?php echo $rating; ?>%</span> (<?php echo $number_of_votes; ?> votes)</p>
<div id='slider-container'>
<?php
if($hasUserRated) {
echo "<p>Your rating: <span id='userrating'> $user_rating%</span></p>";
}
else {
echo "
<p>Rate it:</p>
<p>
<input type='range' min='10' max='100' value='10' step='10' id='slider'>
<span id='output'></span>% <a href='javascript:rateMovie()'>Submit</a>
</p>";
}
?>
</div>
</div>
</div>
<div class="clear"></div>
<div id="shows">
<?php
$sql = "SELECT * FROM movie_show WHERE movie_id=$movieId order by date,time";
$temp = '1st Jan, 0000';
if($result = mysqli_query($conn, $sql)) {
while($row = mysqli_fetch_assoc($result)) {
$show_date = date_create($row['date']);
$show_date = date_format($show_date, "j M, D");
if($show_date != $temp){
echo "<span id='date'>$show_date</span>";
$temp = $show_date;
}
$show_time = date_create($row['date']. " ". $row['time']);
$show_time = date_format($show_time, "h:i A");
echo "<button class='show' id=".$row['show_id']." onclick='getShowTime(this.id)'>".$show_time."</button>";
}
}
mysqli_close($conn);
?>
</div>
<form id='ratingForm' method='get' action='ratemovie.php' style='display:none'>
<input type="text" name='userId' value='<?php echo @$userId; ?>' id='userId'>
<input type="text" name='movieId' value='<?php echo @$movieId; ?>' id='movieId'>
</form>
<form id='showForm' method='get' action='screenpage.php' style='display:none'>
<input type="text" name='showId' id='showId'>
</form>
<div class="clear"></div>
</div>
<div id="footer"></div>
<script>
function getShowTime(showTime)
{
document.getElementById('showId').value = showTime;
document.getElementById('showForm').submit();
}
// Display the default slider value
var slider = document.getElementById("slider");
var output = document.getElementById("output");
output.innerHTML = slider.value;
// Update the current slider value (each time you drag the slider handle)
slider.oninput = function() {
output.innerHTML = this.value;
}
function rateMovie()
{
var userId = document.getElementById("userId").value;
var movieId = document.getElementById("movieId").value;
if(userId == 0){
alert("Please login to your account to give a rating");
}
else {
var givenRating = slider.value;
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function(){
if (this.readyState==4 && this.status==200){
document.getElementById('rating').innerHTML = this.responseText;
}
}
xmlhttp.open("GET","ratemovie.php?userId="+ userId +"&movieId="+ movieId +"&rating="+ givenRating, true);
xmlhttp.send();
}
}
</script>
</body>
</html>