-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadd.php
More file actions
58 lines (47 loc) · 1.31 KB
/
add.php
File metadata and controls
58 lines (47 loc) · 1.31 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
<?php
/** @var string $userName */
/** @var bool $isAuth */
require_once __DIR__ . '/init.php';
/** @var mysqli $dbConnection */
if (!$dbConnection) {
exit('Не удалось подключиться к базе данных');
}
$categories = getCategories($dbConnection);
if (!$categories) {
exit('Не удалось получить категории товаров');
}
$formData = [];
$fileData = [];
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// получаем данные
$formData = $_POST;
$fileData = $_FILES;
$errors = validateFormAddLot($formData, $fileData);
$file = uploadFile($fileData['lot-img']);
if (empty($errors) && $file !== false) {
$formData['lot-img'] = $file;
$formData['author'] = 1;
$id = addLot($dbConnection, $formData);
header("Location: /lot.php?id=$id");
}
}
$content = includeTemplate('add-lot.php',
[
'categories' => $categories,
'formData' => $formData,
'fileData' => $fileData,
'errors' => $errors,
]
);
$layout = includeTemplate('layout.php',
[
'title' => 'Главная',
'userName' => $userName,
'isAuth' => $isAuth,
'content' => $content,
'categories' => $categories,
'cssClass' => '',
]
);
print($layout);