<?

/*
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][209];
	$BrowserTitle = $MsgText[9][209];
	$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][174].'</a> > '.$MsgText[9][209];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[905] == 'y') {
		
			$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 ($ecSettings['OrdersEmail'] == '') {
				$ecSettings['OrdersEmail'] = $Settings['ContactEmail'];
			}
			
		
			
			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);
				
				if ($FormArguments['OrderAction'] == 'record_payment') {
			
					if ($row['PaymentReceived'] < 1) {
				
						if ($FormArguments['AmPm'] == 'pm') {
							$FormArguments['Hour'] += 12;
						}
						$DateCode = mktime($FormArguments['Hour'], $FormArguments['Minute'], 0, $FormArguments['Month'], $FormArguments['Day'], $FormArguments['Year']);
		
		
						$query = "update `".$Settings['DBPrefix']."ec-Orders` set PaymentReceived='".$DateCode."', PaymentMethod='".$FormArguments['PaymentMethod']."', PaymentDetails='".$FormArguments['PaymentDetails_'.$FormArguments['PaymentMethod']]."', PaymentDetails2='".$FormArguments['PaymentDetails2_'.$FormArguments['PaymentMethod']]."' where RecordNumber=".$FormArguments['OrderID']." limit 1";
						$result = mysql_query($query) or die (mysql_error());
						
						
						if ($FormArguments['NotifyCustomer'] == 'y') {
						
							if ($FormArguments['PaymentDetails_'.$FormArguments['PaymentMethod']] != '') {
								if ($FormArguments['PaymentDetails2_'.$FormArguments['PaymentMethod']] != '') {
									$FormArguments['PaymentDetails_'.$FormArguments['PaymentMethod']] .= "\n". $FormArguments['PaymentDetails2_'.$FormArguments['PaymentMethod']];
								}
								
								$AdditionalInformation = "\n\n".$MsgText[9][228].":\n".$FormArguments['PaymentDetails_'.$FormArguments['PaymentMethod']]."\n";
							}
							
							$Message = $MsgText[9][229]." ".$FormArguments['OrderID']."-".$row['OrderID'].".".$AdditionalInformation."\n\n".$MsgText[9][230]." ".$MsgText[9][239]."\n\n\n".$MsgText[9][231]."\n\n\n".$Settings['SiteName']."\n".$Settings['BaseURL'];
							
							$query = "insert into `".$Settings['DBPrefix']."ec-StatusMessages` (Account, OrderNum, DateCode, Title, Text) values ('".$row['Account']."', '".$FormArguments['OrderID']."', '".$DateCode."', '".str_replace('\'','\\\'',$MsgText[9][232])."', '".addslashes($Message)."')";
							$result = mysql_query($query) or die (mysql_error());
							
							$query2 = "select * from `".$Settings['DBPrefix']."core-Users` where RecordNumber='".$row['Account']."' limit 1";
							$result2 = mysql_query($query2) or die (mysql_error());
							$row2 = mysql_fetch_array($result2);
							
							$NotifyEmail = $row2['Email'];
							
												
							mail($NotifyEmail, $MsgText[9][232].' '.$FormArguments['OrderID'].'-'.$row['OrderID'], $Message, 'From: "'.$Settings['SiteName'].'" <'.$ecSettings['OrdersEmail'].'>','-f'.$ecSettings['OrdersEmail']);
							
						}
						
					
						$PageContents = '<br><br>'.$MsgText[9][233].'<br><br><a href="'.$MainURL.'/admin/store-orderdetails/'.$FormArguments['OrderID'].'.html">'.$MsgText[9][234].'</a><br><br><a href="'.$MainURL.'/admin/store-orders.html">'.$MsgText[9][235].'</a>';
					
					
					}
					else {
					
						$PageContents = '<br><br>'.$MsgText[9][221];
				
					}
					
				} // end if $FormArguments['OrderAction'] == 'record_payment'
				
				else if ($FormArguments['OrderAction'] == 'mark_shipped') {
			
					if ($row['ShippedDate'] < 1) {
				
						if ($FormArguments['AmPm'] == 'pm') {
							$FormArguments['Hour'] += 12;
						}
						$DateCode = mktime($FormArguments['Hour'], $FormArguments['Minute'], 0, $FormArguments['Month'], $FormArguments['Day'], $FormArguments['Year']);
		
		
						$query = "update `".$Settings['DBPrefix']."ec-Orders` set ShippedDate='".$DateCode."', ShippingDetails='".$FormArguments['ShippingDetails']."', ShippingDetails2='".$FormArguments['ShippingDetails2']."' where RecordNumber=".$FormArguments['OrderID']." limit 1";
						$result = mysql_query($query) or die (mysql_error());
						
						
						if ($FormArguments['NotifyCustomer'] == 'y') {
						
							if ($FormArguments['ShippingDetails'] != '') {
								if ($FormArguments['ShippingDetails2'] != '') {
									$FormArguments['ShippingDetails'] .= "\n". $FormArguments['ShippingDetails2'];
								}
								
								$AdditionalInformation = "\n\n".$MsgText[9][236].":\n".$FormArguments['ShippingDetails']."\n";
							}
							
							
							$Message = $MsgText[9][237]." ".$FormArguments['OrderID']."-".$row['OrderID']." ".$MsgText[9][238].$AdditionalInformation."\n\n".$MsgText[9][239]."\n\n\n".$MsgText[9][231]."\n\n\n".$Settings['SiteName']."\n".$Settings['BaseURL'];
							
							$query = "insert into `".$Settings['DBPrefix']."ec-StatusMessages` (Account, OrderNum, DateCode, Title, Text) values ('".$row['Account']."', '".$FormArguments['OrderID']."', '".$DateCode."', '".str_replace('\'','\\\'',$MsgText[9][240])."', '".addslashes($Message)."')";
							$result = mysql_query($query) or die (mysql_error());
							
							$query2 = "select * from `".$Settings['DBPrefix']."core-Users` where RecordNumber='".$row['Account']."' limit 1";
							$result2 = mysql_query($query2) or die (mysql_error());
							$row2 = mysql_fetch_array($result2);
							
							$NotifyEmail = $row2['Email'];
							
							
							mail($NotifyEmail, $MsgText[9][240].' '.$FormArguments['OrderID'].'-'.$row['OrderID'], $Message, 'From: "'.$Settings['SiteName'].'" <'.$ecSettings['OrdersEmail'].'>','-f'.$ecSettings['OrdersEmail']);
							
						}
										
					
						$PageContents = '<br><br>'.$MsgText[9][241].'<br><br><a href="'.$MainURL.'/admin/store-orderdetails/'.$FormArguments['OrderID'].'.html">'.$MsgText[9][234].'</a><br><br><a href="'.$MainURL.'/admin/store-orders.html">'.$MsgText[9][235].'</a>';
					
					
					}
					else {
					
						$PageContents = '<br><br>'.$MsgText[9][227];
				
					}
					
				} // end if $FormArguments['OrderAction'] == 'mark_shipped'
			
			
			}
			else {
				$PageContents = $MsgText[0][98];
			}
			
				
		}
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}

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




?>
