$sqlite = new SQLite3($db_str, SQLITE3_OPEN_READWRITE); $id = intval($_POST["id"]); $name = $_POST["name"]; $container = is_numeric($_POST["container"]) && intval($_POST["container"]) > 0 ? intval($_POST["container"]) : null; $position = is_numeric($_POST["position"]) && intval($_POST["position"]) > 0 ? intval($_POST["position"]) : 1; $section = findSectionById($id); if ($section !== false && sectionExists($container) && hack($container, $position, $section)) { $update = $sqlite->prepare("update sections set s_name=:name,s_container=:container,s_position=:position,s_updated=current_timestamp where s_id=:id"); $update->bindValue("name", $name, SQLITE3_TEXT); $update->bindValue("container", $container, SQLITE3_INTEGER); $update->bindValue("position", $position, SQLITE3_INTEGER); $update->bindValue("id", $id, SQLITE3_INTEGER); if ($update->execute() !== false) { $source = true; if ($section["container"] !== $container) { $source = sortSection($section["container"]); } $result = ["update" => $section, "success" => true, "message" => date("Y-m-d H:i:s"), "target" => findSectionById($id), "anchor" => "s{$id}"]; if (!$source) { $result["warning"] = "Section " . $section["container"] . " is corrupted"; } } else { $result = ["update" => $section, "success" => false, "message" => "Unable to execute query", "target" => ["name" => $name, "container" => $container, "position" => $position]]; } $update->close(); } else { if ($section === false) { $message = "Identifier {$id} not found"; } else { $message = "Container {$container} not found or not accesible"; }
require "../includes/include.php"; if (is_numeric($_POST["id"]) && intval($_POST["id"]) > 0) { $sqlite = new SQLite3($db_str, SQLITE3_OPEN_READWRITE); $id = intval($_POST["id"]); $section = findSectionById($id); $container = null; if ($section !== false) { $container = $section["container"]; } $changes = 0; $success = false; if ($sqlite->exec("pragma foreign_keys = on")) { $delete = $sqlite->prepare("delete from sections where s_id=:id"); $delete->bindValue("id", $id, SQLITE3_INTEGER); $success = $delete->execute() !== false; $changes = $sqlite->changes(); } else { $success = deleteSection($id); } if ($success) { sortSection($container); $message = date("Y-m-d H:i:s"); } else { $message = "Unable to delete some links or sections"; } $result = ["delete" => $section, "success" => $success, "message" => $message, "changes" => $changes, "anchor" => "s" . ($container != null ? $container : "null")]; $sqlite->close(); } else { $result = ["delete" => $_POST["id"], "success" => false, "message" => "Bad request", "changes" => 0]; } print json_encode($result);