<?php session_start();?>
<?php require_once('open_connection.php');?>
<link href='css/imagetable.css' rel='stylesheet' type='text/css' />
<!DOCTYPE html>
<html>
<head>
      <title>PICCSB e-Directory System</title>

</head>
<body bgcolor="#333333"> 
<table width="100%" border="0" align="center">
<tr>
<td width="15%" bgcolor="#333333">&nbsp;</td>
<td width="70%" align="center" bgcolor="#FFFFFF" > 

<table width="100%" border="0" align="center">

<!-- row for header picc 1 -->
<tr>  
     <th width="100%" colspan="4"><img src="images/header-cox.jpg" width="100%" height="30%"></th>
</tr>

<!-- row for header picc 2 -->
<tr>
     <th width="100%" colspan="4"><img src="images/eoffice-cox.jpg" width="100%" height="15%"></th>
</tr>

<!-- calling frame -->	
<tr>
    <td colspan="1" width="10%" align="center"><?php include("header.php");?></td>
	
</tr>
<tr>

<td colspan="3" width="90%" align="center" >
<tr><td>&nbsp;</td></tr>
<tr><td align="left">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<?php
								echo 'Welcome: ' . $_SESSION['username'];
							?>
							<a href="vendor_logout.php"><img src="images/logout3.gif" align="right"></a>

							</td>
</tr>
<tr><td>
<h2 align="center">UPDATE VENDOR RECORD</h2>

<?php
      $vendor_id = $_REQUEST['vendor_id'];

echo $vendor_id;

       $sql = "select tbl_dir_evendor.vendor_id, tbl_dir_evendor.vendor_name, tbl_dir_evendor.vendor_address1,tbl_dir_evendor.vendor_address2,tbl_dir_evendor.vendor_postcode,tbl_dir_evendor.vendor_city,tbl_dir_evendor.state_name,
	   tbl_dir_evendor.vendor_contact,  tbl_dir_evendor.vendor_hp1,tbl_dir_evendor.vendor_hp2,tbl_dir_evendor.vendor_fax, tbl_dir_evendor.vendor_email,tbl_dir_evendor.vendor_www,tbl_dir_evendor.category_name,tbl_dir_evendor.subCategory_name,tbl_ref_ecategory.category_id,tbl_ref_ecategory.category_name,tbl_ref_esubcategory.SubCategory_id,
tbl_ref_esubcategory.subCategory_name
       
from tbl_dir_evendor

