|
@@ -20,6 +20,51 @@ function hspech($str)
|
|
|
return (htmlspecialchars($str, ENT_QUOTES | ENT_HTML5, 'UTF-8'));
|
|
|
}
|
|
|
|
|
|
+function are_valid_ids($ids)
|
|
|
+{
|
|
|
+ if (count($ids) <= 0) return false;
|
|
|
+ foreach ($ids as $id) {
|
|
|
+ if (!(preg_match('/^[0-9]+$/', $id) === 1)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER["CONTENT_TYPE"] === "application/json") {
|
|
|
+ $response = array(
|
|
|
+ "done" => true,
|
|
|
+ "error" => ""
|
|
|
+ );
|
|
|
+ $body = json_decode(file_get_contents('php://input'), true);
|
|
|
+ if (array_key_exists('act', $body) &&
|
|
|
+ array_key_exists('ids', $body) &&
|
|
|
+ are_valid_ids($body["ids"])) {
|
|
|
+ switch ($body['act']) {
|
|
|
+ case "massread":
|
|
|
+ mysqli_query($link, 'UPDATE Notifications SET Seen=1 WHERE ID in (' . implode(", ", $body["ids"]) . ')')
|
|
|
+ or muoribene(mysqli_error($link), true);
|
|
|
+ break;
|
|
|
+ case "massdelete":
|
|
|
+ mysqli_query($link, 'UPDATE Notifications SET Deleted=1 WHERE ID in (' . implode(", ", $body["ids"]) . ')')
|
|
|
+ or muoribene(mysqli_error($link), true);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ http_response_code(400);
|
|
|
+ $response["done"] = false;
|
|
|
+ $response["error"] = "Unknown act.";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ http_response_code(400);
|
|
|
+ $response["done"] = false;
|
|
|
+ $response["error"] = "Bad request.";
|
|
|
+ }
|
|
|
+ echo(json_encode($response));
|
|
|
+ mysqli_close($link);
|
|
|
+ exit(0);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
$dbg .= $dlang . '<br>' . N;
|
|
|
$dbg .= '<pre>' . print_r($_GET, 1) . '</pre>';
|
|
|
|
|
@@ -61,8 +106,26 @@ if ($filtordon) {
|
|
|
<!--
|
|
|
<?php if ($account['Level'] != 'guest') require('js/notifs.js.php'); ?>
|
|
|
|
|
|
+ function reverseSelection() {
|
|
|
+ let checkboxes = getAliveCheckboxes()
|
|
|
+ checkboxes.forEach(function (box) {
|
|
|
+ box.checked = !box.checked;
|
|
|
+ })
|
|
|
+ let n_selected = getSelectedNotifs().length;
|
|
|
+ if (n_selected > 0) {
|
|
|
+ setBtnsVisibility("visible");
|
|
|
+ } else if (n_selected === 0) {
|
|
|
+ setBtnsVisibility("hidden");
|
|
|
+ document.getElementById("global-selector").checked = false;
|
|
|
+ }
|
|
|
+ if (n_selected === checkboxes.length) {
|
|
|
+ document.getElementById("global-selector").checked = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function setBtnsVisibility(state) {
|
|
|
- let btns = document.querySelectorAll("#notifs-list-controls .control-btn");
|
|
|
+ let controls = document.querySelector("#notifs-list-controls");
|
|
|
+ let btns = Array(controls.querySelector("#read-btn"), controls.querySelector("#delete-btn"));
|
|
|
btns.forEach(function (btn) {
|
|
|
btn.style.visibility = state;
|
|
|
});
|
|
@@ -74,14 +137,14 @@ if ($filtordon) {
|
|
|
} else {
|
|
|
setBtnsVisibility("hidden")
|
|
|
}
|
|
|
- let checkboxes = document.querySelectorAll("div.notif > input.seen-checkbox");
|
|
|
+ let checkboxes = getAliveCheckboxes()
|
|
|
checkboxes.forEach(function (box) {
|
|
|
box.checked = check.checked;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function notifSelect(check) {
|
|
|
- let checkboxes = Array.from(document.querySelectorAll("div.notif > input.seen-checkbox"));
|
|
|
+ let checkboxes = getAliveCheckboxes()
|
|
|
if (check.checked) {
|
|
|
setBtnsVisibility("visible");
|
|
|
} else if (checkboxes.every(box => !box.checked)) {
|
|
@@ -113,22 +176,9 @@ if ($filtordon) {
|
|
|
<?php echo($notifs['div']); ?>
|
|
|
|
|
|
<div id="notifs-grid">
|
|
|
- <div id="notifs-list-controls">
|
|
|
- <input id="global-selector" type="checkbox" onclick="toggleState(this)">
|
|
|
- <button class="control-btn" onclick="applyAllSelected(markread)"><i class="fa fa-envelope-open-o"
|
|
|
- aria-hidden="true"></i>
|
|
|
- </button>
|
|
|
- <button class="control-btn" onclick="applyAllSelected(markdeleted)"><i class="fa fa-trash-o"
|
|
|
- aria-hidden="true"></i>
|
|
|
- </button>
|
|
|
- </div>
|
|
|
- <h1 class="control-btn">CIAONEE</h1>
|
|
|
<div id="notifs-list">
|
|
|
<?php
|
|
|
if ($account['Level'] != 'guest') {
|
|
|
- // Questi valori sono un po' a (n|c)aso,
|
|
|
- // dovrebbero avere senso ma non ho
|
|
|
- // indagato troppo
|
|
|
$sev_classes = array(
|
|
|
1 => "sev-normal",
|
|
|
2 => "sev-warning",
|
|
@@ -138,18 +188,35 @@ if ($filtordon) {
|
|
|
0 => "unseen",
|
|
|
1 => "seen"
|
|
|
);
|
|
|
+ $deleted = array(
|
|
|
+ 0 => "",
|
|
|
+ 1 => "deleted"
|
|
|
+ );
|
|
|
foreach ($notifs['notifs'] as $n) {
|
|
|
- echo("<div id=\"notif-" . $n["ID"] .
|
|
|
- "\" class=\"" . "notif " . $sev_classes[$n["Severity"]] . " " . $seen_class[$n["Seen"]] . "\">" .
|
|
|
+ echo("<div id=\"notif-" . $n["ID"] . "\" class=\"" . "notif " . $deleted[$n["Deleted"]] . " " . $sev_classes[$n["Severity"]] . " " . $seen_class[$n["Seen"]] . "\">" .
|
|
|
"<input type=\"checkbox\" class=\"seen-checkbox\" onclick='notifSelect(this)'>" .
|
|
|
"<button type='button' onclick='markread(this.parentElement)'><i class=\"fa fa-envelope-open-o\" aria-hidden=\"true\"></i></button>" .
|
|
|
"<button type='button' onclick='markdeleted(this.parentElement)'><i class=\"fa fa-trash-o\" aria-hidden=\"true\"></i></button>" .
|
|
|
- "<p>" . $n["Notification"] . "</p>" .
|
|
|
+ "<p id='notif-text'>" . strftime('%d/%m/%y %T', $n['Microtime']) . ": " . $n["Notification"] . "</p>" .
|
|
|
"</div>\n");
|
|
|
}
|
|
|
} ?>
|
|
|
</div>
|
|
|
|
|
|
+ <div id="footer">
|
|
|
+ <div id="notifs-list-controls">
|
|
|
+ <input id="global-selector" type="checkbox" onclick="toggleState(this)">
|
|
|
+ <button id='reverse-btn' type='button' class="control-btn" onclick="reverseSelection()">
|
|
|
+ Inverti selezione
|
|
|
+ </button>
|
|
|
+ <button id='read-btn' type='button' class="control-btn" onclick="readSelected()">
|
|
|
+ <i class="fa fa-envelope-open-o" aria-hidden="true"></i>
|
|
|
+ </button>
|
|
|
+ <button id='delete-btn' type='button' class="control-btn" onclick="deleteSelected()">
|
|
|
+ <i class="fa fa-trash-o" aria-hidden="true"></i>
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</body>
|
|
|
</html>
|