<?php
#=
/****************************************************************************
Copyright 2002, Daniel Deycard, Jacques Messines, Alain Pomirol
(CATICE Académie de Bordeaux)

This file is part of GiBii/Melia.

GiBii/Melia 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.

GiBii/Melia 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 GiBii/Melia; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

****************************************************************************/
include("../include/vars_adm.php");
include("../include/util.inc.php");
include("../include/utiljs.php");
opensession("Sadmin",false);
if ($sess_login=='admstats') {
	aneantir_session();
	goto("./index.php");
	}
    print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
       <title>Liste des Etablissements</title>
<link rel="stylesheet" href="../include/general.css">
<script language='javascript'>
    function configLDAP(etabid) { //nouvelle fenêtre avec la config CAS
    var adr='configLDAP.php?etab_id='+etabid;
     wliste=open(adr,'nomfenLDAP',
                 'dependent,top=10,left=200,height=380,width=570,resizable');
    }
    function configCAS(etabid) { //nouvelle fenêtre avec la config CAS
    var adr='configCAS.php?etab_id='+etabid;
     wliste=open(adr,'nomfenCAS',
                 'dependent,top=10,left=200,height=350,width=570,resizable');
    }
    function configBDD(etabid) { //nouvelle fenêtre avec la config CAS
    var adr='configBDD.php?etab_id='+etabid;
     wliste=open(adr,'nomfenBDD',
                 'dependent,top=10,left=200,height=150,width=300,resizable');
    }
</script>
</head>
<body class="arial_sadmin" bgcolor="white" text="black" link="white" vlink="white" alink="blue">


<?php
function check($ploc, $typ) { //retroune "checked si égalité
if ($ploc==$typ) return "checked";
else return "";
        }
$PHP_SELF=basename($_SERVER['PHP_SELF']);

print "<p class='titre'>Liste des Etablissements</p>";

if (!isset($tri)) $tri="";

switch($tri) {
   case "id":
        $ordre="etablissements.etab_id";
        break;
   case "rne":
        $ordre="etablissements.rne";
        break;
   case "codepostal":
        $ordre="etablissements.codepostal";
        break;
   case "ville":
        $ordre="etablissements.ville";
        break;
   case "nom":
        $ordre="etablissements.nom";
        break;
   case "type":
        $ordre="typetab.type";
        break;
   default :
        $ordre="etablissements.etab_id";
}
if (!isset($order)) $order="";
if ($order=="d") $ordre=$ordre." DESC";

$conn  = connecte($host,$user,$mdp,$db);
$sql="SELECT *  FROM etablissements,typetab 
		WHERE etablissements.type_id=typetab.type_id
		 ORDER BY $ordre" ;
$resetab=query ($sql);
$nbetabs=0;
//alert($sql);
//début du tableau

