prepare('SELECT b.*, group_concat(a.name, "|") as author_name, s.id as star FROM book as b LEFT JOIN author_book as ab ON b.id = ab.book_id LEFT JOIN author AS a ON ab.author_id = a.id LEFT JOIN star AS s on s.book_id = b.id WHERE category_slug = :category_slug GROUP BY b.id ');
$stmt->bindValue(':category_slug', $_GET['category'], SQLITE3_TEXT);
} elseif (isset($_GET['search']) && isset($_GET['search_title']) && !empty($_GET['search_title'])) {
$stmt = $db->prepare('SELECT b.*, group_concat(a.name, "|") as author_name, s.id as star FROM book as b LEFT JOIN author_book as ab ON b.id = ab.book_id LEFT JOIN author AS a ON ab.author_id = a.id LEFT JOIN star AS s on s.book_id = b.id WHERE title like :search GROUP BY b.id ');
$stmt->bindValue(':search', '%' . $_GET['search_title'] . '%', SQLITE3_TEXT);
} elseif (isset($_GET['author']) && !empty($_GET['author'])) {
$stmt = $db->prepare('SELECT b.*, group_concat(a.name, "|") as author_name, s.id as star FROM book as b LEFT JOIN author_book as ab ON b.id = ab.book_id LEFT JOIN author AS a ON ab.author_id = a.id LEFT JOIN star AS s on s.book_id = b.id WHERE a.name = :author GROUP BY b.id ');
$stmt->bindValue(':author', $_GET['author'], SQLITE3_TEXT);
} elseif (isset($_GET['book']) && !empty($_GET['book'])) {
$stmt = $db->prepare('SELECT * FROM chapter WHERE book_id = :book');
$stmt->bindValue(':book', $_GET['book'], SQLITE3_INTEGER);
$result = $stmt->execute();
$chaptersArray = [];
while ($chapter = $result->fetchArray(SQLITE3_ASSOC)) {
if (!$chapter['parent_id']) {
$chaptersArray[$chapter['id']] = ['name' => $chapter['name'], 'order' => $chapter['chapter_number'], 'subchapter' => []];
} else {
$chaptersArray[$chapter['parent_id']]['subchapter'][$chapter['chapter_number']] = ['id' => $chapter['id'], 'name' => $chapter['name']];
}
}
$stmt = $db->prepare('SELECT b.*, group_concat(a.name, "|") as author_name, s.id as star FROM book as b LEFT JOIN author_book as ab ON b.id = ab.book_id LEFT JOIN author AS a ON ab.author_id = a.id LEFT JOIN star AS s on s.book_id = b.id WHERE b.id = :book GROUP BY b.id ');
$stmt->bindValue(':book', $_GET['book'], SQLITE3_INTEGER);
} elseif (isset($_GET['star']) && !empty($_GET['star'])) {
$stmt = $db->prepare('SELECT * FROM star WHERE book_id = :book');
$stmt->bindValue(':book', $_GET['star'], SQLITE3_INTEGER);
$result = $stmt->execute();
if ($result->fetchArray(SQLITE3_ASSOC) === false) {
$insertStmt = $db->prepare('INSERT INTO star (book_id, user_id) VALUES (:book_id, :user_id) ');
$insertStmt->bindValue(':book_id', $_GET['star'], SQLITE3_INTEGER);
$insertStmt->bindValue(':user_id', 1, SQLITE3_INTEGER);
$insertStmt->execute();
} else {
$stmt = $db->prepare('DELETE FROM star WHERE book_id = :book');
$stmt->bindValue(':book', $_GET['star'], SQLITE3_INTEGER);
$result = $stmt->execute();
}
if (isset($_SERVER['HTTP_REFERER'])) {
header('Location: ' . $_SERVER['HTTP_REFERER']);
} else {
header('Location: /');
}
} else {
$stmt = $db->prepare('SELECT b.*, group_concat(a.name, "|") as author_name, s.id as star FROM book as b LEFT JOIN author_book as ab ON b.id = ab.book_id LEFT JOIN author AS a ON ab.author_id = a.id LEFT JOIN star AS s on s.book_id = b.id GROUP BY b.id');
}
$result = $stmt->execute();
?>
Clear";
echo '