<?php 
include('header.php');
include('config.php');
if(isset($_GET['id'])) {
	$id = $_GET['id'];
	$query = "select * from `tbllenders` where `id`='".$id."';";
	$result = mysql_query($query);
	$rows = mysql_num_rows($result);
	if ($rows >0) {		
		while($row=mysql_fetch_array($result))
		{?>
		<div class="InnerContainer" >            
		<h2>Edit Lender</h2>
		<div class="Border"></div>
		<form name="edit_form" id="edit_form" method="post">
			<table align="center" cellpadding="5" cellspacing="0" border="0" width="40%" class="ListContent MediumSize" style="text-align:center;">
				<tr>    
					<th colspan="2" align="left">Edit Lender</th>                             
				</tr>
				<tr>
					<td align="right">Lender's Name:</td>
					<td align="left"><input type="text" name="name" id="name" value="<?php echo $row['lender_name']; ?>" /></td>
				</tr>
				<tr>
					<td align="right">Upfront Commission:</td>
					<td align="left"><input type="text" name="front" id="front" value="<?php echo $row['front']; ?>" /></td>
				</tr>
				<tr>
					<td align="right">Trail Year 1:</td>
					<td align="left"><input type="text" name="trail1" id="trail1" value="<?php echo $row['trail1']; ?>" /></td>
				</tr>
				<tr>
					<td align="right">Trail Year 2:</td>
					<td align="left"><input type="text" name="trail2" id="trail2" value="<?php echo $row['trail2']; ?>" /></td>
				</tr>
				<tr>
					<td align="right">Trail Year 3:</td>
					<td align="left"><input type="text" name="trail3" id="trail3" value="<?php echo $row['trail3']; ?>" /></td>
				</tr>
				<tr>
					<td align="right">Trail Year 4:</td>
					<td align="left"><input type="text" name="trail4" id="trail4" value="<?php echo $row['trail4']; ?>" /></td>
				</tr>
				<tr>
					<td align="right">Trail Year 5 onwards:</td>
					<td align="left"><input type="text" name="trail5" id="trail5" value="<?php echo $row['trail5']; ?>" /></td>
				</tr>
				<tr>
					<td colspan="2"><input class="Submit" type="submit" name="submit" value="Save" /><a href="lenders.php">&nbsp;&nbsp;<input class="Cancel" type="button" name="cancel" value="cancel" /></a></td>
				</tr>
			</table>
		</form>
	</div>
		<script  type="text/javascript">
			 var frmvalidator = new Validator("edit_form");
			 frmvalidator.addValidation("name","req","Please enter your Name");
			 frmvalidator.addValidation("front","req","Please enter Upfront Commission");
			 frmvalidator.addValidation("front","numeric","Please enter numbers only for Upfront Commission");
			 frmvalidator.addValidation("trail","req","Please enter Trail Commission");
			 frmvalidator.addValidation("trail","numeric","Please enter numbers only for Trail Commission");	  
		</script>
	<?php
		}
	}
		
	if(isset($_POST['submit'])) {
		$query="update `tbllenders` set `lender_name`='".$_POST['name']."', front='".$_POST['front']."', trail1='".$_POST['trail1']."', trail2='".$_POST["trail2"]."', trail3= '".$_POST["trail3"]. "', trail4='".$_POST["trail4"]."', trail5='".$_POST["trail5"]."' where `id` = '".$id."'";
		$result = mysql_query($query);
		if($result) {
			echo "<script language='javascript'>alert('Updated successfully')</script>";
			echo "<script>window.location='lenders.php';</script>";
		}
	}
}
?>
</body>
</html>