<?php

/* index.php
 * - Identification
 * Copyright (c) 2003 Frédéric Jacquot
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
	include("includes/config.inc.php");
	include(WEB_ROOT."includes/database.inc.php");
	include(WEB_ROOT."includes/functions.inc.php");
	include(WEB_ROOT."includes/lang.inc.php");
	include(WEB_ROOT."includes/session.inc.php");

	if (isset($_POST["ident"]))
	{
		if ($_POST["login"]==PREF_ADMIN_LOGIN && $_POST["password"]==PREF_ADMIN_PASS)
		{
			$_SESSION["logged_status"]=1;
			$_SESSION["admin_status"]=1;
			$_SESSION["logged_username"]=$_POST["login"];
			$_SESSION["logged_nom_adh"]=_T("Administrateur");
			$_SESSION["sess_cuser"]='O:5:"tUser":3:{s:2:"id";s:1:"4";s:4:"name";s:5:"admin";s:4:"perm";s:3:"126";}';
			dblog(_T("Identification"));
		}
		else
		{
			$requete = "SELECT id_adh, bool_admin_adh, nom_adh, prenom_adh
					FROM ".PREFIX_DB."adherents
									WHERE login_adh=" . txt_sqls($_POST["login"]) . "
									AND activite_adh='1'
									AND mdp_adh=" . txt_sqls($_POST["password"]);
			$resultat = &$DB->Execute($requete);
			if (!$resultat->EOF)
			{
				if ($resultat->fields[1]=="1")
					$_SESSION["admin_status"]=1;
				$_SESSION["logged_id_adh"]=$resultat->fields[0];
				$_SESSION["logged_status"]=1;
				$_SESSION["logged_nom_adh"]=strtoupper($resultat->fields[2]) . " " . strtolower($resultat->fields[3]);
				if ($_SESSION["admin_status"] == "1")
				{
					$_SESSION["sess_cuser"]='O:5:"tUser":3:{s:2:"id";s:1:"4";s:4:"name";s:5:"admin";s:4:"perm";s:3:"126";}';
				} else {
					$_SESSION["sess_cuser"]='O:5:"tUser":3:{s:2:"id";s:1:"1";s:4:"name";s:9:"Anonymous";s:4:"perm";s:1:"0";}';
				}

				$_SESSION["sess_clogin"] = $_SESSION["logged_nom_adh"];
				$_SESSION["sess_sort"] = "258";
				$_SESSION["sess_grp"]="1";
				dblog(_T("Identification"));
			}
			else
				dblog(_T("Echec authentification. Login :")." \"" . $_POST["login"] . "\"");
		}
	}

	if ($_SESSION["logged_status"]!=0)
		header("location: gestion_adherents.php");
	else
	{
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr-FR" lang="fr-FR"><head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<title>L’A.M.A.P. des Jardins de Virgile - Produits</title>
        <link rel="stylesheet" type="text/css" href="style.css" />
        <link rel="icon" type="image/png" href="icon-mini.png" />
        <meta name="Author" content="GARETTE Emmanuel" />
        <meta name="Keywords" content="AMAP, Dijon, Les bourroches, Le jardin de Virgile, A.M.A.P." />
        <meta name="Description" content="AMAP Dijon le Jardin de Virgile." />
</head>
<body>
	<h1>Partie privée de l'<acronym title="Association pour le Maintien de l'Agriculture Paysanne">A.M.A.P.</acronym> <br />les Jardins de Virgile</h1>
<p id="soustitre">::&nbsp;L’<acronym title="Association pour le Maintien de l'Agriculture Paysanne">A.M.A.P.</acronym> des Jardins de Virgile des bourroches, Dijon en Côte d’Or&nbsp;::</p>
<div id="body">
<div id="content">
	<h2>Accès à la partie privée</h2>
	<form action="index.php" method="post">
	<fieldset>
	<legend><?php echo _T("Identification"); ?></legend>
		<p><label><?php echo _T("Identifiant :"); ?></label><input type="text" name="login" /></p>
		<p><label><?php echo _T("Mot de passe :"); ?></label><input type="password" name="password" /></p>
		<p><input type="submit" name="ident" value="<?php echo _T("Identification"); ?>" /></p>
	</fieldset>
	</form>
	<p><a href="lostpasswd.php"><?php echo _T("Mot de passe perdu ?"); ?></a></p>
</div>
<p id="pieddepage">
::&nbsp;Mise en page <a href="http://www.gnunux.info">GARETTE Emmanuel</a>&nbsp;::
</p>
</div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />

</body>
</html>

<?php
	}
?>
