From f1158196598cf5d248b5ded1f3527b8d54aeced0 Mon Sep 17 00:00:00 2001
From: darode <drd.sqki@gmail.com>
Date: Mon, 2 Apr 2012 09:49:12 +0000
Subject: [PATCH] 2012-04-02 Dario Rodriguez <dario.rodriguez@artica.es>

	* include/functions_menu.php
	operation/menu.php
	godmode/menu.php: Finish changes in reporting menu.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5863 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_console/ChangeLog                  |   6 ++
 pandora_console/godmode/menu.php           |   7 +-
 pandora_console/include/functions_menu.php | 116 +++++++++++++++++++--
 pandora_console/operation/menu.php         |   4 +-
 4 files changed, 119 insertions(+), 14 deletions(-)

diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index 8728956072..75c59bf9cf 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,9 @@
+2012-04-02 Dario Rodriguez <dario.rodriguez@artica.es>
+
+	* include/functions_menu.php
+	operation/menu.php
+	godmode/menu.php: Finish changes in reporting menu.
+
 2012-04-02  Sergio Martin <sergio.martin@artica.es>
 
 	* include/functions_reporting.php
diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php
index 4a88c7159f..2327e818c1 100644
--- a/pandora_console/godmode/menu.php
+++ b/pandora_console/godmode/menu.php
@@ -59,9 +59,11 @@ if (check_acl ($config['id_user'], 0, "AW")) {
 	$menu["gmassive"]["sub"] = $sub;
 }
 
