Pārlūkot izejas kodu

In the 'context', pass menus by ID and no longer by index.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2144 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 13 gadi atpakaļ
vecāks
revīzija
e305d24256

+ 1 - 1
application/applicationcontext.class.inc.php

@@ -98,7 +98,7 @@ class ApplicationContext
 		if (!isset(self::$aDefaultValues))
 		{
 			self::$aDefaultValues = array();
-			$aContext = utils::ReadParam('c', array());
+			$aContext = utils::ReadParam('c', array(), false, 'context_param');
 			foreach($this->aNames as $sName)
 			{
 				$sValue = isset($aContext[$sName]) ? $aContext[$sName] : '';

+ 9 - 10
application/menunode.class.inc.php

@@ -138,7 +138,7 @@ class ApplicationMenu
 		// Sort the root menu based on the rank
 		usort(self::$aRootMenus, array('ApplicationMenu', 'CompareOnRank'));
 		$iAccordion = 0;
-		$iActiveMenu = ApplicationMenu::GetActiveNodeId();
+		$iActiveMenu = self::GetMenuIndexById(self::GetActiveNodeId());
 		foreach(self::$aRootMenus as $aMenu)
 		{
 			$oMenuNode = self::GetMenuNode($aMenu['index']);
@@ -257,22 +257,21 @@ class ApplicationMenu
 	
 	/**
 	 * Retrieves the currently active menu (if any, otherwise the first menu is the default)
-	 * @return MenuNode or null if there is no menu at all !
+	 * @return string The Id of the currently active menu
 	 */
 	static public function GetActiveNodeId()
 	{
 		$oAppContext = new ApplicationContext();
-		$iMenuIndex = $oAppContext->GetCurrentValue('menu', -1);
-		
-		if ($iMenuIndex  == -1)
+		$sMenuId = $oAppContext->GetCurrentValue('menu', null);		
+		if ($sMenuId  === null)
 		{
 			// Make sure the root menu is sorted on 'rank'
 			usort(self::$aRootMenus, array('ApplicationMenu', 'CompareOnRank'));
 			$oFirstGroup = self::GetMenuNode(self::$aRootMenus[0]['index']);
 			$oMenuNode = self::GetMenuNode(self::$aMenusIndex[$oFirstGroup->GetIndex()]['children'][0]['index']);
-			$iMenuIndex = $oMenuNode->GetIndex();
+			$sMenuId = $oMenuNode->GetMenuId();
 		}
-		return $iMenuIndex;
+		return $sMenuId;
 	}	
 }
 
@@ -388,7 +387,7 @@ abstract class MenuNode
 	
 	public function GetHyperlink($aExtraParams)
 	{
-		$aExtraParams['c[menu]'] = $this->GetIndex();
+		$aExtraParams['c[menu]'] = $this->GetMenuId();
 		return $this->AddParams(utils::GetAbsoluteUrlAppRoot().'pages/UI.php', $aExtraParams);
 	}
 	
@@ -689,7 +688,7 @@ class WebPageMenuNode extends MenuNode
 
 	public function GetHyperlink($aExtraParams)
 	{
-		$aExtraParams['c[menu]'] = $this->GetIndex();
+		$aExtraParams['c[menu]'] = $this->GetMenuId();
 		return $this->AddParams( $this->sHyperlink, $aExtraParams);
 	}
 	
@@ -728,7 +727,7 @@ class NewObjectMenuNode extends MenuNode
 	public function GetHyperlink($aExtraParams)
 	{
 		$sHyperlink = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=new&class='.$this->sClass;
-		$aExtraParams['c[menu]'] = $this->GetIndex();
+		$aExtraParams['c[menu]'] = $this->GetMenuId();
 		return $this->AddParams($sHyperlink, $aExtraParams);
 	}
 

+ 7 - 3
application/utils.inc.php

@@ -210,6 +210,7 @@ class utils
 			$retValue = filter_var($value, FILTER_SANITIZE_SPECIAL_CHARS);
 			break;
 			
+			case 'context_param':
 			case 'parameter':
 			case 'field_name':
 			if (is_array($value))
@@ -236,12 +237,15 @@ class utils
 					case 'field_name':
 					$retValue = filter_var($value, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>'/^[A-Za-z0-9_]+(->[A-Za-z0-9_]+)*$/'))); // att_code or att_code->name or AttCode->Name or AttCode->Key2->Name
 					break;
+					
+					case 'context_param':
+					$retValue = filter_var($value, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>'/^[ A-Za-z0-9_=%:+-]*$/')));
+					break;
+						
 				}
 			}
 			break;
-			
-			break;
-			
+						
 			default:
 			case 'raw_data':
 			$retValue = $value;