getAlarmen.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. include_once('includes/db_connect.php');
  3. include_once('includes/global_functions.php');
  4. $radioid = $_GET['radioid'];
  5. $radiomac = $_GET['radiomac'];
  6. if($radioid == "" && $radiomac == ""){
  7. print(json_encode([error => "Not a valid radioid"]));
  8. die();
  9. }else{
  10. if($radiomac != ""){
  11. $radiomac = str_replace(':', '', $radiomac);
  12. $radioid = substr($radiomac, 6 , 11);
  13. }
  14. $array = array();
  15. if($stmt = $mysqli -> prepare("SELECT id, message, message, streamip, streamurl, streamport, tijd, snoozetijd FROM alarm LEFT JOIN users ON alarm.uid = users.uid WHERE users.radiotoken = ? LIMIT 5")){
  16. $stmt -> bind_param("s", $radioid);
  17. $stmt -> execute();
  18. $stmt -> bind_result($id, $message, $message, $streamip, $streamurl, $streamport, $tijdstr, $snoozetijd);
  19. while($result = $stmt -> fetch()){
  20. $tijd = strtotime($tijdstr);
  21. if($tijd < time()){
  22. $tijd = strtotime($tijdstr.' +1 day');
  23. }
  24. array_push($array, array( YYYY=> date("Y", $tijd),
  25. MM => date("m", $tijd),
  26. DD => date("d", $tijd),
  27. hh => date("H", $tijd),
  28. mm => date("i", $tijd),
  29. ss => date("s", $tijd),
  30. name => $message,
  31. ip => $streamip,
  32. id => $id,
  33. port => $streamport,
  34. url => $streamurl,
  35. st => $snoozetijd
  36. )
  37. );
  38. };
  39. $stmt -> close();
  40. }
  41. print(json_encode($array, JSON_UNESCAPED_SLASHES));
  42. }