-
Notifications
You must be signed in to change notification settings - Fork 1
/
add.php
49 lines (42 loc) · 1.39 KB
/
add.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
<?php
/**
* @var array $lot
* @var array $categories
* @var mysqli $link
* @var array $errors
*/
require_once 'helpers.php';
require_once 'functions.php';
require_once 'init.php';
$categories = get_categories($link);
$errors = [];
$user_id = get_user_id_session();
if ($user_id === null) {
header("Location: /403.php");
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$lot = filter_input_array(INPUT_POST, [
'name' => FILTER_DEFAULT, 'category_id' => FILTER_DEFAULT, 'finished_date' => FILTER_DEFAULT,
'description' => FILTER_DEFAULT, 'img_url' => FILTER_DEFAULT, 'initial_price' => FILTER_DEFAULT, 'bid_step' => FILTER_DEFAULT
], true);
$categories_id = array_column($categories, 'id');
$errors = validate_form_add_lot($lot, $categories_id, $_FILES);
$errors = array_filter($errors);
if (empty($errors)) {
$result = add_lot($link, $lot, $_FILES);
if ($result) {
$lot_id = mysqli_insert_id($link);
header("Location: lot.php?id=" . $lot_id);
} else {
header("Location:/404.php");
}
}
}
$page_content = include_template('add.php', ['categories' => $categories, 'errors' => $errors]);
$layout_content = include_template('layout.php', [
'content' => $page_content,
'categories' => $categories,
'title' => 'Добавление лота',
]);
debug_to_console($errors);
print($layout_content);