<?php 

/*ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);*/

include '../lib/configuration.inc';


/*print_r($_POST);echo "\n";
echo "SESSION\n";
print_r($_SESSION);*/

$prix_forfait = "";


if(isset($_SESSION['SessionWeb_competition_id'])) {
	$requete_prix_forfait = mysqli_query($connexion_mysql, 'SELECT prix_forfait, DATE_FORMAT(competition_date_debut, "%Y-%m-%d"), DATE_FORMAT(competition_date_fin, "%Y-%m-%d"), text_heb, text_heb_pro, text_heb_acc, text_heb_2, text_heb_3, text_heb_4, text_heb_pro_2, text_heb_pro_3, text_heb_2_en, text_heb_3_en, text_heb_4_en, text_heb_pro_2_en, text_heb_pro_3_en, text_heb_en, text_heb_pro_en, text_heb_acc_en FROM competitions WHERE competition_id = "'.$_SESSION['SessionWeb_competition_id'].'"');
	$req = mysqli_fetch_array($requete_prix_forfait);
	$prix_forfait=$req[0];
	$competition_date_debut=$req[1];
	$competition_date_fin=$req[2];

	$date_debut_heb = date("Y-m-d", strtotime('-5 days', strtotime($competition_date_debut)));
	$date_fin_heb = date("Y-m-d", strtotime('+5 days', strtotime($competition_date_fin)));


	$text_heb=$req[3];
	$text_heb_pro=$req[4];
	$text_heb_acc = $req[5];

	$text_heb_2 = $req[6];
	$text_heb_3 = $req[7];
	$text_heb_4 = $req[8];
	$text_heb_pro_2 = $req[9];
	$text_heb_pro_3 = $req[10];
	$text_heb_2_en = $req[11];
	$text_heb_3_en = $req[12];
	$text_heb_4_en = $req[13];
	$text_heb_pro_2_en = $req[14];
	$text_heb_pro_3_en = $req[15];
	$text_heb_en = $req[16];
	$text_heb_pro_en = $req[17];
	$text_heb_acc_en = $req[18];

}



if ( isset($_SESSION['SessionWeb_joueur_profil']) AND isset($_POST['hebergement']) AND 

	( ( ( isset($_POST['simple']) AND $_POST['simple']!='empty' ) AND ( isset($_POST['hotel']) AND $_POST['hotel']!='empty' ) ) OR ( isset($_POST['hebornot']) && $_POST['hebornot']=='no' ) ) AND

	( ( $_SESSION['SessionWeb_joueur_profil']=='am' AND $_POST['piscine']!='empty' ) OR ( $_SESSION['SessionWeb_joueur_profil']=='pro' ) OR ( $_SESSION['SessionWeb_joueur_profil']=='acc' ) )

	)  {

	$_SESSION['heb_id'] = $_POST['hotel'];

	$_SESSION['nbre_places'] = $_POST['nbre_places'];

	$_SESSION['trip-start'] = $_POST['trip-start'];

	$_SESSION['trip-departure'] = $_POST['trip-departure'];

	$_SESSION['piscine'] = $_POST['piscine'];

	$_SESSION['chambre_double'] = $_POST['simple'];

	if($_SESSION['SessionWeb_joueur_profil'] == 'pro') {
		header('Location: ./inscription_6_pro.php');
	} else if ($_SESSION['SessionWeb_joueur_profil'] == 'am') {
		header('Location: ./inscription_6_am.php');
	} else {
		header('Location: ./inscription_6_acc.php');
	}
}


?>

<!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" lang="<?=$_SESSION['SessionWeb_langue']?>" xml:lang="<?=strtolower($_SESSION['SessionWeb_langue'])?>">
<head>
	<title><?=$txt_page_titre?></title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=8">
	<meta name="language" content="<?=strtolower($_SESSION['SessionWeb_langue'])?>">
	<meta name="robots" content="index, follow">
	<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
	<link rel="shortcut icon" href="/favicon.png">
	<link rel="stylesheet" type="text/css" href="<?=$web_commun?>commun.css">
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>

<body scroll="auto">

