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) { 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 = '' . '' . '' . '' . '' . '' . ''; $rowstart = ''; $dataend = '
' . __('Agent') . '' . __('Module') . '' . __('Data') . '' .__('Timestamp') . '
'; $divider = ''; $rowend = '
'; break; } //****************************************************************** // Data processing //****************************************************************** $data = array (); switch ($export_type) { case "data": case "avg": // Show header echo $datastart; foreach ($module as $selected) { $output = ""; $work_period = 120000; if ($work_period > $period) { $work_period = $period; } $work_end = $end - $period + $work_period; //Buffer to get data, anyway this will report a memory exhaustin while ($work_end <= $end) { $data = array (); // Reinitialize array for each module chunk if ($export_type == "avg") { $arr = array (); $arr["data"] = reporting_get_agentmodule_data_average ($selected, $work_period, $work_end); if ($arr["data"] === false) { 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; $output .= io_safe_output($module['agent_name']); $output .= $divider; $output .= io_safe_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; } unset($output); $output = ""; unset($data); unset($data_single); $work_end = $work_end + $work_period; } unset ($output); $output = ""; } // main foreach echo $dataend; break; } } elseif (!empty ($export_btn) && empty ($module)) { ui_print_error_message (__('No modules specified')); } if (empty($export_btn)) { echo '
'; $table->width = '98%'; $table->border = 0; $table->cellspacing = 3; $table->cellpadding = 5; $table->class = "databox_color"; $table->style[0] = 'vertical-align: top;'; $table->data = array (); //Group selector $table->data[0][0] = ''.__('Group').''; $groups = users_get_groups ($config['id_user'], "RR", users_can_manage_group_all()); $table->data[0][1] = html_print_select_groups($config['id_user'], "RR", users_can_manage_group_all(), "group", $group, '', '', 0, true, false, true, 'w130', false); //Agent selector $table->data[1][0] = ''.__('Source agent').''; if ($group > 0) { $filter['id_grupo'] = (array) $group; } else { $filter['id_grupo'] = array_keys ($groups); } $agents = array (); $rows = agents_get_agents ($filter, false, 'RR'); if ($rows == null) $rows = array(); foreach ($rows as $row) { $agents[$row['id_agente']] = $row['nombre']; } //Src code of lightning image with skins $src_code = html_print_image ('images/lightning.png', true, false, true); $params = array(); $params['return'] = true; $params['show_helptip'] = true; $params['input_name'] = 'agent'; $params['selectbox_group'] = 'group'; $params['value'] = agents_get_name ($agent); $params['javascript_is_function_select'] = true; $params['add_none_module'] = false; $params['selectbox_id'] = 'module_arr'; $table->data[1][1] = ui_print_agent_autocomplete_input($params); //Module selector $table->data[2][0] = ''.__('Modules').''; $table->data[2][0] .= ui_print_help_tip(__("No modules of type string. You can not calculate their average"),true); if ($agent > 0) { $modules = agents_get_modules ($agent); } else { $modules = array (); } if(!empty($modules)) { //remove modules of type string because you cant calculate their average. $i = 0; foreach ($modules as $key=>$module) { $id_module_type = modules_get_agentmodule_type ($key); switch ($id_module_type) { case 3: case 10: case 17: case 23: case 33: unset($modules[$i]); break; } $i++; } } $disabled_export_button = false; if (empty($modules)) { $disabled_export_button = true; } $table->data[2][1] = html_print_select ($modules, "module_arr[]", array_keys ($modules), '', '', 0, true, true, true, 'w155', false); //Start date selector $table->data[3][0] = ''.__('Begin date').''; $table->data[3][1] = html_print_input_text ('start_date', date ("Y-m-d", get_system_time () - 86400), false, 10, 10, true); $table->data[3][1] .= html_print_image ("images/calendar_view_day.png", true, array ("alt" => "calendar", "onclick" => "scwShow(scwID('text-start_date'),this);")); $table->data[3][1] .= html_print_input_text ('start_time', date ("H:i", get_system_time () - 86400), false, 10, 5, true); //End date selector $table->data[4][0] = ''.__('End date').''; $table->data[4][1] = html_print_input_text ('end_date', date ("Y-m-d", get_system_time ()), false, 10, 10, true); $table->data[4][1] .= html_print_image ("images/calendar_view_day.png", true, array ("alt" => "calendar", "onclick" => "scwShow(scwID('text-end_date'),this);")); $table->data[4][1] .= html_print_input_text ('end_time', date ("H:i", get_system_time ()), false, 10, 5, true); //Export type $table->data[5][0] = ''.__('Export type').''; $export_types = array (); $export_types["data"] = __('Data table'); $export_types["csv"] = __('CSV'); $export_types["excel"] = __('MS Excel'); $export_types["avg"] = __('Average per hour/day'); $table->data[5][1] = html_print_select ($export_types, "export_type", $export_type, '', '', 0, true, false, true, 'w130', false); html_print_table ($table); // Submit button echo '
'; html_print_button (__('Export'), 'export_btn', false, 'change_action()', 'class="sub wand"'); echo '
'; } ui_require_jquery_file ('pandora.controls'); ui_require_jquery_file ('ajaxqueue'); ui_require_jquery_file ('bgiframe'); ?>