123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- /*
- Status codes:
- 0: sending
- 1: sent
- 2: failed to contact gate
- 3: generic error
- 4: no service
- 5: no pdu
- 6: radio off
- 7: unknown error
- */
- require_once "sql.php";
- if(isset($_GET['id']))
- $id = $_GET['id'];
- else
- $id = "";
- if(isset($_GET['status']))
- $status = $_GET['status'];
- else
- $status = "";
-
- if($id == "")
- error("Empty id");
- if($status == "")
- error("Empty status");
-
- $id = intval($id);
- if($id <= 0)
- error("Invalid id");
- $status = intval($status);
- if($status < 1 || $status > 7)
- error("Invalid status");
-
- $select = $db->prepare("SELECT timeStatus, status FROM sent WHERE id=:id AND gate=(SELECT id FROM gates WHERE address=:address)");
- if(!$select->execute(array(":address" => $_SERVER['REMOTE_ADDR'], ":id" => $id)))
- error("Unable to retrieve gate details");
-
- if($g = $select->fetch())
- {
- if($g['timeStatus'] || $g['status'] != 0)
- error("This status has already been set: ".$g['status']);
- $update = $db->prepare("UPDATE sent SET `status`=:status, `timeStatus`=NOW() WHERE `id`=:id");
- if(!$update->execute(array(":id" => $id, ":status" => $status)))
- error("Failed to update database");
- else
- echo json_encode(array("id" => $id, "status" => $status));
- }
- else
- error("You're not allowed to do this");
- ?>
|