//workflow for redirecting

//we will only redirecting if there are no errors

if (count($WorkFlowReturnArray['Errors']) == 0 && count ($WorkFlowReturnArray['RuleErrors']) == 0)
{

		switch ($ApplyFor)
		{
		case COLLECTION_WORKFLOW_APPLY_IN_ADMIN_ADD:
		
						//if being in admin there are 2 situations
						//we execute from inside the cms or from the front end as a dialog window
						if ($ExtraGetParams['dialog']==1)
						{
								if (isset($WorkFlowReturnArray['ApprovalID']) )
								{
									if ($SuperAdminUser == true)
									{
											$smarty->assign('AwaitingApprovalRowID',$WorkFlowReturnArray['EditedID']);
									}
									
									$smarty->assign('AwaitingApproval',1);
								}	
								$smarty->display (ADMIN_APP_DIR.'/closeDialog.html');
								die();
						}
						
						if (isset($WorkFlowReturnArray['ApprovalID']) )
						{
							if ($SuperAdminUser == true)
							{
								header("Location: /".ADMIN_APP_DIR."/admin.php?". $QueryURLString."&apinfo=approve&eid=".$WorkFlowReturnArray['InsertedID']);
							}
							else
							{
								header("Location: /".ADMIN_APP_DIR."/admin.php?". $QueryURLString."&apinfo=waitapprove");
							}	
						}
						else
						{
							header("Location: /".ADMIN_APP_DIR."/admin.php?". $QueryURLString."&eid=".$WorkFlowReturnArray['InsertedID']);
						}
						die();
		
		  break;  //end admin add specific code
		case COLLECTION_WORKFLOW_APPLY_IN_ADMIN_EDIT:
		  			
						if ($ExtraGetParams['dialog']==1)
						{
								if (isset($WorkFlowReturnArray['ApprovalID']) )
								{
									if ($SuperAdminUser == true)
									{
											$smarty->assign('AwaitingApprovalRowID',$WorkFlowReturnArray['EditedID']);
									}
									
									$smarty->assign('AwaitingApproval',1);
								}	
								$smarty->display (ADMIN_APP_DIR.'/closeDialog.html');
								die();
						}
						
						if (isset($WorkFlowReturnArray['ApprovalID']) )
						{
							if ($SuperAdminUser == true)
							{
								header("Location: /".ADMIN_APP_DIR."/admin.php?". $QueryURLString."&apinfo=approve&eid=".$WorkFlowReturnArray['EditedID']);
							}
							else
							{
								header("Location: /".ADMIN_APP_DIR."/admin.php?". $QueryURLString."&apinfo=waitapprove&eid=".$ExtraGetParams['eid']);
							}	
						}
						else
						{
							header("Location: /".ADMIN_APP_DIR."/admin.php?". $QueryURLString."&eid=".$EditID);
						}	
						die();
		  
		  
		  break; //end admin edit specific code
		case COLLECTION_WORKFLOW_APPLY_IN_ADMIN_DELETE:
		  
		  				if ($ExtraGetParams['dialog']==1)
						{
								$smarty->display (ADMIN_APP_DIR.'/closeDialog.html');
								die();
						}
						
						if ($SuperAdminUser == true && isset($WorkFlowReturnArray['ApprovalID']))
						{
							header("Location: /".ADMIN_APP_DIR."/admin.php?". $QueryURLString."&eid=".$ExtraGetParams['did']);
						}
						else
						{
							header("Location: /".ADMIN_APP_DIR."/admin.php?". $QueryURLString);
						}
						die();
		  
		  break;  //end admin delete specific code
		case COLLECTION_WORKFLOW_APPLY_IN_FRONTEND_ADD:
		
					
					$RedirectActive		= $WorkFlow['WorkflowSetting'][$this->_getCollectionFieldName($WFlowCollection, 3)];
					$RedirectURL 		= $WorkFlow['WorkflowSetting'][$this->_getCollectionFieldName($WFlowCollection, 4)];
					$RedirectHTTPS		= $WorkFlow['WorkflowSetting'][$this->_getCollectionFieldName($WFlowCollection, 5)];
						
					
					if ($RedirectActive == 'on')		
					{
							$pos = strpos($RedirectURL, 'http');
							
							if ($pos == false)
							{
									
									$tmpUrl = $smarty->fetch('string:'. $RedirectURL);
									if ($RedirectHTTPS == 'on')
									{
											$urlTo = 'https://' . $_SERVER['HTTP_HOST']. $tmpUrl;
									}
									else
									{
											$urlTo = 'http://' . $_SERVER['HTTP_HOST']. $tmpUrl;
									}
							}
							else
							{
									$urlTo = $RedirectURL;
							}
							
							header('Location: '. $urlTo);
							die();
					}		
		
		  break;  //end front end add specific code
		case COLLECTION_WORKFLOW_APPLY_IN_FRONTEND_EDIT:
		  		
				
					$RedirectActive		= $WorkFlow['WorkflowSetting'][$this->_getCollectionFieldName($WFlowCollection, 3)];
					$RedirectURL 		= $WorkFlow['WorkflowSetting'][$this->_getCollectionFieldName($WFlowCollection, 4)];
					$RedirectHTTPS		= $WorkFlow['WorkflowSetting'][$this->_getCollectionFieldName($WFlowCollection, 5)];
					
					
					
					if ($RedirectActive == 'on')		
					{
							$pos = strpos($RedirectURL, 'http');
							
							if ($pos == false)
							{
									
									$tmpUrl = $smarty->fetch('string:'. $RedirectURL);
									if ($RedirectHTTPS == 'on')
									{
											$urlTo = 'https://' . $_SERVER['HTTP_HOST']. $tmpUrl;
									}
									else
									{
											$urlTo = 'http://' . $_SERVER['HTTP_HOST']. $tmpUrl;
									}
							}
							else
							{
									$urlTo = $RedirectURL;
							}
							header('Location: '. $urlTo);
							die();
					}		
		  
		  
		  break; //end front end edit specific code
		case COLLECTION_WORKFLOW_APPLY_IN_FRONTEND_DELETE:
		  
		  
		  
		  break;   //end front end delete specific code
		default:
		  
		  // we will not run any code here
		  
		} 



} //end workflow for redirecting