<?php
					   
	//-------------------------------------------------------------------------
	$chart_type_column	= "area" ;
	//$chart_type_column	= "column" ;
	
	//$chart_type_biquo	= "line" ;
	$chart_type_biquo	= "areaspline" ;

	//-------------------------------------------------------------------------
	if ( $scheduled_status ) {
		$chart_type 		= "column" ;
		$chart_type_min 	= "column" ;
		$chart_type_moy	= "column" ;
		$chart_type_max 	= "column" ;
		$min_max_visible	= "false"   ;
		$delta_temps 		= 6 * 3600 ;
	}
	else {
		$chart_type 				= "line" ;
		$chart_type_min 			= "spline" ;
		$chart_type_moy			= "spline" ;
		$chart_type_moy_thin	= "areaspline" ;
		$chart_type_max 			= "spline" ;
		$min_max_visible			= "false"   ;
		$delta_temps 				= 0 ;
	}
	//-------------------------------------------------------------------------
	$Flag_debug = 1;
	$Flag_debug = 0;
	
	//-------------------------------------------------------------------------
	$Titre_page = "AQCM05";

	$HC_couleur_courbes_min  		= "#0000FF";
	$HC_couleur_courbes_moy_thin	= "#000000";
	$HC_couleur_courbes_moy  		= "#811453";
	$HC_couleur_courbes_max  		= "#FF0000";

	$HC_lineWidth_min			= "2";
	$HC_lineWidth_moy_thin		= "1";
	$HC_lineWidth_moy			= "2";
	$HC_lineWidth_max			= "2";

	$legend_status           = "false" ;
	$legend_margin_right     = "68" ;
	$legend_margin_right     = "10" ;

	$X_offset_for_titles	= 160;		
	
	//-------------------------------------------------------------------------
	if ( True ) {
		
		$Nb_mesures_graphes  = array();
		
		$T_min_value        = array();
		$T_value	        	= array();
		$T_max_value        = array();
		
		$HR_min_value       = array();
		$HR_value           = array();
		$HR_max_value       = array();

		$CO2_min_value      = array();
		$CO2_value 	        = array();
		$CO2_max_value      = array();
		
		$CO2_IAQ_min_value  = array();
		$CO2_IAQ_value 	    = array();
		$CO2_IAQ_max_value  = array();
		
		$P_min_value        = array();
		$P_value            = array();
		$P_max_value        = array();
		
		$COV_IAQ_min_value  = array();
		$COV_IAQ_value      = array();
		$COV_IAQ_max_value  = array();
		
		$COV_IAQq_min_value = array();
		$COV_IAQq_value     = array();
		$COV_IAQq_max_value = array();

		$PM25_min_value     = array();
		$PM25_value         = array();
		$PM25_max_value     = array();
		
		$PM10_min_value     = array();
		$PM10_value         = array();
		$PM10_max_value     = array();
		
		$HCHO_min_value     = array();
		$HCHO_value         = array();
		$HCHO_max_value     = array();

		$LUX_min_value     = array();
		$LUX_value         = array();
		$LUX_max_value     = array();

		$SPL_min_value     = array();
		$SPL_value         = array();
		$SPL_max_value     = array();

		$NOX_IAQ_min_value  = array();
		$NOX_IAQ_value      = array();
		$NOX_IAQ_max_value  = array();

	}
	
	if ( True ) {
		
		$Nb_mesures_presence			= array();

		$T_min_value_presence        = array();
		$T_value_presence	        	= array();
		$T_max_value_presence        = array();
		
		$HR_min_value_presence       = array();
		$HR_value_presence           = array();
		$HR_max_value_presence       = array();

		$CO2_min_value_presence      = array();
		$CO2_value_presence 	        = array();
		$CO2_max_value_presence      = array();
		
		$CO2_IAQ_min_value_presence  = array();
		$CO2_IAQ_value_presence 	    = array();
		$CO2_IAQ_max_value_presence  = array();
		
		$P_min_value_presence        = array();
		$P_value_presence            = array();
		$P_max_value_presence        = array();
		
		$COV_IAQ_min_value_presence  = array();
		$COV_IAQ_value_presence      = array();
		$COV_IAQ_max_value_presence  = array();
		
		$COV_IAQq_min_value_presence = array();
		$COV_IAQq_value_presence     = array();
		$COV_IAQq_max_value_presence = array();

		$PM25_min_value_presence     = array();
		$PM25_value_presence         = array();
		$PM25_max_value_presence     = array();
		
		$PM10_min_value_presence     = array();
		$PM10_value_presence         = array();
		$PM10_max_value_presence     = array();
		
		$HCHO_min_value_presence     = array();
		$HCHO_value_presence         = array();
		$HCHO_max_value_presence     = array();

		$LUX_min_value_presence     = array();
		$LUX_value_presence         = array();
		$LUX_max_value_presence     = array();

		$SPL_min_value_presence     = array();
		$SPL_value_presence         = array();
		$SPL_max_value_presence     = array();

		$NOX_IAQ_min_value_presence  = array();
		$NOX_IAQ_value_presence      = array();
		$NOX_IAQ_max_value_presence  = array();
		
	}
	
	//-------------------------------------------------------------------------
	$NB_sondes       = 1 ;
	$aqcm_MAC[0]     = $p_aqcm_MAC ;
	$aqcm_NAME_1[0]  = $aqcm_NAME ;
	$aqcm_SITE_ID[0] = "none" ;
	
	$T_moy[0]        = 0.00 ;
	$HR_moy[0]       = 0.00 ;
	$CO2_moy[0]      = 0000 ;
	$CO2_IAQ_moy[0]  = 0000 ;
	$P_moy[0]        = 0.00 ;
	$COV_moy[0]      = 0000 ;
	$COV_IAQ_moy[0]  = 0000 ;
	$PM25_moy[0]     = 0.00 ;
	$PM10_moy[0]     = 0.00 ;
	$HCHO_moy[0]     = 0.00 ;
	$LUX_moy[0]      = 0.00 ;
	$SPL_moy[0]      = 0.00 ;
	$NOX_moy[0]      = 0.00 ;

	//-------------------------------------------------------------------------
	$column_pointWidth = "2" ;
	
	switch ($p_echelle_temps) {
		case '1 jour' :
			$delta_timestamp = 1;
			$column_pointWidth = "10" ;
			$periode = "10_MN";
			break;
		case '2 jours' :
			$delta_timestamp = 2;
			$column_pointWidth = "5" ;
			$periode = "10_MN";
			break;
		case '1 semaine' :
			$delta_timestamp = 7;
			$periode = "10_MN";
			break;
		case '2 semaines' :
			$delta_timestamp = 14;
			$periode = "10_MN";
			break;
		case '1 mois' :
			$Flag_affiche_min_max = "enabled: true,";
			$delta_timestamp = 31;
			$periode = "HEURE";
			break;
		case '2 mois' :
			$Flag_affiche_min_max = "enabled: true,";
			$delta_timestamp = 1*31 + 1*30;
			$periode = "HEURE";
			break;
		case '3 mois' :
			$Flag_affiche_min_max = "enabled: true,";
			$delta_timestamp = 2*31 + 1*30 ;
			$periode = "HEURE";
			break;
		case '6 mois' :
			$Flag_affiche_min_max = "enabled: true,";
			$delta_timestamp = 3*30 + 3*31;
			$periode = "JOUR";
			break;
		case '1 an' :
			$Flag_affiche_min_max = "enabled: true,";
			$delta_timestamp = 365;
			$periode = "JOUR";
			break; 
		default : {
			$delta_timestamp = 7;
			$periode = "10_MN";
		}
	}

	if ( $scheduled_status ) {
		$periode = "SCHED";
	}

	$periode_requete = $periode ;
	
	if ( $periode == "10_MN" ) {
		
		if ( isset( $_SESSION['PRESENCE'] ) ) {
			if ( $_SESSION['PRESENCE'] == "serveur" ) {
				$periode_requete = "BIQUO" ;
			} else {
				$periode_requete = "10_MN" ;
			}
		}
	}

	//-------------------------------------------------------------------------
	date_default_timezone_set('Europe/Paris');
	$start  = mktime(0, 0, 0, date($p_mois)  , date($p_jour),                   date($p_annee));
	$stop   = mktime(0, 0, 0, date($p_mois)  , date($p_jour)+ $delta_timestamp, date($p_annee));
	
	if ($Flag_debug == 1) {
		echo "START = " . $start . "</br>";
		echo "STOP  = " . $stop  . "</br>";

		echo $p_jour . "</br>";
		echo $p_mois . "</br>";
		echo $p_annee . "</br>";
		echo $p_echelle_temps . "</br>";
	}

	$jour_start_string = "début de la période : " . $p_jour . "/" . $p_mois . "/" . $p_annee . " ;  durée = " . $p_echelle_temps ;
	
	//--------------------------------------------------------------------
	// préparation des tableaux de mesures
	//--------------------------------------------------------------------
	$error = 0;
	
	$mesures_names = ["T","HR","CO2","CO2_IAQ","P_mer","COV_IAQ","COV_IAQq","PM25","PM10","HCHO","LUX","SPL","NOX_IAQ","CO2_BIQUO"];

	$chaine_requete = "";
	for ($j = 0; $j < sizeof($mesures_names); $j++) {
		$chaine_requete = $chaine_requete . $mesures_names[$j];
		if ( $j<(sizeof($mesures_names)-1) ) {
			$chaine_requete = $chaine_requete . ",";
		}
	}
	
	for ( $index_sonde=0; $index_sonde < $NB_sondes; $index_sonde++ ) {
		
		$Flag_SONDE_OK[$index_sonde] = False;
		$Nb_mesures_presence[$index_sonde] = 0 ;
				
		$mysql_table_mesures[$index_sonde] = $aqcm_MAC[$index_sonde] . "_mesures" ;
		$nom_sonde[$index_sonde] 		   = $aqcm_NAME_1[$index_sonde] ;

		if ($Flag_debug == 1) {
			echo "i=" . $index_sonde . " ; " . $mysql_table_mesures[$index_sonde] . " ; " . $nom_sonde[$index_sonde] . "</br>";
		}
	
		//-------------------------------------------------------------------------
		// accès à la base de données
		//-------------------------------------------------------------------------
		$link_mesures = mysqli_connect($mysql_host,$mysql_user,$mysql_password, $mysql_base);
		
		if ( ! $link_mesures ) {
			
			$error = 1;
			$message_error = "MySQL : connexion impossible !" ;
			if ($Flag_debug == 1) {
				echo $message_error . PHP_EOL; echo '</br>';
				echo "</br>Debugging errno: " . mysqli_connect_errno() . PHP_EOL; echo '</br>';
				echo "</br>Debugging error: " . mysqli_connect_error() . PHP_EOL; echo '</br>';
			}

		} 
		else {

			$query = "
				SELECT temps," . $chaine_requete . " 
				FROM " . $mysql_table_mesures[$index_sonde] . " 
				WHERE ( (periode = '" . $periode_requete . "') AND (temps >= ".$start.") AND  (temps < ".$stop.") ) 
				ORDER BY temps
			";

			if ( $Flag_debug == 1 ) {
				
				echo($query . "</br>");
				
			}
		
			$result = mysqli_query($link_mesures, $query) ;
			
			if ( ! $result ) {
				
				$error = 2;
				$message_error = "accès aux données :</br> échec de la requête ! </br>" ;

				if ($Flag_debug == 1) {
					echo $message_error ;
				}
				mysqli_close($link_mesures);
				
			} else {
				
				if ( mysqli_num_rows($result) < 1 ) {
					
					$error = 3;
					$message_error = "accès aux données :</br> le nombre de mesures est insuffisant ! </br>" ;
					if ($Flag_debug == 1) {
						echo $message_error ;
					}
					mysqli_close($link_mesures);
					
				} 
				else {
					
					$i=0;		// mesures du graphe
					$ii=0;		// mesures du graphe avec présence
					
					while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {

						$temps  = $row["temps"];
						$temps  = $temps + $delta_temps ;
						$temps *= 1000;
						
						$mesures_chaines_OK = True ;
						
						for ($j = 0; $j < sizeof($mesures_names); $j++) {
							
							$mesures_chaines = $row[$mesures_names[$j]] ;
							$nb_separateurs  = substr_count($mesures_chaines, '|') ;
							if ( $nb_separateurs == 2 ) {
								$mesures_chaines_splitted[$j] = explode( "|", $mesures_chaines, 3 );
								$mesures_chaines_splitted[$index_sonde][$j] = explode( "|", $mesures_chaines, 3 );
							}
							else {
								$mesures_chaines_OK = False ;
							}
							
						}
						
						if ( $mesures_chaines_OK ) {
							
							$Value_AQCM05_T_min        = strval($mesures_chaines_splitted[$index_sonde][0][0]);
							$Value_AQCM05_T            = strval($mesures_chaines_splitted[$index_sonde][0][1]);
							$Value_AQCM05_T_max        = strval($mesures_chaines_splitted[$index_sonde][0][2]);
							
							$Value_AQCM05_HR_min       = strval($mesures_chaines_splitted[$index_sonde][1][0]);
							$Value_AQCM05_HR           = strval($mesures_chaines_splitted[$index_sonde][1][1]);
							$Value_AQCM05_HR_max       = strval($mesures_chaines_splitted[$index_sonde][1][2]);
							
							$Value_AQCM05_CO2_min      = strval($mesures_chaines_splitted[$index_sonde][2][0]);
							$Value_AQCM05_CO2          = strval($mesures_chaines_splitted[$index_sonde][2][1]);
							$Value_AQCM05_CO2_max      = strval($mesures_chaines_splitted[$index_sonde][2][2]);
							$Value_AQCM05_PRES		    = strval($mesures_chaines_splitted[$index_sonde][13][0]);
							$Value_AQCM05_CO2_PRES		= strval($mesures_chaines_splitted[$index_sonde][13][1]);
							
							$Value_AQCM05_CO2_IAQ_min  = strval($mesures_chaines_splitted[$index_sonde][3][0]);
							$Value_AQCM05_CO2_IAQ      = strval($mesures_chaines_splitted[$index_sonde][3][1]);
							$Value_AQCM05_CO2_IAQ_max  = strval($mesures_chaines_splitted[$index_sonde][3][2]);
							
							$Value_AQCM05_P_mer_min    = strval($mesures_chaines_splitted[$index_sonde][4][0]);
							$Value_AQCM05_P_mer        = strval($mesures_chaines_splitted[$index_sonde][4][1]);
							$Value_AQCM05_P_mer_max    = strval($mesures_chaines_splitted[$index_sonde][4][2]);
							
							$Value_AQCM05_COV_IAQ_min  = strval($mesures_chaines_splitted[$index_sonde][5][0]);
							$Value_AQCM05_COV_IAQ      = strval($mesures_chaines_splitted[$index_sonde][5][1]);
							$Value_AQCM05_COV_IAQ_max  = strval($mesures_chaines_splitted[$index_sonde][5][2]);
							
							$Value_AQCM05_COV_IAQq_min = strval($mesures_chaines_splitted[$index_sonde][6][0]);
							$Value_AQCM05_COV_IAQq     = strval($mesures_chaines_splitted[$index_sonde][6][1]);
							$Value_AQCM05_COV_IAQq_max = strval($mesures_chaines_splitted[$index_sonde][6][2]);
							
							$Value_AQCM05_PM25_min     = strval($mesures_chaines_splitted[$index_sonde][7][0]);
							$Value_AQCM05_PM25         = strval($mesures_chaines_splitted[$index_sonde][7][1]);
							$Value_AQCM05_PM25_max     = strval($mesures_chaines_splitted[$index_sonde][7][2]);
							
							$Value_AQCM05_PM10_min     = strval($mesures_chaines_splitted[$index_sonde][8][0]);
							$Value_AQCM05_PM10         = strval($mesures_chaines_splitted[$index_sonde][8][1]);
							$Value_AQCM05_PM10_max     = strval($mesures_chaines_splitted[$index_sonde][8][2]);
							
							$Value_AQCM05_HCHO_min     = strval($mesures_chaines_splitted[$index_sonde][9][0]);
							$Value_AQCM05_HCHO         = strval($mesures_chaines_splitted[$index_sonde][9][1]);
							$Value_AQCM05_HCHO_max     = strval($mesures_chaines_splitted[$index_sonde][9][2]);
						
							$Value_AQCM05_LUX_min      = strval($mesures_chaines_splitted[$index_sonde][10][0]);
							$Value_AQCM05_LUX          = strval($mesures_chaines_splitted[$index_sonde][10][1]);
							$Value_AQCM05_LUX_max      = strval($mesures_chaines_splitted[$index_sonde][10][2]);
						
							$Value_AQCM05_SPL_min      = strval($mesures_chaines_splitted[$index_sonde][11][0]);
							$Value_AQCM05_SPL          = strval($mesures_chaines_splitted[$index_sonde][11][1]);
							$Value_AQCM05_SPL_max      = strval($mesures_chaines_splitted[$index_sonde][11][2]);
						
							$Value_AQCM05_NOX_IAQ_min  = strval($mesures_chaines_splitted[$index_sonde][12][0]);
							$Value_AQCM05_NOX_IAQ      = strval($mesures_chaines_splitted[$index_sonde][12][1]);
							$Value_AQCM05_NOX_IAQ_max  = strval($mesures_chaines_splitted[$index_sonde][12][2]);
							
							$data_AQCM05[$index_sonde][0][0][$i]  = "[$temps, $Value_AQCM05_T_min]";
							$data_AQCM05[$index_sonde][0][1][$i]  = "[$temps, $Value_AQCM05_T]";
							$data_AQCM05[$index_sonde][0][2][$i]  = "[$temps, $Value_AQCM05_T_max]";
							
							$data_AQCM05[$index_sonde][1][0][$i]  = "[$temps, $Value_AQCM05_HR_min]";
							$data_AQCM05[$index_sonde][1][1][$i]  = "[$temps, $Value_AQCM05_HR]";
							$data_AQCM05[$index_sonde][1][2][$i]  = "[$temps, $Value_AQCM05_HR_max]";
							
							$data_AQCM05[$index_sonde][2][0][$i]  = "[$temps, $Value_AQCM05_CO2_min]";
							$data_AQCM05[$index_sonde][2][1][$i]  = "[$temps, $Value_AQCM05_CO2]";
							$data_AQCM05[$index_sonde][2][2][$i]  = "[$temps, $Value_AQCM05_CO2_max]";
							$data_AQCM05[$index_sonde][13][0][$i]  = "[$temps, $Value_AQCM05_PRES]";
							$data_AQCM05[$index_sonde][13][1][$i]  = "[$temps, $Value_AQCM05_CO2_PRES]";
							
							$data_AQCM05[$index_sonde][3][0][$i]  = "[$temps, $Value_AQCM05_CO2_IAQ_min]";
							$data_AQCM05[$index_sonde][3][1][$i]  = "[$temps, $Value_AQCM05_CO2_IAQ]";
							$data_AQCM05[$index_sonde][3][2][$i]  = "[$temps, $Value_AQCM05_CO2_IAQ_max]";
							
							$data_AQCM05[$index_sonde][4][0][$i]  = "[$temps, $Value_AQCM05_P_mer_min]";
							$data_AQCM05[$index_sonde][4][1][$i]  = "[$temps, $Value_AQCM05_P_mer]";
							$data_AQCM05[$index_sonde][4][2][$i]  = "[$temps, $Value_AQCM05_P_mer_max]";
							
							$data_AQCM05[$index_sonde][5][0][$i]  = "[$temps, $Value_AQCM05_COV_IAQ_min]";
							$data_AQCM05[$index_sonde][5][1][$i]  = "[$temps, $Value_AQCM05_COV_IAQ]";
							$data_AQCM05[$index_sonde][5][2][$i]  = "[$temps, $Value_AQCM05_COV_IAQ_max]";
							
							$data_AQCM05[$index_sonde][6][0][$i]  = "[$temps, $Value_AQCM05_COV_IAQq_min]";
							$data_AQCM05[$index_sonde][6][1][$i]  = "[$temps, $Value_AQCM05_COV_IAQq]";
							$data_AQCM05[$index_sonde][6][2][$i]  = "[$temps, $Value_AQCM05_COV_IAQq_max]";
							
							$data_AQCM05[$index_sonde][7][0][$i]  = "[$temps, $Value_AQCM05_PM25_min]";
							$data_AQCM05[$index_sonde][7][1][$i]  = "[$temps, $Value_AQCM05_PM25]";
							$data_AQCM05[$index_sonde][7][2][$i]  = "[$temps, $Value_AQCM05_PM25_max]";
							
							$data_AQCM05[$index_sonde][8][0][$i]  = "[$temps, $Value_AQCM05_PM10_min]";
							$data_AQCM05[$index_sonde][8][1][$i]  = "[$temps, $Value_AQCM05_PM10]";
							$data_AQCM05[$index_sonde][8][2][$i]  = "[$temps, $Value_AQCM05_PM10_max]";
							
							$data_AQCM05[$index_sonde][9][0][$i]  = "[$temps, $Value_AQCM05_HCHO_min]";
							$data_AQCM05[$index_sonde][9][1][$i]  = "[$temps, $Value_AQCM05_HCHO]";
							$data_AQCM05[$index_sonde][9][2][$i]  = "[$temps, $Value_AQCM05_HCHO_max]";

							$data_AQCM05[$index_sonde][10][0][$i]  = "[$temps, $Value_AQCM05_LUX_min]";
							$data_AQCM05[$index_sonde][10][1][$i]  = "[$temps, $Value_AQCM05_LUX]";
							$data_AQCM05[$index_sonde][10][2][$i]  = "[$temps, $Value_AQCM05_LUX_max]";

							$data_AQCM05[$index_sonde][11][0][$i]  = "[$temps, $Value_AQCM05_SPL_min]";
							$data_AQCM05[$index_sonde][11][1][$i]  = "[$temps, $Value_AQCM05_SPL]";
							$data_AQCM05[$index_sonde][11][2][$i]  = "[$temps, $Value_AQCM05_SPL_max]";

							$data_AQCM05[$index_sonde][12][0][$i]  = "[$temps, $Value_AQCM05_NOX_IAQ_min]";
							$data_AQCM05[$index_sonde][12][1][$i]  = "[$temps, $Value_AQCM05_NOX_IAQ]";
							$data_AQCM05[$index_sonde][12][2][$i]  = "[$temps, $Value_AQCM05_NOX_IAQ_max]";
							
							//---------------------------------------------------------------------
							// calculs sans présence
							//---------------------------------------------------------------------
							if ( True ) {
								
								$AQCM05_T_min_value[$index_sonde][$i]        = $Value_AQCM05_T_min;
								$AQCM05_T_value[$index_sonde][$i]            = $Value_AQCM05_T;
								$AQCM05_T_max_value[$index_sonde][$i]        = $Value_AQCM05_T_max;
								
								$AQCM05_HR_min_value[$index_sonde][$i]       = $Value_AQCM05_HR_min;
								$AQCM05_HR_value[$index_sonde][$i]           = $Value_AQCM05_HR;
								$AQCM05_HR_max_value[$index_sonde][$i]       = $Value_AQCM05_HR_max;
								
								$AQCM05_CO2_min_value[$index_sonde][$i]      = $Value_AQCM05_CO2_min ;
								$AQCM05_CO2_value[$index_sonde][$i]          = $Value_AQCM05_CO2 ;
								$AQCM05_CO2_max_value[$index_sonde][$i]      = $Value_AQCM05_CO2_max ;
								
								$AQCM05_CO2_IAQ_min_value[$index_sonde][$i]  = $Value_AQCM05_CO2_IAQ_min;
								$AQCM05_CO2_IAQ_value[$index_sonde][$i]      = $Value_AQCM05_CO2_IAQ;
								$AQCM05_CO2_IAQ_max_value[$index_sonde][$i]  = $Value_AQCM05_CO2_IAQ_max;
								
								$AQCM05_P_mer_min_value[$index_sonde][$i]    = $Value_AQCM05_P_mer_min;
								$AQCM05_P_mer_value[$index_sonde][$i]        = $Value_AQCM05_P_mer;
								$AQCM05_P_mer_max_value[$index_sonde][$i]    = $Value_AQCM05_P_mer_max;
								
								$AQCM05_COV_IAQ_min_value[$index_sonde][$i]  = $Value_AQCM05_COV_IAQ_min;
								$AQCM05_COV_IAQ_value[$index_sonde][$i]      = $Value_AQCM05_COV_IAQ;
								$AQCM05_COV_IAQ_max_value[$index_sonde][$i]  = $Value_AQCM05_COV_IAQ_max;
								
								$AQCM05_COV_IAQq_min_value[$index_sonde][$i] = $Value_AQCM05_COV_IAQq_min;
								$AQCM05_COV_IAQq_value[$index_sonde][$i]     = $Value_AQCM05_COV_IAQq;
								$AQCM05_COV_IAQq_max_value[$index_sonde][$i] = $Value_AQCM05_COV_IAQq_max;
								
								$AQCM05_PM25_min_value[$index_sonde][$i]     = $Value_AQCM05_PM25_min;
								$AQCM05_PM25_value[$index_sonde][$i]         = $Value_AQCM05_PM25;
								$AQCM05_PM25_max_value[$index_sonde][$i]     = $Value_AQCM05_PM25_max;
								
								$AQCM05_PM10_min_value[$index_sonde][$i]     = $Value_AQCM05_PM10_min;
								$AQCM05_PM10_value[$index_sonde][$i]         = $Value_AQCM05_PM10;
								$AQCM05_PM10_max_value[$index_sonde][$i]     = $Value_AQCM05_PM10_max;
								
								$AQCM05_HCHO_min_value[$index_sonde][$i]     = $Value_AQCM05_HCHO_min;
								$AQCM05_HCHO_value[$index_sonde][$i]         = $Value_AQCM05_HCHO;
								$AQCM05_HCHO_max_value[$index_sonde][$i]     = $Value_AQCM05_HCHO_max;

								$AQCM05_LUX_min_value[$index_sonde][$i]      = $Value_AQCM05_LUX_min;
								$AQCM05_LUX_value[$index_sonde][$i]          = $Value_AQCM05_LUX;
								$AQCM05_LUX_max_value[$index_sonde][$i]      = $Value_AQCM05_LUX_max;

								$AQCM05_SPL_min_value[$index_sonde][$i]      = $Value_AQCM05_SPL_min;
								$AQCM05_SPL_value[$index_sonde][$i]          = $Value_AQCM05_SPL;
								$AQCM05_SPL_max_value[$index_sonde][$i]      = $Value_AQCM05_SPL_max;

								$AQCM05_NOX_IAQ_min_value[$index_sonde][$i]  = $Value_AQCM05_NOX_IAQ_min;
								$AQCM05_NOX_IAQ_value[$index_sonde][$i]      = $Value_AQCM05_NOX_IAQ;
								$AQCM05_NOX_IAQ_max_value[$index_sonde][$i]  = $Value_AQCM05_NOX_IAQ_max;
							
							}
							
							//---------------------------------------------------------------------
							// calculs avec présence
							//---------------------------------------------------------------------
							if ( $Value_AQCM05_PRES != 0 ) {
								
								$AQCM05_T_min_value_presence[$index_sonde][$ii]        = $Value_AQCM05_T_min;
								$AQCM05_T_value_presence[$index_sonde][$ii]            = $Value_AQCM05_T;
								$AQCM05_T_max_value_presence[$index_sonde][$ii]        = $Value_AQCM05_T_max;
								
								$AQCM05_HR_min_value_presence[$index_sonde][$ii]       = $Value_AQCM05_HR_min;
								$AQCM05_HR_value_presence[$index_sonde][$ii]           = $Value_AQCM05_HR;
								$AQCM05_HR_max_value_presence[$index_sonde][$ii]       = $Value_AQCM05_HR_max;
								
								$AQCM05_CO2_min_value_presence[$index_sonde][$ii]      = $Value_AQCM05_CO2_min ;
								$AQCM05_CO2_value_presence[$index_sonde][$ii]          = $Value_AQCM05_CO2 ;
								$AQCM05_CO2_max_value_presence[$index_sonde][$ii]      = $Value_AQCM05_CO2_max ;
								
								$AQCM05_CO2_IAQ_min_value_presence[$index_sonde][$ii]  = $Value_AQCM05_CO2_IAQ_min;
								$AQCM05_CO2_IAQ_value_presence[$index_sonde][$ii]      = $Value_AQCM05_CO2_IAQ;
								$AQCM05_CO2_IAQ_max_value_presence[$index_sonde][$ii]  = $Value_AQCM05_CO2_IAQ_max;
								
								$AQCM05_P_mer_min_value_presence[$index_sonde][$ii]    = $Value_AQCM05_P_mer_min;
								$AQCM05_P_mer_value_presence[$index_sonde][$ii]        = $Value_AQCM05_P_mer;
								$AQCM05_P_mer_max_value_presence[$index_sonde][$ii]    = $Value_AQCM05_P_mer_max;
								
								$AQCM05_COV_IAQ_min_value_presence[$index_sonde][$ii]  = $Value_AQCM05_COV_IAQ_min;
								$AQCM05_COV_IAQ_value_presence[$index_sonde][$ii]      = $Value_AQCM05_COV_IAQ;
								$AQCM05_COV_IAQ_max_value_presence[$index_sonde][$ii]  = $Value_AQCM05_COV_IAQ_max;
								
								$AQCM05_COV_IAQq_min_value_presence[$index_sonde][$ii] = $Value_AQCM05_COV_IAQq_min;
								$AQCM05_COV_IAQq_value_presence[$index_sonde][$ii]     = $Value_AQCM05_COV_IAQq;
								$AQCM05_COV_IAQq_max_value_presence[$index_sonde][$ii] = $Value_AQCM05_COV_IAQq_max;
								
								$AQCM05_PM25_min_value_presence[$index_sonde][$ii]     = $Value_AQCM05_PM25_min;
								$AQCM05_PM25_value_presence[$index_sonde][$ii]         = $Value_AQCM05_PM25;
								$AQCM05_PM25_max_value_presence[$index_sonde][$ii]     = $Value_AQCM05_PM25_max;
								
								$AQCM05_PM10_min_value_presence[$index_sonde][$ii]     = $Value_AQCM05_PM10_min;
								$AQCM05_PM10_value_presence[$index_sonde][$ii]         = $Value_AQCM05_PM10;
								$AQCM05_PM10_max_value_presence[$index_sonde][$ii]     = $Value_AQCM05_PM10_max;
								
								$AQCM05_HCHO_min_value_presence[$index_sonde][$ii]     = $Value_AQCM05_HCHO_min;
								$AQCM05_HCHO_value_presence[$index_sonde][$ii]         = $Value_AQCM05_HCHO;
								$AQCM05_HCHO_max_value_presence[$index_sonde][$ii]     = $Value_AQCM05_HCHO_max;

								$AQCM05_LUX_min_value_presence[$index_sonde][$ii]      = $Value_AQCM05_LUX_min;
								$AQCM05_LUX_value_presence[$index_sonde][$ii]          = $Value_AQCM05_LUX;
								$AQCM05_LUX_max_value_presence[$index_sonde][$ii]      = $Value_AQCM05_LUX_max;

								$AQCM05_SPL_min_value_presence[$index_sonde][$ii]      = $Value_AQCM05_SPL_min;
								$AQCM05_SPL_value_presence[$index_sonde][$ii]          = $Value_AQCM05_SPL;
								$AQCM05_SPL_max_value_presence[$index_sonde][$ii]      = $Value_AQCM05_SPL_max;

								$AQCM05_NOX_IAQ_min_value_presence[$index_sonde][$ii]  = $Value_AQCM05_NOX_IAQ_min;
								$AQCM05_NOX_IAQ_value_presence[$index_sonde][$ii]      = $Value_AQCM05_NOX_IAQ;
								$AQCM05_NOX_IAQ_max_value_presence[$index_sonde][$ii]  = $Value_AQCM05_NOX_IAQ_max;
								
								$ii++;
							
							}
							
							$i++ ;

						}
						
					}
	
					$Nb_mesures_graphes[$index_sonde] = $i ;
					$Nb_mesures_presence[$index_sonde] = $ii ;
					
					//echo($Nb_mesures_graphes[$index_sonde] . ";" . $Nb_mesures_presence[$index_sonde] . "<br>");
					
					mysqli_close($link_mesures);
					
					//---------------------------------------------------------
					// calcul des min,moy,max
					//---------------------------------------------------------

					//-------------------------------------------------------------------
					// T
					//-------------------------------------------------------------------
					$AQCM05_T_moy[$index_sonde] = round((array_sum($AQCM05_T_value[$index_sonde]))/$Nb_mesures_graphes[$index_sonde], 1);
					
					if ( $show_mini_maxi == "true"  )	{ $AQCM05_T_min[$index_sonde] = min($AQCM05_T_min_value[$index_sonde]) ; }
					else 								{ $AQCM05_T_min[$index_sonde] = min($AQCM05_T_value[$index_sonde])     ; }
					
					if ( $show_mini_maxi == "true"  )	{ $AQCM05_T_max[$index_sonde] = max($AQCM05_T_max_value[$index_sonde]) ; }
					else 								{ $AQCM05_T_max[$index_sonde] = max($AQCM05_T_value[$index_sonde])     ; }
					
					//-------------------------------------------------------------------
					// HR
					//-------------------------------------------------------------------
					$AQCM05_HR_moy[$index_sonde] = round((array_sum($AQCM05_HR_value[$index_sonde]))/$Nb_mesures_graphes[$index_sonde],1); 
				
					//-------------------------------------------------------------------
					// CO2
					//-------------------------------------------------------------------
					$AQCM05_CO2_moy[$index_sonde] 			= round((array_sum($AQCM05_CO2_value[$index_sonde]))/$Nb_mesures_graphes[$index_sonde], 0); 
					
					if ( $show_mini_maxi == "true" ) {
						$HC_CO2_max[$index_sonde] = max($AQCM05_CO2_max_value[$index_sonde]);
					}
					else {
						$HC_CO2_max[$index_sonde] = max($AQCM05_CO2_value[$index_sonde]);
					}

					//-------------------------------------------------------------------
					// CO2_IAQ
					//-------------------------------------------------------------------
					$AQCM05_CO2_IAQ_moy[$index_sonde] = round((array_sum($AQCM05_CO2_IAQ_value[$index_sonde]))/$Nb_mesures_graphes[$index_sonde], 2); 
					
					//-------------------------------------------------------------------
					// P
					//-------------------------------------------------------------------
					$AQCM05_P_mer_moy[$index_sonde] = round((array_sum($AQCM05_P_mer_value[$index_sonde]))/$Nb_mesures_graphes[$index_sonde], 2); 
					$HC_P_mer_min[$index_sonde]     = min($AQCM05_P_mer_value[$index_sonde]);
					$HC_P_mer_max[$index_sonde]     = max($AQCM05_P_mer_value[$index_sonde]);
					
					//-------------------------------------------------------------------
					// COV
					//-------------------------------------------------------------------
					$AQCM05_COV_IAQ_moy[$index_sonde]  = round((array_sum($AQCM05_COV_IAQ_value[$index_sonde]))/$Nb_mesures_graphes[$index_sonde],0); 
					$AQCM05_COV_IAQq_moy[$index_sonde] = round((array_sum($AQCM05_COV_IAQq_value[$index_sonde]))/$Nb_mesures_graphes[$index_sonde],2); 
					
					//-------------------------------------------------------------------
					// PM
					//-------------------------------------------------------------------
					$AQCM05_PM25_moy[$index_sonde] = round((array_sum($AQCM05_PM25_value[$index_sonde]))/$Nb_mesures_graphes[$index_sonde],1); 
					$AQCM05_PM10_moy[$index_sonde] = round((array_sum($AQCM05_PM10_value[$index_sonde]))/$Nb_mesures_graphes[$index_sonde],1); 
					
					if ( $show_mini_maxi == "true" )		{ $HC_PM25_max_0 = max($AQCM05_PM25_max_value[$index_sonde]) ; }
					else 									{ $HC_PM25_max_0 = max($AQCM05_PM25_value[$index_sonde])     ; }
					if ( $show_mini_maxi == "true" )		{ $HC_PM10_max_0 = max($AQCM05_PM10_max_value[$index_sonde]) ; }
					else 									{ $HC_PM10_max_0 = max($AQCM05_PM10_value[$index_sonde])     ; }
					if ( $HC_PM25_max_0 > $HC_PM10_max_0 )	{ $AQCM05_PM25_PM10_maxi[$index_sonde] = $HC_PM25_max_0 ; } 
					else 									{ $AQCM05_PM25_PM10_maxi[$index_sonde] = $HC_PM10_max_0 ; }
					
					//-------------------------------------------------------------------
					// HCHO
					//-------------------------------------------------------------------
					$AQCM05_HCHO_moy[$index_sonde] = round((array_sum($AQCM05_HCHO_value[$index_sonde]))/$Nb_mesures_graphes[$index_sonde], 1); 
					if ( $show_mini_maxi == "true" )	{ $AQCM05_HCHO_max[$index_sonde] = max($AQCM05_HCHO_max_value[$index_sonde]) ; }
					else 								{ $AQCM05_HCHO_max[$index_sonde] = max($AQCM05_HCHO_value[$index_sonde])     ; }
											
					//-------------------------------------------------------------------
					// LUX
					//-------------------------------------------------------------------
					$AQCM05_LUX_moy[$index_sonde] = round((array_sum($AQCM05_LUX_value[$index_sonde]))/$Nb_mesures_graphes[$index_sonde], 0); 
					if ( $show_mini_maxi == "true" )	{ $AQCM05_LUX_max[$index_sonde] = max($AQCM05_LUX_max_value[$index_sonde]) ; }
					else 								{ $AQCM05_LUX_max[$index_sonde] = max($AQCM05_LUX_value[$index_sonde])     ; }
											
					//-------------------------------------------------------------------
					// SPL
					//-------------------------------------------------------------------
					$AQCM05_SPL_moy[$index_sonde] = round((array_sum($AQCM05_SPL_value[$index_sonde]))/$Nb_mesures_graphes[$index_sonde], 1); 
					if ( $show_mini_maxi == "true" )	{ $AQCM05_SPL_max[$index_sonde] = max($AQCM05_SPL_max_value[$index_sonde]) ; }
					else 						{ $AQCM05_SPL_max[$index_sonde] = max($AQCM05_SPL_value[$index_sonde])     ; }

					//-------------------------------------------------------------------
					// NOX_IAQ
					//-------------------------------------------------------------------
					$AQCM05_NOX_IAQ_moy[$index_sonde] = round((array_sum($AQCM05_NOX_IAQ_value[$index_sonde]))/$Nb_mesures_graphes[$index_sonde], 1); 
					$AQCM05_NOX_IAQ_max[$index_sonde] = max($AQCM05_NOX_IAQ_value[$index_sonde]);
											
					
					//---------------------------------------------------------
					// calcul des moyennes en tenant compte des présences
					//---------------------------------------------------------
					if ( $Nb_mesures_presence[$index_sonde] > 2 ) {
						
						$AQCM05_T_moy_presence[$index_sonde] = round((array_sum($AQCM05_T_value_presence[$index_sonde]))/$Nb_mesures_presence[$index_sonde], 1);
						$AQCM05_HR_moy_presence[$index_sonde] = round((array_sum($AQCM05_HR_value_presence[$index_sonde]))/$Nb_mesures_presence[$index_sonde], 1);
						$AQCM05_CO2_moy_presence[$index_sonde] 	= round((array_sum($AQCM05_CO2_value_presence[$index_sonde]))/$Nb_mesures_presence[$index_sonde], 0); 
						$AQCM05_CO2_IAQ_moy_presence[$index_sonde] 	= round((array_sum($AQCM05_CO2_IAQ_value_presence[$index_sonde]))/$Nb_mesures_presence[$index_sonde], 2); 
						$AQCM05_P_mer_moy_presence[$index_sonde] 	= round((array_sum($AQCM05_P_mer_value_presence[$index_sonde]))/$Nb_mesures_presence[$index_sonde], 2); 
						$AQCM05_COV_IAQ_moy_presence[$index_sonde] 	= round((array_sum($AQCM05_COV_IAQ_value_presence[$index_sonde]))/$Nb_mesures_presence[$index_sonde], 0); 
						$AQCM05_COV_IAQq_moy_presence[$index_sonde] 	= round((array_sum($AQCM05_COV_IAQq_value_presence[$index_sonde]))/$Nb_mesures_presence[$index_sonde], 2); 
						$AQCM05_PM25_moy_presence[$index_sonde] 	= round((array_sum($AQCM05_PM25_value_presence[$index_sonde]))/$Nb_mesures_presence[$index_sonde], 1); 
						$AQCM05_PM10_moy_presence[$index_sonde] 	= round((array_sum($AQCM05_PM10_value_presence[$index_sonde]))/$Nb_mesures_presence[$index_sonde], 1); 
						$AQCM05_HCHO_moy_presence[$index_sonde] 	= round((array_sum($AQCM05_HCHO_value_presence[$index_sonde]))/$Nb_mesures_presence[$index_sonde], 1); 
						$AQCM05_LUX_moy_presence[$index_sonde] 	= round((array_sum($AQCM05_LUX_value_presence[$index_sonde]))/$Nb_mesures_presence[$index_sonde], 0); 
						$AQCM05_SPL_moy_presence[$index_sonde] 	= round((array_sum($AQCM05_SPL_value_presence[$index_sonde]))/$Nb_mesures_presence[$index_sonde], 1); 
						$AQCM05_NOX_IAQ_moy_presence[$index_sonde] 	= round((array_sum($AQCM05_NOX_IAQ_value_presence[$index_sonde]))/$Nb_mesures_presence[$index_sonde], 1);
						
					} else {
					}

					
					
					
					//-------------------------------------------------------------------
					$Flag_SONDE_OK[$index_sonde] = True;
					
					if ($Flag_debug == 1) {
						echo("AQCM3 : " . $i . " mesures" . "</br>");
						echo "data: [ "; echo join( ',' , $data_AQCM05[$index_sonde][0] ); echo "]";
						echo "<br>";
						echo $index_sonde . " " . $Flag_SONDE_OK[$index_sonde] . "</br>";
						echo "<br>";
					}

				}
			}
		}
	}
	
	if ( $error == 0 ) {
		
		//-----------------------------------------------------------------------------------
		$AQCM05_T_moy_0			= $AQCM05_T_moy[0] ;
		$AQCM05_HR_moy_0			= $AQCM05_HR_moy[0] ;
		$AQCM05_CO2_moy_0      	= $AQCM05_CO2_moy[0] ;
		$AQCM05_CO2_IAQ_moy_0	= $AQCM05_CO2_IAQ_moy[0] ;
		$AQCM05_P_mer_moy_0    = $AQCM05_P_mer_moy[0] ;
		$AQCM05_COV_IAQ_moy_0  = $AQCM05_COV_IAQ_moy[0] ;
		$AQCM05_COV_IAQq_moy_0 = $AQCM05_COV_IAQq_moy[0] ;
		$AQCM05_PM25_moy_0     = $AQCM05_PM25_moy[0] ;
		$AQCM05_PM10_moy_0     = $AQCM05_PM10_moy[0] ;
		$AQCM05_HCHO_moy_0     = $AQCM05_HCHO_moy[0] ;
		$AQCM05_LUX_moy_0      = $AQCM05_LUX_moy[0] ;
		$AQCM05_SPL_moy_0      = $AQCM05_SPL_moy[0] ;
		$AQCM05_NOX_IAQ_moy_0  = $AQCM05_NOX_IAQ_moy[0] ;

		if ( ( $periode == "10_MN" ) && ( $Nb_mesures_presence[0] > 2 ) ) {
			
			$AQCM05_T_moy_presence_0			= "/" . strval($AQCM05_T_moy_presence[0]) ;
			$AQCM05_HR_moy_presence_0			= "/" . strval($AQCM05_HR_moy_presence[0]) ;
			$AQCM05_CO2_moy_presence_0			= "/" . strval($AQCM05_CO2_moy_presence[0]) ;
			$AQCM05_CO2_IAQ_moy_presence_0	= "/" . strval($AQCM05_CO2_IAQ_moy_presence[0]) ;
			$AQCM05_P_mer_moy_presence_0		= "/" . strval($AQCM05_P_mer_moy_presence[0]) ;
			$AQCM05_COV_IAQ_moy_presence_0	= "/" . strval($AQCM05_COV_IAQ_moy_presence[0]) ;
			$AQCM05_COV_IAQq_moy_presence_0	= "/" . strval($AQCM05_COV_IAQq_moy_presence[0]) ;
			$AQCM05_PM25_moy_presence_0		= "/" . strval($AQCM05_PM25_moy_presence[0]) ;
			$AQCM05_PM10_moy_presence_0		= "/" . strval($AQCM05_PM10_moy_presence[0]) ;
			$AQCM05_HCHO_moy_presence_0		= "/" . strval($AQCM05_HCHO_moy_presence[0]) ;
			$AQCM05_LUX_moy_presence_0			= "/" . strval($AQCM05_LUX_moy_presence[0]) ;
			$AQCM05_SPL_moy_presence_0			= "/" . strval($AQCM05_SPL_moy_presence[0]) ;
			$AQCM05_NOX_IAQ_moy_presence_0	= "/" . strval($AQCM05_NOX_IAQ_moy_presence[0]) ;
			
		} else {
			
			$AQCM05_T_moy_presence_0			= "" ;
			$AQCM05_HR_moy_presence_0			= "" ;
			$AQCM05_CO2_moy_presence_0			= "" ;
			$AQCM05_CO2_IAQ_moy_presence_0	= "" ;
			$AQCM05_P_mer_moy_presence_0		= "" ;
			$AQCM05_COV_IAQ_moy_presence_0	= "" ;
			$AQCM05_COV_IAQq_moy_presence_0	= "" ;
			$AQCM05_PM25_moy_presence_0		= "" ;
			$AQCM05_PM10_moy_presence_0		= "" ;
			$AQCM05_HCHO_moy_presence_0		= "" ;
			$AQCM05_LUX_moy_presence_0			= "" ;
			$AQCM05_SPL_moy_presence_0			= "" ;
			$AQCM05_NOX_IAQ_moy_presence_0	= "" ;
			
		}


		//-----------------------------------------------------------------------------------
		// détermination des échelles des graphiques
		//-----------------------------------------------------------------------------------
		$HC_T_min_scale = 5 * floor( min($AQCM05_T_min) / 5.0 ) ;
		$HC_T_max_scale = 5 *  ceil( max($AQCM05_T_max) / 5.0 ) ;
		if ( $scheduled_status ) {
			$HC_T_tickInterval = 1.0;
			$HC_T_minorTickInterval = 1.0 ;
		}
		else {
			$HC_T_tickInterval = 1.0;
			$HC_T_minorTickInterval = 0.5 ;
		}

		//-----------------------------------------------------------------------------------
		$HC_HR_min_scale = 0.0 ;
		$HC_HR_max_scale = 100.0 ;
		$HC_HR_tickInterval = 10.0;
		$HC_HR_minorTickInterval = 5.0 ;

		//-----------------------------------------------------------------------------------
		$HC_CO2_maxi = max($HC_CO2_max);
		if ( $HC_CO2_maxi <=  1000.0 ) { $HC_CO2_max_scale =   1000 ; $HC_CO2_tickInterval =  100 ; $HC_CO2_minorTickInterval =   50; }
		if ( $HC_CO2_maxi >   1000.0 ) { $HC_CO2_max_scale =   2000 ; $HC_CO2_tickInterval =  200 ; $HC_CO2_minorTickInterval =  100; }
		if ( $HC_CO2_maxi >   2000.0 ) { $HC_CO2_max_scale =   3000 ; $HC_CO2_tickInterval =  200 ; $HC_CO2_minorTickInterval =  100; }
		if ( $HC_CO2_maxi >   3000.0 ) { $HC_CO2_max_scale =   4000 ; $HC_CO2_tickInterval =  500 ; $HC_CO2_minorTickInterval =  250; }
		if ( $HC_CO2_maxi >   4000.0 ) { $HC_CO2_max_scale =   5000 ; $HC_CO2_tickInterval =  500 ; $HC_CO2_minorTickInterval =  250; }
		if ( $HC_CO2_maxi >   5000.0 ) { $HC_CO2_max_scale =  10000 ; $HC_CO2_tickInterval = 1000 ; $HC_CO2_minorTickInterval =  500; }
		
		$HC_CO2_IAQ_max_scale   = 6 ;

		//--------------------------------------------------------------------
		$HC_P_mer_min_scale = intval( -2 + ( floor( floatval(min($HC_P_mer_min))))) ;
		$HC_P_mer_max_scale = intval( +2 + (  ceil( floatval(max($HC_P_mer_max)))) );
		$HC_P_mer_tickInterval = 1.0;
		$HC_P_mer_minorTickInterval = 1.0 ;
		
		//--------------------------------------------------------------------
		$HC_COV_IAQ_min_scale = 0.0 ;
		$HC_COV_IAQ_max_scale = 500.0 ;
		$HC_COV_IAQ_tickInterval = 100.0;
		$HC_COV_IAQ_minorTickInterval = 50.0 ;

		//--------------------------------------------------------------------
		$HC_PM25_PM10_min_scale = 0.0 ;
		$HC_PM25_PM10_maxi = max($AQCM05_PM25_PM10_maxi);
		if ( $HC_PM25_PM10_maxi <=   10.0 ) { $HC_PM25_PM10_max_scale =    10 ; $HC_PM25_PM10_tickInterval =   1 ; $HC_PM25_PM10_minorTickInterval = 0.5; }
		if ( $HC_PM25_PM10_maxi >    10.0 ) { $HC_PM25_PM10_max_scale =    20 ; $HC_PM25_PM10_tickInterval =   2 ; $HC_PM25_PM10_minorTickInterval = 1.0; }
		if ( $HC_PM25_PM10_maxi >    20.0 ) { $HC_PM25_PM10_max_scale =    50 ; $HC_PM25_PM10_tickInterval =   5 ; $HC_PM25_PM10_minorTickInterval = 2.5; }
		if ( $HC_PM25_PM10_maxi >    50.0 ) { $HC_PM25_PM10_max_scale =   100 ; $HC_PM25_PM10_tickInterval =  10 ; $HC_PM25_PM10_minorTickInterval = 5.0; }
		if ( $HC_PM25_PM10_maxi >   100.0 ) { $HC_PM25_PM10_max_scale =   200 ; $HC_PM25_PM10_tickInterval =  20 ; $HC_PM25_PM10_minorTickInterval =  10; }
		if ( $HC_PM25_PM10_maxi >   200.0 ) { $HC_PM25_PM10_max_scale =   500 ; $HC_PM25_PM10_tickInterval =  50 ; $HC_PM25_PM10_minorTickInterval =  25; }
		if ( $HC_PM25_PM10_maxi >   500.0 ) { $HC_PM25_PM10_max_scale =  1000 ; $HC_PM25_PM10_tickInterval = 100 ; $HC_PM25_PM10_minorTickInterval =  50; }
		if ( $HC_PM25_PM10_maxi >  1000.0 ) { $HC_PM25_PM10_max_scale =  2000 ; $HC_PM25_PM10_tickInterval = 200 ; $HC_PM25_PM10_minorTickInterval = 100; }
		if ( $HC_PM25_PM10_maxi >  2000.0 ) { $HC_PM25_PM10_max_scale =  5000 ; $HC_PM25_PM10_tickInterval = 500 ; $HC_PM25_PM10_minorTickInterval = 250; }

		//--------------------------------------------------------------------
		$HC_HCHO_min_scale = 0.0 ;
		$HC_HCHO_maxi = max($AQCM05_HCHO_max);
		if ( $HC_HCHO_maxi <=  10.0 ) { $HC_HCHO_max_scale =   10 ; $HC_HCHO_tickInterval =   1; $HC_HCHO_minorTickInterval = 0.5; }
		if ( $HC_HCHO_maxi >   10.0 ) { $HC_HCHO_max_scale =   20 ; $HC_HCHO_tickInterval =   2; $HC_HCHO_minorTickInterval =   1; }
		if ( $HC_HCHO_maxi >   20.0 ) { $HC_HCHO_max_scale =   50 ; $HC_HCHO_tickInterval =   5; $HC_HCHO_minorTickInterval = 2.5; }
		if ( $HC_HCHO_maxi >   50.0 ) { $HC_HCHO_max_scale =  100 ; $HC_HCHO_tickInterval =  10; $HC_HCHO_minorTickInterval =   5; }
		if ( $HC_HCHO_maxi >  100.0 ) { $HC_HCHO_max_scale =  200 ; $HC_HCHO_tickInterval =  20; $HC_HCHO_minorTickInterval =  10; }
		if ( $HC_HCHO_maxi >  200.0 ) { $HC_HCHO_max_scale =  500 ; $HC_HCHO_tickInterval =  50; $HC_HCHO_minorTickInterval =  25; }
		if ( $HC_HCHO_maxi >  500.0 ) { $HC_HCHO_max_scale = 1000 ; $HC_HCHO_tickInterval = 100; $HC_HCHO_minorTickInterval =  50; }
		
		//--------------------------------------------------------------------
		$HC_LUX_min_scale = 0.0 ;
		$HC_LUX_maxi = max($AQCM05_LUX_max);
		if ( $HC_LUX_maxi <=  100.0 ) { $HC_LUX_max_scale =   100 ; $HC_LUX_tickInterval =   10; $HC_LUX_minorTickInterval =    5; }
		if ( $HC_LUX_maxi >   100.0 ) { $HC_LUX_max_scale =   200 ; $HC_LUX_tickInterval =   20; $HC_LUX_minorTickInterval =   10; }
		if ( $HC_LUX_maxi >   200.0 ) { $HC_LUX_max_scale =   500 ; $HC_LUX_tickInterval =   50; $HC_LUX_minorTickInterval =   25; }
		if ( $HC_LUX_maxi >   500.0 ) { $HC_LUX_max_scale =  1000 ; $HC_LUX_tickInterval =  100; $HC_LUX_minorTickInterval =   50; }
		if ( $HC_LUX_maxi >  1000.0 ) { $HC_LUX_max_scale =  2000 ; $HC_LUX_tickInterval =  200; $HC_LUX_minorTickInterval =  100; }
		if ( $HC_LUX_maxi >  2000.0 ) { $HC_LUX_max_scale =  5000 ; $HC_LUX_tickInterval =  500; $HC_LUX_minorTickInterval =  250; }
		if ( $HC_LUX_maxi >  5000.0 ) { $HC_LUX_max_scale = 10000 ; $HC_LUX_tickInterval = 1000; $HC_LUX_minorTickInterval =  500; }
		if ( $HC_LUX_maxi > 10000.0 ) { $HC_LUX_max_scale = 20000 ; $HC_LUX_tickInterval = 2000; $HC_LUX_minorTickInterval = 1000; }
		if ( $HC_LUX_maxi > 20000.0 ) { $HC_LUX_max_scale = 50000 ; $HC_LUX_tickInterval = 5000; $HC_LUX_minorTickInterval = 2500; }
		
		//--------------------------------------------------------------------
		$HC_SPL_min_scale = 0.0 ;
		$HC_SPL_max_scale = 140.0 ;
		$HC_SPL_tickInterval = 10.0;
		$HC_SPL_minorTickInterval = 5.0 ;
		$HC_SPL_max_scale = 10 * intval( 1 + (  ceil( floatval(max($AQCM05_SPL_max) ) ) ) / 10.0 ) ;
		
		//--------------------------------------------------------------------
		$HC_NOX_min_scale = 0.0 ;
		$AQCM05_NOX_IAQ_maxi = max($AQCM05_NOX_IAQ_max);
		if ( $AQCM05_NOX_IAQ_maxi <=   10.0 ) { $HC_NOX_IAQ_max_scale =    10 ; $HC_NOX_IAQ_tickInterval =   1 ; $HC_NOX_IAQ_minorTickInterval =  0.5; }
		if ( $AQCM05_NOX_IAQ_maxi >    10.0 ) { $HC_NOX_IAQ_max_scale =    20 ; $HC_NOX_IAQ_tickInterval =   2 ; $HC_NOX_IAQ_minorTickInterval =    1; }
		if ( $AQCM05_NOX_IAQ_maxi >    20.0 ) { $HC_NOX_IAQ_max_scale =    50 ; $HC_NOX_IAQ_tickInterval =   5 ; $HC_NOX_IAQ_minorTickInterval =  2.5; }
		if ( $AQCM05_NOX_IAQ_maxi >    50.0 ) { $HC_NOX_IAQ_max_scale =   100 ; $HC_NOX_IAQ_tickInterval =  10 ; $HC_NOX_IAQ_minorTickInterval =    5; }
		if ( $AQCM05_NOX_IAQ_maxi >   100.0 ) { $HC_NOX_IAQ_max_scale =   200 ; $HC_NOX_IAQ_tickInterval =  20 ; $HC_NOX_IAQ_minorTickInterval =   10; }
		if ( $AQCM05_NOX_IAQ_maxi >   200.0 ) { $HC_NOX_IAQ_max_scale =   500 ; $HC_NOX_IAQ_tickInterval =  50 ; $HC_NOX_IAQ_minorTickInterval =   25; }
		if ( $AQCM05_NOX_IAQ_maxi >   500.0 ) { $HC_NOX_IAQ_max_scale =  1000 ; $HC_NOX_IAQ_tickInterval = 100 ; $HC_NOX_IAQ_minorTickInterval =   50; }
		

		//--------------------------------------------------------------------
		// préparation des titres des graphes
		//--------------------------------------------------------------------
		if ( $scheduled_status ) {
			$text_T        = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'température' + whiteSpacer(5) + 'bilans AM/PM' " ;
			$text_HR       = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'humidité relative' + whiteSpacer(5) + 'bilans AM/PM' " ;
			$text_CO2      = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'taux de CO2' + whiteSpacer(5) + 'bilans AM/PM' " ;
			$text_CO2_IAQ  = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'indice CO2 (/5)' + whiteSpacer(5) + 'bilans AM/PM' " ;
			$text_P_mer    = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'P_atmosphérique' + whiteSpacer(5) + 'bilans AM/PM' " ;
			$text_COV_IAQ  = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'indice COV (/500)' + whiteSpacer(5) + 'bilans AM/PM' " ;
			$text_COV_IAQq = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'accuracy status' + whiteSpacer(5) + 'bilans AM/PM' " ;
			$text_PM25     = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'PM2.5' + whiteSpacer(5) + 'bilans AM/PM' " ;
			$text_PM10     = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'PM10' + whiteSpacer(5) + 'bilans AM/PM' " ;
			$text_HCHO     = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'formaldéhyde' + whiteSpacer(5) + 'bilans AM/PM' " ;
			$text_LUX      = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'luminosité' + whiteSpacer(5) + 'bilans AM/PM' " ;
			$text_SPL      = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'niveau sonore (SPL)' + whiteSpacer(5) + 'bilans AM/PM' " ;
			$text_NOX_IAQ  = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'indice NOx (/500)</sub>' + whiteSpacer(5) + 'bilans AM/PM' " ;
		} 
		else {
			
			$text_T        = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'température' + whiteSpacer(5) + 'moyenne = " . $AQCM05_T_moy_0 . $AQCM05_T_moy_presence_0 . " °C'" ;

			$text_HR        = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'humidité relative' + whiteSpacer(5) + 'moyenne = " . $AQCM05_HR_moy_0 . $AQCM05_HR_moy_presence_0 . " %'" ;

			$text_CO2      = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'taux de CO2' + whiteSpacer(5) + 'moyennes = " . $AQCM05_CO2_moy_0 . $AQCM05_CO2_moy_presence_0 . " ppm'" ;

			$text_CO2_IAQ        = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'indice CO2' + whiteSpacer(5) + 'moyenne = " . $AQCM05_CO2_IAQ_moy_0 . $AQCM05_CO2_IAQ_moy_presence_0 . " /5'" ;
			
			$text_P_mer        = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'P_atm' + whiteSpacer(5) + 'moyenne = " . $AQCM05_P_mer_moy_0 . $AQCM05_P_mer_moy_presence_0 . " hPa'" ;
			
			$text_COV_IAQ        = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'indice COV' + whiteSpacer(5) + 'moyenne = " . $AQCM05_COV_IAQ_moy_0 . $AQCM05_COV_IAQ_moy_presence_0 . " /500'" ;
			
			$text_COV_IAQq        = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'température' + whiteSpacer(5) + 'moyenne = " . $AQCM05_COV_IAQq_moy_0 . $AQCM05_COV_IAQq_moy_presence_0 . " /3'" ;
			
			$text_PM25        = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'PM2.5' + whiteSpacer(5) + 'moyenne = " . $AQCM05_PM25_moy_0 . $AQCM05_PM25_moy_presence_0 . " μg/m3'" ;
			
			$text_PM10        = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'PM10' + whiteSpacer(5) + 'moyenne = " . $AQCM05_PM10_moy_0 . $AQCM05_PM10_moy_presence_0 . " μg/m3'" ;
			
			$text_HCHO        = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'formaldéhyde' + whiteSpacer(5) + 'moyenne = " . $AQCM05_HCHO_moy_0 . $AQCM05_HCHO_moy_presence_0 . " μg/m3'" ;
			
			$text_LUX        = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'luminosité' + whiteSpacer(5) + 'moyenne = " . $AQCM05_LUX_moy_0 . $AQCM05_LUX_moy_presence_0 . " lux'" ;
			
			$text_SPL        = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'niveau sonore' + whiteSpacer(5) + 'moyenne = " . $AQCM05_SPL_moy_0 . $AQCM05_SPL_moy_presence_0 . " dBA'" ;
			
			$text_NOX_IAQ        = "text: '" . $aqcm_NAME . "' + '@' + '" . $p_aqcm_SITE_ID . "' + whiteSpacer(5) + 'indice NOx' + whiteSpacer(5) + 'moyenne = " . $AQCM05_NOX_IAQ_moy_0 . $AQCM05_NOX_IAQ_moy_presence_0 . " /500'" ;

		}

		{
			$title_AQCM05_T_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" }," . $text_T ;

			$title_AQCM05_HR_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" }," . $text_HR ;

			$title_AQCM05_CO2_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true,
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" }," . $text_CO2 ;

			$title_AQCM05_CO2_IAQ_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" }," . $text_CO2_IAQ ;

			$title_AQCM05_P_mer_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" }," . $text_P_mer ;

			$title_AQCM05_COV_IAQ_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13,
				useHTML: true,
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" }," . $text_COV_IAQ ;

			$title_AQCM05_COV_IAQq_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13,
				useHTML: true,
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" }," . $text_COV_IAQq ;

			$title_AQCM05_PM25_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" }," . $text_PM25 ;

			$title_AQCM05_PM10_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" }," . $text_PM10 ;

			$title_AQCM05_HCHO_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" }," . $text_HCHO ;

			$title_AQCM05_LUX_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" }," . $text_LUX ;

			$title_AQCM05_SPL_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" }," . $text_SPL ;

			$title_AQCM05_NOX_IAQ_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13,
				useHTML: true,
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" }," . $text_NOX_IAQ ;
		}
	}
	else {

	}
	


