<?php

include ("config.php");

$highlight_menu = 5;
$highlight_cousu = 6;
$display_consu = true;

include ("header.php");

$list_consu = $consu->list_consultation($_SESSION["Sid_pat"], $_SESSION["Sid_user"]);

if ($c = count($list_consu))
{
	$last_consu = $consu->get_last_consultation($_SESSION["Sid_user"], $_SESSION["Sid_pat"]);
	$infoPatient = $pat->get_patient($_SESSION["Sid_pat"]);
	echo "<table class=\"list pad center\" id=\"list-consultation\">\n";

	echo "<tr>\n";
	echo "<th>Numéro</th>\n";
	echo "<th>Date de consultation</th>\n";
	echo "<th>Type de consultation</th>\n";
	echo "<th>Faite par</th>\n";
	echo "<th>&nbsp;</th>\n";
	echo "</tr>\n";

	for ($i = 0; $i < $c; $i++)
	{
		echo "<tr" . ($i % 2 == 0 ? "" : " class=\"inter\"") . ">\n";
		echo "<td>" . substr($infoPatient["pat_nom"], 0, 3) . "-" . $infoPatient["pat_dossier"] . "-" . substr($infoPatient["pat_prenom"], 0, 1) . "-" . $list_consu[$i]["id_consult"] . "</td>\n";
		echo "<td class=\"center\">" . format_date($list_consu[$i]["consu_date"]) . "</td>\n";
		echo "<td>" . $consu_type_tab[$list_consu[$i]["consu_type"]] . "</td>\n";
		echo "<td class=\"center\">" . $list_consu[$i]["user_nom"] . " " . $list_consu[$i]["user_prenom"] . "</td>\n";
//		if ($last_consu["id_consult"] == $list_consu[$i]["id_consult"] && $last_consu["consu_ferme"] == 0)
//		{
// 			if ($last_consu["id_user"] == $_SESSION["Sid_user"] || isset($_SESSION["Sadmin"]))
// 			{
				if (($_SESSION["Suser_cat"] == 2 && $list_consu[$i]["consu_type"] == 1) || $_SESSION["Suser_cat"] == 1 || isset($_SESSION["Sadmin"]))
					echo "<td class=\"center\"><a class=\"slink\" href=\"" . $consu_type_file_tab[$list_consu[$i]["consu_type"]] . "?id_consult=" . $list_consu[$i]["id_consult"] . "\">Modifier</a>&nbsp;";
				if (isset($_SESSION["Sadmin"]))
					echo "<a class=\"sdel\" href=\"dossier_suppression.php?id_consult=" . $list_consu[$i]["id_consult"] . "\">Supprimer</a>";

				echo "</td>\n";
// 			}
// 			else
// 				echo "<td class=\"center\">En cours</td>\n";
//		}
//		else
//		{
//			echo "<td><a class=\"slink\" href=\"consultation_impression.php?id_consult=" . $list_consu[$i]["id_consult"] . "\">Imprimer</a></td>\n";
//			echo "<td>&nbsp;</td>\n";
//		}
		echo "</tr>\n";
	}

	echo "</table>\n";
}
else
	echo "<p class=\"error center\">Aucune consultation n'a &eacute;t&eacute; trouv&eacute;e.</p>\n";

include ("footer.php");

?>