-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewGroup.php
290 lines (272 loc) · 9.18 KB
/
viewGroup.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
<?php require "header.php";?>
<?php
if (!empty($_GET["gid"]))
$gid = $_GET["gid"];
else
$gid = 0;
?>
<div class="callout">
<?php
if ($gid != 0) {
$db = new Database();
$stmt = $db->prepare("SELECT * FROM groups
INNER JOIN groupUserRel USING(groupID)
INNER JOIN users USING(userID)
WHERE groups.groupID = :gid AND owner = 1");
$stmt->bindValue(":gid", $gid, SQLITE3_INTEGER);
$result = $stmt->execute();
$groupData = $result->fetchArray();
if ($groupData) {
$groupOwner = $groupData["userID"] == $_SESSION["uid"];
echo '<ul class="accordion" data-accordion data-multi-expand="true" data-allow-all-closed="true">
<li class="accordion-item is-active" data-accordion-item>
<a href="#" class="accordion-title">'.$groupData["name"].'</a>
<div class="accordion-content" data-tab-content>
<a id="qrURL"><div id="qr-code"></div></a>
<script>
$("#qrURL").attr("href", window.location.href);
new QRCode(document.getElementById("qr-code"), window.location.href);
</script>
Name: '.$groupData["name"].'<br />
Owner: <a href="profile.php?uid='.$groupData["userID"].'">'.$groupData["realname"].'</a><br />
Created: '.$groupData["createTS"].'<br/>
<a href="https://twitter.com/share" class="twitter-share-button" data-size="large" data-text="Join my bill group " data-hashtags="coopBillInitiative" data-show-count="false">Tweet</a><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
<script>$(".twitter-share-button").html("Join my bill group " + window.location.href);</script>
</div>
</li>';
echo '
<li class="accordion-item is-active" data-accordion-item>
<a href="#" class="accordion-title">Control Panel</a>
<div class="accordion-content" data-tab-content>
<input type="hidden" id="gid" value="'.$gid.'">
<input type="hidden" id="uid" value="'.$_SESSION["uid"].'">
<input type="hidden" id="oid" value="'.$groupData["userID"].'">';
if ($groupOwner) {
echo '
<input id="addUserName" type="text" name="username" pattern="[a-zA-Z0-9]+" maxlength="30" required />
<button id="addUser" class="button">Add User</button>
<span id="addUserMsg" style="display:none"></span><br />
Group Join Requests
<table>
<thead>
<tr>
<td>Name</td>
<td>Accept Request?</td>
</tr>
</thead>
<tbody>';
$stmt = $db->prepare("SELECT * FROM notifications
INNER JOIN notiUser USING(notiID)
INNER JOIN notiGroup USING(notiID)
INNER JOIN users ON users.userID = notiUser.secondUserID
WHERE groupID = :gid AND notifications.userID = :oid
AND typeID = 17 AND checked != 1");
$stmt->bindValue(":gid", $gid, SQLITE3_INTEGER);
$stmt->bindValue(":oid", $groupData["userID"], SQLITE3_INTEGER);
$result = $stmt->execute();
while ($temp = $result->fetchArray()) {
echo '
<tr>
<input type="hidden" class="notiID" value="'.$temp["notiID"].'">
<input type="hidden" class="userID" value="'.$temp["secondUserID"].'">
<td class="name">
<a href="profile.php?uid='.$temp["secondUserID"].'">'.$temp["realname"].'</a>
</td>
<td class="actionsOnContact">
<button class="button success notiReply" value="1">Yes</button>
<button class="button alert notiReply" value="0">No</button>
</td>
</tr>';
}
echo '
</tbody>
</table>
<br />
<button id="deleteGroup" class="button alert">Delete Group</button>';
} else {
$stmt = $db->prepare("SELECT userID from groupUserRel
WHERE userID = :uid AND groupID = :gid");
$stmt->bindValue(":uid", $_SESSION["uid"], SQLITE3_INTEGER);
$stmt->bindValue(":gid", $gid, SQLITE3_INTEGER);
$tempRes = $stmt->execute();
$temp = $tempRes->fetchArray();
if (!$temp)
echo '
<button id="requestJoin" class="button">Request Invitation</button>
<span id="requestJoinMsg" style="display:none"></span>';
else
echo '
<button id="leaveGroup" class="button alert">Leave Group</button>
<span id="leaveGroupMsg" style="display:none"></span>';
}
echo '
</div>
</li>
<li class="accordion-item is-active" data-accordion-item>
<a href="#" class="accordion-title">Users</a>
<div class="accordion-content" data-tab-content>';
$stmt = $db->prepare("SELECT * FROM users
INNER JOIN groupUserRel ON groupUserRel.userID = users.userID
WHERE groupUserRel.groupID = :gid");
$stmt->bindValue(":gid", $gid, SQLITE3_INTEGER);
$result = $stmt->execute();
$count = 0;
if ($groupOwner) echo '
<table id="users">
<thead>
<tr>
<td>Name</td>
<td>Remove?</td>
<td>Make Owner?</td>
</tr>
</thead>
<tbody>';
while ($user = $result->fetchArray()) {
$count++;
if ($groupOwner) {
echo '
<tr id="'.$user["userID"].'">
<td class="name">
<a href="profile.php?uid='.$user["userID"].'">'.$user["realname"].'</a>
</td>
<td class="remove">';
if($user["userID"] != $groupData["userID"]) echo'
<button class="button alert removeUser" name="remove">X</button>';
echo '
</td>
<td class="transfer">';
if($user["userID"] != $groupData["userID"]) echo'
<button class="button warning transferUser" name="transfer">O</button>';
echo '
</td>
</tr>';
} else echo (($user["userID"] == $groupData["userID"]) ? '* ': '').' <a href="profile.php?uid='.$user["userID"].'">'
.$user["realname"].'</a><br />
';
}
if ($count == 0) echo '<div class="callout warning">'.$groupData["name"]
.' has no members!!!!(</div>';
if ($groupOwner)
echo '
</tbody>
</table>';
echo'
</div>
</li>
</ul>';
} else {
echo '<div class="callout warning">Group not found.</div>';
die();
}
} else {
echo '<div class="classout warning">No group provided.</div>';
die();
}
?>
</div>
<script>
$(function() {
var gid = $("#gid").attr("value");
var uid = $("#uid").attr("value");
var oid = $("#oid").attr("value");
$("#addUser").click(function() {
$("#addUser").prop("disabled", true);
var user = $("#addUserName").val();
if(user) {
var msg = $("#addUserMsg");
$.post("addUserToGroup.php", {name: user, gid: gid, oid: oid}, function(d) {
console.log(d);
switch (parseInt(d)) {
case 0: msg.html("User not found.");
break;
case 1: msg.html("User already invited.");
break;
case 2: msg.html("User requested to join already, request accepted.");
break;
case 3: msg.html("Invite sent.");
break;
case 4: msg.html("User already part of group.");
break;
default: msg.html("Something Happened!");
}
msg.show("slow");
setTimeout(function(){msg.hide("slow")},2000);
setTimeout(function(){$("#addUser").prop("disabled", false);},2600);
});
}
});
$("#deleteGroup").click(function() {
$("#deleteGroup").prop("disabled", true);
$.post("deleteGroup.php", {gid: gid}, function(d) {
console.log(d);
window.location.replace("groups.php");
});
});
$("#requestJoin").click(function() {
var msg = $("#requestJoinMsg");
$("#requestJoin").prop("disabled", true);
$.post("requestJoinGroup.php", {gid: gid, uid: uid, oid: oid}, function(d) {
console.log(d);
switch (parseInt(d)) {
case 0:
msg.html("Already part of group!");
break;
case 1:
msg.html("Request already sent.");
break;
case 2:
msg.html("Request sent!");
break;
default:
msg.html("Something Happened!");
}
msg.show("slow");
setTimeout(function(){msg.hide("slow")}, 2000);
setTimeout(function(){$("#requestJoin").prop("disabled", false)}, 2600);
});
});
$("#leaveGroup").click(function() {
$("#leaveGroup").prop("disabled", true);
$.post("leaveGroup.php", {gid: gid, uid: uid, oid: oid}, function(d) {
console.log(d);
window.location.replace("viewGroup.php?gid="+gid);
});
});
$(".removeUser").click(function() {
var row = $(this).parent().parent();
row.find("button").prop("disabled", true);
var targID = row.attr("id");
$.post("removeUserFromGroup.php", {gid: gid, uid: targID}, function(d) {
console.log(d);
});
row.hide(1000);
setTimeout(function() {row.remove();}, 1000);
});
$(".transferUser").click(function() {
var row = $(this).parent().parent();
row.find("button").prop("disabled", true);
var targID = row.attr("id");
var name = row.find("td.name a").html();
$.post("promoteUser.php", {gid: gid, uid: targID, oid: oid, name: name}, function(d) {
console.log(d);
window.location.reload();
});
});
$(".notiReply").click(function() {
nReply = $(this).attr("value");
notiRow = $(this).parent().parent();
notiRow.find(".notiReply").prop("disabled", true);
notiID = notiRow.find("input.notiID").attr("value");
suid = notiRow.find("input.userID").attr("value");
nType = 17;
$.post("handleNotification.php",
{nid: notiID, nType: nType, nReply: nReply, bid: 0, gid: gid, suid: suid},
function(d) {
console.log(d);
});
notiRow.hide(1000);
setTimeout(function(){notiRow.remove()}, 1000);
});
});
</script>
<?php require "footer.php";?>