forked from chriszhou1992/ABCD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowGameInfo.php
221 lines (181 loc) · 6.55 KB
/
showGameInfo.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
<?php
session_start();
$name = addslashes($_POST['game']);
require_once "classes/connecToDB.php";
$con = connectToDB();
if($con === false):
return;
endif;
$sql = "SELECT * FROM games WHERE name = '$name'";
$result = mysqli_query($con, $sql);
if(!$result) {
die('Error: ' . mysqli_error($con));
}
$row = mysqli_fetch_array($result);
echo '<div class="panel panel-default">
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#accordion" href="#title">';
echo "<div class='gameName' style='color: red;'>".$_POST['game']."</div>".'<span class="displayLikes float-right">Total Likes: '.$row['num_likes'].'</span>';
echo '</a>
</div>';
echo '<div id="title" class="panel-collapse collapse in">';
echo '<div class="panel-body">';
//echo "<div><i class='fa fa-thumbs-up float-right fa-2x'></i></div>";
//echo '<span class="displayLikes">Total Likes: '.$row['num_likes'].'</span>'
//. '<hr>';
$gameName = str_replace(" ", "!-!-!", $_POST['game']);
if(isset($_SESSION['user']) && checkIfGameLiked($con, $_SESSION['user'], $_POST['game'])) {
echo '<button type="button" class="btn btn-default float-right unlike" id="likeButton" name='.$gameName.'><i class="fa fa-thumbs-up"></i>  <span class="justLike">Unlike</span><span class="like"> '.$_POST['game']."</span></button>";
} else {
echo '<button type="button" class="btn btn-default float-right" id="likeButton" name='.$gameName.'><i class="fa fa-thumbs-up"></i>  <span class="justLike">Like</span><span class="like"> '.$_POST['game']."</span></button>";
}
/********tag system********/
require_once "classes/Tags.php";
//fetch tags for the company
$results = Tags::getGameTags($con, $row["id"]);
//display tags
Tags::printTags($results, $row["id"]);
echo '</div>';
echo '</div>';
echo "</div>";
$images = explode("<br>", $row['gameImageURLs']);
echo '<div id="gameCarousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">';
$imagSrc = $images[1];
echo " <div class='item active'>
<img src='$imagSrc' alt='Loading...' class='gameCarousel largeImages'>
<div class='container'>
<div class='carousel-caption'>
</div>
</div>
</div>";
for($i = 2; $i < count($images); $i++):
echo " <div class='item'>
<img src='$images[$i]' alt='Loading...' class='gameCarousel largeImages'>
<div class='container'>
<div class='carousel-caption'>
</div>
</div>
</div>";
endfor;
echo "</div>";
echo ' <a class="left carousel-control" href="#gameCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left gameC"></span>
</a>
<a class="right carousel-control" href="#gameCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right gameC"></span>
</a>';
echo '</div>';
echo '<div class="panel-group" id="accordion">';
echo '<div class="panel panel-default">
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#accordion" href="#publisher">
Publisher
</a>
</div>';
echo '<div id="publisher" class="panel-collapse collapse out">';
echo '<div class="panel-body">';
echo $row['publishers']."<br>";
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="panel panel-default">
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#accordion" href="#date">
Release date
</a>
</div>';
echo '<div id="date" class="panel-collapse collapse out">';
echo '<div class="panel-body">';
if($row['date_released'] == NULL) {
$new_date = "To be added...";
} else {
$date = new DateTime($row['date_released']);
$new_date= $date->format('M-d-Y');
}
echo $new_date."<br>";
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="panel panel-default">
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#accordion" href="#genres">
Genres
</a>
</div>';
echo '<div id="genres" class="panel-collapse collapse out">';
echo '<div class="panel-body">';
$genres = str_replace(" ", "<br>", trim($row['genres'], " "));
echo $genres."<br>";
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="panel panel-default">
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#accordion" href="#themes">
Themes
</a>
</div>';
echo '<div id="themes" class="panel-collapse collapse out">';
echo '<div class="panel-body">';
$themes = str_replace(" ", "<br>", trim($row['themes'], " "));
echo $themes."<br>";
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="panel panel-default">
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#accordion" href="#description">
Description
</a>
</div>';
echo '<div id="description" class="panel-collapse collapse out">';
echo '<div class="panel-body">';
echo $row['description']."<br>";
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="panel panel-default">
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#accordion" href="#platforms">
Platforms
</a>
</div>';
echo '<div id="platforms" class="panel-collapse collapse out">';
echo '<div class="panel-body">';
$platforms = substr($row['platforms'], 4);
echo $platforms."<br>";
echo '</div>';
echo '</div>';
echo '</div>';
echo '<div class="panel panel-default">';
echo ' <div class="panel-heading">
<a data-toggle="collapse" data-parent="#accordion" href="#gameImages">
Images
</a>
</div>';
echo '<div id="gameImages" class="panel-collapse collapse out">';
echo '<div class="panel-body">';
for($i = 1; $i < count($images); $i++):
echo "<img src='$images[$i]' alt='Loading...' class='smallImages'>";
endfor;
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div></div>';
function checkIfGameLiked($con, $username, $game) {
$sql = "SELECT gamesLiked FROM users WHERE email = '$username'";
$result = mysqli_query($con, $sql);
if(!$result) {
die('Error: ' . mysqli_error($con));
}
$row = mysqli_fetch_array($result);
if($row['gamesLiked'] === null) {
return false;
} else {
$games = $row['gamesLiked'];
}
$games = stripslashes($games);
$games = explode("<br>", $games);
return in_array($game, $games);
}