diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 3cc3c55be1..b9584fc757 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,18 @@ +2013-02-07 Miguel de Dios + + * include/functions_ui.php, include/ajax/agent.php: improved the + widget of autocomplete agent, now show first the agents with same + name to the search, second block with the agents with the address + same to the search and the last block is the agents with the + description with the same to the search. + + Fixes: #3603692 + + * godmode/modules/manage_nc_groups.php, + godmode/modules/manage_network_templates.php, + godmode/modules/manage_network_templates_form.php: improved the code + style. + 2013-02-07 Miguel de Dios * godmode/db/db_refine.php, godmode/servers/plugin.php: improved diff --git a/pandora_console/godmode/modules/manage_nc_groups.php b/pandora_console/godmode/modules/manage_nc_groups.php index fd30ad0ab8..c18050d2ec 100644 --- a/pandora_console/godmode/modules/manage_nc_groups.php +++ b/pandora_console/godmode/modules/manage_nc_groups.php @@ -129,7 +129,7 @@ if ($multiple_delete) { $result = db_process_sql_delete ('tnetwork_component_group', array ('id_sg' => $id)); - $result1 = db_process_sql_update('tnetwork_component_group', array('parent' => 0), array('parent' => $id)); + $result1 = db_process_sql_update('tnetwork_component_group', array('parent' => 0), array('parent' => $id)); if (($result === false) or ($result1 === false)) { db_process_sql_rollback(); @@ -210,10 +210,10 @@ $total_groups = $total_groups[0]['total']; foreach ($groups as $group) { $data = array (); - $tabulation = str_repeat('    ', $group['deep']); + $tabulation = str_repeat('    ', $group['deep']); $data[0] = $tabulation . ''.$group['name'].''; - + $data[1] = "" . html_print_image('images/cross.png', true, array('title' => __('Delete'))) . "" . @@ -222,7 +222,7 @@ foreach ($groups as $group) { array_push ($table->data, $data); } -if(isset($data)) { +if (isset($data)) { echo "
"; html_print_input_hidden('multiple_delete', 1); html_print_table ($table); diff --git a/pandora_console/godmode/modules/manage_network_templates.php b/pandora_console/godmode/modules/manage_network_templates.php index cf792a904c..f68331b29e 100644 --- a/pandora_console/godmode/modules/manage_network_templates.php +++ b/pandora_console/godmode/modules/manage_network_templates.php @@ -227,7 +227,7 @@ if (!empty ($table->data)) { echo "
"; } else { - echo '
'.__('There are no defined network profiles').'
'; + echo '
'.__('There are no defined network profiles').'
'; } echo '
'; diff --git a/pandora_console/godmode/modules/manage_network_templates_form.php b/pandora_console/godmode/modules/manage_network_templates_form.php index 96e5490883..94c9aba32f 100644 --- a/pandora_console/godmode/modules/manage_network_templates_form.php +++ b/pandora_console/godmode/modules/manage_network_templates_form.php @@ -251,9 +251,9 @@ if ($id_np > 0) { $groups = array (); $groups_compound = array (); foreach ($result as $row) { - $groups[$row["id_sg"]] = $row["name"]; + $groups[$row["id_sg"]] = $row["name"]; } - + foreach ($result as $row) { $groups_compound[$row["id_sg"]] = ''; if ($row["parent"] > 1) { @@ -263,7 +263,7 @@ if ($id_np > 0) { } $group_filter .= html_print_select ($groups_compound, "ncgroup", $ncgroup, 'javascript:this.form.submit();', __('Group')." - ".__('All'), -1, true, false, true, '" style="width:350px'); - + $group_filter .= '
'; if ($ncgroup > 0) { @@ -272,16 +272,16 @@ if ($id_np > 0) { else { $sql = "SELECT id_nc, name, id_group FROM tnetwork_component WHERE name LIKE '%".$ncfilter."%' ORDER BY name"; } - + $result = db_get_all_rows_sql ($sql); $components = array (); if ($result === false) $result = array (); - + foreach ($result as $row) { $components[$row["id_nc"]] = $row["name"]; } - + $components_select = '
'; $components_select .= html_print_select ($components, "components[]", $id_nc, '', '', -1, true, true, false, '" style="width:350px'); @@ -304,7 +304,7 @@ if ($id_np > 0) { /* $agent['id_agente'], 'name' => io_safe_output($agent['nombre']), 'ip' => io_safe_output($agent['direccion'])); + //Get agents for only the name. + $filter_agents = $filter; + switch ($config['dbtype']) { + case "mysql": + $filter_agents[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%")'; + break; + case "postgresql": + $filter_agents[] = '(nombre LIKE \'%'.$string.'%\')'; + break; + case "oracle": + $filter_agents[] = '(UPPER(nombre) LIKE UPPER(\'%'.$string.'%\')'; + break; + } + $agents = agents_get_agents($filter_agents, array ('id_agente', 'nombre', 'direccion')); + if ($agents !== false) { + foreach ($agents as $agent) { + $data[] = array('id' => $agent['id_agente'], + 'name' => io_safe_output($agent['nombre']), + 'ip' => io_safe_output($agent['direccion']), + 'filter' => 'agent'); + } + } + + //Get agents for only the address + $filter_address = $filter; + switch ($config['dbtype']) { + case "mysql": + $filter_address[] = '(nombre COLLATE utf8_general_ci NOT LIKE "%'.$string.'%" AND direccion LIKE "%'.$string.'%")'; + break; + case "postgresql": + $filter_address[] = '(nombre NOT LIKE \'%'.$string.'%\' AND direccion LIKE \'%'.$string.'%\')'; + break; + case "oracle": + $filter_address[] = '(UPPER(nombre) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(direccion) LIKE UPPER(\'%'.$string.'%\'))'; + break; + } + $agents = agents_get_agents($filter_address, array ('id_agente', 'nombre', 'direccion')); + if ($agents !== false) { + foreach ($agents as $agent) { + $data[] = array('id' => $agent['id_agente'], + 'name' => io_safe_output($agent['nombre']), + 'ip' => io_safe_output($agent['direccion']), + 'filter' => 'address'); + } + } + + //Get agents for only the description + $filter_description = $filter; + switch ($config['dbtype']) { + case "mysql": + $filter_description[] = '(nombre COLLATE utf8_general_ci NOT LIKE "%'.$string.'%" AND direccion NOT LIKE "%'.$string.'%" AND comentarios LIKE "%'.$string.'%")'; + break; + case "postgresql": + $filter_description[] = '(nombre NOT LIKE \'%'.$string.'%\' AND direccion NOT LIKE \'%'.$string.'%\' AND comentarios LIKE \'%'.$string.'%\')'; + break; + case "oracle": + $filter_description[] = '(UPPER(nombre) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(direccion) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(comentarios) LIKE UPPER(\'%'.$string.'%\'))'; + break; + } + $agents = agents_get_agents($filter_description, array ('id_agente', 'nombre', 'direccion')); + if ($agents !== false) { + foreach ($agents as $agent) { + $data[] = array('id' => $agent['id_agente'], + 'name' => io_safe_output($agent['nombre']), + 'ip' => io_safe_output($agent['direccion']), + 'filter' => 'description'); + } } echo json_encode($data); @@ -155,42 +205,91 @@ elseif ($search_agents && ($config['metaconsole'] == 1) && defined('METACONSOLE' } $filter = array (); - switch ($config["dbtype"]) { - case "mysql": - case "postgresql": - $filter[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%")'; - break; - case "oracle": - $filter[] = '(UPPER(nombre) LIKE UPPER(\'%'.$string.'%\') OR UPPER(direccion) LIKE UPPER(\'%'.$string.'%\'))'; - break; - } if ($id_group != -1) { - if($id_group == 0) { + if ($id_group == 0) { $user_groups = users_get_groups ($config['id_user'], "AR", true); - + $filter['id_grupo'] = array_keys ($user_groups); } else { $filter['id_grupo'] = $id_group; } } - + $data = array(); foreach ($servers as $server) { if (metaconsole_load_external_db ($server) != NOERR) { continue; } - $agents = agents_get_agents ($filter, array ('id_agente','nombre', 'direccion')); - if ($agents === false) - continue; + //Get agents for only the name. + $filter_agents = $filter; + switch ($config['dbtype']) { + case "mysql": + $filter_agents[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%")'; + break; + case "postgresql": + $filter_agents[] = '(nombre LIKE \'%'.$string.'%\')'; + break; + case "oracle": + $filter_agents[] = '(UPPER(nombre) LIKE UPPER(\'%'.$string.'%\')'; + break; + } + $agents = agents_get_agents($filter_agents, array ('id_agente', 'nombre', 'direccion')); + if ($agents !== false) { + foreach ($agents as $agent) { + $data[] = array('id' => $agent['id_agente'], + 'name' => io_safe_output($agent['nombre']), + 'ip' => io_safe_output($agent['direccion']), + 'filter' => 'agent'); + } + } - foreach ($agents as $agent) { - $data[] = array('id' => $agent['id_agente'], - 'name' => io_safe_output($agent['nombre']) . " (" . io_safe_output($server['server_name']) . ") ", - 'ip' => io_safe_output($agent['direccion']), - 'server' => io_safe_output($server['server_name'])); + //Get agents for only the address + $filter_address = $filter; + switch ($config['dbtype']) { + case "mysql": + $filter_address[] = '(nombre COLLATE utf8_general_ci NOT LIKE "%'.$string.'%" AND direccion LIKE "%'.$string.'%")'; + break; + case "postgresql": + $filter_address[] = '(nombre NOT LIKE \'%'.$string.'%\' AND direccion LIKE \'%'.$string.'%\')'; + break; + case "oracle": + $filter_address[] = '(UPPER(nombre) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(direccion) LIKE UPPER(\'%'.$string.'%\'))'; + break; + } + $agents = agents_get_agents($filter_address, array ('id_agente', 'nombre', 'direccion')); + if ($agents !== false) { + foreach ($agents as $agent) { + $data[] = array('id' => $agent['id_agente'], + 'name' => io_safe_output($agent['nombre']), + 'ip' => io_safe_output($agent['direccion']), + 'filter' => 'address'); + } + } + + //Get agents for only the description + $filter_description = $filter; + switch ($config['dbtype']) { + case "mysql": + $filter_description[] = '(nombre COLLATE utf8_general_ci NOT LIKE "%'.$string.'%" AND direccion NOT LIKE "%'.$string.'%" AND comentarios LIKE "%'.$string.'%")'; + break; + case "postgresql": + $filter_description[] = '(nombre NOT LIKE \'%'.$string.'%\' AND direccion NOT LIKE \'%'.$string.'%\' AND comentarios LIKE \'%'.$string.'%\')'; + break; + case "oracle": + $filter_description[] = '(UPPER(nombre) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(direccion) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(comentarios) LIKE UPPER(\'%'.$string.'%\'))'; + break; + } + $agents = agents_get_agents($filter_description, array ('id_agente', 'nombre', 'direccion')); + if ($agents !== false) { + foreach ($agents as $agent) { + $data[] = array('id' => $agent['id_agente'], + 'name' => io_safe_output($agent['nombre']), + 'ip' => io_safe_output($agent['direccion']), + 'filter' => 'description'); + } } //Restore db connection metaconsole_restore_db(); diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 4a4c52d8f7..208c94ba38 100644 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -2756,10 +2756,28 @@ function ui_print_agent_autocomplete_input($parameters) { + "
IP:" + item.ip + ""; } - return $("
  • ") - .data("item.autocomplete", item) - .append(text) - .appendTo(ul); + switch (item.filter) { + case \'agent\': + return $("
  • ") + .data("item.autocomplete", item) + .append(text) + .appendTo(ul); + break; + case \'address\': + return $("
  • ") + .data("item.autocomplete", item) + .append(text) + .appendTo(ul); + break; + case \'description\': + return $("
  • ") + .data("item.autocomplete", item) + .append(text) + .appendTo(ul); + break; + } + + }; //Force the size of autocomplete