function success($message = "success", $status = false) { if ($status) { REST::response_code($status); } elseif (REST::response_code() >= 300) { REST::response_code(200); } if (REST::preferred("text/html")) { echo '<div class="container"><div class="alert alert-success">' . $message . '</div></div>'; } else { echo $message; } }
} // POST // $id = fetch("SELECT MAX(RID)+1 as id FROM reports")[0]["id"]; if (!$id) { $id = 1; } $content = file_get_contents("php://input"); global $db; $q = $db->prepare("INSERT INTO reports (RID, DID, Content) VALUES (:report_id, :device_id, :content)"); if (!$q->execute(array(":report_id" => $id, ":device_id" => $device_id, ":content" => $content))) { return error("failure", "Failed to post the report."); } // REPLY / RENDER // REST::response_code("created"); header('Location: ' . lnk("/reports/{$id}")); if (!REST::preferred("text/html")) { return success("Successfully posted the report."); } else { echo '<script type="text/javascript">window.location.href="' . lnk("/reports/{$id}") . '"</script>"'; } } else { return error("bad-method", "Unsupported HTTP Method"); } } handle_item_commands: if (count(REST::$ARGS) == 3 && REST::$ARGS[2] == "commands") { if (REST::$REQUEST_METHOD == "GET") { $device_id = REST::$ARGS[1]; if (isset($_REQUEST["since"])) { $since = $_REQUEST["since"]; } else {