<?php
					   
	//-------------------------------------------------------------------------
	date_default_timezone_set('Europe/Paris');

	//-------------------------------------------------------------------------
	include ("../_identifiants/sql_identification_sans_base.php");
	$mysql_base ='AQCM05_SITE_' . $p_aqcm_SITE_ID ;

	include ("./graphiques_one_site_execute_2.php");

	//-------------------------------------------------------------------------
	$Titre_page = "AQCM05";

	$couleur_courbes = ["Green","Red","Navy","DarkGoldenRod","Green","Navy","Purple"];
	$NB_couleurs = sizeof($couleur_courbes) ;

	$HC_lineWidth    = "1";
	
	$legend_status = "true" ;
	$legend_margin_right = "80" ;
	
	$X_offset_for_titles	= 160;		

	//-------------------------------------------------------------------------
	$query = [];
	$errors = [];
	$Flag_SONDE_OK = [];
	$mysql_table_mesures = [];
	$nom_sonde = [];
	$mesures_sonde = [];
	$mesures_chaines_splitted = [];
	//-------------------------------------------------------------------------
	$errors      		= array();	
	$T_value      	= array();	
	$HR_value     	= array();
	$CO2_value    	= array();	
	$CO2_IAQ_value   = array();	
	$P_mer_value   	= array();
	$COV_IAQ_value   = array();
	$PM25_value   	= array();
	$PM10_value     	= array();
	$HCHO_value   	= array();
	$LUX_value   		= array();
	$SPL_value   		= array();
	$SPL_peak_value	= array();
	$NOX_IAQ_value  	= array();	
	
	//--------------------------------------------------------------------------------------------------------
	// traitement de la période de temps demandée
	//--------------------------------------------------------------------------------------------------------
	{
		switch ($p_echelle_temps) {
			case '1 jour' :
				$delta_timestamp = 1;
				$periode = "10_MN";
				break;
			case '2 jours' :
				$delta_timestamp = 2;
				$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' :
				$delta_timestamp = 31;
				$periode = "HEURE";
				break;
			case '2 mois' :
				$delta_timestamp = 2*31;
				$periode = "HEURE";
				break;
			case '3 mois' :
				$delta_timestamp = 2*31+30;
				$periode = "HEURE";
				break;
			case '6 mois' :
				$delta_timestamp = 3*30 + 3*31;
				$periode = "JOUR";
				break;
			case '1 an' :
				$delta_timestamp = 365;
				$periode = "JOUR";
				break; 
			default : {
				$delta_timestamp = 7;
				$periode = "10_MN";
			}
		}
		
		$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));
		
		$texte_start = $p_jour . "/" . $p_mois . "/" . $p_annee ;
	
	}
	
	if ( $NB_sondes > 0 ) {
		
		//----------------------------------------------------------------------------------------------------
		// préparation des tableaux de mesures
		//----------------------------------------------------------------------------------------------------
		
		$mesures_names = ["T","HR","CO2","CO2_IAQ","P_mer","COV_IAQ","PM25","PM10","HCHO","LUX","SPL","NOX_IAQ"];

		$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++ ) {
			
			$errors[$index_sonde] = 1 ;
			$Flag_SONDE_OK[$index_sonde] = False;
			
			$mysql_table_mesures[$index_sonde] = $aqcm_MAC[$index_sonde] . "_mesures" ;
			$nom_sonde[$index_sonde] 		   = $aqcm_NAME[$index_sonde] ;
			$mesures_sonde[$index_sonde] 	   = $aqcm_MESURES[$index_sonde] ;

			if ($Flag_debug == 1) {
				echo "</br>";
				echo "i = " . $index_sonde . " ; " . $mysql_table_mesures[$index_sonde] . " ; " . $nom_sonde[$index_sonde] . " ; " . $mesures_sonde[$index_sonde] . "</br>";
			}
		
			$link_mesures = mysqli_connect($mysql_host,$mysql_user,$mysql_password, $mysql_base);
			
			if ( ! $link_mesures ) {
				$errors[$index_sonde] = 0;
				$message_erreur = "Connexion impossible à la base de donnée MySQL !" ;
				echo "Connexion impossible à la base de donnée MySQL !" . PHP_EOL; echo '</br>';
				if ($Flag_debug == 1) {
					echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; echo '</br>';
					echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; echo '</br>';
				}
			} 
			else {

				$query[$index_sonde] = "SELECT temps," . $chaine_requete . " FROM " . $mysql_table_mesures[$index_sonde] . " WHERE ( (periode = '$periode') AND (temps >= $start) AND  (temps <= $stop) ) ORDER BY temps";
				
				if ($Flag_debug == 1) {
					echo($query[$index_sonde] . "</br>");
				}
			
				$result_mesures = mysqli_query($link_mesures, $query[$index_sonde]) ;
				
				if (!$result_mesures) {
					
					$errors[$index_sonde] = 0;
					mysqli_close($link_mesures);
					
				} 
				else {
					
					if (mysqli_num_rows($result_mesures) == 0) {
						
						$errors[$index_sonde] = 0;
						mysqli_close($link_mesures);
						
					} 
					else {
						
						$i=0;
						
						while ($row = mysqli_fetch_array($result_mesures, MYSQLI_BOTH)) {

							$temps  = $row["temps"];
							
							$temps *= 1000;
							
							//---------------------------------------------------------
							for ($j = 0; $j < sizeof($mesures_names); $j++) {
								$mesures_chaines_splitted[$index_sonde][$j] = explode("|", $row[$mesures_names[$j]]);
							}
							
							//---------------------------------------------------------
							$mesure_T		 = isset( $mesures_chaines_splitted[$index_sonde][ 0][1] ) ? $mesures_chaines_splitted[$index_sonde][ 0][1] : "0.0";
							$mesure_HR		 = isset( $mesures_chaines_splitted[$index_sonde][ 1][1] ) ? $mesures_chaines_splitted[$index_sonde][ 1][1] : "0.0";
							$mesure_CO2		 = isset( $mesures_chaines_splitted[$index_sonde][ 2][1] ) ? $mesures_chaines_splitted[$index_sonde][ 2][1] : "400";
							$mesure_CO2_IAQ	 = isset( $mesures_chaines_splitted[$index_sonde][ 3][1] ) ? $mesures_chaines_splitted[$index_sonde][ 3][1] : "0.0";
							$mesure_P_mer	 = isset( $mesures_chaines_splitted[$index_sonde][ 4][1] ) ? $mesures_chaines_splitted[$index_sonde][ 4][1] : "1013.25";
							$mesure_COV_IAQ	 = isset( $mesures_chaines_splitted[$index_sonde][ 5][1] ) ? $mesures_chaines_splitted[$index_sonde][ 5][1] : "0.0";
							$mesure_PM25	 = isset( $mesures_chaines_splitted[$index_sonde][ 6][1] ) ? $mesures_chaines_splitted[$index_sonde][ 6][1] : "0.0";
							$mesure_PM10	 = isset( $mesures_chaines_splitted[$index_sonde][ 7][1] ) ? $mesures_chaines_splitted[$index_sonde][ 7][1] : "0.0";
							$mesure_HCHO	 = isset( $mesures_chaines_splitted[$index_sonde][ 8][1] ) ? $mesures_chaines_splitted[$index_sonde][ 8][1] : "0.0";
							$mesure_LUX		 = isset( $mesures_chaines_splitted[$index_sonde][ 9][1] ) ? $mesures_chaines_splitted[$index_sonde][ 9][1] : "0.0";
							$mesure_SPL		 = isset( $mesures_chaines_splitted[$index_sonde][10][1] ) ? $mesures_chaines_splitted[$index_sonde][10][1] : "0.0";
							$mesure_NOX_IAQ	 = isset( $mesures_chaines_splitted[$index_sonde][11][1] ) ? $mesures_chaines_splitted[$index_sonde][11][1] : "0.00";
							$mesure_SPL_peak = isset( $mesures_chaines_splitted[$index_sonde][10][2] ) ? $mesures_chaines_splitted[$index_sonde][10][2] : "0.0";

							$Value_T        = strval(floatval( $mesure_T )) ;
							$Value_HR       = strval(floatval( $mesure_HR )) ;
							$Value_CO2      = strval(floatval( $mesure_CO2 )) ;
							$Value_CO2_IAQ  = strval(floatval( $mesure_CO2_IAQ )) ;
							$Value_P_mer    = strval(floatval( $mesure_P_mer )) ;
							$Value_COV_IAQ  = strval(floatval( $mesure_COV_IAQ )) ;
							$Value_PM25     = strval(floatval( $mesure_PM25 )) ;
							$Value_PM10     = strval(floatval( $mesure_PM10 )) ;
							$Value_HCHO     = strval(floatval( $mesure_HCHO )) ;
							$Value_LUX      = strval(floatval( $mesure_LUX )) ;
							$Value_SPL      = strval(floatval( $mesure_SPL )) ;
							$Value_SPL_peak = strval(floatval( $mesure_SPL_peak )) ;
							$Value_NOX_IAQ  = strval(floatval( $mesure_NOX_IAQ )) ;
					
							$data_AQCM05[$index_sonde][ 0][$i]  = "[$temps, $Value_T]";
							$data_AQCM05[$index_sonde][ 1][$i]  = "[$temps, $Value_HR]";
							$data_AQCM05[$index_sonde][ 2][$i]  = "[$temps, $Value_CO2]";
							$data_AQCM05[$index_sonde][ 3][$i]  = "[$temps, $Value_CO2_IAQ]";
							$data_AQCM05[$index_sonde][ 4][$i]  = "[$temps, $Value_P_mer]";
							$data_AQCM05[$index_sonde][ 5][$i]  = "[$temps, $Value_COV_IAQ]";
							$data_AQCM05[$index_sonde][ 6][$i]  = "[$temps, $Value_PM25]";
							$data_AQCM05[$index_sonde][ 7][$i]  = "[$temps, $Value_PM10]";
							$data_AQCM05[$index_sonde][ 8][$i]  = "[$temps, $Value_HCHO]";
							$data_AQCM05[$index_sonde][ 9][$i]  = "[$temps, $Value_LUX]";
							$data_AQCM05[$index_sonde][10][$i]  = "[$temps, $Value_SPL]";
							$data_AQCM05[$index_sonde][11][$i]  = "[$temps, $Value_SPL_peak]";
							$data_AQCM05[$index_sonde][12][$i]  = "[$temps, $Value_NOX_IAQ]";

							$T_value[$index_sonde][$i]        = $Value_T;
							$HR_value[$index_sonde][$i]       = $Value_HR;
							$CO2_value[$index_sonde][$i]      = $Value_CO2;
							$CO2_IAQ_value[$index_sonde][$i]  = $Value_CO2_IAQ;
							$P_mer_value[$index_sonde][$i]    = $Value_P_mer;
							$COV_IAQ_value[$index_sonde][$i]  = $Value_COV_IAQ;
							$PM25_value[$index_sonde][$i]     = $Value_PM25;
							$PM10_value[$index_sonde][$i]     = $Value_PM10;
							$HCHO_value[$index_sonde][$i]     = $Value_HCHO;
							$LUX_value[$index_sonde][$i]      = $Value_LUX;
							$SPL_value[$index_sonde][$i]      = $Value_SPL;
							$SPL_peak_value[$index_sonde][$i] = $Value_SPL_peak;
							$NOX_IAQ_value[$index_sonde][$i]  = $Value_NOX_IAQ;

							//---------------------------------------------------------
							if ($Flag_debug == 1) {
								echo $data_AQCM05[$index_sonde][12][$i] ;
								echo "<br>";
							}
							
							//---------------------------------------------------------
							$i++ ;
							
							//---------------------------------------------------------
							
						}
						
						//---------------------------------------------------------
						if ($Flag_debug == 1) {
							echo("index_sonde = " . $index_sonde . " ; i = " . $i . "</br>");
						}
			
						//---------------------------------------------------------
						// calcul des min,moy,max
						//---------------------------------------------------------

						//--------------------------------------------------------------------------------------------
						// T
						//--------------------------------------------------------------------------------------------
						$T_moy[$index_sonde]    = round((array_sum($T_value[$index_sonde]))/$i,1); 
						$HC_T_min_0             = min($T_value[$index_sonde]);
						$HC_T_min[$index_sonde] = 5 * intval( 0 + ( floor( floatval($HC_T_min_0) )) / 5.0 );
						$HC_T_max_0             = max($T_value[$index_sonde]);
						$HC_T_max[$index_sonde] = 5 * intval( 1 + ( ceil( floatval($HC_T_max_0) )) / 5.0 );
						
						//--------------------------------------------------------------------------------------------
						// HR
						//--------------------------------------------------------------------------------------------
						$HR_moy[$index_sonde]   = round((array_sum($HR_value[$index_sonde]))/$i,0); 
						
						//--------------------------------------------------------------------------------------------
						// CO2
						//--------------------------------------------------------------------------------------------
						$CO2_moy[$index_sonde]  = round((array_sum($CO2_value[$index_sonde]))/$i,0); 
						
						$CO2_max_value[$index_sonde] = max($CO2_value[$index_sonde]);
						if ( $CO2_max_value[$index_sonde] <=  1000.0 ) { $CO2_maxi[$index_sonde] =   1000 ; }
						if ( $CO2_max_value[$index_sonde] >   1000.0 ) { $CO2_maxi[$index_sonde] =   2000 ; }
						if ( $CO2_max_value[$index_sonde] >   2000.0 ) { $CO2_maxi[$index_sonde] =   3000 ; }
						if ( $CO2_max_value[$index_sonde] >   3000.0 ) { $CO2_maxi[$index_sonde] =   4000 ; }
						if ( $CO2_max_value[$index_sonde] >   4000.0 ) { $CO2_maxi[$index_sonde] =   5000 ; }
						if ( $CO2_max_value[$index_sonde] >   5000.0 ) { $CO2_maxi[$index_sonde] =  10000 ; }

						//--------------------------------------------------------------------------------------------
						// CO2_IAQ
						//--------------------------------------------------------------------------------------------
						$CO2_IAQ_moy[$index_sonde]    = round((array_sum($CO2_IAQ_value[$index_sonde]))/$i,0); 

						//--------------------------------------------------------------------------------------------
						// P_mer
						//--------------------------------------------------------------------------------------------
						$P_mer_moy[$index_sonde]  = round((array_sum($P_mer_value[$index_sonde]))/$i,0);
						
						$P_mer_min_0              = min($P_mer_value[$index_sonde]);
						$P_mer_mini[$index_sonde] = 1 * intval( -1 + ( floor( floatval($P_mer_min_0) )) / 1.0 );
						
						$P_mer_max_0 = max($P_mer_value[$index_sonde]);
						$P_mer_maxi[$index_sonde] = 1 * intval( +1 + ( ceil( floatval($P_mer_max_0) )) / 1.0 );
						
						$P_mer_Tick_intervalle = 1 ;

						//--------------------------------------------------------------------------------------------
						// COV_IAQ
						//--------------------------------------------------------------------------------------------
						$COV_IAQ_moy[$index_sonde]  = round((array_sum($COV_IAQ_value[$index_sonde]))/$i,0); 
						
						$COV_IAQ_max_0              = max($COV_IAQ_value[$index_sonde]);
						$COV_IAQ_maxi[$index_sonde] = 100 * intval( 1 + ( ceil( floatval($COV_IAQ_max_0) )) / 100.0 );

						//--------------------------------------------------------------------------------------------
						// PM25
						//--------------------------------------------------------------------------------------------
						$PM25_moy[$index_sonde]  = round((array_sum($PM25_value[$index_sonde]))/$i,0);
						
						$PM25_max_value[$index_sonde] = max($PM25_value[$index_sonde]);
						if ( $PM25_max_value[$index_sonde] <=  10.0 ) { $PM25_maxi[$index_sonde] =   10 ; }
						if ( $PM25_max_value[$index_sonde] >   10.0 ) { $PM25_maxi[$index_sonde] =   20 ; }
						if ( $PM25_max_value[$index_sonde] >   20.0 ) { $PM25_maxi[$index_sonde] =   50 ; }
						if ( $PM25_max_value[$index_sonde] >   50.0 ) { $PM25_maxi[$index_sonde] =  100 ; }
						if ( $PM25_max_value[$index_sonde] >  100.0 ) { $PM25_maxi[$index_sonde] =  200 ; }
						if ( $PM25_max_value[$index_sonde] >  200.0 ) { $PM25_maxi[$index_sonde] =  500 ; }
						if ( $PM25_max_value[$index_sonde] >  500.0 ) { $PM25_maxi[$index_sonde] = 1000 ; }
						if ( $PM25_max_value[$index_sonde] > 1000.0 ) { $PM25_maxi[$index_sonde] = 2000 ; }
						if ( $PM25_max_value[$index_sonde] > 2000.0 ) { $PM25_maxi[$index_sonde] = 5000 ; }

						//--------------------------------------------------------------------------------------------
						// PM10
						//--------------------------------------------------------------------------------------------
						$PM10_moy[$index_sonde]  = round((array_sum($PM10_value[$index_sonde]))/$i,0);
						
						$PM10_max_value[$index_sonde] = max($PM10_value[$index_sonde]);
						if ( $PM10_max_value[$index_sonde] <=  10.0 ) { $PM10_maxi[$index_sonde] =   10 ; }
						if ( $PM10_max_value[$index_sonde] >   10.0 ) { $PM10_maxi[$index_sonde] =   20 ; }
						if ( $PM10_max_value[$index_sonde] >   20.0 ) { $PM10_maxi[$index_sonde] =   50 ; }
						if ( $PM10_max_value[$index_sonde] >   50.0 ) { $PM10_maxi[$index_sonde] =  100 ; }
						if ( $PM10_max_value[$index_sonde] >  100.0 ) { $PM10_maxi[$index_sonde] =  200 ; }
						if ( $PM10_max_value[$index_sonde] >  200.0 ) { $PM10_maxi[$index_sonde] =  500 ; }
						if ( $PM10_max_value[$index_sonde] >  500.0 ) { $PM10_maxi[$index_sonde] = 1000 ; }
						if ( $PM10_max_value[$index_sonde] > 1000.0 ) { $PM10_maxi[$index_sonde] = 2000 ; }
						if ( $PM10_max_value[$index_sonde] > 2000.0 ) { $PM10_maxi[$index_sonde] = 5000 ; }

						//--------------------------------------------------------------------------------------------
						//HCHO
						//--------------------------------------------------------------------------------------------
						$HCHO_moy[$index_sonde]  = round((array_sum($HCHO_value[$index_sonde]))/$i,0);
						
						$HCHO_max_value[$index_sonde] = max($HCHO_value[$index_sonde]);
						if ( $HCHO_max_value[$index_sonde] <=  10.0 ) { $HCHO_maxi[$index_sonde] =   10 ; }
						if ( $HCHO_max_value[$index_sonde] >   10.0 ) { $HCHO_maxi[$index_sonde] =   20 ; }
						if ( $HCHO_max_value[$index_sonde] >   20.0 ) { $HCHO_maxi[$index_sonde] =   50 ; }
						if ( $HCHO_max_value[$index_sonde] >   50.0 ) { $HCHO_maxi[$index_sonde] =  100 ; }
						if ( $HCHO_max_value[$index_sonde] >  100.0 ) { $HCHO_maxi[$index_sonde] =  200 ; }
						if ( $HCHO_max_value[$index_sonde] >  200.0 ) { $HCHO_maxi[$index_sonde] =  500 ; }
						if ( $HCHO_max_value[$index_sonde] >  500.0 ) { $HCHO_maxi[$index_sonde] = 1000 ; }
						if ( $HCHO_max_value[$index_sonde] > 1000.0 ) { $HCHO_maxi[$index_sonde] = 2000 ; }
						if ( $HCHO_max_value[$index_sonde] > 2000.0 ) { $HCHO_maxi[$index_sonde] = 5000 ; }

						//--------------------------------------------------------------------------------------------
						//LUX
						//--------------------------------------------------------------------------------------------
						$LUX_moy[$index_sonde] = round((array_sum($LUX_value[$index_sonde]))/$i,0);
						
						$LUX_max_value[$index_sonde] = max($LUX_value[$index_sonde]);
						if ( $LUX_max_value[$index_sonde] <=  100.0 ) { $LUX_maxi[$index_sonde] =   100 ; }
						if ( $LUX_max_value[$index_sonde] >   100.0 ) { $LUX_maxi[$index_sonde] =   200 ; }
						if ( $LUX_max_value[$index_sonde] >   200.0 ) { $LUX_maxi[$index_sonde] =   500 ; }
						if ( $LUX_max_value[$index_sonde] >   500.0 ) { $LUX_maxi[$index_sonde] =  1000 ; }
						if ( $LUX_max_value[$index_sonde] >  1000.0 ) { $LUX_maxi[$index_sonde] =  2000 ; }
						if ( $LUX_max_value[$index_sonde] >  2000.0 ) { $LUX_maxi[$index_sonde] =  5000 ; }
						if ( $LUX_max_value[$index_sonde] >  5000.0 ) { $LUX_maxi[$index_sonde] = 10000 ; }
						if ( $LUX_max_value[$index_sonde] > 10000.0 ) { $LUX_maxi[$index_sonde] = 20000 ; }
						if ( $LUX_max_value[$index_sonde] > 20000.0 ) { $LUX_maxi[$index_sonde] = 50000 ; }

						//--------------------------------------------------------------------------------------------
						// SPL
						//--------------------------------------------------------------------------------------------
						$SPL_moy[$index_sonde]  = round((array_sum($SPL_value[$index_sonde]))/$i,0); 
						
						$SPL_max_0              = max($SPL_value[$index_sonde]);
						$SPL_maxi[$index_sonde] = 10 * intval( 1 + ( ceil( floatval($SPL_max_0) )) / 10.0 );

						$SPL_peak_moy[$index_sonde]  = round((array_sum($SPL_peak_value[$index_sonde]))/$i,0); 
						
						$SPL_peak_max_0              = max($SPL_peak_value[$index_sonde]);
						$SPL_peak_maxi[$index_sonde] = 10 * intval( 1 + ( ceil( floatval($SPL_peak_max_0) )) / 10.0 );

						//--------------------------------------------------------------------------------------------
						// NOX_IAQ
						//--------------------------------------------------------------------------------------------
						$NOX_IAQ_moy[$index_sonde]  = round((array_sum($NOX_IAQ_value[$index_sonde]))/$i,0); 
						
						$NOX_IAQ_max_value[$index_sonde] = max($NOX_IAQ_value[$index_sonde]);
						if ( $NOX_IAQ_max_value[$index_sonde] <=  50.0 ) { $NOX_IAQ_maxi[$index_sonde] =   50 ; }
						if ( $NOX_IAQ_max_value[$index_sonde] >   50.0 ) { $NOX_IAQ_maxi[$index_sonde] =  100 ; }
						if ( $NOX_IAQ_max_value[$index_sonde] >  100.0 ) { $NOX_IAQ_maxi[$index_sonde] =  200 ; }
						if ( $NOX_IAQ_max_value[$index_sonde] >  200.0 ) { $NOX_IAQ_maxi[$index_sonde] =  500 ; }

						//--------------------------------------------------------------------------------------------
						mysqli_close($link_mesures);
						
						$Flag_SONDE_OK[$index_sonde] = True;
						
						//--------------------------------------------------------------------------------------------
					}
					
					if ($Flag_debug == 1) {
						echo("error = " . $errors[$index_sonde] . "</br>");
					}
					
				}
			}
		}

		//-------------------------------------------------------------------------------
		// calcul de $mesures_sondes_str -> affichage sélectif des graphiques
		// en fonction des capteurs installés dans les différentes sondes
		//-------------------------------------------------------------------------------
		// 0  1   2   3   4   5   6   7   8
		// T HR CO2 Pmer COV PM HCHO LUX SPL
		//-------------------------------------------------------------------------------
		$mesures_sondes_bin = 0b10000000000 ;
		$mesures_sondes_str =  "YNNNNNNNNNN" ;
		$mesures_sonde_str  = array() ;
		$mesures_sonde_bin  = array() ;
		for ( $index_sonde=0; $index_sonde < $NB_sondes; $index_sonde++ ) {
			$koko_1_str = str_replace('Y', '1', $mesures_sonde[$index_sonde]) ;
			$koko_2_str = str_replace('N', '0', $koko_1_str) ;
			$koko_3_str = '1' . $koko_2_str ;
			$koko_3_bin = intval(bindec($koko_3_str)) ;
			$mesures_sondes_bin = $mesures_sondes_bin | $koko_3_bin ;
		}
		$koko_1_str = decbin($mesures_sondes_bin) ;
		$koko_2_str = str_replace('0', 'N', $koko_1_str) ;
		$mesures_sondes_str = str_replace('1', 'Y', $koko_2_str) ;
		$mesures_sondes_str = substr($mesures_sondes_str,1,10) ;
		
		//-------------------------------------------------------------------------------
		if ( array_sum($errors) != 0 ) {
			
			$min_scale_T    = min($HC_T_min);
			$max_scale_T    = max($HC_T_max);
			
			$CO2_max			= max($CO2_maxi);
			switch ($CO2_max) {
				case 1000:
					$CO2_tickInterval = 50 ;
					break;
				case 2000:
					$CO2_tickInterval = 100 ;
					break;
				case 3000:
					$CO2_tickInterval = 100 ;
					break;
				case 4000:
					$CO2_tickInterval = 200 ;
					break;
				case 5000:
					$CO2_tickInterval = 200 ;
					break;
				case 10000:
					$CO2_tickInterval = 500 ;
					break;
				default:
					$CO2_tickInterval = 100 ;
			}			

			$P_mer_min      = min($P_mer_mini);
			$P_mer_max      = max($P_mer_maxi);
			if ( $P_mer_min < 900  ) $P_mer_min = 900 ;
			if ( $P_mer_max > 1100 ) $P_mer_max = 1100 ;
		
			$COV_IAQ_max       = max($COV_IAQ_maxi);
			
			$PM25_max          = max($PM25_maxi);
			$PM25_tickInterval = $PM25_max / 10 ;
			
			$PM10_max          = max($PM10_maxi);
			$PM10_tickInterval = $PM10_max / 10 ;
			
			$HCHO_max          = max($HCHO_maxi);
			$HCHO_tickInterval = $HCHO_max / 10 ;
			
			$LUX_max           = max($LUX_maxi);
			$LUX_tickInterval  = $LUX_max / 10 ;
			
			$SPL_max           = max($SPL_maxi);
			$SPL_tickInterval  = 10 ;
			
			$SPL_peak_max          = max($SPL_peak_maxi);
			$SPL_peak_tickInterval = 10 ;
			
			$NOX_IAQ_max			= max($NOX_IAQ_maxi);
			$NOX_IAQ_tickInterval	= $NOX_IAQ_max / 10 ;
			
			//--------------------------------------------------------------------
			// préparation des titres des graphes
			//--------------------------------------------------------------------
			$title_T_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" },
				text: '| $p_aqcm_SITE_ID | températures | début : $texte_start | durée : $p_echelle_temps |' "
				;

			$title_HR_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" },
				text: '| $p_aqcm_SITE_ID | humidité relative | début : $texte_start | durée : $p_echelle_temps |' "
				;

			$title_CO2_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" },
				text: '| $p_aqcm_SITE_ID | taux de CO2 | début : $texte_start | durée : $p_echelle_temps |' "
				;

			$title_CO2_IAQ_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" },
				text: '| $p_aqcm_SITE_ID | indice CO2 (/5) | début : $texte_start | durée : $p_echelle_temps |' "
				;

			$title_P_mer_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" },
				text: '| $p_aqcm_SITE_ID | P_atm | début : $texte_start | durée : $p_echelle_temps |' "
				;

			$title_COV_IAQ_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" },
				text: '| $p_aqcm_SITE_ID | indice COV (/500) | début : $texte_start | durée : $p_echelle_temps |' "
				;
				
			$title_PM25_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" },
				text: '| $p_aqcm_SITE_ID | PM2.5 | début : $texte_start | durée : $p_echelle_temps |' "
				;
				
			$title_PM10_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" },
				text: '| $p_aqcm_SITE_ID | PM10 | début : $texte_start | durée : $p_echelle_temps |' "
				;
				
			$title_HCHO_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" },
				text: '| $p_aqcm_SITE_ID | formaldéhyde | début : $texte_start | durée : $p_echelle_temps |' "
				;

			$title_LUX_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" },
				text: '| $p_aqcm_SITE_ID | luminosité | début : $texte_start | durée : $p_echelle_temps |' "
				;

			$title_SPL_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" },
				text: '| $p_aqcm_SITE_ID | SPL<sub>&nbsp;moyen</sub> | début : $texte_start | durée : $p_echelle_temps |' "
				;

			$title_SPL_peak_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" },
				text: '| $p_aqcm_SITE_ID | SPL<sub>&nbsp;crête</sub> | début : $texte_start | durée : $p_echelle_temps |' "
				;

			$title_NOX_IAQ_HighCharts = "
				x: " . $X_offset_for_titles . ",
				y: 13, 
				useHTML: true, 
				align: 'left',				
				style : { \"color\": \"#000000\", \"fontSize\": \"22px\" },
				text: '| $p_aqcm_SITE_ID | indice NOx (/500) | début : $texte_start | durée : $p_echelle_temps |' "
				;
				
			//----------------------------------------------------------------------------------------------------
			// création des graphiques
			//----------------------------------------------------------------------------------------------------
			include("./graphiques_one_site_execute_3.php");
			
		} 
		else {
			
			//----------------------------------------------------------------------------------------------------
			// aucune mesure exploitable
			//----------------------------------------------------------------------------------------------------
			include("./graphiques_one_site_execute_7.php");
			
		}

	} 
	else {
		
		//----------------------------------------------------------------------------------------------------
		// aucune sonde répertoriée
		//----------------------------------------------------------------------------------------------------
		include("./graphiques_one_site_execute_8.php");
		
	}
	
	//--------------------------------------------------------------------------------------------


?>


 
