<?php



function site_url(){

  // output: /myproject/index.php
  $currentPath = $_SERVER['PHP_SELF'];

  // output: Array ( [dirname] => /myproject [basename] => index.php [extension] => php [filename] => index )
  $pathInfo = pathinfo($currentPath);

  // output: localhost
  $hostName = $_SERVER['HTTP_HOST'];

  // output: http://
  $protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https'?'https':'http';

    return  'https://www.clubexelsior.com/res/';
  //return $protocol.'://'.$hostName.$pathInfo['dirname']."/";
}


function url_get_contents ($Url) {
    if (!function_exists('curl_init')){
        die('CURL is not installed!');
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $Url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}

function lang(){
  $lang='en';
  return $lang;
}

function api_url(){
	return('https://www.clubexelsior.com/reservation/api');
}

function api_key(){
  return $apikey='8E19B3FE0C8603C3F8A6453F3EDBFB12';
}

function get_hotels(){
  $str = url_get_contents(api_url().'/hotels?apikey='.api_key());
  $json = json_decode($str, true);
  return $json;
}

function post_reservation(){



}

function get_hotel($hotelId){
  $str = file_get_contents(api_url().'/hotel?resortId='.$hotelId.'&apikey='.api_key());
  $json = json_decode($str, true);
  return $json;
}

function get_room($roomId){
  $str = file_get_contents(api_url().'/room?roomId='.$roomId.'&apikey='.api_key());
  $json = json_decode($str, true);
  return $json;
}

function get_gallery($galleryId){
  $str = file_get_contents(api_url().'/gallery?galleryId='.$galleryId.'&apikey='.api_key());
  $json = json_decode($str, true);
  return $json;
}


 function MailGonder($ref_no,$cart_name=false,$toplam_para,$postDatas){



      if ($_POST['paxEmail']){

		echo  '<script type="text/javascript">alert("Your form has been sent..'.print_r($_POST).'");   </script>';

	$res_no = trim(strip_tags($_POST['reservation_no']));
	$ref_no = trim(strip_tags($ref_no));
	$toplam_para = trim(strip_tags($toplam_para));
	$toplam_para = ' '.$toplam_para;
	$checkInDate = trim(strip_tags($_POST['checkInDate']));
	$checkOutDate = trim(strip_tags($_POST['checkOutDate']));
	$totalRoomWrapper = trim(strip_tags($_POST['totalRoomWrapper']));
	$paxNameSurname = trim(strip_tags($_POST['paxNameSurname']));
	$paxEmail = trim(strip_tags($_POST['paxEmail']));
	$totalAdultWrapper = trim(strip_tags($_POST['totalAdultWrapper']));
	$totalChildWrapper = trim(strip_tags($_POST['totalChildWrapper']));
	$totalInfantWrapper = trim(strip_tags($_POST['totalInfantWrapper']));
	$paxPhone = trim(strip_tags($_POST['paxPhone']));
	$paxPostalCode = trim(strip_tags($_POST['paxPostalCode']));
	$paxCountry = trim(strip_tags($_POST['paxCountry']));
	$paxNotes = trim(strip_tags($_POST['paxNotes']));
	$hotelsName = trim(strip_tags($_POST['hotel1']));
	$checkedHotelName = trim(strip_tags($_POST['checkedHotelNameInput']));
	$checkedRoomName = trim(strip_tags($_POST['checkedRoomNameInput']));

	 require("smtp_new/class.phpmailer.php");
	 $mail = new PHPMailer();
	$mail->IsSMTP();
	$mail->SMTPDebug = 1; // Hata ayıklama değişkeni: 1 = hata ve mesaj gösterir, 2 = sadece mesaj gösterir
	$mail->SMTPAuth = true; //SMTP doğrulama olmalı ve bu değer değişmemeli
	$mail->SMTPSecure = ''; // Normal bağlantı için boş bırakın veya tls yazın, güvenli bağlantı kullanmak için ssl yazın
	$mail->Host = "voda23.vodahost23.com"; // Mail sunucusunun adresi (IP de olabilir)
	$mail->Port = 587; // Normal bağlantı için 587, güvenli bağlantı için 465 yazın
	$mail->IsHTML(true);
	$mail->SetLanguage("tr", "phpmailer/language");
	$mail->CharSet  ="utf-8";
	$mail->Username = "smtp@exelsiorhotels.com"; // Gönderici adresiniz (e-posta adresiniz)
	$mail->Password = "Smtp_1234*2018"; // Mail adresimizin sifresi
	
	$mail->SetFrom("reservation@exelsiorhotels.com", "Exelsior Hotels Reservation Confirmation");//$email; //formdan gelen mail adresi
	$mail->addAddress("info@exelsiorhotels.com","Exelsior Hotels Reservation Confirmation");
	$mail->addAddress($paxEmail,"Exelsior Hotels Reservation Confirmation");
	$mail->Subject = "Exelsior Hotels Reservation Confirmation"; //formdan gelen konu
	$mail->isHTML(true); //Mailimizin HTML formatında hazırlanacağını bildiriyoruz.



	$mail->Body ='<style type="text/css">
	<!--
	.style1 {
		font-family: tahoma;
		font-size: 12px;
		color: #000000;
		font-weight: bold;
	}
	.style2 {
		font-family: tahoma;
		font-size: 12px;
		color: #000000;
	}
	-->
	</style>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td ><table width="400" border="1" align="center" cellpadding="12" cellspacing="0" bordercolor="#ededed" bgcolor="#FFFFFF">
		  <tr>
			<td><table width="100%" border="0" cellspacing="1" cellpadding="1">
			  <tr>
				<td height="10"></td>
			  </tr>
			  <tr>
				<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; "><div align="center">'.$checkedHotelName.' Reservation</div></td>
			  </tr>  <tr>
				<td height="10"></td>
			  </tr>
			  <tr>
				<td><table border="0" cellspacing="1" cellpadding="1">
				<tr style="height:30px;">
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">Reservation Ref No</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">:</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; "> '.$res_no.'</td>
				  </tr>
				  <tr style="height:30px;" bgcolor="#ededed">
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">Bank Ref No</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">:</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; "> '.$ref_no.'</td>
				  </tr>
				   <tr style="height:30px;">
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">Name Surname</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">:</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; "> '.$paxNameSurname.'</td>
				  </tr>
				    <tr style="height:30px;" bgcolor="#ededed">
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">Check-in Date</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">:</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; "> '.$checkInDate.'</td>
				  </tr>
				   <tr style="height:30px;">
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">Check-out Date</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">:</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; "> '.$checkOutDate.'</td>
				  </tr>
				    <tr style="height:30px;" bgcolor="#ededed">
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">City / Country</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">:</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; "> '.$paxCountry.'</td>
				  </tr>
				  <tr style="height:30px;">
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">Phone</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">:</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; "> '.$paxPhone.'</td>
				  </tr>
				    <tr style="height:30px;" bgcolor="#ededed">
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">Email</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">:</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; "> '.$paxEmail.'</td>
				  </tr>

				  <tr style="height:30px;">
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">Room type</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">:</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; "> '.$checkedRoomName.'</td>
				  </tr>

				  <tr style="height:30px;" bgcolor="#ededed">
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">Total Room(s)</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">:</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; ">'.$totalRoomWrapper.'</td>
				  </tr>

				  <tr style="height:30px;">
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">Total Adult(s)</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">:</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; ">'.$totalAdultWrapper.'</td>
				  </tr>
				  <tr style="height:30px;" bgcolor="#ededed">
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">Total Child(s)</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">:</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; "> '.$totalChildWrapper.'</td>
				  </tr>
				  <tr style="height:30px;">
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">Total Infant(s)</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">:</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; "> '.$totalInfantWrapper.'</td>
				  </tr>
				   <tr style="height:30px;" bgcolor="#ededed">
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">Requests</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; font-weight: bold; ">:</td>
					<td style="font-family:tahoma; font-size:12px; color:000000; "> '.$paxNotes.'</td>
				  </tr>
				  <tr style="height:30px;" bgcolor="#b92424">
					<td style="font-family:tahoma; font-size:12px; color:#fff; font-weight: bold; ">Total Amount</td>
					<td style="font-family:tahoma; font-size:12px; color:#fff; font-weight: bold; ">: </td>
					<td style="font-family:tahoma; font-size:12px; color:#fff; padding-left:5px; "> '.$toplam_para.' TRY</td>
				  </tr>
				 <tr>
				<td colspan="3" height="10"></td>
			  </tr>
					</table></td>
			  </tr>
			</table></td>
		  </tr>
		</table></td>
	  </tr>
	</table>
	';

		if(!$mail->Send())
		{
		echo "<script type='text/javascript'>alert('Somethings Wrong! Please Try Another Time'); history.back(); </script>";
		} else {
		echo "<script type='text/javascript'>alert('Your reservation has been sent..'); history.back(); </script>";
		}



		}
	}

	function testEmail(){
	 require("smtp_new/class.phpmailer.php");
	 $mail = new PHPMailer();
	$mail->IsSMTP();
	$mail->SMTPDebug = 1; // Hata ayıklama değişkeni: 1 = hata ve mesaj gösterir, 2 = sadece mesaj gösterir
	$mail->SMTPAuth = true; //SMTP doğrulama olmalı ve bu değer değişmemeli
	$mail->SMTPSecure = ''; // Normal bağlantı için boş bırakın veya tls yazın, güvenli bağlantı kullanmak için ssl yazın
	$mail->Host = "voda23.vodahost23.com"; // Mail sunucusunun adresi (IP de olabilir)
	$mail->Port = 587; // Normal bağlantı için 587, güvenli bağlantı için 465 yazın
	$mail->IsHTML(true);
	$mail->SetLanguage("tr", "phpmailer/language");
	$mail->CharSet  ="utf-8";
	$mail->Username = "smtp@exelsiorhotels.com"; // Gönderici adresiniz (e-posta adresiniz)
	$mail->Password = "Smtp_1234*2018"; // Mail adresimizin sifresi
	$mail->SetFrom("info@exelsiorhotels.com", "Exelsior Hotels"); // Mail atıldığında gorulecek isim ve email
	$mail->AddAddress("cihanyasin48@gmail.com"); // Mailin gönderileceği alıcı adres
	$mail->Subject = "Mesaj Basligi"; // Email konu başlığı
	$mail->Body = "Mesaj icerigi ve metni"; // Mailin içeriği
	if(!$mail->Send()){
	  echo "Email Gönderim Hatasi: ".$mail->ErrorInfo;
	} else {
	  echo "Email Gonderildi";
	}
		 
	  

		
	}
