notifsh.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. header('Content-Type: application/json; charset=utf-8');
  3. require('include/glob.php');
  4. require('include/muoribene.php');
  5. require('include/sessionstart.php');
  6. if (array_key_exists('act',$_GET) && $_GET['act']=='markread' && array_key_exists('id',$_GET) && preg_match('/^[0-9]+$/',$_GET['id'])===1) {
  7. $_GET['id']+=0;
  8. require('include/myconn.php');
  9. mysqli_query($link,'UPDATE Notifications SET Seen=1 WHERE ID='.$_GET['id'])
  10. or muoribene(mysqli_error($link),true);
  11. $res=mysqli_query($link,'SELECT ID FROM Notifications WHERE Seen=0')
  12. or muoribene(mysqli_error($link),true);
  13. echo('{"hmunseen":'.mysqli_num_rows($res).'}'.N);
  14. mysqli_close($link);
  15. } elseif (array_key_exists('act',$_GET) && $_GET['act']=='loadchunk' && array_key_exists('chunk',$_GET) && preg_match('/^[0-9]+$/',$_GET['chunk'])===1) {
  16. $_GET['chunk']+=0;
  17. $chunksize=20; // questo dev'essere uguale in instances.php
  18. require('include/myconn.php');
  19. $res=mysqli_query($link,'SELECT * FROM Notifications ORDER BY Microtime DESC LIMIT '.($_GET['chunk']*$chunksize).','.$chunksize)
  20. or muoribene(mysqli_error($link),true);
  21. mysqli_close($link);
  22. $buf=array();
  23. while ($row=mysqli_fetch_assoc($res)) {
  24. ($row['Seen']==0) ? $notifclass='notifunseen' : $notifclass='notifseen';
  25. $buf[]='<div id="notif-'.$row['ID'].'" class="'.$notifclass.'" onclick="markread(this)">'.strftime('%d/%m/%y %T',$row['Microtime']).': '.$row['Notification'].'</div>';
  26. }
  27. echo(json_encode($buf));
  28. } elseif (array_key_exists('act',$_GET) && $_GET['act']=='loadnew' && array_key_exists('lmt',$_GET) && preg_match('/^[0-9]+(\.[0-9]+)?$/',$_GET['lmt'])===1) {
  29. $_GET['lmt']+=0;
  30. $newlmt=$_GET['lmt'];
  31. $newunread=false;
  32. require('include/myconn.php');
  33. $res=mysqli_query($link,'SELECT * FROM Notifications WHERE Microtime > '.$_GET['lmt'].' ORDER BY Microtime DESC')
  34. or muoribene(mysqli_error($link),true);
  35. mysqli_close($link);
  36. $buf=array();
  37. while ($row=mysqli_fetch_assoc($res)) {
  38. if ($row['Seen']==0) {
  39. $notifclass='notifunseen';
  40. $newunread=true;
  41. } else {
  42. $notifclass='notifseen';
  43. }
  44. $buf[]='<div id="notif-'.$row['ID'].'" class="'.$notifclass.'" onclick="markread(this)">'.strftime('%d/%m/%y %T',$row['Microtime']).': '.$row['Notification'].'</div>';
  45. if ($row['Microtime']+0>$newlmt) $newlmt=$row['Microtime'];
  46. }
  47. $buf=array('newlmt'=>$newlmt,'newunread'=>$newunread,'buf'=>$buf);
  48. echo(json_encode($buf));
  49. }
  50. exit(0);
  51. ?>