Left join  tbl_ref_ecategory ON tbl_dir_evendor.category_name=tbl_ref_ecategory.category_name
Left Join  tbl_ref_esubcategory ON tbl_dir_evendor.subCategory_name=tbl_ref_esubcategory.subCategory_name
where  vendor_id= '$vendor_id'";
																		
				$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
				// $row = mysql_fetch_array($result, MYSQL_ASSOC);
				
				$row=mysql_fetch_array($result);
			    $vendor_id=$row['vendor_id'];
			
		?>
			<?php
     $category_name = $_POST['category_name'];
  $subCategory_name = $_POST['subCategory_name'];
           $listcat = mysql_query("SELECT category_name FROM tbl_ref_ecategory")or die(mysql_error());
		   $listsub = mysql_query("SELECT  tbl_ref_esubcategory.subCategory_name from tbl_ref_esubcategory 
								   Left join  tbl_ref_ecategory ON tbl_ref_esubcategory.category_name=tbl_ref_ecategory.category_name
								   where 
                                   tbl_ref_ecategory.category_name='$category_name' ")or die(mysql_error());?>
				
<form  method="post">
						<table border=0 align=center  class="imagetable">
						&nbsp; <h4 align="center">Vendor's Details</h4>
							<tr><td>Vendor Name</td><td> : </td><td><input type="text" size="100" name="vendor_name" value="<?php echo "$row[vendor_name]"?>"></td></tr>
							<tr><td>Address</td><td> : </td><td><input type="text" size="100" name="vendor_address1"required value="<?php echo "$row[vendor_address1]"?>">
							<br><input type="text" size="100" name="vendor_address2" value="<?php echo "$row[vendor_address2]"?>">
							<br><input type="text" size="100" name="vendor_address3" value="<?php echo "$row[vendor_address3]"?>">
							<br><input type="text" size="100" name="vendor_address4" value="<?php echo "$row[vendor_address4]"?>">
							<br><input type="text" size="10" name="vendor_postcode" placeholder="postcode" value="<?php echo "$row[vendor_postcode]"?>"><input type="text" size="84" name="vendor_city" placeholder="city" value="<?php echo "$row[vendor_city]"?>">
							<br><select name="state_name" >
                                <option ><?php echo  $row['state_name']; ?></option>
                                <?php $state_query=mysql_query("select * from tbl_ref_state")or die(mysql_error());
                                       while($row_section=mysql_fetch_array($state_query)){?>
                                <option> <?php echo $row_section['state_name']; ?>
                                <?php } ?>
                                </option>
                              </select>
							</td></tr>
							<tr><td>Contact Person</td><td> : </td><td><input type="text" size="50" name="vendor_contact" value="<?php echo "$row[vendor_contact]"?>"></td></tr>
							
							<tr><td>Salutation</td><td> : </td><td><select name="vendor_salutation" class="input-xlarge">
						<option ><?php echo $row['vendor_salutation']; ?></option>
						<option >Mr</option>
						<option >Ms</option>
                        </select></td></tr>

							<tr><td>Tel</td><td> : </td><td><input type="text" size="11" name="vendor_hp1" value="<?php echo "$row[vendor_hp1]"?>"></td></tr>
							<tr><td>Tel</td><td> : </td><td><input type="text" size="11" name="vendor_hp2" value="<?php echo "$row[vendor_hp2]"?>"></td></tr>
							<tr><td>Fax</td><td> : </td><td><input type="text" size="20" name="vendor_fax" value="<?php echo "$row[vendor_fax]"?>"></td></tr>
							<tr><td>Email</td><td> : </td><td><input type="text" size="30" name="vendor_email" value="<?php echo "$row[vendor_email]"?>"></td></tr>
							<tr><td>Website</td><td> : </td><td><input type="text" size="30" name="vendor_www" value="<?php echo "$row[vendor_www]"?>"></td></tr>
							<h4 align="center">Category and Subcategory</h4> 
							<tr><td>Category</td><td> : </td><td>
							<select name="category_name" class="input-xlarge" onChange="submit()">
							<!--option selected="selected"> <?php echo $row['category_name']; ?></option-->
                           <?php 
		                       if ($category_name != "" )
                                { ?>
                               <strong><?php echo '<option value="'.$category_name.'">'.$category_name.'</option>';?></strong>
                             <?php
                               }
		                        else{
								echo '<option selected="selected" value="'.$row['category_name'].'">'.$row['category_name'].'</option>';}
								while($row1 = mysql_fetch_array($listcat)){
  								echo '<option value="'.$row1['category_name'].'">'.$row1['category_name'].'</option>'; }?>
                            <!--option>
                                 <?php echo $row1['category_name']; ?>
                            </option-->
                            <!--?php  } ?-->
                            </select></td></tr>
							<tr><td>subCategory</td><td> : </td><td>
							<select name="subCategory_name" class="input-xlarge">
							<option selected="selected"><?php echo $row['subCategory_name']; ?></option>
                            <?php
                                $subcat=mysql_query("SELECT  tbl_ref_esubcategory.subCategory_name from tbl_ref_esubcategory 
                                                     Left join  tbl_ref_ecategory ON tbl_ref_esubcategory.category_name=tbl_ref_ecategory.category_name
                                                    where 
													tbl_ref_ecategory.category_name='$category_name'")or die(mysql_error());
                                while($row2=mysql_fetch_array($subcat)){
                            ?>
                            <option>
                                 <?php echo $row2['subCategory_name']; ?>
                            </option>
                            <?php  } ?>
                            </select></td></tr>
							
							</table>
													  
							 <table border=0 align="center">
							<tr><td colspan="3" align="center">
						<input type="submit" class="myButton" value="UPDATE"  name="save" id="save">
						<input type="button" class="myButton" value="VENDOR LIST" onClick="window.location.href='vendor_view.php'">
						</td></tr>
					
						<input type="hidden" name="id" value="<?php echo "$row[vendor_id]" ?>"></table>
			</form>
<?php
// escape variables for security

if (isset($_POST['save'])){
       $vendor_name = $_POST['vendor_name'];
    $vendor_address1 =$_POST['vendor_address1'];
	$vendor_address2 =$_POST['vendor_address2'];
	$vendor_address3 =$_POST['vendor_address3'];
	$vendor_address4 =$_POST['vendor_address4'];
	$vendor_postcode =$_POST['vendor_postcode'];
	$vendor_city =$_POST['vendor_city'];
	$state_name =$_POST['state_name'];
$vendor_contact = $_POST['vendor_contact'];
        $vendor_hp1 = $_POST['vendor_hp1'];
		$vendor_hp2 = $_POST['vendor_hp2'];
         $vendor_fax =$_POST['vendor_fax'];
       $vendor_email = $_POST['vendor_email'];
     $vendor_www = $_POST['vendor_www'];
	 $category_name = $_POST['category_name'];
	$subCategory_name = $_POST['subCategory_name'];
// insert record into database
$sql="update tbl_dir_evendor set vendor_name='$vendor_name',vendor_address1='$vendor_address1',vendor_address2='$vendor_address2',vendor_address3='$vendor_address3',vendor_address4='$vendor_address4',
vendor_postcode='$vendor_postcode',vendor_city='$vendor_city', state_name='$state_name',vendor_contact='$vendor_contact',
	  vendor_hp1='$vendor_hp1',vendor_hp2='$vendor_hp2',vendor_fax='$vendor_fax', vendor_email='$vendor_email' , 
	  vendor_www='$vendor_www', category_name='$category_name', subCategory_name='$subCategory_name' where vendor_id='$vendor_id'";

$result=mysql_query($sql);
if($result)
echo "<script language='javascript'>window.location='vendor_view.php'</script>";

else
   
   echo 'Unsuccessfull update';
   }
?>
<!-- row for footer -->	
<tr>
	<th align="center" colspan="4">
	<?php include('footer.php');?>
		
	</th>
</tr>

<!--- end for ruang kerja 80% -->
</table>

</td>

<td width="15%" bgcolor="#333333">&nbsp;</td>

</tr>

<!--- end for ruang kerja 100% -->
</table>

</body>
</html>