<?php

include ("config.php");

_request("id_pat");
_post("id_user", "edit_submit");

$highlight_menu = 3;

if ($id_pat && $info_pat = $pat->get_patient($id_pat))
{
	$pat_nom = $info_pat["pat_nom"];
	$pat_prenom = $info_pat["pat_prenom"];
}
else
	header ("Location: patient.php");

if ($edit_submit)
{
	if ($id_user && $info_util = $util->get_utilisateur($id_user))
	{
		if ($suivi->edit_suivi($id_pat, $id_user))
			header ("Location: patient_suivi.php?id_pat=" . $id_pat . "&action=ajout");
	}
}

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 "<div id=\"list-suivi\">\n";

if ($id_pat)
{
	$pat_nom = substr($pat_nom, 0, 3);
	$pat_prenom = substr($pat_prenom, 0, 1);

	echo "<form action=\"patient_suivi.php?id_pat=" . $id_pat . "\" method=\"post\">\n";
	echo "<p>Associ&eacute; le patient <span class=\"bold\">" . $pat_nom . " " . $pat_prenom ."</span> &agrave; l'utilisateur " . $suivi->select_utilisateur($id_pat, 0) . " <input type=\"submit\" class=\"inb\" name=\"edit_submit\" id=\"edit_submit\" value=\"Enregistrer\" /></p>\n";
	echo "</form>\n";

	echo "<table>\n";

	echo "<tr>\n";
	echo "<th class=\"center\" colspan=\"3\">Liste des utilisateurs</th>\n";
	echo "</tr>\n";

	$list_suivi_pat = $suivi->list_suivi_pat($id_pat);

	if ($c = count($list_suivi_pat))
	{
		echo "<tr class=\"titre\">\n";
		echo "<td>Nom</td>\n";
		echo "<td>Pr&eacute;nom</td>\n";
		echo "<td>Action</td>\n";
		echo "</tr>\n";

		for ($i = 0; $i < $c; $i++)
		{
			$class = ($i % 2 == 0 ? "item" : "item2");
			echo "<tr class=\"" . $class . "\">\n";
			echo "<td>" . $list_suivi_pat[$i]["user_nom"] . "</td>\n";
			echo "<td>" . $list_suivi_pat[$i]["user_prenom"] . "</td>\n";
			echo "<td class=\"action\"><a class=\"sdel\" href=\"suivi_suppression.php?id_user=" . $list_suivi_pat[$i]["id_user"] . "&amp;id_pat=" . $id_pat . "&amp;from=pat\">Supprimer</a></td>\n";
			echo "</tr>\n";
		}
	}
	else
	{
		echo "<tr>\n";
		echo "<td class=\"center error\" colspan=\"3\">Aucun utilisateur enregistr&eacute;</td>\n";
		echo "</tr>\n";
	}

	echo "</table>\n";
}

echo "</div>\n";

include ("footer.php");

?>