-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlot.php
More file actions
126 lines (104 loc) · 3.22 KB
/
lot.php
File metadata and controls
126 lines (104 loc) · 3.22 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* @var string $title Заголовок страницы
* @var string[] $categories Список категорий
* @var array<int,array{name: string, category: string, price: int, img: string} $lots Список лотов
*/
declare(strict_types=1);
require_once 'helpers.php';
require_once 'init.php';
require_once 'models/category.php';
require_once 'models/lot.php';
require_once 'models/user.php';
require_once 'models/bet.php';
require_once 'validation.php';
$title = 'Лот';
$categories = get_categories($link);
if (!isset($_GET['id'])) {
$page_content = include_template('404.php', ['categories' => $categories]);
$layout_content = include_template('layout.php', [
'title' => $title,
'categories' => $categories,
'page_content' => $page_content
]);
print($layout_content);
die();
}
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
$lots = get_lot_by_id($link, $id);
if (empty($lots)) {
$page_content = include_template('404.php', ['categories' => $categories]);
$layout_content = include_template('layout.php', [
'title' => $title,
'categories' => $categories,
'page_content' => $page_content
]);
print($layout_content);
die();
}
$user_id = (int)($_SESSION['user']['id'] ?? 0);
$start_price = 0;
$bet_step = 0;
$lot_id = 0;
$user_lot_id = 0;
foreach ($lots as $lot) {
$start_price = $lot['start_price'];
$bet_step = $lot['bet_step'];
$lot_id = $lot['id'];
$user_lot_id = $lot['user_id'];
}
$user_id_last_bet = get_user_by_bet($link, $lot_id);
$count_bets = count_bets($link, $lot_id);
$bets = show_bets($link, $lot_id);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['price'])) {
$price = $_POST['price'];
}
$required = ['price'];
$rules = [
'price' => function ($value) use ($start_price, $bet_step) {
return validate_bet($value, $start_price, $bet_step);
}
];
$form = filter_input_array(INPUT_POST, [
'price' => FILTER_DEFAULT
], true);
$errors = [];
$errors = validate_value($required, $rules, $form, $errors);
if (!count($errors)) {
add_bet($link, $price, $user_id, $lot_id);
update_price($link, $price, $lot_id);
}
$page_content = include_template('lot.php', [
'lots' => $lots,
'form' => $form,
'errors' => $errors,
'user_id' => $user_id,
'user_lot_id' => $user_lot_id,
'user_id_last_bet' => $user_id_last_bet,
'count_bets' => $count_bets,
'bets' => $bets,
'categories' => $categories
]);
$layout_content = include_template('layout.php', [
'title' => $title,
'categories' => $categories,
'page_content' => $page_content
]);
print($layout_content);
}
$page_content = include_template('lot.php', [
'count_bets' => $count_bets,
'bets' => $bets,
'user_id' => $user_id,
'user_lot_id' => $user_lot_id,
'user_id_last_bet' => $user_id_last_bet,
'categories' => $categories,
'lots' => $lots
]);
$layout_content = include_template('layout.php', [
'title' => $title,
'categories' => $categories,
'page_content' => $page_content
]);
print($layout_content);