summaryrefslogtreecommitdiff
path: root/www/search.php
blob: cb72c6aa8c64cfacd1980b7354127a61d1631ce9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace phorkie;
/**
 * Search for a search term
 */
require_once 'www-header.php';

if (!isset($_GET['q']) || $_GET['q'] == '') {
    header('Location: ' . Tools::fullUrl('/list'));
    exit();
}
$query = $_GET['q'];

$page = 0;
if (isset($_GET['page'])) {
    if (!is_numeric($_GET['page'])) {
        throw new Exception_Input('List page is not numeric');
    }
    //PEAR Pager begins at 1
    $page = (int)$_GET['page'] - 1;
}
$perPage = 10;

$db     = new Database();
$search = $db->getSearch();

$sres = $search->search($query, $page, $perPage);

$pager = new Html_Pager(
    $sres->getResults(), $perPage, $page + 1, $sres->getLink($query)
);
render(
    'search',
    array(
        'query' => $query,
        'sres'  => $sres,
        'pager' => $pager
    )
);
?>