notifs.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. function notifs(&$link) {
  3. $chunksize=20; // questo deve essere settato paro-paro in notifsh.php
  4. $i=0;
  5. $notifs = array();
  6. $notif_divs='<div id="notifc">'.N;
  7. $notif_divs.='<div id="notifs" onscroll="morenotifs();">'.N;
  8. $unreadnotifs=false;
  9. $res=mysqli_query($link,'SELECT * FROM Notifications ORDER BY Microtime DESC')
  10. or muoribene(mysqli_error($link),true);
  11. while ($row=mysqli_fetch_assoc($res)) {
  12. $notifs[]=$row;
  13. if ($row['Seen']==0) {
  14. $unreadnotifs=true;
  15. $notifclass='notifunseen';
  16. } else {
  17. $notifclass='notifseen';
  18. }
  19. $i++;
  20. if ($i<=$chunksize) {
  21. if ($i==1) $lastmicrotime=$row['Microtime'];
  22. $notif_divs.='<div id="notif-'.$row['ID'].'" class="'.$notifclass.'" onclick="markread(this)">'.gmdate('d/m/y H:i:s',round($row['Microtime'])).': '.$row['Notification'].'</div>'.N;
  23. }
  24. }
  25. $notif_divs.='</div>'.N;
  26. $notif_divs.='<div id="notifa"><a href="notifs.php">Vedi tutte le notifiche</a></div>'.N;
  27. $notif_divs.='</div>'.N;
  28. if ($unreadnotifs) {
  29. $imgoff='imgs/bell_act_off.svg';
  30. $imgon='imgs/bell_act_on.svg';
  31. } else {
  32. $imgoff='imgs/bell_off.svg';
  33. $imgon='imgs/bell_on.svg';
  34. }
  35. return(array(
  36. 'notifs'=>$notifs,
  37. 'div'=>$notif_divs,
  38. 'imgoff'=>$imgoff,
  39. 'imgon'=>$imgon,
  40. 'lastmicrotime'=>$lastmicrotime,
  41. 'chunksize'=>$chunksize));
  42. }
  43. ?>