forked from htmlacademy-php1/1622797-yeticave-14
-
Notifications
You must be signed in to change notification settings - Fork 0
/
all-lots.php
50 lines (38 loc) · 1.22 KB
/
all-lots.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
47
48
49
50
<?php
/**
* @var mysqli $link
* @var mysqli $config
*/
require_once __DIR__ . '/init.php';
$user_name = check_session_name();
$categories = get_categories($link);
$categories_ids = get_categories_ids($categories);
$pagination_limit = $config['pagination_limit'];
$cur_page = intval($_GET['page'] ?? 1);
$category_id = intval($_GET['category']);
$category_id = mysqli_real_escape_string($link, $category_id);
if (!in_array($category_id, $categories_ids)) {
header("Location: /404.php");
}
$lots = get_lot_by_category($link, $category_id, $cur_page, $pagination_limit);
$count_lots = get_count_lot_by_category($link, $category_id);
$page_count = ceil($count_lots / $pagination_limit);
$pages = range(1, $page_count);
if (!in_array($cur_page, $pages)) {
header("Location: /404.php");
}
$content = include_template('all-lots.php', [
'categories' => $categories,
'category_id' => $category_id,
'lots' => $lots,
'pages' => $pages,
'page_count' => $page_count,
'cur_page' => $cur_page
]);
$layout_content = include_template('layout.php', [
'categories' => $categories,
'content' => $content,
'user_name' => $user_name,
'title' => 'Лоты по категориям'
]);
print($layout_content);