summaryrefslogtreecommitdiff
path: root/pages/rules.inc
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-11-11 23:47:49 +0100
committerMinteck <contact@minteck.org>2022-11-11 23:47:49 +0100
commit209356b8ade1920b50d1d3a1a5e121c6623d167b (patch)
tree5301396987d1510f715a0b1c24754873af19e1dc /pages/rules.inc
parent2c4ae43e688a9873e86211ea0e7aeb9ba770dd77 (diff)
downloadpluralconnect-209356b8ade1920b50d1d3a1a5e121c6623d167b.tar.gz
pluralconnect-209356b8ade1920b50d1d3a1a5e121c6623d167b.tar.bz2
pluralconnect-209356b8ade1920b50d1d3a1a5e121c6623d167b.zip
Update
Diffstat (limited to 'pages/rules.inc')
-rw-r--r--pages/rules.inc243
1 files changed, 70 insertions, 173 deletions
diff --git a/pages/rules.inc b/pages/rules.inc
index 21ae7e6..eee3508 100644
--- a/pages/rules.inc
+++ b/pages/rules.inc
@@ -1,39 +1,6 @@
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn;
-
-if (isset($_POST["updateRules"])) {
- header("Content-Type: text/plain");
-
- if (!isset($_POST['payload'])) {
- header("Location: /-/rules");
- die();
- }
-
- foreach ($_POST['payload'] as $index => $rule) {
- if (!isset($rule["name"]) || !isset($rule["content"]) && !is_numeric($index)) {
- header("Location: /-/rules");
- die();
- }
-
- if (trim($rule["name"]) === "") {
- unset($_POST["payload"][$index]);
- continue;
- }
-
- if (!isset($rule["approved"])) $rule["approved"] = [];
- if (isset($rule["approved"][0])) $rule["approved"][0] = true; else $rule["approved"][0] = false;
- if (isset($rule["approved"][1])) $rule["approved"][1] = true; else $rule["approved"][1] = false;
-
- $_POST["payload"][$index] = $rule;
- }
-
- file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/rules/rules.json", utf8_encode(json_encode($_POST["payload"])));
-
- header("Location: /-/rules");
- die();
-}
-
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.inc';
?>
@@ -41,164 +8,95 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.inc';
<br>
<div class="container">
<div id="page-content">
- <h2>Systems rules</h2>
- <p>Click on a rule to view additional details. <a onclick="event.target.blur();" href="#" data-bs-toggle="modal" data-bs-target="#editor">Edit rules</a></p>
+ <h2>General rules</h2>
+ <p>Click on a rule in the list to view the history of that rule, including all amendments. Note that older versions of a rule cannot be enforced anymore and are provided only for informational purposes.</p>
<?php
- $rules = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/rules/rules.json"), true);
+ $rules = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/rules/newrules.json"), true);
- $protectorCloudburst = array_values(array_filter(scoreOrderGlobal(), function ($i) {
- return $i["_system"] === "ynmuc" && $i["_metadata"]["protector"];
- }))[0];
- $protectorRaindrops = array_values(array_filter(scoreOrderGlobal(), function ($i) {
- return $i["_system"] === "gdapd" && $i["_metadata"]["protector"];
- }))[0];
+ $catindex = 0;
+ foreach ($rules as $category): ?>
- $pcName = getMiniName($protectorCloudburst["display_name"] ?? $protectorCloudburst["name"]);
- $prName = getMiniName($protectorRaindrops["display_name"] ?? $protectorRaindrops["name"]);
-
- ?>
+ <?php if ($catindex === 0): ?>
<ul class="list-group">
- <?php $index = 1; foreach ($rules as $rule): ?>
<li class="list-group-item rule-outer">
<details>
<summary class="rule">
- <b><?= $index ?>. <?= strip_tags($rule["name"]) ?></b>
- <?php if (in_array(false, $rule["approved"])): ?>
- <span class="badge bg-warning text-black rounded-pill">Unapproved</span>
+ <b><?= $category['title'] ?><?php if (count($category['rules'][0]['amendments']) > 0): ?>-<?= $category['rules'][0]['amendments'][count($category['rules'][0]['amendments']) - 1]['id'] ?>:</b> <?= $category['rules'][0]['amendments'][count($category['rules'][0]['amendments']) - 1]['text'] ?><?php else: ?>:</b> <?= $category['rules'][0]['text'] ?><?php endif; ?>
+ </summary>
+
+ <ul class="list-group" style="margin-top:10px;">
+ <?php if (count($category['rules'][0]['amendments']) > 0): ?>
+ <?php $aindex = 0; foreach (array_reverse($category['rules'][0]['amendments']) as $amendment): ?>
+
+ <?php if ($aindex === 0): ?>
+ <li class="list-group-item"><b>Curent version:</b> <?= $amendment['text'] ?></li>
+ <?php else: ?>
+ <li class="list-group-item"><b>Amendment Preamble-<?= $amendment['id'] ?>:</b> <?= $amendment['text'] ?></li>
+ <?php endif; ?>
+
+ <?php $aindex++; endforeach; ?>
+ <li class="list-group-item"><b>Original rule:</b> <?= $category['rules'][0]['text'] ?></li>
+ <?php else: ?>
+ <li class="list-group-item">
+ <i>This rule was never amended.</i>
+ </li>
<?php endif; ?>
+ </ul>
+ </details>
+ </li>
+ </ul>
+
+ <?php else:
+
+ if ($category["title"] === "@punishments") {
+ $catindex = "P";
+ $category["title"] = "Planned punishments";
+ }
+
+ ?>
+
+ <h4 style="margin-top: 15px;">Articles <?= $catindex ?>.1 to <?= $catindex ?>.<?= count($category['rules']) ?>: <?= $category["title"] ?></h4>
+
+ <ul class="list-group">
+ <?php $ruleindex = 1; foreach ($category['rules'] as $rule): ?>
+ <li class="list-group-item rule-outer">
+ <details>
+ <summary class="rule">
+ <b>Article <?= $catindex ?>.<?= $ruleindex ?><?php if (count($rule['amendments']) > 0): ?>-<?= $rule['amendments'][count($rule['amendments']) - 1]['id'] ?>:</b> <?= $rule['amendments'][count($rule['amendments']) - 1]['text'] ?><?php else: ?>:</b> <?= $rule['text'] ?><?php endif; ?>
</summary>
- <?php if (in_array(false, $rule["approved"])): ?>
- <div style="margin-top:10px;" class="alert alert-warning">
- <b>This rule has not yet been approved.</b> All rules need to be approved by the leaders from both systems. This rule is still missing approval from <?php
-
- if ($rule["approved"][0] === false) {
- if ($rule["approved"][1] === false) {
- echo($pcName . " and " . $prName);
- } else {
- echo($pcName);
- }
- } else if ($rule["approved"][1] === false) {
- echo($prName);
- }
-
- ?>.
- </div>
- <?php endif; ?>
- <div <?= !in_array(false, $rule["approved"]) ? 'style="margin-top:10px;"' : '' ?> class="list-group-item">
- <?= strip_tags($rule["content"]) ?>
- </div>
+
+ <ul class="list-group" style="margin-top:10px;">
+ <?php if (count($rule['amendments']) > 0): ?>
+ <?php $aindex = 0; foreach (array_reverse($rule['amendments']) as $amendment): ?>
+
+ <?php if ($aindex === 0): ?>
+ <li class="list-group-item"><b>Curent version:</b> <?= $amendment['text'] ?></li>
+ <?php else: ?>
+ <li class="list-group-item"><b>Amendment Preamble-<?= $amendment['id'] ?>:</b> <?= $amendment['text'] ?></li>
+ <?php endif; ?>
+
+ <?php $aindex++; endforeach; ?>
+ <li class="list-group-item"><b>Original rule:</b> <?= $rule['text'] ?></li>
+ <?php else: ?>
+ <li class="list-group-item">
+ <i>This rule was never amended.</i>
+ </li>
+ <?php endif; ?>
+ </ul>
</details>
</li>
- <?php $index++; endforeach; ?>
+ <?php $ruleindex++; endforeach; ?>
</ul>
- </div>
-</div>
-<div class="modal fade" id="editor">
- <div class="modal-dialog">
- <div class="modal-content">
- <div class="modal-header">
- <h4 class="modal-title">Rules editor</h4>
- <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
- </div>
-
- <div class="modal-body">
- <p>Rules with an empty name are automatically deleted. Buttons to add new rules and save the changes are at the bottom of the list.</p>
- <hr>
- <form method="post">
- <div id="rules-editor">
- <?php $index = 1; foreach ($rules as $rule): ?>
- <div <?= $index === 1 ? 'id="default-rule"' : '' ?>>
- <p><b <?= $index === 1 ? 'id="default-rule--number"' : '' ?>>Rule #<?= $index ?>:</b></p>
- <input <?= $index === 1 ? 'id="default-rule--name"' : '' ?> type="text" placeholder="Rule name" class="form-control" style="margin-bottom:15px;color:white;background:#111;border-color:#222;" name="payload[<?= $index - 1 ?>][name]" value="<?= str_replace('"', "&quot;", strip_tags($rule["name"])) ?>">
-
- <textarea <?= $index === 1 ? 'id="default-rule--content"' : '' ?> name="payload[<?= $index - 1 ?>][content]" class="form-control" style="resize: none;color:white;background:#111;border-color:#222;" placeholder="Rule details"><?= strip_tags($rule["content"] ?? "") ?></textarea>
-
- <label style="margin-top:10px;margin-left:5px;">
- <input <?= $index === 1 ? 'id="default-rule--approval-1"' : '' ?> <?= ($rule["approved"][0] ?? false) ? "checked" : "" ?> type="checkbox" name="payload[<?= $index - 1 ?>][approved][0]">
- Approved by <?= $pcName ?>
- </label><br>
- <label style="margin-left:5px;">
- <input <?= $index === 1 ? 'id="default-rule--approval-2"' : '' ?> <?= ($rule["approved"][1] ?? false) ? "checked" : "" ?> type="checkbox" name="payload[<?= $index - 1 ?>][approved][1]">
- Approved by <?= $prName ?>
- </label><br>
-
- <hr>
- </div>
- <?php $index++; endforeach; ?>
- </div>
- <input type="submit" value="Save" class="btn btn-primary">
- <a onclick="editorNewRule();" class="btn btn-secondary">New rule</a>
- <input type="hidden" name="updateRules">
- </form>
- </div>
- </div>
+ <?php endif; ?>
+
+ <?php $catindex++; endforeach; ?>
</div>
</div>
-<script>
- window.numberOfRules = <?= count($rules) ?>;
-
- Array.from(document.getElementsByClassName("rule-outer")).forEach((el) => {
- let details = el.children[0];
-
- el.onclick = () => {
- Array.from(document.getElementsByClassName("rule-outer")).forEach((sel) => {
- if (el === sel) return;
- sel.children[0].open = false;
- sel.classList.remove("open");
- });
-
- details.open = !details.open;
-
- if (details.open) {
- el.classList.add("open");
- } else {
- el.classList.remove("open");
- }
- }
- })
-
- function editorNewRule() {
- let id = Math.random(36).toString().split(".")[1];
-
- document.getElementById("default-rule").id = "added-" + id + "-1";
- document.getElementById("default-rule--number").id = "added-" + id + "-2";
- document.getElementById("default-rule--name").id = "added-" + id + "-3";
- document.getElementById("default-rule--content").id = "added-" + id + "-4";
- document.getElementById("default-rule--approval-1").id = "added-" + id + "-5";
- document.getElementById("default-rule--approval-2").id = "added-" + id + "-6";
-
- let child = document.createElement("div");
- child.id = "temp-" + id;
- window.numberOfRules++;
-
- document.getElementById("rules-editor").appendChild(child);
- document.getElementById("temp-" + id).outerHTML = document.getElementById("added-" + id + "-1").outerHTML;
-
- document.getElementById("added-" + id + "-1").id = "default-rule";
- document.getElementById("added-" + id + "-2").id = "default-rule--number";
- document.getElementById("added-" + id + "-3").id = "default-rule--name";
- document.getElementById("added-" + id + "-4").id = "default-rule--content";
- document.getElementById("added-" + id + "-5").id = "default-rule--approval-1";
- document.getElementById("added-" + id + "-6").id = "default-rule--approval-2";
-
- document.getElementById("added-" + id + "-3").name = "payload[" + (numberOfRules - 1) + "][name]";
- document.getElementById("added-" + id + "-4").name = "payload[" + (numberOfRules - 1) + "][content]";
- document.getElementById("added-" + id + "-5").name = "payload[" + (numberOfRules - 1) + "][approved][0]";
- document.getElementById("added-" + id + "-6").name = "payload[" + (numberOfRules - 1) + "][approved][1]";
-
- document.getElementById("added-" + id + "-5").checked = false;
- document.getElementById("added-" + id + "-6").checked = false;
- document.getElementById("added-" + id + "-3").value = "";
- document.getElementById("added-" + id + "-4").value = "";
- document.getElementById("added-" + id + "-2").innerText = "Rule #" + numberOfRules + ":";
- }
-</script>
-
<style>
.list-group-item {
color: #fff;
@@ -229,7 +127,6 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.inc';
.rule {
list-style: none;
- pointer-events: none;
}
.rule-outer {