Database connection failed.
'; return; } /* * --------------------------------------------------------- * CSS * --------------------------------------------------------- */ echo ''; /* * --------------------------------------------------------- * Get all Bible books * --------------------------------------------------------- */ $stmt = $pdo->query(" SELECT id, book_code, book_name, testament, book_order, chapter_count FROM bible_books ORDER BY book_order ASC "); $books = $stmt->fetchAll(); /* * --------------------------------------------------------- * Selected book * --------------------------------------------------------- */ $selected_book_id = isset($_GET['book']) ? (int) $_GET['book'] : 0; /* * --------------------------------------------------------- * Selected chapter * --------------------------------------------------------- */ $selected_chapter_id = isset($_GET['chapter']) ? (int) $_GET['chapter'] : 0; /* * --------------------------------------------------------- * Get chapters * --------------------------------------------------------- */ $chapters = array(); if ($selected_book_id > 0) { $chapter_stmt = $pdo->prepare(" SELECT id, chapter_number FROM bible_chapters WHERE book_id = ? ORDER BY chapter_number ASC "); $chapter_stmt->execute( array($selected_book_id) ); $chapters = $chapter_stmt->fetchAll(); } /* * --------------------------------------------------------- * Get selected book information * --------------------------------------------------------- */ $selected_book = null; if ($selected_book_id > 0) { $book_stmt = $pdo->prepare(" SELECT id, book_name, testament, book_order, chapter_count FROM bible_books WHERE id = ? LIMIT 1 "); $book_stmt->execute( array($selected_book_id) ); $selected_book = $book_stmt->fetch(); } /* * --------------------------------------------------------- * Get selected chapter information * --------------------------------------------------------- */ $current_chapter_number = 0; if ($selected_chapter_id > 0) { $current_chapter_stmt = $pdo->prepare(" SELECT id, book_id, chapter_number FROM bible_chapters WHERE id = ? LIMIT 1 "); $current_chapter_stmt->execute( array($selected_chapter_id) ); $current_chapter = $current_chapter_stmt->fetch(); if ($current_chapter) { $current_chapter_number = (int) $current_chapter['chapter_number']; /* * Make sure the selected chapter belongs * to the selected book. */ if ( (int) $current_chapter['book_id'] !== $selected_book_id ) { $selected_chapter_id = 0; $current_chapter_number = 0; } } } /* * --------------------------------------------------------- * Find previous and next chapters * --------------------------------------------------------- */ $previous_chapter = null; $next_chapter = null; if ( $selected_book_id > 0 && $selected_chapter_id > 0 ) { $previous_stmt = $pdo->prepare(" SELECT id, chapter_number FROM bible_chapters WHERE book_id = ? AND chapter_number < ? ORDER BY chapter_number DESC LIMIT 1 "); $previous_stmt->execute(array( $selected_book_id, $current_chapter_number )); $previous_chapter = $previous_stmt->fetch(); $next_stmt = $pdo->prepare(" SELECT id, chapter_number FROM bible_chapters WHERE book_id = ? AND chapter_number > ? ORDER BY chapter_number ASC LIMIT 1 "); $next_stmt->execute(array( $selected_book_id, $current_chapter_number )); $next_chapter = $next_stmt->fetch(); } /* * --------------------------------------------------------- * Get verses * --------------------------------------------------------- */ $verses = array(); if ($selected_chapter_id > 0) { $verse_stmt = $pdo->prepare(" SELECT id, verse_start, verse_end, verse_text, source_id, source_page, source_status, validation_status FROM bible_verses WHERE chapter_id = ? ORDER BY verse_start ASC "); $verse_stmt->execute( array($selected_chapter_id) ); $verses = $verse_stmt->fetchAll(); } /* * --------------------------------------------------------- * Bible Reader * --------------------------------------------------------- */ echo 'Select Book:
'; echo ''; /* * --------------------------------------------------------- * CHAPTER SELECTOR * --------------------------------------------------------- */ if ($selected_book_id > 0) { echo 'Select Chapter:
'; echo ''; /* * --------------------------------------------------------- * CHAPTER BUTTONS * --------------------------------------------------------- */ echo ''; } /* * --------------------------------------------------------- * BOOK / CHAPTER HEADER * --------------------------------------------------------- */ if ( $selected_book && $selected_chapter_id > 0 && $current_chapter_number > 0 ) { echo 'No verses found for this chapter.
'; } else { foreach ($verses as $verse) { echo '