<?

/*
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][70];
	$BrowserTitle = $MsgText[9][70];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="' . $MainURL . '/options.html">'.$MsgText[0][4].'</a> > <a href="'.$MainURL.'/admin/store-products.html">'.$MsgText[9][3].'</a> > <a href="'.$MainURL.'/admin/store-products_edit/'.$Arguments3.'.html">'.$MsgText[9][39].'</a> > '.$MsgText[9][70];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[901] == 'y') {
		
			ReadFormArguments();
			Global $FormArguments;
			
			
			if (count($FormArguments) > 0) {
			
				$query = "select * from `".$Settings['DBPrefix']."ec-Settings`";
				$result = mysql_query($query) or die (mysql_error());
				while ($row = mysql_fetch_array($result)) {
					$ecSettings[$row['Name']] = $row['Value'];
				}
						
		
				if ($FormArguments['DeleteItem'] == 'yes') {
					$query = "delete from `".$Settings['DBPrefix']."ec-Items` where RecordNumber='".$FormArguments['ItemIDToEdit']."' limit 1";
					$result = mysql_query($query) or die (mysql_error());	
				}
				else {
					
					if ($FormArguments['ItemID'] == '') {
						//$query = "select count(ItemID) as ItemsCount from `".$Settings['DBPrefix']."ec-Items` where Product='".$FormArguments['ProductID']."'";
						//$result = mysql_query($query) or die (mysql_error());
						//$row = mysql_fetch_array($result);
						
						//$FormArguments['ItemID'] = ($row['ItemsCount'] + 1);
						
						$FormArguments['ItemID'] = $FormArguments['ItemIDToEdit'];
					}
					
					
					if ($FormArguments['Option1'] == '') {
						$FormArguments['Option1'] = $FormArguments['NewOption1'];
					}
					if ($FormArguments['Option2'] == '') {
						$FormArguments['Option2'] = $FormArguments['NewOption2'];
					}
					
					
					if ($FormArguments['ProductInventory'] == '') {
						$FormArguments['ProductInventory'] = -1;
					}
					
					
					
					$FormArguments['Price1'] = str_replace($ecSettings['ThousandsSep'],'',$FormArguments['Price1']);
					$FormArguments['Price1'] = str_replace($ecSettings['DecimalSymbol'],'.',$FormArguments['Price1']);
					
					$FormArguments['Price2'] = str_replace($ecSettings['ThousandsSep'],'',$FormArguments['Price2']);
					$FormArguments['Price2'] = str_replace($ecSettings['DecimalSymbol'],'.',$FormArguments['Price2']);
					
					$FormArguments['Price3'] = str_replace($ecSettings['ThousandsSep'],'',$FormArguments['Price3']);
					$FormArguments['Price3'] = str_replace($ecSettings['DecimalSymbol'],'.',$FormArguments['Price3']);
					
					$FormArguments['Price4'] = str_replace($ecSettings['ThousandsSep'],'',$FormArguments['Price4']);
					$FormArguments['Price4'] = str_replace($ecSettings['DecimalSymbol'],'.',$FormArguments['Price4']);
					
					$FormArguments['Price5'] = str_replace($ecSettings['ThousandsSep'],'',$FormArguments['Price5']);
					$FormArguments['Price5'] = str_replace($ecSettings['DecimalSymbol'],'.',$FormArguments['Price5']);
					
					$FormArguments['Price6'] = str_replace($ecSettings['ThousandsSep'],'',$FormArguments['Price6']);
					$FormArguments['Price6'] = str_replace($ecSettings['DecimalSymbol'],'.',$FormArguments['Price6']);
					
					$FormArguments['Price7'] = str_replace($ecSettings['ThousandsSep'],'',$FormArguments['Price7']);
					$FormArguments['Price7'] = str_replace($ecSettings['DecimalSymbol'],'.',$FormArguments['Price7']);
					
					$FormArguments['Price8'] = str_replace($ecSettings['ThousandsSep'],'',$FormArguments['Price8']);
					$FormArguments['Price8'] = str_replace($ecSettings['DecimalSymbol'],'.',$FormArguments['Price8']);
					
					$FormArguments['Price9'] = str_replace($ecSettings['ThousandsSep'],'',$FormArguments['Price9']);
					$FormArguments['Price9'] = str_replace($ecSettings['DecimalSymbol'],'.',$FormArguments['Price9']);
					
					$FormArguments['Price10'] = str_replace($ecSettings['ThousandsSep'],'',$FormArguments['Price10']);
					$FormArguments['Price10'] = str_replace($ecSettings['DecimalSymbol'],'.',$FormArguments['Price10']); 
					
					
					$FormArguments['ComparePrice'] = str_replace($ecSettings['ThousandsSep'],'',$FormArguments['ComparePrice']);
					$FormArguments['ComparePrice'] = str_replace($ecSettings['DecimalSymbol'],'.',$FormArguments['ComparePrice']);
					
					$FormArguments['AdditionalShipping'] = str_replace($ecSettings['ThousandsSep'],'',$FormArguments['AdditionalShipping']);
					$FormArguments['AdditionalShipping'] = str_replace($ecSettings['DecimalSymbol'],'.',$FormArguments['AdditionalShipping']);
					
					
					
					$query = "update `".$Settings['DBPrefix']."ec-Items` set Product='".$FormArguments['ProductID']."', ItemID='".$FormArguments['ItemID']."', Option1='".$FormArguments['Option1']."', Option2='".$FormArguments['Option2']."', Price1='".number_format($FormArguments['Price1'],4,'.','')."', Price2='".number_format($FormArguments['Price2'],4,'.','')."', PriceQty2='".number_format($FormArguments['PriceQty2'],0,'.','')."', Price3='".number_format($FormArguments['Price3'],4,'.','')."', PriceQty3='".number_format($FormArguments['PriceQty3'],0,'.','')."', Price4='".number_format($FormArguments['Price4'],4,'.','')."', PriceQty4='".number_format($FormArguments['PriceQty4'],0,'.','')."', Price5='".number_format($FormArguments['Price5'],4,'.','')."', PriceQty5='".number_format($FormArguments['PriceQty5'],0,'.','')."', Price6='".number_format($FormArguments['Price6'],4,'.','')."', PriceQty6='".number_format($FormArguments['PriceQty6'],0,'.','')."', Price7='".number_format($FormArguments['Price7'],4,'.','')."', PriceQty7='".number_format($FormArguments['PriceQty7'],0,'.','')."', Price8='".number_format($FormArguments['Price8'],4,'.','')."', PriceQty8='".number_format($FormArguments['PriceQty8'],0,'.','')."', Price9='".number_format($FormArguments['Price9'],4,'.','')."', PriceQty9='".number_format($FormArguments['PriceQty9'],0,'.','')."', Price10='".number_format($FormArguments['Price10'],4,'.','')."', PriceQty10='".number_format($FormArguments['PriceQty10'],0,'.','')."', ComparePrice='".number_format($FormArguments['ComparePrice'],4,'.','')."', AdditionalShipping='".number_format($FormArguments['AdditionalShipping'],4,'.','')."', Stock='".$FormArguments['ProductInventory']."', StockMin='".$FormArguments['ProductInventoryMin']."', StockMax='".$FormArguments['ProductInventoryMax']."', ShippingWeight='".number_format(($FormArguments['ShippingWeight']+($FormArguments['ShippingWeightOz']/16)),4,'.','')."' where RecordNumber='".$FormArguments['ItemIDToEdit']."' limit 1";
					$result = mysql_query($query) or die (mysql_error());
				
				
				}
				
				
				header('Location: '.$MainURL.'/admin/store-products_edit/'.$FormArguments['ProductID'].'.html');
				
				
			}
			else {
			
				$PageContents = $MsgText[0][98];
			
			}
		
		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}

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




?>
