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>
* godmode/db/db_refine.php, godmode/servers/plugin.php: improved

View File

@ -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('&nbsp;&nbsp;&nbsp;&nbsp;', $group['deep']);
$tabulation = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $group['deep']);
$data[0] = $tabulation . '<a href="index.php?sec=gmodules&sec2=godmode/modules/manage_nc_groups&id='.$group['id_sg'].'">'.$group['name'].'</a>';
$data[1] = "<a onclick='if(confirm(\"" . __('Are you sure?') . "\")) return true; else return false;'
href='index.php?sec=".$sec."&sec2=godmode/modules/manage_nc_groups&delete=1&id=".$group['id_sg']."&offset=0'>" .
html_print_image('images/cross.png', true, array('title' => __('Delete'))) . "</a>" .
@ -222,7 +222,7 @@ foreach ($groups as $group) {
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'>";
html_print_input_hidden('multiple_delete', 1);
html_print_table ($table);

View File

@ -227,7 +227,7 @@ if (!empty ($table->data)) {
echo "</form>";
}
else {
echo '<div class="nf" style="width:'.$table->width.'">'.__('There are no defined network profiles').'</div>';
echo '<div class="nf" style="width:'.$table->width.'">'.__('There are no defined network profiles').'</div>';
}
echo '<form method="post" action="index.php?sec=gmodules&amp;sec2=godmode/modules/manage_network_templates_form">';

View File

@ -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 .= '</div></form>';
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 = '<form name="add_module" method="post" action="index.php?sec=gmodules&sec2=godmode/modules/manage_network_templates_form&id_np='.$id_np.'&add_module=1">';
$components_select .= html_print_select ($components, "components[]", $id_nc, '', '', -1, true, true, false, '" style="width:350px');
@ -304,7 +304,7 @@ if ($id_np > 0) {
/* <![CDATA[ */
function CheckAll() {
for (var i = 0; i < document.component_delete.elements.length; i++) {
var e = document.component_delete.elements[i];
if (e.type == 'checkbox' && e.name != 'allbox')
e.checked = !e.checked;

View File

@ -92,22 +92,11 @@ if ($search_agents && ((!defined('METACONSOLE')) || $force_local)) {
}
$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 == 0) {
$user_groups = users_get_groups ($config['id_user'], "AR", true);
$filter['id_grupo'] = array_keys ($user_groups);
}
else {
@ -121,13 +110,74 @@ if ($search_agents && ((!defined('METACONSOLE')) || $force_local)) {
break;
}
$agents = agents_get_agents ($filter, array ('id_agente', 'nombre', 'direccion'));
if ($agents === false)
$agents = array();
$data = array();
foreach ($agents as $agent) {
$data[] = array('id' => $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();

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>";
}
return $("<li></li>")
.data("item.autocomplete", item)
.append(text)
.appendTo(ul);
switch (item.filter) {
case \'agent\':
return $("<li style=\'background: #DFFFC4;\'></li>")
.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