<?php date_default_timezone_set('ASIA/Kuala_Lumpur'); 
	
$getReservationId = $_GET['rv'];
$getGuestName = getDetailFromTable('reservation',$getReservationId)['rv_guest'];
$getReservationNo = getDetailFromTable('reservation',$getReservationId)['rv_no'];
$getContact = getDetailFromTable('reservation',$getReservationId)['rv_contact'];
$getEmail = getDetailFromTable('reservation',$getReservationId)['rv_email'];
$getCheckIn = getDetailFromTable('reservation',$getReservationId)['rv_ci_date'];
$getApartment = getDetailFromTable('reservation',$getReservationId)['rv_apartment'];
$respondioId = getDetailFromTable('reservation',$getReservationId)['rv_respondio_id'];
$airbnbId = getDetailFromTable('reservation',$getReservationId)['rv_airbnb_id'];
$platformId = getDetailFromTable('reservation',$getReservationId)['rv_platform'];
//$todayDate = date("Y-m-d"); //$_GET['date'];

?>
        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
              <div class="title_left">
                <h3>Whatsapp Template</h3>
              </div>

            </div>

            <div class="clearfix"></div>

            <div class="row">
				
				
              <div class="col-md-4 col-sm-4 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Communication</h2>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                    <a href="https://wa.me/<?php echo $getContact; ?>"><button class="btn btn-success btn-block">DIRECT WHATSAPP</button></a>
                  </div>
                  <div class="x_content">
                    <button class="btn btn-primary  btn-block" onclick="navigator.clipboard.writeText('https://web.whatsapp.com/send?phone=<?php echo $getContact; ?>&text&app_absent=0')">COPY WS LINK</button>
                  </div>
					
					<?php if($respondioId){ ?>
                  <div class="x_content">
                    <a href="https://app.respond.io/space/80806/message/<?php echo $respondioId; ?>" target="_blank"><button class="btn btn-success btn-block">RESPOND.IO</button></a>
                  </div>
					<?php }else{ ?>
					
                        <div class="x_content">
                    <a href="?pagecontent=reservation_update&id=<?php echo $getReservationId; ?>"><button class="btn btn-default btn-block">UPDATE RESPOND.IO</button></a>
                  </div>
					<?php } ?>
					
					<?php if($airbnbId){ ?>
                  <div class="x_content">
                    <a href="https://www.airbnb.com/hosting/inbox/folder/all/thread/<?php echo $airbnbId; ?>" target="_blank"><button class="btn btn-success btn-block">AIRBNB MESSENGER</button></a>
                  </div>
					<?php }else{ ?>
					
                  <div class="x_content">
                    <a href="?pagecontent=reservation_update&id=<?php echo $getReservationId; ?>"><button class="btn btn-default btn-block">UPDATE AIRBNB ID</button></a>
                  </div>
					<?php } ?>
					
                </div>
              </div>
				
              <div class="col-md-4 col-sm-4 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Welcome</h2>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                    <form method="post" id="demo-form2" data-parsley-validate class="form-horizontal form-label-left">

                      <div class="form-group">
                        <label class="control-label" for="first-name">Text <span class="required">*</span>
                        </label>
                        <div class="">
							<textarea class="form-control col-md-7 col-xs-12" rows="3" name="msgWelcome">
Salam/Hi, saya Faiz, nak confirm kemasukan hari ini di <?php echo $getApartment; ?>. Jam berapa sampai nanti?
							</textarea>
                        </div>
                      </div>
						
                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="">
                          <input class="btn btn-primary btn-block" type="submit" name="welcomeBtn" value="SEND">
                        </div>
                      </div>
                        <div class="">
                          <button class="btn btn-primary  btn-block" onclick="navigator.clipboard.writeText('Salam/Hi, saya Faiz, nak confirm kemasukan hari ini di <?php echo $getApartment; ?>. Jam berapa sampai nanti?')">COPY TEXT</button>
                        </div>

                    </form>
					  <?php
					  	if(isset($_POST['welcomeBtn'])){
							$postMessage = $_POST['msgWelcome'];
							
							header("Location: https://wa.me/$getContact?text=$postMessage");
						}
					  ?>
                  </div>
                </div>
              </div>
				
              <div class="col-md-4 col-sm-4 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Details</h2>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                    <form method="post" id="demo-form2" data-parsley-validate class="form-horizontal form-label-left">

                      <div class="form-group">
                        <label class="control-label" for="first-name">Text <span class="required">*</span>
                        </label>
                        <div class="">
							<textarea class="form-control col-md-7 col-xs-12" rows="3" name="msgWelcome">
