<?php
	
	// http://192.168.1.230/get_AQCM05_users.php
	
	$code_erreur = 0;
	$NB_users    = 0 ;
	
	$marqueur_temps_maintenant = time();
	$marqueur_temps_maintenant = mktime(0, 0, 0, date("m", $marqueur_temps_maintenant)  , date("d", $marqueur_temps_maintenant) + 1, date("Y", $marqueur_temps_maintenant) );

	//--------------------------------------------------------------------------------------------------------
	// connexion à la base de données
	//--------------------------------------------------------------------------------------------------------
	include ("../_identifiants/sql_identification_sans_base.php");

	$link_AQCM05 = mysqli_connect($mysql_host,$mysql_user,$mysql_password, $mysql_base);
	
	if (!$link_AQCM05) {
		$code_erreur = 100;
		
		if ($Flag_debug_1 == 1) {
			echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; echo '</br>';
			echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; echo '</br>';
		}

		echo "Connexion impossible à la base de donnée MySQL !" . PHP_EOL; echo '</br>';
		exit($code_erreur);
	}

	//--------------------------------------------------------------------------------------------------------
	// recherche des sondes du site demandé
	//--------------------------------------------------------------------------------------------------------

	$query_users = "SELECT SITE_ID,USER_ID,USER_PW,USER_LEVEL,LIMIT_TIMESTAMP FROM AQCM05_SITES ORDER BY SITE_ID";

	if ($Flag_debug_1 == 1) {
		echo $query_users . "</br>" ;
	}

	$code_erreur = 0;

	$result_users = mysqli_query($link_AQCM05, $query_users); 
	
	if (!$result_users) {
		$code_erreur = 11;
	} 
	else {
		
		if (mysqli_num_rows($result_users) == 0) {	

			$code_erreur = 12;
			
		} 
		else {
			
			$i=0;
			while ($row = mysqli_fetch_array($result_users, MYSQLI_BOTH)) {

				$aqcm_SITES_ID[$i]		  = $row["SITE_ID"];
				$aqcm_USER_ID[$i]		  = $row["USER_ID"];
				$aqcm_USER_PW[$i]	      = $row["USER_PW"];
				$aqcm_USER_LEVEL[$i]      = $row["USER_LEVEL"];
				$aqcm_LIMIT_TIMESTAMP[$i] = $row["LIMIT_TIMESTAMP"];
				
				if ($Flag_debug_1 == 1) {
					echo("i=" . $i . " ; " . $aqcm_USER_ID[$i] . " ; " . $aqcm_USER_PW[$i] . " ; " . $aqcm_SITES_ID[$i] . " ; " . $aqcm_USER_LEVEL[$i] . " ; " . $aqcm_LIMIT_TIMESTAMP[$i] . "</br>" );
				}
				
				$i++ ;
			}
			
			$NB_users = $i;
			
			if ($Flag_debug_1 == 1) {
				echo "NB_users = " . $NB_users . "</br>";
				
			}
		}
	}

	if ($Flag_debug_1 == 1) {
		if ( $code_erreur != 0 ) {
			echo "code erreur = " . strval($code_erreur) . "</br>";
		}
	}

	mysqli_close($link_AQCM05);

?>
