From d4b2f7863d0bffefe9de87866e50c0398e853b0a Mon Sep 17 00:00:00 2001 From: Esteban Sanchez Date: Mon, 25 May 2009 13:29:48 +0000 Subject: [PATCH] 2009-05-25 Esteban Sanchez * general/ui/agents_list.php: Fixed pagination javascript selector to avoid collisions. * godmode/modules/manage_nc_groups.php, godmode/modules/manage_nc_groups_form.php: Rewritten to use pandora functions. Code cleanup. * godmode/modules/manage_network_components.php: Fixed string search query. * include/functions_network_components.php: Added get_network_component_group(). git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1705 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 15 ++++ pandora_console/general/ui/agents_list.php | 4 +- .../godmode/modules/manage_nc_groups.php | 67 +++++++++++----- .../godmode/modules/manage_nc_groups_form.php | 77 ++++++++----------- .../modules/manage_network_components.php | 2 +- .../include/functions_network_components.php | 19 +++++ 6 files changed, 119 insertions(+), 65 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index efc9c86333..84dc8b909c 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,18 @@ +2009-05-25 Esteban Sanchez + + * general/ui/agents_list.php: Fixed pagination javascript selector + to avoid collisions. + + * godmode/modules/manage_nc_groups.php, + godmode/modules/manage_nc_groups_form.php: Rewritten to use pandora + functions. Code cleanup. + + * godmode/modules/manage_network_components.php: Fixed string search + query. + + * include/functions_network_components.php: Added + get_network_component_group(). + 2009-05-25 Jorge Gonzalez * include/languages/es.po, include/languages/es.mo: Updated Spanish diff --git a/pandora_console/general/ui/agents_list.php b/pandora_console/general/ui/agents_list.php index b7160cc68b..7bb91a8519 100644 --- a/pandora_console/general/ui/agents_list.php +++ b/pandora_console/general/ui/agents_list.php @@ -189,7 +189,7 @@ function send_search_form (offset) { function (data, status) { $("#agents_loading").hide ().after (data); $("#agents_list, table#agents_table").show (); - $("a.pagination").click (function () { + $("#agents a.pagination").click (function () { offset = this.href.split ("=").pop (); send_search_form (offset); return false; @@ -206,7 +206,7 @@ $(document).ready (function () { return false; }); - $("a.pagination").click (function () { + $("#agents a.pagination").click (function () { offset = this.href.split ("=").pop (); send_search_form (offset); return false; diff --git a/pandora_console/godmode/modules/manage_nc_groups.php b/pandora_console/godmode/modules/manage_nc_groups.php index ca2f628757..7059d01af7 100644 --- a/pandora_console/godmode/modules/manage_nc_groups.php +++ b/pandora_console/godmode/modules/manage_nc_groups.php @@ -25,15 +25,17 @@ if (! give_acl ($config['id_user'], 0, "PM")) { audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", "Trying to access SNMP Group Management"); require ("general/noaccess.php"); - exit; + return; } +require_once ('include/functions_network_components.php'); + $create = (bool) get_parameter ('create'); $update = (bool) get_parameter ('update'); $delete = (bool) get_parameter ('delete'); - -echo '

'.__('Module management').' » '. __('Component group management').'

'; - +$new = (bool) get_parameter ('new'); +$id = (int) get_parameter ('id'); + if ($create) { $name = (string) get_parameter ('name'); $parent = (int) get_parameter ('parent'); @@ -47,7 +49,6 @@ if ($create) { } if ($update) { - $id = (int) get_parameter ('id_sg'); $name = (string) get_parameter ('name'); $parent = (int) get_parameter ('parent'); @@ -60,9 +61,7 @@ if ($update) { __('Not updated. Error updating data')); } -if ($delete) { // if delete - $id = (int) get_parameter ('id_sg'); - +if ($delete) { $result = process_sql_delete ('tnetwork_component_group', array ('id_sg' => $id)); print_result_message ($result, @@ -70,40 +69,72 @@ if ($delete) { // if delete __('Not deleted. Error deleting data')); } +if ($id || $new) { + require_once ('manage_nc_groups_form.php'); + return; +} + +echo '

'.__('Module management').' » '. __('Component group management').'

'; + +$url = get_url_refresh (array ('offset' => false, + 'create' => false, + 'update' => false, + 'delete' => false, + 'new' => false, + 'crt' => false, + 'upd' => false, + 'id_sg' => false)); + $table->width = '90%'; $table->head = array (); $table->head[0] = __('Name'); $table->head[1] = __('Parent'); -$table->head[2] = __('Delete'); +$table->head[2] = ''; $table->style = array (); $table->style[0] = 'font-weight: bold'; $table->align = array (); $table->align[2] = 'center'; +$table->size = array (); +$table->size[0] = '50%'; +$table->size[1] = '50%'; +$table->size[2] = '40px'; $table->data = array (); -$groups = get_db_all_rows_filter ('tnetwork_component_group', - array ('order' => 'parent')); +$total_groups = get_db_all_rows_filter ('tnetwork_component_group', false, 'COUNT(*) AS total'); +$total_groups = $total_groups[0]['total']; + +$filter = array (); +$filter['offset'] = (int) get_parameter ('offset'); +$filter['limit'] = (int) $config['block_size']; + +$groups = get_db_all_rows_filter ('tnetwork_component_group', $filter); if ($groups === false) $groups = array (); +pagination ($total_groups, $url); + foreach ($groups as $group) { $data = array (); - $data[0] = ''.$group["name"].''; + $data[0] = ''.$group['name'].''; - $data[1] = get_network_component_group_name ($group["parent"]); - $data[2] = ' - '; + $data[1] = get_network_component_group_name ($group['parent']); + + $data[2] = '
'; + $data[2] .= print_input_hidden ('delete', 1, true); + $data[2] .= print_input_hidden ('id', $group['id_sg'], true); + $data[2] .= print_input_image ('del', 'images/cross.png', 1, '', true, + array ('title' => __('Delete'))); + $data[2] .= '
'; array_push ($table->data, $data); } print_table ($table); -echo '
'; +echo ''; echo '
'; -print_input_hidden ('create', 1); +print_input_hidden ('new', 1); print_submit_button (__('Create'), 'crt', false, 'class="sub next"'); echo '
'; echo '
'; diff --git a/pandora_console/godmode/modules/manage_nc_groups_form.php b/pandora_console/godmode/modules/manage_nc_groups_form.php index 164c374963..885406538c 100644 --- a/pandora_console/godmode/modules/manage_nc_groups_form.php +++ b/pandora_console/godmode/modules/manage_nc_groups_form.php @@ -28,55 +28,44 @@ if (! give_acl ($config['id_user'], 0, "PM")) { exit; } -$create = (bool) get_parameter ('create'); -$edit = (bool) get_parameter ('edit'); +require_once ('include/functions_network_components.php'); -if ($edit) { // Edit mode - $id_sg = entrada_limpia ($_GET["id_sg"]); - $sql1 = "SELECT * FROM tnetwork_component_group where id_sg = $id_sg"; - $result=mysql_query($sql1); - $row=mysql_fetch_array($result); - $name = $row["name"]; - $parent = $row["parent"]; -} elseif ($create) { - $id_sg = -1; - $name = ""; - $parent = ""; +$id = (int) get_parameter ('id'); + +if ($id) { + $group = get_network_component_group ($id); + $name = $group['name']; + $parent = $group['parent']; +} else { + $name = ''; + $parent = ''; } -echo "

".__('Component group management')."

"; -echo ''; +echo '

'.__('Component group management').'

'; -// Different Form url if it's a create or if it's a update form -if ($id_sg != -1) - echo ""; -else - echo ""; - -echo ""; -echo ""; -echo ""; +$table->width = '50%'; +$table->style = array (); +$table->style[0] = 'font-weight: bold'; +$table->data = array (); -echo ""; -echo ""; -echo "
".__('Name')."
".__('Parent').""; -echo ""; +$table->data[0][0] = __('Name'); +$table->data[0][1] = print_input_text ('name', $name, '', 15, 255, true); -echo "
"; -echo '
'; -echo '
'; - -if ($id_sg == -1) - echo ""; -else - echo ""; - -echo "
"; +$table->data[1][0] = __('Parent'); +$table->data[1][1] = print_select (get_network_component_groups (), + 'parent', $parent, false, __('None'), 0, true, false, false); +echo '
'; +print_table ($table); +echo '
'; +if ($id) { + print_input_hidden ('update', 1); + print_input_hidden ('id', $id); + print_submit_button (__('Update'), 'crt', false, 'class="sub upd"'); +} else { + print_input_hidden ('create', 1); + print_submit_button (__('Create'), 'crt', false, 'class="sub next"'); +} +echo '
'; +echo '
'; ?> diff --git a/pandora_console/godmode/modules/manage_network_components.php b/pandora_console/godmode/modules/manage_network_components.php index f22369f4a9..35259e368e 100644 --- a/pandora_console/godmode/modules/manage_network_components.php +++ b/pandora_console/godmode/modules/manage_network_components.php @@ -216,7 +216,7 @@ $filter = array (); if ($search_id_group) $filter['id_group'] = $search_id_group; if ($search_string != '') - $filter[] = '(nombre LIKE "%'.$search_id_group.'%" OR description LIKE "%'.$search_id_group.'%" OR tcp_send LIKE "%'.$search_id_group.'%" OR tcp_rcv LIKE "%'.$search_id_group.'%")'; + $filter[] = '(name LIKE "%'.$search_string.'%" OR description LIKE "%'.$search_string.'%" OR tcp_send LIKE "%'.$search_string.'%" OR tcp_rcv LIKE "%'.$search_stringg.'%")'; $total_components = get_network_components (false, $filter, 'COUNT(*) AS total'); $total_components = $total_components[0]['total']; diff --git a/pandora_console/include/functions_network_components.php b/pandora_console/include/functions_network_components.php index 7855af3f1d..b494c9b22b 100644 --- a/pandora_console/include/functions_network_components.php +++ b/pandora_console/include/functions_network_components.php @@ -64,6 +64,25 @@ function get_network_component_group_name ($id_network_component_group) { return @get_db_value ('name', 'tnetwork_component_group', 'id_sg', $id_network_component_group); } +/** + * Get a network component group. + * + * @param int Group id to be fetched. + * @param array Extra filter. + * @param array Fields to be fetched. + * + * @return array A network component group matching id and filter. + */ +function get_network_component_group ($id_network_component_group, $filter = false, $fields = false) { + if (empty ($id_network_component_group)) + return false; + if (! is_array ($filter)) + $filter = array (); + $filter['id_sg'] = (int) $id_network_component_group; + + return get_db_row_filter ('tnetwork_component_group', $filter, $fields); +} + /** * Get a list of network component groups. *