<?
require_once('includes/configure.php');
require_once "../admin/include/function.php";
require_once "../admin/include/parameter.php";
require_once "includes/$lang/reservrecordedit.php";
require_once "includes/formvalidator.php";

if($btnCancel){
/*	$canceldate=date("Y-m-d",mktime(0,0,0,$m,$d+3,$y));
	
	if($canceldate > $cin){
		$action_msg="Cancel date must do 3 days before check in date!";
		
	}else{
 */ 
	  $newstamp=nextid('n_stamp');
	  $sql="
		  update `ivc_reservation` set irs_status='C',irs_cancel_date=now(), irs_stamp='$newstamp', 
		  `irs_cancelby`='".$_SESSION["egoMemberID"]."', irs_cancel_remark='Cancel by member' where irs_id='$id' and irs_stamp='$stamp'";
  
	  @mysql_query($sql) or die(mysql_error());
	  if(mysql_affected_rows()==0)$ainfo=urlencode(RESERV_FAIL);
	  else{
		  $ainfo=urlencode(RESERV_CANCEL);
	  
		  // notice to admin
		$cardno=$_SESSION["egoMemberCard"];
		$message="
		Cancellateion Reservation 
		________________________________
		
		Card NO : $cardno
		Membername : ".$_SESSION["egoMemberName"]."
		Booking  No : $bookingno 
		Cancellation Make : ".date("d/m/Y");
											  
		  mail(EMAIL,"Cancellation from $cardno",$message,'From: '.$_SESSION["egoMemberEmail"]);		
  
		  print("<script type='text/javascript'>location.href='index.php?ai=$ainfo'</script>");	
	  }
	//}
}


$sql="select * from ivc_reservation left join ivc_members on irs_memberno=im_formno 
left join ivc_products on im_scheme=ip_id left join ivc_rooms on ip_room = ir_id 
where irs_id='$id' and irs_status='Y' and irs_memberno='".$_SESSION["egoMemberNo"]."'";
$result=mysql_query($sql);	
while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC))
{
	$reserv=$myrow["irs_for"];
	$gname=$myrow["irs_guestname"];
	$gic=$myrow["irs_guestic"];
	$gcontact=$myrow["irs_guestcontact"];
	$gemail=$myrow["irs_guestemail"];

	$adult=$myrow["irs_adult1"];
	$child=$myrow["irs_child1"];
	$room=$myrow["irs_room1"];

	$bookingno=$myrow["irs_bookingno"];
	if($myrow["irs_confirm_choice"]=="1"){
		$cin=window_date($myrow["irs_checkin1"]);
		$cout=window_date($myrow["irs_checkout1"]);
	}else if($myrow["irs_confirm_choice"]=="2"){
		$cin=window_date($myrow["irs_checkin2"]);
		$cout=window_date($myrow["irs_checkout2"]);
	}else if($myrow["irs_confirm_choice"]=="3"){
		$cin=window_date($myrow["irs_checkin3"]);
		$cout=window_date($myrow["irs_checkout3"]);
	}
	
	$name=$myrow["im_name"];
	$ic=$myrow["im_ic"];
	$email=$myrow["im_email"];
	$mobile=$myrow["im_mobile"];
	$scheme=$myrow["ip_name"];
	$roomtype=$myrow["ir_type"]." - ".$myrow["ir_descr"];

	$remark=str_replace("/r/n","<br>",$myrow["irs_remark"]);
	$stamp=$myrow["irs_stamp"];


	list($d,$m,$y)=split("/",$cin);

		

	list($d,$m,$y)=split("/",$cin);

	$canceldate=date("Y-m-d",mktime(0,0,0,$m,$d-3,$y));
	
	if($canceldate > date("Y-m-d"))$valid_cancel=true;
		
}
?>
<!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" <?= HTML_PARAMS ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?= CHARSET ?>" />
<title><?=TITLE?></title>
<!-- SmartMenus 6 config and script core files -->
<? if($_SESSION["egoLang"]=="ENG"){ ?>
<script type="text/javascript" src="c_config.js"></script>
<? }else if($_SESSION["egoLang"]=="CH"){ ?>
<script type="text/javascript" src="ch_config.js"></script>
<? } ?>
<script type="text/javascript" src="c_smartmenus.js"></script>

