<?PHP
//================================================================================
// PLEASE DO NOT REMOVE THIS HEADER!!!
//
// COPYRIGHT NOTICE
// This script is licensed under the GPL
// 
// Copyright 2007-2008 Alias 454 Studios and Brandon Keep (c) All rights reserved.
// Created 11/18/2007   
// Brandon Keep,    http://www.openautoclassifieds.com
//                  http://www.alias454studios.com/scripts/
//
// Last Modified 04-12-2008 by
// Brandon Keep,    http://alias454studios.com
//================================================================================
// This software IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//================================================================================

require_once './Includes/configs/functions.php';
require_once './Includes/libs/Smarty.class.php';
include_once "./Includes/language/$site_lang.php";

$smarty = new Smarty;

$smarty->assign("manufacturerslist",getSearchList("make"));
$smarty->assign("modelslist",getSearchList("model"));
$smarty->assign("typeslist",getSearchList("vehicle_type"));

//Check if single user mode 1 or multi-user mode 0
if ($site_mode == 1 && !isset($_SESSION["admin"])) {
	header("Location: login.php");
} elseif ($site_mode == 0) {
	$smarty->assign("site_mode",1);
}

//The user is already logged in, not allowed to register.
//redirect to member home
$status = checkPrivs();
$smarty->assign("$status",1);

if (isset($_SESSION["logged_in"])){
	$smarty->assign("logged_in",1);
	if (!isset($_SESSION["admin"])){
		header("Location: member.php");
	}
}
	
//Multi-user mode. Allow new users to register
if (isset($_POST["submit"])) {
 	$res = registerUser($_POST["user"], $_POST["pass"], $_POST["email"], $_POST["first_name"], $_POST["last_name"], $_POST["phone"], $_POST["alt_phone"], $_POST["fax"], $_POST["agree"]);

	// Registration was successful
	if ($res == 99) {
		$smarty->assign("success",REGISTRATION_SUCCESS);
		//header("Location: login.php");
	} else {
		//keep users data in the form for resubmission
		$smarty->assign("formagree",$_POST["agree"]);
		$smarty->assign("formemail",htmlentities($_POST["email"]));
		$smarty->assign("formuser",htmlentities($_POST["user"]));
		$smarty->assign("first_name",htmlentities($_POST["first_name"])); 
		$smarty->assign("last_name",htmlentities($_POST["last_name"])); 
		$smarty->assign("phone",htmlentities($_POST["phone"]));
		$smarty->assign("alt_phone",htmlentities($_POST["alt_phone"]));
		$smarty->assign("fax",htmlentities($_POST["fax"]));

		//Errors during registration	
		if ($res == 1) {
			$smarty->assign("error_message",ALREADY_USER_ERROR);
			$smarty->assign("user_error",1);
		}
		if ($res == 2) {
			$smarty->assign("error_message",VALIDATE_EMAIL_ERROR);
			$smarty->assign("mail_error",1);		
		}
		if ($res == 3) {
			$smarty->assign("error_message",VALIDATE_USER_ERROR);
			$smarty->assign("user_error",1);
		}
		if ($res == 4) {
			$smarty->assign("error_message",ALREADY_EMAIL_ERROR);
			$smarty->assign("mail_error",1);
		}
		if ($res == 5) {
			$smarty->assign("error_message",CHECK_AGREE_ERROR);
			$smarty->assign("agree_error",1);
		}
		if ($res == 6) {
			$smarty->assign("error_message",SUPPLY_PASSWORD);
			$smarty->assign("pass_error",1);
		}
	}
}

$smarty->assign("register",1);
$smarty->display('register.tpl');
?>