Browse Source

#478 Fixed issue in the audit: the results are wrong whenever an organization is selected

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1595 a333f486-631f-4898-b8df-5754b55c2be0
romainq 13 năm trước cách đây
mục cha
commit
80cc5e21f7
1 tập tin đã thay đổi với 95 bổ sung97 xóa
  1. 95 97
      pages/audit.php

+ 95 - 97
pages/audit.php

@@ -22,128 +22,126 @@
  * @author      Denis Flaven <denis.flaven@combodo.com>
  * @license     http://www.opensource.org/licenses/gpl-3.0.html LGPL
  */
-try
+/**
+ * Adds the context parameters to the audit query
+ */
+function FilterByContext(DBObjectSearch &$oFilter, ApplicationContext $oAppContext)
 {
-	require_once('../approot.inc.php');
-	require_once(APPROOT.'/application/application.inc.php');
-	require_once(APPROOT.'/application/itopwebpage.class.inc.php');
-	
-	require_once(APPROOT.'/application/startup.inc.php');
-	$operation = utils::ReadParam('operation', '');
-	$oAppContext = new ApplicationContext();
-	
-	require_once(APPROOT.'/application/loginwebpage.class.inc.php');
-	LoginWebPage::DoLogin(); // Check user rights and prompt if needed
-	
-	$oP = new iTopWebPage(Dict::S('UI:Audit:Title'));
-	
-	/**
-	 * Adds the context parameters to the audit query
-	 */
-	function FilterByContext(DBObjectSearch &$oFilter, ApplicationContext $oAppContext)
+	$sObjClass = $oFilter->GetClass();		
+	$aContextParams = $oAppContext->GetNames();
+	$aCallSpec = array($sObjClass, 'MapContextParam');
+	if (is_callable($aCallSpec))
 	{
-		$sObjClass = $oFilter->GetClass();		
-		$aContextParams = $oAppContext->GetNames();
-		$aCallSpec = array($sObjClass, 'MapContextParam');
-		if (is_callable($aCallSpec))
+		foreach($aContextParams as $sParamName)
 		{
-			foreach($aContextParams as $sParamName)
+			$sValue = $oAppContext->GetCurrentValue($sParamName, null);
+			if ($sValue != null)
 			{
-				$sValue = $oAppContext->GetCurrentValue($sParamName, null);
-				if ($sValue != null)
+				$sAttCode = call_user_func($aCallSpec, $sParamName); // Returns null when there is no mapping for this parameter
+				if ( ($sAttCode != null) && MetaModel::IsValidAttCode($sObjClass, $sAttCode))
 				{
-					$sAttCode = call_user_func($aCallSpec, $sParamName); // Returns null when there is no mapping for this parameter
-					if ( ($sAttCode != null) && MetaModel::IsValidAttCode($sObjClass, $sAttCode))
+					// Check if the condition points to a hierarchical key
+					if ($sAttCode == 'id')
 					{
-						$oFilter  = new DBObjectSearch($sObjClass);
-
-						// Check if the condition points to a hierarchical key
-						if ($sAttCode == 'id')
+						// Filtering on the objects themselves
+						$sHierarchicalKeyCode = MetaModel::IsHierarchicalClass($sObjClass);
+						
+						if ($sHierarchicalKeyCode !== false)
 						{
-							// Filtering on the objects themselves
-							$sHierarchicalKeyCode = MetaModel::IsHierarchicalClass($sObjClass);
+							$oRootFilter = new DBObjectSearch($sObjClass);
+							$oRootFilter->AddCondition($sAttCode, $sValue);
+							$oFilter->AddCondition_PointingTo($oRootFilter, $sHierarchicalKeyCode, TREE_OPERATOR_BELOW); // Use the 'below' operator by default
+							$bConditionAdded = true;
+						}
+					}
+					else
+					{
+						$oAttDef = MetaModel::GetAttributeDef($sObjClass, $sAttCode);
+						$bConditionAdded = false;
+						if ($oAttDef->IsExternalKey())
+						{
+							$sHierarchicalKeyCode = MetaModel::IsHierarchicalClass($oAttDef->GetTargetClass());
 							
 							if ($sHierarchicalKeyCode !== false)
 							{
-								$oRootFilter = new DBObjectSearch($sObjClass);
-								$oRootFilter->AddCondition($sAttCode, $sValue);
-								$oFilter->AddCondition_PointingTo($oRootFilter, $sHierarchicalKeyCode, TREE_OPERATOR_BELOW); // Use the 'below' operator by default
+								$oRootFilter = new DBObjectSearch($oAttDef->GetTargetClass());
+								$oRootFilter->AddCondition('id', $sValue);
+								$oHKFilter = new DBObjectSearch($oAttDef->GetTargetClass());
+								$oHKFilter->AddCondition_PointingTo($oRootFilter, $sHierarchicalKeyCode, TREE_OPERATOR_BELOW); // Use the 'below' operator by default
+								$oFilter->AddCondition_PointingTo($oHKFilter, $sAttCode);
 								$bConditionAdded = true;
 							}
 						}
-						else
-						{
-							$oAttDef = MetaModel::GetAttributeDef($sObjClass, $sAttCode);
-							$bConditionAdded = false;
-							if ($oAttDef->IsExternalKey())
-							{
-								$sHierarchicalKeyCode = MetaModel::IsHierarchicalClass($oAttDef->GetTargetClass());
-								
-								if ($sHierarchicalKeyCode !== false)
-								{
-									$oRootFilter = new DBObjectSearch($oAttDef->GetTargetClass());
-									$oRootFilter->AddCondition('id', $sValue);
-									$oHKFilter = new DBObjectSearch($oAttDef->GetTargetClass());
-									$oHKFilter->AddCondition_PointingTo($oRootFilter, $sHierarchicalKeyCode, TREE_OPERATOR_BELOW); // Use the 'below' operator by default
-									$oFilter->AddCondition_PointingTo($oHKFilter, $sAttCode);
-									$bConditionAdded = true;
-								}
-							}
-						}
-						if (!$bConditionAdded)
-						{
-							$oFilter->AddCondition($sAttCode, $sValue);
-						}
+					}
+					if (!$bConditionAdded)
+					{
+						$oFilter->AddCondition($sAttCode, $sValue);
 					}
 				}
 			}
 		}
 	}
+}
 
