<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/



	// ========================================================================================
	
	// ========================================================================================
	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_ecom.gif" width="20" height="21" align="middle"> '.$MsgText[9][16];
	$BrowserTitle = $MsgText[9][16];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="' . $MainURL . '/options.html">'.$MsgText[0][4].'</a> > <a href="'.$MainURL.'/admin/store-orders.html">'.$MsgText[9][15].'</a> > '.$MsgText[9][16];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[905] == 'y') {
					
			ReadFormArguments();
			Global $FormArguments;
			
			if (count($FormArguments) > 0) {
			
				$query = "select * from `".$Settings['DBPrefix']."ec-Orders` where RecordNumber='".$FormArguments['OrderID']."' limit 1";
				$result = mysql_query($query) or die (mysql_error());
				$row = mysql_fetch_array($result);
				
				$ShoppingCartContents = $row['Items'];
		
				if ($ShoppingCartContents != '') {
			
					$ItemsList = explode(',',$ShoppingCartContents);
					$ItemFound = false;
				
					for ($i = 0; $i < (count($ItemsList)-1); $i++) {
					
						list ($ItemNumA, $Qty) = explode('x',$ItemsList[$i]);
												
						list ($ItemNum, $Incentive) = explode('-', $ItemNumA);
						
						list ($Qty, $ItemPrice) = explode('@', $Qty);
					
					
						$query3 = "update `".$Settings['DBPrefix']."ec-Items` set Stock=Stock+".number_format($Qty,0,'','')." where RecordNumber='".$ItemNum."' and Stock>=0 limit 1";
						$result3 = mysql_query($query3) or die (mysql_error());
					
					}	
				}		
						
						
			
				$query = "delete from `".$Settings['DBPrefix']."ec-Orders` where RecordNumber='".$FormArguments['OrderID']."' limit 1";
				$result = mysql_query($query) or die (mysql_error());
						
				$PageContents = '<br><br>'.$MsgText[9][19].'<br><br><a href="'.$MainURL.'/admin/store-orders.html">'.$MsgText[9][20].'</a>';
			
			}
			else {
				$PageContents = $MsgText[0][98];
			}
			
				
		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}

	// ========================================================================================




?>
