summaryrefslogtreecommitdiff
path: root/pages/rules.inc
diff options
context:
space:
mode:
Diffstat (limited to 'pages/rules.inc')
-rw-r--r--pages/rules.inc251
1 files changed, 175 insertions, 76 deletions
diff --git a/pages/rules.inc b/pages/rules.inc
index cf88eb1..2268e75 100644
--- a/pages/rules.inc
+++ b/pages/rules.inc
@@ -1,6 +1,40 @@
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages;
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/Parsedown.php"; $Parsedown = new Parsedown();
+
+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';
?>
@@ -8,95 +42,159 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.inc';
<br>
<div class="container">
<div id="page-content">
- <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>
+ <h2>Rules</h2>
+ <p><a onclick="event.target.blur();" href="#" data-bs-toggle="modal" data-bs-target="#editor">Edit rules</a></p>
<?php
- $rules = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/rules/newrules.json"), true);
-
- $catindex = 0;
- foreach ($rules as $category): ?>
-
- <?php if ($catindex === 0): ?>
+ $rules = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/rules/rules.json"), true);
- <ul class="list-group">
- <li class="list-group-item rule-outer">
- <details>
- <summary class="rule">
- <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>
+ $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];
- <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): ?>
+ $pcName = getMiniName($protectorCloudburst["display_name"] ?? $protectorCloudburst["name"]);
+ $prName = getMiniName($protectorRaindrops["display_name"] ?? $protectorRaindrops["name"]);
- <?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>
-
- <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 $index = 1; foreach ($rules as $rule): ?>
+ <h4 style="margin-top: 20px;">
+ <b>Rule <?= $index ?>: <?= strip_tags($rule["name"]) ?></b>
+ <?php if (in_array(false, $rule["approved"])): ?>
+ <span class="badge bg-warning text-black rounded-pill">Unapproved</span>
<?php endif; ?>
- </ul>
- </details>
+ </h4>
+ <?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>
+ <p><?= $Parsedown->text(strip_tags($rule["content"])) ?></p>
+ </div>
</li>
- <?php $ruleindex++; endforeach; ?>
- </ul>
-
- <?php endif; ?>
+ <?php $index++; endforeach; ?>
+ </div>
+</div>
- <?php $catindex++; endforeach; ?>
+<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]" rows="5" 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>
</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;
@@ -127,6 +225,7 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.inc';
.rule {
list-style: none;
+ pointer-events: none;
}
.rule-outer {