<?php
include("../include/session.php");


	date_default_timezone_set('Africa/Gaborone');
	$entry_date = date("Y-m-d H:i:s", time()); 
		
	$table_name = $_SESSION['db_prefix']."_customer";
	$cust_no_query = "SELECT cust_no FROM $table_name ORDER BY cust_no DESC LIMIT 1  ";
	$cust_no_result = mySQL_query($cust_no_query);
	$cust_no_num = mysql_num_rows($cust_no_result);
	
	if ($cust_no_num==0) {
			$cust_no = 1000;
	}
	else {
		$cust_no = mysql_result($cust_no_result, 0, "cust_no") + 1;
	}
	
	
	$table_name = $_SESSION['db_prefix']."_customer";
	$accountQuery = "INSERT INTO $table_name (cust_no, account, account_type, comp_name, bag_box, box_no, postal_place, phys_address, phys_place, country, phone, fax, vat_no, contact_1, cell_1, email_1, contact_2, cell_2, email_2, web_site, notes) VALUES ('".$cust_no."', 'corporate', '".$_SESSION['credit_cash']."', '".$_SESSION['comp_name']."', '".$_SESSION['AddressText1']."', '".$_SESSION['AddressText2']."', '".$_SESSION['PlaceText']."', '".$_SESSION['AddressText3']."', '".$_SESSION['PlaceText2']."', '".$_SESSION['CountryText']."', '".$_SESSION['PhoneText']."', '".$_SESSION['FaxText']."', '".$_SESSION['VATText']."', '".$_SESSION['ContactText1']."', '".$_SESSION['CellText1']."', '".$_SESSION['emailText1']."', '".$_SESSION['ContactText2']."', '".$_SESSION['CellText2']."', '".$_SESSION['emailText2']."', '".$_SESSION['WebText']."', '".$_SESSION['RemarksText']."' )";
	execsql($accountQuery);
	
	$table_name = $_SESSION['db_prefix']."_customer";
	$cust_id_query = "SELECT cust_id FROM $table_name WHERE cust_no = '".$cust_no."' ";
	$cust_id_result = mySQL_query($cust_id_query);
	$cust_id = mysql_result($cust_id_result, 0, "cust_id");
	
                

	$table_name = $_SESSION['db_prefix']."_tracking_orders";
	$trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$_SESSION['username']."', '40', '', '".$cust_no."' ,'','' )";
	$trackingResult = mySQL_query($trackingQuery);	
	
	if (isset($_GET['new_button']) )
	   {
		 $action='newAccountWiz0.php';
	   }
		 
	if (isset($_GET['finish_button']) )
	  {
		$action='account_details.php?cust_id='.$cust_id;
	  }
	
?>
<?php
     $_SESSION['comp_name'] ="";
	 $_SESSION['AddressText1'] = "";
	 $_SESSION['AddressText2'] = "";
	 $_SESSION['PlaceText'] = "";
	 $_SESSION['AddressText3'] = "";
	 $_SESSION['PlaceText2'] = "";
	 $_SESSION['CountryText'] = "";
	 $_SESSION['ContactText'] = "";
	 $_SESSION['PhoneText'] = "";
	 $_SESSION['FaxText'] = "";
	 $_SESSION['VATText'] = "";
	 $_SESSION['ContactText1'] ="";
	 $_SESSION['CellText1'] = "";
	 $_SESSION['emailText1'] = "";
	 $_SESSION['ContactText2'] ="";
	 $_SESSION['CellText2'] = "";
	 $_SESSION['emailText2'] = "";
	 $_SESSION['RemarksText'] = "";
	 
?>
<script language="javascript" type="text/javascript">
        
		  window.location="<?php echo $action ?> ";
        
       </script>