-
Notifications
You must be signed in to change notification settings - Fork 0
/
photo.php
341 lines (294 loc) · 15.1 KB
/
photo.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
<!DOCTYPE html>
<?php
include("dbconfig.php");
session_start();
if (isset($_SESSION['login_user'])) {
$user_email = $_SESSION['login_user'];
} else {
$user_email = "error";
}
$load_accountID = "SELECT accountID FROM Account WHERE email_address = '$user_email'";
$user_accountID = mysqli_fetch_assoc(mysqli_query($conn, $load_accountID))['accountID'];
$bp_ID = $_GET['photoID'];
$select_photo_query = "SELECT Photo.accountID, image, title, timestamp, photoID, collectionID, name FROM Photo INNER JOIN Account ON Photo.accountID = Account.accountID WHERE photoID = $bp_ID";
$result = mysqli_query($conn, $select_photo_query)
or die('Error making select photo query' . mysql_error());
$Photo = mysqli_fetch_array($result);
//Add Annotation
if (isset($_POST['annotation'])) {
$annotation = $_POST['annotation'];
//if annotation exists, delete it
$search_annotation_Query = "SELECT * FROM Annotation WHERE photoID = $bp_ID AND accountID = $user_accountID AND annotation LIKE '%$annotation%'";
$result = mysqli_query($conn, $search_annotation_Query)
or die('Error making search annotation query' . mysql_error());
$anno = mysqli_fetch_array($result);
if ($anno) {
$delete_annotation_Query = "DELETE FROM Annotation WHERE photoID = $bp_ID AND accountID = $user_accountID AND annotation LIKE '%$annotation%'";
$result = mysqli_query($conn, $delete_annotation_Query)
or die('Error making delete annotation query' . mysql_error());
} else {
$insert_annotatin_Query = "INSERT INTO Annotation (photoID, accountID, annotation)
VALUES ( '$bp_ID', '$user_accountID','$annotation')";
$result = mysqli_query($conn, $insert_annotatin_Query)
or die('Error making insert annotation query' . mysql_error());
}
}
//Add Comments
if (isset($_POST['comment'])) {
$comment = mysqli_real_escape_string($conn, $_POST['comment']);
$insert_comment_Query = "INSERT INTO Comment (photoID, accountID, comment)
VALUES ( '$bp_ID', '$user_accountID','$comment')";
$result = mysqli_query($conn, $insert_comment_Query)
or die('Error making insert comments query' . mysql_error());
}
//Delete Comments
if (isset($_POST['delete'])) {
$timeOfComment = $_POST['delete'];
$delete_comment_Query = "DELETE FROM Comment WHERE photoID = $bp_ID AND accountID = $user_accountID AND timestamp = '$timeOfComment'";
$result = mysqli_query($conn, $delete_comment_Query)
or die('Error making delete comment query' . mysql_error());
}
// Get all comments on photo
$comments = array();
$select_comments_query = "SELECT photoID, Comment.accountID, timestamp, comment, name FROM Comment INNER JOIN Account ON Comment.accountID = Account.accountID WHERE photoID = $bp_ID ORDER BY timestamp ASC";
$result = mysqli_query($conn, $select_comments_query)
or die('Error making select comments query' . mysql_error());
$k = 0;
while ($row = mysqli_fetch_array($result)) {
$comments[$k] = $row;
$k = $k + 1;
}
// Get all annotations on photo
$annotations = array();
$select_annotations_query = "SELECT name, annotation FROM Annotation INNER JOIN Account ON Annotation.accountID = Account.accountID WHERE photoID = $bp_ID";
$result = mysqli_query($conn, $select_annotations_query)
or die('Error making select annotations query' . mysql_error());
$k = 0;
while ($row = mysqli_fetch_array($result)) {
$annotations[$k] = $row;
$k = $k + 1;
}
function display($annotations, $type) {
for ($x = 0; $x < count($annotations); $x++) {
$Anno = $annotations[$x];
if ($Anno[1] === $type) {
echo "<li> ${Anno[0]}\n </li>";
}
}
}
function displayComments($comments, $user_accountID) {
for ($x = 0; $x < count($comments); $x++) {
$Comment = $comments[$x];
if ($Comment[1] == $user_accountID) {
echo "
<form name=\"delete\" action=\"photo.php?photoID=$Comment[0]\" id=\"delete\" method=\"post\">
<div class = \"chat-body clearfix\">
<div class = \"header\">
<strong class = \"primary-font\">${Comment[4]}</strong>
<small class = \"pull-right text-muted\">
<i class = \"fa fa-clock-o fa-fw\"></i> ${Comment[2]}
</small>
</div>
<p>
${Comment[3]}
<input name=\"delete\" type=\"hidden\" id=\"delele\" value=\"$Comment[2]\" />
<small class = \"pull-right text-muted\">
<button type=\"submit\" class=\"btn-default btn-xs\" >
<i class=\"fa fa-times\" aria-hidden=\"true\"></i>
</button>
</small>
</p>
</div>
</form>";
} else {
echo "
<div class = \"chat-body clearfix\">
<div class = \"header\">
<strong class = \"primary-font\">${Comment[4]}</strong>
<small class = \"pull-right text-muted\">
<i class = \"fa fa-clock-o fa-fw\"></i> ${Comment[2]}
</small>
</div>
<p>
${Comment[3]}";
echo "
</p>
</div>";
}
}
}
?>
<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">
<meta name="description" content="">
<meta name="author" content="">
<title><?php echo $Photo[2] ?></title>
<!-- Bootstrap Core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Theme CSS -->
<link href="css/clean-blog.min.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<link href="https://afeld.github.io/emoji-css/emoji.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src = "https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Page Header -->
<!-- Set your background image for this header on the line below. -->
<header class="intro-header">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<h1><?php echo $Photo[2] ?></h1>
<span class="meta"><a href="#"><?php echo $Photo[6] ?></a> uploaded at <?php echo $Photo[3] ?></span>
</div>
</div>
</div>
</header>
<!-- Post Content -->
<article>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<img class="img-responsive" src="images/<?php echo $Photo[1] ?>">
</div>
</div>
</div>
</article>
<hr>
<article>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<form name="like" action='photo.php?photoID=<?php echo $bp_ID ?>' id="like" method='post'>
<input name="annotation" type="hidden" id="annotation" value="like" />
<button type="submit" class="btn btn-default btn-xs" ><i class="glyphicon glyphicon-thumbs-up"></i> Like </button>
<div class="btn-group pull-right">
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-chevron-down"></i>
</button>
<ul class="dropdown-menu slidedown">
<li>
<u><b>Like</b></u>
</li>
<li class="divider"></li>
<?php display($annotations, 'like') ?>
</ul>
</div>
</form>
<form name="love" action='photo.php?photoID=<?php echo $bp_ID ?>' id="love" method='post'>
<button type="submit" class="btn btn-default btn-xs"><i class="glyphicon glyphicon-heart"></i> Love </button>
<input name="annotation" type="hidden" id="annotation" value="love" />
<div class="btn-group pull-right">
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-chevron-down"></i>
</button>
<ul class="dropdown-menu slidedown">
<li>
<u><b>Love</b></u>
</li>
<li class="divider"></li>
<?php display($annotations, 'love') ?>
</ul>
</div>
</form>
<form name="sad" action='photo.php?photoID=<?php echo $bp_ID ?>' id="sad" method='post'>
<button type="submit" class="btn btn-default btn-xs"><i class="em em-disappointed"></i> Sad </button>
<input name="annotation" type="hidden" id="annotation" value="sad" />
<div class="btn-group pull-right">
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-chevron-down"></i>
</button>
<ul class="dropdown-menu slidedown">
<li>
<u><b>Sad</b></u>
</li>
<li class="divider"></li>
<?php display($annotations, 'sad') ?>
</ul>
</div>
</form>
<form name="angry" action='photo.php?photoID=<?php echo $bp_ID ?>' id="angry" method='post'>
<button type="submit" class="btn btn-default btn-xs"><i class="em em-angry"></i> Angry</button>
<input name="annotation" type="hidden" id="annotation" value="angry" />
<div class="btn-group pull-right">
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-chevron-down"></i>
</button>
<ul class="dropdown-menu slidedown">
<li>
<u><b>Angry</b></u>
</li>
<li class="divider"></li>
<?php display($annotations, 'angry') ?>
</ul>
</div>
</form>
</div>
</div>
</article>
<!-- /.panel -->
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="chat-panel panel panel-default">
<div class="panel-heading">
<i class="fa fa-comments fa-fw"></i> Comments
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<ul class="chat">
<?php displayComments($comments, $user_accountID) ?>
</ul>
</div>
<!-- /.panel-body -->
<div class="panel-footer">
<form name="comment" action='photo.php?photoID=<?php echo $bp_ID ?>' id="comment" method='post'>
<div class="input-group">
<input name="comment" id="comment" type="text" class="form-control input-sm" placeholder="Type your comment here..." required data-validation-required-message="Comment" />
<span class="input-group-btn">
<button class="btn btn-warning btn-sm" type="submit">
Comment
</button>
</span>
</div>
</form>
</div>
<!-- /.panel-footer -->
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<ul class="pager">
<li class="next">
<a href="collection.php?collectionID=<?php echo $Photo[5] ?>">Back to Collection</a>
</li>
</ul>
</div>
</div>
</div>
<?php require_once('common_footer.html'); ?>
<!-- jQuery -->
<script src="vendor/jquery/jquery.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<!-- Contact Form JavaScript -->
<script src="js/jqBootstrapValidation.js"></script>
<script src="js/contact_me.js"></script>
<!-- Theme JavaScript -->
<script src="js/clean-blog.min.js"></script>
</body>
</html>