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 ''; print(''); while ($resultArray = $result->fetchArray(SQLITE3_ASSOC)) { $pdfUrl = 'books/' . $resultArray['nid'] . '/' . $resultArray['nid'] . '.pdf'; $epubUrl = 'books/' . $resultArray['nid'] . '/' . $resultArray['nid'] . '.epub'; $mobiUrl = 'books/' . $resultArray['nid'] . '/' . $resultArray['nid'] . '.mobi'; $codeUrl = ''; if (preg_match('#\d+#', $resultArray['code'], $found)) { $codeId = $found[0]; $codeUrl = 'books/' . $codeId . '/' . $codeId . '.zip'; } $authorsArray = explode('|', $resultArray['author_name']); $authors = []; foreach ($authorsArray as $author) { $authors[] = '' . $author . ''; } printf('', $resultArray['url'], $resultArray['nid'], $resultArray['star'] ? 'on' : 'off', $resultArray['id'], $resultArray['star'] ? '★' : '☆', $resultArray['id'], $resultArray['title'], $resultArray['category_slug'], $resultArray['category'], implode(', ', $authors), $resultArray['datepublished'], $resultArray['numberofpages'], $resultArray['reviewCount'], $resultArray['ratingValue'], is_file($pdfUrl) ? "pdf" : (strlen($resultArray['pdf']) ? 'nie pobrano' : ''), is_file($epubUrl) ? "epub" : (strlen($resultArray['epub']) ? 'nie pobrano' : ''), is_file($mobiUrl) ? "mobi" : (strlen($resultArray['mobi']) ? 'nie pobrano' : ''), is_file($codeUrl) ? "zip" : (strlen($resultArray['code']) ? 'nie pobrano' : '') ); if (isset($chaptersArray) && $chaptersArray != []) { $table = '
nid Title Category Author Publish date Pages Votes Rating Pdf Epub Mobi Code
%d %s %s %s %s %s %s %d %.1f %s %s%s%s
'; foreach ($chaptersArray as $chapter) { $table .= ''; foreach ($chapter['subchapter'] as $subchapter) { $table .= ''; } } $table .= '
' . $chapter['name'] . '
' . $subchapter['name'] . '
'; echo $table; } // if ($resultArray) { // $x = $resultArray; // } } echo '';