<?php
extract($_POST);
extract($_SESSION);
extract($_COOKIE);
ini_set('display_errors','off');
error_reporting(E_ALL);
$noupdate = 0;
// edit user account details
//echo" $submitnoupt =$noupdate=";
if($submit)
	{
		session_start();
		include("admin/config.php");


		// check relevant fields have been filled
		if ((empty($f_name))or(empty($l_name))or(empty($add_1))or(empty($town))or(empty($county))or(empty($postcode))or(empty($country))or(empty($phone)))
			{
                              //  echo"=================nie empty====================<br>";
				include( "admin/settings.inc.php");

				include( "shoppingcart.php");

				include("images/makethumb.txt");

				include( "header.inc.php");

				$cart = new Cart;

				include("subheader.inc.php"); 

				// start border
				sb("100%",$la_register,$colour_1,$bg_colour);

				echo"<a href=\"index.php\" target=\"_self\">$la_search_home</a> > $la_register<br>";
				
				echo "<p align=\"center\"><font color=#990000><b>$la_account_form_must</b></font></p>";
				$noupdate=1;
				echo"<p align=\"center\"><a href = \"javascript:history.back()\">$la_customer_try_again</a></p>";
				
				eb($bg_colour,$colour_1);
				include("subfooter.inc.php");
				include("footer.inc.php");
				exit;
			} //else
  // {echo"================= empty ====================<br>"; }
		
		if (!eregi("[0-9]",$phone))
			{
    // echo"=================eregi [0-9]====================<br>";
				include( "admin/settings.inc.php");

				include( "shoppingcart.php");

				include("images/makethumb.txt");

				include( "header.inc.php");

				$cart = new Cart;

				include("subheader.inc.php"); 

				// start border
				sb("100%",$la_register,$colour_1,$bg_colour);

				echo"<a href=\"index.php\" target=\"_self\">$la_search_home</a> > $la_register<br>";
				
				echo "<p align='center'><font color=#990000><b>$la_account_tel_validate</b></font></p>";
				$noupdate=1;
				echo"<p align=\"center\"><a href = \"javascript:history.back()\">$la_customer_try_again</a></p>";
				eb($bg_colour,$colour_1);
				include("subfooter.inc.php");
				include("footer.inc.php");
				exit;
	}
	// check email was entered or valid

	
	// make sure no other customer is using the email
    $dupe_email = mysql_query ("select * from ".$prefix."store_customer where email = '$email'");
	if (mysql_num_rows($dupe_email)>0)
		{
                               //    echo"=================dupe email====================<br>";
				include( "admin/settings.inc.php");

				include( "shoppingcart.php");

				include("images/makethumb.txt");

				include( "header.inc.php");

				$cart = new Cart;

				include("subheader.inc.php"); 

				// start border
				sb("100%",$la_register,$colour_1,$bg_colour);

				echo"<a href=\"index.php\" target=\"_self\">$la_search_home</a> > $la_register<br>";
			

			
			print "<p align='center'><font color=#990000><b>Duplicate E-mail Found !</b></font></p>";
			$noupdate=1;
			echo"<p align=\"center\"><a href = \"javascript:history.back()\">$la_customer_try_again</a></p>";
			eb($bg_colour,$colour_1);
			include("subfooter.inc.php");
			include("footer.inc.php");
			exit;
			if ((!ereg("^[a-zA-Z0-9_.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email))or(empty($email)))
			{
				echo "<p align='center'><font color=#990000><b>$la_customer_email_inval</b></font></p>";
                                $noupdate=1;
                                echo"<p align=\"center\"><a href = \"javascript:history.back()\">$la_customer_try_again</a></p>";
			eb($bg_colour,$colour_1);
			include("subfooter.inc.php");
			include("footer.inc.php");
			exit;
			}
		}
	// check passwords match
	if($password1!=$password2)
		{
                         //  echo"================= rozne passwords====================<br>";
			include( "admin/settings.inc.php");

			include( "shoppingcart.php");

			include("images/makethumb.txt");

			include( "header.inc.php");

			$cart = new Cart;

			include("subheader.inc.php"); 

			// start border
			sb("100%",$la_register,$colour_1,$bg_colour);

			echo"<a href=\"index.php\" target=\"_self\">$la_search_home</a> > $la_register<br>";
			
			echo "<p align='center'><font color=#990000><b>$la_account_password_match</b></font></p>";
			$noupdate=1;
			echo"<p align=\"center\"><a href = \"javascript:history.back()\">$la_customer_try_again</a></p>";
			eb($bg_colour,$colour_1);
			include("subfooter.inc.php");
			include("footer.inc.php");
			exit;
		}
    
	// check password length 
	if ((strlen($password1)<6 || strlen($password1) >20)and(strlen($password2)<6 || strlen($password2) >20))
		{
                       //     echo"=================dlugosc password====================<br>";
			include( "admin/settings.inc.php");

			include( "shoppingcart.php");

			include("images/makethumb.txt");

			include( "header.inc.php");

			$cart = new Cart;

			include("subheader.inc.php"); 

			// start border
			sb("100%",$la_register,$colour_1,$bg_colour);

			echo"<a href=\"index.php\" target=\"_self\">$la_search_home</a> > $la_register<br>";
			
			echo "<p align='center'><font color=#990000><b>$la_account_password_length</b></font></p>";
			$noupdate = 1;
			echo"<p align=\"center\"><a href = \"javascript:history.back()\">$la_customer_try_again</a></p>";
			eb($bg_colour,$colour_1);
			include("subfooter.inc.php");
			include("footer.inc.php");
			exit;
		}
	
	// if ok update database
    if($noupdate!==1)
		{
                      //     echo"================= noupdate <> 1====================<br>";
			include( "admin/settings.inc.php");

			include( "shoppingcart.php");

			include("images/makethumb.txt");

			$valid_user = $email;
			//odkomentowacsession_register("valid_user");
			$_SESSION[valid_user]=$valid_user;

			$cus_date=date("Ymd");
			$cus_time=date("H:i");
			$enc_pass = md5($password1);
			$ip= $_SERVER["REMOTE_ADDR"];
                        $name="$f_name $l_name";
			$sql= mysql_query ("insert into ".$prefix."store_customer set email='$email', company='$company',name='$name', f_name='$f_name',l_name='$l_name', add_1='$add_1', add_2='$add_2', town='$town', county='$county', postcode='$postcode', country='$country', phone='$phone', perm='$perm', ip='$ip',date='$cus_date',time='$cus_time', password='$enc_pass'");
			
			include( "header.inc.php");

			$cart = new Cart;

			include("subheader.inc.php");
                        include("menu.inc.php");

			// start border
			sb("100%",$la_register,$colour_1,$bg_colour);

			echo"<a href=\"index.php\" target=\"_self\">$la_search_home</a> > $la_register<br>";
			
			echo"<p align=\"center\"><b>$la_register_comp</b></p>";

			$sql_select = mysql_query( "select * from ".$prefix."store_customer where email='$email'");

			// Email user
			$subject = "$la_order_reg_details";
			$message = "$la_account_dear $name,\n$la_order_reg_thank $site_business\n\n";
			$message .= "$la_order_look_after\n";
			$message .= "----------------------------------------------\n";
			$message .= "  $la_account_username: $email\n";
			$message .= "  $la_account_password: $password1\n";
			$message .= "----------------------------------------------\n";
			$message .="\n$la_order_rem_pass";
			$message .= "\r\n\n$la_account_ending,\n\n\n$site_business\n$site_url";
		 
			mail($email, $subject, $message, "From: $site_email");
	
			while ($row = mysql_fetch_array($sql_select))
				{
					$email=$row["email"]; 
					$name= $row["name"];
					$add_1=$row["add_1"]; 
					$add_2=$row["add_2"];
					$town=$row["town"];
					$county=$row["county"];
					$postcode=$row["postcode"];
					$country=$row["country"];
					$phone=$row["phone"];
					$customer_id=$row["customer_id"];
					$perm=$row["perm"];
				}

			echo"<br><form method=\"post\" action=\"account.php\">
			<table align=\"center\" width=\"550\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
				<tr>
					<td bgcolor=\"$colour_2\">
						<table cellpadding=\"2\" cellspacing=\"1\" border=\"0\" width=\"100%\" align=\"center\">
							<tr bgcolor=\"$colour_1\"> 
								<td width=\"100%\" height=\"20\"colspan=\"2\" background=\"images/bevel_bg.gif\"><b>$la_register_det</b></td>
							</tr>
							<tr bgcolor=\"$colour_1\">
								<td width=\"40%\"><b>Company Name</b></td>
								<td width=\"60%\">$company</td>
							</tr>
							<tr bgcolor=\"$colour_1\"> 
								<td width=\"40%\">$la_account_full_name</td>
								<td width=\"60%\">$name</td>
							</tr>
							<tr bgcolor=\"$colour_1\">
								<td width=\"40%\">$la_account_email</td>
								<td width=\"60%\">$email</td>
							</tr>
							<tr bgcolor=\"$colour_1\"> 
								<td width=\"40%\">$la_account_add_1</td>
								<td width=\"60%\">$add_1</td>
							</tr>
							<tr bgcolor=\"$colour_1\">
								<td width=\"40%\">$la_account_add_2</td>
								<td width=\"60%\">$add_2</td>
							</tr>
							<tr bgcolor=\"$colour_1\"> 
								<td width=\"40%\">$la_account_town</td>
								<td width=\"60%\">$town</td>
							</tr>
							<tr bgcolor=\"$colour_1\"> 
								<td width=\"40%\">$la_account_state</td>
								<td width=\"60%\">$county</td>
							</tr>
							<tr bgcolor=\"$colour_1\">
								<td width=\"40%\">$la_account_zip</td>
								<td width=\"60%\">$postcode</td>
							</tr>
							<tr bgcolor=\"$colour_1\"> 
								<td width=\"40%\">$la_account_country</td>
								<td width=\"60%\">$country</td>
							</tr>
							<tr bgcolor=\"$colour_1\">
								<td width=\"40%\">$la_account_phone_no</td>
								<td width=\"60%\">$phone</td>
							</tr>
							<tr bgcolor=\"$colour_1\">
								<td width=\"40%\">&nbsp;</td>
								<td width=\"60%\"><input type=\"submit\" class=\"submit\" name=\"submit\" value=\"$la_edit\"></td>
							</tr>
						</table>
					</td>
				</tr>
			</table></form>";
		}

}//end task edit

if(!$submit)
	{
		session_start();

		include("admin/config.php");

		include( "admin/settings.inc.php");

		include( "shoppingcart.php");

		include("images/makethumb.txt");

		include( "header.inc.php");

		$cart = new Cart;

		include("subheader.inc.php"); 

		// start border
		sb("100%",$la_register,$colour_1,$bg_colour);

		echo"<a href=\"index.php\" target=\"_self\">$la_search_home</a> > $la_register<br>";
		
		// display table
		echo"<br><form method=\"post\" action=\"register.php\">
					<table align=\"center\" width=\"550\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
						<tr>
							<td bgcolor=\"$colour_2\">
								<table cellpadding=\"2\" cellspacing=\"1\" border=\"0\" width=\"100%\" align=\"center\">
									<tr bgcolor=\"$colour_1\">
										<td width=\"100%\" height=\"20\"colspan=\"2\" background=\"images/bevel_bg.gif\"><b>$la_customer_add_ent</b></td>
									</tr>
									<tr bgcolor=\"$colour_1\">
										<td width=\"40%\"><b>Company Name:</b></td>
										<td width=\"60%\"><input type=\"text\" class=\"textbox\" name=\"company\" size=\"25\" maxlength=\"40\"></td>
									</tr>
									<tr bgcolor=\"$colour_1\">
										<td width=\"40%\"><b>First Name:</b></td>
										<td width=\"60%\"><input type=\"text\" class=\"textbox\" name=\"f_name\" size=\"25\" maxlength=\"40\"><font color=\"#990000\">*</font></td>
									</tr>
									<tr bgcolor=\"$colour_1\">
										<td width=\"40%\"><b>Last Name:</b></td>
										<td width=\"60%\"><input type=\"text\" class=\"textbox\" name=\"l_name\" size=\"25\" maxlength=\"40\"><font color=\"#990000\">*</font></td>
									</tr>
									<tr bgcolor=\"$colour_1\">
										<td width=\"40%\">$la_account_email</td>
										<td width=\"60%\"><input type=\"text\" class=\"textbox\" name=\"email\" size=\"25\" maxlength=\"40\"><font color=\"#990000\">*</font></td>
									</tr>
									<tr bgcolor=\"$colour_1\"> 
										<td width=\"40%\">$la_account_add_1</td>
										<td width=\"60%\"><input name=\"add_1\" class=\"textbox\" type=\"text\" size=\"25\"><font color=\"#990000\">*</font></td>
									</tr>
									<tr bgcolor=\"$colour_1\">
										<td width=\"40%\">$la_account_add_2</td>
										<td width=\"60%\"><input name=\"add_2\" class=\"textbox\" type=\"text\" size=\"25\"></td>
									</tr>
									<tr bgcolor=\"$colour_1\">
										<td width=\"40%\">$la_account_town</td>
										<td width=\"60%\"><input name=\"town\" class=\"textbox\" type=\"text\" size=\"25\"><font color=\"#990000\">*</font></td>
									</tr>
									<tr bgcolor=\"$colour_1\"> 
										<td width=\"40%\">$la_account_state</td>
										<td width=\"60%\"><input name=\"county\" class=\"textbox\" type=\"text\" size=\"25\"><font color=\"#990000\">*</font></td>
									</tr>
									<tr bgcolor=\"$colour_1\">
										<td width=\"40%\">$la_account_zip</td>
										<td width=\"60%\"><input name=\"postcode\" class=\"textbox\" type=\"text\" size=\"15\"><font color=\"#990000\">*</font></td>
									</tr>
									<tr bgcolor=\"$colour_1\">
										<td width=\"40%\">$la_account_country</td>
										<td width=\"60%\">";
							
											countries("country",$country,$prefix);
										echo"</td>
									</tr>
									<tr bgcolor=\"$colour_1\">
										<td width=\"40%\">$la_account_phone_no</td>
										<td width=\"60%\"><input name=\"phone\" class=\"textbox\" size=\"15\" type=\"text\"name=\"phone\"><font color=\"#990000\">*</font></td>
									</tr>
									<tr bgcolor=\"$colour_1\">
										<td>&nbsp;</td>
										<td>$la_account_no_emails<input type=\"checkbox\" name=\"perm\" value=\"N\" ";if($perm=="N"){echo"checked";}echo"></td>
									</tr>
									<tr bgcolor=\"$colour_1\">
										<td width=\"40%\">$la_customer_choose_pass</td>
										<td width=\"60%\"><input name=\"password1\" class=\"textbox\" type=\"password\"name=\"password1\"><font color=\"#990000\">*</font></td>
									</tr>
									<tr bgcolor=\"$colour_1\">
										<td width=\"40%\">$la_account_conf_pass</td>
										<td width=\"60%\"><input name=\"password2\" class=\"textbox\" type=\"password\"name=\"password2\"><font color=\"#990000\">*</font></td>
									</tr>
									<tr bgcolor=\"$colour_1\">
										<td width=\"40%\">&nbsp;</td>
										<td width=\"60%\"><input type=\"submit\" class=\"submit\" name=\"submit\" value=\"$la_register\"><br>$la_account_form_must</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</form>";
}// end if !$edit

eb($bg_colour,$colour_1);

include("subfooter.inc.php");

include("footer.inc.php");

?>