Make calls compatible with area and tile wise lookups, added get-options call
Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
parent
10f7af253c
commit
093ddfa1bb
1 changed files with 73 additions and 10 deletions
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
include("config.php");
|
||||
$API_VERSION = 0.1;
|
||||
$API_VERSION = 0.2;
|
||||
|
||||
function quit()
|
||||
{
|
||||
|
@ -93,12 +93,17 @@ function set_status($con, $name, $status, $type)
|
|||
}
|
||||
$sid = $result->fetch_array()[0];
|
||||
|
||||
// Update tiles in area
|
||||
$sql = "UPDATE tile SET status_id = ? WHERE parent_id = ?";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bind_param("ii", $sid, $pid);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
$sql = 'SELECT * FROM information_schema.tables WHERE table_name = "tile" AND table_schema = "' . $SQL_DATABASE . '"';
|
||||
$ret = $con->query($sql)->fetch_all(MYSQLI_ASSOC);
|
||||
if (!empty($ret))
|
||||
{
|
||||
// Update tiles in area
|
||||
$sql = "UPDATE tile SET status_id = ? WHERE parent_id = ?";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bind_param("ii", $sid, $pid);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -131,8 +136,26 @@ if ($action == "set")
|
|||
}
|
||||
else if ($action == "get-job" && isset($_POST["status"]) && $_POST["status"] != "" && isset($_POST["new-status"]) && $_POST["new-status"] != "")
|
||||
{
|
||||
if (isset($_POST["level"]) && ($_POST["level"] == "tile" || $_POST["level"] == "area"))
|
||||
{
|
||||
$level = $_POST["level"];
|
||||
}
|
||||
else
|
||||
{
|
||||
$level = "tile";
|
||||
}
|
||||
|
||||
if (level == "tile")
|
||||
{
|
||||
$table = "tile";
|
||||
}
|
||||
else
|
||||
{
|
||||
$table = "secondLevel";
|
||||
}
|
||||
|
||||
get_lock($con);
|
||||
$sql = "SELECT id, parent_id FROM tile WHERE status_id = (SELECT id FROM status WHERE name = ?) ORDER BY parent_id LIMIT 1";
|
||||
$sql = "SELECT id, parent_id FROM " + $table + " WHERE status_id = (SELECT id FROM status WHERE name = ?) ORDER BY parent_id LIMIT 1";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bind_param("s", $_POST["status"]);
|
||||
$stmt->execute();
|
||||
|
@ -155,7 +178,7 @@ else if ($action == "get-job" && isset($_POST["status"]) && $_POST["status"] !=
|
|||
{
|
||||
$ret->jobs = [];
|
||||
$ret->jobs[] = $ret->job;
|
||||
$sql = "SELECT id FROM tile WHERE parent_id = ? AND status_id = (SELECT id FROM status WHERE name = ?)";
|
||||
$sql = "SELECT id FROM " + $table + " WHERE parent_id = ? AND status_id = (SELECT id FROM status WHERE name = ?)";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bind_param("ss", $res["parent_id"], $_POST["status"]);
|
||||
$stmt->execute();
|
||||
|
@ -165,7 +188,7 @@ else if ($action == "get-job" && isset($_POST["status"]) && $_POST["status"] !=
|
|||
{
|
||||
while ($row = $result->fetch_array())
|
||||
{
|
||||
set_status($con, $row["id"], $_POST["new-status"], "tile");
|
||||
set_status($con, $row["id"], $_POST["new-status"], $level);
|
||||
$ret->jobs[] = $row["id"];
|
||||
}
|
||||
}
|
||||
|
@ -173,6 +196,46 @@ else if ($action == "get-job" && isset($_POST["status"]) && $_POST["status"] !=
|
|||
}
|
||||
rel_lock($con);
|
||||
}
|
||||
else if ($action == "get-options")
|
||||
{
|
||||
if (isset($_POST['tile']) && $_POST['tile'] != "")
|
||||
{
|
||||
$sql = "SELECT tile_options.priority, option FROM tile_options INNER JOIN options ON tile_options.option_id = options.id where tile_id = (SELECT id FROM tile WHERE name = ?) ORDER BY tile_options.priority";
|
||||
$pattern = "i";
|
||||
$req = $_POST['tile'];
|
||||
}
|
||||
else if (isset($_POST['area']) && $_POST['area'] != "")
|
||||
{
|
||||
$sql = "SELECT secondLevel_options.priority, option FROM secondLevel_options INNER JOIN options ON secondLevel_options.option_id = options.id where tile_id = (SELECT id FROM secondLevel WHERE name = ?) ORDER BY secondLevel_options.priority";
|
||||
$pattern = "s";
|
||||
$req = $_POST['area'];
|
||||
}
|
||||
else
|
||||
{
|
||||
quit();
|
||||
}
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bind_param($pattern, $req);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
if ($result == False)
|
||||
{
|
||||
quit();
|
||||
}
|
||||
$stmt->close();
|
||||
if ($res == Null)
|
||||
{
|
||||
quit();
|
||||
}
|
||||
$ret->options = [];
|
||||
if ($result != False)
|
||||
{
|
||||
while ($row = $result->fetch_array())
|
||||
{
|
||||
$ret->options[] = $row["option"];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($action == "status")
|
||||
{
|
||||
if (isset($_POST['tile']) && $_POST['tile'] != "")
|
||||
|
|
Loading…
Add table
Reference in a new issue