$id_downtime, 'id_agent' => $id_agente_dt, 'all_modules' => $all_modules); $result = db_process_sql_insert('tplanned_downtime_agents', $values); if ($result && !$all_modules) { foreach ($module_names as $module_name) { $module = modules_get_agentmodule_id($module_name, $id_agente_dt); $values = array( 'id_downtime' => $id_downtime, 'id_agent' => $id_agente_dt, 'id_agent_module' => $module["id_agente_modulo"]); $result = db_process_sql_insert('tplanned_downtime_modules', $values); if ($result) { $values = array('id_user' => $config['id_user']); $result = db_process_sql_update('tplanned_downtime', $values, array('id' => $id_downtime)); } } } } } // DELETE A DOWNTIME_AGENT ASSOCIATION if ($delete_downtime_agent == 1) { $id_da = (int)get_parameter ("id_downtime_agent", 0); $id_agent_delete = (int)get_parameter('id_agent', 0); $row_to_delete = db_get_row('tplanned_downtime_agents', 'id', $id_da); $result = db_process_sql_delete('tplanned_downtime_agents', array('id' => $id_da)); if ($result) { //Delete modules in downtime db_process_sql_delete('tplanned_downtime_modules', array('id_downtime' => $row_to_delete['id_downtime'], 'id_agent' => $id_agent_delete)); } } // UPDATE OR CREATE A DOWNTIME (MAIN DATA, NOT AGENT ASSOCIATION) if ($create_downtime || $update_downtime) { $check = db_get_value ('name', 'tplanned_downtime', 'name', $name); $datetime_from = strtotime ($once_date_from . ' ' . $once_time_from); $datetime_to = strtotime ($once_date_to . ' ' . $once_time_to); if (($type_periodicity == 'once') && ($datetime_from >= $datetime_to)) { ui_print_error_message(__('Not created. Error inserting data' ). ': START >= END'); } else { $sql = ''; if ($create_downtime) { if (trim(io_safe_output($name)) != '') { if (!$check) { $values = array( 'name' => $name, 'description' => $description, 'date_from' => $datetime_from, 'date_to' => $datetime_to, 'executed' => 0, 'id_group' => $id_group, 'only_alerts' => 0, 'monday' => $monday, 'tuesday' => $tuesday, 'wednesday' => $wednesday, 'thursday' => $thursday, 'friday' => $friday, 'saturday' => $saturday, 'sunday' => $sunday, 'periodically_time_from' => $periodically_time_from, 'periodically_time_to' => $periodically_time_to, 'periodically_day_from' => $periodically_day_from, 'periodically_day_to' => $periodically_day_to, 'type_downtime' => $type_downtime, 'type_execution' => $type_execution, 'type_periodicity' => $type_periodicity, 'id_user' => $config['id_user'] ); $result = db_process_sql_insert( 'tplanned_downtime', $values); } else { ui_print_error_message( __('Each planned downtime must have a different name')); } } else { ui_print_error_message( __('Planned downtime must have a name')); } } else if ($update_downtime) { if (trim(io_safe_output($name)) != '') { $values = array( 'name' => $name, 'description' => $description, 'date_from' => $datetime_from, 'date_to' => $datetime_to, 'executed' => 0, 'id_group' => $id_group, 'only_alerts' => 0, 'monday' => $monday, 'tuesday' => $tuesday, 'wednesday' => $wednesday, 'thursday' => $thursday, 'friday' => $friday, 'saturday' => $saturday, 'sunday' => $sunday, 'periodically_time_from' => $periodically_time_from, 'periodically_time_to' => $periodically_time_to, 'periodically_day_from' => $periodically_day_from, 'periodically_day_to' => $periodically_day_to, 'type_downtime' => $type_downtime, 'type_execution' => $type_execution, 'type_periodicity' => $type_periodicity, 'id_user' => $config['id_user'] ); $result = db_process_sql_update('tplanned_downtime', $values, array('id' => $id_downtime)); } else { ui_print_error_message( __('Planned downtime must have a name')); } } if ($result === false) { if ($create_downtime) { ui_print_error_message(__('Could not be created')); } else { ui_print_error_message(__('Could not be updated')); } } else { if ($create_downtime && $name && !$check) { $id_downtime = $result; ui_print_success_message(__('Successfully created')); } else if ($update_downtime && $name) { ui_print_success_message(__('Successfully updated')); } } } } // Have any data to show ? if ($id_downtime > 0) { switch ($config["dbtype"]) { case "mysql": $sql = sprintf ("SELECT * FROM `tplanned_downtime` WHERE `id` = %d", $id_downtime); break; case "postgresql": $sql = sprintf ("SELECT * FROM \"tplanned_downtime\" WHERE \"id\" = %d", $id_downtime); break; case "oracle": $sql = sprintf ("SELECT * FROM tplanned_downtime WHERE id = %d", $id_downtime); break; } $result = db_get_row_sql ($sql); $name = $result["name"]; $description = $result["description"]; $once_date_from = date(DATE_FORMAT, $result["date_from"]); $once_date_to = date(DATE_FORMAT, $result["date_to"]); $once_time_from = date(TIME_FORMAT, $result["date_from"]); $once_time_to = date(TIME_FORMAT, $result["date_to"]); $monday = $result['monday']; $tuesday = $result['tuesday']; $wednesday = $result['wednesday']; $thursday = $result['thursday']; $friday = $result['friday']; $saturday = $result['saturday']; $sunday = $result['sunday']; $periodically_time_from = $result['periodically_time_from']; $periodically_time_to = $result['periodically_time_to']; $periodically_day_from = $result['periodically_day_from']; $periodically_day_to = $result['periodically_day_to']; $type_downtime = $result['type_downtime']; $type_execution = $result['type_execution']; $type_periodicity = $result['type_periodicity']; if ($id_group == 0) $id_group = $result['id_group']; } $table->class = 'databox_color'; $table->width = '98%'; $table->data = array (); $table->data[0][0] = __('Name'); $table->data[0][1] = html_print_input_text ('name', $name, '', 25, 40, true); $table->data[1][0] = __('Group'); $table->data[1][1] = html_print_select_groups(false, "AW", true, 'id_group', $id_group, '', '', 0, true); $table->data[2][0] = __('Description'); $table->data[2][1] = html_print_textarea ('description', 3, 35, $description, '', true); $table->data[3][0] = __('Type'); $table->data[3][1] = html_print_select(array('quiet' => __('Quiet'), 'disable_agents' => __('Disabled Agents'), 'disable_agents_alerts' => __('Disabled only Alerts')), 'type_downtime', $type_downtime, 'change_type_downtime()', '', 0, true, false, true, ''); $table->data[4][0] = __('Execution'); $table->data[4][1] = html_print_select(array('once' => __('once'), 'periodically' => __('Periodically')), 'type_execution', $type_execution, 'change_type_execution();', '', 0, true); $days = array_combine(range(1, 31), range(1, 31)); $table->data[5][0] = __('Configure the time'); $table->data[5][1] = " "; echo '
'; if ($id_downtime > 0) { echo ""; echo "
"; } //Editor form html_print_table ($table); html_print_input_hidden ('id_agent', $id_agent); echo '
'; if ($id_downtime) { html_print_input_hidden ('update_downtime', 1); html_print_input_hidden ('id_downtime', $id_downtime); html_print_submit_button (__('Update'), 'updbutton', false, 'class="sub upd"'); } else { html_print_input_hidden ('create_downtime', 1); html_print_submit_button (__('Add'), 'crtbutton', false, 'class="sub wand"'); } echo '
'; echo ''; if ($id_downtime > 0) { echo "
"; // Show available agents to include into downtime echo '

