0);
//Convert start time and end time to unix timestamps
$start = strtotime ($start_date." ".$start_time);
$end = strtotime ($end_date." ".$end_time);
$period = $end - $start;
$data = array ();
//If time is negative or zero, don't process - it's invalid
if ($start < 1 || $end < 1) {
print_error_message (__('Invalid time specified'));
return;
}
// ***************************************************
// Starts, ends and dividers
// ***************************************************
switch ($export_type) {
case "data":
case "avg":
default:
//HTML output - don't style or use XHTML just in case somebody needs to copy/paste it. (Office doesn't handle and
)
$datastart = ''.__('Agent').' | '.__('Module').' | '.__('Data').' | '.__('Timestamp').' |
';
$rowstart = '';
$divider = ' | ';
$rowend = ' |
';
$dataend = '
';
break;
case "excel":
//Excel is tab-delimited, needs quotes and needs Windows-style newlines
$datastart = __('Agent')."\t".__('Module')."\t".__('Data')."\t".__('Timestamp')."\r\n";
$rowstart = '"';
$divider = '"'."\t".'"';
$rowend = '"'."\r\n";
$dataend = "\r\n";
$extension = "xls";
break;
case "csv":
//Pure CSV is comma delimited
$datastart = __('Agent').','.__('Module').','.__('Data').','.__('Timestamp')."\n";
$rowstart = '"';
$divider = '","';
$rowend = '"'."\n";
$dataend = "\n";
$extension = "csv";
break;
}
// ***************************************************
// Header output
// ***************************************************
switch ($export_type) {
case "excel":
case "csv":
$config['ignore_callback'] = true;
while (@ob_end_clean ());
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=export_".date("Ymd", $start)."_".date("Ymd", $end).".".$extension);
header("Pragma: no-cache");
header("Expires: 0");
}
// ***************************************************
// Data processing
// ***************************************************
$data = array ();
switch ($export_type) {
case "data":
case "excel":
case "csv":
// Show header
echo $datastart;
foreach ($module as $selected) {
$output = "";
$work_period = 120000;
$work_end = $end - $period + $work_period;
//Buffer to get data, anyway this will report a memory exhaustin
while ( $work_end < $end) {
$work_end = $work_end + $work_period;
$data = array (); // Reinitialize array for each module chunk
$data_single = get_agentmodule_data ($selected, $work_period, $work_end);
if (!empty ($data_single)) {
$data = array_merge ($data, $data_single);
}
/*
if ($work_end > $end) {
$work_period = $work_end - $end;
$work_end = $end;
}
*/
foreach ($data as $key => $module) {
$output .= $rowstart;
$output .= $module['agent_name'];
$output .= $divider;
$output .= $module['module_name'];
$output .= $divider;
$output .= $module['data'];
$output .= $divider;
$output .= date ("Y-m-d g:i:s", $module['utimestamp']);
$output .= $rowend;
}
switch ($export_type) {
default:
case "data":
case "avg":
echo $output;
break;
case "excel":
case "csv":
echo $output;
break;
}
unset($output);
$output = "";
unset($data);
unset($data_single);
}
unset ($output);
$output = "";
} // main foreach
echo $dataend;
break;
case "avg":
foreach ($module as $selected) {
$arr = array ();
$arr["data"] = get_agentmodule_data_average ($selected, $period, $end);
if ($arr["data"] === false) {
continue;
}
$arr["module_name"] = get_agentmodule_name ($selected);
$arr["agent_name"] = get_agentmodule_agent_name ($selected);
$arr["agent_id"] = get_agentmodule_agent ($selected);
$arr["utimestamp"] = $end;
array_push ($data, $arr);
}
break;
default:
print_error_message (__('Invalid method supplied'));
return;
break;
}
switch ($export_type) {
case "excel":
case "csv":
exit; // Necesary for CSV export, if not give problems
break;
default:
return;
}
} elseif (!empty ($export_btn) && empty ($module)) {
print_error_message (__('No modules specified'));
}
echo '';
require_jquery_file ('pandora.controls');
require_jquery_file ('ajaxqueue');
require_jquery_file ('bgiframe');
require_jquery_file ('autocomplete');
?>