assign("title","Library"); if (isset($_REQUEST['search']) && (trim($_REQUEST['search']) != "")) { // Pass the template some search results $mode = "search"; $search = $_REQUEST['search']; $query = "SELECT * FROM books WHERE (title || ' ' || author || ' ' || keywords) ~* ? ORDER BY title ASC"; $results = $DB->GetAll($query,array($search)); $smarty->assign("results", $results); } elseif (isset($pathlist[$library_index + 1]) && is_numeric($pathlist[$library_index + 1])) { // We're displaying a specific book $mode = "display"; $book_index = intval($pathlist[$library_index + 1]); $results = $DB->GetAll("SELECT * FROM books WHERE id=? LIMIT 1", array($book_index)); $smarty->assign("book", $results[0]); // Edit the path list to make the breadcrumbs tastier $pathlist[$library_index + 1] = $results[0]['title']; $smarty->assign("pathlist", $pathlist); } else { $smarty->assign("randoms", $DB->GetAll("SELECT * FROM books WHERE image_url IS NOT NULL ORDER BY random() LIMIT 5")); } $smarty->assign("mode", $mode); $smarty->assign("search", $search); $output = $smarty->fetch("library.tpl"); $output2 = $smarty->fetch("library-search.tpl"); $smarty->assign("body",$output); $smarty->assign("secondary", $output2); ?>