summaryrefslogtreecommitdiff
path: root/pages/api/fronter.php
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2023-02-25 19:59:31 +0100
committerMinteck <contact@minteck.org>2023-02-25 19:59:31 +0100
commit3d77712a9ab014635c75a33ea0f491bbda6aead3 (patch)
tree616bef5215db4f1d1cea2566079db2a130363e6b /pages/api/fronter.php
parent15bb1453008237edbc2cb4e82a9eb44db6f99794 (diff)
downloadpluralconnect-3d77712a9ab014635c75a33ea0f491bbda6aead3.tar.gz
pluralconnect-3d77712a9ab014635c75a33ea0f491bbda6aead3.tar.bz2
pluralconnect-3d77712a9ab014635c75a33ea0f491bbda6aead3.zip
Updated 16 files and added 2 files (automated)
Diffstat (limited to 'pages/api/fronter.php')
-rw-r--r--pages/api/fronter.php71
1 files changed, 44 insertions, 27 deletions
diff --git a/pages/api/fronter.php b/pages/api/fronter.php
index 51ee4ee..b380a56 100644
--- a/pages/api/fronter.php
+++ b/pages/api/fronter.php
@@ -12,14 +12,17 @@ $index = (int)$_GET['i'] ?? null;
$type = $_GET['t'] ?? null;
$date = $_GET['d'] ?? null;
-if (!isset($system) || trim($system) === "" || strlen($system) !== 5 || !preg_match("/[a-z]/i", $system) || ($system !== "gdapd" && $system !== "ynmuc"))
+if (!isset($system) || trim($system) === "" || strlen($system) !== 5 || !preg_match("/[a-z]/i", $system) || ($system !== "gdapd" && $system !== "ynmuc")) {
peh_error("System not found", 404);
+}
-if (!isset($type) || trim($type) === "")
+if (!isset($type) || trim($type) === "") {
peh_error("Type not found", 404);
+}
-if (!isset($date) || trim($date) === "" || strlen($date) !== 10 || !preg_match("/[\d-]/i", $date))
+if (!isset($date) || trim($date) === "" || strlen($date) !== 10 || !preg_match("/[\d-]/i", $date)) {
peh_error("Date not found", 404);
+}
$list = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/planner/$system.json"), true);
@@ -30,36 +33,42 @@ function moveElement(&$array, $a, $b) {
switch ($type) {
case "add":
- if (!isset($member) || trim($member) === "" || strlen($member) !== 5 || !preg_match("/[a-z]/i", $member))
+ if (!isset($member) || trim($member) === "" || strlen($member) !== 5 || !preg_match("/[a-z]/i", $member)) {
if ($member !== null && $member !== "null") peh_error("System member not found", 404);
+ }
if (!isset($list[$date])) $list[$date] = [];
$list[$date][] = [$member, null];
break;
case "cofront":
- if (!isset($index) || trim($index) === "" || is_integer($index))
- if ($index !== null && $index !== "null") peh_error("Invalid index", 400);
+ if (!isset($index) || trim($index) === "" || !is_integer($index)) {
+ if ($index !== null) peh_error("Invalid index", 400);
+ }
$day = $list[$date];
- if (!isset($day[$index]))
- if ($index !== null && $index !== "null") peh_error("Index not found", 404);
+ if (!isset($day[$index])) {
+ if ($index !== null) peh_error("Index not found", 404);
+ }
- if (!isset($member) || trim($member) === "" || strlen($member) !== 5 || !preg_match("/[a-z]/i", $member))
+ if (!isset($member) || trim($member) === "" || strlen($member) !== 5 || !preg_match("/[a-z]/i", $member)) {
if ($member !== null && $member !== "null") peh_error("System member not found", 404);
+ }
$list[$date][$index][1] = $member;
break;
case "delete":
- if (!isset($index) || trim($index) === "" || is_integer($index))
- if ($index !== null && $index !== "null") peh_error("Invalid index", 400);
+ if (!isset($index) || trim($index) === "" || !is_integer($index)) {
+ if ($index !== null) peh_error("Invalid index", 400);
+ }
$day = $list[$date];
- if (!isset($day[$index]))
- if ($index !== null && $index !== "null") peh_error("Index not found", 404);
+ if (!isset($day[$index])) {
+ if ($index !== null) peh_error("Index not found", 404);
+ }
unset($day[$index]);
$list[$date] = array_values($day);
@@ -67,38 +76,46 @@ switch ($type) {
break;
case "codelete":
- if (!isset($index) || trim($index) === "" || is_integer($index))
- if ($index !== null && $index !== "null") peh_error("Invalid index", 400);
+ if (!isset($index) || trim($index) === "" || !is_integer($index)) {
+ if ($index !== null) peh_error("Invalid index", 400);
+ }
$day = $list[$date];
- if (!isset($day[$index]))
- if ($index !== null && $index !== "null") peh_error("Index not found", 404);
+ if (!isset($day[$index])) {
+ if ($index !== null) peh_error("Index not found", 404);
+ }
$list[$date][$index][1] = null;
break;
case "down":
- if (!isset($index) || trim($index) === "" || is_integer($index))
- if ($index !== null && $index !== "null") peh_error("Invalid index", 400);
-
- if (!isset($day[$index]))
- if ($index !== null && $index !== "null") peh_error("Index not found", 404);
+ if (!isset($index) || trim($index) === "" || !is_integer($index)) {
+ if ($index !== null) peh_error("Invalid index", 400);
+ }
$day = $list[$date];
+
+ if (!isset($day[$index])) {
+ if ($index !== null) peh_error("Index not found", 404);
+ }
+
moveElement($list[$date], $index, $index + 1 < count($list[$date]) ? $index + 1 : $index);
break;
case "up":
- if (!isset($index) || trim($index) === "" || is_integer($index))
- if ($index !== null && $index !== "null") peh_error("Invalid index", 400);
-
- if (!isset($day[$index]))
- if ($index !== null && $index !== "null") peh_error("Index not found", 404);
+ if (!isset($index) || trim($index) === "" || !is_integer($index)) {
+ if ($index !== null) peh_error("Invalid index", 400);
+ }
$day = $list[$date];
+
+ if (!isset($day[$index])) {
+ if ($index !== null) peh_error("Index not found", 404);
+ }
+
moveElement($list[$date], $index, $index - 1 > -1 ? $index - 1 : $index);
break;