<?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

****************************************************************************/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script language='javascript'>
function etabok() { //vérifie le formulaire avant envoi
    var frm=document.frldap;
    if ((!frm.ldap_server.value)||(!frm.ldap_port.value)||(!frm.ldap_basedn.value) ) {
       alert("Au moins un champ est vide.");
       return false;
       }
       return true;
    }
</script>
<?php
include("../include/vars_adm.php");
include("../include/util.inc.php");
recuprequest();
print "<meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\">\n";
print "<title>Config du serveur LDAP de l'&eacute;tablissement</title>";
print "<link rel=\"stylesheet\" href=\"../include/general.css\">";
print "</head>";
print "<BODY class='arial_sadmin'>";
$PHP_SELF=basename($_SERVER['PHP_SELF']);

if (!isset($vabene)) { //Formulaire
   getparams_auth($etab_id,false);
   if (!isset($ldap_server)) $ldap_server="";
   if (!isset($ldap_port)) $ldap_port="";
   if (!isset($ldap_basedn)) $ldap_basedn="";

   print "<div align='center'>\n";
   print "<table cellpadding='10'><tr><td><img src='images/ldap.png' border=0></td>";
   print "<td><b>Saisissez ou modifiez les param&egrave;tres n&eacute;cessaires pour votre serveur LDAP :</b></td>";
   print "</tr></table>";
   print "<hr>\n";
   print "</div>";
   print "<i>(*&nbsp;Les lignes avec un astérisque doivent &ecirc;tre saisies)</i><br>";

   print "<div align='center'>\n";
   print "<form name='frldap' method='post' action='$PHP_SELF' onsubmit='return etabok();'>\n";
   print "<table>";
   print "<tr><td>*&nbsp;Adresse IP du serveur LDAP :</td>\n";
   print "<td><input type='text' name='ldap_server' value='$ldap_server' size=25></td></tr>\n";
   print "<tr><td>*&nbsp;Port d'&eacute;coute du serveur LDAP :</td>\n";
   print "<td><input type='text' name='ldap_port' value='$ldap_port' size=6></td></tr>\n";
   print "<tr><td>&nbsp;&nbsp;&nbsp;*&nbsp;Base DN :</td>";
   print "<td><input type='text' name='ldap_basedn' value='$ldap_basedn' size=20></td></tr>\n";
   print "</table>\n";
   print "<p align='center'>\n";
   print "<input type='hidden' name='etab_id' value='$etab_id'>\n";
   print "<input type='submit' class='coul' name='vabene' value='  OK  ' >\n";
   print "&nbsp;&nbsp;&nbsp;\n";
   print "</p>";
   print "</form>";
   print "</div>";
   print "</body>";
   print "</html>\n";
   }
else { //Enregistrement des paramètres
   $conn  = connecte($host,$user,$mdp,$db);
   query("DELETE FROM _params_auth WHERE etab_id=$etab_id");
   query("INSERT INTO _params_auth VALUES (DEFAULT,$etab_id,'ldap_server','s','".secs($ldap_server)."','Adresse du serveur LDAP',-1)");
   query("INSERT INTO _params_auth VALUES (DEFAULT,$etab_id,'ldap_port','i','".secs($ldap_port)."','Port du serveur LDAP',-1)");
   query("INSERT INTO _params_auth VALUES (DEFAULT,$etab_id,'ldap_basedn','s','".secs($ldap_basedn)."','Base DN',-1)");
   //Et hop, on sauve en prime le type d'authentification de l'étab !
   query("UPDATE etablissements SET typauth_id=2 WHERE etab_id=".seci($etab_id)." ");
   print "<div align='center'>\n";
   print "Param&egrave;tres correctement enregistr&eacute;s...";
   print "<p><form name='fexit'>\n";
   print "<input type='submit' name='exit_btn' value='   OK   '  onclick='window.close();'>\n";
   print "</form></p>";
   print "</div>";
   print "</body>";
   print "</html>";
}

?>