-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions_add.php
More file actions
162 lines (131 loc) · 5.04 KB
/
functions_add.php
File metadata and controls
162 lines (131 loc) · 5.04 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/*** add_room_form ***/
function add_room_form(){
global $connection;
global $errors;
check_admin_permissions();
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['add_room']) && !empty($_POST['new_room'])){
$room = mysqli_real_escape_string($connection, htmlspecialchars($_POST['new_room']));
$sql = "INSERT INTO tvari_kodu_rooms (name) VALUES ('".$room."')";
$result = mysqli_query($connection, $sql);
echo $sql;
if ($result && mysqli_insert_id($connection) > 0){
header("Location: ?page=infra");
die();
}
else{
$errors[] = 'Ruumi lisamine ebaõnnestus';
include_once('views/infra_page.php');
die();
}
} else {
header("Location: ?page=infra");
}
}
/*** add_bookcase_form ***/
function add_bookcase_form(){
global $connection;
global $errors;
check_admin_permissions();
if ($_SERVER['REQUEST_METHOD'] == 'POST'
&& !empty($_POST['add_bookcase'])
&& !empty($_POST['new_bookcase'])
&& !empty($_POST['new_bookcase_room_id'])){
$description = mysqli_real_escape_string($connection, htmlspecialchars($_POST['new_bookcase']));
$room = mysqli_real_escape_string($connection, htmlspecialchars($_POST['new_bookcase_room_id']));
$sql = "INSERT INTO tvari_kodu_bookcases (description, room) VALUES ('".$description."', ".$room.")";
$result = mysqli_query($connection, $sql);
if ($result && mysqli_insert_id($connection) > 0){
header("Location: ?page=infra");
die();
}
else{
$errors[] = 'Raamatukapi lisamine ebaõnnestus';
include_once('views/infra_page.php');
die();
}
} else {
header("Location: ?page=infra");
}
}
/*** add_shelf_form ***/
function add_shelf_form(){
global $connection;
global $errors;
check_admin_permissions();
if ($_SERVER['REQUEST_METHOD'] == 'POST'
&& !empty($_POST['add_shelf'])
&& !empty($_POST['new_shelf_bookcase_id'])
&& !empty($_POST['new_shelf_category'])
&& !empty($_POST['new_shelf_nr'])){
$bookcase = mysqli_real_escape_string($connection, htmlspecialchars($_POST['new_shelf_bookcase_id']));
$category = mysqli_real_escape_string($connection, htmlspecialchars($_POST['new_shelf_category']));
$shelf_nr = mysqli_real_escape_string($connection, htmlspecialchars($_POST['new_shelf_nr']));
$sql = "INSERT INTO tvari_kodu_shelves (bookcase, category, shelf_nr) VALUES (".$bookcase.", ".$category.", ".$shelf_nr.")";
$result = mysqli_query($connection, $sql);
if ($result && mysqli_insert_id($connection) > 0){
header("Location: ?page=infra");
die();
}
else{
$errors[] = 'Riiuli lisamine ebaõnnestus';
include_once('views/infra_page.php');
die();
}
} else {
header("Location: ?page=infra");
}
}
/*** add_category_form ***/
function add_category_form(){
global $connection;
global $errors;
check_admin_permissions();
if ($_SERVER['REQUEST_METHOD'] == 'POST'
&& !empty($_POST['add_category'])
&& !empty($_POST['new_category'])
&& !empty($_POST['new_category_system'])
&& !empty($_POST['new_category_color'])){
$category = mysqli_real_escape_string($connection, htmlspecialchars($_POST['new_category']));
$system = mysqli_real_escape_string($connection, htmlspecialchars($_POST['new_category_system']));
$color_id = mysqli_real_escape_string($connection, htmlspecialchars($_POST['new_category_color']));
$sql = "INSERT INTO tvari_kodu_categories (category, system, color_id) VALUES ('".$category."', ".$system.", '".$color_id."')";
$result = mysqli_query($connection, $sql);
if ($result && mysqli_insert_id($connection) > 0){
header("Location: ?page=infra");
die();
}
else{
$errors[] = 'Kategooria lisamine ebaõnnestus';
include_once('views/infra_page.php');
die();
}
} else {
header("Location: ?page=infra");
}
}
/*** add_system_form ***/
function add_system_form(){
global $connection;
global $errors;
check_admin_permissions();
if ($_SERVER['REQUEST_METHOD'] == 'POST'
&& !empty($_POST['add_system'])
&& !empty($_POST['new_system'])){
$description = mysqli_real_escape_string($connection, htmlspecialchars($_POST['new_system']));
$sql = "INSERT INTO tvari_kodu_systems (description) VALUES ('".$description."')";
$result = mysqli_query($connection, $sql);
if ($result && mysqli_insert_id($connection) > 0){
header("Location: ?page=infra");
die();
}
else{
$errors[] = 'Sorteerimiskriteeriumi lisamine ebaõnnestus';
include_once('views/infra_page.php');
die();
}
} else {
header("Location: ?page=infra");
}
}
?>