forked from LahiruSen/OOSD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacademic_year_submit.php
More file actions
318 lines (217 loc) · 8.25 KB
/
Copy pathacademic_year_submit.php
File metadata and controls
318 lines (217 loc) · 8.25 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<?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['id']))
{
if(isset($_POST['from_date']))
{
if(isset($_POST['to_date']))
{
$from_to = date_withing_validator($_POST['from_date'],$_POST['to_date'],$mysqli,$_POST['id']);
}else
{
$from_to = "Please select a valid date range";
}
}else
{
$from_to = "Please select a valid date range";
}
}
else
{
if(isset($_POST['from_date']))
{
if(isset($_POST['to_date']))
{
$from_to = date_withing_validator($_POST['from_date'],$_POST['to_date'],$mysqli);
}else
{
$from_to = "Please select a valid date range";
}
}else
{
$from_to = "Please select a valid date range";
}
}
if(isset($_POST['from_date'])){$old['from_date'] = $_POST['from_date'];$validation_result[] = array('from_date',$from_to);}else{$validation_result[] = array('from_date',"Please put a valid start date");}
if(isset($_POST['to_date'])){$old['to_date'] = $_POST['to_date'];$validation_result[] = array('to_date',$from_to);}else{$validation_result[] = array('to_date',"Please put a valid start date");}
if(isset($_POST['from_date']))
{
if(isset($_POST['to_date']))
{
if(isset($_POST['registration_deadline']))
{
$from_date = new DateTime($_POST['from_date']);
$to_date = new DateTime($_POST['to_date']);
$registration_deadline = new DateTime($_POST['registration_deadline']);
$val_deadline = deadline_validator($from_date,$to_date,$registration_deadline);
}
else
{
$val_deadline = "Please select a valid deadline";
}
}
else
{
$val_deadline = "To define a valid deadline, academic year end date should be defined first";
}
}
else
{
$val_deadline = "To define a valid deadline, academic year start date should be defined first";
}
if(isset($_POST['registration_deadline'])){$old['registration_deadline'] = $_POST['registration_deadline'];$validation_result[] = array('registration_deadline',$val_deadline);}else{$validation_result[] = array('registration_deadline',"Please put a valid registration deadline");}
if(isset($_POST['status'])){$old['status'] = $_POST['status'];}else{$validation_result[] = array('status',"Please select a valid title");}
$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_ay']))
{
$title = $_POST['title'];
$description = $_POST['description'];
$from_date = $_POST['from_date'];
$to_date = $_POST['to_date'];
$registration_deadline = $_POST['registration_deadline'];
$status = $_POST['status'];
$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 academic_year (title, description, from_date, to_date, registration_deadline, date_of_create,"
." date_of_update,status) "
. "VALUES ('$title','$description','$from_date','$to_date', '$registration_deadline','$date_of_create','$date_of_update',"
."'$status')";
if($mysqli->query($sql))
{
header("location:create_academic_year.php");
}
else
{
$_SESSION['message'] = "Something went wrong!";
header("location:error.php");
}
}
else
{
$title = $_POST['title'];
$description = $_POST['description'];
$from_date = $_POST['from_date'];
$to_date = $_POST['to_date'];
$registration_deadline = $_POST['registration_deadline'];
$status = $_POST['status'];
$date_of_update= $mysqli->escape_string( date("Y-m-d H:i:s"));
$id = $_GET['id'];
$sql_year = "SELECT * FROM academic_year WHERE id='$id'";
$year_result = $mysqli->query($sql_year);
if($year_result->num_rows !=0)
{
$sql = "UPDATE academic_year SET title='$title', description='$description', from_date='$from_date', to_date='$to_date', registration_deadline='$registration_deadline', date_of_update='$date_of_update',"
." status='$status' WHERE id='$id'";
if($mysqli->query($sql))
{
header("location:create_academic_year.php");
}
else
{
$_SESSION['message'] = "Something went wrong!";
header("location:error.php");
}
$year_result->free();
}else
{
$_SESSION['message'] = "This academic year is not available ";
header("location:error.php");
}
}
}
else
{
if(!isset($_POST['create_new_ay']))
{
$id = $_GET['id'];
if((is_int($id) || ctype_digit($id)) && (int)$id > 0)
{
$ay_id = $id;
$selceted_accedemic_years_result = $mysqli->query("select * from academic_year where id='$ay_id'") or die($mysqli->error());
if($selceted_accedemic_years_result->num_rows !=0)
{
$selceted_accedemic_years_data=$selceted_accedemic_years_result->fetch_assoc();
$selceted_accedemic_years_result->free();
if(isset($selceted_accedemic_years_data))
{
$selected = $selceted_accedemic_years_data;
}else
{
header("location: create_academic_year.php");
}
}else
{
header("location: create_academic_year.php");
}
}else
{
header("location: create_academic_year.php");
}
}
}