Skip to content

Commit fc0177d

Browse files
author
Alena Holligan
committed
ohm-525 Teacher Audit Log
ohm-527 migration for data model ohm-527 change creation timestamp to created_at field ohm-527 match ENUM plural form ohm-527 update table name output ohm-528 initial logging class and testing pattern ohm-528 add findCourseAction and update/cleanup tests ohm-525 fix in memory sqlite db for tests ohm-525 use global userid ohm-525 add source file to all metadata ohm-525 Assessment setting changes logged ohm-525 update for mass updates not reqiring itemid ohm-525 Mass change assessment ohm-525 Unenroll with grade save ohm-525 Mass Assessment Date Change ohm-525 Clear Attempts, Question Settings Change, Assessment Settings Change ohm-525 Clear Attempts ohm-525 Clear Scores and Attempts ohm-525 update Clear Scores ohm-524 delete items ohm-525 initial Teacher Audit Log Report ohm-525 use blob for metadata ohm-525 update for code bugs ohm-525 record updated scores ohm-525 update Clear Scores, Clear Attempts. Change 'Grade Override' to 'Grade Change' ohm-525 mass change dates ohm-525 Change Grades Old Assessment ohm-525 record new assessment updates ohm-525 update include to TeacherAuditLog ohm-525 build assess2 for production ohm-525 loadRecord to get score data. Only record if this is a scoreoverride ohm-525 do not need to log teacher clearing their own scores ohm-525 clear attempts ohm-525 do not need to record for adding a new assessment ohm-525 clean up logged data ohm-525 record offline, forum and external grades from imas_grades ohm-525 must be admin to access Teacher Audit Log Report ohm-525 update breadcrumbs ohm-525 only pull imas_grades where appropriate ohm-525 count forums ohm-525 fix migrations ohm-525 add to actions file. Allow teacher audit log report to have no information. Add URI to tests ohm-525 add tracking grades. Add methods to report on count
1 parent e6fb80e commit fc0177d

39 files changed

Lines changed: 1202 additions & 108 deletions

admin/actions.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//(c) 2006 David Lippman
44
require("../init.php");
55
require_once("../includes/password.php");
6+
require_once("../includes/TeacherAuditLog.php");
67

78
//Look to see if a hook file is defined, and include if it is
89
if (isset($CFG['hooks']['admin/actions'])) {
@@ -662,6 +663,12 @@
662663
}
663664

