| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | $library_index = array_search("Library", $pathlist); |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | $mode = "browse"; |
|---|
| 9 | $search = ""; |
|---|
| 10 | $smarty->assign("title","Library"); |
|---|
| 11 | |
|---|
| 12 | if (isset($_REQUEST['search']) && (trim($_REQUEST['search']) != "")) { |
|---|
| 13 | |
|---|
| 14 | $mode = "search"; |
|---|
| 15 | $search = $_REQUEST['search']; |
|---|
| 16 | $query = "SELECT * FROM books WHERE (title || ' ' || author || ' ' || keywords) ~* ? ORDER BY title ASC"; |
|---|
| 17 | $results = $DB->GetAll($query,array($search)); |
|---|
| 18 | $smarty->assign("results", $results); |
|---|
| 19 | } elseif (isset($pathlist[$library_index + 1]) && is_numeric($pathlist[$library_index + 1])) { |
|---|
| 20 | |
|---|
| 21 | $mode = "display"; |
|---|
| 22 | $book_index = intval($pathlist[$library_index + 1]); |
|---|
| 23 | $results = $DB->GetAll("SELECT * FROM books WHERE id=? LIMIT 1", array($book_index)); |
|---|
| 24 | $smarty->assign("book", $results[0]); |
|---|
| 25 | |
|---|
| 26 | $pathlist[$library_index + 1] = $results[0]['title']; |
|---|
| 27 | $smarty->assign("pathlist", $pathlist); |
|---|
| 28 | } else { |
|---|
| 29 | $smarty->assign("randoms", $DB->GetAll("SELECT * FROM books WHERE image_url IS NOT NULL ORDER BY random() LIMIT 5")); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | $smarty->assign("mode", $mode); |
|---|
| 34 | $smarty->assign("search", $search); |
|---|
| 35 | $output = $smarty->fetch("library.tpl"); |
|---|
| 36 | $output2 = $smarty->fetch("library-search.tpl"); |
|---|
| 37 | $smarty->assign("body",$output); |
|---|
| 38 | $smarty->assign("secondary", $output2); |
|---|
| 39 | |
|---|
| 40 | ?> |
|---|