notifsh.php 2.4 KB

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