diff --git a/web/mustard/js/notifs.js.php b/web/mustard/js/notifs.js.php
index b508fff..a08bed6 100644
--- a/web/mustard/js/notifs.js.php
+++ b/web/mustard/js/notifs.js.php
@@ -47,7 +47,7 @@ function markdeleted(notif) {
xhr.send();
xhr.onload = function () {
if (xhr.response['deleted']) {
- notif.remove();
+ notif.classList.add("deleted");
} else {
alert("Il server non ha potuto cancellare la notifica '" + notif.text + "'");
}
@@ -57,16 +57,61 @@ function markdeleted(notif) {
};
}
-function applyAllSelected(fun) {
- let notifs = document.querySelectorAll("div#notifs-list > div");
- notifs.forEach(function (notif) {
- let checkbox = notif.querySelector("input.seen-checkbox");
- if (checkbox.checked) {
- fun(notif);
- }});
+function readSelected() {
+ let selected = getSelectedNotifs()
+ let request = {
+ "act": "massread",
+ "ids": selected.map(div => div.id.replace(/^notif-([0-9]+)$/, '$1'))
+ }
+ let xhr = new XMLHttpRequest();
+ xhr.open('POST', 'notifs.php');
+ xhr.setRequestHeader('Content-type','application/json');
+ xhr.responseType = 'json';
+ xhr.send(JSON.stringify(request));
+ xhr.onload = function () {
+ if (xhr.response['done']) {
+ selected.forEach(notif => {
+ notif.classList.remove("unseen");
+ notif.classList.add("seen");
+ })
+ } else {
+ alert("Il server non ha potuto completare la richiesta:\n" + xhr.response["error"]);
+ }
+ };
+ xhr.onerror = function () {
+ alert('La richiesta è fallita.');
+ };
}
-lmt=;
+function deleteSelected() {
+ let selected = getSelectedNotifs()
+ let request = {
+ "act": "massdelete",
+ "ids": selected.map(div => div.id.replace(/^notif-([0-9]+)$/, '$1'))
+ }
+ let xhr = new XMLHttpRequest();
+ xhr.open('POST', 'notifs.php');
+ xhr.setRequestHeader('Content-type','application/json');
+ xhr.responseType = 'json';
+ xhr.send(JSON.stringify(request));
+ xhr.onload = function () {
+ if (xhr.response['done']) {
+ selected.forEach(notif => notif.classList.add("deleted"));
+ } else {
+ alert("Il server non ha potuto completare la richiesta:\n" + xhr.response["error"]);
+ }
+ };
+ xhr.onerror = function () {
+ alert('La richiesta è fallita.');
+ };
+}
+
+function getSelectedNotifs() {
+ let notifs = Array.from(document.querySelectorAll("div.notif"));
+ return notifs.filter(notif => notif.querySelector("input.seen-checkbox").checked)
+}
+
+lmt =;
chunk=0;
end=false;
loading=false;
diff --git a/web/mustard/notifs.php b/web/mustard/notifs.php
index bae2c6e..50a59c0 100644
--- a/web/mustard/notifs.php
+++ b/web/mustard/notifs.php
@@ -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 . '
' . N;
$dbg .= '
' . print_r($_GET, 1) . ''; @@ -115,20 +160,17 @@ if ($filtordon) {