' . __('Available agents') . ':

'; $filter_group = get_parameter("filter_group", 0); $filter_cond = ''; if($filter_group > 0) $filter_cond = " AND id_grupo = $filter_group "; $sql = sprintf ("SELECT tagente.id_agente, tagente.nombre, tagente.id_grupo FROM tagente WHERE tagente.id_agente NOT IN ( SELECT tagente.id_agente FROM tagente, tplanned_downtime_agents WHERE tplanned_downtime_agents.id_agent = tagente.id_agente AND tplanned_downtime_agents.id_downtime = %d ) AND disabled = 0 $filter_cond ORDER by tagente.nombre", $id_downtime); $downtimes = db_get_all_rows_sql ($sql); $data = array (); if ($downtimes) { foreach ($downtimes as $downtime) { if (check_acl ($config["id_user"], $downtime['id_grupo'], "AW")) { $data[$downtime['id_agente']] = $downtime['nombre']; } } } $disabled_add_button = false; if (empty($data)) { $disabled_add_button = true; } echo "
"; html_print_select_groups(false, "AW", true, 'filter_group', $filter_group, '', '', '', false, false, true, '', false, 'width:180px'); echo "

"; html_print_submit_button (__('Filter by group'), '', false, 'class="sub next"',false); echo "
"; echo "
"; echo html_print_select ($data, "id_agents[]", '', '', '', 0, false, true, true, '', false, 'width: 180px;'); echo '

