<?php

	include("../M0/session_start.php") ;

	if ( $_SESSION['level'] < 8 ) {
		header('Location: ' . $root_dir . '/M5/gestion_sondes.php');
		exit();
	}

	include("../M0/communs_en_tete_HTML.html") ;
	
	$back_link = "../M5/gestion_sondes.php";
	include('../M0/communs_en_tete_home_back.html');

	$return_path = "/M5/gestion_sondes.php" ;
	include('../M0/display_user_site.php');
	
	$user_level_to_js = $_SESSION['level'] ;
?>

<font size="1" face="Arial, Helvetica, sans-serif">&nbsp;</font>

<form name="form2" id="form2" method="post" action="">

<table align="center" width="<?php echo $tables_width ; ?>"  border="2" cellspacing="2" cellpadding="2" bordercolor="#ffffff" bgcolor="#000033">	

	<tr align="center">
		<td >

			<div><label style="display: block;font-size:24px; color:lightblue;margin-top:10px;margin-bottom:10px;" >
			<u>- modification de plusieurs sondes -</u>
			</label></div>
		
			<table width="100%" align="center">
			
				<tr>
					<td align="center">
					
						<?php

							$p_aqcm_SITE_ID = $_SESSION['SITE_ID'] ;
							include('./modify_some_sondes_of_one_site_get_sondes.php');
							
							if ( $get_sondes_of_one_site_erreur == 0 ) {
								
								if ( sizeof($aqcm_NAME) >= 1 ) {
									
									echo( '<select name="select_sonde_name[]" id="select_sonde_name" size="7" style="width: 90%; font-size:16px; font-family: Arial Narrow;"  class="txtField_A" multiple onclick="koko_1()" >' ) ;
									for ( $i = 0; $i < sizeof($aqcm_NAME); $i++ ) {
										
										echo( '<option value="' . $aqcm_NAME[$i] . '"' ) ;
										echo( '>' ) ;
										echo( $aqcm_NAME[$i] . '&nbsp;&nbsp;&nbsp;(&nbsp;' . $aqcm_MAC[$i] . ' ; ' .  $aqcm_T_MAX_string[$i] . ' ; ' . $aqcm_RX_WARNING_EN[$i] . ' ; ' . $aqcm_SHELLY_EN[$i] . '&nbsp;)' ) ;
										echo( '</option>' ) ;

									}
									echo( '</select>' ) ;
									
								}
								else {
								echo( '<label>' ) ;
								echo( 'erreur : liste des sondes vide !!!' ) ;
								echo( '</label>' ) ;
								}
								
							}
							else {
								echo( '<label>' ) ;
								//echo( 'erreur (' . strval( $get_sondes_of_one_site_erreur ) . ') !!!' ) ;
								echo( "</br><font color='salmon'>$get_sondes_of_one_site_message</font></br></br>" ) ;
								echo( '</label>' ) ;
							}


						?>
						
					</td>
				</tr>

				<tr>
					<td >
						<?php
							if ( $_SESSION['level'] >= 90 ) {
								include("./modify_some_sondes_of_one_site_target_a.php");
							}
						?>
					</td>
				</tr>

				<tr>
					<td >
						<?php 
							include("./modify_some_sondes_of_one_site_target_b.php"); 
						?>
					</td>
				</tr>

				<tr>
					<td >
						<?php 
						/*

							if ( $_SESSION['level'] < 9 ) {
								echo("<input type='checkbox' id='aqcm_SHELLY_EN_checkbox' name='aqcm_SHELLY_EN_checkbox' style='visibility:hidden'>");
								echo("<input type='hidden' id='aqcm_SHELLY_EN'  name='aqcm_SHELLY_EN'  value='OFF' >");
							}
							else {
								include("./modify_some_sondes_of_one_site_target_c.php"); 
							}
							*/
						?>
					</td>
				</tr>
				
				<tr>
					<td align="center" >
					
						<?php

							if ( $get_sondes_of_one_site_erreur == 0 ) {
								echo( '<input type="submit" id="submit_form" onclick="my_confirm_function()" value="appliquer" disabled class="button_A" >' ) ;
							}
						?>
							
					</td>
				</tr>
				
			</table>
			
			<font size="1" face="Arial, Helvetica, sans-serif">&nbsp;</font>
			
		</td>
	</tr>
	
</table>

</form>

<script>

function my_confirm_function() {
	var msg="attention : voulez-vous vraiment modifier les sondes sélectionnées ?";
	var txt;
	var r = confirm(msg);
	if (r == true) {
		txt = "./modify_some_sondes_of_one_site_target_execute.php";
	} else {
		txt = "./modify_some_sondes_of_one_site_target.php";
	}
	document.getElementById("form2").action = txt;

}

function koko_1() {
	
	var user_level  = <?php echo($user_level_to_js);  ?>;

	var f = document.getElementById("submit_form");

	var c = document.getElementById("aqcm_T_LIMIT_checkbox");
	var cc = document.getElementById("aqcm_SONDES_T_MAX");

	/*
	var d = document.getElementById("aqcm_SHELLY_EN_checkbox");
	var dd = document.getElementById("aqcm_SHELLY_EN");
	*/
	
	var e = document.getElementById("aqcm_RX_WARNING_checkbox");
	var ee = document.getElementById("aqcm_RX_WARNING");

	var options = document.getElementById("select_sonde_name").options, count = 0;
	for (var i=0; i < options.length; i++) {
	  if (options[i].selected) count++;
	}

	if ( ( c.checked ) && ( user_level < 9 ) ) {
		alert("vos droits sont insuffisants pour cette option !");
	}
	
	if ( user_level < 90 ) {
		c.checked = false;
	}
	
	if ( c.checked ) {
		cc.disabled = false;
	} else {
		cc.disabled = true;
	}

	/*
	if ( d.checked ) {
		dd.disabled = false;
	} else {
		dd.disabled = true;
	}
	*/

	if ( e.checked ) {
		ee.disabled = false;
	} else {
		ee.disabled = true;
	}

	//if ( ( ( c.checked ) || ( d.checked ) || ( e.checked ) ) && ( count > 0 ) ) {
	if ( ( ( c.checked ) || ( e.checked ) ) && ( count > 0 ) ) {
		f.disabled = false;
	} else {
		f.disabled = true;
	}

}


</script>


 </body>
</html>