MastodonHelp/web/mustard/notifs.php

225 lines
7.9 KiB
PHP
Raw Normal View History

<?php
require('include/glob.php');
require('include/muoribene.php');
require('include/sessionstart.php');
require('include/myconn.php');
require('include/getadmacc.php');
if ($account['Level'] == 'guest')
muoribene('Sorry, you are not authorized.', true);
require('include/menu.php');
$menu['menu']['selected'] = true;
$menu['menu']['submenu']['notifs']['selected'] = true;
buildmenu($menu);
$dbg = '';
// praticamente una macro
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>';
$dbg .= '<pre>' . print_r($inst, 1) . '</pre>' . N;
if ($account['Level'] != 'guest') {
require('include/notifs.php');
$notifs = notifs($link);
} else {
muoribene("Non hai i permessi per vedere questa pagina", true);
}
$filtordon = false;
if ($filtordon) {
$filtordimgoff = 'imgs/cerca_act_off.svg';
$filtordimgon = 'imgs/cerca_act_on.svg';
} else {
$filtordimgoff = 'imgs/cerca_off.svg';
$filtordimgon = 'imgs/cerca_on.svg';
}
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Mustard - Notifs</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="description" content="Admin pages for Mastodon Startpage">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="icon" type="image/png" href="imgs/icona-32.png" sizes="32x32">
<link rel="icon" type="image/png" href="imgs/icona-192.png" sizes="192x192">
<link rel="icon" type="image/png" href="imgs/icona-512.png" sizes="512x512">
<link rel="apple-touch-icon-precomposed" href="imgs/icona-180.png">
<script language="JavaScript" src="js/menu.js?v=<?php echo($cjrand); ?>"></script>
<script language="JavaScript" src="js/confirma.js?v=<?php echo($cjrand); ?>"></script>
<script language="JavaScript" src="js/alerta.js?v=<?php echo($cjrand); ?>"></script>
<link rel="stylesheet" type="text/css" href="theme.css?v=<?php echo($cjrand); ?>">
<script language="JavaScript">
<!--
<?php if ($account['Level'] != 'guest') require('js/notifs.js.php'); ?>
function reverseSelection() {
let checkboxes = Array.from(document.querySelectorAll("div.notif > input.seen-checkbox"));
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 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;
});
}
function toggleState(check) {
if (check.checked) {
setBtnsVisibility("visible");
} else {
setBtnsVisibility("hidden")
}
let checkboxes = document.querySelectorAll("div.notif > input.seen-checkbox");
checkboxes.forEach(function (box) {
box.checked = check.checked;
});
}
function notifSelect(check) {
let checkboxes = Array.from(document.querySelectorAll("div.notif > input.seen-checkbox"));
if (check.checked) {
setBtnsVisibility("visible");
} else if (checkboxes.every(box => !box.checked)) {
setBtnsVisibility("hidden");
}
}
// -->
</script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/fork-awesome@1.1.7/css/fork-awesome.min.css"
integrity="sha256-gsmEoJAws/Kd3CjuOQzLie5Q3yshhvmo7YNtBG7aaEY=" crossorigin="anonymous">
</head>
<body>
<nav>
<div id="hmenu">
<ul>
<?php echo($menuout); ?>
</ul>
<div class="mtit">Notifiche</div>
<div id="rightdiv">
<?php if ($account['Level'] != 'guest') echo('<img src="' . $notifs['imgoff'] . '" id="bell" class="rlinks" title="Show notifications" onclick="shidenotifs();">' . N); ?>
<img src="imgs/esci.svg" class="rlinks" title="Logout" onclick="document.location.href='logout.php';">
</div>
</div>
</nav>
<?php echo($notifs['div']); ?>
<div id="notifs-grid">
<div id="notifs-list">
<?php
if ($account['Level'] != 'guest') {
$sev_classes = array(
1 => "sev-normal",
2 => "sev-warning",
3 => "sev-error"
);
$seen_class = array(
0 => "unseen",
1 => "seen"
);
foreach ($notifs['notifs'] as $n) {
echo("<div id=\"notif-" . $n["ID"] . "\" class=\"" . "notif " . $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>" .
"</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>
<?php
mysqli_close($link);
?>