' . __('Available modules:') . ui_print_help_tip (__('Only for type Quiet for downtimes.'), true) . '

'; if ($type_downtime != 'quiet') echo '
"; //Start Overview of existing planned downtime echo '

'.__('Agents planned for this downtime').':

'; $sql = sprintf ("SELECT tagente.nombre, tplanned_downtime_agents.id, tagente.id_os, tagente.id_agente, tagente.id_grupo, tagente.ultimo_contacto, tplanned_downtime_agents.all_modules FROM tagente, tplanned_downtime_agents WHERE tplanned_downtime_agents.id_agent = tagente.id_agente AND tplanned_downtime_agents.id_downtime = %d ", $id_downtime); $downtimes = db_get_all_rows_sql ($sql); if ($downtimes === false) { echo '
' . __('There are no scheduled downtimes') . '
'; } else { $table->id = 'list'; $table->class = 'databox'; $table->width = '98%'; $table->data = array (); $table->head = array (); $table->head[0] = __('Name'); $table->head[1] = __('Group'); $table->head[2] = __('OS'); $table->head[3] = __('Last contact'); $table->head['count_modules'] = __('Modules'); $table->head[5] = __('Actions'); $table->align[5] = "center"; $table->size[5] = "5%"; foreach ($downtimes as $downtime) { $data = array (); $data[0] = $downtime['nombre']; $data[1] = db_get_sql ("SELECT nombre FROM tgrupo WHERE id_grupo = " . $downtime["id_grupo"]); $data[2] = ui_print_os_icon($downtime["id_os"], true, true); $data[3] = $downtime["ultimo_contacto"]; if ($type_downtime == 'disable_agents_alerts') { $data['count_modules'] = __("All alerts"); } elseif ($type_downtime == 'disable_agents') { $data['count_modules'] = __("Entire agent"); } else { if ($downtime["all_modules"]) { $data['count_modules'] = __("All modules"); } else { $data['count_modules'] = __("Some modules"); } } $data[5] = ''; if (($type_downtime != 'disable_agents_alerts') && ($type_downtime != 'disable_agents')) { $data[5] = '' . html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Delete'))) . ""; } $data[5] .= '' . html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete'))) . ""; $table->data['agent_' . $downtime["id_agente"]] = $data; } html_print_table ($table); } } $table = null; $table->id = 'loading'; $table->colspan['loading'][0] = '6'; $table->style[0] = 'text-align: center;'; $table->data = array(); $table->data['loading'] = array(); $table->data['loading'][0] = html_print_image("images/spinner.gif", true); echo "
"; html_print_table ($table); echo "
"; $table = null; $table->id = 'editor'; $table->colspan['module'][1] = '5'; $table->data = array(); $table->data['module'] = array(); $table->data['module'][0] = ''; $table->data['module'][1] = "

" . __('Modules') . "

"; //List of modules, empty, it is populated by javascript. $table->data['module'][1] = "
" . __('Module') . " " . __('Action') . "
" . __("Add Module:") . ' ' . html_print_select(array(), 'modules', '', '', '', 0, true) . " " . '' . "" . "
"; echo "
"; html_print_table ($table); echo "
"; echo "
"; echo "
"; html_print_image("images/spinner.gif"); echo "
"; echo "
"; echo ""; echo ""; echo ""; ui_require_jquery_file ("ui-timepicker-addon"); // This script is included manually to be included after jquery and avoid error echo ''; ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascript/i18n/"); ?>