<?php include 'header.php'; 
      include 'open_connection.php'; ?>

<!--link href='blue/style.css' rel='stylesheet' type='text/css' /-->
<link href='css/imagetable.css' rel='stylesheet' type='text/css' />
<h2 align="center">INSERT VENDOR RECORD</h2>
<form  method="post">
<table align="center"  class="imagetable"> 
<tr><td>Vendor Name</td><td> : </td><td><input type="text" size="100" maxlength="100" name="vendor_name" value="<?php echo htmlentities($_REQUEST['vendor_name']); ?>"></td></tr>
<tr><td>Address</td><td> : </td><td><input type="text" size="100" maxlength="100" name="vendor_address1" value="<?php echo htmlentities($_REQUEST['vendor_address1']); ?>"></td></tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td><input type="text" size="100" maxlength="100" name="vendor_address2" value="<?php echo htmlentities($_REQUEST['vendor_address2']); ?>"/></td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td><input type="text" size="100" maxlength="100" name="vendor_address3" value="<?php echo htmlentities($_REQUEST['vendor_address3']); ?>"/></td>
</tr>
<tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td><input type="text" size="100" maxlength="100" name="vendor_address4" value="<?php echo htmlentities($_REQUEST['vendor_address4']); ?>"/></td>
</tr>
<tr>
  <td>City</td>
  <td>&nbsp;</td>
  <td><input type="text" size="100" maxlength="100" name="vendor_city" value="<?php echo htmlentities($_REQUEST['vendor_city']); ?>"/></td>
</tr>
<tr>
  <td>State</td>
  <td>&nbsp;</td>
  <td><input type="text" size="100" maxlength="100" name="vendor_state" value="<?php echo htmlentities($_REQUEST['vendor_state']); ?>"/></td>
</tr>
<tr>
  <td>Postcode</td>
  <td>&nbsp;</td>
  <td><input type="text" size="100" maxlength="100" name="vendor_postcode" value="<?php echo htmlentities($_REQUEST['vendor_postcode']); ?>"/></td>
</tr>
<tr>
  <td>Country</td>
  <td>&nbsp;</td>
  <td><input type="text" size="100" maxlength="100" name="vendor_country" value="<?php echo htmlentities($_REQUEST['vendor_country']); ?>"/></td>
</tr>
<tr><td>Tel 1</td><td> : </td><td><input type="text" size="11" maxlength="11" name="vendor_hp1" value="<?php echo htmlentities($_REQUEST['vendor_hp1']); ?>"></td></tr>
<tr><td>Twl 2</td><td> : </td><td><input type="text" size="11" maxlength="11" name="vendor_hp2" value="<?php echo htmlentities($_REQUEST['vendor_hp2']); ?>"></td></tr>
<tr><td>Tel 3</td><td> : </td><td><input type="text" size="11" maxlength="11" name="vendor_hp3" value="<?php echo htmlentities($_REQUEST['vendor_hp3']); ?>"></td></tr>
<tr><td>Fax</td><td> : </td><td><input type="text" size="20" maxlength="20" name="vendor_fax" value="<?php echo htmlentities($_REQUEST['vendor_fax']); ?>"></td></tr>
<tr><td>Email</td><td> : </td><td><input type="text" size="20" maxlength="20" name="vendor_email" value="<?php echo htmlentities($_REQUEST['vendor_email']); ?>"></td></tr>
<tr><td>Website</td><td> : </td><td><input type="text" size="20" maxlength="20" name="vendor_www" value="<?php echo htmlentities($_REQUEST['vendor_www']); ?>"></td></tr>
<tr><td>Contact</td><td> : </td><td><input type="text" size="50" maxlength="50" name="vendor_contact" value="<?php echo htmlentities($_REQUEST['vendor_contact']); ?>"></td></tr>
<tr><td>Salutation</td><td> : </td><td><input type="text" size="50" maxlength="50" name="vendor_salutation" value="<?php echo htmlentities($_REQUEST['vendor_salutation']); ?>"></td></tr>

							
							
<?php
     $category_name = $_POST['category_name'];
  $subCategory_name = $_POST['subCategory_name'];
             $type= $_POST['type'];
 
if (isset($_GET['page'])) 
		{ 
			$page = $_GET['page']; 
		} 
		else 
		{ 
			$page = 1; 
		}
		$start_from = ($page-1) * 10; 
$listcat = mysql_query("SELECT category_name FROM tbl_ref_ecategory");
//$cat_id = mysql_query("Select category_id form tbl_ref_ecategory where category_name='$listcat'");
$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' ");
//$listitem = mysql_query("SELECT * FROM item ORDER BY subcategoryname ASC LIMIT $start_from, 10");

//$sub_id = mysql_query("Select SubCategory_id form tbl_ref_esubcategory where SubCategory_name='$listsub'");
?>
 <tr>
        <td>Category</td><td> : </td>
        <td><label>
          <select id='category_name' name="category_name" onchange="submit()">
            <?php 
		 if ($category_name != "" )
 {
 ?>
            <strong><?php echo '<option selected="selected" value="'.$category_name.'">'.$category_name.'</option>';?></strong>
            <?php
 }
		else
		{
		echo '<option selected="selected" value=""></option>';
		}
		while($row = mysql_fetch_array($listcat))
  {
  echo '<option value="'.$row['category_name'].'">'.$row['category_name'].'</option>';
 }	
 
  ?>
          </select>
        </label></td>
  </tr>
      <tr>
        <td>Sub-Category</td><td> : </td>
        <td><label>
          <select id='subCategory_name' name="subCategory_name" >
            <?php 
