forked from htmlacademy-php1/1622797-yeticave-14
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
46 lines (34 loc) · 1.12 KB
/
search.php
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
41
42
43
44
45
46
<?php
/**
* @var mysqli $config
* @var mysqli $link
*/
require_once __DIR__ . '/init.php';
$categories = get_categories($link);
$pagination_limit = $config['pagination_limit'];
$user_name = check_session_name();
$cur_page = intval($_GET['page'] ?? 1);
$search = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_SPECIAL_CHARS);
$search = trim(strip_tags($search));
$search_result = get_lot_by_search($link, $search, $cur_page, $pagination_limit);
$count_lots_from_search = get_count_lots_from_search($link, $search);
$page_count = ceil($count_lots_from_search / $pagination_limit);
$pages = range(1, $page_count);
if (!in_array($cur_page, $pages)) {
header("Location: /404.php");
}
$content = include_template('search.php', [
'categories' => $categories,
'search' => $search,
'search_result' => $search_result,
'cur_page' => $cur_page,
'page_count' => $page_count,
'pages' => $pages
]);
$layout_content = include_template('layout.php', [
'categories' => $categories,
'content' => $content,
'user_name' => $user_name,
'title' => 'Результаты поиска'
]);
print($layout_content);