
<form name="form2" id="form2" method="post" action="./modify_one_site_target_execute.php">

<table align="center" width="<?php echo $tables_width ; ?>"  border="2" cellspacing="2" cellpadding="2" bordercolor="#ffffff" bgcolor="#000033">				
	<tr align="center">
		<td>
		
			<table width="100%" align="center">
								
				<tr>
					<td width="168px" align="right">
						<label>
							nom du site :&nbsp;
						</label>
					</td>
					<td align="left" colspan="3" >
						<input id="aqcm_SITE_NAME" name="aqcm_SITE_NAME" type="text" value="<?php echo($_SESSION['SITE_NAME']); ?>" maxlength="64" class="txtField_A"  style="width:253px;" required >
					</td>
				</tr>
								
				<tr>
					<td align="right">
						<label>
							valide jusqu'au :
						</label>
					</td>
					<td align="left" colspan="2">
						<input
						  class="txtField_A"
						  type="date"
						  id="start"
						  name="aqcm_SITE_T_MAX"
						  id="aqcm_SITE_T_MAX"
						  style="width:253px;"
						  value="<?php echo(date("Y-m-d", $_SESSION['SITE_T_MAX'])); ?>"
						  min="2020-01-01"
						  max="2100-12-31" 
						  required />

					</td>
				</tr>

				<tr>
					<td align="right">
						<label title="définit si le site est actif : ON/OFF" style="cursor:help;font-size:14px;" >
							STATUS
						</label>
						<label style="font-size:14px;" >
							&nbsp;|&nbsp;
						</label>
						<label title="nombre maximal de sondes autorisé pour ce site" style="cursor:help;font-size:14px;" >
							Nmax
						</label>
						<label style="font-size:14px;" >
							&nbsp;:&nbsp;
						</label>
					</td>
					<td align="left" >
						<select name="aqcm_STATUT" id="aqcm_STATUT" size="1" class="txtField_A" style="width:122px;" >
							<?php
								include ("./selection_STATUS.php");
							?>
						</select>
						<select name="aqcm_NB_MAX" id="aqcm_NB_MAX" size="1"  class="txtField_A" style="width:122px;" >
							<?php
								include ("./selection_NB_MAX.php");
							?>
						</select>
					</td>
				</tr>
				
				<tr>

					<td align="right">
						<label title="alarmes par SMS : ON/OFF" style="cursor:help;font-size:14px;" >
							SMS
						</label>
						<label style="font-size:14px;" >
							&nbsp;|&nbsp;
						</label>
						<label title="Inscription By Mail : ON/OFF" style="cursor:help;font-size:14px;" >
							IBM
						</label>
						<label style="font-size:14px;" >
							&nbsp;:&nbsp;
						</label>
					</td>
					<td align="left" >
						<select name="aqcm_RX_WARNING_EN" id="aqcm_RX_WARNING_EN" size="1"  class="txtField_A" style="width:122px;" >
							<?php
								include ("./selection_RX_WARNING.php");
							?>
						</select>
						<select name="aqcm_SITE_IBM" id="aqcm_SITE_IBM" size="1"  class="txtField_A" style="width:122px;" >
							<?php
								include ("./selection_IBM.php");
							?>
						</select>
					</td>
				</tr>
				
				<tr>
					<td align="right">
						<label>
							coordonnées :&nbsp;
						</label>
					</td>
					<td align="left" >
						<input id="aqcm_SITE_LAT" name="aqcm_SITE_LAT" type="text"  title="latitude avec 6 décimales" onkeypress="return (event.charCode !=8 && event.charCode ==0 || ( (event.charCode >= 48 && event.charCode <= 57) || (event.charCode == 45) || (event.charCode == 46) ) )" pattern="([-]?)([0-9]{1,2})([.])([0-9]{6})" value="<?php echo($_SESSION['SITE_LAT']); ?>" maxlength="10" class="txtField_A"  style="width:122px;" required >
						<input id="aqcm_SITE_LON" name="aqcm_SITE_LON" type="text"  title="longitude avec 6 décimales" onkeypress="return (event.charCode !=8 && event.charCode ==0 || ( (event.charCode >= 48 && event.charCode <= 57) || (event.charCode == 45) || (event.charCode == 46) ) )" pattern="([-]?)([0-9]{1,3})([.])([0-9]{6})" value="<?php echo($_SESSION['SITE_LON']); ?>" maxlength="10" class="txtField_A"  style="width:122px;" required >
					</td>
				</tr>
				
			</table>
								
			<table width="100%" align="center">

				<tr>
					<td align="center" colspan="4">
						<div id="carte" align="center" >
							<!-- Ici s'affichera la carte -->
						</div>
					</td>
				</tr>
				
				<tr>
					<td align="center" colspan="4">
						<input type="submit" value="modifier le site sélectionné" class="button_A" >
					</td>
				</tr>

			</table>
			
		</td>
	</tr>
	
</table>

</form>

<script>

function my_confirm_function() {
	var msg="attention : voulez-vous vraiment modifier le site sépectionné ?";
	var txt;
	var r = confirm(msg);
	if (r == true) {
		txt = "./modify_one_site_target_execute.php";
	} else {
		txt = "./modify_one_site_target.php";
	}
	document.getElementById("form2").action = txt;

}

</script>

<script>

	var site_name	=  <?php echo $maps_site_name; ?>;	
	var site_code	=  <?php echo $maps_site_code; ?>;	
	var lat			=  <?php echo $maps_latitude; ?>;	
	var lon			=  <?php echo $maps_longitude; ?>;	
	let my_zoom		= 12 ;
	let my_maxZoom	= 20 ;

	var macarte = null;
	var macarte = new L.map('carte', {center: [lat, lon],zoom: my_zoom,maxZoom: my_maxZoom,zoomControl:false });
	L.tileLayer('https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', {
		attribution: 'OpenStreetMap',
		maxZoom: my_maxZoom
	}).addTo(macarte);
	var scale = L.control.scale(); 
	scale.addTo(macarte); 

	var marker_site = new L.Marker([lat, lon]).addTo(macarte);
	contenuHTML = site_name + "</br>(" + site_code + ")" ;
	marker_site.bindPopup(contenuHTML);
	
	function onMapClick(e) {

		// la variable e contient les informations sur l'événement
		let koko 			= e.latlng.toString() ;
		let jojo 			= koko.substring(koko.indexOf("(") + 1, koko.lastIndexOf(")") );
		let hoho 			= jojo.split(',');
		let lati_string 	= parseFloat(hoho[0].trim()).toFixed(6)
		let longi_string 	= parseFloat(hoho[1].trim()).toFixed(6)
		document.getElementById("aqcm_SITE_LAT").value  = lati_string;
		document.getElementById("aqcm_SITE_LON").value  = longi_string;

		marker_site.remove();
		marker_site = L.marker([lati_string, longi_string]).addTo(macarte);
		
	}
	
	macarte.on('click', onMapClick);

</script>

