$CollectionID = $_GET['cid'];
$queryString = $_GET['querystring'];

$admin = false; 
if($_SESSION['FrontEndAdmin'] == 1)
{
	$admin = true;
}

$selectedRow = $api-> getCollectionSingleRow (array('collection_id' => 4, 'row_id' => $CollectionID));
$columnName = $api->_getCollectionFieldName(4, '2');

if ($selectedRow[$columnName] == 'on')
{
	header('Location: admin.php?systemerase=1&'.urldecode($queryString));
	die();
}

if(!$admin && !$api->CanUserAccess($_SESSION['AAuserid'],  4, $CollectionID))
{
		header('Location: admin.php?erase=0&'.urldecode($queryString));
		die();
}
else
{

$queryArray = array('collection_id'=>$CollectionID);
	
	if(!$admin)
	{
		$queryArray['userId']=$_SESSION['AAuserid'];
	}
	
	$table = $api->Filter($queryArray);
	
	$NumResults = count($table['AllResults']);

	$columnName = $api->_getCollectionFieldName($CollectionID, 'ID');
	$collectionSettings  = $api->getCollectionSettings($CollectionID);
	$taxonomy = $api->getCollectionTaxonomy($CollectionID);
	
	foreach ($table['Results'] as $k => $v)
	{
		$did = $v[$columnName];
				
		$args = array(  'CollectionID' => $CollectionID ,
							'ApplyFor' => 3 , //admin front end
							'UserID' => $user_id ,
							'SuperAdminUser' => $admin ,
							'SubmittedData' => $_POST ,
							'ExtraGetParams' => $_GET ,
							'CollectionSettings' => $collectionSettings ,
							'CollectionTaxonomy' => $taxonomy ,
							'UploadDirectory'  => $UploadDirectory ,
							'UploadPrefix'  => $UploadPrefix ,
							'Smarty'  => $smarty ,
							'DeleteID' => intval($did),
							'OverrideWorkflowIDs'=> array(0=>6)
						 );	
						 
		$WorkFlowReturnArray = $api -> Workflow ( $args );				 	
		
	}


}

header('Location: admin.php?erase=1&'.urldecode($queryString));
die();