Skip to content
Permalink
Browse files

User Audit Exports:

This commit adds the ability to export the User Audit log as a CSV.
  • Loading branch information...
aydreeihn committed Jan 18, 2019
1 parent 919e1b7 commit 9b80889a107c63435c622529169153fc673c72c6
Showing with 45 additions and 0 deletions.
  1. +34 −0 include/class.export.php
  2. +11 −0 scp/users.php
@@ -321,6 +321,40 @@ static function departmentMembers($dept, $agents, $filename='', $how='csv') {
);
exit;
}
static function audits($tableInfo, $user, $filename='', $how='csv') {
$sql = AuditEntry::objects()->filter(array('user_id'=>$user->getId()))->order_by('timestamp');
// Filename or stream to export to
$filename = $filename ?: sprintf('%s-%s.csv', $user->getName()->name,
strftime('%Y%m%d'));
Http::download($filename, "text/$how");
echo self::dumpQuery($sql, array(
0 => 'ID',
1 => 'User Class',
2 => 'User Name',
3 => 'Object',
4 => 'Description',
5 => 'Timestamp',
6 => 'IP',
),
$how,
array('modify' => function(&$record, $keys, $obj) use ($tableInfo) {
foreach ($tableInfo as $k => $v) {
if (is_numeric($k) && ($i = in_array($obj->id, $v)) !== false) {
$record[0] = $v['id'];
$record[1] = $v['class'];
$record[2] = $v['name'];
$record[3] = $v['object'];
$record[4] = $v['description'];
$record[5] = $v['timestamp'];
$record[6] = $v['ip'];
}
}
return $record;
})
);
exit;
}
}
@@ -189,6 +189,17 @@
.' '.__('Internal error occurred');
}
break;
case 'audits':
if ($_REQUEST['a'] == 'export') {
require_once(INCLUDE_DIR.'plugins/audit-ticket/class.audit.php');
$filename = sprintf('%s-audits-%s.csv',
$user->getName(), strftime('%Y%m%d'));
$tableInfo = AuditEntry::getTableInfo($user, true);
if (!Export::audits($tableInfo, $user, $filename, 'csv'))
$errors['err'] = __('Unable to dump query results.')
.' '.__('Internal error occurred');
}
break;
}
}

0 comments on commit 9b80889

Please sign in to comment.
You can’t perform that action at this time.