2013-02-07 Miguel de Dios <miguel.dedios@artica.es>

* 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.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7607 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2013-02-07 15:53:04 +00:00
parent f6fd3a085d
commit 3d644a232d
6 changed files with 186 additions and 54 deletions

View File

@ -1,3 +1,18 @@
2013-02-07 Miguel de Dios <miguel.dedios@artica.es>
* 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 <miguel.dedios@artica.es> 2013-02-07 Miguel de Dios <miguel.dedios@artica.es>
* godmode/db/db_refine.php, godmode/servers/plugin.php: improved * godmode/db/db_refine.php, godmode/servers/plugin.php: improved

View File

@ -222,7 +222,7 @@ foreach ($groups as $group) {
array_push ($table->data, $data); array_push ($table->data, $data);
} }
if(isset($data)) { if (isset($data)) {
echo "<form method='post' action='index.php?sec=".$sec."&sec2=godmode/modules/manage_nc_groups'>"; echo "<form method='post' action='index.php?sec=".$sec."&sec2=godmode/modules/manage_nc_groups'>";
html_print_input_hidden('multiple_delete', 1); html_print_input_hidden('multiple_delete', 1);
html_print_table ($table); html_print_table ($table);

View File

@ -92,17 +92,6 @@ if ($search_agents && ((!defined('METACONSOLE')) || $force_local)) {
} }
$filter = array (); $filter = array ();
switch ($config['dbtype']) {
case "mysql":
$filter[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")';
break;
case "postgresql":
$filter[] = '(nombre LIKE \'%'.$string.'%\' OR direccion LIKE \'%'.$string.'%\' OR comentarios LIKE \'%'.$string.'%\')';
break;
case "oracle":
$filter[] = '(UPPER(nombre) LIKE UPPER(\'%'.$string.'%\') OR UPPER(direccion) LIKE UPPER(\'%'.$string.'%\') OR UPPER(comentarios) LIKE UPPER(\'%'.$string.'%\'))';
break;
}
if ($id_group != -1) { if ($id_group != -1) {
if($id_group == 0) { if($id_group == 0) {
@ -121,13 +110,74 @@ if ($search_agents && ((!defined('METACONSOLE')) || $force_local)) {
break; break;
} }
$agents = agents_get_agents ($filter, array ('id_agente', 'nombre', 'direccion'));
if ($agents === false)
$agents = array();
$data = array(); $data = array();
foreach ($agents as $agent) { //Get agents for only the name.
$data[] = array('id' => $agent['id_agente'], 'name' => io_safe_output($agent['nombre']), 'ip' => io_safe_output($agent['direccion'])); $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); echo json_encode($data);
@ -155,18 +205,9 @@ elseif ($search_agents && ($config['metaconsole'] == 1) && defined('METACONSOLE'
} }
$filter = array (); $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 != -1) {
if($id_group == 0) { if ($id_group == 0) {
$user_groups = users_get_groups ($config['id_user'], "AR", true); $user_groups = users_get_groups ($config['id_user'], "AR", true);
$filter['id_grupo'] = array_keys ($user_groups); $filter['id_grupo'] = array_keys ($user_groups);
@ -182,15 +223,73 @@ elseif ($search_agents && ($config['metaconsole'] == 1) && defined('METACONSOLE'
continue; continue;
} }
$agents = agents_get_agents ($filter, array ('id_agente','nombre', 'direccion')); //Get agents for only the name.
if ($agents === false) $filter_agents = $filter;
continue; 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) { //Get agents for only the address
$data[] = array('id' => $agent['id_agente'], $filter_address = $filter;
'name' => io_safe_output($agent['nombre']) . " (" . io_safe_output($server['server_name']) . ") ", switch ($config['dbtype']) {
'ip' => io_safe_output($agent['direccion']), case "mysql":
'server' => io_safe_output($server['server_name'])); $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 //Restore db connection
metaconsole_restore_db(); metaconsole_restore_db();

View File

@ -2756,10 +2756,28 @@ function ui_print_agent_autocomplete_input($parameters) {
+ "<br><span style=\"font-size: 70%; font-style: italic;\">IP:" + item.ip + "</span></a>"; + "<br><span style=\"font-size: 70%; font-style: italic;\">IP:" + item.ip + "</span></a>";
} }
return $("<li></li>") switch (item.filter) {
.data("item.autocomplete", item) case \'agent\':
.append(text) return $("<li style=\'background: #DFFFC4;\'></li>")
.appendTo(ul); .data("item.autocomplete", item)
.append(text)
.appendTo(ul);
break;
case \'address\':
return $("<li style=\'background: #F7CFFF;\'></li>")
.data("item.autocomplete", item)
.append(text)
.appendTo(ul);
break;
case \'description\':
return $("<li style=\'background: #FEFCC6;\'></li>")
.data("item.autocomplete", item)
.append(text)
.appendTo(ul);
break;
}
}; };
//Force the size of autocomplete //Force the size of autocomplete