diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 4a61d3b81a..fcf83ad426 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,13 @@ +2011-12-02 Sergio Martin + + * include/functions_modules.php + include/functions.php + extensions/snmp_explorer.php + godmode/agentes/configurar_agente.php + godmode/massive/massive_edit_modules.php: Check if a module + name exists in the agent when you edit the module and + improve the errors feedback + 2011-12-02 Sergio Martin * include/functions_modules.php diff --git a/pandora_console/extensions/snmp_explorer.php b/pandora_console/extensions/snmp_explorer.php index 67d7abd65d..7d2d0a48d3 100755 --- a/pandora_console/extensions/snmp_explorer.php +++ b/pandora_console/extensions/snmp_explorer.php @@ -240,7 +240,7 @@ function snmp_explorer() { case ERR_DB: case ERR_GENERIC: default: - $msg .= '
'.__('Processing errors')." ($number)"; + $msg .= '
'.__('Processing error')." ($number)"; break; } diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 0dc303eb0d..ec4edcb72f 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -742,8 +742,28 @@ if ($update_module) { $values, false, $id_tag); } - if ($result === false) { - echo '

'.__('There was a problem updating module').'

'; + if (is_error($result)) { + $msg = __('There was a problem updating module').'. '; + + switch($result) { + case ERR_EXIST: + $msg .= __('Another module already exists with the same name').'.'; + break; + case ERR_INCOMPLETE: + $msg .= __('Some required fields are missed').': ('.__('name').')'; + break; + case ERR_NOCHANGES: + $msg .= __('"No change"'); + break; + case ERR_DB: + case ERR_GENERIC: + default: + $msg .= __('Processing error'); + break; + } + $result = false; + echo '

'.$msg.'

'; + $edit_module = true; db_pandora_audit("Agent management", @@ -841,7 +861,7 @@ if ($create_module) { case ERR_DB: case ERR_GENERIC: default: - // No more info + $msg .= __('Processing error'); break; } $id_agent_module = false; diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index b0d2a60344..54621b72bc 100644 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -73,7 +73,7 @@ else { foreach ($modules as $module) { $result = modules_update_agent_module ($module['id_agente_modulo'], $values, true, $update_tags); - if ($result === false) { + if (is_error($result)) { db_process_sql_rollback (); return false; diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 5a644ffe05..0e41db28f2 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -48,6 +48,8 @@ define ('ERR_DB', -40000); define ('ERR_FILE', -50000); +define ('ERR_NOCHANGES', -60000); + /* Visual console constants */ define("MIN_WIDTH",300); define("MIN_HEIGHT",120); @@ -1119,7 +1121,7 @@ function is_ajax () { * @return bool true if a result code is an error or false otherwise */ function is_error($code) { - if($code <= ERR_GENERIC) { + if($code !== true AND ($code <= ERR_GENERIC || $code === false)) { return true; } else { diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 54f6e95818..4d5e75bc63 100644 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -194,28 +194,47 @@ function modules_delete_agent_module ($id_agent_module) { * * @return True if the module was updated. False if not. */ -function modules_update_agent_module ($id, $values, $onlyNoDeletePending = false, - $tags = false) { - if (! is_array ($values) || empty ($values)) - return false; - - if (isset ($values['nombre']) && empty ($values['nombre'])) - return false; - - if ($tags !== false) - $return_tag = tags_update_module_tag ($id, $tags); - -// if ($return_tag === false){ -// return false; -// } - - if ($onlyNoDeletePending) { - return (@db_process_sql_update ('tagente_modulo', $values, - array ('id_agente_modulo' => (int) $id, 'delete_pending' => 0)) !== false); +function modules_update_agent_module ($id, $values, $onlyNoDeletePending = false, $tags = false) { + if (!is_array ($values) || empty ($values)) { + return ERR_GENERIC; } - else { - return (@db_process_sql_update ('tagente_modulo', $values, - array ('id_agente_modulo' => (int) $id)) !== false); + + if (isset ($values['nombre'])) { + if(empty ($values['nombre'])) { + return ERR_INCOMPLETE; + } + + $id_agent = modules_get_agentmodule_agent($id); + + $exists = (bool)db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('nombre' => $values['nombre'], 'id_agente' => $id_agent, 'id_agente_modulo' => "<>$id")); + + if($exists) { + return ERR_EXIST; + } + } + + $return_tag = true; + if ($tags !== false) { + $return_tag = tags_update_module_tag ($id, $tags); + } + + if ($return_tag === false){ + return ERR_DB; + } + + $where = array(); + $where['id_agente_modulo'] = $id; + if ($onlyNoDeletePending) { + $where['delete_pending'] = 0; + } + + $result = @db_process_sql_update ('tagente_modulo', $values, $where); + + if($result === false) { + return ERR_DB; + } + else { + return true; } }