forked from lepkelly/3.kodutoo-I-ruhm-1
/
data.php
141 lines (100 loc) · 4.18 KB
/
data.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
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
<?php
require_once("functions.php");
require_once("../config_global.php");
//Kui kasutaja ei ole sisse logitud, suuna teisele lehele
//Kontrollin kas sessiooni muutuja on olemas
if(!isset($_SESSION['logged_in_user_id'])) {
header("Location: register.php");
}
if($_SESSION['logged_in_user_group'] == 1) {
header("Location: noaccess.php");
}
//MUUTUJAD
$job_name = $job_desc = $job_company = $job_county = $job_parish = $job_location = $job_address = "";
$job_name_error = $job_desc_error = $job_company_error = $job_county_error = $job_parish_error = $job_location_error = $job_address_error = "";
$m = "";
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(isset($_POST["add_job"])){
if (empty($_POST["job_name"])) {
$job_name_error = "Ameti nimi on kohustuslik";
} else {
$job_name = cleanInput($_POST["job_name"]);
}
if (empty($_POST["job_desc"])) {
$job_desc_error = "Töö kirjeldus on kohustuslik";
} else {
$job_desc = cleanInput($_POST["job_desc"]);
}
if (empty($_POST["job_company"])) {
$job_company_error = "Asutus on kohustuslik";
} else {
$job_company = cleanInput($_POST["job_company"]);
}
if (empty($_POST["job_county"])) {
$job_county_error = "Maakond on kohustuslik";
} else {
$job_county = cleanInput($_POST["job_county"]);
}
if (empty($_POST["job_parish"])) {
$job_parish_error = "Vald on kohustuslik";
} else {
$job_parish = cleanInput($_POST["job_parish"]);
}
if (empty($_POST["job_location"])) {
$job_location_error = "Asula on kohustuslik";
} else {
$job_location = cleanInput($_POST["job_location"]);
}
if (empty($_POST["job_address"])) {
$job_address_error = "Aadress on kohustuslik";
} else {
$job_address = cleanInput($_POST["job_address"]);
}
//Errorite puudumisel käivitub funktsioon, mis sisestab andmebaasi
if ($job_name_error == "" && $job_desc_error == "" && $job_company_error == "" && $job_county_error == "" && $job_parish_error == "" && $job_location_error == "" && $job_address_error == "") {
//m - message, mis tuleb functions.php failist
$m = createJob($job_name, $job_desc, $job_company, $job_county, $job_parish, $job_location, $job_address);
}
if ($m != "") {
//Vorm tühjaks
$job_name = "";
$job_desc = "";
$job_company = "";
$job_county = "";
$job_parish = "";
$job_location = "";
$job_address = "";
}
}
}
// kirjuta fn
//Küsime tabeli kujul andmed
getAllData();
?>
<?php
//Lehe nimi
$page_title = "Uus töökoht";
//Faili nimi
$page_file = "data.php";
?>
<?php require_once("header.php"); ?>
<h2>Lisa uus töökoht</h2>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" >
<label for="job_name"> Amet </label>
<input id="job_name" name="job_name" type="text" value="<?=$job_name;?>"> <?=$job_name_error;?><br><br>
<label for="job_desc"> Töö kirjeldus </label>
<input id="job_desc" name="job_desc" type="text" value="<?=$job_desc;?>"> <?=$job_desc_error;?><br><br>
<label for="job_company"> Asutus </label>
<input id="job_company" name="job_company" type="text" value="<?=$job_company;?>"> <?=$job_company_error;?><br><br>
<label for="job_county"> Maakond </label>
<input id="job_county" name="job_county" type="text" value="<?=$job_county;?>"> <?=$job_county_error;?><br><br>
<label for="job_parish"> Vald </label>
<input id="job_parish" name="job_parish" type="text" value="<?=$job_parish;?>"> <?=$job_parish_error;?><br><br>
<label for="job_location"> Asula </label>
<input id="job_location" name="job_location" type="text" value="<?=$job_location;?>"> <?=$job_location_error;?><br><br>
<label for="job_address"> Aadress </label>
<input id="job_address" name="job_address" type="text" value="<?=$job_address;?>"> <?=$job_address_error;?><br><br>
<input type="submit" name="add_job" value="Lisa">
<p style="color: green;"><?=$m;?></p>
</form>
<?php require_once("footer.php"); ?>