<? 
require_once "include/application.php"; 
require_once "include/function.php";


if($btnDelete){
	$sql="delete from `ivc_products` where ip_id='$id'";	
	@mysql_query($sql) or die(mysql_error());

	print("<script type='text/javascript'>alert('Record is deleted.')</script>");
	print("<script type='text/javascript'>location.href='products.php'</script>");

}
if($btnAdd){
	$sql="
		UPDATE `ivc_products` SET 
		 ip_code='$code',
		`ip_name` = \"$name\",
		`ip_price` = '$price',
		`ip_program` = '$program',
		`ip_night` = '$night',
		`ip_maint` = '$maint',
		`ip_adult` = '$adult',
		`ip_child` = '$child',
		`ip_room` = '$room' 
		WHERE `ip_id` ='$id' 
	";	


	@mysql_query($sql) or die(mysql_error());
	print("<script type='text/javascript'>alert('Record is updated.')</script>");
	print("<script type='text/javascript'>location.href='products.php'</script>");

}else{
	$sql="select * from ivc_products where ip_id='$id'";
	$result=mysql_query($sql);	
	while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC))
	{
		$code=$myrow["ip_code"];		
		$name=$myrow["ip_name"];		
		$price=$myrow["ip_price"];		
		$program=$myrow["ip_program"];		
		$night=$myrow["ip_night"];		
		$maint=$myrow["ip_maint"];		
		$room=$myrow["ip_room"];		
		$adult=$myrow["ip_adult"];		
		$child=$myrow["ip_child"];		
	}

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="sddm.css" >
<script src="include/validation.js" type="text/javascript"></script>


<title><? echo TITLE?></title></head>
<body>

<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#f1efd8">
  <tr>
    <td  colspan="2" align="center"><? require_once "include/header.php"; ?></td>
  </tr>
  <tr>
    <td colspan="2" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td width="185" valign="top" bgcolor="e6f3f9">
	
<? require_once "include/columnLeft.php"; 

if(array_search("Rooms",$menulist)==false)
		print("<script type='text/javascript'>location.href='index.php'</script>");

?>	</td>
    <td width="834" valign="top">
	<form name="form" method="post" action="<?=$PHP_SELF ?>"  ONSUBMIT="return ValidateAddProduct(this)">
	  <table width="800" height="250" border="0" align="center" cellpadding="0" cellspacing="0">
      
      <tr>
        
        <td valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="100%" height="30" class="TitleH3">Products <span class="TextH1"><strong><strong><strong><strong><strong><strong><strong><strong><strong>
              <input name="id" type="hidden" id="id" value="<? echo $id ?>" />
            </strong></strong></strong></strong></strong></strong></strong></strong></strong></span></td>
          </tr>
          <tr>
            <td height="1" bgcolor="#B8ED83"></td>
          </tr>
          <tr>
            <td ><? echo "<div class='Msg'>$action_msg</div>" ?>&nbsp;</td>
          </tr>

        </table>
          <table border="0" cellpadding="2" width="100%" cellspacing="1" class="small">
            <tr>
              <td class="TextH1">Product Code  : <span class="require">*</span></td>
              <td class="TextH1"><input name="code" type="text" class="small" id="code" value="<? echo $code ?>" size="10" maxlength="10" /></td>
            </tr>
            <tr>
              <td width="199" class="TextH1">Product name  : <span class="require">*</span></td>
              <td width="493" class="TextH1"><input name="name" type="text" class="small" id="name" value="<? echo $name ?>" maxlength="30" /></td>
            </tr>
            <tr>
              <td class="TextH1">Price  (RM) : <span class="require">*</span></td>
              <td class="TextH1"><input name="price" type="text" class="small" id="price" value="<? echo $price ?>" size="10" maxlength="10" />
                  <span class="subItem">eg 25800.00 (no comma) </span></td>
            </tr>
            <tr>
              <td class="TextH1">Program Tenure : <span class="require"> *</span></td>
              <td class="TextH1"><input name="program" type="text" class="small" id="program" value="<? echo $program ?>" size="2" maxlength="2" />
                year(s)</td>
            </tr>
            <tr>
              <td class="TextH1">Annual Entitlement : <span class="require"> *</span></td>
              <td class="TextH1"><input name="night" type="text" class="small" id="night" value="<? echo $night ?>" size="2" maxlength="2" />
                night(s)</td>
            </tr>
            <tr>
              <td class="TextH1">Maintenance Fees (RM) : <span class="require"> *</span></td>
              <td class="TextH1"><input name="maint" type="text" class="small" id="maint" value="<? echo $maint ?>" size="8" maxlength="8" />
                year(s)</td>
            </tr>
            <tr>
              <td class="TextH1">Room : <span class="require"> *</span></td>
              <td class="TextH1"><select name="room" id="room" >
                  <option value=""></option>
                  <?
			 
			 	$sql="select * from ivc_rooms order by ir_type";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["ir_id"]."' ";
					if($room==$myrow["ir_id"])echo "selected";
					echo ">".$myrow["ir_type"]." ".$myrow["ir_descr"]."</option>";
				}
			
?>
              </select></td>
            </tr>
            <tr>
              <td class="TextH1">No of Adult : <span class="require"> *</span></td>
              <td class="TextH1"><input name="adult" type="text" class="small" id="adult" value="<? echo $adult ?>" size="2" maxlength="2" /></td>
            </tr>
            <tr>
              <td class="TextH1">No of Child : <span class="require"> *</span></td>
              <td class="TextH1"><input name="child" type="text" class="small" id="child" value="<? echo $child ?>" size="2" maxlength="2" /></td>
            </tr>
            
            <tr>
              <td height="30" colspan="2" class="text12">&nbsp;</td>
            </tr>
            <tr>
              <td height="1" colspan="2" bgcolor="#999999"></td>
            </tr>
            <tr>
              <td height="30" colspan="2" class="TextH1"><span class="require">* Denotes a require_onced field</span></td>
            </tr>
            <tr>
              <td colspan="2" class="text12">
                  <input name="btnAdd" type="submit" class="btn" id="btnAdd" value="UPDATE" onclick="return confirm('Are you sure ?')"/>
&nbsp;
<? 

if($_SESSION["egoBlock"]<>"Yes"){ ?>
<input name="btnDelete" type="submit" class="btn" id="btnDelete" value="DELETE" onclick="return confirm('Are you sure want to delete?')"/>
<? } ?>
&nbsp;                
<input name="btnBack" type="button" class="btn" id="btnBack" onclick="location.href='products.php'" value="BACK" />              </td>
            </tr>
          </table></td>

      </tr>
 
    </table><br />
	</form>	</td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#333333" class="Footer" align="center"><br />
    <? require_once "footer.php"; ?></td>
  </tr>
</table>
</body>
</html>
