-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_community.php
112 lines (97 loc) · 3.02 KB
/
sample_community.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
<?php
$commid = 1;
// Check if there is a community with that id
$stmt = $db->prepare ( "SELECT * FROM Comms WHERE CommID=?" );
$stmt->execute ( array (
$commid
) );
$numrows = $stmt->rowCount ();
if ($numrows == 0) {
$_SESSION ['AlertRed'] = "No such community can be found.";
// header ( "location:index.php" );
} else {
// Save the privacy setting of the group aside
$row = $stmt->fetch ( PDO::FETCH_ASSOC );
if ($row ['Privacy'] == 'private') {
$private = true;
} else {
$private = false;
}
$commname = $row ['CommName'];
$shortdesc = $row ['ShortDesc'];
// Check whether user is joined to the community.
$stmt = $db->prepare ( "SELECT * FROM UsersInComms WHERE CommID=? AND UserID=?" );
$stmt->execute ( array (
$commid,
$userid
) );
$numrows = $stmt->rowCount ();
if ($numrows == 0) {
$joined = false;
} else {
$joined = true;
}
// Check whether user has a pending request for given community.
$stmt = $db->prepare ( "SELECT * FROM Requests WHERE CommID=? AND UserID=?" );
$stmt->execute ( array (
$commid,
$userid
) );
$numrows = $stmt->rowCount ();
if ($numrows == 0) {
$pending = false;
} else {
$pending = true;
}
// Check whether user is admin of the page or not.
$stmt = $db->prepare ( "SELECT * FROM UsersInComms WHERE CommID=? AND UserID=? AND Role='admin';" );
$stmt->execute ( array (
$commid,
$userid
) );
$numrows = $stmt->rowCount ();
if ($numrows == 0) {
$admin = false;
} else {
$admin = true;
}
// Let's start drawing the page
echo "<div class='container'><h2>" . $commname . "</h2><p>" . $shortdesc . " </p><p><i>";
// Handling the buttons (join-joined-request-pending)
if ($admin) {
echo "<a href='./show_Requests.php?comm_id=" . $commid . "'>Click here to see Requests to join</a>";
} else if ($joined) {
echo "Joined";
} else if (! $private) {
echo "<a href='./join.php?comm_id=" . $commid . "'>Click here to join</a>";
} else if ($pending) {
echo "Request Pending";
} else {
echo "<a href='./join.php?comm_id=" . $commid . "'>Click here to send a join request</a>";
}
echo "</i></p>";
// Handling the Posts
if (! (! $joined && $private)) {
echo "
<table class='table table-striped'>
<thead>
<tr>
<th>Post Title</th>
<th>Author</th>
</tr>
</thead>
<tbody>";
$query = "SELECT P.PostID pid, P.PostTitle ptitle, U.UserName uname, U.UserID uid
FROM Posts P, Users U WHERE P.UserID=U.UserID AND P.CommID=" . $commid . ";";
foreach ( $db->query ( $query ) as $row ) {
echo "<tr>
<td><a href='./show_post.php?post_id=" . $row ['pid'] . "'>" . $row ['ptitle'] . "</a></td>
<td><a href='./show_user.php?user_id=" . $row ['uid'] . "'>" . $row ['uname'] . "</a></td>
</tr>";
}
}
}
?>
</tbody>
</table>
</div>