root/components/library.php @ 97

Revision 97, 1.4 KB (checked in by dez, 7 years ago)

Work on library component (chckens)
Introduces CSS formatting for forms. Fixes #6 (dez)

Line 
1<?php
2
3// this component is a mess. That's cause it's not finished yet :-)
4
5$library_index = array_search("Library", $pathlist);
6
7// Default to browsing, empty search box, generic title
8$mode = "browse";
9$search = "";
10$smarty->assign("title","Library");
11
12if (isset($_REQUEST['search']) && (trim($_REQUEST['search']) != "")) {
13// Pass the template some search results
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// We're displaying a specific book
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    // Edit the path list to make the breadcrumbs tastier
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?>
Note: See TracBrowser for help on using the browser.