+/*
 if (check_acl ($config['id_user'], 0, "AW")) {
 	enterprise_hook ('services_godmenu');
 }
+*/
 
 if (check_acl ($config['id_user'], 0, "PM")) {
 	$menu["gmodules"]["text"] = __('Manage modules');
@@ -140,15 +142,16 @@ if (check_acl ($config['id_user'], 0, "IW")) {
 
 	// Custom graph builder
 	$sub["godmode/reporting/graphs"]["text"] = __('Graph builder');
-	enterprise_hook ('reporting_godmenu');
-
+	
 	$menu["greporting"]["sub"] = $sub;
 }
 if (check_acl ($config['id_user'], 0, "IW")) {
 	// Custom map builder
+/*
 	$menu["gmap"]["text"] = __('Visual console builder');
 	$menu["gmap"]["sec2"] = "godmode/reporting/map_builder";
 	$menu["gmap"]["id"] = "god-map";
+*/
 	
 	if ($config['activate_gis']) {
 		$menu["godgismaps"]["text"] = __('GIS Maps builder');
diff --git a/pandora_console/include/functions_menu.php b/pandora_console/include/functions_menu.php
index 03b5741e43..9964419fd3 100644
--- a/pandora_console/include/functions_menu.php
+++ b/pandora_console/include/functions_menu.php
@@ -87,25 +87,76 @@ function menu_print_menu (&$menu) {
 		}
 		
 		$submenu_output = '';
-		$selected = false;
-		$visible = false;
+		
 		foreach ($main["sub"] as $subsec2 => $sub) {
+			//Init some variables
+			$visible = false;
+			$selected = false;
+			
 			$subsec2 = io_safe_output($subsec2);
 			// Choose valid suboptions (sec2)
 			if (enterprise_hook ('enterprise_acl', array ($config['id_user'], $mainsec, $subsec2)) == false){
 				continue;
 			}
+			
+			$class = '';
+			
+			$selected_submenu2 = false;
+			
+			//Look for submenus in level2!
+			if(isset($sub['sub2'])) {
+				$class .= 'has_submenu ';
+				
+				//This hacks avoid empty delimiter error when sec2 is not provided.
+				if (!$sec2) {
+					$sec2=" ";
+				}
+				
+				//Check if some submenu was selected to mark this (the parent) as selected
+				foreach (array_keys($sub['sub2']) as $key) {
+					
+					if (strpos($key, $sec2) !== false) {
+						$selected_submenu2 = true;
+						break;
+					}
+				}
+			}
+			
+			
+			//Create godmode option if submenu has godmode on
+			if (isset($sub['subsecs'])) {
+				
+				//Sometimes you need to add all paths because in the 
+				//same dir are code from visual console and reports
+				//for example
+				if (is_array($sub['subsecs'])) {
+				
+					//Compare each string
+					foreach ($sub['subsecs'] as $god_path) {
+						
+						if (strpos($sec2, $god_path) !== false) {
+							$selected_submenu2=true;	
+							break;
+						}
+					} 
+				} else {
+					//If there is only a string just compare
+					if (strpos($sec2, $sub['subsecs']) !== false) {
+							$selected_submenu2=true;	
+					}
+				}
+			}
 
 			//Set class
-			if (($sec2 == $subsec2 || $allsec2 == $subsec2) && isset ($sub[$subsec2]["options"])
+			if (($sec2 == $subsec2 || $allsec2 == $subsec2 || $selected_submenu2) && isset ($sub[$subsec2]["options"])
 				&& (get_parameter_get ($sub[$subsec2]["options"]["name"]) == $sub[$subsec2]["options"]["value"])) {
 				//If the subclass is selected and there are options and that options value is true
-				$class = 'submenu_selected';
+				$class .= 'submenu_selected selected';
 				$selected = true;
 				$visible = true;
 			}
-			elseif (($sec2 == $subsec2 || $allsec2 == $subsec2) && !isset ($sub[$subsec2]["options"])) {
-				$class = 'submenu_selected';
+			elseif (($sec2 == $subsec2 || $allsec2 == $subsec2|| $selected_submenu2) && !isset ($sub[$subsec2]["options"])) {
+				$class .= 'submenu_selected selected';
 				$selected = true;
 
 				$hasExtensions = (array_key_exists('hasExtensions',$main)) ? $main['hasExtensions'] : false;
@@ -116,7 +167,7 @@ function menu_print_menu (&$menu) {
 			}
 			else {
 				//Else it's not selected
-				$class = 'submenu_not_selected';
+				$class .= 'submenu_not_selected';
 			}
 			if (! isset ($sub["refr"])) {
 				$sub["refr"] = 0;
@@ -124,7 +175,11 @@ function menu_print_menu (&$menu) {
 			
 			if (isset ($sub["type"]) && $sub["type"] == "direct") {
 				//This is an external link
-				$submenu_output .= '<li class="'.$class.'"><a href="'.$subsec2.'">'.$sub["text"]."</a></li>";
+				$submenu_output .= '<li class="'.$class.'"><a href="'.$subsec2.'">'.$sub["text"]."</a>";
+				
+				if(isset($sub['sub2']) || $selected) {
+					$submenu_output .= html_print_image("include/styles/images/toggle.png", true, array("class" => "toggle", "alt" => "toogle"));
+				}
 			}
 			else {
 				//This is an internal link
@@ -179,14 +234,53 @@ function menu_print_menu (&$menu) {
 					$extensionInMenu = '';
 				}
 				
-				if (isset ($sub["title"])) {
+				if (isset ($sub["title"]) || $selected) {
 					$title = ' title="' . $sub["title"] . ' "';
 				} else {
 					$title = '';
 				}
-				$submenu_output .= '<a class="item_drag_shortcut" href="index.php?'.$extensionInMenu.'sec='.$secUrl.'&amp;sec2='.$subsec2.($sub["refr"] ? '&amp;refr=' . $sub["refr"] : '').$link_add.'"' . $title . '>'.$sub["text"].'</a>';
-				$submenu_output .= '</li>';			
+				$submenu_output .= '<a href="index.php?'.$extensionInMenu.'sec='.$secUrl.'&amp;sec2='.$subsec2.($sub["refr"] ? '&amp;refr=' . $sub["refr"] : '').$link_add.'"' . $title . '>'.$sub["text"].'</a>';
+				
+				if(isset($sub['sub2'])) {
+					$submenu_output .= html_print_image("include/styles/images/toggle.png", true, array("class" => "toggle", "alt" => "toogle"));
+				}
+			
 			}
+		
+			//Print second level submenu
+			if(isset($sub['sub2'])) {
+				
+				//Display if father is selected
+				$display = "style='display:none'";
+				
+				if ($selected) {
+					$display = "";
+				}
+				
+				$submenu2_list = '';
+				
+				foreach ($sub['sub2'] as $key => $sub2) {
+					$link = "index.php?sec=".$sec."&sec2=".$key;
+					
+					//Display if one submenu2 was selected!
+					if (strpos($key, $sec2) !== false) {
+						$display = "";	
+					}
+					
+					$class = "submenu2";
+					
+					$submenu2_list .= '<li class="'.$class.'" style="font-weight: normal;">';
+					$submenu2_list .= '<a style="font-weight:normal;" href="'.$link.'">'.$sub2["text"].'</a></li>';
+				}
+				
+				//Add submenu2 to submenu string
+				$submenu_output .= "<ul class=submenu2 $display>";
+				$submenu_output .= $submenu2_list;
+				$submenu_output .= "</ul>";
+			}
+	
+			//Submenu close list!
+			$submenu_output .= '</li>';		
 		}
 		
 		// Choose valid section (sec)
diff --git a/pandora_console/operation/menu.php b/pandora_console/operation/menu.php
index 7e41c03c16..d616320d06 100644
--- a/pandora_console/operation/menu.php
+++ b/pandora_console/operation/menu.php
@@ -29,7 +29,6 @@ $menu['class'] = 'operation';
 if (check_acl ($config['id_user'], 0, "AR")) {
 
 	enterprise_hook ('metaconsole_menu');
-	enterprise_hook ('dashboard_menu');
 
 	//View agents
 	$menu["estado"]["text"] = __('Monitoring');
@@ -153,6 +152,9 @@ if (check_acl ($config['id_user'], 0, "AR")) {
 	//Set godomode path
 	$sub["godmode/reporting/graphs"]["subsecs"] = array("operation/reporting/graph_viewer",
 														"godmode/reporting/graph_builder");	
+														
+	enterprise_hook ('dashboard_menu');
+	enterprise_hook ('reporting_godmenu');	
 		
 	$menu["reporting"]["sub"] = $sub;
 	//End reporting