forked from LahiruSen/OOSD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacademic_level_submit.php
More file actions
265 lines (174 loc) · 7.53 KB
/
Copy pathacademic_level_submit.php
File metadata and controls
265 lines (174 loc) · 7.53 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
/**
* Created by PhpStorm.
* User: BlackLion
* Date: 4/6/2018
* Time: 8:19 AM
*/
require 'validator.php';
require 'db.php';
if (session_status() == PHP_SESSION_NONE) { session_start();}
// CHECK THERE IS A LOGNG[SESSION VARIABLE WERE ONLY CREATED DURING LOGIN] &&&& CHECK USER TYPE = ADMINISTRATOR
if(isset($_SESSION['email']))
{
$email = $_SESSION['email'];
$user_id = $_SESSION['user_id']; $current_employee_type_result = $mysqli->query("select DISTINCT employee_types.title,employee_types.id from employee_types, users, employee_data where employee_data.user_id = '$user_id' and employee_types.id = employee_data.employee_type_id") or die($mysqli->error());
if($current_employee_type_result->num_rows !=0)
{
$current_employee_type_data = $current_employee_type_result->fetch_assoc();
$current_employee_type_result->free();
$type_of_employment = $current_employee_type_data['title'];
}
else
{
$_SESSION['message'] = "Not a valid email address";
header("location:error.php");
}
if(isset($type_of_employment))
{
if($type_of_employment != 'Administrator')
{
$_SESSION['message'] = "This is invalid submission";
header("location:error.php");
}
if($_SESSION['two_step'] == 0)
{
$_SESSION['message'] = "You are not completed 2nd step of registration";
header("location:error.php");
}
}else
{
$_SESSION['message'] = "Something went wrong";
header("location:error.php");
}
}else
{
$_SESSION['message'] = "This session has expired. Please login again!!!";
header("location:error.php");
}
/*
academic year
*/
//Defining validation check and old variable arrays
$old = array();
$validation_result = array();
if(isset($_POST['title'])){$old['title'] = $_POST['title'];}else{$validation_result[] = array('title',"Please put a valid title");}
if(isset($_POST['description'])){$old['description'] = $_POST['description'];}else{$validation_result[] = array('description',"Please put a valid description");}
if(isset($_POST['deadline'])){$old['deadline'] = $_POST['deadline']; if(isset($_POST['academic_year_id'])){ $ayv = academic_year_for_level_validator($_POST['academic_year_id'],$mysqli); if($ayv[0] =='Y') {$from_date = new DateTime($ayv[1]['from_date']);$to_date = new DateTime($ayv[1]['to_date']);$deadline = new DateTime($_POST['deadline']);$validation_result[] = array('deadline',deadline_validator($from_date,$to_date,$deadline));}}else{$validation_result[] = array('deadline',"Should have an associative valid academic year");}}else{$validation_result[] = array('deadline',"Please put a valid deadline");}
if(isset($_POST['academic_year_id'])){$old['academic_year_id'] = $_POST['academic_year_id'];$validation_result[] = array('academic_year_id',academic_year_for_level_validator($_POST['academic_year_id'],$mysqli)[0]);}else{$validation_result[] = array('academic_year_id',"Please put a valid academic year");}
if(isset($_GET['id'])) {
if (isset($_POST['type']) && isset($_POST['academic_year_id'])) {
$old['type'] = $_POST['type'];
$validation_result[] = array('type', academic_level_type_validator($_POST['academic_year_id'],$_POST['type'],$_GET['id'], $mysqli));
} else {
$validation_result[] = array('type', "Please put a valid academic year or select a type[academic year is required to define type]");
}
}else
{
if (isset($_POST['type']) && isset($_POST['academic_year_id'])) {
$old['type'] = $_POST['type'];
$validation_result[] = array('type', academic_level_type_validator($_POST['academic_year_id'],$_POST['type'],0, $mysqli));
} else {
$validation_result[] = array('type', "Please put a valid academic year or select a type[academic year is required to define type]");
}
}
$error_counter = 0;
$error_array = array();
for($i=0;$i< sizeof($validation_result);$i++)
{
if($validation_result[$i][1] != 'Y')
{
$error_counter++;
$error_array[$validation_result[$i][0]] = $validation_result[$i][1];
}
}
if($error_counter == 0)
{
if(isset($_POST['create_new_al']))
{
$title = $_POST['title'];
$description = $_POST['description'];
$deadline = $_POST['deadline'];
$type = $_POST['type'];
$academic_year_id = $_POST['academic_year_id'];
$date_of_create= $mysqli->escape_string( date("Y-m-d H:i:s"));
$date_of_update= $mysqli->escape_string( date("Y-m-d H:i:s"));
//insert query
$sql = "INSERT INTO level (title, description, deadline, academic_year_id, date_of_create,"
." date_of_update,type) "
. "VALUES ('$title','$description','$deadline',$academic_year_id,'$date_of_create','$date_of_update','$type')";
if($mysqli->query($sql))
{
header("location:create_academic_level.php");
}
else
{
$_SESSION['message'] = "Something went wrong!";
header("location:error.php");
}
}
else
{
$title = $_POST['title'];
$description = $_POST['description'];
$deadline = $_POST['deadline'];
$type = $_POST['type'];
$academic_year_id = $_POST['academic_year_id'];
$date_of_update= $mysqli->escape_string( date("Y-m-d H:i:s"));
$id = $_GET['id'];
$sql_level = "SELECT * FROM level WHERE id='$id'";
$level_result = $mysqli->query($sql_level);
if($level_result->num_rows !=0)
{
$sql = "UPDATE level SET title='$title', description='$description', deadline='$deadline', academic_year_id='$academic_year_id', date_of_update='$date_of_update',type='$type'"
." WHERE id='$id'";
if($mysqli->query($sql))
{
header("location:create_academic_level.php");
}
else
{
$_SESSION['message'] = "Something went wrong!";
header("location:error.php");
}
$level_result->free();
}else
{
$_SESSION['message'] = "This academic year is not available ";
header("location:error.php");
}
}
}else
{
if(!isset($_POST['create_new_al'])) {
$id = $_GET['id'];
if((is_int($id) || ctype_digit($id)) && (int)$id > 0)
{
$level_id = $id;
$selceted_accedemic_level_result = $mysqli->query("select * from level where id='$level_id'") or die($mysqli->error());
if($selceted_accedemic_level_result->num_rows !=0)
{
$selceted_accedemic_level_data=$selceted_accedemic_level_result->fetch_assoc();
$selceted_accedemic_level_result->free();
if(isset($selceted_accedemic_level_data))
{
$selected = $selceted_accedemic_level_data;
}else
{
header("location: create_academic_level.php");
}
}else
{
header("location: create_academic_level.php");
}
}else
{
header("location: create_academic_level.php");
}
}else
{
$_SESSION['message'] = "No valid submission";
header("location:error.php");
//should set error in here
}
}