<?php

	include("../M0/session_start.php") ;
	include("../M0/2FAS_Authenticator.php") ;

	//-----------------------------------------------------------------------------------------------------------------
	// création d'un mot de passe
	//-----------------------------------------------------------------------------------------------------------------
	$taille = 24 ;

	// Liste des caractères possibles
	$cars="abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
	$mdp='';
	$long=strlen($cars);

	srand((double)microtime()*1000000); //Initialise le générateur de nombres aléatoires

	for($i=0;$i<$taille;$i++) {
		$mdp = $mdp.substr($cars,rand(0,$long-1),1);
	}

	// résultat : $mdp
	$fas_totp_secret = Authenticator::createSecret(16);

	
	include("../M0/communs_en_tete_HTML_no_arrows.html") ;
	$back_link = "../M6_b/gestion_admins.php";
	include('../M0/communs_en_tete_home_back.html');

	$return_path = "../M6_b/gestion_admins.php" ;
	include('../M0/display_user_only.php'); 

?>

<form name="form2" method="post" action="./create_one_user_target_execute.php">
<table align="center" width="<?php echo $tables_width ; ?>"  border="2" cellspacing="2" cellpadding="2" bordercolor="#ffffff" bgcolor="#000033">	

	<tr align="center">
		<td colspan="2">
		
			<table width="98%">
			
				<tr align="center">
					<td>
						<div style="margin-top:10px;margin-bottom:10px;">
						<label 
							class="label_titres_menus" 
							style="font-size:21px;"
						>
							<u>- création d'un nouvel administrateur -</u>
						</label>
						</div>
					</td>
				</tr>
			</table>
			
			<table width="90%" align="center" >
				<tr valign="middle" bordercolor="#666666"> 
					<td>
						<p align="justify" style="margin-top:1px;margin-bottom:-30px;"><font color="orange" >
						L'identifiant doit être l'adresse mail valide de l'administrateur à créer. Une fois connecté, ce nouvel administrateur pourra
						personnaliser son mot de passe.
						</font></p>
					</td>
				</tr>
			</table>
	
			<table width="98%" align="center">
			
					<tr>
						<td align="right">
							<label>
								identifiant :&nbsp;
							</label>
						</td>
						<td align="left" colspan="2" >
							<input id="USER_ID" name="USER_ID" type="text" value="" maxlength="64" size="30" class="txtField_A" >
						</td>
					</tr>

					<tr>
						<td width="120px" align="right">
							<label>
								mot de passe :&nbsp;
							</label>
						</td>
						<td width="265px" align="left">
							<input 
								type="text" 
								name="USER_PW" 
								id="USER_PW" 
								value=<?php echo($mdp); ?>
								placeholder="nouveau_mot_de_passe" 
								class="txtField_A" 
								style="width:260px;color:#000000;backgroundcolor:#ffffff;font-family:Arial;" 
							/>
						</td>
						<td align="left">
							<label class="container"  for="check_box_1" >
								<input type="checkbox" checked id="check_box_1" name="check_box_1" onclick="myFunction()" >
								<img class="img-unchecked"  src="../styles/close_eye_small.png" width="30px">
								<img class="img-checked"    src="../styles/open_eye_small.png"   width="30px">
							</label>						
						</td>
					</tr>
					
					<tr>
						<td align="right">
							<label>
								niveau :&nbsp;
							</label>
						</td>
						<td align="left" colspan="2" >
							<input
								type="number"
								id="USER_LEVEL" 
								name="USER_LEVEL" 
								value="90" 
								min="90" 
								max="127" 
								class="txtField_M1" 
								inputMode="numeric" //Opens numeric keyboard on mobile
								style="
									width:150px;
									color:black;
									background-color:white;
								" 

								onInput="myFunction_2()"

							/>

							<label>
								&nbsp;&nbsp;&nbsp;90...127
							</label>

						</td>
					</tr>

					<tr>
						<td align="right">
							<label>
								Tmax :&nbsp;
							</label>
						</td>
						<td align="left" colspan="2">
							<input
							  class="txtField_A"
							  type="date"
							  id="start"
							  name="USER_T_MAX"
							  id="USER_T_MAX"
							  style="width:150px;"
							  value="2025-01-01"
							  min="2020-01-01"
							  max="2100-12-31" 
							  required />

						</td>
					</tr>

					<tr>
						<td align="right">
							<label>
								2FA phone :&nbsp;
							</label>
						</td>
						<td align="left" colspan="2">
							<input
							  class="txtField_A"
							  type="tel"
							  name="USER_2FA_PHONE"
							  id="USER_2FA_PHONE"
							  style="width:150px;"
							  name="USER_2FA_PHONE"
							  id="USER_2FA_PHONE"
							  value="+33123456789" 
							  pattern="\+33|0)[1-9]\d{9}"
							  required 
							 />
						</td>
	
					</tr>

					<tr>
						<td align="right">
							<label for="USER_2FA_STATUS"  class="txtField_C" >
								2FA SMS :
							</label>
						</td>
						<td align="left" colspan="2">
							<input id="USER_2FA_STATUS" name="USER_2FA_STATUS" type="checkbox"  >
						</td>
	
					</tr>

				<tr>
						<td align="right">
							<label>
								2FAS secret :&nbsp;
							</label>
						</td>
						<td align="left" colspan="2">
							<input 
								id="USER_2FAS_SECRET" 
								name="USER_2FAS_SECRET" 
								type="text" 
								value=<?php echo($fas_totp_secret); ?> 
								maxlength="32" 
								size="30" 
								class="txtField_A"  
								style="width:260px;" 
							/>
						</td>
					</tr>
				
				</br>
				
				<tr>
						<td align="right">
							<label for="USER_2FAS_STATUS"  class="txtField_C" >
								2FAS TOTP :&nbsp;
							</label>
						</td>
						<td align="left" colspan="2">
							<input id="USER_2FAS_STATUS" name="USER_2FAS_STATUS" type="checkbox"  >
						</td>
					</tr>
				
				</br>
				
				<tr>
					<td align="center" colspan="3">
						</br>
						<input type="submit" value="créer ce nouvel administrateur" class="button_A" >
						</br></br>
					</td>
				</tr>
				
			</table>
			
		</td>
	</tr>
	
</table>
</form>

<script>

	function myFunction() {
		
	  var check_1 = document.getElementById("check_box_1");
	  
	  var x = document.getElementById("USER_PW");

	  if (check_1.checked == true) {
		x.style.fontFamily = "Arial";
	  } else {
		x.style.fontFamily = "password";
	  }

	}
	
</script>


<script>
function myFunction_2() {
	var target = document.getElementById("USER_LEVEL");

	if (target.value.length > 3) {
		target.value = 127;
	}
	
	if (target.value > 127) {
		target.value = 127;
		target.style.color = "#000000";
		target.style.backgroundColor = "#ffffff";
	}
	else if (target.value < 90) {
		target.style.color = "#000000";
		target.style.backgroundColor = "salmon";
	}
	else {
		target.style.color = "#000000";
		target.style.backgroundColor = "#ffffff";
	}
}
</script>

 </body>
</html>