<?php

include ("config.php");

$highlight_menu = 2;

_request("id_user");
_post("id_zone", "user_nom", "user_prenom", "user_coords", "user_tel1", "user_tel2", "user_login", "user_pass", "user_pass2", "user_cat", "edit_submit");

if (empty($edit_submit) && $info_util = $util->get_utilisateur($id_user))
{
	$id_zone = $info_util["id_zone"];
	$user_nom = $info_util["user_nom"];
	$user_prenom = $info_util["user_prenom"];
	$user_coords = $info_util["user_coords"];
	$user_tel1 = $info_util["user_tel1"];
	$user_tel2 = $info_util["user_tel2"];
	$user_login = $info_util["user_login"];
	$user_pass = $info_util["user_pass"];
	$user_cat = $info_util["user_cat"];
}

if ($edit_submit)
{
	if ($user_nom && $user_prenom && $user_coords)
	{
		if ($user_pass === $user_pass2)
		{
			if ($util->edit_utilisateur($id_user, $id_zone, $user_nom, $user_prenom, $user_coords, $user_tel1, $user_tel2, $user_login, $user_pass, $user_cat))
				header ("Location: utilisateur.php?action=ajout");
		}
		else
			$error = 4;
	}
	else
		$error = 2;
}

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 "<p class=\"center\">(" . req() . ") Champs &agrave; remplir obligatoirement<br />** Laisser vide si inchang&eacute;</p>\n";

echo "<div id=\"form-utilisateur\">\n";
echo "<form action=\"utilisateur_edition.php\" method=\"post\">\n";
echo "<table class=\"center\">\n";

echo "<tr>\n";
echo "<th class=\"center\" colspan=\"2\">Informations concernant cet utilisateur</th>\n";
echo "</tr>\n";

echo "<tr>\n";
echo "<td class=\"r\"><label for=\"user_nom\">Nom</label> " . req() . "</td>\n";
echo "<td><input type=\"text\" class=\"int\" name=\"user_nom\" id=\"user_nom\" value=\"" . $user_nom . "\" /></td>\n";
echo "</tr>\n";

echo "<tr>\n";
echo "<td class=\"r\"><label for=\"user_prenom\">Pr&eacute;nom</label> " . req() . "</td>\n";
echo "<td><input type=\"text\" class=\"int\" name=\"user_prenom\" id=\"user_prenom\" value=\"" . $user_prenom . "\" /></td>\n";
echo "</tr>\n";

echo "<tr>\n";
echo "<td class=\"r\"><label for=\"user_coords\">Adresse</label> " . req() . "</td>\n";
echo "<td><textarea name=\"user_coords\" id=\"user_coords\">" . nobr($user_coords) . "</textarea></td>\n";
echo "</tr>\n";

echo "<tr>\n";
echo "<td class=\"r\"><label for=\"user_tel1\">T&eacute;l&eacute;phone 1</label></td>\n";
echo "<td><input type=\"text\" class=\"int\" name=\"user_tel1\" id=\"user_tel1\" value=\"" . $user_tel1 . "\" /></td>\n";
echo "</tr>\n";

echo "<tr>\n";
echo "<td class=\"r\"><label for=\"user_tel2\">T&eacute;l&eacute;phone 2</label></td>\n";
echo "<td><input type=\"text\" class=\"int\" name=\"user_tel2\" id=\"user_tel2\" value=\"" . $user_tel2 . "\" /></td>\n";
echo "</tr>\n";

echo "<tr>\n";
echo "<td class=\"r\">Zone g&eacute;ographique</td>\n";
echo "<td>" . $menu->select_zone_geo($id_zone) . "</td>\n";
echo "</tr>\n";

echo "<tr>\n";
echo "<td class=\"r\"><label for=\"user_login\">Adresse mail (Login)</label></td>\n";
echo "<td><input type=\"text\" class=\"int\" name=\"user_login\" id=\"user_login\" value=\"" . $user_login . "\" /></td>\n";
echo "</tr>\n";

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

echo "<tr>\n";
echo "<td class=\"r\"><label for=\"user_pass2\">Vérification mot de passe</label></td>\n";
echo "<td><input type=\"password\" class=\"int\" name=\"user_pass2\" id=\"user_pass2\" value=\"\" /></td>\n";
echo "</tr>\n";

echo "<tr>\n";
echo "<td class=\"r\">Cat&eacute;gorie</td>\n";
echo "<td>" . select("user_cat", $cat_tab, $user_cat) . "</td>\n";
echo "</tr>\n";


echo "<tr>\n";
echo "<td class=\"center\" colspan=\"2\">";
echo "<input type=\"hidden\" name=\"id_user\" value=\"" . $id_user . "\" />";
echo "<input class=\"inb\" type=\"submit\" name=\"edit_submit\" value=\"Enregistrer\" />";
echo "</td>\n";
echo "</tr>\n";

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

echo "<p><a class=\"slink\" href=\"utilisateur.php\">Retour &agrave; la liste des utilisateurs</a></p>\n";

include ("footer.php");

?>