664665
if ($stm->rowCount()>0) {
666+
$result = TeacherAuditLog::addTracking(
667+
$cid,
668+
"Mass Assessment Settings Change",
669+
null,
670+
$qarr
671+
);
665672
if ($setdatesbylti==1) {
666673
$stm = $DBH->prepare("UPDATE imas_assessments SET date_by_lti=1 WHERE date_by_lti=0 AND courseid=:cid");
667674
$stm->execute(array(':cid'=>$_GET['id']));

admin/teacherauditlog.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
//IMathAS: Add/modify blocks of items on course page
3+
//(c) 2019 David Lippman
4+
5+
/*** master php includes *******/
6+
require("../init.php");
7+
require("../includes/htmlutil.php");
8+
require_once("../includes/TeacherAuditLog.php");
9+
10+
/*** pre-html data manipulation, including function code *******/
11+
12+
//set some page specific variables and counters
13+
$overwriteBody = 0;
14+
$body = "";
15+
$pagetitle = "Teacher Audit Log";
16+
$userid = Sanitize::onlyInt($_GET['userid']);
17+
$cid = Sanitize::courseId($_GET['cid']);
18+
19+
$curBreadcrumb = "$breadcrumbbase <a href=\"admin2.php\">Admin</a> &gt; <a href=\"userdetails.php?id=$userid\">User Details</a> ";
20+
$curBreadcrumb .= "&gt; Teacher Audit Log\n";
21+
22+
if (isset($_GET['id'])) {
23+
$stm = $DBH->prepare("SELECT courseid FROM imas_assessments WHERE id=?");
24+
$stm->execute(array(intval($_GET['id'])));
25+
if ($stm->rowCount()==0 || $stm->fetchColumn(0) != $_GET['cid']) {
26+
echo "Invalid ID";
27+
exit;
28+
}
29+
}
30+
31+
if ($myrights <75) {
32+
$overwriteBody=1;
33+
$body = "You need to log in as an admin to access this page";
34+
} elseif (!(isset($_GET['cid']))) {
35+
$overwriteBody=1;
36+
$body = "You need to select the course";
37+
}
38+
function formatdate($date) {
39+
return tzdate("M j, Y, g:i a",strtotime($date));
40+
}
41+
42+
43+
//BEGIN DISPLAY BLOCK
44+
45+
/******* begin html output ********/
46+
//$placeinhead = "<script type=\"text/javascript\" src=\"$imasroot/javascript/DatePicker.js?v=080818\"></script>";
47+
48+
require("../header.php");
49+
50+
if ($overwriteBody==1) {
51+
echo $body;
52+
} else {
53+
$stm = $DBH->prepare("SELECT ic.name,ic.ownerid,iu.groupid FROM imas_courses AS ic JOIN imas_users AS iu ON ic.ownerid=iu.id WHERE ic.id=?");
54+
$stm->execute(array($cid));
55+
list($coursename, $courseownerid, $coursegroupid) = $stm->fetch(PDO::FETCH_NUM);
56+
57+
echo '<div class=breadcrumb>', $curBreadcrumb, '</div>';
58+
echo '<div id="headeruserdetail" class="pagetitle"><h1>' . _('Teacher Audit Log') . ': ';
59+
echo Sanitize::encodeStringForDisplay($coursename);
60+
echo '</h1></div>';
61+
62+
$teacher_actions = TeacherAuditLog::findActionsByCourse($cid);
63+
if (empty($teacher_actions)) {
64+
echo "<p>Nothing to report</p>";
65+
} else {
66+
$stm = $DBH->query("SELECT FirstName, LastName FROM imas_users WHERE id=" . $teacher_actions[0]['userid']);
67+
list($first, $last) = $stm->fetch();
68+
echo '<table><tr>';
69+
echo '<th>Date/Time</th>';
70+
echo '<th>Teacher</th>';
71+
echo '<th>Action</th>';
72+
echo '<th>ItemID</th>';
73+
echo '<th>Details</th>';
74+
echo '</tr>';
75+
76+
foreach ($teacher_actions as $action) {
77+
echo '<tr>';
78+
echo '<td>' . formatdate($action['created_at']) . '</td>';
79+
echo "<td>$first $last (" . Sanitize::onlyInt($action['userid']) . ')</td>';
80+
echo '<td>' . Sanitize::encodeStringForDisplay($action['action']) . '</td>';
81+
echo '<td>' . Sanitize::onlyInt($action['itemid']) . '</td>';
82+
echo '<td><a href="javascript:alert(\'' . Sanitize::encodeStringForDisplay($action['metadata']) . '\')">Details</a></td>';
83+
echo '</tr>';
84+
}
85+
}
86+
}
87+
88+
require("../footer.php");

admin/userdetails.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ function hidecourse(el) {
392392
var cid = $(el).attr("data-cid");
393393
var thishtml = html + \' <li class="unhide"><a href="#" onclick="unhidecourse(this);return false;">'._('Return to home page course list').'</a></li>\';
394394
thishtml += \' <li class="hide"><a href="#" onclick="hidecourse(this);return false;">'._('Hide from home page course list').'</a></li>\';
395-
395+
396+
thishtml += \' <li><a href="teacherauditlog.php?userid='.$uid.'&cid=\'+cid+\'">'._('Teacher Audit Log').'</a></li>\';
396397
thishtml += \' <li><a href="forms.php?from=ud'.$uid.'&action=modify&id=\'+cid+\'">'._('Settings').'</a></li>\';
397398
thishtml += \' <li><a href="addremoveteachers.php?from=ud'.$uid.'&id=\'+cid+\'">'._('Add/remove teachers').'</a></li>\';
398399
thishtml += \' <li><a href="transfercourse.php?from=ud'.$uid.'&id=\'+cid+\'">'._('Transfer ownership').'</a></li>\';

admin/userreportdetails.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ function hidecourse(el) {
516516
var thishtml = html + \' <li class="unhide"><a href="#" onclick="unhidecourse(this);return false;">'._('Return to home page course list').'</a></li>\';
517517
thishtml += \' <li class="hide"><a href="#" onclick="hidecourse(this);return false;">'._('Hide from home page course list').'</a></li>\';
518518
519+
thishtml += \' <li><a href="teacherauditlog.php?userid='.$uid.'&cid=\'+cid+\'">'._('Teacher Audit Log').'</a></li>\';
519520
thishtml += \' <li><a href="forms.php?from=ud'.$uid.'&action=modify&id=\'+cid+\'">'._('Settings').'</a></li>\';
520521
thishtml += \' <li><a href="addremoveteachers.php?from=ud'.$uid.'&id=\'+cid+\'">'._('Add/remove teachers').'</a></li>\';
521522
thishtml += \' <li><a href="transfercourse.php?from=ud'.$uid.'&id=\'+cid+\'">'._('Transfer ownership').'</a></li>\';

assess2/AssessRecord.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
require_once(__DIR__ . '/questions/models/ShowAnswer.php');
1212
require_once(__DIR__ . '/questions/ScoreEngine.php');
1313
require_once(__DIR__ . '/questions/models/ScoreQuestionParams.php');
14+
require_once(__DIR__ . '/../includes/TeacherAuditLog.php');
1415

1516
use IMathAS\assess2\questions\QuestionGenerator;
1617
use IMathAS\assess2\questions\models\QuestionParams;
@@ -180,6 +181,23 @@ public function saveRecord() {
180181
}
181182
$stm = $this->DBH->prepare($query);
182183
$stm->execute($qarr);
184+
if ($stm->rowCount()>0 && $this->data['scoreoverride']==true) {
185+
$this->loadRecord($this->curUid);
186+
//do we want to keep the score data? if so we need to decode or else unset
187+
$this->assessRecord['scoreddata'] = json_decode(gzdecode($this->assessRecord['scoreddata']), true);
188+
$qarr[':scoreddata'] = json_decode(gzdecode($qarr[':scoreddata']), true);
189+
$result = TeacherAuditLog::addTracking(
190+
$this->assess_info->getCourseId(),
191+
"Change Grades",
192+
$this->curAid,
193+
array(
194+
'Assessment Ver' => 2,
195+
'studentid' => $this->curUid,
196+
'old score' => $this->assessRecord['score'],
197+
'new score' => $qarr[':score']
198+
)
199+
);
200+
}
183201

184202
$this->need_to_record = false;
185203
}
@@ -2942,6 +2960,18 @@ public function gbClearAttempts($type, $keepver, $av=0, $qn=0, $qv=0) {
29422960
$replacedDeleted = true;
29432961
}
29442962
$this->updateStatus();
2963+
$result = TeacherAuditLog::addTracking(
2964+
$this->assess_info->getCourseId(),
2965+
"Clear Attempts",
2966+
2967+
$this->curAid,
2968+
array(
2969+
'Assessment Ver' => 2,
2970+
'studentid' => $this->curUid,
2971+
'type'=>$type,
2972+
'keepver' => $this->assessRecord,
2973+
)
2974+
);
29452975
return $replacedDeleted;
29462976
}
29472977

assess2/gbclearattempt.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
require_once("./AssessInfo.php");
2727
require_once("./AssessRecord.php");
2828
require_once('./AssessUtils.php');
29+
require_once("../includes/TeacherAuditLog.php");
2930

3031
header('Content-Type: application/json; charset=utf-8');
3132

@@ -72,6 +73,14 @@
7273
if ($type == 'all' && $keepver == 0) {
7374
$stm = $DBH->prepare('DELETE FROM imas_assessment_records WHERE assessmentid=? AND userid=?');
7475
$stm->execute(array($aid, $uid));
76+
if ($stm->rowCount()>0) {
77+
$result = TeacherAuditLog::addTracking(
78+
$cid,
79+
"Clear Attempts",
80+
$aid,
81+
array('grades'=>$assess_record->getGbScore())
82+
);
83+
}
7584
// update LTI grade
7685
$lti_sourcedid = $assess_record->getLTIsourcedId();
7786
if (strlen($lti_sourcedid) > 1) {

assess2/vue-src/package-lock.json

Lines changed: 34 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)