<?php
ob_start();
session_start();

// Inclusion des librairie
require_once ('../lib/aeos.lib.php');
require_once ('../lib/config.lib.php');
require_once ('../lib/var.lib.php');
$password = AEOS_PASSWORD;
$login = AEOS_LOGIN;
$email = AEOS_MAIL;

?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php echo AEOS_NAME; ?></title>
<meta name="description" content="<?php echo AEOS_DESC; ?>" />
<link rel="stylesheet" type="text/css" media="screen" href="../themes/system/styles.css" />
<script type="text/javascript" src="owEditor/owEditor.js"></script>
<link rel="icon" type="image/png" href="../themes/<?php echo AEOS_THEME; ?>/images/favicon_aeos.ico" />
</head>
<?php if(!isset($_SESSION['_LOGIN']) || !isset($_SESSION['_PASSWORD'])){ ?>
<body>
	<div id="Layout"></div>	
    <div id="Administration">
			<h1><img src="../themes/system/images/logo_black.png" alt="Logo AEOS" /></h1>
			<h6>
				<img src="../themes/system/images/icones/logout.png" alt="Logout" class="icon" />
				Administration - AEOS
			</h6>
			
			<?php
			if (@$_GET['action']=="mdpperdu")
			{
				if(isset($_POST['login']) && isset($_POST['email']))
				{
					if(($login == $_POST['login']) && (strtolower($email) == strtolower($_POST['email'])))
					{
						$mdp = generer_mdp(12);
						sendMail(AEOS_NAME, $email, "Récupération de mot de passe", "Ce mail provient de ".AEOS_NAME.".\nVous avez fait une demande de nouveau mot de passe.\n\nVoici votre nouveau mot de passe: ".$mdp);
						ecriture_xml('../data/config.xml', 'mdp_admin', md5($mdp));
						echo "<p><span class='valide'>Un email vous a été envoyé.</span></p>";
					}
					else
					{
						echo "<p><span class='erreur'>Login ou email incorrect.</span></p>";
					}
				}
			?>
			<form action="index.php?action=mdpperdu" method="POST">	
				<p>Login<br /><input type="text" name="login" class="input_text" value="" /></p>
				<p>Email<br /><input type="text" name="email" class="input_text" value="" /></p>
				<p><input type="submit" value="Renvoyer un mot de passe" class="input_button" /></p>
			</form>
			<p><a href="index.php" class="link">Retour</a></p>
			<?php
			}
			else
			{
				if(isset($_POST['login']) && isset($_POST['mdp']))
				{
					if(($login == $_POST['login']) && ($password == md5($_POST['mdp'])))
					{
						$_SESSION['_LOGIN'] = $login;
						$_SESSION['_PASSWORD'] = $password;
						$n = lecture_xml(URL_CHECK_UPDATE);
						if($n['notifications']['update']['#text']!=UPDATE)
						{
							$_SESSION['_NOTIFICATIONS']=TRUE;
							copy(URL_CHECK_UPDATE, 'notifications.xml');
						}
						else
						{
							$_SESSION['_NOTIFICATIONS']=FALSE;
						}
						if($_SESSION['_NOTIFICATIONS']) ecriture_xml('../data/config.xml', 'update', $n['notifications']['update']['#text']);
						header('Location: index.php');   
					}
					else
					{
						echo "<p><span class='erreur'>Login ou mot de passe incorrect.</span></p>";
					}
				}
			?>
			<form action="index.php" method="POST">
				<p>LOGIN<br /><input type="text" name="login" class="input_text" value="" /></p>
				<p>MOT DE PASSE<br /><input type="password" name="mdp" class="input_text" value="" /></p>
				<p><input type="submit" value="Connexion" class="input_button" /></p>
				<p><a href="index.php?action=mdpperdu" class="link">Mot de passe perdu ?</a></p>
			</form>
			<?php
			}
			?>
	</div>
	</body>	
<?php } else {require_once('base.php');} ?>
</html>
<?php ob_end_flush(); ?>