From a33ac2d1302362f91de1634291b6312c634b5c86 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 15 May 2020 18:43:06 +0200 Subject: [PATCH 01/21] menu: Aggiunto link a "notifs.php". * web/mustard/include/menu.php: Aggiunto link alla pagina per la gestione delle notifiche. --- web/mustard/include/menu.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/mustard/include/menu.php b/web/mustard/include/menu.php index b71c781..5a830fb 100644 --- a/web/mustard/include/menu.php +++ b/web/mustard/include/menu.php @@ -7,7 +7,7 @@ if ($account['Level']!='guest') { 'instances'=>array('liadd'=>null, 'href'=>'instances.php', 'title'=>'Istanze', 'selected'=>false, 'submenu'=>null), 'blacklist'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Blacklist', 'selected'=>false, 'submenu'=>null), 'accounts'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Accounts', 'selected'=>false, 'submenu'=>null), - 'notifs'=>array('liadd'=>null, 'href'=>'#', 'title'=>'Notifiche', 'selected'=>false, 'submenu'=>null), + 'notifs'=>array('liadd'=>null, 'href'=>'notifs.php', 'title'=>'Notifiche', 'selected'=>false, 'submenu'=>null), 'logout'=>array('liadd'=>null, 'href'=>'logout.php', 'title'=>'Logout', 'selected'=>false, 'submenu'=>null) ) ) From 9c1a3f40684d12b536d7368d1d364dabce5fa77d Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 15 May 2020 18:44:48 +0200 Subject: [PATCH 02/21] include: notifs: Ritorna un array di notifiche. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * web/mustard/include/notifs.php (notifs): Rinomina a notif_divs, (notifs): Ora è un array di notifiche. --- web/mustard/include/notifs.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/web/mustard/include/notifs.php b/web/mustard/include/notifs.php index 9f0229e..198bb7d 100644 --- a/web/mustard/include/notifs.php +++ b/web/mustard/include/notifs.php @@ -2,12 +2,14 @@ function notifs(&$link) { $chunksize=20; // questo deve essere settato paro-paro in notifsh.php $i=0; - $notifs='
'.N; - $notifs.='
'.N; + $notifs = array(); + $notif_divs='
'.N; + $notif_divs.='
'.N; $unreadnotifs=false; $res=mysqli_query($link,'SELECT * FROM Notifications ORDER BY Microtime DESC') or muoribene(mysqli_error($link),true); while ($row=mysqli_fetch_assoc($res)) { + array_push($notifs, $row); if ($row['Seen']==0) { $unreadnotifs=true; $notifclass='notifunseen'; @@ -17,12 +19,12 @@ function notifs(&$link) { $i++; if ($i<=$chunksize) { if ($i==1) $lastmicrotime=$row['Microtime']; - $notifs.='
'.strftime('%d/%m/%y %T',$row['Microtime']).': '.$row['Notification'].'
'.N; + $notif_divs.='
'.strftime('%d/%m/%y %T',$row['Microtime']).': '.$row['Notification'].'
'.N; } } - $notifs.='
'.N; - $notifs.=''.N; - $notifs.='
'.N; + $notif_divs.='
'.N; + $notif_divs.=''.N; + $notif_divs.='
'.N; if ($unreadnotifs) { $imgoff='imgs/bell_act_off.svg'; $imgon='imgs/bell_act_on.svg'; @@ -31,7 +33,8 @@ function notifs(&$link) { $imgon='imgs/bell_on.svg'; } return(array( - 'div'=>$notifs, + 'notifs'=>$notifs, + 'div'=>$notif_divs, 'imgoff'=>$imgoff, 'imgon'=>$imgon, 'lastmicrotime'=>$lastmicrotime, From 5fd367c26a02334af96988b426e65d5708c87650 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 15 May 2020 18:47:41 +0200 Subject: [PATCH 03/21] notifs: Nuova pagina. * web/mustard/notifs.php: Nuovo file. Ritorna una pagina che permette di gestire la lista delle notifiche. --- web/mustard/notifs.php | 333 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 333 insertions(+) create mode 100644 web/mustard/notifs.php diff --git a/web/mustard/notifs.php b/web/mustard/notifs.php new file mode 100644 index 0000000..043599d --- /dev/null +++ b/web/mustard/notifs.php @@ -0,0 +1,333 @@ +' . N; +$dbg .= '
' . print_r($_GET, 1) . '
'; + +$dbg .= '
' . print_r($inst, 1) . '
' . N; + +if ($account['Level'] != 'guest') { + require('include/notifs.php'); + $notifs = notifs($link); +} else { + muoribene("Non hai i permessi per vedere questa pagina", true); +} + +?> + + + + + Mustard - Notifs + + + + + + + + + + + + + + + + + +
+
+
+ "sev-normal", + 2 => "sev-warning", + 3 => "sev-error" + ); + foreach ($notifs['notifs'] as $n) { + echo("
" . $n["Notification"] . "
\n"); + } + } ?> +
+
+
+ + + + + + From 53b5294fb00e77bca454e1b2f7ed12210caa0bcb Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 15 May 2020 18:49:32 +0200 Subject: [PATCH 04/21] mustard: theme: Aggiunte regole per notifs.php. * web/mustard/theme.css: Aggiunte regole per "#notifs-list", e i vari livelli di severity. --- web/mustard/theme.css | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/web/mustard/theme.css b/web/mustard/theme.css index f07336b..3f2ee21 100644 --- a/web/mustard/theme.css +++ b/web/mustard/theme.css @@ -127,6 +127,34 @@ p { background-color: #FFEEAA; color: black; } + +#notifs-list { + margin-top: 32px; + margin-left: 360px; + margin-right: 360px; +} + +#notifs-list div { + padding: 3px; + margin: 10px; + min-width: 360px; + + vertical-align: top; + + word-break: break-word; + + background-color: lightgrey; + border-radius: 5px; +} + +#notifs-list div.sev-warning { + background-color: #FFEEAA; +} + +#notifs-list div.sev-error { + background-color: #DE8787; +} + .ourfield { background-color: #FFB380; } From 0198c3b52311655430830a7e87f5d4d47a4bfae8 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 15 May 2020 18:53:42 +0200 Subject: [PATCH 05/21] Sposta flag mail.add_x_header. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Il flag può stare in .htaccess solo se l'app non viene hostata tramite CGI. * web/mustard/.htaccess: Da qui... * web/mustard/php.ini: ...a qui. --- web/mustard/.htaccess | 1 - web/mustard/php.ini | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 web/mustard/php.ini diff --git a/web/mustard/.htaccess b/web/mustard/.htaccess index 56610dd..226358b 100644 --- a/web/mustard/.htaccess +++ b/web/mustard/.htaccess @@ -1,3 +1,2 @@ RewriteEngine Off RewriteEngine On -php_flag mail.add_x_header Off diff --git a/web/mustard/php.ini b/web/mustard/php.ini new file mode 100644 index 0000000..2c8e24b --- /dev/null +++ b/web/mustard/php.ini @@ -0,0 +1 @@ +mail.add_x_header="0" From db3fd262dd26be3ad9e91489ddcb72222cc6ff1c Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 15 May 2020 20:04:58 +0200 Subject: [PATCH 06/21] js: notifs: Se una notifica viene letta aggiornane la classe. * web/mustard/js/notifs.js.php (markread): Aggiunto caso in cui la funzione viene chiamata su un elemento della pagina di gestione delle notifiche. --- web/mustard/js/notifs.js.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/web/mustard/js/notifs.js.php b/web/mustard/js/notifs.js.php index 9645e2c..8e36b84 100644 --- a/web/mustard/js/notifs.js.php +++ b/web/mustard/js/notifs.js.php @@ -19,13 +19,21 @@ function markread(notif) { xhr.responseType='json'; xhr.send(); xhr.onload=function() { - notif.className='notifseen'; let jarr=xhr.response; if (jarr['hmunseen']==0) { notifimgon='imgs/bell_on.svg'; notifimgoff='imgs/bell_off.svg'; bell.src=notifimgon; } + + if (notif.classList.contains("notifunseen")){ + // Notifica nella navbar + notif.className='notifseen'; + } else if (notif.classList.contains("unseen")) { + // Notifica nella pagina di gestione notifiche + notif.classList.remove("unseen"); + notif.classList.add("seen"); + } }; xhr.onerror=function() { alert('La richiesta è fallita.'); From 44db4b4aa2a81c9cc2108fd95e5e49b8a38fdf4f Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 15 May 2020 20:08:10 +0200 Subject: [PATCH 07/21] =?UTF-8?q?mustard:=20theme:=20Aggiunta=20regola=20p?= =?UTF-8?q?er=20le=20notifiche=20gi=C3=A0=20lette.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/mustard/theme.css | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web/mustard/theme.css b/web/mustard/theme.css index 3f2ee21..793e404 100644 --- a/web/mustard/theme.css +++ b/web/mustard/theme.css @@ -143,7 +143,7 @@ p { word-break: break-word; - background-color: lightgrey; + background-color: #87DE87; border-radius: 5px; } @@ -155,6 +155,10 @@ p { background-color: #DE8787; } +#notifs-list div.seen { + background-color: lightgrey; +} + .ourfield { background-color: #FFB380; } From e04853ce5fc1041afaca55031a78c6dd5ce5ba36 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 15 May 2020 20:09:31 +0200 Subject: [PATCH 08/21] mustard: notifs: Aggiunto bottone per leggere le notifiche. * web/mustard/notifs.php: Aggiunto bottone che chiama la funzione JS markread per marcare come letta la notifica. --- web/mustard/notifs.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/web/mustard/notifs.php b/web/mustard/notifs.php index 043599d..8e2cb94 100644 --- a/web/mustard/notifs.php +++ b/web/mustard/notifs.php @@ -304,6 +304,8 @@ if ($account['Level'] != 'guest') { + +
@@ -314,8 +316,16 @@ if ($account['Level'] != 'guest') { 2 => "sev-warning", 3 => "sev-error" ); + $seen_class = array( + 0 => "unseen", + 1 => "seen" + ); foreach ($notifs['notifs'] as $n) { - echo("
" . $n["Notification"] . "
\n"); + echo("
" . + $n["Notification"] . + "" . + "
\n"); } } ?>
From c44d3b0d6e754a04413c8c9967b7a11f07cc4d25 Mon Sep 17 00:00:00 2001 From: paul Date: Sat, 16 May 2020 02:04:06 +0200 Subject: [PATCH 09/21] mustard: theme: Aggiunte regole per i controlli di notifs.php --- web/mustard/theme.css | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/web/mustard/theme.css b/web/mustard/theme.css index 793e404..9266fdc 100644 --- a/web/mustard/theme.css +++ b/web/mustard/theme.css @@ -128,12 +128,17 @@ p { color: black; } -#notifs-list { +#notifs-list-controls { margin-top: 32px; margin-left: 360px; margin-right: 360px; } +#notifs-list { + margin-left: 360px; + margin-right: 360px; +} + #notifs-list div { padding: 3px; margin: 10px; From 6778516add2538bd4e64e90a644747b105f77d71 Mon Sep 17 00:00:00 2001 From: paul Date: Sat, 16 May 2020 02:04:41 +0200 Subject: [PATCH 10/21] mustard: notifs: Aggiunti controlli per la lista delle notifiche. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * web/mustard/notifs.php: Aggiunta una checkbox per selezionare/deselezionare in massa le notifiche ed un bottone per segnare tutte quelle selezionate come già lette. --- web/mustard/notifs.php | 260 +++++------------------------------------ 1 file changed, 30 insertions(+), 230 deletions(-) diff --git a/web/mustard/notifs.php b/web/mustard/notifs.php index 8e2cb94..c4f04b8 100644 --- a/web/mustard/notifs.php +++ b/web/mustard/notifs.php @@ -32,6 +32,14 @@ if ($account['Level'] != 'guest') { 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'; +} ?> @@ -52,241 +60,24 @@ if ($account['Level'] != 'guest') { @@ -308,9 +99,16 @@ if ($account['Level'] != 'guest') {
+
+ + +
"sev-normal", 2 => "sev-warning", @@ -323,12 +121,14 @@ if ($account['Level'] != 'guest') { foreach ($notifs['notifs'] as $n) { echo("
" . + "" . $n["Notification"] . "" . "
\n"); } } ?>
+
From 7314ce63d18e81f51fdc3032fc5fb0813dded0b8 Mon Sep 17 00:00:00 2001 From: paul Date: Sat, 16 May 2020 10:42:16 +0200 Subject: [PATCH 11/21] mustard: notifsh: Aggiunto endpoint per cancellare le notifiche. * web/mustard/notifsh.php: Aggiunto un nuovo endpoint (?act="delete") che permette di cancellare le notifiche. --- web/mustard/notifsh.php | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/web/mustard/notifsh.php b/web/mustard/notifsh.php index aee1b1c..f96cffe 100644 --- a/web/mustard/notifsh.php +++ b/web/mustard/notifsh.php @@ -7,25 +7,30 @@ require('include/muoribenejson.php'); require('include/sessionstart.php'); require('include/myconn.php'); require('include/getadmacc.php'); -if ($account['Level']=='guest') - muoribene('Sorry, you are not authorized.',true); +if ($account['Level'] == 'guest') + muoribene('Sorry, you are not authorized.', true); -if (array_key_exists('act',$_GET) && $_GET['act']=='markread' && array_key_exists('id',$_GET) && preg_match('/^[0-9]+$/',$_GET['id'])===1) { - $_GET['id']+=0; - mysqli_query($link,'UPDATE Notifications SET Seen=1 WHERE ID='.$_GET['id']) - or muoribene(mysqli_error($link),true); - $res=mysqli_query($link,'SELECT ID FROM Notifications WHERE Seen=0') - or muoribene(mysqli_error($link),true); - echo('{"hmunseen":'.mysqli_num_rows($res).'}'.N); -} elseif (array_key_exists('act',$_GET) && $_GET['act']=='loadchunk' && array_key_exists('chunk',$_GET) && preg_match('/^[0-9]+$/',$_GET['chunk'])===1) { - $_GET['chunk']+=0; - $chunksize=20; // questo dev'essere uguale in include/notifs.php - $res=mysqli_query($link,'SELECT * FROM Notifications ORDER BY Microtime DESC LIMIT '.($_GET['chunk']*$chunksize).','.$chunksize) - or muoribene(mysqli_error($link),true); - $buf=array(); - while ($row=mysqli_fetch_assoc($res)) { - ($row['Seen']==0) ? $notifclass='notifunseen' : $notifclass='notifseen'; - $buf[]='
'.strftime('%d/%m/%y %T',$row['Microtime']).': '.$row['Notification'].'
'; +if (array_key_exists('act', $_GET) && $_GET['act'] == 'markread' && array_key_exists('id', $_GET) && preg_match('/^[0-9]+$/', $_GET['id']) === 1) { + $_GET['id'] += 0; + mysqli_query($link, 'UPDATE Notifications SET Seen=1 WHERE ID=' . $_GET['id']) + or muoribene(mysqli_error($link), true); + $res = mysqli_query($link, 'SELECT ID FROM Notifications WHERE Seen=0') + or muoribene(mysqli_error($link), true); + echo('{"hmunseen":' . mysqli_num_rows($res) . '}' . N); +} elseif (array_key_exists('act', $_GET) && $_GET['act'] == 'delete' && array_key_exists('id', $_GET) && preg_match('/^[0-9]+$/', $_GET['id']) === 1) { + $_GET['id'] += 0; + mysqli_query($link, 'DELETE FROM Notifications WHERE ID=' . $_GET['id']) + or muoribene(mysqli_error($link), true); + echo('{"deleted":' . true . '}' . N); +} elseif (array_key_exists('act', $_GET) && $_GET['act'] == 'loadchunk' && array_key_exists('chunk', $_GET) && preg_match('/^[0-9]+$/', $_GET['chunk']) === 1) { + $_GET['chunk'] += 0; + $chunksize = 20; // questo dev'essere uguale in include/notifs.php + $res = mysqli_query($link, 'SELECT * FROM Notifications ORDER BY Microtime DESC LIMIT ' . ($_GET['chunk'] * $chunksize) . ',' . $chunksize) + or muoribene(mysqli_error($link), true); + $buf = array(); + while ($row = mysqli_fetch_assoc($res)) { + ($row['Seen'] == 0) ? $notifclass = 'notifunseen' : $notifclass = 'notifseen'; + $buf[] = '
' . strftime('%d/%m/%y %T', $row['Microtime']) . ': ' . $row['Notification'] . '
'; } echo(json_encode($buf)); } elseif (array_key_exists('act',$_GET) && $_GET['act']=='loadnew' && array_key_exists('lmt',$_GET) && preg_match('/^[0-9]+(\.[0-9]+)?$/',$_GET['lmt'])===1) { From 3c7756f76fb3a8cf675d912abe34f81055ff4fed Mon Sep 17 00:00:00 2001 From: paul Date: Sat, 16 May 2020 10:44:34 +0200 Subject: [PATCH 12/21] mustard: notifs.js: Aggiunta funzione per cancellare le notifiche. * web/mustard/js/notifs.js.php: Aggiunta funzione per la rimozione delle notifiche ed una funzione per applicare una funzione a tutte le notifiche selezionate. --- web/mustard/js/notifs.js.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/web/mustard/js/notifs.js.php b/web/mustard/js/notifs.js.php index 8e36b84..4d507a1 100644 --- a/web/mustard/js/notifs.js.php +++ b/web/mustard/js/notifs.js.php @@ -39,6 +39,33 @@ function markread(notif) { alert('La richiesta è fallita.'); }; } + +function markdeleted(notif) { + let xhr=new XMLHttpRequest(); + xhr.open('GET','notifsh.php?act=delete&id='+notif.id.replace(/^notif-([0-9]+)$/,'$1')); + xhr.responseType='json'; + xhr.send(); + xhr.onload=function() { + if (xhr.response['deleted']) { + notif.remove(); + } else { + alert("Il server non ha potuto cancellare la notifica " + notif.text); + } + }; + xhr.onerror=function() { + alert('La richiesta è fallita.'); + }; +} + +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); + }}); +} + lmt=; chunk=0; end=false; From a9e7bfb13241885b9de2a419590d2e7593217336 Mon Sep 17 00:00:00 2001 From: paul Date: Sat, 16 May 2020 10:47:47 +0200 Subject: [PATCH 13/21] mustard: notifs: Aggiunti controlli per cancellare le notifiche. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * web/mustard/notifs.php: Aggiunto bottone per eliminare le notifiche, e temporaneamente ForkAwesome, giusto perchè mi sembrava very cool. --- web/mustard/notifs.php | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/web/mustard/notifs.php b/web/mustard/notifs.php index c4f04b8..f3c530d 100644 --- a/web/mustard/notifs.php +++ b/web/mustard/notifs.php @@ -66,19 +66,10 @@ if ($filtordon) { box.checked = check.checked; }) } - - function readAllSelected() { - let notifs = document.querySelectorAll("div#notifs-list > div"); - notifs.forEach(function (notif) { - let checkbox = notif.querySelector("input.seen-checkbox"); - if (checkbox.checked) { - markread(notif); - } - }) - } - // --> + + @@ -101,7 +92,8 @@ if ($filtordon) {
- + +
Date: Sat, 16 May 2020 23:36:03 +0200 Subject: [PATCH 14/21] mustard: notifs: Refactor layout pagina gestione notifiche. * web/mustard/notifs.php: Aggiunto layout con CSS Grid, [script]: Aggiunta logica per mostare/nascondere i bottoni per operare su multiple notifiche. --- web/mustard/notifs.php | 102 ++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 38 deletions(-) diff --git a/web/mustard/notifs.php b/web/mustard/notifs.php index f3c530d..bae2c6e 100644 --- a/web/mustard/notifs.php +++ b/web/mustard/notifs.php @@ -60,16 +60,40 @@ if ($filtordon) { - + @@ -88,43 +112,45 @@ if ($filtordon) { -
-
-
- - - -
-
- "sev-normal", - 2 => "sev-warning", - 3 => "sev-error" - ); - $seen_class = array( - 0 => "unseen", - 1 => "seen" - ); - foreach ($notifs['notifs'] as $n) { - echo("
" . - "" . - $n["Notification"] . - "" . - "
\n"); - } - } ?> -
- +
+
+ + + +
+

CIAONEE

+
+ "sev-normal", + 2 => "sev-warning", + 3 => "sev-error" + ); + $seen_class = array( + 0 => "unseen", + 1 => "seen" + ); + foreach ($notifs['notifs'] as $n) { + echo("
" . + "" . + "" . + "" . + "

" . $n["Notification"] . "

" . + "
\n"); + } + } ?>
-
-
+
From 1a6602490781dd0430f926d8a5a2fe42dfd24fda Mon Sep 17 00:00:00 2001 From: paul Date: Sat, 16 May 2020 23:41:54 +0200 Subject: [PATCH 15/21] mustard: theme: Aggiunte regole per notifs.php. --- web/mustard/js/notifs.js.php | 12 ++-- web/mustard/theme.css | 106 +++++++++++++++++++++++------------ 2 files changed, 75 insertions(+), 43 deletions(-) diff --git a/web/mustard/js/notifs.js.php b/web/mustard/js/notifs.js.php index 4d507a1..b508fff 100644 --- a/web/mustard/js/notifs.js.php +++ b/web/mustard/js/notifs.js.php @@ -41,18 +41,18 @@ function markread(notif) { } function markdeleted(notif) { - let xhr=new XMLHttpRequest(); - xhr.open('GET','notifsh.php?act=delete&id='+notif.id.replace(/^notif-([0-9]+)$/,'$1')); - xhr.responseType='json'; + let xhr = new XMLHttpRequest(); + xhr.open('GET', 'notifsh.php?act=delete&id=' + notif.id.replace(/^notif-([0-9]+)$/, '$1')); + xhr.responseType = 'json'; xhr.send(); - xhr.onload=function() { + xhr.onload = function () { if (xhr.response['deleted']) { notif.remove(); } else { - alert("Il server non ha potuto cancellare la notifica " + notif.text); + alert("Il server non ha potuto cancellare la notifica '" + notif.text + "'"); } }; - xhr.onerror=function() { + xhr.onerror = function () { alert('La richiesta è fallita.'); }; } diff --git a/web/mustard/theme.css b/web/mustard/theme.css index 9266fdc..0060599 100644 --- a/web/mustard/theme.css +++ b/web/mustard/theme.css @@ -118,6 +118,7 @@ p { .bad { background-color: #DE8787; } + .neut { background-color: #FFCCAA; } @@ -128,42 +129,6 @@ p { color: black; } -#notifs-list-controls { - margin-top: 32px; - margin-left: 360px; - margin-right: 360px; -} - -#notifs-list { - margin-left: 360px; - margin-right: 360px; -} - -#notifs-list div { - padding: 3px; - margin: 10px; - min-width: 360px; - - vertical-align: top; - - word-break: break-word; - - background-color: #87DE87; - border-radius: 5px; -} - -#notifs-list div.sev-warning { - background-color: #FFEEAA; -} - -#notifs-list div.sev-error { - background-color: #DE8787; -} - -#notifs-list div.seen { - background-color: lightgrey; -} - .ourfield { background-color: #FFB380; } @@ -849,15 +814,82 @@ input { color: black; border-radius: 6px; } + .message p, ul { margin-bottom: 10px; } -@media only screen and (max-width:720px) { +#notifs-grid { + display: grid; + grid-template-columns: repeat(3, 1fr); + grid-gap: 10px; +} + +#notifs-list-controls { + display: inline-block; + overflow: auto; + margin-top: 32px; + margin-left: 10px; + margin-right: 10px; + grid-column: 2; + border-radius: 5px; + padding: 3px; + background-color: #FFEEAA; +} + +#global-selector { + width: auto; +} + +.control-btn { + float: right; + visibility: hidden; +} + +#notifs-list { + grid-column: 2; +} + +div.notif { + padding: 5px; + margin: 10px; + word-break: break-word; + background-color: #87DE87; + border-radius: 5px; +} + +div.notif p { + text-align: center; + padding: 3px; +} + + +div.notif input { + width: auto; +} + +div.notif button { + float: right; +} + +div.sev-warning { + background-color: #FFEEAA; +} + +div.sev-error { + background-color: #DE8787; +} + +div.seen { + background-color: lightgrey; +} + +@media only screen and (max-width: 720px) { .bigtab td { width: 244px; min-width: 244px; } + .message { width: 340px; } From df9782ab1e6b61914936f2ef16ca107159ab7f27 Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 18 May 2020 15:13:23 +0200 Subject: [PATCH 16/21] mustard: Aggiunti controlli per gestione in massa delle notifiche. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * web/mustard/js/notifs.js.php: Aggiunte funzioni per cancellare e marcare come lette che operano su liste di notifiche. * web/mustard/notifs.php: Quando riceve una POST con un body JSON esegue un'azione su liste di notifiche. * web/mustard/notifsh.php: Le notifiche non vengono più cancellate dal DB ma vengono marcate "deleted". * web/mustard/theme.css: Aggiunta classe "deleted". --- web/mustard/js/notifs.js.php | 63 ++++++++++++++++++++++++++++++------ web/mustard/notifs.php | 59 +++++++++++++++++++++++++++------ web/mustard/notifsh.php | 2 +- web/mustard/theme.css | 4 +++ 4 files changed, 109 insertions(+), 19 deletions(-) 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) {
- -

CIAONEE

"sev-normal", 2 => "sev-warning", @@ -139,8 +181,7 @@ if ($filtordon) { 1 => "seen" ); foreach ($notifs['notifs'] as $n) { - echo("
" . + echo("
" . "" . "" . "" . diff --git a/web/mustard/notifsh.php b/web/mustard/notifsh.php index f96cffe..3b28176 100644 --- a/web/mustard/notifsh.php +++ b/web/mustard/notifsh.php @@ -19,7 +19,7 @@ if (array_key_exists('act', $_GET) && $_GET['act'] == 'markread' && array_key_ex echo('{"hmunseen":' . mysqli_num_rows($res) . '}' . N); } elseif (array_key_exists('act', $_GET) && $_GET['act'] == 'delete' && array_key_exists('id', $_GET) && preg_match('/^[0-9]+$/', $_GET['id']) === 1) { $_GET['id'] += 0; - mysqli_query($link, 'DELETE FROM Notifications WHERE ID=' . $_GET['id']) + mysqli_query($link, 'UPDATE Notifications SET Deleted=1 WHERE ID=' . $_GET['id']) or muoribene(mysqli_error($link), true); echo('{"deleted":' . true . '}' . N); } elseif (array_key_exists('act', $_GET) && $_GET['act'] == 'loadchunk' && array_key_exists('chunk', $_GET) && preg_match('/^[0-9]+$/', $_GET['chunk']) === 1) { diff --git a/web/mustard/theme.css b/web/mustard/theme.css index 0060599..c586701 100644 --- a/web/mustard/theme.css +++ b/web/mustard/theme.css @@ -872,6 +872,10 @@ div.notif button { float: right; } +div.deleted { + display: none; +} + div.sev-warning { background-color: #FFEEAA; } From 14200ea5fd232ac4970262d828b9a953ad01e420 Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 18 May 2020 19:18:23 +0200 Subject: [PATCH 17/21] mustard: notifs: Aggiunto bottone per invertire la selezione. * web/mustard/notifs.php: Aggiunto footer di instances.php, bottone e funzione JS per invertire la selezione e alcuni side effects. * web/mustard/theme.css: Aggiunte regole per i controlli nel footer. --- web/mustard/notifs.php | 44 +++++++++++++++++++++++++++++++----------- web/mustard/theme.css | 35 ++++++++++++++++++++++++--------- 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/web/mustard/notifs.php b/web/mustard/notifs.php index 50a59c0..0a241da 100644 --- a/web/mustard/notifs.php +++ b/web/mustard/notifs.php @@ -106,8 +106,26 @@ if ($filtordon) { @@ -167,6 +284,8 @@ if ($filtordon) {
Notifiche
+ ' . N); ?>
@@ -193,7 +312,9 @@ if ($filtordon) { 1 => "deleted" ); foreach ($notifs['notifs'] as $n) { - echo("
" . + echo("
" . "" . "" . "" . @@ -203,6 +324,14 @@ if ($filtordon) { } ?>
+ +
+ +
+ +
+ +
+