print "<table border='1' align='center' cellspacing='0' >\n";
print "<tr class='rubrique'>\n";
print "\t<td>Action<br />&nbsp;</td>";
print "<td>&nbsp;N°&nbsp;<br /><a href=\"$PHP_SELF?tri=id\"><img src=\"./images/haut.gif\" border=\"0\" align=\"middle\"></a><a href=\"$PHP_SELF?tri=id&order=d\"><img src=\"./images/bas.gif\" border=\"0\" align=\"middle\"></a></td>";
print "<td>&nbsp;RNE&nbsp;<br /><a href=\"$PHP_SELF?tri=rne\"><img src=\"./images/haut.gif\" border=\"0\" align=\"middle\"></a><a href=\"$PHP_SELF?tri=rne&order=d\"><img src=\"./images/bas.gif\" border=\"0\" align=\"middle\"></a></td>";
print "<td>Authentification<br />&nbsp;</td>\n";
print "<td>&nbsp;Nom&nbsp;<br /><a href=\"$PHP_SELF?tri=nom\"><img src=\"./images/haut.gif\" border=\"0\" align=\"middle\"></a><a href=\"$PHP_SELF?tri=nom&order=d\"><img src=\"./images/bas.gif\" border=\"0\" align=\"middle\"></a></td>";
print "<td>Type<br /><a href=\"$PHP_SELF?tri=type\"><img src=\"./images/haut.gif\" border=\"0\" align=\"middle\"></a><a href=\"$PHP_SELF?tri=type&order=d\"><img src=\"./images/bas.gif\" border=\"0\" align=\"middle\"></a></td>\n";
print "<td>&nbsp;Adresse&nbsp;<br /><a href=\"$PHP_SELF?tri=adresse\"><img src=\"./images/haut.gif\" border=\"0\" align=\"middle\"></a><a href=\"$PHP_SELF?tri=adresse&order=d\"><img src=\"./images/bas.gif\" border=\"0\" align=\"middle\"></a></td>";
print "<td>&nbsp;C.post.&nbsp;<br /><a href=\"$PHP_SELF?tri=codepostal\"><img src=\"./images/haut.gif\" border=\"0\" align=\"middle\"></a><a href=\"$PHP_SELF?tri=codepostal&order=d\"><img src=\"./images/bas.gif\" border=\"0\" align=\"middle\"></a></td>";
print "<td>&nbsp;Ville&nbsp;<br /><a href=\"$PHP_SELF?tri=ville\"><img src=\"./images/haut.gif\" border=\"0\" align=\"middle\"></a><a href=\"$PHP_SELF?tri=ville&order=d\"><img src=\"./images/bas.gif\" border=\"0\" align=\"middle\"></a></td>\n";
print "<td>Mail Admin<br />&nbsp;</td>\n";
print "<td>Tél Admin<br />&nbsp;</td></tr>\n";


while ($rowetab=mysql_fetch_array($resetab)) {
      $etab_id=$rowetab["etab_id"];
      $nbetabs++;
      $rne=$rowetab["rne"];
      $nom=$rowetab["nom"];
      $type=$rowetab["type"];
      $adresse=$rowetab["adresse"];
      $codepost=$rowetab["codepostal"];
      $ville=$rowetab["ville"];
      $meladm=$rowetab["mail_admin"];
      $teladm=$rowetab["tel_admin"];
      $typauth_id=$rowetab["typauth_id"];
      $nom=stripslashes($nom);
      $adresse=stripslashes($adresse);
      $ville=stripslashes($ville);
      if (empty($meladm)) $meladm="&nbsp;"; else $meladm=stripslashes($meladm);
      if (empty($teladm)) $teladm="&nbsp;"; else $teladm=stripslashes($teladm);
	 

     //couleur de la ligne suivant sa parité
     $cl=($nbetabs%2==0) ? "sadmin_paire" : "sadmin_impaire";

     //Affichage d'une ligne
     print "\t<tr class=$cl>\n";
     print "\t<td class=\"rubrique\"><a href=\"modifetab.php?etab_id=$etab_id&rne=$rne\">Modifier</a> / <a href=\"supetab.php?etab_id=$etab_id&rne=$rne\">Supprimer</a></td>\n";
     print "\t<td align=\"center\">$etab_id</td>\n";
     print "\t<td >$rne</td>\n";
     print "\t<td><input type='radio' name='auth".$etab_id."' value=1 ".check(1,$typauth_id)." onclick='configBDD(".$etab_id.");' >".$MODULE."&nbsp;";
     print "<input type='radio' name='auth".$etab_id."' value=2 ".check(2,$typauth_id)." onclick='configLDAP(".$etab_id.");'>LDAP&nbsp;";
     print "<input type='radio' name='auth".$etab_id."' value=3 ".check(3,$typauth_id)." onclick='configCAS(".$etab_id.");'>CAS</td>\n";
     print "\t<td >$nom</td>\n";
     print "\t<td >$type</td>\n";
     print "\t<td >$adresse</td>\n";
     print "\t<td >$codepost</td>\n";
     print "\t<td >$ville</td>\n";
     print "\t<td >$meladm</td>\n";
     print "\t<td >$teladm</td>\n";

     print "\t</tr>\n";
}

 print "</table><br>\n";
 if ($nbetabs<2) $pluriel="";
    else $pluriel="s";
 print $nbetabs." établissement".$pluriel;

?>
</body>

</html>