<?

/*
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
*/



	// ========================================================================================
	
	// ========================================================================================
		
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[901] == 'y') {
		
			ReadFormArguments();
			Global $FormArguments;
			
			
			$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'];
			}
			
			
					$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['AdditionalShipping'] = str_replace($ecSettings['ThousandsSep'],'',$FormArguments['AdditionalShipping']);
					$FormArguments['AdditionalShipping'] = str_replace($ecSettings['DecimalSymbol'],'.',$FormArguments['AdditionalShipping']);  
					
												
			
			
			for ($x = 1; $x <= intval($FormArguments['NumItems']); $x++) {
			
				if (($FormArguments['ItemOption1_'.$x] != '' || $FormArguments['ItemID_'.$x] != '') && $FormArguments['ItemSelected_'.$x] == 'y') {
				
					if ($FormArguments['ItemStock_'.$x] == '') {
						$FormArguments['ItemStock_'.$x] = '-1';
					}
				
					$query = "insert into `".$Settings['DBPrefix']."ec-Items` (Product, ItemID, Option1, Option2, Price1, PriceQty1, Price2, PriceQty2, Price3, PriceQty3, Price4, PriceQty4, Price5, PriceQty5, Price6, PriceQty6, Price7, PriceQty7, Price8, PriceQty8, Price9, PriceQty9, Price10, PriceQty10, Stock, StockMin, StockMax, ShippingWeight, AdditionalShipping) values ('".$FormArguments['ProductID']."', '".$FormArguments['ItemID_'.$x]."', '".$FormArguments['ItemOption1_'.$x]."', '".$FormArguments['ItemOption2_'.$x]."', '".number_format($FormArguments['Price1'],4,'.','')."', '1', '".number_format($FormArguments['Price2'],4,'.','')."', '".number_format($FormArguments['PriceQty2'],0,'.','')."', '".number_format($FormArguments['Price3'],4,'.','')."', '".number_format($FormArguments['PriceQty3'],0,'.','')."', '".number_format($FormArguments['Price4'],4,'.','')."', '".number_format($FormArguments['PriceQty4'],0,'.','')."', '".number_format($FormArguments['Price5'],4,'.','')."', '".number_format($FormArguments['PriceQty5'],0,'.','')."', '".number_format($FormArguments['Price6'],4,'.','')."', '".number_format($FormArguments['PriceQty6'],0,'.','')."', '".number_format($FormArguments['Price7'],4,'.','')."', '".number_format($FormArguments['PriceQty7'],0,'.','')."', '".number_format($FormArguments['Price8'],4,'.','')."', '".number_format($FormArguments['PriceQty8'],0,'.','')."', '".number_format($FormArguments['Price9'],4,'.','')."', '".number_format($FormArguments['PriceQty9'],0,'.','')."', '".number_format($FormArguments['Price10'],4,'.','')."', '".number_format($FormArguments['PriceQty10'],0,'.','')."', '".$FormArguments['ItemStock_'.$x]."', '".$FormArguments['ProductInventoryMin']."', '".$FormArguments['ProductInventoryMax']."', '".number_format(($FormArguments['ShippingWeight']+($FormArguments['ShippingWeightOz']/16)),4,'.','')."', '".number_format($FormArguments['AdditionalShipping'],4,'.','')."')";
					$result = mysql_query($query) or die (mysql_error());
				
					if ($FormArguments['ItemID_'.$x] == '') {
						$RecordNumberCreated = mysql_insert_id();
						
						$query = "update `".$Settings['DBPrefix']."ec-Items` set ItemID='".$RecordNumberCreated."' where RecordNumber='".$RecordNumberCreated."' limit 1";
						$result = mysql_query($query) or die (mysql_error());
					}
					
				}
			
			}
			
			
			$PageContents = $MsgText[9][67].'<br><br><b><a href="'.$MainURL.'/admin/store-products.html">'.$MsgText[0][564].'</a></b>';
		
		
		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}

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




?>
