-
Notifications
You must be signed in to change notification settings - Fork 0
/
staff.php
executable file
·266 lines (221 loc) · 8.21 KB
/
staff.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
<?php
require_once 'config.inc.php';
$tpl_main = new TemplatePower('template/master.html');
$tpl_main->prepare();
// check to see if the user is logged in and is a staff or admin
if(!$_AUTH->isLoggedIn() || (!$_AUTH->isStaff() && !$_AUTH->isAdmin())) {
// send the user to an error page and that's it
$tpl = new TemplatePower('template/error.html');
$tpl->assignGlobal('error_message', 'You are not logged in as an administrator or staff.');
$tpl->prepare();
// the user is good to go
} else {
$tpl = new TemplatePower('template/staff.html');
$tpl->prepare();
if (isset($_POST['course_id'])) {
$course = $_POST['course_id'];
$c = get_course($_DB, $course);
$tpl->assignGlobal('course', $c['courseTitle']);
}
// see if a form was submitted
if(isset($_POST['action'])) {
$action = $_POST['action'];
// check to see what the user wanted to do
switch ($action) {
// selecting a new course
case 'course_change':
$course = $_POST['course'];
break;
case 'student_change':
$student = $_POST['student'];
break;
case 'modify':
if(isset($_POST['delete'])) {
$assignment = $_POST['assn_id'];
$_DB->sql_query("DELETE FROM assignments WHERE assignmentID='$assignment';");
} elseif(isset($_POST['update'])) {
$assignment = $_POST['assn_id'];
$title = $_POST['title'];
$base = $_POST['base'];
$weight = $_POST['weight'];
$upload = isset($_POST['upload'])?1:0;
$_DB->sql_query("UPDATE assignments SET assignmentTitle='$title', assignmentCourse='$course', assignmentBase='$base', assignmentWeight='$weight', assignmentUpload='$upload' WHERE assignmentID='$assignment' ;");
} elseif(isset($_POST['add'])) {
if(isset($course)){
$_DB->sql_query("INSERT INTO assignments (assignmentTitle, assignmentCourse) VALUES ('NEW ASSIGNMENT', '$course');");
}
}
break;
case 'grademodify':
$assignment = $_POST['assn_id'];
$student = $_POST['student_id'];
$score = $_POST['score'];
$_DB->sql_query("SELECT * FROM grades WHERE gradeAssignment='$assignment' AND gradeUser='$student'");
if($row = $_DB->sql_fetchrow()) {
$gradeID = $row['gradeID'];
} else {
$_DB->sql_query("INSERT INTO grades (gradeUser, gradeAssignment) VALUES ('$student', '$assignment');");
$_DB->sql_query("SELECT * FROM grades WHERE gradeAssignment='$assignment' AND gradeUser='$student'");
$row = $_DB->sql_fetchrow();
$gradeID = $row['gradeID'];
}
$_DB->sql_query("UPDATE grades SET gradeScore = '$score' WHERE gradeAssignment='$assignment' AND gradeUser='$student'");
}
}
if (isset($student)) {
set_student_template($_DB, $tpl, $course, $student);
$stud = get_student($_DB, $student);
$tpl->assignGlobal('student', $stud['userName']);
$tpl->assignGlobal('student_select_box', gen_student_select_box($_DB, $course));
$tpl->assignGlobal('course_id', $course);
} else if(isset($course)) {
set_course_template($_DB, $tpl, $course);
$tpl->assignGlobal('student_select_box', gen_student_select_box($_DB, $course));
$tpl->assignGlobal('course_id', $course);
}
// add the remaining components to the template
$tpl->assignGlobal('course_select_box', gen_course_select_box($_DB));
$tpl->assignGlobal('username', $_SESSION['userName']);
}
// for all of the pages, put the content into the main template
$tpl->showUnAssigned(false);
$tpl_main->assignGlobal("content", $tpl->getOutputContent());
$tpl_main->showUnAssigned(false);
$tpl_main->printToScreen();
/**
* Return a list of courses that the user is enrolled in
*
* @db the MySQL database connection
*
**/
function get_user_courses($db) {
$user = $_SESSION['userID'];
$db->sql_query("SELECT * FROM stafftocourses JOIN courses ON staff = $user;");
return $db->sql_fetchrowset();
}
/**
* Return a HTML combo box populated with the courses that the user is in
*
* @db the MySQL database connection
*
**/
function gen_course_select_box($db) {
$course_select_box = '<select name="course" onChange="frmCourse.submit();"><option value="" selected>Select Course</option>';
foreach(get_user_courses($db) as $row) {
$course_select_box .= "<option value='".$row['courseID']."'>".$row['courseTitle']."</option>";
}
$course_select_box .= '</select>';
return $course_select_box;
}
/**
* Return a list of courses that the user is enrolled in
*
* @db the MySQL database connection
*
**/
function get_course_students($db, $courseID) {
$db->sql_query("SELECT * FROM studentstocourses JOIN users ON userID = student AND course = '$courseID' ");
return $db->sql_fetchrowset();
}
/**
* Return a HTML combo box populated with the students in a course
*
* @db the MySQL database connection
*
**/
function gen_student_select_box($db, $courseID) {
$course_select_box = '<select name="student" onChange="frmStudent.submit();"><option value="" selected>Select Student</option>';
foreach(get_course_students($db, $courseID) as $row) {
$course_select_box .= "<option value='".$row['userID']."'>".$row['userName']."</option>";
}
$course_select_box .= '</select>';
return $course_select_box;
}
/**
* Return a single course's data or nothing if the course doesn't exist
*
* @db the MySQL database connection
*
**/
function get_course($db, $courseID) {
$courses = get_user_courses($db);
foreach($courses as $row) {
if($row['courseID'] == $courseID) {
return $row;
}
}
}
/**
* Return a single course's data or nothing if the course doesn't exist
*
* @db the MySQL database connection
*
**/
function get_student($db, $userID) {
$db->sql_query("SELECT * FROM users WHERE userID = '$userID' LIMIT 1;");
return $db->sql_fetchrow();
}
/**
* Populate a template with the individual assignments and user's grades
*
* @db the MySQL database connection
* @tpl the existing template to populate
* @courseID the course to populate assignments for
*
**/
function set_student_template($db, $tpl, $courseID, $userID) {
$course = get_course($db, $courseID);
$tpl->assignGlobal('course', $course['courseTitle']);
$db->sql_query("SELECT * FROM assignments WHERE assignmentCourse = '$courseID';");
$assignments = $db->sql_fetchrowset();
$tpl->newBlock( 'grade_head_blk' );
foreach($assignments as $assn) {
$tpl->newBlock( 'grade_blk' );
$tpl->assign('g_title', $assn['assignmentTitle']);
$tpl->assign('g_base', $assn['assignmentBase']);
$tpl->assign('g_weight', $assn['assignmentWeight']);
$tpl->assign('g_id', $assn['assignmentID']);
$tpl->assign('g_student', $userID);
$assnID = $assn['assignmentID'];
$db->sql_query("SELECT * FROM grades WHERE (gradeAssignment = '$assnID' AND gradeUser = '$userID');");
$grade = $db->sql_fetchrow();
$tpl->assign('g_score', $grade['gradeScore']);
if (!$assn['assignmentUpload']) {
$tpl->assign('g_upload', 'disabled');
$tpl->assign('g_download', 'Download');
} else {
$tpl->assign('g_download', '<a href="' . $grade['gradeFile'] . '">Download</a>');
}
}
$tpl->gotoBlock( "_ROOT" );
}
/**
* Populate a template with the individual assignments and user's grades
*
* @db the MySQL database connection
* @tpl the existing template to populate
* @courseID the course to populate assignments for
*
**/
function set_course_template($db, $tpl, $courseID) {
$course = get_course($db, $courseID);
$tpl->assignGlobal('course', $course['courseTitle']);
$tpl->newBlock( 'assignment_head_blk');
$db->sql_query("SELECT * FROM assignments WHERE assignmentCourse = '$courseID';");
$assignments = $db->sql_fetchrowset();
foreach($assignments as $assn) {
$tpl->newBlock( 'assignment_blk' );
$tpl->assign('g_title', $assn['assignmentTitle']);
$tpl->assign('g_base', $assn['assignmentBase']);
$tpl->assign('g_weight', $assn['assignmentWeight']);
$tpl->assign('g_id', $assn['assignmentID']);
if($assn['assignmentUpload']) {
$tpl->assign('g_upload', 'checked');
}
$assnID = $assn['assignmentID'];
$tpl->assign('g_download', '<a href="staff.php?delete='.$assnID.'">Delete</a>');
}
$tpl->newBlock('assignment_add_blk');
$tpl->gotoBlock( "_ROOT" );
}
?>