-
Notifications
You must be signed in to change notification settings - Fork 2
/
media_videogame.php
403 lines (324 loc) · 16.7 KB
/
media_videogame.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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<?php
/**
* SHOWS NON-DUPLICATE VIDEO GAMES LOGGED BY THE USER IN A GRID/GALLERY FORM. ON HOVERING ON AN ITEM THE DATE OF LOGGING IS DISPLAYED.
*
* @version PHP 8.0.12
* @since July 2022
* @author AtharvaShah
*/
session_start();
if (empty($_SESSION)) {
header("Location: login.php");
}
require "header.php";
require "connection.php";
require "functions.php";
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$user_data = check_login($con);
$username = $user_data['user_name'];
// flush();
// ob_flush();
?>
<!-------------------------------------------------------------------------------------
HTML PART
------------------------------------------------------------------------------------->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="shows videogames added by the user" />
<meta name="keywords" content="WYDRN, media videogame" />
<title>WYDRN - Your Video Games</title>
<!--Bootstrap Link-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<!--Custom Link-->
<link rel="stylesheet" href="CSS/media_videogame.css">
<link href="css/backToTop.css" rel="stylesheet">
<!--Preloader Links-->
<link rel="stylesheet" href="css/preloader.css">
<link rel="icon" type="image/png" href="images/website/favicons/favicon-32x32.png" sizes="32x32">
<link rel="apple-touch-icon" href="images/website/favicons/apple-touch-icon.png">
<script src="js/modernizr-2.6.2.min.js"></script>
<!--PRELOADER JS-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery-1.9.1.min.js"><\/script>')
</script>
<script>
$(document).ready(function() {
setTimeout(function() {
$('body').addClass('loaded');
$('h1').css('color', '#222222');
}, 500);
});
</script>
</head>
<body class="css-selector">
<button onclick="topFunction()" id="BackToTopBtn" title="Go to top">⇑</button>
<div>
<!--PRELOADER-->
<header class="entry-header">
<h1 class="entry-title"></h1>
</header>
<div id="loader-wrapper">
<div id="loader"></div>
<div class="loader-section section-left"></div>
<div class="loader-section section-right"></div>
</div>
<!--END OF PRELOADER-->
<!--ALL MEDIA ITEMS THAT WILL APPEAR AFTER PRELOADER-->
<div id="content">
<!--TITLE BANNER ANIMATED-->
<div class="my_container">
<h1 class="my-title"> YOUR VIDEOGAMES<br> <sub class="my-subtitle"><?php echo getRandomVideoGameQuote(); ?> </sub>
</h1>
<h1 class="my-title my-title-large">YOUR VIDEOGAMES</h1>
<div id="img-1" class="img-container">
<img class="img" src="images/website/assets/banners/games/1.jpg">
</div>
<div class="img-container second-animation">
<img class="img" src="images/website/assets/banners/games/2.jpg">
</div>
<div class="img-container third-animation">
<img class="img" src="images/website/assets/banners/games/3.jpg">
</div>
<div class="img-container fourth-animation">
<img class="img nba" src="images/website/assets/banners/games/4.jpg">
</div>
<div class="img-container fifth-animation">
<img class="img" src="images/website/assets/banners/games/5.jpg">
</div>
<div id="img-6" class="img-container sixth-animation">
<img class="img" src="images/website/assets/banners/games/6.jpg">
</div>
<div id="img-7" class="img-container seventh-animation">
<img class="img" src="images/website/assets/banners/games/7.png">
</div>
</div>
<div class="flex">
<!-- Sorting Functionality -->
<form method="get" action="" name="sort">
<select name="sortby" id="sort-by-select" onchange="this.form.submit()">
<option value="">Sort By</option>
<option value="added-desc">Added Date (Newest To Oldest)</option>
<option value="added-asc">Added Date (Oldest To Newest)</option>
<option value="alphabetic-asc">Videogame (A-Z)</option>
<option value="alphabetic-desc">Videogame (Z-A)</option>
<option value="platform-asc">Platform (A-Z)</option>
<option value="platform-desc">Platform(Z-A)</option>
</select>
</form>
<button class="btn" onclick="window.location.href='media_list_view.php?videogame'"><img src="images/Icons/list-view.png"></button>
</div>
<!--Display Active Filters-->
<?php if (isset($_GET['sortby'])) { ?>
<span class="active-filter">
<img src="images/Icons/sort.png" alt="filter" height="15px" width="10px" />
<?php echo $_GET['sortby']; ?>
</span>
<?php } ?>
<!-------------------------------------------------------------------------------------
DYNAMICALLY GENERATED PHP PART
------------------------------------------------------------------------------------->
<?php
//set default sort order
$sortby = "added-desc";
$sorting = "`date`"; //default sorting is by added date;
$order = "DESC"; //default order is newest to oldest
// default sorting is by added date;
if (isset($_GET["sortby"])) {
$sortby = $_GET["sortby"];
/*************** SORT BY DATE OF LOGGING ***********/
// Newest To Oldest
if ($sortby == "added-desc") {
$sorting = "`date`";
$order = "DESC";
}
//Oldest to Newest
else if ($sortby == "added-asc") {
$sorting = "`date`";
$order = "ASC";
}
/*************** SORT BY VIDEOGAME NAME ***********/
//A-Z
else if ($sortby == "alphabetic-asc") {
$sorting = "`videogame`";
$order = "ASC";
}
// Z-A
else if ($sortby == "alphabetic-desc") {
$sorting = "`videogame`";
$order = "DESC";
}
/*************** SORT BY GAMING PLATFORM***********/
//A-Z
else if ($sortby == "platform-asc") {
$sorting = "`platform`";
$order = "ASC";
}
//Z-A
else if ($sortby == "platform-desc") {
$sorting = "`platform`";
$order = "DESC";
}
} //end of if isset($_GET["sortby"])
// Number of entries to show in a page.
$per_page_record = 9;
// Look for a GET variable page if not found default is 1.
if (isset($_GET["page"])) {
$page = $_GET["page"];
} else {
$page = 1;
}
$start_from = ($page - 1) * $per_page_record;
?>
<br><br>
<section class='cards-wrapper'>
<?php
//only select unique videogames logged by the user
$sql = "SELECT `videogame`, `platform`, `date` FROM `data` where videogame != '' and username='$username' GROUP BY `videogame` order by " . $sorting . " " . $order . " LIMIT $start_from, $per_page_record;";
if ($query = mysqli_query($con, $sql)) {
$totalgamecount = mysqli_num_rows($query);
if ($totalgamecount > 0) {
while ($row = mysqli_fetch_assoc($query)) {
$game = $row['videogame'];
$platform = $row['platform'];
$game_logged = date("F jS, Y", strtotime($row['date']));
$stripgame = str_replace(' ', '+', $game);
//TO DISPLAY WHO HAS LOGGED THIS ITEM AMONG PEOPLE YOU ARE FOLLOWING
$followed_username = array();
$profile_pic = array();
try {
//this will throw an error if the name of the media contains an apostrophe.
$sql2 = "SELECT DISTINCT `follower_username`, `followed_username`, `videogame`, `profile_pic` FROM social
JOIN data ON data.username=social.followed_username
JOIN users on social.followed_username=users.user_name
WHERE social.follower_username='$username' and data.videogame='$game'
LIMIT 5";
$res = mysqli_query($con, $sql2);
while ($row = mysqli_fetch_assoc($res)) {
$followed_username[] = $row['followed_username'];
$profile_pic[] = $row['profile_pic'];
}
}
// TO CATCH APOSTROPHE ERROR AND CONTINUE
catch (mysqli_sql_exception $e) {
$error = $e->getMessage();
}
/**if poster is not downloaded, download the poster in the directory and show the image*/
//remove special characters since we are using it as a file name
$filename = preg_replace('/[^A-Za-z0-9\-]/', '', $stripgame);
$pseudo_poster = 'images/API/game-' . $filename . '.jpg';
if (file_exists($pseudo_poster)) {
$posterpath = $pseudo_poster;
} else {
$posterpath = GamePosterPath($stripgame); // URL to download file from
$img = 'images/API/game-' . $filename . '.jpg'; // Image path to save downloaded image
// Save image
file_put_contents($img, file_get_contents($posterpath));
}
?>
<!-- // one single div tag for each movie -->
<div class='card-grid-space'>
<!-- // image tag for the movie -->
<div class='card' style='background-image:url(<?php echo $posterpath; ?>);'>
<!--Delete item on hover-->
<div class='delete-item' title="Delete Videogame">
<img class="delete-icon" src="images/icons/delete.png" alt="Delete">
</div>
<!--Show logged date on hover-->
<div class='logged-date'><img src="images/Icons/plus.png" class="plus-icon"><?php echo $game_logged; ?></div>
<!--Contains Profile Pics of Users followed by logged in user and who have added the same media -->
<?php if (!empty($profile_pic) && !empty($followed_username)) {
echo "<div class='mutual-enjoyers'>";
foreach (array_combine($profile_pic, $followed_username) as $pic => $fname) {
echo "<img src='$pic' class='mutual-enjoyer-pic' alt='$fname' title='$fname'>";
}
echo "</div>";
} ?>
</div><!--END OF CARD-->
<h1 class='moviename'><?php echo $game; ?>
<div class='tags'>
<div class='tag'><?php echo $platform ?></div>
</div>
</h1>
</div>
<?php
}
} else {
?>
<!-- NO TV SHOWS LOGGED MESSAGE -->
<div class="zero-media"><img src='images/Icons/Videogame.svg' width='15' height='15' class='media-icon'> No Videogames added to your account.</div>
<?php }
}
?>
</section>
<!-------------------------------------------------------------------------------------
PAGINATION
------------------------------------------------------------------------------------->
<center>
<div class="pagination">
<?php
$query = "SELECT DISTINCT count(DISTINCT `videogame`) FROM `data` where videogame != '' and username='$username'";
$rs_result = mysqli_query($con, $query);
$row = mysqli_fetch_row($rs_result);
$total_records = $row[0];
echo "</br>";
// CALCULATING THE NUMBER OF PAGES
$total_pages = ceil($total_records / $per_page_record);
$pageLink = "";
// SHOW PREVIOUS BUTTON IF NOT ON PAGE 1
if ($page >= 2) {
echo "<a href='media_videogame.php?sortby=" . $sortby . "&page=" . ($page - 1) . "'> <span class='neonText'> ← </span> </a>";
}
// SHOW THE LINKS TO EACH PAGE IN THE PAGINATION GRID
for ($i = 1; $i <= $total_pages; $i++) {
if ($i == $page) {
$pageLink .= "<a class = 'active' href='media_videogame.php?page="
. $i . "'>" . $i . " </a>";
} else {
$pageLink .= "<a href='media_videogame.php?sortby=" . $sortby . "&page=" . $i . "'>" . $i . " </a>";
}
}
echo $pageLink;
// SHOW NEXT BUTTON IF NOT ON LAST PAGE
if ($page < $total_pages) {
echo "<a href='media_videogame.php?sortby=" . $sortby . "&page=" . ($page + 1) . "'> <span class='neonText'> → </span> </a>";
}
?>
</div>
<!--END OF PAGINATION ROW -->
</div>
<!--END OF MEDIA CONTENT -->
</div>
<!---END OF ENTIRE DOCUMENT (PRELOADER + MEDIA CONTENT) -->
</center>
<body>
<script src="js/backToTop.js"></script>
<script>
//Delete item on click
$('.delete-item').click(function() {
var gameName = $(this).closest('.card-grid-space').find('.moviename').text();
var parent = $(this).parent("div").parent("div");
//trim the name to remove trailing whitespace and match the name to be the same as the one in the database
gameName = gameName.substring(0, gameName.indexOf(' '));
console.log(gameName);
$.ajax({
type: "GET",
url: "delete_item.php",
data: 'videogame=' + gameName,
success: function() {
parent.fadeOut('slow', function() {
$(this).remove();
});
},
error: function() {
alert('This videogame could not be deleted!');
}
});
});
</script>
</html>
<?php mysqli_close($con); ?>