Skip to content
Permalink
Browse files

Audit Export Update

Make audit exports work with the changes implemented in PR #5015.
  • Loading branch information...
aydreeihn committed Sep 3, 2019
1 parent 205b3ae commit 5c91dc1885fc8aefde1791941c267fdb1550d704
Showing with 29 additions and 72 deletions.
  1. +10 −35 include/class.export.php
  2. +0 −37 include/class.organization.php
  3. +19 −0 scp/js/scp.js
@@ -322,19 +322,18 @@ static function departmentMembers($dept, $agents, $filename='', $how='csv') {
exit;
}
static function audits($type, $abbrv='', $state='', $filename='', $tableInfo='', $object='', $how='csv', $show_viewed=true) {
static function audits($type, $filename='', $tableInfo='', $object='', $how='csv', $show_viewed=true, $data=array(), CsvExporter $exporter) {
$headings = array('Description', 'Timestamp', 'IP');
switch ($type) {
case 'audit':
$sql = AuditEntry::objects()->filter(array('object_type'=>$abbrv));
if ($state && $state != 'All') {
$eventId = Event::getIdByName(strtolower($state));
$sql = AuditEntry::objects()->filter(array('object_type'=>$data['type']));
if ($data['state'] && $data['state'] != 'All') {
$eventId = Event::getIdByName(strtolower($data['state']));
$sql = $sql->filter(array('event_id'=>$eventId));
}
if ($_REQUEST['starttime'] && $_REQUEST['endtime'])
$sql = $sql->filter(array('timestamp__range' =>
array('"'.$_REQUEST['starttime'].'"', '"'.$_REQUEST['endtime'].'"', true)));
if ($data['startDate'] && $data['endDate'])
$sql = $sql->filter(array('timestamp__range' =>
array('"'.$data['startDate'].'"', '"'.$data['endDate'].'"', true)));
$sql = $sql->order_by('-timestamp');
$tableInfo = $sql;
@@ -352,42 +351,18 @@ static function audits($type, $abbrv='', $state='', $filename='', $tableInfo='',
if (!$show_viewed)
$sql = $sql->filter(Q::not(array('event_id'=>Event::getIdByName('viewed'))))->order_by('-timestamp');
// Create and store export start time
$_SESSION['export']['start'] = microtime(true);
// Store filename
$_SESSION['export']['filename'] = $filename;
// Create and store export temp name
$prefix = base64_encode(sha1(microtime(), true));
$_SESSION['export']['tempname'] = str_replace(
array('=','+','/'),
array('','-','_'),
substr($prefix, 0, 5) . $sha1);
// Create temp file to build CSV
$output = fopen(tempnam(sys_get_temp_dir(),
$_SESSION['export']['tempname']), 'w+');
// Save path in session for later
$_SESSION['export']['tempath'] = stream_get_meta_data($output)['uri'];
$delimiter = Internationalization::getCSVDelimiter();
// Output a UTF-8 BOM (byte order mark)
fputs($output, chr(0xEF) . chr(0xBB) . chr(0xBF));
fputcsv($output, $headings, $delimiter);
$exporter->write($headings);
$row = array();
foreach ($sql as $key => $value) {
if (is_object($value)) {
$description = AuditEntry::getDescription($value, true);
$value = $value->ht;
}
$row[0] = $description;
$row[1] = $value['timestamp'];
$row[1] = Format::datetime($value['timestamp']);
$row[2] = $value['ip'];
fputcsv($output, $row, $delimiter);
$exporter->write($row);
}
// Create and store export end time
$_SESSION['export']['end'] = microtime(true);
}
}
@@ -532,43 +532,6 @@ function update($vars, &$errors) {
return $this->save();
}
function update($vars, &$errors) {
$valid = true;
$forms = $this->getForms($vars);
foreach ($forms as $entry) {
if (!$entry->isValid())
$valid = false;
if ($entry->getDynamicForm()->get('type') == 'O'
&& ($f = $entry->getField('name'))
&& $f->getClean()
&& ($o=Organization::lookup(array('name'=>$f->getClean())))
&& $o->id != $this->getId()) {
$valid = false;
$f->addError(__('Organization with the same name already exists'));
}
}
if (!$valid || $errors)
return false;
// Save dynamic data.
foreach ($this->getDynamicData() as $entry) {
if ($entry->getDynamicForm()->get('type') == 'O'
&& ($name = $entry->getField('name'))
) {
$this->name = $name->getClean();
$this->save();
}
$entry->setSource($vars);
if ($entry->save())
$this->updated = SqlFunction::NOW();
}
return true;
}
function delete() {
if (!parent::delete())
return false;
@@ -1032,6 +1032,25 @@ $(document).on('click', 'a.export', function(e) {
return false;
});

$(document).on('click', 'a.nomodalexport', function(e) {
e.preventDefault();
var url = 'ajax.php/'+$(this).attr('href').substr(1);

$.ajax({
type: "GET",
url: url,
dataType: 'json',
error:function(XMLHttpRequest, textStatus, errorThrown) {
},
success: function(resp) {
var checker = 'ajax.php/export/'+resp.eid+'/check';
$.dialog(checker, 201, function (xhr) { });
return false;
}
});
return false;
});

// Forms — submit, stay on same tab
$(document).on('submit', 'form', function() {
if (!!$(this).attr('action') && $(this).attr('action').indexOf('#') == -1)

0 comments on commit 5c91dc1

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