<div id="page" align="center">

	<div id="contenu">

		<?php include './commun/entete.inc'; ?>

		<div id="formulaire">

			<form action="<?=$REQUEST_URI?>" method="post">

				<input type="hidden" name="autorisation" value="inscription">

				<h1><?=$title_heb;?></h1>

				<?php
					$requete_hebergements = mysqli_query($connexion_mysql, 'SELECT DISTINCT hotel, ID, prix, chambre_double FROM hebergements');
					$nb_hebergements = mysqli_num_rows($requete_hebergements);

				?>


				<br clear="all">
				<div class="colonne_gauche_obligatoire" style="padding-top: 0px;"><?=$besoin_heb;?></div>
				<div class="colonne_droite" style="height: 33px;">
					
					<?php
						$check_no = "checked";
						$check_yes = "";


						//if (isset($_POST["trip-start"])) {
						if (isset($_GET["heb"])) {
							if($_GET["heb"] == "yes") {
								$check_no = "";
								$check_yes = "checked";
							} else {
								$check_no = "checked";
								$check_yes = "";
							}
						}
					?>


					<label for="yes">
						<?php
						echo '<input type="radio" id="radioyes" name="hebornot" value="yes" '.$check_yes.'/>'.$txt_pro_etape2_champ_membre_clubs_competition_oui."\n";
						?>
					</label>
					<label for="no">
						<?php					
						echo '<input type="radio" id="radiono" name="hebornot" value="no" '.$check_no.'/>'.$txt_pro_etape2_champ_membre_clubs_competition_non."\n";
						?>
					</label>
				</div>


				<br clear="all">
				<div class="separateur to_hide_0"></div>
				<?php if ($_SESSION['SessionWeb_joueur_profil'] == 'am' && isset($_GET['heb']) && $_GET['heb']=='yes') { ?>
					






					<br>
					<div id="texte" style="width:600px;" class="to_hide_0">
						
						<div id="calque_package_golfeur_infos" class="to_hide_0">
							
						
							<?php if( strtolower($_SESSION['SessionWeb_langue']) == 'fr' ) { 
									echo $text_heb;
								} else {
									echo $text_heb_en;
								}
							?>

						</div>
					</div>





				<?php } ?>


				<?php if ($_SESSION['SessionWeb_joueur_profil'] == 'pro' && isset($_GET['heb']) && $_GET['heb']=='yes') { ?>



					<br>
					<div id="texte to_hide_0" style="width:600px;">
						<div id="calque_package_golfeur_infos to_hide_0">

							<?php if( strtolower($_SESSION['SessionWeb_langue']) == 'fr' ) { 
									echo $text_heb_pro;
								} else {
									echo $text_heb_pro_en;
								}
							?>

						</div>
					</div>


				<?php } ?>



				<?php if ($_SESSION['SessionWeb_joueur_profil'] == 'acc' && isset($_GET['heb']) && $_GET['heb']=='yes') { ?>
					<br>
					<div id="texte to_hide_0" style="width:600px;">
						<div id="calque_package_golfeur_infos to_hide_0">

							<?php if( strtolower($_SESSION['SessionWeb_langue']) == 'fr' ) { 
									echo $text_heb_acc;
								} else {
									echo $text_heb_acc_en;
								}
							?>
						</div>
					</div>


				<?php } ?>



				<br clear="all">
				<div class="separateur"></div>

				<div class="colonne_gauche_obligatoire to_hide_1" style="height: 85px; padding-top: 0px;" hidden><?=$votre_hotel;?></div>
				<div class="colonne_droite to_hide_1" style="height: 33px;" hidden>

					<?php



					  // Variable qui ajoutera l'attribut selected de la liste déroulante
					  $selected = '';
					  
					  $seen = array();

					  // Parcours du tableau
					  echo '<select name="hotel">',"\n";


						if(!isset($_GET['hotel_id']))
						{
						  echo "\t",'<option value="empty" selected>'.$choisir_hotel.'</option>',"\n";
						}


					  for($heb_boucle=0; $heb_boucle<$nb_hebergements; $heb_boucle++){



						$resultat_heb = mysqli_fetch_array($requete_hebergements);
						$ID = $resultat_heb[1];
						$hotel = $resultat_heb[0];

						if(!in_array($hotel, $seen)) {
							array_push($seen, $hotel);
						  
						    if(isset($_GET['hotel_id']) && (int)$_GET['hotel_id'] == (int)$ID) {
						    	$selected = ' selected="selected"';
						    }
							//$chambre_  = '';
							//if($chambre_double == 1){$chambre_ = "chambre double";}else{$chambre_ = "chambre simple";}
							echo "\t",'<option value="', $ID ,'"', $selected ,'>', $hotel.'</option>',"\n";
							$selected='';
						}

					  }
					  echo '</select>',"\n";


					?>
				</div>


				<?php
				if (isset($_GET['hotel_id']) && $_SESSION['SessionWeb_joueur_profil'] == 'am' && isset($_GET['heb']) && $_GET['heb']=='yes') {

					if( strtolower($_SESSION['SessionWeb_langue']) == 'fr' )

					{ ?>
						<br clear="all">
						<div class="separateur"></div>
						<div id="texte to_hide_0" style="width:600px;">
							<div id="calque_package_golfeur_infos to_hide_0">
								<?php echo $text_heb_2; ?>
							</div>
						</div>
					<?php } else { ?>

						<br clear="all">
						<div class="separateur"></div>
						<div id="texte to_hide_0" style="width:600px;">
							<div id="calque_package_golfeur_infos to_hide_0">
								<?php echo $text_heb_2_en; ?>
							</div>
						</div>
				<?php }} ?>
			


				<?php
				if (isset($_GET['hotel_id']) && $_SESSION['SessionWeb_joueur_profil'] == 'pro' && isset($_GET['heb']) && $_GET['heb']=='yes') {

					if( strtolower($_SESSION['SessionWeb_langue']) == 'fr' )

					{ ?>
						<br clear="all">
						<div class="separateur"></div>
						<div id="texte to_hide_0" style="width:600px;">
							<div id="calque_package_golfeur_infos to_hide_0">
								<?php echo $text_heb_pro_2; ?>
							</div>
						</div>
					<?php } else { ?>

						<br clear="all">
						<div class="separateur"></div>
						<div id="texte to_hide_0" style="width:600px;">
							<div id="calque_package_golfeur_infos to_hide_0">
								<?php echo $text_heb_pro_2_en; ?>
							</div>
						</div>
				<?php }} ?>
			





					<?php

						if(isset($_GET['hotel_id'])) {
							?>
								<br clear="all">
								<div class="separateur to_hide2"></div>
								<div class="colonne_gauche_obligatoire to_hide2" style="height: 85px; padding-top: 0px;"><?=$type_chambre;?></div>
								<div class="colonne_droite to_hide2" style="height: 33px;">
									<?php
									  // Variable qui ajoutera l'attribut selected de la liste déroulante

									// 1) récupérer nom hotel
									if(!isset($_GET['hotel_id'])) {
										$requete_name = mysqli_query($connexion_mysql, 'SELECT hotel FROM hebergements LIMIT 1');
										$res_name = mysqli_fetch_array($requete_name);
										$name_hotel = $res_name[0];

									} else {
										$requete_name = mysqli_query($connexion_mysql, 'SELECT hotel FROM hebergements WHERE ID = "'.$_GET['hotel_id'].'"');
										$res_name = mysqli_fetch_array($requete_name);
										$name_hotel = $res_name[0];
									}

									// 2) récupérer à partir du nom, si il y a chambre double et/ou simple

									$requete_type_simple = mysqli_query($connexion_mysql, 'SELECT * FROM hebergements WHERE chambre_double = 0 AND hotel = "'.$name_hotel.'"');
									$res_type_simple = mysqli_num_rows($requete_type_simple);

									$requete_type_double = mysqli_query($connexion_mysql, 'SELECT * FROM hebergements WHERE chambre_double = 1 AND hotel = "'.$name_hotel.'"');
									$res_type_double = mysqli_num_rows($requete_type_double);

									echo '<select name="simple">',"\n";


									if(!isset($_GET['type_chambre']))
									{
									  echo "\t",'<option value="empty" selected>'.$choisissez_type_chambre.'</option>',"\n";
									}

									// Selection
									$selected_simple = '';
									$selected_double = '';

									if(isset($_GET['type_chambre'])) {
										if($_GET['type_chambre'] == 'simple') {
											$selected_simple = 'selected';
										} else {
											$selected_double = 'selected';
										}
									}


									// Le single vous sera facturé en supplément.
									$message_single_pro = "";
									if(isset($_SESSION['SessionWeb_joueur_profil'])) {
										//$message_single_pro = " (facturé en supplément)";
										$message_single_pro = $message_single_pro_;
									}

									if($res_type_simple > 0 && $_SESSION['SessionWeb_joueur_profil'] != "acc") 
									{
										echo "\t",'<option value="simple" '.$selected_simple.'>single '.$message_single_pro.'</option>',"\n";
									}
									if($res_type_double > 0)
									{
										echo "\t",'<option value="double" '.$selected_double.'>double'.$compris_dans_forfait.'</option>',"\n";
									}


									echo '</select>',"\n";



									?>
								</div>



								<?php
								if (isset($_GET['hotel_id']) && $_SESSION['SessionWeb_joueur_profil'] == 'am' && isset($_GET['heb']) && $_GET['heb']=='yes') {

									if( strtolower($_SESSION['SessionWeb_langue']) == 'fr' )

									{ ?>
										<br clear="all">
										<div class="separateur"></div>
										<div id="texte to_hide_0" style="width:600px;">
											<div id="calque_package_golfeur_infos to_hide_0">
												<?php echo $text_heb_3; ?>
											</div>
										</div>
									<?php } else { ?>

										<br clear="all">
										<div class="separateur"></div>
										<div id="texte to_hide_0" style="width:600px;">
											<div id="calque_package_golfeur_infos to_hide_0">
												<?php echo $text_heb_3_en; ?>
											</div>
										</div>

									<?php }} ?>
								







								<?php
								if ( isset($_GET['hotel_id']) && $_SESSION['SessionWeb_joueur_profil'] == 'pro' && isset($_GET['heb']) && $_GET['heb']=='yes' && isset($_GET['type_chambre']) ) {

									if( strtolower($_SESSION['SessionWeb_langue']) == 'fr' )

									{ ?>
										<br clear="all">
										<div class=""></div>
										<div id="texte to_hide_0" style="width:600px;">
											<div id="calque_package_golfeur_infos to_hide_0">
												<?php echo $text_heb_pro_3; ?>
											</div>
										</div>
									<?php } else { ?>

										<br clear="all">
										<div class="separateur"></div>
										<div id="texte to_hide_0" style="width:600px;">
											<div id="calque_package_golfeur_infos to_hide_0">
												<?php echo $text_heb_pro_3_en; ?>
											</div>
										</div>
								<?php }} ?>
							




								<br clear="all">
								<div class="separateur to_hide_3"></div>


								<div style="display:flex;" class="to_hide_3">

										
									<div class="colonne_gauche_obligatoire" style="height: 85px; padding-top: 0px;"><?=$arrivee;?></div>
									<div class="colonne_droite" style="height: 33px;">
									<?php

									$val = "";
									if (isset($_GET["trip-start"])) {
										$val = $_GET["trip-start"];
									} else {
										$val = $competition_date_debut;
									}
									echo '<input type="date" id="start" name="trip-start" value="' . $val . '" min="'.$date_debut_heb.'" max="'.$competition_date_debut.'" />'."\n";
									?>
							
									</div>


									<!-- <br clear="all">
									<div class="separateur"></div> -->

									<div class="colonne_gauche_obligatoire" style="height: 85px; padding-top: 0px;"><?=$depart;?></div>
									<div class="colonne_droite" style="height: 33px;">

									<?php

									$val = "";
									if (isset($_GET["trip-departure"])) {
										$val = $_GET["trip-departure"];
									} else {
										$val = $competition_date_fin;
									}
									echo '<input type="date" id="departure" name="trip-departure" value="' . $val . '" min="'.$competition_date_fin.'" max="'.$date_fin_heb.'" />'."\n";
									?>

									</div>

								</div>


								<?php
								if (isset($_GET['hotel_id']) && $_SESSION['SessionWeb_joueur_profil'] == 'am' && isset($_GET['heb']) && $_GET['heb']=='yes' && isset($_GET['type_chambre'])) {

									if( strtolower($_SESSION['SessionWeb_langue']) == 'fr' )

									{ ?>
										<br clear="all">
										<div class="separateur"></div>
										<div id="texte to_hide_0" style="width:600px;">
											<div id="calque_package_golfeur_infos to_hide_0">
												<?php echo $text_heb_4; ?>
											</div>
										</div>
									<?php } else { ?>

										<br clear="all">
										<div class="separateur"></div>
										<div id="texte to_hide_0" style="width:600px;">
											<div id="calque_package_golfeur_infos to_hide_0">
												<?php echo $text_heb_4_en; ?>
											</div>
										</div>


								<?php }} ?>


							<?php
						}

					?>


					<?php
					if(isset($_GET['type_chambre'])) {

						if(isset($_SESSION['SessionWeb_joueur_profil']) AND ( $_SESSION['SessionWeb_joueur_profil'] == "pro" )) {
							echo '<input name="hidden_in" value="" hidden>';
						}

					?>

					<br clear="all">
					<div class="separateur to_hide_4"></div>

					<?php 

					echo "\t",'<div class="colonne_gauche_obligatoire to_hide_4" style="height: 85px; padding-top: 0px;">'.$choisir_vue.'</div>',"\n"; ?>

					
					<div class="colonne_droite to_hide_4" style="height: 33px;">
							<?php

								if(isset($_GET['hotel_id']) && isset($_GET['type_chambre'])) {

									$requete_name = mysqli_query($connexion_mysql, 'SELECT hotel FROM hebergements WHERE ID = "'.$_GET['hotel_id'].'"');
									$res_name = mysqli_fetch_array($requete_name);
									$name_hotel = $res_name[0];

									if($_GET['type_chambre'] == "double")
										$type_chambre = 1;
									else
										$type_chambre = 0;
									$requete_vue_0 = mysqli_query($connexion_mysql, 'SELECT * FROM hebergements WHERE hotel = "'.$name_hotel.'" AND chambre_double = "'.$type_chambre.'" AND qtte > 0 AND vue_piscine = 0');
									$res_vue_0 = mysqli_num_rows($requete_vue_0);

									$requete_vue_1 = mysqli_query($connexion_mysql, 'SELECT * FROM hebergements WHERE hotel = "'.$name_hotel.'" AND chambre_double = "'.$type_chambre.'" AND qtte > 0 AND vue_piscine = 1');
									$res_vue_1 = mysqli_num_rows($requete_vue_1);

								}

							  echo '<select name="piscine">',"\n";

								$selected_oui = '';
								$selected_non = '';

								if(isset($_GET['piscine'])) {
									if($_GET['piscine'] == 1) {
										$selected_oui = 'selected';
									} else {
										$selected_non = 'selected';
									}
								}

								// isset($_SESSION['SessionWeb_joueur_profil'])

								if (isset($_SESSION['SessionWeb_joueur_profil']) AND $_SESSION['SessionWeb_joueur_profil'] == "pro") {
									$selected_non = 'selected';
									$selected_oui = '';
								}

							  echo "\t",'<option value="empty">'.$choisir_vue.'</option>',"\n";
							  if($res_vue_0 > 0) { echo "\t",'<option value=0 '.$selected_non.'>'.$vue_standard.'</option>',"\n"; }
							  if($res_vue_1 > 0) { echo "\t",'<option value=1 '.$selected_oui.'>'.$vue_piscine.'</option>',"\n"; }
							  
							  echo '</select>',"\n";
							?>
					</div>

					<?php
					}
					?>

					<?php if(isset($_GET['piscine'])) {  
						$requete_name = mysqli_query($connexion_mysql, 'SELECT hotel FROM hebergements WHERE ID = "'.$_GET['hotel_id'].'"');
						$res_name = mysqli_fetch_array($requete_name);
						$name_hotel = $res_name[0];

						if($_GET['type_chambre']=='simple') {
							$typechambre = 0;
						} else {
							$typechambre = 1;
						}
						$requete_qtte = mysqli_query($connexion_mysql, 'SELECT qtte FROM hebergements WHERE hotel = "'.$name_hotel.'" AND chambre_double = "'.$typechambre.'" AND vue_piscine = "'.$_GET['piscine'].'"');
						$res_qtte = mysqli_fetch_array($requete_qtte);
						?>
					<br clear="all">
					<div class="separateur" hidden></div>
					<div class="colonne_gauche_obligatoire" hidden style="height: 85px; padding-top: 0px;">Nombre de chambres</div>
					<div class="colonne_droite" hidden style="height: 33px;">
						<select name="nbre_places">
							<option value=1></option>
							<!-- <?php for ($i=0; $i<(int)$res_qtte[0]; $i++) {?>
							    <option value=<?=$i+1?>><?=$i+1?></option>
						    <?php } ?> -->
						</select>
					</div>
					<?php } ?>
					<br clear="all">
					<div class="separateur" hidden></div>

					<div style="float: left; width: 200px;"><input type="button" value="<?=$txt_bouton_annuler?>" onclick="window.location='./inscription_1.php';" class="bouton_annuler"></div>
					<div align="right" style="margin-right: 130px;"><input type="submit" value="<?=$txt_bouton_etape_suivante?>"></div>

					<input type="text" name="hebergement" hidden>


			</form>

		</div>

	</div>