if ($subCategory_name != "" )
 {
 echo '<option selected="selected" value="'.$subCategory_name.'">'.$subCategory_name.'</option>';
 }
 else
		{
		echo '<option selected="selected" value=""></option>';
		}
		while($row = mysql_fetch_array($listsub))
  {
  echo '<option value="'.$row['subCategory_name'].'">'.$row['subCategory_name'].'</option>';
 }
  ?>
          </select>
        </label>        </td>
      </tr>
</form>
	 
  
										
	<!--tr><td>Category</td><td> : </td><td>  <select name="category" class="input-xlarge">
           <option selected="selected">--Please Select-- </option>
                                   
                            <!--?php
                                $category_query=mysql_query("select * from tbl_ref_ecategory order by category_id")or die(mysql_error());
                                while($row=mysql_fetch_array($category_query)){
                            ?>
                            <option value="<!--?php echo $row['category_id'];?>">
                                 <!--?php echo $row['category_name']; ?>
                                
                            </option>
							
                            <!--?php
                                }
                            ?>
							</select></td></tr>
							<!--?php 
							 $category = $_POST['category'];
  						 $subCategory_id = $_POST['subCategory_id'];
								$listcat = mysql_query("SELECT category_id,category_name FROM tbl_ref_ecategory");
								$listsub = mysql_query("SELECT  tbl_ref_esubcategory.SubCategory_name from tbl_ref_esubcategory 
Left join  tbl_ref_ecategory ON tbl_ref_esubcategory.category_id=tbl_ref_ecategory.category_id
where 
tbl_ref_ecategory.category_name='$category'");?>
														
	<tr><td>Sub Category</td><td> : </td><td>  <select name="subCategory_id" class="input-xlarge">
           <option selected="selected">--Please Select-- </option>
                                   
                            <!--?php
							$subcategory_query=$listsub;
                               // $subcategory_query=mysql_query("select subCategory_id,subCategory_name from tbl_ref_esubcategory where SubCategory_id=category_id order by subcategory_id")or die(mysql_error());
                                while($row=mysql_fetch_array($subcategory_query)){
                            ?>
                            <option value="<!---?php echo $row['subCategory_id'];?>">
                               <!--?php echo $row['subCategory_id']; ?> &nbsp; <!--?php echo $row['subCategory_name']; ?> 
                            </option>
							
                            <!--?php
                                }
                            ?>
							</select></td></tr-->
							
<tr><td colspan="3" align="center"><input type="submit" value="INSERT" id="save" name="save" class="myButton">
  <input name="button" type="button" class="myButton1" onclick="window.location.href='vendor_view.php'" value="VENDOR LIST" /></td>
</tr>
</table>   
</form>
<?php
// escape variables for security
if (isset($_POST['save'])){
$vendor_name = mysql_real_escape_string($_POST['vendor_name']);
$vendor_address1 = mysql_real_escape_string($_POST['vendor_address1']);
$vendor_address2 = mysql_real_escape_string($_POST['vendor_address2']);
$vendor_address3 = mysql_real_escape_string($_POST['vendor_address3']);
$vendor_address4 = mysql_real_escape_string($_POST['vendor_address4']);
$vendor_city = mysql_real_escape_string($_POST['vendor_city']);
$vendor_state = mysql_real_escape_string($_POST['vendor_state']);
$vendor_postcode = mysql_real_escape_string($_POST['vendor_postcode']);
$vendor_country = mysql_real_escape_string($_POST['vendor_country']);
$vendor_hp1 = mysql_real_escape_string($_POST['vendor_hp1']);
$vendor_hp2= mysql_real_escape_string($_POST['vendor_hp2']);
$vendor_hp3 = mysql_real_escape_string($_POST['vendor_hp3']);
$vendor_fax = mysql_real_escape_string($_POST['vendor_fax']);
$vendor_email = mysql_real_escape_string($_POST['vendor_email']);
$vendor_www = mysql_real_escape_string($_POST['vendor_www']);
$vendor_contact = mysql_real_escape_string($_POST['vendor_contact']);
$vendor_salutation = mysql_real_escape_string($_POST['vendor_salutation']);
$category_name = mysql_real_escape_string($_POST['category_name']);
$subCategory_name = mysql_real_escape_string($_POST['subCategory_name']);
// insert record into database
$sql="INSERT INTO tbl_dir_evendor (vendor_name, vendor_address1, vendor_address2, vendor_address3, vendor_address4,vendor_city,vendor_state, vendor_postcode, vendor_country, vendor_hp1, vendor_hp2, vendor_hp3, vendor_fax, vendor_email,vendor_www ,vendor_contact,vendor_salutation, category_name, subCategory_name)

VALUES ('".$vendor_name."', '".$vendor_address1."','".$vendor_address2."','".$vendor_address3."','".$vendor_address4."','".$vendor_city."',
'".$vendor_state."','".$vendor_postcode."','".$vendor_country."','".$vendor_hp1."','".$vendor_hp2."','".$vendor_hp3."','".$vendor_fax."',
'".$vendor_email."','".$vendor_www."','".$vendor_contact."','".$vendor_salutation."','".$category_name."', '".$subCategory_name."')";


if (!mysql_query($sql)) {
  die('Error: ' . mysql_error($conn));
} else {
echo "<script> alert('1 record added!');window.location.href='vendor_FinanceAdmin_menu.php';</script>";
}
}

mysql_close($conn);
?>


><?php include("Footer.php"); ?>
