From d212b59b8868ec96c52dff30e5dc3b030bdda8c2 Mon Sep 17 00:00:00 2001 From: guruevi Date: Thu, 16 Oct 2008 19:47:06 +0000 Subject: [PATCH] 2008-10-16 Evi Vanoost * include/functions_html.php: Added print_error_message, a function that will print out

error messages for you given a result * godmode/modules/manage_network_templates_form.php: Rewrite for new style and makes it easier for mass updates to templates (eg. if you have port 1-48 of a Cisco Switch (input, output and status) now you don't have to click 288 times. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1163 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 10 + .../modules/manage_network_templates_form.php | 355 ++++++++++-------- pandora_console/include/functions_html.php | 35 ++ 3 files changed, 235 insertions(+), 165 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index e2dae169d2..3d73e9d592 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,13 @@ +2008-10-16 Evi Vanoost + + * include/functions_html.php: Added print_error_message, a function + that will print out

error messages for you given a result + + * godmode/modules/manage_network_templates_form.php: Rewrite for new + style and makes it easier for mass updates to templates (eg. if you + have port 1-48 of a Cisco Switch (input, output and status) now you + don't have to click 288 times. + 2008-10-16 Sancho Lerena * operation/snmpconsole/snmp_alert.php: Fixed problem creating diff --git a/pandora_console/godmode/modules/manage_network_templates_form.php b/pandora_console/godmode/modules/manage_network_templates_form.php index a82d6557ee..8ddff0429d 100644 --- a/pandora_console/godmode/modules/manage_network_templates_form.php +++ b/pandora_console/godmode/modules/manage_network_templates_form.php @@ -17,10 +17,11 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // Load global vars -require("include/config.php"); +require_once ("include/config.php"); check_login (); + if (! give_acl ($config['id_user'], 0, "PM")) { audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", "Trying to access Network Profile Management"); @@ -28,180 +29,204 @@ if (! give_acl ($config['id_user'], 0, "PM")) { exit; } +$id_np = get_parameter ("id_np", -1); //Network Profile +$ncgroup = get_parameter ("ncgroup", -1); //Network component group +$id_nc = get_parameter ("components", array ()); -if (isset($_GET["delete_module"])){ // Delete module from profile - $id_npc = $_GET["delete_module"]; - $sql1="DELETE FROM tnetwork_profile_component WHERE id_npc = $id_npc"; - $result=mysql_query($sql1); - if (! $result) - echo "

".__('Not deleted. Error deleting data')."

"; - else { - echo "

".__('Deleted successfully')."

"; - } -} - -if (isset($_GET["add_module"])){ // Add module to profile - $id_nc = $_POST["component"]; - $id_np = $_GET["id_np"]; - $sql1="INSERT INTO tnetwork_profile_component (id_np,id_nc) VALUES ($id_np, $id_nc)"; - $result=mysql_query($sql1); - if (! $result) - echo "

".__('Not created. Error inserting data')."

"; - else { - echo "

".__('Created successfully')."

"; - } -} - -$ncgroup = -1; - -if (isset($_GET["refresh_module"])){ //Refresh module info from group combo - $ncgroup = $_POST["ncgroup"]; -} - - -if (isset($_GET["id_np"])){ // Read module data - $id_np = $_GET["id_np"]; - if ($id_np != -1){ - $sql1="SELECT * FROM tnetwork_profile WHERE id_np = $id_np ORDER BY - name"; - $result=mysql_query($sql1); - $row=mysql_fetch_array($result); - $description = $row["description"]; - $name = $row["name"]; - } else { - $comentarios = ""; - $name = ""; - } -} - -if (isset($_GET["create"])){ // Create module - $name = entrada_limpia ($_POST["name"]); - $description = entrada_limpia ($_POST["description"]); - $sql_insert="INSERT INTO tnetwork_profile (name,description) - VALUES ('$name', '$description')"; - $result=mysql_query($sql_insert); - if (! $result) - echo "

".__('Not created. Error inserting data')."

"; - else { - echo "

".__('Created successfully')."

"; - $id_np = mysql_insert_id(); - } -} - -if (isset($_GET["update"])){ // Update profile - $id_np = $_GET["update"]; - $name = entrada_limpia ($_POST["name"]); - $description = entrada_limpia ($_POST["description"]); - $sql_insert="UPDATE tnetwork_profile set name = '$name', description = '$description' WHERE id_np = $id_np"; - $result=mysql_query($sql_insert); - if (! $result) - echo "

".__('Not updated. Error updating data')."

"; - else { - echo "

".__('Updated successfully')."

"; - } -} - -echo "

".__('Module management')." > "; -echo __('Module template management')."

"; -echo ""; - -if ($id_np == -1) - echo ''; -else - echo ''; - -echo ""; -echo ""; -echo ""; -echo "
".__('Name').""; -echo ""; -echo "
".__('Description').""; -echo ""; -echo "
"; - -if ($id_np != -1){ - // Show associated modules, allow to delete, and to add - - $sql1 = "SELECT * FROM tnetwork_profile_component where id_np = $id_np"; - $result = mysql_query ($sql1); - if ($row=mysql_num_rows($result)) { - - echo ''; - echo ''; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - $color =0; - - while ( $row = mysql_fetch_array($result)) { - $id_nc = $row["id_nc"]; - $id_npc = $row["id_npc"]; - $sql2 = "SELECT * FROM tnetwork_component where id_nc = $id_nc ORDER BY name"; - $result2 = mysql_query ($sql2); - if ($row2=mysql_fetch_array($result2)){ - if ($color == 1){ - $tdcolor="datos"; - $color =0; - } else { - $tdcolor="datos2"; - $color =1; - } - $id_tipo = $row2["type"]; - $id_group = $row2["id_group"]; - $nombre_modulo =$row2["name"]; - $description = $row2["description"]; - $module_group2 = $row2["id_module_group"]; - - echo ""; - echo ""; - echo ""; +if (isset ($_GET["delete_module"])) { + // Delete module from profile + $errors = 0; + foreach ($id_nc as $component) { + $sql = sprintf ("DELETE FROM tnetwork_profile_component WHERE id_np = %d AND id_nc = %d", $id_np, $component); + $result = process_sql ($sql); + if ($result === false) { + $errors++; } } - } else { - echo "
No modules
"; + + print_error_message (($errors < 1), __('Successfully deleted module from profile'), __('Error deleting module from profile')); +} elseif (isset ($_GET["add_module"])) { + // Add module to profile + $errors = 0; + foreach ($id_nc as $component) { + $sql = sprintf ("INSERT INTO tnetwork_profile_component (id_np,id_nc) VALUES (%d, %d)", $id_np, $component); + $result = process_sql ($sql); + if ($result === false) { + $errors++; + } } - echo "
".__('Module name')."".__('Type')."".__('Description')."".__('NC.Group')."X
"; - echo $nombre_modulo; - echo ""; - if ($id_tipo > 0) { - echo ""; - } - echo "".substr($description,0,30)."".give_network_component_group_name($id_group)."
"; + + print_error_message (($errors < 1), __('Successfully added module to profile'), __('Error adding module to profile')); +} + +if (isset ($_GET["create"]) || isset ($_GET["update"])) { + //Submitted form + $name = get_parameter_post ("name"); + $description = get_parameter_post ("description"); + + if ($id_np > 0) { + //Profile exists + $sql = sprintf ("UPDATE tnetwork_profile SET name = '%s', description = '%s' WHERE id_np = %d", $name, $description, $id_np); + $result = process_sql ($sql); + print_error_message ($result, __('Successfully updated network profile'), __('Error updating network profile')); + } else { + //Profile doesn't exist + $sql = sprintf ("INSERT INTO tnetwork_profile (name, description) VALUES ('%s', '%s')", $name, $description); + $result = process_sql ($sql, "insert_id"); + print_error_message ($result, __('Successfully added network profile'), __('Error adding network profile')); + $id_np = (int) $result; //Will return either 0 (in case of error) or an int + } + +} elseif ($id_np > 0) { + //Profile exists + $row = get_db_row ("tnetwork_profile", "id_np", $id_np); + + $description = $row["description"]; + $name = $row["name"]; + +} else { + //Profile has to be created + $description = ""; + $name = ""; } -echo ""; -echo '
'; -if ($id_np == -1) - echo ''; -else - echo ''; -echo "
"; -echo ""; +echo "

".__('Module management')." > ".__('Module template management')."

"; +if ($id_np < 1) { + echo '
'; +} else { + echo ''; +} -if ($id_np != -1){ - echo "

".__('Add')." ".__('Module')."

"; - echo ""; - echo '
'; - echo ''; - $sql1 = "SELECT * FROM tnetwork_component ORDER BY id_group, name"; - $result = mysql_query ($sql1); - echo "'; + +echo ''; + +echo ''; +echo '"; +echo '
'.__('Name').''; +print_input_text ("name", $name, '', 63); +echo '
'.__('Description').''; +print_textarea ("description", 2, 60, $description); +echo "
'; +if ($id_np > 0) { + print_submit_button (__("Update"), "updbutton", false, 'class="sub upd"'); +} else { + print_submit_button (__("Create"), "crtbutton", false, 'class="sub wand"'); +} +echo "
"; + +if ($id_np > 0) { + // Show associated modules, allow to delete, and to add + $sql = sprintf ("SELECT npc.id_nc AS component_id, nc.name, nc.type, nc.description, nc.id_module_group AS `group` + FROM tnetwork_profile_component AS npc, tnetwork_component AS nc + WHERE npc.id_nc = nc.id_nc AND npc.id_np = %d", $id_np); + + $result = get_db_all_rows_sql ($sql); + + if (empty ($result)) { + echo '
'.__("No modules for this profile").'
'; + $result = array (); } - echo ""; - echo '
'; - echo ''; - echo "
"; - echo ""; + $table->head = array (); + $table->data = array (); + $table->align = array (); + $table->width = 550; + $table->cellpadding = 4; + $table->cellspacing = 4; + $table->class = "databox"; + + $table->head[0] = __('Module name'); + $table->head[1] = __('Type'); + $table->align[1] = "center"; + $table->head[2] = __('Description'); + $table->head[3] = __('Group'); + $table->align[3] = "center"; + $table->head[4] = print_checkbox_extended ('allbox', '', false, false, 'CheckAll();', '', true); + $table->align[4] = "center"; + + foreach ($result as $row) { + $data = array (); + $data[0] = $row["name"]; + $data[1] = ''; + $data[2] = substr($row["description"],0,30); + $data[3] = give_network_component_group_name ($row["group"]); + $data[4] = print_checkbox ("components[]", $row["component_id"], false, true); + array_push ($table->data, $data); + } + + if (!empty ($table->data)) { + echo '
'; + print_table ($table); + echo '
'; + print_submit_button (__('Delete'), "delbutton", false, 'class="sub delete" onClick="if (!confirm(\'Are you sure?\')) return false;"'); + echo '
'; + } + unset ($table); + + echo "

".__('Add Modules')."

"; + + //Here should be a form to filter group + + //The form to submit when adding a list of components + echo '
'; + echo '
'; + $result = get_db_all_rows_in_table ("tnetwork_component_group","name"); + + //2 arrays. 1 with the groups, 1 with the groups by parent + $groups = array (); + $groups_compound = array (); + foreach ($result as $row) { + $groups[$row["id_sg"]] = $row["name"]; + } + + foreach ($result as $row) { + $groups_compound[$row["id_sg"]] = ''; + if ($row["parent"] > 1) { + $groups_compound[$row["id_sg"]] = $groups[$row["parent"]]." / "; + } + $groups_compound[$row["id_sg"]] .= $row["name"]; + } + + print_select ($groups_compound, "ncgroup", $ncgroup, 'javascript:this.form.submit();', __('Group')." - ".__('All'), -1, false, false, true, '" style="width:350px'); + echo '
'; + + echo '
'; + echo '
'; + if ($ncgroup > 0) { + $sql = sprintf ("SELECT id_nc, name, id_group FROM tnetwork_component WHERE id_group = %d ORDER BY name", $ncgroup); + } else { + $sql = "SELECT id_nc, name, id_group FROM tnetwork_component ORDER BY name"; + } + + $result = get_db_all_rows_sql ($sql); + $components = array (); + if ($result === false) + $result = array (); + + foreach ($result as $row) { + $components[$row["id_nc"]] = $row["name"]; + } + + print_select ($components, "components[]", $id_nc, '', '', -1, false, true, false, '" style="width:350px'); + echo "  "; + print_submit_button (__('Add'), 'crtbutton', false, 'class="sub wand"'); + echo "
"; } ?> + diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index dbcdb978fa..3b02d3ae36 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -567,4 +567,39 @@ function print_help_tip ($text, $return = false) { echo $output; } +/** + * Evaluates a result using empty () and then prints an error message or a + * success message + * + * @param any $result the results to evaluate. 0, NULL, false, '' or array() + * is bad, the rest is good + * @param string $good the string to be displayed if the result was good + * @param string $bad the string to be displayed if the result was bad + * @param string $attributes any other attributes to be set for the h3 + * @param bool $return whether to output the string or return it + * @param string $tag what tag to use (you could specify something else than + * h3 like div or h2 + * + * @return a string or an output +*/ + +function print_error_message ($result, $good = '', $bad = '', $attributes = '', $return = false, $tag = 'h3') { + if ($good == '' || $good === false) + $good = __('Request successfully processed'); + + if ($bad == '' || $bad === false) + $bad = __('Error processing request'); + + if (empty ($result)) { + $output = '<'.$tag.' class="error" '.$attributes.'>'.$bad.''; + } else { + $output = '<'.$tag.' class="suc" '.$attributes.'>'.$good.''; + } + + if ($return !== false) + return $output; + + echo $output; +} + ?>