Skip to content
Permalink
Browse files

Add Agent/Ticket Audit Export

- ability to export Agent audits
- ability to export Ticket audits
- ensures that the export for Agents, Tickets, and Users takes plugin options chosen into account.
  • Loading branch information...
aydreeihn committed Jan 24, 2019
1 parent 46a764f commit 72974c8f74b2f2d2ca3753d34b8335c1d1be7a5e
Showing with 36 additions and 5 deletions.
  1. +10 −3 include/class.export.php
  2. +11 −0 scp/staff.php
  3. +13 −1 scp/tickets.php
  4. +2 −1 scp/users.php
@@ -322,7 +322,7 @@ static function departmentMembers($dept, $agents, $filename='', $how='csv') {
exit;
}
static function audits($type, $filename='', $tableInfo='', $object='', $how='csv') {
static function audits($type, $filename='', $tableInfo='', $object='', $how='csv', $show_viewed=true) {
$headings = array('Description', 'Timestamp', 'IP');
switch ($type) {
case 'audit':
@@ -342,9 +342,15 @@ static function audits($type, $filename='', $tableInfo='', $object='', $how='csv
$sql = AuditEntry::objects()->filter(array('user_id'=>$object->getId()))->order_by('timestamp');
break;
case 'staff':
// code...
$sql = AuditEntry::objects()->filter(array('staff_id'=>$object->getId()))->order_by('timestamp');
break;
case 'ticket':
$sql = AuditEntry::objects()->filter(array('object_id'=>$object->getId(), 'object_type'=>'T'))->order_by('timestamp');
break;
}
if (!$show_viewed)
$sql = $sql->filter(Q::not(array('event_id'=>Event::getIdByName('viewed'))))->order_by('timestamp');
//Download the file
Http::download($filename, "text/$how");
echo self::dumpQuery($sql, $headings,
@@ -359,7 +365,8 @@ static function audits($type, $filename='', $tableInfo='', $object='', $how='csv
if (is_numeric($k) && ($i = in_array(
is_array($obj->ht) ? $obj->ht['id'] : $obj->id,
$v)) !== false) {
$record[0] = $description ?: $v['description'];
$description = $description ?: $v['description'];
$record[0] = $description;
$record[1] = $v['timestamp'];
$record[2] = $v['ip'];
}
@@ -179,6 +179,17 @@
$tip_namespace = 'staff.agent';
if($staff || ($_REQUEST['a'] && !strcasecmp($_REQUEST['a'],'add'))) {
if (strtolower($_REQUEST['t']) == 'audits') {
require_once(INCLUDE_DIR.'plugins/audit-ticket/class.audit.php');
$show = AuditEntry::$show_view_audits;
$filename = sprintf('%s-audits-%s.csv',
$staff->getName(), strftime('%Y%m%d'));
$tableInfo = AuditEntry::getTableInfo($staff, true);
if (!Export::audits('staff', $filename, $tableInfo, $staff, 'csv', $show))
$errors['err'] = __('Unable to dump query results.')
.' '.__('Internal error occurred');
}
if ($staff && ($pdept=$staff->getDept()) && !$pdept->isActive())
$warn = sprintf(__('%s is assigned a %s that is not active.'), __('Agent'), __('Primary Department'));
@@ -496,14 +496,26 @@
$f->filterFields(function($f) { return !$f->isStorable(); });
$f->addMissingFields();
}
} elseif($_REQUEST['a'] == 'print')
} elseif($_REQUEST['a'] == 'print' && !$ticket->pdfExport($_REQUEST['psize'], $_REQUEST['notes'], $_REQUEST['events'])) {
if (!extension_loaded('mbstring'))
$errors['err'] = sprintf('%s %s',
'mbstring',
__('extension required to print ticket to PDF'));
elseif (!$ticket->pdfExport($_REQUEST['psize'], $_REQUEST['notes'], $_REQUEST['events']))
$errors['err'] = __('Unable to export the ticket to PDF for print.')
.' '.__('Internal error occurred');
} elseif ($_REQUEST['a'] == 'export' && strtolower($_REQUEST['t']) == 'audits') {
require_once(INCLUDE_DIR.'plugins/audit-ticket/class.audit.php');
$show = AuditEntry::$show_view_audits;
$filename = sprintf('%s-audits-%s.csv',
$ticket->getNumber(), strftime('%Y%m%d'));
$tableInfo = AuditEntry::getTableInfo($ticket, true);
if (!Export::audits('ticket', $filename, $tableInfo, $ticket, 'csv', $show))
$errors['err'] = __('Unable to dump query results.')
.' '.__('Internal error occurred');
} elseif($_REQUEST['a'] == 'print' && !$ticket->pdfExport($_REQUEST['psize'], $_REQUEST['notes']))
$errors['err'] = __('Unable to export the ticket to PDF for print.')
.' '.__('Internal error occurred');
} else {
$inc = 'templates/queue-tickets.tmpl.php';
if ($_REQUEST['a']=='open' &&
@@ -192,10 +192,11 @@
case 'audits':
if ($_REQUEST['a'] == 'export') {
require_once(INCLUDE_DIR.'plugins/audit-ticket/class.audit.php');
$show = AuditEntry::$show_view_audits;
$filename = sprintf('%s-audits-%s.csv',
$user->getName(), strftime('%Y%m%d'));
$tableInfo = AuditEntry::getTableInfo($user, true);
if (!Export::audits('user', $filename, $tableInfo, $user, 'csv'))
if (!Export::audits('user', $filename, $tableInfo, $user, 'csv', $show))
$errors['err'] = __('Unable to dump query results.')
.' '.__('Internal error occurred');
}

0 comments on commit 72974c8

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