<?php

include ("config.php");

$_SESSION = array();
$highlight_menu = 1;

_post("id_user");
_post("user_login", "user_pass", "login");

if (NO_LOGIN == 1)
{
	if (empty($login) && !empty($_SESSION["Sid_user"]))
		$id_user = $_SESSION["Sid_user"];
}

if (NO_LOGIN == 1)
{
	if ($login)
	{
		$_SESSION["Sid_user"] = $id_user;
		$_SESSION["Suser_cat"] = 1;
		if ($_SESSION["Sid_user"] == ADMIN_USER)
			$_SESSION["Sadmin"] = 1;
		session_write_close();
		header ("Location: suivi.php");
		exit;
	}
}
else
{
	if ($login)
	{
		if ($util->check_login($user_login, $user_pass))
		{
			session_write_close();
			header ("Location: suivi.php");
			exit;
		}
		else
			$error = "Utilisateur ou mot de passe incorrect.";
	}
}

include ("header.php");

if (!empty($error))
{
	if (is_int($error))
		echo "<p class=\"center error\">" . $error_list[$error] . "</p>\n";
	else
		echo "<p class=\"center error\">" . $error . "</p>\n";
}

echo "<form action=\"index.php\" method=\"post\">\n";
echo "<table>\n";

echo "<tr>\n";
echo "<th colspan=\"2\">Connexion</th>\n";
echo "</tr>\n";

if (NO_LOGIN == 1)
{
	$list_util = $util->list_utilisateur();
	$c = count($list_util);

	echo "<tr>\n";
	echo "<td colspan=\"2\" class=\"center\">";
	echo "<select name=\"id_user\" size=\"1\">\n";
	echo "<option value=\"\">-- Choisir --</option>\n";
	for ($i = 0; $i < $c; $i++)
		echo "<option value=\"" . $list_util[$i]["id_user"] . "\" " . ($id_user == $list_util[$i]["id_user"] ? " selected=selected" : "") . ">" . $list_util[$i]["user_nom"] . " " . $list_util[$i]["user_prenom"] . "</option>\n";
	echo "</select>\n";
	echo "</td>\n";
	echo "</tr>\n";
}
else
{
	echo "<tr>\n";
	echo "<td class=\"ar\"><label for=\"user_login\">Utilisateur</label></td>\n";
	echo "<td><input class=\"int\" type=\"text\" name=\"user_login\" id=\"user_login\" value=\"\" /></td>\n";
	echo "</tr>\n";

	echo "<tr>\n";
	echo "<td class=\"ar\"><label for=\"user_pass\">Mot de passe</label></td>\n";
	echo "<td><input class=\"int\" type=\"password\" name=\"user_pass\" id=\"user_pass\" /></td>\n";
	echo "</tr>\n";
}

echo "<tr>\n";
echo "<td colspan=\"2\" class=\"center\"><input class=\"inb\" type=\"submit\" name=\"login\" value=\"Se connecter\" /></td>\n";
echo "</tr>\n";

echo "</table>\n";
echo "</form>\n";

include ("footer.php");

?>