getAlarmen.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. $tz = $_GET['tz'];
  7. if($radioid == "" && $radiomac == ""){
  8. print(json_encode([error => "Not a valid radioid"]));
  9. die();
  10. }else{
  11. if($radiomac != ""){
  12. $radiomac = str_replace(':', '', $radiomac);
  13. $radioid = substr($radiomac, 6 , 11);
  14. }
  15. $array = array();
  16. if($stmt = $mysqli -> prepare("SELECT id, message, message, streamip, streamurl, streamport, tijd, snoozetijd, onlyOnce FROM alarm LEFT JOIN users ON alarm.uid = users.uid WHERE users.radiotoken = ? LIMIT 5")){
  17. $stmt -> bind_param("s", $radioid);
  18. $stmt -> execute();
  19. $stmt -> bind_result($id, $message, $message, $streamip, $streamurl, $streamport, $tijdstr, $snoozetijd, $onlyOnce);
  20. while($result = $stmt -> fetch()){
  21. $tijd = strtotime($tijdstr);
  22. $timezone_name = timezone_name_from_abbr('', $tz * 3600, true);
  23. $datTimeZoneuser = new DateTimeZone($timezone_name);
  24. $time = new DateTime('now', $datTimeZoneuser );
  25. if($tijd < strtotime($time->format("Y-m-d H:i:s "))){
  26. $tijd = strtotime($tijdstr.' +1 day');
  27. }
  28. array_push($array, array( YYYY=> date("Y", $tijd),
  29. MM => date("m", $tijd),
  30. DD => date("d", $tijd),
  31. hh => date("H", $tijd),
  32. mm => date("i", $tijd),
  33. ss => date("s", $tijd),
  34. name => $message,
  35. ip => $streamip,
  36. id => $id,
  37. port => $streamport,
  38. url => $streamurl,
  39. oo => $onlyOnce,
  40. st => $snoozetijd
  41. )
  42. );
  43. };
  44. $stmt -> close();
  45. }
  46. print(json_encode($array, JSON_UNESCAPED_SLASHES));
  47. }