-	function GetRuleResultSet($iRuleId, $oDefinitionFilter, $oAppContext)
-	{
-		$oRule = MetaModel::GetObject('AuditRule', $iRuleId);
-		$sOql = $oRule->Get('query');
-		$oRuleFilter = DBObjectSearch::FromOQL($sOql);
-		FilterByContext($oRuleFilter, $oAppContext); // Not needed since this filter is a subset of the definition filter, but may speedup things
+function GetRuleResultSet($iRuleId, $oDefinitionFilter, $oAppContext)
+{
+	$oRule = MetaModel::GetObject('AuditRule', $iRuleId);
+	$sOql = $oRule->Get('query');
+	$oRuleFilter = DBObjectSearch::FromOQL($sOql);
+	FilterByContext($oRuleFilter, $oAppContext); // Not needed since this filter is a subset of the definition filter, but may speedup things
 
-		if ($oRule->Get('valid_flag') == 'false')
-		{
-			// The query returns directly the invalid elements
-			$oFilter = $oRuleFilter; 
-			$oFilter->MergeWith($oDefinitionFilter);
-			$oErrorObjectSet = new CMDBObjectSet($oFilter);
-		}
-		else
-		{
-			// The query returns only the valid elements, all the others are invalid
-			$oFilter = $oRuleFilter; 
-			$oErrorObjectSet = new CMDBObjectSet($oFilter);
-			$aValidIds = array(0); // Make sure that we have at least one value in the list
-			while($oObj = $oErrorObjectSet->Fetch())
-			{
-				$aValidIds[] = $oObj->GetKey(); 
-			}
-			$oFilter = clone $oDefinitionFilter;
-			$oFilter->AddCondition('id', $aValidIds, 'NOTIN');
-			$oErrorObjectSet = new CMDBObjectSet($oFilter);
-		}
-		return $oErrorObjectSet;
+	if ($oRule->Get('valid_flag') == 'false')
+	{
+		// The query returns directly the invalid elements
+		$oFilter = $oRuleFilter; 
+		$oFilter->MergeWith($oDefinitionFilter);
+		$oErrorObjectSet = new CMDBObjectSet($oFilter);
 	}
-	
-	function GetReportColor($iTotal, $iErrors)
+	else
 	{
-		$sResult = 'red';
-		if ( ($iTotal == 0) || ($iErrors / $iTotal) <= 0.05 )
-		{
-			$sResult = 'green';
-		}
-		else if ( ($iErrors / $iTotal) <= 0.25 )
+		// The query returns only the valid elements, all the others are invalid
+		$oFilter = $oRuleFilter; 
+		$oErrorObjectSet = new CMDBObjectSet($oFilter);
+		$aValidIds = array(0); // Make sure that we have at least one value in the list
+		while($oObj = $oErrorObjectSet->Fetch())
 		{
-			$sResult = 'orange';
+			$aValidIds[] = $oObj->GetKey(); 
 		}
-		return $sResult;
+		$oFilter = clone $oDefinitionFilter;
+		$oFilter->AddCondition('id', $aValidIds, 'NOTIN');
+		$oErrorObjectSet = new CMDBObjectSet($oFilter);
+	}
+	return $oErrorObjectSet;
+}
+
+function GetReportColor($iTotal, $iErrors)
+{
+	$sResult = 'red';
+	if ( ($iTotal == 0) || ($iErrors / $iTotal) <= 0.05 )
+	{
+		$sResult = 'green';
+	}
+	else if ( ($iErrors / $iTotal) <= 0.25 )
+	{
+		$sResult = 'orange';
 	}
+	return $sResult;
+}
+
+try
+{
+	require_once('../approot.inc.php');
+	require_once(APPROOT.'/application/application.inc.php');
+	require_once(APPROOT.'/application/itopwebpage.class.inc.php');
+	
+	require_once(APPROOT.'/application/startup.inc.php');
+	$operation = utils::ReadParam('operation', '');
+	$oAppContext = new ApplicationContext();
+	
+	require_once(APPROOT.'/application/loginwebpage.class.inc.php');
+	LoginWebPage::DoLogin(); // Check user rights and prompt if needed
+	
+	$oP = new iTopWebPage(Dict::S('UI:Audit:Title'));
 	
 	switch($operation)
 	{