<?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 05-05-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;

//if the user is logged in let them be else redirect them to login
if (isset($_SESSION["logged_in"])){
	$smarty->assign("logged_in",1);
	$smarty->assign("username",$_SESSION["user"]);
	//check privs to find out if user 
	//is a seller, admin or user
	$status = checkPrivs();
	$smarty->assign("$status",1);
	
	//if (isset($_SESSION["admin"]) || isset($_SESSION["seller"])) {
	if (checkIfAdmin($_SESSION["user"],$_SESSION["pass"]) || checkIfSeller($_SESSION["user"],$_SESSION["pass"])) {
		if (isset($_POST["submit"]) && $_POST["submit"] == ADD_LISTING_FORM_SUBMIT_BUTTON) {
			$_POST = codeClean($_POST);
			$serializedfeature = serialize($_POST["features"]);
			$res = addListing($_POST["ad_title"],$_POST["make"],$_POST["model"],$_POST["vehicle_type"],$_POST["doors"],$_POST["color"],$_POST["mileage"],$_POST["year"],$_POST["listing_condition"],$_POST["engine"],$_POST["trans"],$_POST["drive_train"],$_POST["mpg"],$_POST["price"],$_POST["adddesc"],$serializedfeature,$_POST["vin"],$_POST["stock"],$_POST["state"],$_POST["zip"],$_POST["sellerid"],$_POST["seller"]);
			if ($res == 99) {
				$smarty->assign("success",ADD_LISTING_SUCCESS);
			} else {
				$smarty->assign("error_message",ADD_LISTING_ERROR);
			}
		}

		$smarty->assign("manufacturerslist",getManufacturersList());
		$smarty->assign("featurelist",getFeaturesList());
		$smarty->assign("drivetrainlist",getDriveTrainsList());
		$smarty->assign("typeslist",getTypesList());
		$smarty->assign("userdetails",getUserRecords($_SESSION["user"]));
		$smarty->assign("sellerslist",getSellers());
		$smarty->assign("stateslist",getStatesList());

	} else {
		header("Location, member.php");
		exit();
	}
} else {
	header("Location: login.php");
	exit();
}

$smarty->display('addlisting.tpl');
?>