//workflow for behaviours

//we will only run behaviours if there are no errors

if (count($WorkFlowReturnArray['Errors']) == 0 && count ($WorkFlowReturnArray['RuleErrors']) == 0)
{
		
		$collection_table 	= $this->_getCollectionTableName(COLLECTION_BEHAVIOURS);
		$addName 			= $this->_getCollectionFieldName(COLLECTION_BEHAVIOURS, COLLECTION_BEHAVIOURS_ADD);
		$deleteName 		= $this->_getCollectionFieldName(COLLECTION_BEHAVIOURS, COLLECTION_BEHAVIOURS_DELETE);
		$editName 			= $this->_getCollectionFieldName(COLLECTION_BEHAVIOURS, COLLECTION_BEHAVIOURS_EDIT);
		$collectionName		= $this->_getCollectionFieldName(COLLECTION_BEHAVIOURS, COLLECTION_BEHAVIOURS_COLLECTION);
		$pluginName			= $this->_getCollectionFieldName(COLLECTION_BEHAVIOURS, COLLECTION_BEHAVIOURS_CODE);
		$idName				= $this->_getCollectionFieldName(COLLECTION_BEHAVIOURS, 'ID');
		$adminName 			= $this->_getCollectionFieldName(COLLECTION_BEHAVIOURS, COLLECTION_BEHAVIOURS_ADMIN);
		$collectionFront	= $this->_getCollectionFieldName(COLLECTION_BEHAVIOURS, COLLECTION_BEHAVIOURS_FRONT_END);
		$collectionSort		= $this->_getCollectionFieldName(COLLECTION_BEHAVIOURS, COLLECTION_BEHAVIOURS_SORT_ORDER);
		
		switch ($ApplyFor)
		{
		case COLLECTION_WORKFLOW_APPLY_IN_ADMIN_ADD:
					
					$q = "SELECT $pluginName as pluginName FROM $collection_table WHERE $addName='on' and $adminName='on' and $collectionName='".$CollectionID."' order by " . $collectionSort;
		
		
		  break;  //end admin add specific code
		case COLLECTION_WORKFLOW_APPLY_IN_ADMIN_EDIT:
		  
		  			$q = "SELECT $pluginName as pluginName FROM $collection_table WHERE $editName='on' and $adminName='on' and $collectionName='".$CollectionID."' order by " . $collectionSort;
		  
		  break; //end admin edit specific code
		case COLLECTION_WORKFLOW_APPLY_IN_ADMIN_DELETE:
		  
		  		$q = "SELECT $pluginName as pluginName FROM $collection_table WHERE $deleteName='on' and $adminName='on' and $collectionName='".$CollectionID."' order by " . $collectionSort;
		  
		  break;  //end admin delete specific code
		case COLLECTION_WORKFLOW_APPLY_IN_FRONTEND_ADD:
		
					$q = "SELECT $pluginName as pluginName FROM $collection_table WHERE $addName='on' and $collectionFront='on' and $collectionName='".$CollectionID."' order by " . $collectionSort;
		
		  break;  //end front end add specific code
		case COLLECTION_WORKFLOW_APPLY_IN_FRONTEND_EDIT:
		  
		  			$q = "SELECT $pluginName as pluginName FROM $collection_table WHERE $editName='on' and $collectionFront='on' and $collectionName='".$CollectionID."' order by " . $collectionSort;
		  
		  break; //end front end edit specific code
		case COLLECTION_WORKFLOW_APPLY_IN_FRONTEND_DELETE:
		  
		  			$q = "SELECT $pluginName as pluginName FROM $collection_table WHERE $deleteName='on' and $collectionFront='on' and $collectionName='".$CollectionID."' order by " . $collectionSort;
		  
		  break;   //end front end delete specific code
		default:
		  
		  // we will not run any code here
		  
		} 

		$Behaviours = $this-> db -> queryAll($q);
		
		if ($Behaviours)
			foreach ( $Behaviours as $k => $v )
				eval($v['pluginName']);
				
				
		//we run functions if necessary
		$funcArray = array();
		$funcArray[1] = addslashes($ExtraGetParams['func']);
		$funcArray[2] = $ApplyFor;
		
		$functionsToRun = $this -> getRowsByColValues( COLLECTION_WORKFLOW_FUNCTIONS_TABLE_ID , $funcArray);		
		
		
		
		if (count($functionsToRun) > 0)
		{
				$funcCodeName = $this->_getCollectionFieldName(COLLECTION_WORKFLOW_FUNCTIONS_TABLE_ID, COLLECTION_WORKFLOW_FUNCTIONS_CODE_ID);
				
				foreach ($functionsToRun as $funcKey => $funcValue)
				{
												
						if ($funcValue[$funcCodeName] != '')
						{
							eval ($funcValue[$funcCodeName]);
						}				
				}
				
				
		}
				
		
} //end workflow for extra behaviours