-
Notifications
You must be signed in to change notification settings - Fork 0
/
show_user.php
311 lines (261 loc) · 10.1 KB
/
show_user.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
<?php
include 'header.php';
if (! $loggedin) {
$_SESSION ['AlertRed'] = "You have to be logged in to do that.";
header ( "location:index.php" );
}
if (! isset ( $_GET ['user_id'] ))
{
// $_SESSION ['AlertRed'] = "No such post can be found.";
// header("location:index.php");
}
else
{
$userid = $_GET ['user_id'];
}
$stmt = $db->prepare ( "SELECT * FROM Users WHERE UserID=?" );
$stmt->execute ( array (
$userid
) );
$numrows = $stmt->rowCount ();
if ($numrows == 0) {
$_SESSION ['AlertRed'] = "No such user can be found.";
header ( "location:index.php" );
} else {
$row = $stmt->fetch ( PDO::FETCH_ASSOC );
$displayedUserID = $row ['UserID'];
$userEmail = $row ['Email'];
$userName = $row ['UserName'];
$regDate = $row ['RegDate'];
// total num of Posts
$stmt = $db->prepare ( "SELECT * FROM Posts WHERE UserID=?" );
$stmt->execute ( array (
$displayedUserID
) );
$totalnumofPosts = $stmt->rowCount ();
// total num of Comments
$stmt = $db->prepare ( "SELECT * FROM Comments WHERE UserID=?" );
$stmt->execute ( array (
$displayedUserID
) );
$totalnumofComments = $stmt->rowCount ();
// total num of upvotes
$stmt = $db->prepare ( "SELECT * FROM UpvotesForPosts WHERE UserID=?" );
$stmt->execute ( array (
$displayedUserID
) );
$totalnumofupvotes = $stmt->rowCount ();
// total num of likes
$stmt = $db->prepare ( "SELECT * FROM UpvotesForComments WHERE UserID=?" );
$stmt->execute ( array (
$displayedUserID
) );
$totalnumoflikes = $stmt->rowCount ();
?>
<hr>
<div class="container">
<div class="row">
<div class="col-sm-10">
<h1><?php echo "$userName"?></h1>
</div>
<!--<div class="col-sm-2">
<a href="index.php" class="pull-right"><img title="profile image"
class="img-rounded img-responsive" src="im_logo.png"></a>
</div>-->
</div>
<div class="row">
<div class="col-sm-3">
<!--left col-->
<ul class="list-group">
<li class="list-group-item text-muted">Profile</li>
<li class="list-group-item text-right"><span class="pull-left"><strong>Joined</strong></span>
<?php echo "$regDate"?></li>
<!-- <li class="list-group-item text-right"><span class="pull-left"><strong>Last -->
<!-- seen</strong></span> Yesterday (?)</li> -->
<li class="list-group-item text-right"><span class="pull-left"><strong>Contact</strong></span>
<?php echo "$userEmail"?>
</li>
</ul>
<!-- <div class="panel panel-default"> -->
<!-- <div class="panel-heading"> -->
<!-- Contact <i class="fa fa-link fa-1x"></i> -->
<!-- </div> -->
<!-- <div class="panel-body"> -->
<?php // echo "$userEmail"?>
<!-- a href="E-">bootply.com</a> -->
<!-- </div> -->
<!-- </div> -->
<ul class="list-group">
<li class="list-group-item text-muted">Activity <i
class="fa fa-dashboard fa-1x"></i></li>
<!-- <li class="list-group-item text-right"><span class="pull-left"><strong>Shares</strong></span> -->
<!-- 125</li> -->
<li class="list-group-item text-right"><span class="pull-left"><strong>Upvotes</strong></span>
<?php echo $totalnumofupvotes ?></li>
<li class="list-group-item text-right"><span class="pull-left"><strong>Likes</strong></span>
<?php echo $totalnumoflikes ?></li>
<li class="list-group-item text-right"><span class="pull-left"><strong>Comments</strong></span>
<?php echo $totalnumofComments ?></li>
<!-- <li class="list-group-item text-right"><span class="pull-left"><strong>Followers</strong></span> -->
<!-- 78</li> -->
</ul>
<div class="panel panel-default">
<div class="panel-heading">Communities</div>
<div class="panel-body">
<?php
$query = "SELECT C.CommID cid, C.CommName cname
FROM Comms C, UsersInComms U WHERE C.CommID=U.CommID AND U.UserID=" . $userid . ";";
foreach ( $db->query ( $query ) as $row ) {
echo "<p>
<h4>
<a href='./show_community.php?comm_id=" . $row ['cid'] . "'>" . $row ['cname'] . "</a></td>
</h4>
</p>";
}
?>
<!-- <p>
<h3>
<a href='./join.php?comm_id=1'>John</a>
</h3>
</p>
<p>
<h3>
<a href='./join.php?comm_id=1'>John</a>
</h3>
</p>
<p>
<h3>
<a href='./join.php?comm_id=1'>John</a>
</h3>
</p> -->
</div>
</div>
</div>
<!--/col-3-->
<div class="col-sm-9">
<div class="tab-content">
<div class="tab-pane active" id="home">
<div class="table-responsive">
<?php
echo "
<table class='table table-striped'>
<thead>
<tr>
<th>Posts ($totalnumofPosts)</th>
<th>Date</th>
</tr>
</thead>
<tbody>";
$query = "SELECT P.PostID pid, P.PostTitle ptitle, P.CreatedOn pdate
FROM Posts P WHERE P.UserID=" . $userid . ";";
foreach ( $db->query ( $query ) as $row ) {
echo "<tr>
<td><a href='./show_post.php?post_id=" . $row ['pid'] . "'>" . $row ['ptitle'] . "</a></td>
<td>" . $row ['pdate'] . "</td>
</tr>";
}
?>
</tbody>
</table>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4 text-center">
<ul class="pagination" id="myPager"></ul>
</div>
</div>
</div>
<!--/table-resp-->
<hr>
<h4>Recent Activity</h4>
<div class="table-responsive">
<table class="table table-hover">
<tbody>
<?php
$query = "SELECT P.PostID pid, P.PostTitle ptitle, C.CreatedOn cdate
FROM Posts P, Comments C
WHERE C.UserID=" . $userid . " AND P.PostID=C.PostID
ORDER BY C.CreatedOn DESC LIMIT 10;";
foreach ( $db->query ( $query ) as $row ) {
echo "<tr><td><i class='pull-right fa fa-edit'></i>";
echo $row ['cdate'] . " - Commented on the post
<a href='./show_post.php?post_id=" . $row ['pid'] . "#Comments'>" . $row ['ptitle'] . "</a>";
echo "</td></tr>";
}
?>
<?php
$query = "SELECT P.PostID pid, P.PostTitle ptitle, C.CreatedOn cdate, U.UserID uid, U.UserName uname
FROM Posts P, Users U, Comments C
WHERE P.UserID=" . $userid . " AND P.PostID=C.PostID AND U.UserID=C.UserID
ORDER BY C.CreatedOn DESC LIMIT 10;";
foreach ( $db->query ( $query ) as $row ) {
if ($row ['uid'] != $userid) {
echo "<tr><td><i class='pull-right fa fa-edit'></i>";
echo $row ['cdate'] . " - " . $row ['uname'] . " commented on your post
<a href='./show_post.php?post_id=" . $row ['pid'] . "#Comments'>" . $row ['ptitle'] . "</a>";
echo "</td></tr>";
}
}
?>
<?php
$query = "SELECT P.PostID pid, P.PostTitle ptitle, UP.CreatedOn udate
FROM Posts P, UpvotesForPosts UP
WHERE UP.UserID=" . $userid . " AND P.PostID=UP.PostID AND UP.IsDeleted=0
ORDER BY UP.CreatedOn DESC LIMIT 10;";
foreach ( $db->query ( $query ) as $row ) {
echo "<tr><td><i class='pull-right fa fa-edit'></i>";
echo $row ['udate'] . " - Upvoted the post
<a href='./show_post.php?post_id=" . $row ['pid'] . "'>" . $row ['ptitle'] . "</a>";
echo "</td></tr>";
}
?>
<?php
$query = "SELECT P.PostID pid, P.PostTitle ptitle, UP.CreatedOn cdate, U.UserID uid, U.UserName uname
FROM Posts P, Users U, UpvotesForPosts UP
WHERE P.UserID=" . $userid . " AND P.PostID=UP.PostID AND U.UserID=UP.UserID
ORDER BY UP.CreatedOn DESC LIMIT 10;";
foreach ( $db->query ( $query ) as $row ) {
echo "<tr><td><i class='pull-right fa fa-edit'></i>";
echo $row ['cdate'] . " - " . $row ['uname'] . " upvoted your post
<a href='./show_post.php?post_id=" . $row ['pid'] . "'>" . $row ['ptitle'] . "</a>";
echo "</td></tr>";
}
?>
<?php
$query = "SELECT P.PostID pid, P.PostTitle ptitle, UC.CreatedOn udate
FROM Posts P, UpvotesForComments UC, Comments C
WHERE UC.UserID=" . $userid . " AND P.PostID=C.PostID AND UC.CommentID=C.CommentID AND UC.IsDeleted=0
ORDER BY UC.CreatedOn DESC LIMIT 10;";
foreach ( $db->query ( $query ) as $row ) {
echo "<tr><td><i class='pull-right fa fa-edit'></i>";
echo $row ['udate'] . " - Liked the comment in the post
<a href='./show_post.php?post_id=" . $row ['pid'] . "#Comments'>" . $row ['ptitle'] . "</a>";
echo "</td></tr>";
}
?>
<?php
$query = "SELECT P.PostID pid, P.PostTitle ptitle, UC.CreatedOn cdate, U.UserID uid, U.UserName uname
FROM Posts P, Users U, UpvotesForComments UC, Comments C
WHERE C.UserID=" . $userid . " AND UC.CommentID=C.CommentID AND U.UserID=UC.UserID AND P.PostID=C.PostID
ORDER BY UC.CreatedOn DESC";
foreach ( $db->query ( $query ) as $row ) {
echo "<tr><td><i class='pull-right fa fa-edit'></i>";
echo $row ['cdate'] . " - " . $row ['uname'] . " liked your comment in the post
<a href='./show_post.php?post_id=" . $row ['pid'] . "#Comments'>" . $row ['ptitle'] . "</a>";
echo "</td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
<!--/tab-pane-->
</div>
<!--/tab-content-->
</div>
<!--/col-9-->
</div>
<!--/row-->
<?php
}
?>
<?php include 'footer.php';?>