...
This commit is contained in:
parent
be6bccbca7
commit
1915458d27
2 changed files with 132 additions and 0 deletions
40
web/admin/include/notifs.php
Normal file
40
web/admin/include/notifs.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
function notifs(&$link) {
|
||||
$chunksize=20; // questo deve essere settato paro-paro in notifsh.php
|
||||
$i=0;
|
||||
$notifs='<div id="notifc">'.N;
|
||||
$notifs.='<div id="notifs" onscroll="morenotifs();">'.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)) {
|
||||
if ($row['Seen']==0) {
|
||||
$unreadnotifs=true;
|
||||
$notifclass='notifunseen';
|
||||
} else {
|
||||
$notifclass='notifseen';
|
||||
}
|
||||
$i++;
|
||||
if ($i<=$chunksize) {
|
||||
if ($i==1) $lastmicrotime=$row['Microtime'];
|
||||
$notifs.='<div id="notif-'.$row['ID'].'" class="'.$notifclass.'" onclick="markread(this)">'.strftime('%d/%m/%y %T',$row['Microtime']).': '.$row['Notification'].'</div>'.N;
|
||||
}
|
||||
}
|
||||
$notifs.='</div>'.N;
|
||||
$notifs.='<div id="notifa"><a href="notifs.php">Vedi tutte le notifiche</a></div>'.N;
|
||||
$notifs.='</div>'.N;
|
||||
if ($unreadnotifs) {
|
||||
$imgoff='imgs/bell_act_off.svg';
|
||||
$imgon='imgs/bell_act_on.svg';
|
||||
} else {
|
||||
$imgoff='imgs/bell_off.svg';
|
||||
$imgon='imgs/bell_on.svg';
|
||||
}
|
||||
return(array(
|
||||
'div'=>$notifs,
|
||||
'imgoff'=>$imgoff,
|
||||
'imgon'=>$imgon,
|
||||
'lastmicrotime'=>$lastmicrotime,
|
||||
'chunksize'=>$chunksize));
|
||||
}
|
||||
?>
|
92
web/admin/js/notifs.js.php
Normal file
92
web/admin/js/notifs.js.php
Normal file
|
@ -0,0 +1,92 @@
|
|||
notifimgon='<?php echo($notifs["imgon"]); ?>';
|
||||
notifimgoff='<?php echo($notifs["imgoff"]); ?>';
|
||||
function shidenotifs() {
|
||||
var notifc=document.getElementById('notifc');
|
||||
var ctrli=document.getElementById('bell');
|
||||
if (notifc.style.display=='block') {
|
||||
notifc.style.display='none';
|
||||
ctrli.src=notifimgoff;
|
||||
ctrli.title='Mostra le notifiche';
|
||||
} else {
|
||||
notifc.style.display='block';
|
||||
ctrli.src=notifimgon;
|
||||
ctrli.title='Nascondi le notifiche';
|
||||
}
|
||||
}
|
||||
function markread(notif) {
|
||||
let xhr=new XMLHttpRequest();
|
||||
xhr.open('GET','notifsh.php?act=markread&id='+notif.id.replace(/^notif-([0-9]+)$/,'$1'));
|
||||
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;
|
||||
}
|
||||
};
|
||||
xhr.onerror=function() {
|
||||
alert('La richiesta è fallita.');
|
||||
};
|
||||
}
|
||||
lmt=<?php echo($notifs['lastmicrotime']); ?>;
|
||||
chunk=0;
|
||||
end=false;
|
||||
loading=false;
|
||||
function morenotifs() {
|
||||
if (!loading && !end && notifs.scrollHeight-notifs.clientHeight-notifs.scrollTop<20) {
|
||||
loading=true;
|
||||
chunk++;
|
||||
let xhr=new XMLHttpRequest();
|
||||
xhr.open('GET','notifsh.php?act=loadchunk&chunk='+chunk);
|
||||
xhr.responseType='json';
|
||||
xhr.send();
|
||||
xhr.onload=function() {
|
||||
let jarr=xhr.response;
|
||||
//console.log(jarr);
|
||||
let i=0, html='';
|
||||
for (i=0; i<jarr.length; i++)
|
||||
html+=jarr[i];
|
||||
notifs.innerHTML+=html;
|
||||
if (jarr.length<<?php echo($notifs['chunksize']); ?>)
|
||||
end=true;
|
||||
loading=false;
|
||||
};
|
||||
xhr.onerror=function() {
|
||||
alert('La richiesta è fallita.');
|
||||
};
|
||||
}
|
||||
}
|
||||
loadingupd=false;
|
||||
function updnotifs() {
|
||||
if (!loadingupd) {
|
||||
loadingupd=true;
|
||||
let xhr=new XMLHttpRequest();
|
||||
xhr.open('GET','notifsh.php?act=loadnew&lmt='+lmt);
|
||||
xhr.responseType='json';
|
||||
xhr.send();
|
||||
xhr.onload=function() {
|
||||
let jarr=xhr.response;
|
||||
//console.log(jarr);
|
||||
let i=0, html='';
|
||||
for (i=0; i<jarr['buf'].length; i++)
|
||||
html+=jarr['buf'][i];
|
||||
notifs.innerHTML=html+notifs.innerHTML;
|
||||
lmt=jarr['newlmt'];
|
||||
if (jarr['newunread']) {
|
||||
notifimgoff='imgs/bell_act_on.svg';
|
||||
notifimgon='imgs/bell_act_off.svg';
|
||||
(notifc.style.display=='block') ? bell.src=notifimgoff : bell.src=notifimgon;
|
||||
}
|
||||
loadingupd=false;
|
||||
};
|
||||
xhr.onerror=function() {
|
||||
alert('La richiesta è fallita.');
|
||||
};
|
||||
} else {
|
||||
console.log('Già sto caricando...');
|
||||
}
|
||||
}
|
||||
updint=setInterval(updnotifs,3000);
|
Loading…
Reference in a new issue