You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

messages.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. require_once "sql.php";
  3. $where = "";
  4. $array = array();
  5. if(isset($_GET['ids']))
  6. {
  7. $ids = explode(",", $_GET['ids']);
  8. $where = "WHERE id=0";
  9. foreach($ids as $id)
  10. {
  11. $id = trim($id);
  12. if($id != "")
  13. {
  14. $id = intval($id);
  15. if($id <= 0)
  16. error("Invalid ids");
  17. $array[] = $id;
  18. $where = $where." OR id=?";
  19. }
  20. }
  21. if(count($array) == 0)
  22. $where = "";
  23. }
  24. else if(isset($_GET['lastMessages']))
  25. {
  26. $l = intval($_GET['lastMessages']);
  27. if($l <= 0)
  28. error("Invalid last messages");
  29. $where = "ORDER BY id DESC LIMIT $l OFFSET 0";
  30. }
  31. else if(isset($_GET['lastMessagesTime']))
  32. {
  33. $l = intval($_GET['lastMessagesTime']);
  34. if($l <= 0)
  35. error("Invalid last time messages");
  36. $where = "WHERE time>=:time";
  37. $array = array(":time" => date("Y-m-d H:i:s", time() - $l));
  38. }
  39. $select = $db->prepare("SELECT * FROM sent ".$where);
  40. if(!$select->execute($array))
  41. error("Unable to read messages");
  42. $messages = array();
  43. while($msg = $select->fetch())
  44. $messages[] = array("id" => intval($msg['id']), "recipient" => $msg['recipient'],
  45. "text" => $msg['text'], "time" => strtotime($msg['time']),
  46. "status" => intval($msg['status']), "gate" => intval($msg['gate']),
  47. "timeStatus" => $msg['timeStatus'] ? strtotime($msg['timeStatus']) : 0);
  48. echo json_encode(array("timestamp" => time(), "messages" => $messages));
  49. ?>