<!doctype html>
<html lang="fr" dir="ltr">
  <head>
	<title></title>
	<script
			  src="https://code.jquery.com/jquery-3.3.1.min.js"
			  integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
			  crossorigin="anonymous"></script>
	<style>
		body {
			margin: 0;
			padding: 1ex 1em;
			font-family: verdana;
			font-size: 11px;
		}
		
		#error {
			color: crimson; 
		}
		
		#connecting {
			color: green;
		}
	</style>
  </head>
  <body>
	<h1>Connexion en mode maintenance</h1>
	<div id="error" style="<?php if (empty($errorMsg)) echo "display: none;"; ?>">
		<h2>Une erreur de connexion s'est produite : </h2>
		<p id="errorMsg"><?php echo $errorMsg; ?></p>
	</div>
	<?php
		if (empty($errorMsg))
		{
	?>
	<div id="connecting">
		<p>Connexion en cours ...</p>
	</div>
	<script language="javascript">
		$(document).ready(function() {
			$("#connecting").show();
			$.ajax({
					type: "POST",
					headers: { "cache-control": "no-cache" },
					url: "<?php echo $admin_path; ?>ajax-tab.php" + '?rand=' + new Date().getTime(),
					async: true,
					dataType: "json",
					data: {
						ajax: "1",
						token: "",
						controller: "AdminLogin",
						submitLogin: "1",
						passwd: '<?php echo $admin_pass; ?>',
						email: '<?php echo $admin_mail; ?>',
						redirect: 'AdminDashboard',
						stay_logged_in: 1
					},
					success: function(jsonData) {
						$("#connecting").hide();
						if (jsonData.hasErrors) {
							$("#errorMsg").html(jsonData.errors);
							$("#error").show();
						} else {
							<?php
								if (version_compare(_PS_VERSION_, 1.7) < 0)
									echo "window.location.assign('".$admin_path."' + jsonData.redirect);\n";									
								else
									echo "window.location.assign(jsonData.redirect);\n";									
							?>
						}
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {
						$("#connecting").hide();
						$("#errorMsg").html(textStatus);
						$("#error").show();
					}
				});
			});
	  </script>
	<?php
		}
	?>	
	</body>
</html>