</div>

</body>
</html>


<script type="text/javascript">

	$( document ).ready(function() {

		console.log($("#radiono").is(':checked'));

		if ( $("#radiono").is(':checked') ) {
			console.log("no");

			$("[class*='to_hide']").hide();
			//$("div.to_hide*").hide();
			//return;
		} else {
			console.log("yes");
			$("[class*='to_hide']").show();

			//if(window.location.href.indexOf("heb") > 0) {
				//$("[class*='to_hide']").show();
			//}
		}


		$( 'input[name=hebornot]' ).change(function(){
			window.location='http://app.proamagadir.com/inscription_hebergement.php?heb=' + this.value;
		});


		$( "[name='hotel']" ).change(function() {
		  //location.reload();
		  window.location='http://app.proamagadir.com/inscription_hebergement.php?heb=yes&hotel_id=' + this.value;
		});

		$( "[name='simple']" ).change(function() {
		  //location.reload();
		  if(window.location.href.indexOf("type_chambre") > 0) {
		  	if(this.value == "double") {
		  		window.location = window.location.href.replace("simple", "double");
		  	} else {
		  		window.location = window.location.href.replace("double", "simple");
		  	}
		  } else if ( window.location.href.indexOf("hotel_id") > 0) {
		  	window.location = window.location.href + "&type_chambre="+this.value;
		  } else {
		  	window.location = window.location.href + "?type_chambre="+this.value;
		  }
		  
		});


		$( "[name='trip-departure']" ).change(function() {
		  //location.reload();
		  if(window.location.href.indexOf("trip-departure") > 0) {
		  		//alert(window.location.href.match(/^\d{4}\-\d{2}\-\d{2}$/g));
		  		window.location = window.location.href.replace("trip-departure="+/^\d{4}\-\d{2}\-\d{2}$/g, "trip-departure="+this.value);
		  	
		  } else {
		  	window.location = window.location.href + "&trip-departure="+this.value;
		  }
		});


		$( "[name='trip-start']" ).change(function() {
		  //location.reload();
		  if(window.location.href.indexOf("trip-start") > 0) {
		  		//alert(window.location.href.match(/^\d{4}\-\d{2}\-\d{2}$/g));
		  		window.location = window.location.href.replace("trip-start="+/^\d{4}\-\d{2}\-\d{2}$/g, "trip-start="+this.value);
		  	
		  } else {
		  	window.location = window.location.href + "&trip-start="+this.value;
		  }
		});


		$( "[name='piscine']" ).change(function() {
		  //location.reload();
		  if(window.location.href.indexOf("piscine") > 0) {

		  	if(this.value == "1") {
		  		window.location = window.location.href.replace("0", "1");
		  	} else {
		  		window.location = window.location.href.replace("1", "0");
		  	}
		  } else {
		  	window.location = window.location.href + "&piscine="+this.value;
		  }
		 
		});

		if ( $("[name='hidden_in']").length ) {
			$(".to_hide_4").hide();
		}

	});
</script>