{include file="header.tpl"}
 
<div id="sidebar">
{include file="sidebar.tpl"}
</div>

<div class="mainContent">

<h1>{$smarty.const.EDIT_LISTING_HEADER} <a href="listings.php?id={$listdata.0.id}">{$smarty.const.VIEW_THIS_LISTING}</a> </h1>

{if $success}
	<p class="green"><strong>{$success}</strong></p>
{elseif $error_message}
	<p class="red"><strong>{$error_message}</strong></p>
{/if}

{foreach item="records" from=$listdata}
<div class="float-center">
	{foreach item="image" from=$records.images}
		<div class="smallimageboxcontainer">
			<div class="editsmallimagebox">
				<img src="{$image.imagethumbpath}" alt="{if $image.mainimage}Main {/if}Image" />
			</div>
			<a href="editlisting.php?id={$records.id}&amp;action=delete&amp;imageid={$image.id}&amp;sellerid={$records.sellerid}">{$smarty.const.EDIT_LISTING_IMG_DELETE}</a><br />
			{if !$image.mainimage}<a href="editlisting.php?id={$records.id}&amp;action=markmain&amp;imageid={$image.id}&amp;sellerid={$records.sellerid}">{$smarty.const.EDIT_LISTING_IMG_MAIN}</a>{/if}
		</div>
	{/foreach}
</div>

