-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteacherPageHandler.php
More file actions
132 lines (115 loc) · 4.54 KB
/
Copy pathteacherPageHandler.php
File metadata and controls
132 lines (115 loc) · 4.54 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
<?php
include_once "php_classes/cDB.php";
include_once "php_classes/cDrawer.php";
include_once "php_classes/сOneDayRecord.php";
/**
* Created by PhpStorm.
* User: user
* Date: 16.10.2017
* Time: 1:15
*/
$db = new cDB();
if (isset($_COOKIE['teacherUnderAdmin'])) {
$currTeacher = $db->LoadTeacherByNickName($_COOKIE['teacherUnderAdmin']);
}
else
$currTeacher = $db->VerifyUser();
if ($_POST['task'] == "ShowGroups") {
echo '<h2>Список ваших групп</h2>';
if (isset($_COOKIE['teacherUnderAdmin']))
cDrawer::DrawAdminFunctionalityInGroups();
echo cDrawer::DrawGroupsList($currTeacher->groups);
}
if ($_POST['task'] == "ShowStudents") {
$index = $_POST['groupID'];
DrawCurrentGroupBlock($currTeacher, $index);
}
if ($_POST['task'] == "ShowTimetable") {
$currStudentID = $_POST['studentID'];
$currGroupID = $_POST['currGroupID'];
$monthOffset = $_POST['monthOffset'];
echo cDrawer::DrawTimetableHeader(Constants::getMonthNameByOffset($monthOffset), Constants::getYeraNumByOffset($monthOffset), true);
echo cDrawer::DrawStudentTimetableToEdit($currTeacher->groups[$currGroupID]->students[$currStudentID], $currTeacher->groups[$currGroupID]->weekTimetable, $monthOffset);
}
if ($_POST['task'] == "SaveNotesAndMarks") {
$monthOffset = $_POST["monthOffset"];
$newNotesAndMarks = json_decode($_POST["notesAndMarks"]);
//var_dump($newNotesAndMarks);
$currStudentID = $_POST['studentID'];
$currGroupID = $_POST['currGroupID'];
//добавление оценки
if ($currStudentID != "ALL_STUDENTS") {
foreach ($newNotesAndMarks as $key => $value) {
$currTeacher->groups[$currGroupID]->students[$currStudentID]->editMark($key, new сOneDayRecord($value[0], $value[1]));
}
if ($db->UpdateStudent($currTeacher->groups[$currGroupID]->students[$currStudentID]))
echo "OK";
else
echo "ERROR";
} else {
$isOK = true;
foreach ($currTeacher->groups[$currGroupID]->students as $currStudent) {
foreach ($newNotesAndMarks as $key => $value) {
$currStudent->editMark($key, new сOneDayRecord($value[0], $value[1]));
//var_dump($newNotesAndMarks);
}
$isOK = $isOK && $db->UpdateStudent($currStudent);
}
if ($isOK)
echo "OK";
else
echo "ERROR";
}
}
if ($_POST['task'] == "ShowCommonTimetable") {
$currGroupID = $_POST['currGroupID'];
$monthOffset = $_POST['monthOffset'];
echo cDrawer::DrawTimetableHeader(Constants::getMonthNameByOffset($monthOffset), Constants::getYeraNumByOffset($monthOffset), true);
echo cDrawer::DrawEmptyTimetableToEdit($currTeacher->groups[$currGroupID]->weekTimetable, $monthOffset);
}
if ($_POST['task'] == "AddStudent") {
$currGroupID = $_POST['groupID'];
$login = $_POST['login'];
$password = $_POST['password'];
$surname = $_POST['surname'];
$name = $_POST['name'];
$t1 = $currGroupID != '';
$t2 = preg_match("#^[a-zA-Z0-9_]+$#", $login);
$t3 = preg_match("#^[a-zA-Z0-9_]+$#", $password);
if ($t1 && $t2 && $t3) {
$currTeacher->groups[$currGroupID]->addStudent(new cStudent($login, $password, $currGroupID, trim($surname) . ' ' . trim($name)));
$isAdded = $db->UpdateGroup($currTeacher->groups[$currGroupID]);
$isAdded = $isAdded && $db->SaveStudent($currTeacher->groups[$currGroupID]->students[$login]);
if ($isAdded) {
DrawCurrentGroupBlock($currTeacher, $currGroupID);
echo "OK";
} else
echo 'DB_ERROR';
} else {
echo 'INPUT_ERROR';
}
}
if ($_POST['task'] == "DeleteStudent") {
$currGroupID = $_POST['groupID'];
$login = $_POST['nick'];
//cDB удаление студента
$student = $db->LoadStudentByNickName($login);
if ($student != null) {
if ($db->DeleteStudent($student))
echo "OK";
else
echo "ERROR1";
} else {
echo "ERROR2";
}
}
if ($_POST['task'] == "ChangeSettings") {
}
function DrawCurrentGroupBlock($teacher, $groupID)
{
echo file_get_contents(Constants::$ROOT_PATH . "html_templates/backToGroupsButton.html");
echo file_get_contents(Constants::$ROOT_PATH . "html_templates/commonHomeworkButton.html");
echo file_get_contents(Constants::$ROOT_PATH . "html_templates/addStudentInGroupButton.html");
echo cDrawer::DrawStudentsList($teacher->groups[$groupID]->students);
echo file_get_contents(Constants::$ROOT_PATH . "html_templates/editOrAddUserForm.html");
}