<?php
	
	// https://www.aqcm.fr/v2/M0/get_super_users.php
	
	//--------------------------------------------------------------------------------------------------------
	// initialisations
	//--------------------------------------------------------------------------------------------------------
	$NB_super_users = 0;
	$Flag_found_user = false ;
	$get_super_users_erreur = 0;

	$Flag_debug_get_super_users = true ;
	$Flag_debug_get_super_users = false ;
	
	$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
	//--------------------------------------------------------------------------------------------------------
	if ( isset($Flag_login) ) {
		if ( $Flag_login ) {
			include ("./_identifiants/sql_identification_main.php");
		}
		else {
			include ("../_identifiants/sql_identification_main.php");
		}
	}
	else {
		include ("../_identifiants/sql_identification_main.php");
	}

	$mysql_base = 'AQCM05_main' ;

	$link_AQCM05 = mysqli_connect($mysql_host, $mysql_user, $mysql_password, $mysql_base);
	
	if (!$link_AQCM05) {
		
		$link_AQCM05_OK = false ;
		$get_super_users_erreur = 1;
		
		if ( $Flag_debug_get_super_users ) {
			echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; echo '</br>';
			echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; echo '</br>';
			echo "Connexion à la base de donnée MySQL : échec!!!" ; echo '</br>';
		}

	}
	else {
		
		$link_AQCM05_OK = true ;
		
		if ( $Flag_debug_get_super_users ) {
			echo "Connexion à la base de donnée MySQL : succès..." ; echo '</br>';
		}

	}

	//--------------------------------------------------------------------------------------------------------
	// recherche des superusers
	//--------------------------------------------------------------------------------------------------------
	if ( $link_AQCM05_OK ) {

		$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 
			ORDER BY USER_ID
		";

		if ( $Flag_debug_get_super_users ) {
			echo $query . "</br>" ;
		}

		$result = mysqli_query($link_AQCM05, $query); 
		
		if ($result) {
			
			if (mysqli_num_rows($result) > 0) {	
				
				$i = 0 ;
				while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {

					$aqcm_SUPER_USER_ID[$i]				= $row["USER_ID"];
					$aqcm_SUPER_USER_PW[$i]				= $row["USER_PW"];
					$aqcm_SUPER_USER_STATUS[$i]			= $row["USER_STATUS"];
					$aqcm_SUPER_USER_LEVEL[$i]			= $row["USER_LEVEL"];
					$aqcm_SUPER_USER_T_MAX[$i]			= $row["USER_T_MAX"];
					$aqcm_SUPER_USER_2FA_STATUS[$i]	= $row["USER_2FA_STATUS"];
					$aqcm_SUPER_USER_2FA_PHONE[$i]		= $row["USER_2FA_PHONE"];
					$aqcm_SUPER_USER_2FAS_STATUS[$i]	= $row["USER_2FAS_STATUS"];
					$aqcm_SUPER_USER_2FAS_SECRET[$i]	= $row["USER_2FAS_SECRET"];
					
					$int_aqcm_SUPER_USER_T_MAX[$i]		= intval($row["USER_T_MAX"]);

					if ( $Flag_debug_get_super_users ) {
						echo("i=" . $i . " ; " . $aqcm_SUPER_USER_ID[$i] . " ; " . $aqcm_SUPER_USER_PW[$i] . " ; " .
						$aqcm_SUPER_USER_STATUS[$i] . " ; " . $aqcm_SUPER_USER_LEVEL[$i] . " ; " . $aqcm_SUPER_USER_T_MAX[$i] . 
						$aqcm_SUPER_USER_2FA_STATUS[$i] . " ; " . $aqcm_SUPER_USER_2FA_PHONE[$i] . " ; " . $aqcm_SUPER_USER_2FAS_STATUS[$i] . " ; " . $aqcm_SUPER_USER_2FAS_SECRET[$i] . "</br>" );
					}
					
					$i++ ;
				}
				
				$NB_super_users = $i;
				
			}
			else {
				$get_super_users_erreur = 2;
			}
		}
		else {
			$get_super_users_erreur = 1;
		}

	}
	
	//--------------------------------------------------------------------------------------------------------
	// clôture
	//--------------------------------------------------------------------------------------------------------
	if ( $Flag_debug_get_super_users ) {
		echo "NB_super_users = " . $NB_super_users . "</br>";
		
	}
	
	if ( $link_AQCM05_OK ) {
		mysqli_close($link_AQCM05);
	}
	
	//--------------------------------------------------------------------------------------------------------
	
?>