<!-- SmartMenus 6 config and script core files -->


<link rel="stylesheet" type="text/css" href="../styles.css" >
</head>

<body>
<table width="1000" height="600" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
  <tr>
    <td height="82" background="../images/iconic_01.jpg"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="91%" height="30" align="right" valign="bottom" ><? include_once "includes/topmenu.php"; ?></td>
        <td width="9%" rowspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td height="4"></td>
      </tr>
      <tr>
        <td height="14" align="right">
          <? include_once "includes/menu.php"; ?>
</td>
        <td height="29" rowspan="2"></td>
      </tr>
      <tr>
        <td height="3" align="right"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="500" valign="top" background="../images/memberlogin_bg.jpg" style="background-repeat:no-repeat">
    
      <table width="76%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="789" height="340" valign="bottom" class="title1"><?=RESERV_RECORD;?></td>
      </tr>
      
      <tr>
        <td >
		<form name="form" method="post" action="<?=$PHP_SELF ?>" >
	   <table width="820" height="250" border="0" align="center" cellpadding="0" cellspacing="0">
      
      <tr>
        
        <td valign="top"><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 class="require"><? echo "<div class='Msg'>$action_msg</div>" ?>&nbsp;<span class="text1"><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>
                    <input name="stamp" type="hidden" id="stamp" value="<? echo $stamp ?>" />
                    <strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong>
                    <input name="cin" type="hidden" id="cin" value="<? echo $cin ?>" />
                    <strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong>
                    <input name="cout" type="hidden" id="cout" value="<? echo $cout ?>" />
                    <strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong>
                    <input name="product" type="hidden" id="product" value="<? echo $scheme ?>" />
                    <strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong>
                    <input name="bookingno" type="hidden" id="bookingno" value="<? echo $bookingno ?>" />
                    </strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></span></td>
                </tr>
              </table>
                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                  <tr>
                    <td width="53%" valign="top"><table border="0" cellpadding="2" width="100%" cellspacing="1" class="small">
                      <tr>
                        <td width="412" class="title1"><strong><span class="title1">
                          <?=BOOKING_NO ?> : 
                        </span><? echo $bookingno ?></strong></td>
                      </tr>
                      <tr>
                        <td class="text1"><strong><span class="TextH1">
                          <? if($reserv=="Personal")echo FOR_PERSONAL;
else echo FOR_GUEST; ?>
                        </span></strong></td>
                      </tr>
                      <? if($reserv=="Guest"){ ?>
                      <tr>
                        <td height="25" bgcolor="#FFFFCC" class="text1"><?=GUEST_NAME; ?> : <span class="TextH1"><strong><? echo $gname ?></strong></span></td>
                      </tr>
                      <tr>
                        <td height="25" bgcolor="#FFFFCC" class="text1"><?=GUEST_IC; ?> : <span class="TextH1"><strong><? echo $gic ?></strong></span></td>
                        </tr>
                      <tr>
                        <td height="25" bgcolor="#FFFFCC" class="text1"><?=GUEST_CONTACT; ?> : <span class="TextH1"><strong><? echo $gcontact ?></strong></span></td>
                        </tr>
                      <tr>
                        <td height="25" bgcolor="#FFFFCC" class="text1"><?=GUEST_EMAIL; ?> :                            <span class="TextH1"><strong><? echo $gemail ?></strong></span></td>
                        </tr>
                        <? }else{ ?>
 <tr>
   <td height="25" bgcolor="#FFFFCC" class="text1"><?=PNAME; ?> : <span class="TextH1"><strong><? echo $name ?></strong></span></td>
 </tr>
                      <tr>
                        <td height="25" bgcolor="#FFFFCC" class="text1"><?=PIC; ?> : <span class="TextH1"><strong><? echo $ic ?></strong></span></td>
                        </tr>
                      <tr>
                        <td height="25" bgcolor="#FFFFCC" class="text1"><?=PCONTACT; ?> : <span class="TextH1"><strong><? echo $mobile ?></strong></span></td>
                        </tr>
                      <tr>
                        <td height="25" bgcolor="#FFFFCC" class="text1"><?=PEMAIL; ?> :                            <span class="TextH1"><strong><? echo $email ?></strong></span></td>
                        </tr>                        
                        <? } ?>
                      <tr>
                        <td class="TextH1"><div align="center"></div></td>
                        </tr>
                      <tr>
                        <td class="TextH1"><table width="100%" border="0" cellspacing="2" cellpadding="2">
                          <tr>
                            <td class="text1"><?=TYPE_PRODUCT;?> : <strong><? echo $scheme ?></strong></td>
                            <td class="text1"><?=TYPE_ROOM;?>
