try { check_permission(PERM_ADDER); if (!isset($_POST['sid']) || !isset($_POST['book_id'])) { throw new UnexpectedValueException(); } $sid = $_POST['sid']; $book_id = $_POST['book_id']; sql_begin(); //creating book if necessary if ($book_id == -1) { //find the parent id $res = sql_pe("SELECT book_id, url FROM sources WHERE source_id = (SELECT parent_id FROM sources WHERE source_id=? LIMIT 1) LIMIT 1", array($sid)); if (!isset($_POST['book_name']) || !$res[0]['book_id']) { throw new UnexpectedValueException(); } $book_id = books_add($_POST['book_name'], $res[0]['book_id']); $res = sql_pe("SELECT url FROM sources WHERE source_id=? LIMIT 1", array($sid)); books_add_tag($book_id, 'url:' . $res[0]['url']); download_url($res[0]['url']); } //bind sql_pe("UPDATE sources SET book_id=? WHERE source_id=? LIMIT 1", array($book_id, $sid)); sql_commit(); $res = sql_pe("SELECT book_name FROM books WHERE book_id=? LIMIT 1", array($book_id)); $result['title'] = htmlspecialchars($res[0]['book_name']); $result['book_id'] = $book_id; } catch (Exception $e) { $result['error'] = 1; } log_timing(true); die(json_encode($result));
<?php require 'lib/header.php'; require_once 'lib/lib_history.php'; if (isset($_POST['comment'])) { $comment = $_POST['comment']; } else { $comment = ''; } if (isset($_GET['set_id']) && ($set_id = $_GET['set_id'])) { $r = revert_changeset($set_id, $comment); header("Location:{$r}"); } elseif (isset($_GET['tf_rev']) && ($rev_id = $_GET['tf_rev'])) { revert_token($rev_id); header("Location:history.php"); } elseif (isset($_GET['dict_rev']) && ($rev_id = $_GET['dict_rev'])) { revert_dict($rev_id); header("Location:dict_history.php"); } log_timing();