-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracker.php
421 lines (330 loc) · 13.9 KB
/
tracker.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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!--Doctype needs to be declared to allow the fixed table heading to work else IE 8 operates in quirks mode-->
<?php
require_once("../../config.php");
//include ('access_context.php');
include('jquery_imports.php');
//include('jscripts.php');
include('accord_functions.php');
include('report_functions.php');
$userid = $USER->id;
// print_r($_SESSION);
?>
<!-- Load the main javscript Asynchronously-->
<script id="myscript" type="text/javascript">
(function() {
var myscript = document.createElement('script');
myscript.type = 'text/javascript';
myscript.src = ('jscripts.js');
var s = document.getElementById('myscript');
s.parentNode.insertBefore(myscript, s);
})();
</script>
<p>
<div id="page">
<div id="layout">
<div class="demo">
<?php
$courseid = $_GET['courseid'];
$contextid = $_GET['var1'];
//$status = $_GET['status'];
//$userid = $USER->id;
//
//
//// start a session
//
if (empty($_SESSION['course_code_session'])) {
$_SESSION['course_code_session'] = $courseid;
$_SESSION['course_context_session'] = $contextid;
}
// the order is important here or the correct information isn't loaded into the navigation header
include('process_forms.php');
include('navigation.php');
// Get all the course code
$query = "SELECT * FROM mdl_course WHERE id='" . $_SESSION['course_code_session'] . "'";
//echo $query;
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
// echo 'Course name is: ' . $row['fullname'] . ' <br/>';
// echo 'Course shortname is: ' . $row['shortname'] . ' <br/>';
$_SESSION['course_ref_session'] = $row['idnumber'];
// echo 'Course number is: ' . $_SESSION['course_ref_session'] . ' <br/>';
}
//$courseContextId = getCourseContextID( $_SESSION['course_code_session']);
// Get all the students on the course
//echo '<h1> students on the course </h1>';
//echo 'group id is: ' . $group_id;
//select and show all students on this course used roleid 5 to indentify students
// $querystudents = "SELECT a.userid, firstname, lastname FROM {$CFG->prefix}role_assignments a JOIN {$CFG->prefix}user u on a.userid=u.id where contextid='" . $contextid . "' AND a.roleid='5' order by lastname";
$select = "SELECT distinct u.id, u.firstname, u.lastname, u.idnumber, u.username";
$from = " FROM {$CFG->prefix}role_assignments a JOIN {$CFG->prefix}user u on a.userid=u.id LEFT JOIN {$CFG->prefix}groups_members gm ON gm.userid=a.userid";
$where = " WHERE contextid='" .$_SESSION['course_context_session'] . "'";
$and = " AND a.roleid='5' order by lastname";
if ($_SESSION['course_group_session'] == 'All groups') {
$andgroup = " ";
} elseif ($_SESSION['course_group_session'] != 'All groups') {
$andgroup = " AND gm.groupid='" . $_SESSION['course_group_session'] . "'";
}
$querystudents = $select . $from . $where . $andgroup . $and;
//echo $querystudents;
$result = mysql_query($querystudents);
$students = array();
$check = 0;
while ($row = mysql_fetch_assoc($result)) {
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$learnerref = $row['idnumber'];
$moodleId = $row['id'];
// echo 'l ref: ' . $learnerref;
// Check the students have an entry in the apprentice tables - else create them
$queryApp = "SELECT * FROM unit_tracker_user_courses WHERE learner_ref='" . $learnerref . "' AND course_code='" . $_SESSION['course_ref_session'] . "'";
// echo $queryApp;
$resultApp = mysql_query($queryApp);
$num_rows = mysql_num_rows($resultApp);
// echo 'num_rows: ' . $num_rows;
if ($num_rows < 1) {
echo 'No record';
echo ' creating a record';
$check = 1;
$queryCreate = "INSERT INTO unit_tracker_user_courses (learner_ref, course_code) VALUES ('$learnerref', '" . $_SESSION['course_ref_session'] . "')";
echo $queryCreate;
mysql_query($queryCreate);
} else {
// echo 'Record found';
// the student exists so pop them into an array to stop having to run the query again
$student = array(
$learnerref,
$firstname,
$lastname
);
array_push($students, $student);
}
}
//echo 'check is: ', $check;
if ($check == 1) {
echo '<font color=red>Warning Accounts have had to be created, please refresh the page</font>';
}
// Get the units for the course
//echo 'ref is: ' . $_SESSION['course_ref_session'];
$query = "SELECT * FROM unit_tracker_courses WHERE course_code='" . $_SESSION['course_ref_session'] . "'";
//echo $query;
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
// echo $row['id'] . ' ' . $row['courseid'] . ' ' . $row['coursename'] . '<br/>';
$apprenticeCourseId = $row['id'];
}
// Build the course units array
echo '<h1>Course Unit/ Subject Tracker *Beta V2*</h1>';
// FIXME break out into an xml service
// Get the course id ion the tables
$query = "SELECT * FROM unit_tracker_courses WHERE course_code='" . $_SESSION['course_ref_session'] . "'";
//echo $query;
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
// count the rows and clear the internal session is a row isn't returned
if ($num_rows >= 1) {
while ($row = mysql_fetch_assoc($result)) {
$_SESSION['course_code_internal_session'] = $row['id'];
}
} else {
$_SESSION['course_code_internal_session'] = '';
}
$course = array();
// Get the units on the course
$query = "SELECT u.id, u.name, u.courseid, u.description, m.type, m.colours FROM unit_tracker_units u LEFT JOIN unit_tracker_marks m ON u.markid=m.id WHERE u.courseid='" . $_SESSION['course_code_internal_session'] . "'";
//echo $query;
$result = mysql_query($query);
// loop through and add the units
while ($row = mysql_fetch_array($result)) {
$unit = array(
"Unit_id" => $row['id'],
"unit_name" => $row['name'],
"unit_type" => $row['type'],
"unit_colours" => $row['colours'],
);
// print_r($unit);
// add the critiea for each unit to the units array
$queryCrit = "SELECT * FROM unit_tracker_units_criteria c JOIN unit_tracker_marks_criteria mc ON c.markid=mc.id WHERE unitid='" . $row['id'] . "'";
// echo $queryCrit;
$resultCrit = mysql_query($queryCrit);
while ($rowCrit = mysql_fetch_assoc($resultCrit)) {
$critria = array(
'Crit_id' => $rowCrit['id'],
'Crit_name' => $rowCrit['name'],
'Crit_mark' => $rowCrit['type'],
'Crit_des' => $rowCrit['description'],
"crit_colours" => $rowCrit['colours'],
);
// print_r($critria);
array_push($unit, $critria);
}
array_push($course, $unit);
}
//print_r($course);
// Count starts at one to allow of the unit mark column
echo '<table><tr><td>';
include('course_select_dropdown.php');
echo '</td><td align="center">';
// Set up the help button
echo '<a href="#" class="addNew"><br/><br/><br/><br/>Unit info</a></p>';
// Set up the edit button
$query = "SELECT * FROM unit_tracker_courses WHERE course_code='" . $_SESSION['course_ref_session'] . "'";
$result = mysql_query($query);
//echo $query;
$num_rows = mysql_num_rows($result);
if ($num_rows >= 1 ) {
// Build the from to turn the units on and off
echo'<form name="tcol" onsubmit="return false">';
while ($row = mysql_fetch_assoc($result)) {
echo '<a class="edit" href="edit_units.php?var1=', $row['id'], '" /><br/><br/><br/><br/>Edit unit details</a/>';
}
echo '</form>';
} else {
echo 'This course hasn\'t been set up for unit tracking. Please contact ICT';
}
echo '</td></tr></table>';
echo '<table><tr><th>Show/ hide units</th>';
$col = 1;
foreach ($course as $key => $value) {
echo '<th class="unit_name"><input type=checkbox name="ucol', $col, '" checked>', $value[unit_name], '</th>';
$col++;
}
echo '</tr>';
echo '<tr><th>Show/ hide unit criteria</th>';
$col = 1;
foreach ($course as $key => $value) {
echo '<th class="show_units"><input type=checkbox name="tcol', $col, '" >', $value[unit_name], '</th>';
$col++;
}
echo '</tr></table>';
$critCount = 1;
$colId = 1;
echo '<form name="process" method="POST" action="process_tracker.php">';
echo '<input type="hidden" name="courseCode" value="', $_SESSION['course_ref_session'] , '"/>';
echo '<table id="examplex" style="text-align: center;">';
echo '<thead><tr><th class="header1">Firstname</th><th class="header1">Lastname</th><th class="header1">Learner Ref</th><th class="header1">Report</th>';
// print out the criteria headers
$colId = 1;
foreach ($course as $key => $value) {
echo '<th class="unit_name ucol', $colId , '" name="ucol' , $colId , '">' . $value[unit_name] .'</th>';
foreach ($value as $iKey => $iValue) {
// Knock out the duff results and count the number of criterias
// if (($iValue[Crit_name] != "U") && ($iValue[Crit_name] != '7') && ($iValue[Crit_name] != 'P') && ($iValue[Crit_name] != '6')) {
// $critCount++;
//
// echo '<th class="criteria_name tcol', $colId, '" name="tcol', $colId, '">' . $iValue[Crit_name] . '</th>';
// }
// Knock out the duff results based on stings 1 character long and count the number of criterias
$num_char = strlen($iValue[Crit_name]);
if ($num_char != 1) {
$critCount++;
echo '<th class="criteria_name tcol', $colId, '" name="tcol', $colId, '">' . $iValue[Crit_name] . '</th>';
}
}
$colId++;
}
echo '</tr></thead><tbody>';
// print out the students criteria marks
$colId = 0;
$count = 0;
$colourId = 0;
foreach ($students as $item) {
echo '<tr><td><input type="hidden" name="learner[][firstname]" value="', $item[1], '"/>' . $item[1] . '</td><td><input type="hidden" name="learner[][lastname]" value="', $item[2], '"/>' . $item[2] . '</td><td><input type="hidden" name="learner[][learner_ref]" value="', $item[0], '"/>' . $item[0] . '</td>';
// The report button
echo '<td><a href="apprentice_report.php?stuID=' , $item[0] , '"/><img src="./images/report_check.png" width="20px" border="0"/></a></td>';
// get all the students units and stuff
$query = "select distinct uc.learner_ref, uc.employer, uc.rep_name, uc.employer_id as employerid ,uc.training_centre, uc.programme_start_date, uc.officer,
c.course_code, c.coursename,
u.id as unit_id, u.name as unit_name, u.description, u.markid,
um.id as mark_id, um.type as mark_type,
uu.target as unit_target, uu.evidence as unit_evidence, uu.user_id,
uuc.id as crit_id, uuc.name as crit_name, uuc.description as crit_description,
usrc.target as crit_target, usrc.evidence as crit_evidence, usrc.user_id,
mc.id as criteria_id, mc.type as criteria_type, mc.colours as criteria_colours,
mm.type as unit_marks, mm.colours as unit_colours
FROM unit_tracker_user_courses uc
LEFT JOIN unit_tracker_courses c ON c.course_code=uc.course_code
LEFT JOIN unit_tracker_units u ON u.courseid=c.id
LEFT JOIN unit_tracker_user_units uu ON u.id=uu.unit_id and uu.user_id=uc.learner_ref
LEFT JOIN unit_tracker_marks mm ON u.markid=mm.id
LEFT JOIN unit_tracker_marks um ON u.markid=um.id LEFT JOIN unit_tracker_units_criteria uuc ON uuc.unitid=u.id
LEFT JOIN unit_tracker_user_criteria usrc ON usrc.criteria_id=uuc.id AND usrc.user_id=uc.learner_ref
LEFT JOIN unit_tracker_marks_criteria mc ON uuc.markid=mc.id
where learner_ref='" . $item[0] . "' AND c.course_code='" . $_SESSION['course_ref_session'] . "'";
// echo $query;
$result = mysql_query($query);
$unitName = '';
$colId = 0;
$id = 1;
$unitId = 1;
while ($row = mysql_fetch_assoc($result)) {
// echo the unit mark using the unit name to test
// echo 'um: ' . $unitName;
if ($unitName != $row['unit_name']) {
// use the unit mark header to increment the tcol value
$colId++;
//echo 'uunitid: ' . $row['unit_id'];
echo '<td class="unit_name ucol', $colId , '" name="ucol' , $colId , '">', getPossbileUnitMarks($row['unit_marks'], $row['unit_colours'] ,$row['unit_target'], $unitId, 'unit', $row['unit_id'], $item[0], $count), '</td>';
$unitName = $row['unit_name'];
$unitId++;
$count++;
//reset the colourid to allow the proper stripping
$colourId = 0;
}
if ($colourId == 0) {
$colour = 'crit_target';
$colourId = 1;
} else {
$colour = 'crit_target2';
$colourId = 0;
}
echo '<td class="' . $colour . ' tcol', $colId, '" name="tcol', $colId, '">', getPossbileUnitMarks($row['criteria_type'], $row['criteria_colours'], $row['crit_target'], $id, 'critieria', $row['crit_id'], $item[0], $count), '</td>';
$id++;
$count++;
}
$colId++;
echo '</tr>';
}
echo '</tbody></table>';
//echo '<input type="submit" id="submit" name="submit" value="submit"/>';
echo '<input id="save" type="submit" name="submit" value="submit_change"/>';
echo '</form>';
// clear the arrays
echo '<div id="dialog" title="Unit Descriptions">';
echo '<p>Below are details about the units and criteria on the course</p>';
echo '<div id="multiOpenAccordion">';
foreach ($course as $key => $value) {
accord_first($value['unit_name']);
foreach ($value as $iKey => $iValue) {
if (($iValue[Crit_name] != "U") && ($iValue[Crit_name] != '7') && ($iValue[Crit_name] != 'P') && ($iValue[Crit_name] != '6')) {
echo $iValue[Crit_name], ' ', $iValue[Crit_des], '<br/>';
}
}
accord_last();
}
echo '<br/>';
echo '<br/>';
echo '</div>';
echo '</div>';
unset($units);
unset($unitsArray);
unset($students);
unset($student);
unset($course);
unset($unit);
unset($critria);
unset($course);
?>
</div>
</div>
</div>
<!--Script to run the submit button graphic - doesn't work when added tot he main js script files-->
<script type="text/javascript">
$(document).ready(function() {
$('#save').hover(function() {
$(this).addClass('mhover')
}, function() {
$(this).removeClass('mhover');
});
})
</script>