您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

sent.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. Status codes:
  4. 0: sending
  5. 1: sent
  6. 2: failed to contact gate
  7. 3: generic error
  8. 4: no service
  9. 5: no pdu
  10. 6: radio off
  11. 7: unknown error
  12. */
  13. require_once "sql.php";
  14. if(isset($_GET['id']))
  15. $id = $_GET['id'];
  16. else
  17. $id = "";
  18. if(isset($_GET['status']))
  19. $status = $_GET['status'];
  20. else
  21. $status = "";
  22. if($id == "")
  23. error("Empty id");
  24. if($status == "")
  25. error("Empty status");
  26. $id = intval($id);
  27. if($id <= 0)
  28. error("Invalid id");
  29. $status = intval($status);
  30. if($status < 1 || $status > 7)
  31. error("Invalid status");
  32. $select = $db->prepare("SELECT timeStatus, status FROM sent WHERE id=:id AND gate=(SELECT id FROM gates WHERE address=:address)");
  33. if(!$select->execute(array(":address" => $_SERVER['REMOTE_ADDR'], ":id" => $id)))
  34. error("Unable to retrieve gate details");
  35. if($g = $select->fetch())
  36. {
  37. if($g['timeStatus'] || $g['status'] != 0)
  38. error("This status has already been set: ".$g['status']);
  39. $update = $db->prepare("UPDATE sent SET `status`=:status, `timeStatus`=NOW() WHERE `id`=:id");
  40. if(!$update->execute(array(":id" => $id, ":status" => $status)))
  41. error("Failed to update database");
  42. else
  43. echo json_encode(array("id" => $id, "status" => $status));
  44. }
  45. else
  46. error("You're not allowed to do this");
  47. ?>