?>

		<table border="2" align="center" cellpadding="2" cellspacing="2">
		
			<tr align="center" valign="middle" bordercolor="#666666">
				<td align="center" width="
					<?php 
						if ( $error == 0 ) {
							echo( "1024" ) ;
						} else {
							echo( "480" ); 
						}
					?>
				">
					<font size="5" color="khaki" face="Arial, Helvetica, sans-serif">
						<?php 
							if ( $scheduled_status ) {
								echo( $aqcm_NAME . "<br>" ) ;
								echo( '<font size="3" color="white" face="Arial, Helvetica, sans-serif">' ) ;
								echo( '(bilans biquotidiens calculés en fonction des présences déclarées et/ou détectées)' ); 
								echo( '</font>' ) ;
							} else {
								echo( "sonde : " ) ;
								echo( $aqcm_NAME );
								echo( "&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;" ) ;
								
								if ( $Nb_mesures_presence[0] > 2 ){
									echo('<font size="3" color="Lime" face="Arial, Helvetica, sans-serif">');
								} else {
									echo('<font size="3" color="Salmon" face="Arial, Helvetica, sans-serif">');
								}
								echo( $jour_start_string ) ;
								echo('</font>');
								
							}
						?>
					</font>
				</td>
			</tr>


			<?php

				if ( $error == 0 ) {
					
					include("./V2_graphique_communs.js");
					
					if ( $aqcm_MESURES[2] == "Y" ) {
						echo('<tr><td><div id="container_CO2">    </div></td></tr>');
						include("./V2_graphique_CO2.js");
					}
					if ( $aqcm_MESURES[8] == "Y" ) {
						echo('<tr><td><div id="container_SPL"></div></td></tr>');
						include("./V2_graphique_SPL.js");
					}
					if ( ( $aqcm_MESURES[2] == "Y" ) AND ( !$scheduled_status ) ) {
						echo('<tr><td><div id="container_CO2_IAQ"></div></td></tr>');
						include("./V2_graphique_CO2_IAQ.js");
					}
					if ( $aqcm_MESURES[0] == "Y" ) {
						echo('<tr><td><div id="container_T"></div></td></tr>');
						include("./V2_graphique_T.js"); 
					}
					if ( $aqcm_MESURES[1] == "Y" ) {
						echo('<tr><td><div id="container_HR"></div></td></tr>');
						include("./V2_graphique_HR.js");
					}
					if ( $aqcm_MESURES[4] == "Y" ) {
						echo('<tr><td><div id="container_COV_IAQ"></div></td></tr>');
						include("./V2_graphique_COV_IAQ.js");
					}
					if ( $aqcm_MESURES[6] == "Y" ) {
						echo('<tr><td><div id="container_HCHO"></div></td></tr>');
						include("./V2_graphique_HCHO.js");
					}
					if ( $aqcm_MESURES[9] == "Y" ) {
						echo('<tr><td><div id="container_NOX_IAQ"></div></td></tr>');
						include("./V2_graphique_NOX_IAQ.js");
					}
					if ( ( $aqcm_MESURES[3] == "Y" ) AND ( !$scheduled_status ) ) {
						echo('<tr><td><div id="container_P_mer"></div></td></tr>');
						include("./V2_graphique_P_mer.js");
					}
					if ( $aqcm_MESURES[5] == "Y" ) {
						echo('<tr><td><div id="container_PM25"></div></td></tr>');
						include("./V2_graphique_PM25.js");
					}
					if ( $aqcm_MESURES[5] == "Y" ) {
						echo('<tr><td><div id="container_PM10"></div></td></tr>');
						include("./V2_graphique_PM10.js");
					}
					if ( $aqcm_MESURES[7] == "Y" ) {
						echo('<tr><td><div id="container_LUX"></div></td></tr>');
						include("./V2_graphique_LUX.js");
					}

				}
				else {
					echo('<tr><td align="center">');
					echo('<font size="4" color="red" face="Arial, Helvetica, sans-serif">');
					echo( $message_error ) ;
					echo('</font>');
					echo('</td></tr>');
				}
			
		?>

		</table>

    </body>
	
</html>

