-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.php
More file actions
72 lines (69 loc) · 2.21 KB
/
add.php
File metadata and controls
72 lines (69 loc) · 2.21 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
<?php
require_once 'helpers.php';
require_once 'core/init.php';
/**
* @var PDO $con
* @var PDO $is_auth
*/
$errors=[];
$cats_ids = array_column($categories,'id');
$lots = $_POST;
$rules = [
'category_id'=>function($value) use ($cats_ids){
return validateCategory($value,$cats_ids);
},
'good_name' => function(){
return error_null_name($_POST['good_name']);
},
'discription' => function(){
return error_null_name($_POST['discription']);
},
'step_price_start' => function(){
return error_null_name($_POST['step_price_start']);
},
'step_price' => function(){
return error_null_name($_POST['step_price']);
},
'close_date' => function(){
return error_null_name($_POST['close_date']);
}
];
$file_rule = function (){
if(!validateImage()){
return "Загрузите картинку в формате jpeg, jpg или png";
}
};
if($_SERVER['REQUEST_METHOD'] == 'POST'){
foreach ($lots as $key => $value){
if(isset($rules[$key])){
$rule = $rules[$key];
$errors[$key] = $rule($value);
}
}
$errors['url_img'] = $file_rule();
}
$errors = array_filter($errors);
if($_SERVER['REQUEST_METHOD'] == 'POST' && empty($errors)){
$file_name = $_FILES['url_img']['name'];
$uniq_url = uniqid();
$lots['url_img'] = 'uploads/'. $uniq_url . $file_name;
move_uploaded_file($_FILES['url_img']['tmp_name'],$lots['url_img']);
$stmt = $con -> prepare('INSERT INTO lots SET good_name=:good_name,
id_category = :id_category,
good_discription = :discription,
url_img = :url_img,
price = :step_price_start,
step_price = :step_price,
close_date = :close_date,
id_user_author = 1,
id_user_win = NULL,
create_date = NOW()');
$stmt->execute($lots);
header("Location:index.php");
}
$goodsObject = $con -> query('SELECT * from lots');
$goods = $goodsObject -> fetchAll();
$addlotsContent = include_template('add_template.php',["categories"=>$categories,'is_Auth'=>$is_auth,'errors'=>$errors]);
$page = include_template('layout.php',['content'=>$addlotsContent,'categories'=>$categories,'is_auth'=>$is_auth, 'user_name'=>$user_name]);
print($page);
?>