[]];
// Convert start time and end time to unix timestamps.
// The date/time will have the user's timezone,
// so we need to change it to the system's timezone.
$fixed_offset = get_fixed_offset();
$start = (strtotime($start_date.' '.$start_time) - $fixed_offset);
$end = (strtotime($end_date.' '.$end_time) - $fixed_offset);
$period = ($end - $start);
$data = [];
// If time is negative or zero, don't process - it's invalid
if ($start < 1 || $end < 1) {
ui_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;
}
// ******************************************************************
// Data processing
// ******************************************************************
$data = [];
switch ($export_type) {
case 'data':
case 'avg':
// Show header
echo $datastart;
foreach ($module as $selected) {
$output = '';
$work_period = SECONDS_1DAY;
if ($work_period > $period) {
$work_period = $period;
}
$work_end = ($end - $period + $work_period);
$work_start = ($work_end - $work_period);
// Buffer to get data, anyway this will report a memory exhaustin
$flag_last_time_slice = false;
while ($work_end <= $end) {
$data = [];
// Reinitialize array for each module chunk
if ($export_type == 'avg') {
$arr = [];
$arr['data'] = reporting_get_agentmodule_data_average(
$selected,
$work_period,
$work_end
);
if ($arr['data'] === false) {
$work_end = ($work_end + $work_period);
continue;
}
$arr['module_name'] = modules_get_agentmodule_name($selected);
$arr['agent_name'] = modules_get_agentmodule_agent_name($selected);
$arr['agent_id'] = modules_get_agentmodule_agent($selected);
$arr['utimestamp'] = $end;
array_push($data, $arr);
} else {
$data_single = modules_get_agentmodule_data(
$selected,
$work_period,
$work_end
);
if (!empty($data_single)) {
$data = array_merge($data, $data_single);
}
}
foreach ($data as $key => $module) {
$output .= $rowstart;
$alias = db_get_value('alias', 'tagente', 'id_agente', $module['agent_id']);
$output .= io_safe_output($alias);
$output .= $divider;
$output .= io_safe_output($module['module_name']);
$output .= $divider;
$output .= $module['data'];
$output .= $divider;
switch ($export_type) {
case 'data':
// Change from the system's timezone to the user's timezone
$output .= date('Y-m-d G:i:s', ($module['utimestamp'] + $fixed_offset));
break;
case 'avg':
// Change from the system's timezone to the user's timezone
$output .= date('Y-m-d G:i:s', ($work_start + $fixed_offset)).' - '.date('Y-m-d G:i:s', ($work_end + $fixed_offset));
break;
}
$output .= $rowend;
}
switch ($export_type) {
default:
case 'data':
case 'avg':
echo $output;
break;
}
unset($output);
$output = '';
unset($data);
unset($data_single);
// The last time slice is executed now exit of
// while loop
if ($flag_last_time_slice) {
break;
}
if (($work_end + $work_period) > $end || $work_period == 0) {
// Get the last timelapse
$work_period = ($end - $work_end);
$work_end = $end;
$flag_last_time_slice = true;
} else {
$work_end = ($work_end + $work_period);
}
$work_start = ($work_end - $work_period);
}
unset($output);
$output = '';
} //end foreach
echo $dataend;
break;
}
} else if (!empty($export_btn) && empty($module)) {
ui_print_error_message(__('No modules specified'));
$show_form = true;
}
if (empty($export_btn) || $show_form) {
echo '';
}
ui_require_jquery_file('pandora.controls');
ui_require_jquery_file('ajaxqueue');
ui_require_jquery_file('bgiframe');
?>