<?php
	
	//--------------------------------------------------------------------------------------------------------
	// initialisation des variables
	//--------------------------------------------------------------------------------------------------------
	$Flag_debug_1 = 1;
	$Flag_debug_1 = 0;

	$code_erreur = 0;
	$NB_users   = 0 ;
	
	//--------------------------------------------------------------------------------------------------------
	// connexion à la base de données
	//--------------------------------------------------------------------------------------------------------
	$mysql_base ='AQCM05_main' ;
	$link = mysqli_connect($mysql_host,$mysql_user,$mysql_password, $mysql_base);
	
	if ( ! $link) {
		
		$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 = "
		SELECT USER_ID,USER_PW,USER_STATUS,USER_LEVEL,USER_T_MAX,USER_2FA_STATUS,USER_2FA_PHONE,USER_2FAS_STATUS,USER_2FAS_SECRET
		FROM AQCM05_SUPER_USERS 
		WHERE (1=1) 
		ORDER BY USER_ID
		";

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

	$code_erreur = 0;

	$result_configuration = mysqli_query($link, $query); 
	
	if (!$result_configuration) {
		
		$code_erreur = 11;
		
	} else {
		
		if (mysqli_num_rows($result_configuration) == 0) {	
			$code_erreur = 12;
			
		} else {
			
			$i=0;
			while ($row = mysqli_fetch_array($result_configuration, MYSQLI_BOTH)) {

				$aqcm_one_site_USER_ID[$i]					= $row["USER_ID"] ;
				$aqcm_one_site_USER_PW[$i]					= $row["USER_PW"] ;
				$aqcm_one_site_USER_STATUS	[$i]			= $row["USER_STATUS"] ;
				$aqcm_one_site_USER_LEVEL[$i]				= $row["USER_LEVEL"] ;
				$aqcm_one_site_USER_T_MAX[$i]				= $row["USER_T_MAX"] ;
				$aqcm_one_site_USER_2FA_STATUS[$i]			= $row["USER_2FA_STATUS"] ;
				$aqcm_one_site_USER_2FA_PHONE[$i]			= $row["USER_2FA_PHONE"] ;
				$aqcm_one_site_USER_2FAS_STATUS[$i]		= $row["USER_2FAS_STATUS"] ;
				$aqcm_one_site_USER_2FAS_SECRET[$i]		= $row["USER_2FAS_SECRET"] ;

				if ($Flag_debug_1 == 1) {
					echo "i = " . $i . " ; " . $aqcm_one_site_USER_ID[$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);

?>
