<?php

include ("config.php");

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

$highlight_menu = 2;

if ($id_user && $info_util = $util->get_utilisateur($id_user))
{
  $user_nom = $info_util["user_nom"];
  $user_prenom = $info_util["user_prenom"];
}
else
  header ("Location: utilisateur.php");

if ($edit_submit)
{
  if ($id_pat && $info_pat = $pat->get_patient($id_pat))
  {
    if ($suivi->edit_suivi($id_pat, $id_user))
      header ("Location: utilisateur_suivi.php?id_user=" . $id_user . "&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_user)
{
  echo "<form action=\"utilisateur_suivi.php?id_user=" . $id_user . "\" method=\"post\">\n";
  echo "<p>Associer l'utilisateur <span class=\"bold\">" . $user_nom . " " . $user_prenom ."</span> au patient " . $suivi->select_patient($id_user, 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=\"4\">Liste des patients</th>\n";
  echo "</tr>\n";

  $list_suivi_util = $suivi->list_suivi_util($id_user);

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

    for ($i = 0; $i < $c; $i++)
    {
			$pat_nom = substr($list_suivi_util[$i]["pat_nom"], 0, 3);
			$pat_prenom = substr($list_suivi_util[$i]["pat_prenom"], 0, 1);

      $class = ($i % 2 == 0 ? "item" : "item2");
      echo "<tr class=\"" . $class . "\">\n";
      echo "<td>" . $pat_nom . "</td>\n";
      echo "<td>" . $pat_prenom . "</td>\n";
			echo "<td class=\"center\">" . format_date($list_suivi_util[$i]["pat_datenaiss"]) . "</td>\n";
      echo "<td class=\"action\"><a class=\"sdel\" href=\"suivi_suppression.php?id_user=" . $id_user. "&amp;id_pat=" . $list_suivi_util[$i]["id_pat"] . "&amp;from=util\">Supprimer</a></td>\n";
      echo "</tr>\n";
    }
  }
  else
  {
    echo "<tr>\n";
    echo "<td class=\"center error\" colspan=\"3\">Aucun patient enregistr&eacute;</td>\n";
    echo "</tr>\n";
  }

  echo "</table>\n";
}

echo "</div>\n";

include ("footer.php");

?>