: <strong><? echo $roomtype ?></strong></td>
                            </tr>
                          <tr>
                            <td colspan="2" class="text1">&nbsp;</td>
                            </tr>
                          <tr>
                            <td width="37%" class="text1"><?=NO_ROOM; ?> : <strong><? echo $room ?> &nbsp;</strong></td>
                            <td width="63%" class="text1"><?=NO_ADULT; ?> : <strong> <? echo $adult ?> &nbsp; &nbsp;</strong>
 &nbsp; &nbsp;
 &nbsp; &nbsp;
<?=NO_CHILD; ?> : <strong><? echo $child ?></strong></td>
                          </tr>
                          <tr>
                            <td class="text1"><?=CHECK_IN; ?>
                              : <strong><? echo $cin ?>
                              &nbsp; &nbsp; &nbsp;</strong> &nbsp;</td>
                            <td class="text1"><?=CHECK_OUT; ?> 
: <strong><? echo $cout ?></strong></td>
                            </tr>
                          <tr>
                            <td colspan="2" class="text1">&nbsp;</td>
                          </tr>
                          <tr>
                            <td colspan="2" class="text1"><?=REMARK; ?>
                              :</td>
                          </tr>
                          <tr>
                            <td colspan="2" class="text1"><b><? echo str_replace("\r\n","<br>",$remark); ?><br />
                              <br />
                            </b></td>
                          </tr>
                        </table></td>
                      </tr>
                      <tr class="editTbl">
                        <td height="23" class="TextH1"><p class="text1"><strong>Disclaimer :</strong><br />
                          Your reservation is accepted / rejected. Kindly keep your  Booking No. as a reference upon your checking in the resort. Last minutes  cancellation (3 days before check-in date) or no turn ups will constitute to  usage of your entitlement. No replacement will be entertained. The Management  decision is final. </p>
<br />
                          <a href="m_reservPrint.php?id=<?=$id?>" target="_blank"><img src="images/printer.png" width="28" height="28" border="0" /></a></td>
                        </tr>
                    </table></td>
                    </tr>
                </table>
              <table border="0" cellpadding="2" width="100%" cellspacing="1" class="small">
                  <tr>
                    <td width="627" class="text12"><? if($valid_cancel){?>    <input name="btnCancel" type="submit" class="btn" id="btnCancel" value="<?=BUTTON_CANCEL; ?>" /> <? } ?>
                      <input name="btnBack" type="button" class="btn" id="btnBack" onclick="location.href='m_reservRecord.php'" value="<?=BUTTON_BACK; ?>" />                      
                      &nbsp;</td>
                  </tr>
              </table></td>
          </tr>
        </table>
<!--        <div class="scroll"> --></td>
      </tr>
    </table>
		</form>		</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><? include_once "includes/bottom.php" ?></td>
  </tr>
</table>
</body>
</html>