Name : <?php echo $getGuestName; ?> 
Reservation No : <?php echo $getReservationNo; ?> 
Check In : <?php echo $getCheckIn; ?> 
Apartment : <?php echo $getApartment; ?> 
							</textarea>
                        </div>
                      </div>
						
                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="">
                          <input class="btn btn-primary btn-block" type="submit" name="btnWelcome" value="SEND">
                        </div>
                      </div>
                        <div class="">
                          <button class="btn btn-primary  btn-block" onclick="navigator.clipboard.writeText('Name : <?php echo $getGuestName; ?>\nReservation No : <?php echo $getReservationNo; ?>\nCheck In : <?php echo $getCheckIn; ?>\nApartment : <?php echo $getApartment; ?> ')">COPY TEXT</button>
                        </div>

                    </form>
					  <?php
					  	if(isset($_POST['btnWelcome'])){
							$postMessage = urlencode($_POST['msgWelcome']);
							
							header("Location: https://wa.me/$getContact?text=$postMessage");
						}
					  ?>
                  </div>
                </div>
              </div>
				
              <div class="col-md-4 col-sm-4 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Guest Name</h2>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                    <form method="post" id="demo-form2" data-parsley-validate class="form-horizontal form-label-left">

                      <div class="form-group">
                        <label class="control-label" for="first-name">Text <span class="required">*</span>
                        </label>
                        <div class="">
							<textarea class="form-control" rows="1" name="msgGreeting" id="myInput"><?php echo $getGuestName; ?></textarea>
                        </div>
                      </div>
						
                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="">
                          <button class="btn btn-primary  btn-block" onclick="copyText()">Copy text</button>
                        </div>
                      </div>

                    </form>
					  <script>
					  	function copyText() {
							  /* Get the text field */
							  var copyText = document.getElementById("myInput");

							  /* Select the text field */
							  copyText.select();
							  copyText.setSelectionRange(0, 99999); /* For mobile devices */

							   /* Copy the text inside the text field */
							  navigator.clipboard.writeText(copyText.value);

							  /* Alert the copied text */
							  alert("Copied the text: " + copyText.value);
							}
					  </script>
                  </div>
                </div>
              </div>
				
              <div class="col-md-4 col-sm-4 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Greeting</h2>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                    <form method="post" id="demo-form2" data-parsley-validate class="form-horizontal form-label-left">

                      <div class="form-group">
                        <label class="control-label" for="first-name">Text <span class="required">*</span>
                        </label>
                        <div class="">
							<textarea class="form-control" rows="1" name="msgGreeting">
