-
Notifications
You must be signed in to change notification settings - Fork 1
/
home.php
250 lines (239 loc) · 11.2 KB
/
home.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
<?php
session_start();
include_once 'dbconnect.php';
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
if( $_POST["rateit"] ) {
$myrating=$_POST['myrating'];
$mid_rating=$_POST['rateit'];
$q=mysql_query("SELECT * FROM ratings WHERE `mid`='$mid_rating' AND userid=".$_SESSION['user']);
$c=mysql_num_rows($q);
if($c==1){
$updateresult=mysql_query("UPDATE `ratings` SET `rating`='$myrating' WHERE `mid`='$mid_rating' AND userid=".$_SESSION['user']);
}
else{
$insertresult=mysql_query("INSERT INTO `ratings`(`mid`,`rating`,`comment`,`userid`) VALUES ($mid_rating,$myrating,'',".$_SESSION['user'].")");
if(!$insertresult){
die('Could not update ' . mysql_error());
}
}
}
/*
if(isset($_POST['rateit']))
{
$myrating=$_POST['myrating'];
}*/
$res=mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome - <?php echo $userRow['email']; ?></title>
<!-- Bootstrap -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" href="css/star-rating.css" media="all" type="text/css"/>
<link rel="stylesheet" href="css/theme-krajee-fa.css" media="all" type="text/css"/>
<script src="js/jquery.min.js"></script>
<script src="js/star-rating.js" type="text/javascript"></script>
<link rel="stylesheet" href="css/home.css" type="text/css" />
<script type="text/javascript" src="js/home.js"></script>
<!--
<script type="text/javascript">
(function movie(id) {
<?php //$_SESSION['movieid']=id; ?>
document.location.href="movie.php";
});
</script>
-->
</head>
<body background="images/background.jpg">
<div id="header">
<div id="left">
<label>Movie Rater</label>
</div>
<div id="right">
<div id="content">
Hello <a href="profile.php"><?php echo $userRow['username']; ?></a> <a href="logout.php?logout">Sign Out</a>
</div>
</div>
</div>
<center><h1>Popular Movies</h1></center>
<div class="container">
<div class="well well-sm">
<strong>Choose view</strong>
<div class="btn-group">
<a href="#" id="list" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-th-list">
</span>List</a> <a href="#" id="grid" class="btn btn-default btn-sm"><span
class="glyphicon glyphicon-th"></span>Grid</a>
</div>
</div>
<div id="products" class="row list-group">
<?php
$moviepopularquery=mysql_query("SELECT * FROM (SELECT mid as id, AVG(ratings.rating) as average FROM ratings GROUP BY mid) t1 NATURAL JOIN movie ORDER BY average DESC LIMIT 6");
for ($i=0; $i<6; $i++){
$popularmovierow = mysql_fetch_assoc($moviepopularquery);
$popularimage = "images/moviepics/".$popularmovierow['id'].".jpg";
if(file_exists($popularimage)==0){$popularimage = "images/moviepics/default.jpg";}
$Popularid=$popularmovierow['id'];
$result=mysql_query("SELECT * FROM ratings WHERE mid='$Popularid' AND userid=".$_SESSION['user']);
$countuser = mysql_num_rows($result);
if($countuser ==1){$myrating=mysql_fetch_array($result);$yy = $myrating['rating'];}
else{$yy =0;}
?>
<div class="item col-xs-4 col-lg-4">
<div class="thumbnail">
<?php echo '<img class="group list-group-image" src="'.$popularimage .'" alt="Random image" />'; ?>
<div class="caption">
<a href="movie.php?id=<?php echo $Popularid ?>"><h4 class="group inner list-group-item-heading">
<?php echo $popularmovierow['NAME'];
echo " ";
echo round($popularmovierow['average'],1);
?></h4></a>
<p class="group inner list-group-item-text">
Date :<?php echo $popularmovierow['YEAR']?></p>
<div class="row">
<div class="col-xs-12 col-md-6">
<div style=" width: 300px; ">
<div class="text-center">
<form action = "<?php $_PHP_SELF ?>" method = "post">
<input type="text" class="kv-fa rating-loading" name="myrating" value='<?php echo $yy?>' data-size="xs" title="">
<button class="btn btn-success btn-lg" name="rateit" value='<?php echo $Popularid?>' id="submitrate" style="padding: 2px 11px;">Rate it!</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php }
?>
</div>
</div>
<center><h1>Latest Movies</h1></center>
<div class="container">
<div id="products" class="row list-group">
<?php
//$movielatestquery=mysql_query("SELECT * FROM movie ORDER BY year desc LIMIT 6");
$movieview = mysql_query("CREATE OR REPLACE VIEW movieview AS SELECT id, NAME, YEAR FROM movie ORDER BY year desc");
$movielatestquery=mysql_query("SELECT * FROM movieview LIMIT 6");
for ($i=0; $i<6; $i++){
$latestmovierow = mysql_fetch_assoc($movielatestquery);
$latestimage = "images/moviepics/".$latestmovierow['id'].".jpg";
if(file_exists($latestimage)==0){$latestimage = "images/moviepics/default.jpg";}
$Latestid=$latestmovierow['id'];
$result=mysql_query("SELECT * FROM ratings WHERE mid='$Latestid' AND userid=".$_SESSION['user']);
$countuser = mysql_num_rows($result);
if($countuser ==1){$myrating=mysql_fetch_array($result);$yy = $myrating['rating'];}
else{$yy =0;}
$averagequery=mysql_query("SELECT * FROM (SELECT mid, AVG(ratings.rating) as average FROM ratings GROUP BY mid) t1 WHERE mid='$Latestid'");
$countaverage = mysql_num_rows($averagequery);
if($countaverage ==1){$averagerating=mysql_fetch_array($averagequery);$tt = $averagerating['average'];}
else{$tt = 0;}
?>
<div class="item col-xs-4 col-lg-4">
<div class="thumbnail">
<?php echo '<img class="group list-group-image" src="'.$latestimage .'" alt="Random image" />'; ?>
<div class="caption">
<a href="movie.php?id=<?php echo $Latestid ?>" ><h4 class="group inner list-group-item-heading">
<?php echo $latestmovierow['NAME'];
echo " ";
echo round($tt,1);
?></h4></a>
<p class="group inner list-group-item-text">
Date :<?php echo $latestmovierow['YEAR']?></p>
<div class="row">
<div class="col-xs-12 col-md-6">
<div style=" width: 300px; ">
<div class="text-center">
<form action = "<?php $_PHP_SELF ?>" method = "post">
<input type="text" class="kv-fa rating-loading" name="myrating" value='<?php echo $yy?>' data-size="xs" title="">
<button class="btn btn-success btn-lg" name="rateit" type="number" value='<?php echo $Latestid?>' id="submitrate" style="padding: 2px 11px;">Rate it!</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php }
?>
</div>
</div>
<center><h1>All Movies</h1></center>
<div class="container">
<div id="products" class="row list-group">
<?php
// $files = glob("images/moviepics/*.jpg");
$movieallquery=mysql_query("SELECT * FROM movie ");
$Count = mysql_num_rows($movieallquery);
for ($i=0; $i<$Count; $i++){
$allmovierow = mysql_fetch_assoc($movieallquery);
// echo $allmovierow['id'];
$movieid = $allmovierow['id'];
$image = "images/moviepics/".$movieid.".jpg";
if(file_exists($image)==0){$image = "images/moviepics/default.jpg";}
$resultall=mysql_query("SELECT * FROM ratings WHERE mid='$movieid' AND userid=".$_SESSION['user']);
$countuserall = mysql_num_rows($resultall);
if($countuserall ==1){
$myratingall=mysql_fetch_array($resultall);$yy1 = $myratingall['rating'];
}
else{
$yy1 =0;
}
$averagequeryall=mysql_query("SELECT * FROM (SELECT mid, AVG(ratings.rating) as average FROM ratings GROUP BY mid) t1 WHERE mid='$movieid'");
$countaverageall = mysql_num_rows($averagequeryall);
if($countaverageall ==1){$averageratingall=mysql_fetch_array($averagequeryall); $tt1 = $averageratingall['average'];}
else{$tt1 = 0;}
?>
<div class="item col-xs-4 col-lg-4">
<div class="thumbnail">
<?php echo '<img class="group list-group-image" src="'.$image .'" alt="Random image" />'; ?>
<div class="caption">
<a href="movie.php?id=<?php echo $movieid ?>" ><h4 class="group inner list-group-item-heading">
<?php echo $allmovierow['NAME'];
echo " ";
echo round($tt1,1);
?></h4></a>
<p class="group inner list-group-item-text">
Date :<?php echo $allmovierow['YEAR']?></p>
<div class="row">
<div class="col-xs-12 col-md-6">
<div style=" width: 300px; ">
<div class="text-center">
<form action = "<?php $_PHP_SELF ?>" method = "post">
<input type="text" class="kv-fa rating-loading" name="myrating" value='<?php echo $yy1?>' data-size="xs" title="">
<button class="btn btn-success btn-lg" name="rateit" value='<?php echo $movieid?>' id="submitrate" style="padding: 2px 11px;">Rate it!</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php }
?>
</div>
</div>
</body>
<script>
$(document).on('ready', function () {
$('.kv-fa').rating({
theme: 'krajee-fa',
filledStar: '<i class="fa fa-star"></i>',
emptyStar: '<i class="fa fa-star-o"></i>'
});
$('.rating,.kv-fa').on(
'change', function () {
console.log('Rating selected: ' + $(this).val());
});
});
</script>
</html>