'0' , 'text' => 'Export as HTML (ideal for on-screen viewing)', 'format' => 'HTML'); // review on screen
$available_export_formats[1] = array('id' => '1' , 'text' => 'Export to CSV (ideal for importing to spreadsheets)', 'format' => 'CSV'); // export to CSV
// $available_export_formats[2]=array('id' => '2', 'text' => 'Export to TXT', 'format' => 'TXT');
// $available_export_formats[3]=array('id' => '3', 'text' => 'Export to XML', 'format' => 'XML');
$save_to_file_checked = (isset($_POST['savetofile']) && zen_not_null($_POST['savetofile']) ? $_POST['savetofile'] : 0);
$post_format = (isset($_POST['format']) && zen_not_null($_POST['format']) ? $_POST['format'] : 1);
$format = $available_export_formats[$post_format]['format'];
$file = (isset($_POST['filename']) ? preg_replace('/[^\w\.-]/', '', $_POST['filename']) : 'admin_activity_archive_' . date('Y-m-d_H-i-s') . '.csv');
zen_set_time_limit(600);
if ($action != '')
{
$NL = "\n";
$limit = '';
if ($perpage > 0 || $start > 0)
{
$limit = ' LIMIT ';
if ($start > 0) $limit .= (int)$start;
if ($start > 0 && $perpage > 0) $limit .= ', ';
if ($perpage > 0) $limit .= (int)$perpage;
}
$sort = '';
switch ($action)
{
case 'save':
global $db;
if ($format == 'CSV')
{
$FIELDSTART = '"';
$FIELDEND = '"';
$FIELDSEPARATOR = ',';
$LINESTART = '';
$LINEBREAK = "\n";
$sort = ' ASC ';
$limit = '';
}
if ($format == 'TXT')
{
$FIELDSTART = '';
$FIELDEND = '';
$FIELDSEPARATOR = "\t";
$LINESTART = '';
$LINEBREAK = "\n";
$sort = ' ASC ';
}
if ($format == 'HTML')
{
$FIELDSTART = '
';
$FIELDEND = ' | ';
$FIELDSEPARATOR = "";
$LINESTART = "";
$LINEBREAK = "
" . $NL;
$sort = ' DESC ';
}
$sql = "select a.access_date, a.admin_id, u.admin_name, a.ip_address, a.page_accessed, a.page_parameters, a.gzpost, a.flagged, a.attention
FROM " . TABLE_ADMIN_ACTIVITY_LOG . " a LEFT OUTER JOIN " . TABLE_ADMIN . " u ON a.admin_id = u.admin_id ORDER BY access_date " . $sort . $limit;
$result = $db->Execute($sql);
$records = $result->RecordCount();
if ($records == 0)
{
$messageStack->add("No Records Found.", 'error');
} else
{ //process records
$i = 0;
// make a tag if HTML output
if ($format == "HTML")
{
$exporter_output .= '' . $NL;
}
// add column headers if CSV or HTML format
if ($format == "CSV" || $format == "HTML")
{
$exporter_output .= $LINESTART;
$exporter_output .= $FIELDSTART . "timestamp" . $FIELDEND;
$exporter_output .= $FIELDSEPARATOR;
$exporter_output .= $FIELDSTART . "admin_user" . $FIELDEND;
$exporter_output .= $FIELDSEPARATOR;
$exporter_output .= $FIELDSTART . "ip_address" . $FIELDEND;
$exporter_output .= $FIELDSEPARATOR;
$exporter_output .= $FIELDSTART . "page_accessed" . $FIELDEND;
$exporter_output .= $FIELDSEPARATOR;
$exporter_output .= $FIELDSTART . "parameters" . $FIELDEND;
$exporter_output .= $FIELDSEPARATOR;
$exporter_output .= $FIELDSTART . "flagged" . $FIELDEND;
$exporter_output .= $FIELDSEPARATOR;
$exporter_output .= $FIELDSTART . "attention" . $FIELDEND;
$exporter_output .= $FIELDSEPARATOR;
$exporter_output .= $FIELDSTART . "postdata" . $FIELDEND;
$exporter_output .= $LINEBREAK;
}
// headers - XML
if ($format == "XML")
{
$exporter_output .= '' . "\n";
}
// output real data
while (! $result->EOF)
{
$i ++;
$postoutput = '';
if ($format == "XML")
{
$postoutput = nl2br(print_r(json_decode(@gzinflate($result->fields['gzpost'])), true));
$exporter_output .= "\n";
$exporter_output .= " \n";
$exporter_output .= " " . $result->fields['access_date'] . "\n";
$exporter_output .= " " . $result->fields['admin_id'] . "\n";
$exporter_output .= " " . htmlspecialchars($result->fields['admin_name'], ENT_COMPAT, CHARSET, TRUE) . "\n";
$exporter_output .= " " . $result->fields['ip_address'] . "\n";
$exporter_output .= " " . $result->fields['page_accessed'] . "\n";
$exporter_output .= " " . htmlspecialchars($result->fields['page_parameters'], ENT_COMPAT, CHARSET, TRUE) . "\n";
$exporter_output .= " " . htmlspecialchars($result->fields['flagged'], ENT_COMPAT, CHARSET, TRUE) . "\n";
$exporter_output .= " " . htmlspecialchars($result->fields['attention'], ENT_COMPAT, CHARSET, TRUE) . "\n";
$exporter_output .= " " . $postoutput . "\n";
$exporter_output .= "
\n";
} else
{ // output non-XML data-format
$postoutput = print_r(json_decode(@gzinflate($result->fields['gzpost'])), true);
if ($format == 'HTML') {
$postoutput = nl2br(zen_output_string_protected($postoutput));
} else {
$postoutput = nl2br($postoutput);
}
$exporter_output .= $LINESTART;
$exporter_output .= $FIELDSTART . $result->fields['access_date'] . $FIELDEND;
$exporter_output .= $FIELDSEPARATOR;
$exporter_output .= $FIELDSTART . $result->fields['admin_id'] . ' ' . $result->fields['admin_name'] . $FIELDEND;
$exporter_output .= $FIELDSEPARATOR;
$exporter_output .= $FIELDSTART . $result->fields['ip_address'] . $FIELDEND;
$exporter_output .= $FIELDSEPARATOR;
$exporter_output .= $FIELDSTART . $result->fields['page_accessed'] . $FIELDEND;
$exporter_output .= $FIELDSEPARATOR;
$exporter_output .= $FIELDSTART . $result->fields['page_parameters'] . $FIELDEND;
$exporter_output .= $FIELDSEPARATOR;
$exporter_output .= $FIELDSTART . $result->fields['flagged'] . $FIELDEND;
$exporter_output .= $FIELDSEPARATOR;
$exporter_output .= $FIELDSTART . $result->fields['attention'] . $FIELDEND;
$exporter_output .= $FIELDSEPARATOR;
$exporter_output .= $FIELDSTART . $postoutput . $FIELDEND;
$exporter_output .= $LINEBREAK;
}
$result->MoveNext();
}
if ($format == "HTML")
{
$exporter_output .= $NL . "
";
}
if ($format == "XML")
{
$exporter_output .= "\n";
}
// theoretically, $i should == $records at this point.
// status message
if ($format != "HTML") $messageStack->add($records . TEXT_PROCESSED, 'success');
// begin streaming file contents
if ($save_to_file_checked != 1)
{ // not saving to a file, so do regular output
if ($format == "CSV" || $format == "TXT" || $format == "XML")
{
if ($format == "CSV" || $format == "TXT")
{
$content_type = 'text/x-csv';
} elseif ($format == "XML")
{
$content_type = 'text/xml; charset=' . CHARSET;
}
if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT']))
{
header('Content-Type: application/octetstream');
// header('Content-Type: '.$content_type);
// header('Content-Disposition: inline; filename="' . $file . '"');
header('Content-Disposition: attachment; filename=' . $file);
header("Expires: Mon, 26 Jul 2001 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: must_revalidate, post-check=0, pre-check=0");
header("Pragma: public");
header("Cache-control: private");
} else
{
header('Content-Type: application/x-octet-stream');
// header('Content-Type: '.$content_type);
header('Content-Disposition: attachment; filename=' . $file);
header("Expires: Mon, 26 Jul 2001 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Pragma: no-cache");
}
echo $exporter_output;
exit();
} else
{
// HTML
?>
>
add_session(SUCCESS_EXPORT_ADMIN_ACTIVITY_LOG . $file, 'success');
} else {
$messageStack->add_session(FAILURE_EXPORT_ADMIN_ACTIVITY_LOG . $file, 'error');
}
unset($f);
} // endif $save_to_file
} //end if $records for processing not 0
zen_redirect(zen_href_link(FILENAME_ADMIN_ACTIVITY));
break;
// clean out the admin_activity_log
case 'clean_admin_activity_log':
if (isset($_POST['confirm']) && $_POST['confirm'] == 'yes')
{
$db->Execute("truncate table " . TABLE_ADMIN_ACTIVITY_LOG);
$admname = '{' . preg_replace('/[^\w]/', '*', zen_get_admin_name()) . '[' . (int)$_SESSION['admin_id'] . ']}';
$sql_data_array = array( 'access_date' => 'now()',
'admin_id' => (isset($_SESSION['admin_id'])) ? (int)$_SESSION['admin_id'] : 0,
'page_accessed' => 'Log reset by ' . $admname . '.',
'page_parameters' => '',
'ip_address' => substr($_SERVER['REMOTE_ADDR'],0,45)
);
zen_db_perform(TABLE_ADMIN_ACTIVITY_LOG, $sql_data_array);
$messageStack->add_session(SUCCESS_CLEAN_ADMIN_ACTIVITY_LOG, 'success');
unset($_SESSION['reset_admin_activity_log']);
zen_redirect(zen_href_link(FILENAME_ADMIN_ACTIVITY));
} else {
$confirmation_needed = TRUE;
}
break;
} //end switch / case
} //endif $action
?>
>
|
|
|
|
|
|
|
|
|
' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . ''; ?> |
|
|
align="left" valign="top"> |
' . zen_image_button('button_reset.gif', IMAGE_RESET) . ''; ?> |
|
|
|