-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgroups.php
174 lines (143 loc) · 5.19 KB
/
groups.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
<?php
require_once "../../resources/autoload.php";
use UnityWebPortal\lib\UnityGroup;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$modalErrors = array();
$errors = array();
if (isset($_POST["form_name"])) {
if (isset($_POST["pi"])) {
$pi_account = new UnityGroup(trim($_POST["pi"]), $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
if (!$pi_account->exists()) {
// "\'" instead of "'", otherwise it will close a single quote used to place the message
array_push($modalErrors, "This PI doesn\'t exist");
}
}
switch ($_POST["form_name"]) {
case "addPIform":
// The new PI modal was submitted
// existing PI request
if ($pi_account->requestExists($USER)) {
array_push($modalErrors, "You\'ve already requested this");
}
if ($pi_account->userExists($USER)) {
array_push($modalErrors, "You\'re already in this PI group");
}
// Add row to sql
if (empty($modalErrors)) {
$pi_account->newUserRequest($USER);
}
break;
case "removePIForm":
// Remove PI form
$pi_account->removeUser($USER);
break;
}
}
}
include $LOC_HEADER;
?>
<h1>My Principal Investigators</h1>
<hr>
<?php
$groups = $USER->getGroups();
$requests = $SQL->getRequestsByUser($USER->getUID());
$req_filtered = array();
foreach ($requests as $request) {
// FIXME "admin" -> UnitySQL::REQUEST_BECOME_PI
if ($request["request_for"] != "admin") { // put this in config later for gypsum
array_push($req_filtered, $request);
}
}
if (count($req_filtered) > 0) {
echo "<h5>Pending Requests</h5>";
echo "<table>";
foreach ($req_filtered as $request) {
$requested_account = new UnityGroup($request["request_for"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
$requested_owner = $requested_account->getOwner();
echo "<tr class='pending_request'>";
echo "<td>" . $requested_owner->getFirstname() . " " . $requested_owner->getLastname() . "</td>";
echo "<td>" . $requested_account->getPIUID() . "</td>";
echo "<td><a href='mailto:" . $requested_owner->getMail() . "'>" . $requested_owner->getMail() . "</a></td>";
echo "<td>" . date("jS F, Y", strtotime($request['timestamp'])) . "</td>";
echo "<td></td>";
echo "</tr>";
}
echo "</table>";
if (count($groups) > 0) {
echo "<hr>";
}
}
echo "<h5>Current Groups</h5>";
if ($USER->isPI() && count($groups) == 1) {
echo "You are only a member of your own PI group.
Navigate to the <a href='" . $CONFIG["site"]["prefix"] . "/panel/pi.php'>my users</a> page to see your group.";
}
if (count($groups) == 0) {
echo "You are not a member of any groups. Request to join a PI using the button below,
or request your own PI account on the <a href='" . $CONFIG["site"]["prefix"] .
"/panel/account.php'>account settings</a> page";
}
echo "<table>";
foreach ($groups as $group) {
$owner = $group->getOwner();
if ($USER->getUID() == $owner->getUID()) {
continue;
}
echo "<tr class='expandable'>";
echo
"<td>
<button class='btnExpand'>▶</button>" . $owner->getFirstname() . " " . $owner->getLastname() . "</td>";
echo "<td>" . $group->getPIUID() . "</td>";
echo "<td><a href='mailto:" . $owner->getMail() . "'>" . $owner->getMail() . "</a></td>";
echo
"<td>
<form action='' method='POST'
onsubmit='return confirm(\"Are you sure you want to leave the PI group " . $group->getPIUID() . "?\")'>
<input type='hidden' name='form_name' value='removePIForm'>
<input type='hidden' name='pi' value='" . $group->getPIUID() . "'>
<input type='submit' value='Leave Group'>
</form>
</td>";
echo "</tr>";
}
echo "</table>";
?>
<?php
if ($SQL->accDeletionRequestExists($USER->getUID())) {
echo "<button type='button' class='plusBtn btnAddPI' disabled>+</button>";
echo "<label>You cannot join a PI while you have requested account deletion.</label>";
} else {
echo "<button type='button' class='plusBtn btnAddPI'>+</button>";
}
?>
<style>
div.modalContent {
max-width: 300px;
}
</style>
<script>
$("button.btnAddPI").click(function() {
openModal("Add New PI", "<?php echo $CONFIG["site"]["prefix"]; ?>/panel/modal/new_pi.php");
});
<?php
// This is here to re-open the modal if there are errors
if (isset($modalErrors) && is_array($modalErrors) && count($modalErrors) > 0) {
$errorHTML = "";
foreach ($modalErrors as $error) {
$errorHTML .= "<span>$error</span>";
}
echo "openModal('Add New PI', '" .
$CONFIG["site"]["prefix"] . "/panel/modal/new_pi.php', '" . $errorHTML . "');";
}
?>
var ajax_url = "<?php echo $CONFIG["site"]["prefix"]; ?>/panel/ajax/get_group_members.php?pi_uid=";
</script>
<style>
@media only screen and (max-width: 1000px) {
table td:nth-child(2) {
display: none;
}
}
</style>
<?php
include $LOC_FOOTER;