<?php
	include("../M0/session_start.php") ;
?>

<?php include("./communs_en_tete_HTML.html") ?>

<?php include('./communs_en_tete_simple.html'); ?> 
<?php include('./titre_jaune.php'); ?>

<?php
	$return_path = "/M5/gestion_sondes.php" ;
	include('../M0/display_user_site.php'); 
?>


<?php 

	// https://www.aqcm.fr/v2/icone_dev/test_scheduler.php
	
	$aqcm_SCHEDULER = 
"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001".
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".
"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" ;
	
	for ($i=1; $i < 8; $i++) {
		
		$db_schedule_str = substr($aqcm_SCHEDULER, 144*($i-1), 144);
		//echo($db_schedule_str) . "</br>";

		$db_schedule_string[$i] = strval($i) . " :[" ;
		for ($j=0; $j < 144; $j++) {
			if ($db_schedule_str[$j] == "1") {
				$db_schedule_string[$i] = $db_schedule_string[$i] . strval($j) . "," ;
			}
		}
		if ( substr($db_schedule_string[$i], strlen($db_schedule_string[$i]) - 1, 1) == "[" ) {
			$db_schedule_string[$i] = $db_schedule_string[$i] . "]" ;
		}
		else if ( substr($db_schedule_string[$i], strlen($db_schedule_string[$i]) - 1, 1) == "," ) {
			$db_schedule_string[$i][strlen($db_schedule_string[$i])-1] = "]" ;
		}
	}

	$SONDE_SCHEDULER = "" ;
	for ($i=1; $i < 7; $i++) {
		$SONDE_SCHEDULER = $SONDE_SCHEDULER . $db_schedule_string[$i] . "," ;
	}
	$SONDE_SCHEDULER = $SONDE_SCHEDULER . $db_schedule_string[$i] ;

	//echo($SONDE_SCHEDULER) . "</br>";
	
?>


<div align="center">

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

	<form name="form2" method="post" action="test_scheduler_execute.php">
	
	<font size="3" color="white" face="Arial, Helvetica, sans-serif">
	<table width="1500" border="2" cellspacing="2" cellpadding="2" bordercolor="#999999" bgcolor="#000033">	

		<tr align="left" valign="middle" bordercolor="#666666"> 
			<td colspan="3">

		
						<?php

							$p_aqcm_SITE_ID = $_SESSION['SITE_ID'] ;
							include('../M0/get_sondes_of_one_site.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="1" class="txtField_A" >' ) ;
									for ($i = 0; $i < sizeof($aqcm_NAME); $i++) {
										
										echo( '<option' ) ;
										echo( '>' ) ;
										echo( $aqcm_NAME[$i] ) ;
										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( '</label>' ) ;
							}


						?>

			</td>
		</tr>

		<tr align="left" valign="middle" bordercolor="#666666"> 
			<td colspan="3">

				<script src="./jquery.min.js"></script>

				<script src="./scheduler.js"></script>

				<table id="LED_SCHEDULE"></table>
				
				<script>
				
					$('#LED_SCHEDULE').scheduler({
						disabled: false,
						data: { <?php echo $SONDE_SCHEDULER; ?>
						}
					});

					$('#LED_SCHEDULE').scheduler({
					accuracy: 6
					});

					$('#get_schedule').on('click', function () {
						var get_txt = $('#LED_SCHEDULE').scheduler('val');
						var get_txt_str = $.fn.scheduler.util.serialize(get_txt, 2);
						//document.getElementById("get_text_scheduler").innerHTML = get_txt_str;
						//$('#get_text_scheduler').html(get_txt_str);
						document.getElementById("aqcm_SCHEDULER").value = get_txt_str;
					});

				</script>

			</td>
		</tr>

				<?php
					{
						include "AQCM_scheduler_setup_seuils_SPL.html" ;
					}
				?>

		<tr>
			<td align="center" colspan="3">
				<button type="button" onclick="SetDefaultsValues()" class="button_A">&nbsp;réinitialiser les valeurs</button>
				<hr>
				<input type="submit" onclick="GetScheduleValues()"  value="enregistrer ces valeurs" class="button_A" >
			</td>
		</tr>




			
	</table>
	</font>					
	</form>

</div>

<p>
<?php include('./communs_bouton_retour.html'); ?>
</p>

<script>
function SetDefaultsValues() {
	$('#LED_SCHEDULE').scheduler('onReset');
	document.getElementById("aqcm_SPL_TRIG_EN").checked = false;
	document.getElementById("aqcm_SPL_TRIG_MOY").value = "35.0";
	document.getElementById("aqcm_SPL_TRIG_MAX").value = "45.0";
	document.getElementById("aqcm_SPL_TRIG_ET_OU").checked = false;
}
function GetScheduleValues() {
	var get_txt = $('#LED_SCHEDULE').scheduler('val');
	var get_txt_str = $.fn.scheduler.util.serialize(get_txt,2);
	document.getElementById("aqcm_SCHEDULER").value = get_txt_str;
	
}
</script>

</body>
</html>