-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
468 lines (369 loc) · 25.1 KB
/
index.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
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>ISEPS</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body style="background-color: #d3fff8;">
<?php
session_start();
require "constants.php";
require DIR_CORE . "/database_connection.php";
if(@$_SESSION["language"] !== "english" &&
@$_SESSION["language"] !== "serbianCyrilic"
&& @$_SESSION["language"] !== "serbianLatin")
$_SESSION["language"] = "serbianCyrilic";
else if(isset($_GET["language"])) @$_SESSION["language"] = $_GET["language"];
$xml = @simplexml_load_file(DIR_LANGUAGES . "/{$_SESSION["language"]}.xml") or die(file_get_contents("error404.html"));
if($_SESSION["loggedInAs"] !== "admin" && $_SESSION["loggedInAs"] !== "professor"
&& $_SESSION["loggedInAs"] !== "assistant") {
$_SESSION["page"] = "login";
$_SESSION["loggedInAs"] = null;
}
if(@$_GET["page"] !== null) $_SESSION["page"] = $_GET["page"];
else header("Location:index.php?language={$_SESSION["language"]}&page={$_SESSION["page"]}", true, 307);
echo initiateHeader($xml);
if($_SESSION["loggedInAs"] === "professor"){
switch($_SESSION["page"]){
case "teaching_subject_management": echo initiateProfessorPage1($xml, $conn); break;
case "add_new_subject": echo initiateProfessorPage2($xml, $conn); break;
case "professor_reports": echo initiateProfessorPage3($xml, $conn); break;
default: echo file_get_contents("error404.html"); break;
}
}
else if($_SESSION["loggedInAs"] === "assistant"){
switch($_SESSION["page"]){
case "teaching_exercises": echo initiateAssistantPage1($xml, $conn); break;
case "exercises_reports": echo initiateAssistantPage2($xml, $conn); break;
default: echo file_get_contents("error404.html"); break;
}
}
else if($_SESSION["loggedInAs"] === "admin"){
switch($_SESSION["page"]){
case "staff_registration": echo initiateAdminPage1($xml); break;
case "staff_management": echo initiateAdminPage2($xml, $conn); break;
case "students_management": echo initiateAdminPage3($xml, $conn); break;
case "admin_reports": echo initiateAdminPage4($xml, $conn); break;
default: echo file_get_contents("error404.html"); break;
}
}
else {
switch(@$_SESSION["page"]){
case "login": echo initiateLoginPage($xml); break;
case "admin_access": echo initiateAdminAccessPage($xml, $conn); break;
default: echo file_get_contents("error404.html"); break;
}
}
echo initiateFooter($xml);
?>
</body>
</html>
<?php
function initiateHeader($xml){
$header = file_get_contents(DIR_TEMPLATES . "/header.html");
$links = "";
$pageName = "";
$linkID = 1;
$logoutHref = DIR_CORE . '/logout.php';
if($_SESSION["loggedInAs"] === null)
$pageName = "home";
else {
$pageName = $_SESSION["loggedInAs"];
$links .= "<a class='navbar-brand mr-2 mr-md-2' style='font-size: 25px !important; margin-top: 0.8em; color: red;'
href={$logoutHref} class=''>". $_SESSION['loggedInUser'] . "</a>";
}
do {
$links .= "
<a class='navbar-brand mr-2 mr-md-2'
style='font-size: 25px !important; margin-top: 0.8em;'
href='index.php?language={$_SESSION["language"]}&page={$xml->navigation->{$pageName . "Page"}->{"link" . $linkID}->href[0]}'>
{$xml->navigation->{$pageName . "Page"}->{"link" . $linkID}->name[0]}</a>
";
$linkID++;
} while(isset($xml->navigation->{$pageName . "Page"}->{"link" . $linkID}));
$header = str_replace("{IMAGE_SRC}", DIR_MISCELLANEOUS . "/logo.png", $header);
$header = str_replace("{LINKS}", $links, $header);
return $header;
}
function initiateAdminAccessPage($xml, $conn){
if(@$_SESSION["isAdminLoggedOut"]){
$_SERVER["PHP_AUTH_USER"] = null;
$_SERVER["PHP_AUTH_PW"] = null;
$_SESSION["isAdminLoggedOut"] = false;
}
authenticateAdmin($xml,$conn);
}
function initiateLoginPage($xml){
$page_context = file_get_contents(DIR_TEMPLATES . "/#.html");
$page_context = str_replace("{FORM_ACTION}", DIR_CORE . "/#.php", $page_context);
$page_context = str_replace("{IMAGE_SRC}", DIR_CORE . "/captcha.php", $page_context);
$page_context = str_replace("{HEADER_TITLE}",$xml->loginPage->headerTitle[0], $page_context);
$page_context = str_replace("{id}",$xml->loginPage->id[0], $page_context);
$page_context = str_replace("{password}",$xml->registrationPage->password[0], $page_context);
$page_context = str_replace("{admin}",$xml->loginPage->admin[0], $page_context);
$page_context = str_replace("{professor}",$xml->registrationPage->professor[0], $page_context);
$page_context = str_replace("{assistant}",$xml->registrationPage->assistant[0], $page_context);
$page_context = str_replace("{captcha}",$xml->registrationPage->captcha[0], $page_context);
$page_context = str_replace("{LOGIN}",$xml->loginPage->login[0], $page_context);
$page_context = str_replace("{RESET}",$xml->registrationPage->reset[0], $page_context);
return $page_context;
}
function initiateProfessorPage1($xml,$conn){
$page_context = file_get_contents(DIR_TEMPLATES . "/teachingSubjectsManagement.html");
$page_context = str_replace("{FORM_ACTION}", DIR_CORE . "/teaching_subjects_managment.php", $page_context);
$page_context = str_replace("{ASSISTENT_TITLE}",$xml->registrationPage->assistant[0], $page_context);
$page_context = str_replace("{SUBJECT_TITLE}",explode("(",$xml->professorPage->subject_name[0])[0], $page_context);
$tBody = "";
$query = sprintf("SELECT subject_id, title, titleEnglish, staff.name_surname as assistant_name_surname, is_inactive FROM `subject`
LEFT JOIN staff ON `subject`.assistant_id = staff.staff_id
WHERE professor_id = '%s';", mysqli_real_escape_string($conn,$_SESSION['loggedInId']));
$data = $conn->query($query);
while($subject = $data->fetch_assoc()){
$subjectName = $_SESSION["language"] === "english" ? $subject["titleEnglish"] : $subject["title"];
$startYearButton = "<input type='submit' id='startSY_{$subject['subject_id']}' name='startSY_{$subject['subject_id']}'class='btn btn-success' value='{$xml->professorPage->startSYBtn[0]}'></input>";
$endYearButton = "<input type='submit' id='endSY_{$subject['subject_id']}' name='endSY_{$subject['subject_id']}'class='btn btn-danger' value='{$xml->professorPage->endSYBtn[0]}'></input>";
$sYInput = $subject["is_inactive"] === '1' ? $startYearButton : $endYearButton;
$tBody .= "
<tr id='tr_{$subject['subject_id']}'>
<td>{$subject["assistant_name_surname"]}</td>
<td>$subjectName</td>
<td>
<input type='submit' id='lectures_{$subject['subject_id']}' name='lectures_{$subject['subject_id']}' class='btn btn-primary' value='{$xml->professorPage->lecturesBtn[0]}'></input>
<input type='submit' id='details_{$subject['subject_id']}' name='details_{$subject['subject_id']}' class='btn btn-info' value='{$xml->professorPage->detailsBtn[0]}'></input>
{$sYInput}
</td>
</tr>
";
}
$page_context = str_replace("{tBody}",$tBody, $page_context);
return $page_context;
}
function initiateProfessorPage2($xml,$conn){
$page_context = file_get_contents(DIR_TEMPLATES . "/addNewSubject.html");
$page_context = str_replace("{FORM_ACTION}", DIR_CORE . "/addNewSubject.php", $page_context);
$page_context = str_replace("{SUBJECT_NAME_TITLE}",$xml->professorPage->subject_name[0], $page_context);
$page_context = str_replace("{ASSISTANT_SELECTION_TITLE}",$xml->professorPage->assistant_selection[0], $page_context);
$assistants = "<option value=''>-</option>";
$studies = "";
$data = $conn->query("SELECT name_surname, staff_id FROM staff WHERE role = 'assistant';");
while($assistant = $data->fetch_assoc()){
$assistants .= "
<option value='{$assistant["staff_id"]}'>{$assistant["name_surname"]}</option>
";
}
$titleLanguage = $_SESSION["language"] === "english" ? "titleEnglish" : "title";
$data = $conn->query("SELECT $titleLanguage, taughtIn, study_id FROM study;");
$numberOfStudies = 0;
while($study = $data->fetch_assoc()){
for($i = 1; $i < 5; $i++){
if($_SESSION["language"] === "english")
$localization = $study["taughtIn"] === "srpski" ? "Serbian language" : "English language";
else
$localization = $study["taughtIn"] === "srpski" ? "Српски језик" : "Енглески језик";
$formatedValue = $study["study_id"] . '_' . $i;
$formatedName = $study["$titleLanguage"] . " - " . $localization . " ($i)";
$studies .= "
<option value='{$formatedValue}'>{$formatedName}</option>
";
$numberOfStudies++;
}
}
$page_context = str_replace("{ASSISTANT_SELECTION_VALUES}",$assistants, $page_context);
$page_context = str_replace("{STUDY_TITLE}",$xml->professorPage->study[0], $page_context);
$page_context = str_replace("{STUDY_SIZE}",$numberOfStudies, $page_context);
$page_context = str_replace("{STUDY_VALUES}",$studies, $page_context);
$page_context = str_replace("{ADD_NEW_SUBJECT}",$xml->professorPage->add_new_subject[0], $page_context);
$page_context = str_replace("{RESET}",$xml->registrationPage->reset[0], $page_context);
return $page_context;
}
function initiateProfessorPage3($xml,$conn){
$page_context = file_get_contents(DIR_TEMPLATES . "/professorReports.html");
$page_context = str_replace("{LABEL_SUBJECTS}",$xml->professorPage->selectSubject[0], $page_context);
$page_context = str_replace("{FORM_ACTION}",DIR_CORE . "/getGraphs.php", $page_context);
$page_context = str_replace("{AJAX_URL}",DIR_CORE . "/getSubjectInfo.php", $page_context);
$page_context = str_replace("{GENERATE_BAR_GRAPH}",$xml->professorPage->generateBGraph[0], $page_context);
$page_context = str_replace("{GENERATE_PIE_GRAPH}",$xml->professorPage->generatePGraph[0], $page_context);
$page_context = str_replace("{RESET}",$xml->registrationPage->reset[0], $page_context);
$subjects = "<option value=''>-</option>";
$query = $query = sprintf("SELECT subject_id FROM subject WHERE professor_id = '%s'"
,mysqli_real_escape_string($conn,$_SESSION['loggedInId']));
$data = $conn->query($query) or die(file_get_contents("error404.html"));
while($subject_id = $data->fetch_assoc()){
$subjects .= "<option value='{$subject_id["subject_id"]}'>ID: {$subject_id["subject_id"]}</option>";
}
$page_context = str_replace("{SUBJECTS}",$subjects, $page_context);
return $page_context;
}
function initiateAssistantPage1($xml,$conn){
$page_context = file_get_contents(DIR_TEMPLATES . "/teachingExercises.html");
$page_context = str_replace("{FORM_ACTION}", DIR_CORE . "/teaching_exercises.php", $page_context);
$page_context = str_replace("{PROFESSOR_TITLE}",$xml->registrationPage->professor[0], $page_context);
$page_context = str_replace("{SUBJECT_TITLE}",explode("(",$xml->professorPage->subject_name[0])[0], $page_context);
$tBody = "";
$query = sprintf("SELECT subject_id, title, titleEnglish, staff.name_surname as professor_name_surname FROM `subject`
INNER JOIN staff ON `subject`.professor_id = staff.staff_id
WHERE assistant_id = '%s';", mysqli_real_escape_string($conn,$_SESSION['loggedInId']));
$data = $conn->query($query);
while($subject = $data->fetch_assoc()){
$subjectName = $_SESSION["language"] === "english" ? $subject["titleEnglish"] : $subject["title"];
$tBody .= "
<tr id='tr_{$subject['subject_id']}'>
<td>{$subject["professor_name_surname"]}</td>
<td>$subjectName</td>
<td>
<input type='submit' id='exercises_{$subject['subject_id']}' name='exercises_{$subject['subject_id']}' class='btn btn-primary' value='{$xml->assistantPage->exercisesBtn[0]}'></input>
<input type='submit' id='details_{$subject['subject_id']}' name='details_{$subject['subject_id']}' class='btn btn-info' value='{$xml->professorPage->detailsBtn[0]}'></input>
</td>
</tr>
";
}
$page_context = str_replace("{tBody}",$tBody, $page_context);
return $page_context;
}
function initiateAssistantPage2($xml, $conn){
$page_context = file_get_contents(DIR_TEMPLATES . "/assistantReports.html");
$page_context = str_replace("{LABEL_SUBJECTS}",$xml->professorPage->selectSubject[0], $page_context);
$page_context = str_replace("{FORM_ACTION}",DIR_CORE . "/getGraphs.php", $page_context);
$page_context = str_replace("{AJAX_URL}",DIR_CORE . "/getSubjectInfo.php", $page_context);
$page_context = str_replace("{GENERATE_BAR_GRAPH}",$xml->professorPage->generateBGraph[0], $page_context);
$page_context = str_replace("{RESET}",$xml->registrationPage->reset[0], $page_context);
$subjects = "<option value=''>-</option>";
$query = $query = sprintf("SELECT subject_id FROM subject WHERE assistant_id = '%s'"
,mysqli_real_escape_string($conn,$_SESSION['loggedInId']));
$data = $conn->query($query) or die(file_get_contents("error404.html"));
while($subject_id = $data->fetch_assoc()){
$subjects .= "<option value='{$subject_id["subject_id"]}'>ID: {$subject_id["subject_id"]}</option>";
}
$page_context = str_replace("{SUBJECTS}",$subjects, $page_context);
return $page_context;
}
function initiateAdminPage1($xml){
$page_context = file_get_contents(DIR_TEMPLATES . "/registration.html");
$page_context = str_replace("{FORM_ACTION}", DIR_CORE . "/register.php", $page_context);
$page_context = str_replace("{IMAGE_SRC}", DIR_CORE . "/captcha.php", $page_context);
$page_context = str_replace("{HEADER_TITLE}",$xml->registrationPage->headerTitle[0], $page_context);
$page_context = str_replace("{nameSurname}",$xml->registrationPage->nameSurname[0], $page_context);
$page_context = str_replace("{email}",$xml->registrationPage->email[0], $page_context);
$page_context = str_replace("{password}",$xml->registrationPage->password[0], $page_context);
$page_context = str_replace("{passwordConfirm}",$xml->registrationPage->passwordConfirm[0], $page_context);
$page_context = str_replace("{professor}",$xml->registrationPage->professor[0], $page_context);
$page_context = str_replace("{assistant}",$xml->registrationPage->assistant[0], $page_context);
$page_context = str_replace("{captcha}",$xml->registrationPage->captcha[0], $page_context);
$page_context = str_replace("{REGISTER}",$xml->registrationPage->register[0], $page_context);
$page_context = str_replace("{RESET}",$xml->registrationPage->reset[0], $page_context);
$page_context = str_replace("{CSV_MESSAGE}",$xml->registrationPage->csvMessage[0], $page_context);
return $page_context;
}
function initiateAdminPage2($xml,$conn){
$page_context = file_get_contents(DIR_TEMPLATES . "/staffManagement.html");
$page_context = str_replace("{FORM_ACTION}", DIR_CORE . "/staff_managment.php", $page_context);
$page_context = str_replace("{NS_TITLE}",$xml->registrationPage->nameSurname[0], $page_context);
$page_context = str_replace("{EMAIL_TITLE}",$xml->registrationPage->email[0], $page_context);
$page_context = str_replace("{PASSWORD_TITLE}",$xml->adminPage->passwordTitle[0], $page_context);
$page_context = str_replace("{ROLE_TITLE}",$xml->adminPage->roleTitle[0], $page_context);
$tBody = "";
$data = $conn->query("SELECT * FROM staff WHERE NOT staff_id = 1"); //not showing admin data
while($staff_member = $data->fetch_assoc()){
$email = explode("@",$staff_member["email"])[0];
$tBody .= "
<tr>
<td><input type='text' id='newNS_{$staff_member['staff_id']}' name='newNS_{$staff_member['staff_id']}' placeholder='{$staff_member['name_surname']}'></td>
<td><input type='text' id='newUE_{$staff_member['staff_id']}' name='newUE_{$staff_member['staff_id']}' placeholder='{$email}'></input>@universityMail.rs</td>
<td><input type='password' id='newPASS_{$staff_member['staff_id']}' name='newPASS_{$staff_member['staff_id']}' placeholder='********'></input></td>
<td><input type='text' id='oldRole_{$staff_member['staff_id']}' name='oldRole_{$staff_member["staff_id"]}' value='{$staff_member["role"]}' readonly></input></td>
<td>
<input type='submit' id='switchRole_{$staff_member['staff_id']}' name='switchRole_{$staff_member['staff_id']}' class='btn btn-info' value='{$xml->adminPage->switchRoleBtn[0]}'></input>
<input type='submit' id='edit_{$staff_member['staff_id']}' name='edit_{$staff_member['staff_id']}' class='btn btn-warning' value='{$xml->adminPage->editBtn[0]}'></input>
<input type='submit' id='delete_{$staff_member['staff_id']}' name='delete_{$staff_member['staff_id']}'class='btn btn-danger' value='{$xml->adminPage->deleteBtn[0]}'></input>
</td>
</tr>
";
}
$page_context = str_replace("{tBody}",$tBody, $page_context);
return $page_context;
}
function initiateAdminPage3($xml, $conn){
$page_context = file_get_contents(DIR_TEMPLATES . "/studentsManagment.html");
$page_context = str_replace("{FORM_ACTION}", DIR_CORE . "/students_managment.php", $page_context);
$page_context = str_replace("{NS_TITLE}",$xml->registrationPage->nameSurname[0], $page_context);
$page_context = str_replace("{INDEX_NO}",$xml->adminPage->indexNumber[0], $page_context);
$page_context = str_replace("{PASSWORD_TITLE}",$xml->adminPage->passwordTitle[0], $page_context);
$page_context = str_replace("{EMAIL_TITLE}",$xml->registrationPage->email[0], $page_context);
$page_context = str_replace("{FACULTY_TITLE - STUDY_TITLE(YEAR)}",$xml->adminPage->facultySY[0], $page_context);
$tBody = "";
$data = $conn->query("SELECT * FROM student");
while($student = $data->fetch_assoc()){
$email = explode("@",$student["studentEmail"])[0];
$studentEnrollment_temp = getEnrollment($student['student_id'], $conn);
$studentEnrollment = explode("-",$studentEnrollment_temp)[0] . "<br>" . explode("-",$studentEnrollment_temp)[1];
$tBody .= "
<tr>
<td><input type='text' id='newNS_{$student['student_id']}' name='newNS_{$student['student_id']}' placeholder='{$student['name_surname']}'></td>
<td><input type='text' id='newIX_{$student['student_id']}' name='newIX_{$student['student_id']}' placeholder='{$student['indexNo']}'></td>
<td><input type='password' id='newPASS_{$student['student_id']}' name='newPASS_{$student['student_id']}' placeholder='********'></input></td>
<td><input type='text' id='newUE_{$student['student_id']}' name='newUE_{$student['student_id']}' placeholder='{$email}'></input>@universityMail.rs</td>
<td>$studentEnrollment</td>
<td>
<input type='submit' id='edit_{$student['student_id']}' name='edit_{$student['student_id']}' class='btn btn-warning' value='{$xml->adminPage->editBtn[0]}'></input>
<input type='submit' id='delete_{$student['student_id']}' name='delete_{$student['student_id']}'class='btn btn-danger' value='{$xml->adminPage->deleteBtn[0]}'></input>
</td>
</tr>
";
}
$page_context = str_replace("{tBody}",$tBody, $page_context);
return $page_context;
}
function initiateAdminPage4($xml, $conn){
$page_context = file_get_contents(DIR_TEMPLATES . "/adminReports.html");
$page_context = str_replace("{LABEL_SUBJECTS}",$xml->professorPage->selectSubject[0], $page_context);
$page_context = str_replace("{FORM_ACTION}",DIR_CORE . "/getGraphs.php", $page_context);
$page_context = str_replace("{AJAX_URL}",DIR_CORE . "/getSubjectInfo.php", $page_context);
$page_context = str_replace("{GENERATE_BAR_GRAPH}",$xml->professorPage->generateBGraph[0], $page_context);
$page_context = str_replace("{GENERATE_PIE_GRAPH}",$xml->professorPage->generatePGraph[0], $page_context);
$page_context = str_replace("{RESET}",$xml->registrationPage->reset[0], $page_context);
$subjects = "<option value=''>-</option>";
$query = $query = sprintf("SELECT subject_id FROM subject");
$data = $conn->query($query) or die(file_get_contents("error404.html"));
while($subject_id = $data->fetch_assoc()){
$subjects .= "<option value='{$subject_id["subject_id"]}'>ID: {$subject_id["subject_id"]}</option>";
}
$page_context = str_replace("{SUBJECTS}",$subjects, $page_context);
return $page_context;
}
function getEnrollment($student_id, $conn){
$titleLanguage = $_SESSION["language"] === "english" ? "titleEnglish" : "title";
$query = sprintf("SELECT concat(faculty.$titleLanguage, ' - ', study.$titleLanguage, ' (', student.enrolledYear, ')') as enrollmentData
FROM faculty
INNER JOIN study ON study.faculty_id = faculty.faculty_id
INNER JOIN student ON student.study_id = study.study_id
WHERE student.student_id = '%s';", mysqli_real_escape_string($conn, $student_id));
return $conn->query($query)->fetch_assoc()["enrollmentData"];
}
function initiateFooter($xml){
$footer = file_get_contents(DIR_TEMPLATES . "/footer.html");
$footer = str_replace("{TITLE}",$xml->navigation->title[0], $footer);
$footer = str_replace("{COPYRIGHT}",$xml->footer->copyright[0], $footer);
$footer = str_replace("{ENGLISH}",$xml->footer->language1[0], $footer);
$footer = str_replace("{SERBIAN_CYRILIC}",$xml->footer->language2[0], $footer);
$footer = str_replace("{SERBIAN_LATIN}",$xml->footer->language3[0], $footer);
$footer = str_replace("{PAGE}",$_GET["page"], $footer);
return $footer;
}
function authenticateAdmin($xml,$conn){
$adminPass = $conn->query("SELECT password_hash FROM staff where staff_id = 1")->fetch_assoc()["password_hash"];
header("WWW-Authenticate: Basic realm=\"Administrator panel\"");
header("HTTP/1.0 401 Unauthorized");
if (@$_SERVER['PHP_AUTH_USER'] === 'Administrator' && password_verify($_SERVER['PHP_AUTH_PW'], $adminPass)){
$_SESSION["loggedInAs"] = "admin";
$_SESSION['loggedInUser'] = $conn->query("SELECT name_surname FROM staff WHERE staff_id = 1")->fetch_assoc()["name_surname"];
header("Location:index.php?language={$_SESSION["language"]}&page=staff_registration",true, 301);
}
echo "<script>window.location = 'index.php?language={$_SESSION["language"]}&page=login';</script>";
}
$conn->close();
?>