Salam/Hi, saya Faiz.
							</textarea>
                        </div>
                      </div>
						
                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="">
                          <input class="btn btn-primary btn-block" type="submit" name="btnGreeting" value="Send">
                        </div>
                      </div>

                    </form>
					  <?php
					  	if(isset($_POST['btnGreeting'])){
							$postMessage = $_POST['msgGreeting'];
							
							header("Location: https://wa.me/$getContact?text=$postMessage");
						}
					  ?>
                  </div>
                </div>
              </div>
				
				
              <div class="col-md-4 col-sm-4 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Check In</h2>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                    <form method="post" id="demo-form2" data-parsley-validate class="form-horizontal form-label-left">

                      <div class="form-group">
                        <label class="control-label" for="first-name">Text <span class="required">*</span>
                        </label>
                        <div class="">
							<textarea class="form-control" rows="4" name="msgCheckOut"><?php echo urldecode(getDetailFromTable('rooms',getDetailFromTable('reservation',$getReservationId)['r_id'])['r_ci_details']); ?></textarea>
                        </div>
                      </div>
						
                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="">
                          <input class="btn btn-primary btn-block" type="submit" name="checkOutBtn" value="SEND">
                        </div>
						  
                      </div>
						
                    </form>
					  
					  <div class=""> <?php $checkInDetails = getDetailFromTable('rooms',getDetailFromTable('reservation',$getReservationId)['r_id'])['r_ci_details']; ?>
						<button class="btn btn-primary btn-block" onclick="navigator.clipboard.writeText('<?php echo urldecode($checkInDetails); ?>')">COPY TEXT</button>
					  </div>
					  
					  <?php
					  	if(isset($_POST['checkOutBtn'])){
							$postMessage = urlencode($_POST['msgCheckOut']);
							
							header("Location: https://wa.me/$getContact?text=$postMessage");
						}
					  ?>
                  </div>
                </div>
              </div>
				
              <div class="col-md-4 col-sm-4 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Check Out</h2>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                    <form method="post" id="demo-form2" data-parsley-validate class="form-horizontal form-label-left">

                      <div class="form-group">
                        <label class="control-label" for="first-name">Text <span class="required">*</span>
                        </label>
                        <div class="">
							<textarea class="form-control" rows="4" name="msgCheckOut"><?php echo urldecode(getDetailFromTable('rooms',getDetailFromTable('reservation',$getReservationId)['r_id'])['r_co_details']); ?></textarea>
                        </div>
                      </div>
						
                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="">
                          <input class="btn btn-primary btn-block" type="submit" name="checkOutBtn" value="SEND">
                        </div>
                      </div>
						
					  <div class=""> <?php $checkOutDetails = getDetailFromTable('rooms',getDetailFromTable('reservation',$getReservationId)['r_id'])['r_co_details']; ?>
						<button class="btn btn-primary  btn-block" onclick="navigator.clipboard.writeText('<?php echo urldecode($checkOutDetails); ?>')">COPY TEXT</button>
					  </div>

                    </form>
					  <?php
					  	if(isset($_POST['checkOutBtn'])){
							$postMessage = urlencode($_POST['msgCheckOut']);
							
							header("Location: https://wa.me/$getContact?text=$postMessage");
						}
					  ?>
                  </div>
                </div>
              </div>

              <div class="col-md-4 col-sm-4 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>ACTION</h2>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
					  <a href="?pagecontent=reservation_view&id=<?php echo $getReservationId; ?>"><button class="btn btn-success btn-block">VIEW RESERVATION</button></a>
                  </div>
                  <div class="x_content">
					  <a href="?pagecontent=reservation_update&id=<?php echo $getReservationId; ?>"><button class="btn btn-success btn-block">UPDATE RESERVATION</button></a>
                  </div>
                  <div class="x_content">
					  <a href="?pagecontent=reservation_status&id=<?php echo $getReservationId; ?>"><button class="btn btn-success btn-block">UPDATE STATUS</button></a>
                  </div>
                  <div class="x_content">
					  <a href="?pagecontent=apiWASend&id=<?php echo $getReservationId; ?>&text=Hi%20there%2C%20how%20are%20you%3F"><button class="btn btn-success btn-block">API Send WA</button></a>
                  </div>
                </div>
              </div>
				
				
            <div class="col-md-4 col-sm-4 col-xs-12">
                <div class="x_panel">
					<div class="x_title">
						<h2>Find by Reservation No</h2>
						<div class="clearfix"></div>
					</div>

					<div class="x_content">
						<form class="form-horizontal form-label-left" method="get" action="index.php?pagecontent=reservations">
							
							<div class="item form-group">
								<label class="control-label" for="night">Reservation No 
								</label>
								<div class="">
									<input id="night" class="form-control col-md-3 col-xs-12" name="pagecontent" type="text" value="reservations" hidden="">
									<input id="night" class="form-control col-md-3 col-xs-12" name="rvno" type="text" value="">
								</div>
							</div>

							<div class="ln_solid"></div>

							<div class="form-group">
								<div class="">
									<button id="send" type="submit" class="btn btn-primary btn-block">Search</button>
								</div>
							</div>

						</form>
						
					</div>
                </div>
            </div>

	  <div class="clearfix"></div>

	  <div class="col-12">
		<div class="x_panel">
		  <div class="x_title">
			<h2>Reservation Activity Log</h2>
			<ul class="nav navbar-right panel_toolbox">
			  <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
			  </li>
			  <li class="dropdown">
				<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
				<ul class="dropdown-menu" role="menu">
				  <li><a href="#">Settings 1</a>
				  </li>
				  <li><a href="#">Settings 2</a>
				  </li>
				</ul>
			  </li>
			  <li><a class="close-link"><i class="fa fa-close"></i></a>
			  </li>
			</ul>
			<div class="clearfix"></div>
		  </div>
		  <div class="x_content">
			<table class="table table-hover">
			  <thead>
				<tr>
				  <th>#</th>
				  <th>Log</th>
				  <th>Date/Time</th>
				  <th>Admin</th>
				  <th>Action</th>
				</tr>
			  </thead>
			  <tbody>
				<?php $result = mysqli_query($conn,"SELECT * FROM reservation_log WHERE rv_id=$getReservationId ORDER BY rl_id DESC");
				while($row = mysqli_fetch_assoc($result)){
				?>
				<tr>
				  <th scope="row"><?php echo ++$no; ?></th>
				  <td><?php echo $row['rl_title']; ?></td>
				  <td><?php echo $row['timestamp']; ?></td>
				  <td><?php echo getDetailFromTable('admin',$row['a_id'])['a_username']; ?></td>
				  <td></td>
				</tr>
				  <?php } ?>
			  </tbody>
			</table>

		  </div>
		</div>
	  </div>
				
            </div>
          </div>
        </div>