<?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 

	$aqcm_CO2_TRIG_LOW			= $_SESSION['aqcm_CO2_TRIG_LOW'] ;
	$aqcm_CO2_TRIG_HIGH			= $_SESSION['aqcm_CO2_TRIG_HIGH'] ;
	
	$aqcm_SPL_TRIG_MOY			= $_SESSION['aqcm_SPL_TRIG_MOY'] ;
	$aqcm_SPL_TRIG_MAX			= $_SESSION['aqcm_SPL_TRIG_MAX'] ;
	$aqcm_SPL_TRIG_MODE_BIQUO = $_SESSION['aqcm_SPL_TRIG_MODE_BIQUO'] ;
	$aqcm_SCHEDULER 				= $_SESSION['aqcm_SCHEDULER'] ;

	for ($i=1; $i < 8; $i++) {
		
		$db_schedule_str = substr($aqcm_SCHEDULER, 144*($i-1), 144);

		$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>";
	
?>


<form name="myform" id="myform" method="post" action="./index.php">

<div align="center">

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

	<table width="<?php echo($tables_width_large); ?>" border="2" cellspacing="2" cellpadding="2" bordercolor="#999999" bgcolor="#000033">	
		<font size="3" color="white" face="Arial, Helvetica, sans-serif">

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

					<?php

						//-----------------------------------------------------------------------------------------------------------------
						echo('&nbsp;site : ');
						echo('<select name="select_site_id" id="select_site_id" size="1" onchange="change()" class="txtField_A" >');
						for ($i = 0; $i < sizeof($_SESSION['list_sites']); $i++) {
							
							echo( '<option' ) ;
							if ( $_SESSION['SITE_ID'] == $_SESSION['list_sites'][$i] ) {
								echo( ' ' ) ;
								echo('selected');
							}
							echo( '>' ) ;
							echo( $_SESSION['list_sites'][$i] ) ;
							echo( '</option>' ) ;

						}
						echo('</select>');

						//-----------------------------------------------------------------------------------------------------------------
						echo('&nbsp;&nbsp;bâtiment : ');
						echo('<select name="aqcm_BAT" id="aqcm_BAT" size="1" onchange="change()" class="txtField_A">');
						include ("../M0/selection_BAT.php");
						echo('</select>');

						//-----------------------------------------------------------------------------------------------------------------
						echo('&nbsp;&nbsp;niveau : ');
						echo('<select name="aqcm_NIVEAU" id="aqcm_NIVEAU" size="1" onchange="change()" class="txtField_A">');
						include ("../M0/selection_NIVEAU.php");
						echo('</select>');

						//-----------------------------------------------------------------------------------------------------------------
						include ("./get_sondes.php");
						
						echo('&nbsp;&nbsp;sonde : ');
						echo('<select name="aqcm_SONDE_PARAMS" size="1" onchange="change()" class="txtField_A">');

						if ( ( $_SESSION['SITE_ID'] != "00001_001" ) && ( $NB_sondes >= 1 ) ) {
								
							for ($i = 0; $i < sizeof($aqcm_NAME); $i++) {
								echo('<option '); 
								if ( $_SESSION['SONDE_NAME'] == $aqcm_NAME[$i] ) echo( "selected " ) ;
								echo('value="' . $aqcm_MAC[$i] . ',' . $aqcm_NAME[$i] . '">' . $aqcm_NAME[$i] . '</option>') ;
							}
						}
						else {
							echo('<option value="' . '00_00_00_00_00_00' . ',' . 'None' . '">' . 'None' . '</option>') ;
						}
						
						echo('</select>');

						//-----------------------------------------------------------------------------------------------------------------
						echo('&nbsp;&nbsp;année : ');
						echo('<select id="aqcm_ANNEE" name="aqcm_ANNEE" size="1" onchange="change()" class="txtField_A" >');
						$debut_periode  = mktime(0, 0, 0, $_SESSION['aqcm_MOIS']  , 1, $_SESSION['aqcm_ANNEE']);
						$annee_debut_periode = date("Y", $debut_periode);
						include ("../M0/selection_annee_0.php");
						echo('</select>');

						//-----------------------------------------------------------------------------------------------------------------
						echo('&nbsp;&nbsp;mois : ');
						echo('<select id="aqcm_MOIS" name="aqcm_MOIS" size="1" onchange="change()" class="txtField_A" >');
						$mois_debut_periode = date("m", $debut_periode);
						include ("../M0/selection_mois_0.php");
						echo('</select>');
					
						//-----------------------------------------------------------------------------------------------------------------
						$lundis_string = [];
						$lundis_value = [];
						$timestamp_first_monday = strtotime('first monday of ' . $_SESSION['aqcm_ANNEE'] . '-' . $_SESSION['aqcm_MOIS'] ) ;
						$timestamp_last_monday  = strtotime('last monday of '  . $_SESSION['aqcm_ANNEE'] . '-' . $_SESSION['aqcm_MOIS'] ) ;
						$last_lundi_value = intval( date("d", $timestamp_last_monday) ) ;
						
						$i = 0 ;
						$lundis_value[$i]  = intval( date("d", $timestamp_first_monday) ) ;
						$lundis_string[$i] = strval($lundis_value[$i]) ;
						
						while ( ( $lundis_value[$i] + 7 ) <= $last_lundi_value ) {
							$lundis_value[$i+1] = $lundis_value[$i] + 7 ;
							$lundis_string[$i+1] = strval($lundis_value[$i+1]) ;
							$i++;
						}
						
						echo('&nbsp;&nbsp;jour (lundi) : ');
						echo('<select name="aqcm_JOUR" id="aqcm_JOUR" size="1" class="txtField_A" >');
						for ($i = 0; $i < sizeof($lundis_string); $i++) {
							echo( '<option ' ) ;
							if ( $_SESSION['aqcm_JOUR'] == $lundis_string[$i] ) echo( "selected " ) ;
							echo( '>' ) ;
							echo( $lundis_string[$i] ) ;
							echo( '</option>' ) ;
						}
						echo('</select>');

					?>

				</td>
				<td>

					&nbsp;&nbsp;&nbsp;&nbsp;durée : &nbsp;
					<input id="aqcm_NB_WEEKS" name="aqcm_NB_WEEKS" type="text" maxlength="2" value="1" size="1" onkeypress="return (event.charCode !=8 && event.charCode ==0 ||  (event.charCode >= 48 && event.charCode <= 57))" class="txtField_A" disabled >
					&nbsp;semaine(s)

				</td>
			</tr>

			
		</font>
	</table>
	
</div>

<font size="1" >&nbsp;</font>
		
<div align="center">
	<table width="<?php echo($tables_width_large); ?>" border="2" cellspacing="2" cellpadding="2" bordercolor="#999999" bgcolor="#000033">	
		<font size="3" color="white" face="Arial, Helvetica, sans-serif">
	
			<label>
				<input type="hidden" id="aqcm_SCHEDULER" name="aqcm_SCHEDULER"  size="50" value=""  >
			</label>

			<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" >
					<input type="submit" formaction="./refresh.php" value="rafraichir les données" class="button_A" >
				</td>
				<td align="center" >
					<button type="button" onclick="SetDefaultsValues()" class="button_A">&nbsp;réinitialiser les valeurs</button>
				</td>
				<td align="center" >
					avec mise à jour CO2(présence)
					<input id="update_co2_biquo"  name="update_co2_biquo" type="checkbox" >

				</td>
			</tr>

			<tr>
				<td align="center" colspan="3">
					<input type="submit" onclick="GetScheduleValues()" formaction="./scheduler_execute.php" value="mettre à jour les bilans hebdomadaires (ICONE) & quotidiens pour cette sonde" class="button_A" >

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

</div>

</form>

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

<script>
function change(){
	
	var get_txt = $('#LED_SCHEDULE').scheduler('val');
	var get_txt_str = $.fn.scheduler.util.serialize(get_txt,6);
	document.getElementById("aqcm_SCHEDULER").value = get_txt_str;

    document.getElementById("myform").requestSubmit();
}
</script>



<script>
function SetDefaultsValues() {
	$('#LED_SCHEDULE').scheduler('onReset');
	document.getElementById("aqcm_SPL_TRIG_MODE_BIQUO").value = "SPL_ONLY";
	document.getElementById("aqcm_SPL_TRIG_MOY").value = "35.0";
	document.getElementById("aqcm_SPL_TRIG_MAX").value = "55.0";
	document.getElementById("aqcm_CO2_TRIG_LOW").value = "800";
	document.getElementById("aqcm_CO2_TRIG_HIGH").value = "1500";
}
function GetScheduleValues() {
	var get_txt = $('#LED_SCHEDULE').scheduler('val');
	var get_txt_str = $.fn.scheduler.util.serialize(get_txt,6);
	document.getElementById("aqcm_SCHEDULER").value = get_txt_str;
	
}
</script>

</body>
</html>