<fieldset>
	<legend>{$smarty.const.EDIT_LISTING_LEGEND}</legend>
		<form action="editlisting.php" method="post">
			<h2>{$smarty.const.EDIT_LISTING_ENTER_INFO}</h2>
			<p><label for="ad_title">{$smarty.const.AD_TITLE}</label>
			<input id="ad_title" name="ad_title" type="text" size="30" maxlength="30" value="{$records.ad_title}" />
			</p>

			<p><label for="make">{$smarty.const.MANUFACTURER}</label>
			<select id="make" name="make" size="1">
				<option value="{$records.make}" selected="selected">{$records.make}</option>
			{foreach item="manufacturer" from=$manufacturerslist}
				<option value="{$manufacturer.manufacturer}">{$manufacturer.manufacturer}</option>
			{/foreach}
			</select>
			</p>
		
			<p><label for="model">{$smarty.const.MODEL}</label>
			<input id="model" name="model" type="text" size="30" maxlength="30" value="{$records.model}" />
			</p>

			<p><label for="vehicle_type">{$smarty.const.TYPE}</label>
			<select id="vehicle_type" name="vehicle_type" size="1">
				<option value="{$records.vehicle_type}" selected="selected">{$records.vehicle_type}</option>
			{foreach item="vehicle_type" from=$typeslist}
				<option value="{$vehicle_type.vehicle_type}">{$vehicle_type.vehicle_type}</option>
			{/foreach}
			</select>
			</p>

			<p><label for="doors">{$smarty.const.DOORS}</label>
			<select id="doors" name="doors" size="1">
				<option value="{$records.doors}" selected="selected">{$records.doors}</option>
				<option value="{$smarty.const.LISTING_FORM_DOORS_OPTION1}">{$smarty.const.LISTING_FORM_DOORS_OPTION1}</option>
				<option value="{$smarty.const.LISTING_FORM_DOORS_OPTION2}">{$smarty.const.LISTING_FORM_DOORS_OPTION2}</option>
				<option value="{$smarty.const.LISTING_FORM_DOORS_OPTION3}">{$smarty.const.LISTING_FORM_DOORS_OPTION3}</option>
				<option value="{$smarty.const.LISTING_FORM_DOORS_OPTION4}">{$smarty.const.LISTING_FORM_DOORS_OPTION4}</option>
				<option value="{$smarty.const.LISTING_FORM_DOORS_OPTION5}">{$smarty.const.LISTING_FORM_DOORS_OPTION5}</option>
			</select>
			</p>
			
			<p><label for="color">{$smarty.const.COLOR}</label>
			<input id="color" name="color" type="text" size="30" maxlength="30" value="{$records.color}" />
			</p>
			<p><label for="mileage">{$smarty.const.MILEAGE}</label>
			<input id="mileage" name="mileage" type="text" size="15" maxlength="10" value="{$records.mileage}" />
			</p>
			<p><label for="year">{$smarty.const.YEAR}</label>
			<input id="year" name="year" type="text" size="10" maxlength="4" value="{$records.year}" />
			</p>

			<p><label for="condition">{$smarty.const.CONDITION}</label>
			<select id="listing_condition" name="listing_condition" size="1">
				<option value="{$records.listing_condition}" selected="selected">{$records.listing_condition}</option>
				<option value="{$smarty.const.LISTING_FORM_CONDITION_OPTION1}">{$smarty.const.LISTING_FORM_CONDITION_OPTION1}</option>
 				<option value="{$smarty.const.LISTING_FORM_CONDITION_OPTION2}">{$smarty.const.LISTING_FORM_CONDITION_OPTION2}</option>
 				<option value="{$smarty.const.LISTING_FORM_CONDITION_OPTION3}">{$smarty.const.LISTING_FORM_CONDITION_OPTION3}</option>
			</select>
			</p>

			<p><label for="engine">{$smarty.const.ENGINE}</label>
			<input id="engine" name="engine" type="text" size="30" maxlength="30" value="{$records.engine}" />
			</p>
			
			<p><label for="trans">{$smarty.const.TRANS}</label>
			<select id="trans" name="trans" size="1">
				<option value="{$records.trans}" selected="selected">{$records.trans}</option>
				<option value="{$smarty.const.LISTING_FORM_TRANS_OPTION1}">{$smarty.const.LISTING_FORM_TRANS_OPTION1}</option>
				<option value="{$smarty.const.LISTING_FORM_TRANS_OPTION2}">{$smarty.const.LISTING_FORM_TRANS_OPTION2}</option>
			</select>
			</p>

			<p><label for="drive_train">{$smarty.const.DRIVETRAIN}</label>
			<select id="drive_train" name="drive_train" size="1">
				<option value="{$records.drive_train}" selected="selected">{$records.drive_train}</option>
			{foreach item="drive_train" from=$drivetrainlist}
				<option value="{$drive_train.drive_train}">{$drive_train.drive_train}</option>
			{/foreach}
			</select>
			</p>
			
			<p><label for="mpg">{$smarty.const.MPG}</label>
			<input id="mpg" name="mpg" type="text" size="5" maxlength="5" value="{$records.mpg}" />
			</p>
			<p><label for="price">{$smarty.const.PRICE}</label>
			<input id="price" name="price" type="text" size="8" maxlength="11" value="{$records.price}" />
			</p>
			<p><label for="adddesc">{$smarty.const.ADDDESC}</label>
			<textarea id="adddesc" name="adddesc" cols="35" rows="4">{$records.adddesc}</textarea>
			</p>
			
    		<p><label for="features">{$smarty.const.FEATURES}</label>
			<select id="features" name="features[]" size="4" multiple="multiple">
			{foreach item="features" from=$featurelist}
				<option value="{$features.id}"{foreach item="data" from=$records.features}{if $features.id eq $data} selected="selected"{/if}{/foreach}>{$features.features}</option>
			{/foreach}
			</select>
			</p>

			<p><label for="vin">{$smarty.const.VIN}</label>
			<input id="vin" name="vin" type="text" size="30" maxlength="17" value="{$records.vin}" />
			</p>
			
			<p><label for="stock">{$smarty.const.STOCK}</label>
			<input id="stock" name="stock" type="text" size="30" maxlength="17" value="{$records.stock}" />
			</p>

			<h2>Add the location of your vehicle.</h2>
			<p><label for="state">{$smarty.const.STATE}</label>
			<select id="state" name="state" size="1">
				<option value="{$records.state}" selected="selected">{$records.state}</option>
			{foreach item="state" from=$stateslist}
				<option value="{$state.state_name}">{$state.state_name}</option>
			{/foreach}
			</select>
			</p>
			
			<p><label for="zip">{$smarty.const.ZIP}</label>
			<input id="zip" name="zip" type="text" size="6" maxlength="6" value="{$records.zip}" />
			</p>

			{if $admin}
			<p><label for="sellerid">{$smarty.const.SELLER}</label>
			<select id="sellerid" name="sellerid" size="1">
			{foreach item="sellers" from=$sellerslist}
				<option value="{$sellers.id}"{if $sellers.id eq $records.sellerid} selected="selected"{/if}>{$sellers.user}</option>
			{/foreach}
			</select>
			</p>
			{else}
			<p>
			<input name="sellerid" type="hidden" value="{$records.sellerid}" />
			<input name="seller" type="hidden" value="{$seller}" />		
			</p>
			{/if}
			
			<h2>{$smarty.const.EDIT_LISTING_MARK_SOLD}</h2>
			<p><label for="sold">{$smarty.const.SOLD}</label>
			<input id="sold" name="sold" type="checkbox"{if $records.sold} checked="checked"{/if} value="1" />
			</p>
			<input name="id" type="hidden" value="{$records.id}" />
			<input name="submit" type="submit" value="{$smarty.const.EDIT_LISTING_FORM_UPDATE_BUTTON}" />
			<input name="delete" type="submit" value="{$smarty.const.EDIT_LISTING_FORM_DELETE_BUTTON}" />
			</p>
	</form>
</fieldset>

<fieldset>
	<legend>{$smarty.const.EDIT_LISTING_ADD_IMAGE_LEGEND}</legend>
		<form enctype="multipart/form-data" action="editlisting.php" method="post">
			<p><label for="image">{$smarty.const.YOUR_IMAGE}</label>
			<input id="image" name="image" type="file" size="30" value="" />
			</p>
			<p>

			<input name="id" type="hidden" value="{$records.id}" />
			<input type="hidden" name="max" value="512000" />
			<input name="addimage" type="submit" value="{$smarty.const.SUBMIT}" />
			<a href="member.php">{$smarty.const.BACK_TO_MEMBER_HOME}</a><br />
			</p>
		</form>
</fieldset>
{/foreach}

</div>

{include file="footer.tpl"}