Skip to content

Commit cdfc219

Browse files
committed
use messages instead of modal errors
1 parent c5e135f commit cdfc219

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

webroot/panel/groups.php

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
use UnityWebPortal\lib\UnityHTTPD;
88

99
if ($_SERVER["REQUEST_METHOD"] == "POST") {
10-
$modalErrors = array();
11-
1210
if (isset($_POST["form_type"])) {
1311
if (isset($_POST["pi"])) {
1412
$pi_groupname = $_POST["pi"];
@@ -20,7 +18,8 @@
2018
}
2119
$pi_account = new UnityGroup($pi_groupname, $LDAP, $SQL, $MAILER, $WEBHOOK);
2220
if (!$pi_account->exists()) {
23-
array_push($modalErrors, "This PI doesn't exist");
21+
UnityHTTPD::messageBad("Invalid Group Membership Request", "This PI doesn't exist");
22+
UnityHTTPD::redirect();
2423
}
2524
}
2625

@@ -31,30 +30,36 @@
3130
}
3231
if ($pi_account->exists()) {
3332
if ($pi_account->requestExists($USER)) {
34-
array_push($modalErrors, "You've already requested this");
33+
UnityHTTPD::messageBad(
34+
"Invalid Group Membership Request",
35+
"You've already requested this"
36+
);
37+
UnityHTTPD::redirect();
3538
}
3639
if ($pi_account->memberExists($USER)) {
37-
array_push($modalErrors, "You're already in this PI group");
40+
UnityHTTPD::messageBad(
41+
"Invalid Group Membership Request",
42+
"You're already in this PI group"
43+
);
44+
UnityHTTPD::redirect();
3845
}
3946
}
40-
if (empty($modalErrors)) {
41-
$pi_account->newUserRequest($USER);
42-
}
47+
$pi_account->newUserRequest($USER);
48+
UnityHTTPD::messageGood("Group Membership Request Submitted", "");
49+
UnityHTTPD::redirect();
4350
break;
4451
case "removePIForm":
4552
$pi_account->removeUser($USER);
53+
UnityHTTPD::messageGood("Group Membership Removed", "");
54+
UnityHTTPD::redirect();
4655
break;
4756
case "cancelPIForm":
4857
$pi_account->cancelGroupJoinRequest($USER);
58+
UnityHTTPD::messageGood("Group Membership Request Cancelled", "");
59+
UnityHTTPD::redirect();
4960
break;
5061
}
5162
}
52-
$_SESSION['MODAL_ERRORS'] = $modalErrors;
53-
} else {
54-
if (isset($_SESSION['MODAL_ERRORS'])) {
55-
$modalErrors = $_SESSION['MODAL_ERRORS'];
56-
$_SESSION['MODAL_ERRORS'] = array(); // Forget after shown
57-
}
5863
}
5964

6065

@@ -178,18 +183,6 @@
178183
openModal("Add New PI", "<?php echo CONFIG["site"]["prefix"]; ?>/panel/modal/new_pi.php");
179184
});
180185

181-
<?php
182-
// This is here to re-open the modal if there are errors
183-
if (isset($modalErrors) && is_array($modalErrors) && count($modalErrors) > 0) {
184-
$errorHTML = "";
185-
foreach ($modalErrors as $error) {
186-
$errorHTML .= "<span>" . htmlentities($error) . "</span>";
187-
}
188-
189-
echo "openModal('Add New PI', '" . CONFIG["site"]["prefix"] . "/panel/modal/new_pi.php');";
190-
}
191-
?>
192-
193186
// tables.js uses ajax_url to populate expandable tables
194187
var ajax_url = "<?php echo CONFIG["site"]["prefix"]; ?>/panel/ajax/get_group_members.php?gid=";
195188
</script>

0 commit comments

Comments
 (0)