<?php
/* voir_adherent.php
 * - Visualisation d'une fiche adhérent
 * Copyright (c) 2004 Frédéric Jaqcuot
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

	include("includes/config.inc.php");
	include(WEB_ROOT."includes/database.inc.php");
	include(WEB_ROOT."includes/functions.inc.php");
	include(WEB_ROOT."includes/lang.inc.php");
	include(WEB_ROOT."includes/session.inc.php");

	$id_adh = "";
	if ($_SESSION["logged_status"]==0)
	{
		header("location: index.php");
		die();
	}
	if ($_SESSION["admin_status"]==0)
		$id_adh = $_SESSION["logged_id_adh"];

	// On vérifie si on a une référence => modif ou création
	if (isset($_GET["id_adh"]))
		if (is_numeric($_GET["id_adh"]))
			$id_adh = $_GET["id_adh"];

	if ($_SESSION["admin_status"]==0)
		$id_adh = $_SESSION["logged_id_adh"];
	if ($id_adh=="")
	{
		header("location: index.php");
		die();
	}

     //
    // Pré-remplissage des champs
   //  avec des valeurs issues de la base
  //

	$requete = "SELECT *
							FROM ".PREFIX_DB."adherents
							WHERE id_adh=$id_adh";
	$result = $DB->Execute($requete);
        if ($result->EOF)
	{
		header("location: index.php");
		die();
	}

	// recuperation de la liste de champs de la table
	$values = Array();
  $fields = $DB->MetaColumns(PREFIX_DB."adherents");
	foreach ($fields as $champ => $proprietes)
	{
		$val="";
		$proprietes_arr = get_object_vars($proprietes);
		// on obtient name, max_length, type, not_null, has_default, primary_key,

		// déclaration des variables correspondant aux champs
		// et reformatage des dates.

		// on doit faire cette verif pour une enventuelle valeur "NULL"
		// non renvoyée -> ex: pas de tel
		// sinon on obtient un warning
		if (isset($result->fields[$proprietes_arr["name"]]))
			$val = $result->fields[$proprietes_arr["name"]];

		if($proprietes_arr["type"]=="date" && $val!="")
		{
			list($a,$m,$j)=explode("-",$val);
			$val="$j/$m/$a";
		}
		$values[$proprietes_arr["name"]] = htmlentities(stripslashes(addslashes($val)), ENT_QUOTES);
	}
	reset($fields);
	include("header.php");
?>
			<H1 class="titre"><?php echo _T("Fiche adhérent"); ?></H1>
			<BLOCKQUOTE>
				<DIV align="center">
				<TABLE border="0">
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Nom :"); ?></B></TD>
<?php
	$nom_adh_ext = "";
	switch($values['titre_adh'])
	{
		case "1" :
			$nom_adh_ext .= _T("M.");
			break;
		case "2" :
			$nom_adh_ext .= _T("Mme.");
			break;
		default :
			$nom_adh_ext .= _T("Mlle.");
	}
	$nom_adh_ext .= " ".htmlentities(strtoupper(custom_html_entity_decode($values['nom_adh'])), ENT_QUOTES)." ".ucfirst(strtolower($values['prenom_adh']));
?>
						<TD bgcolor="#EEEEEE"><?php echo $nom_adh_ext; ?></TD>
<?php
	$image_adh = "";
	if (file_exists(WEB_ROOT . "photos/tn_" . $id_adh . ".jpg"))
	{
		$image_adh = "photos/tn_" . $id_adh . ".jpg";
		$image_adh_full = "photos/" . $id_adh . ".jpg";
	}
	elseif (file_exists(WEB_ROOT . "photos/tn_" . $id_adh . ".gif"))
	{
		$image_adh = "photos/tn_" . $id_adh . ".gif";
		$image_adh_full = "photos/" . $id_adh . ".gif";
	}
	elseif (file_exists(WEB_ROOT . "photos/tn_" . $id_adh . ".png"))
	{
		$image_adh = "photos/tn_" . $id_adh . ".png";
		$image_adh_full = "photos/" . $id_adh . ".png";
	}
	elseif (file_exists(WEB_ROOT . "photos/" . $id_adh . ".jpg"))
	{
		$image_adh = "photos/" . $id_adh . ".jpg";
		$image_adh_full = "photos/" . $id_adh . ".jpg";
	}
	elseif (file_exists(WEB_ROOT . "photos/" . $id_adh . ".gif"))
	{
		$image_adh = "photos/" . $id_adh . ".gif";
		$image_adh_full = "photos/" . $id_adh . ".gif";
	}
	elseif (file_exists(WEB_ROOT . "photos/" . $id_adh . ".png"))
	{
		$image_adh = "photos/" . $id_adh . ".png";
		$image_adh_full = "photos/" . $id_adh . ".png";
	}

	if ($image_adh != "")
	{
                if (function_exists("ImageCreateFromString"))
                        $imagedata = getimagesize($image_adh);
                else
                        $imagedata = array("130","");
		$photo_adh ="<A href=\"".$image_adh_full."\" target=\"_blank\"><IMG src=\"".$image_adh."?nocache".time()."\" border=\"1\" alt=\""._T("Photo")."\" width=\"".$imagedata[0]."\" width=\"".$imagedata[1]."\"></A>";
	}
	else
		$photo_adh = _T("[ pas de photo ]");

	if ($_SESSION["admin_status"]!=0)
		$rowspan_photo = "8";
	else
		$rowspan_photo = "5";
?>
						<TD colspan="2" rowspan="<?php echo $rowspan_photo; ?>" align="center"><?php echo $photo_adh; ?></TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Pseudo :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php echo $values['pseudo_adh']; ?>&nbsp;</TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Date de naissance :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php echo $values['ddn_adh']; ?>&nbsp;</TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Statut :"); ?></B></TD>
<?php
	if(isset($id_statut)) {
	$requete = "SELECT libelle_statut
								FROM ".PREFIX_DB."statuts
								WHERE id_statut=".$id_statut."
								ORDER BY priorite_statut";
	$result = &$DB->Execute($requete);
	if (!$result->EOF)
		$libelle_statut = _T($result->fields["libelle_statut"]);
	$result->Close();
	} else {
		$libelle_statut = '';
	}
?>
						<TD bgcolor="#EEEEEE"><?php echo $libelle_statut ?>&nbsp;</TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Profession :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php echo $values['prof_adh']; ?>&nbsp;</TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Je souhaite apparaître dans la liste des membres :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if ($values['bool_display_info']=="1") echo _T("Oui"); else echo _T("Non"); ?></TD>
					</TR>
                                        <TR>
                                                <TD bgcolor="#DDDDFF"><B><?php echo _T("Panier :"); ?></B></TD>
                                                <TD bgcolor="#EEEEEE"><?php if ($values['panier_adh']=="1")        echo _T("GP");
						if ($values['panier_adh']=="0")	echo _T("pp");
						if ($values['panier_adh']=="-1")	echo "-";?></TD>
                                        </TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Pain :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if ($values['pain_adh']=="4")	echo _T("9¿50"); elseif ($values['pain_adh']=="3")        echo _T("7¿"); elseif ($values['pain_adh']=="2")        echo _T("5¿"); elseif ($values['pain_adh']=="1") echo _T("3¿"); else echo "-"; ?></TD>/
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Volaille :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if ($values['volaille_adh']=="0")	echo _T("non"); else echo _T("oui"); ?></TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Fromage de chèvre :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if ($values['chevre_adh']=="0")	echo _T("non"); else echo _T("oui"); ?></TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Boeuf :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if ($values['boeuf_adh']=="0")	echo _T("non"); else echo _T("oui"); ?></TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Veau :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if ($values['veau_adh']=="0")	echo _T("non"); else echo _T("oui"); ?></TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Cochon :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if ($values['cochon_adh']=="0")	echo _T("non"); else echo _T("oui"); ?></TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Farine-Huile :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if ($values['farine_adh']=="0")	echo _T("non"); else echo _T("oui"); ?></TD>
					</TR>

<?php
	if ($_SESSION["admin_status"]!=0)
	{
?>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Compte :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if ($values['activite_adh']=="1") 	echo _T("Actif"); else echo _T("Inactif"); ?></TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Admin Galette :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if ($values['bool_admin_adh']=="1") echo _T("Oui"); else echo _T("Non"); ?></TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Exempt de cotisation :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if ($values['bool_exempt_adh']=="1") echo _T("Oui"); else echo _T("Non"); ?></TD>
					</TR>

<?php
	}
?>
					<TR>
						<TD colspan="4">&nbsp;</TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF" valign="top"><B><?php echo _T("Adresse :"); ?></B></TD>
						<TD bgcolor="#EEEEEE" colspan="3"><?php echo $values['adresse_adh']; ?>&nbsp;<BR><?php echo $values['adresse2_adh']; ?>&nbsp;</TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Code Postal :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php echo $values['cp_adh']; ?>&nbsp;</TD>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Ville :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php echo $values['ville_adh']; ?>&nbsp;</TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Pays :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php echo $values['pays_adh']; ?>&nbsp;</TD>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Tel :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php echo $values['tel_adh']; ?>&nbsp;</TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("GSM :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if(isset($gsm_adh)) {echo $gsm_adh; }?>&nbsp;</TD>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("E-Mail :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if (isset($email_adh)) { ?><A href="mailto:<?php echo $email_adh; ?>"><?php echo $email_adh; ?></A><?php } ?>&nbsp;</TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Site Web :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if (isset($url_adh)) { ?><A href="<?php echo $url_adh; ?>"><?php echo $url_adh; ?></A><?php } ?>&nbsp;</TD>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("ICQ :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if(isset($icq_adh)) {echo $icq_adh; }?>&nbsp;</TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Jabber :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if(isset($jabber_adh)) {echo $jabber_adh;} ?>&nbsp;</TD>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("MSN :"); ?></B></TD>
						<TD bgcolor="#EEEEEE"><?php if (isset($msn_adh)) { ?><A href="mailto:<?php echo $msn_adh; ?>"><?php echo $msn_adh; ?></A><?php } ?>&nbsp;</TD>
					</TR>
					<TR>
						<TD colspan="4">&nbsp;</TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Identifiant :"); ?>&nbsp;</B></TD>
						<TD bgcolor="#EEEEEE"><?php if (isset($values['login_adh'])) {echo $values['login_adh'];} ?></TD>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Mot de passe :"); ?></B>&nbsp;</TD>
						<TD bgcolor="#EEEEEE"><?php if (isset($values['mdp_adh'])) {echo $values['mdp_adh'];} ?></TD>
					</TR>
<?php
			$ajout_contrib="";
			if ($_SESSION["admin_status"]!=0)
			{
?>
					<TR>
						<TD bgcolor="#DDDDFF"><B><?php echo _T("Date de création :"); ?></B>&nbsp;</TD>
						<TD bgcolor="#EEEEEE" colspan="3"><?php echo $values['date_crea_adh']; ?></TD>
					</TR>
					<TR>
						<TD bgcolor="#DDDDFF" valign="top"><B><?php echo _T("Autres informations (admin) :"); ?></B></TD>
						<TD bgcolor="#EEEEEE" colspan="3"><?php echo nl2br($values['info_adh']); ?></TD>
					</TR>
<?php
				$ajout_contrib = "&nbsp;&nbsp;&nbsp;<A href=\"ajouter_contribution.php?id_adh=".$id_adh."\">"._T("[ Ajouter une contribution ]")."</A>";
			}
?>
					<TR>
						<TD bgcolor="#DDDDFF" valign="top"><B><?php echo _T("Autres informations :"); ?></B></TD>
						<TD bgcolor="#EEEEEE" colspan="3"><?php echo nl2br($values['info_public_adh']); ?></TD>
					</TR>
					<TR>
						<TD colspan="4" align="center"><BR><A href="ajouter_adherent.php?id_adh=<?php echo $id_adh; ?>"><?php echo _T("[ Modification ]"); ?></A>&nbsp;&nbsp;&nbsp;<A href="gestion_contributions.php?id_adh=<?php echo $id_adh; ?>"><?php echo _T("[ Contributions ]"); ?></A><?php echo $ajout_contrib; ?></TD>
						</TR>
				</TABLE>
			</DIV>
			<BR>
		</BLOCKQUOTE>
<?php
  include("footer.php")
?>
