$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 '