<?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.frcas;
    if ((!frm.CAS_SERVEUR.value)||(!frm.CAS_PORT.value)||(!frm.CAS_RETOUR.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 CAS 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($CAS_SERVEUR)) $CAS_SERVEUR="";
   if (!isset($CAS_PORT)) $CAS_PORT="";
   if (!isset($CAS_URI)) $CAS_URI="";
   if (!isset($CAS_RETOUR)) $CAS_RETOUR="";

   print "<div align='center'>\n";
   print "<table cellpadding='10'><tr><td><img src='images/tank.png' border=0></td>";
   print "<td><b>Saisissez ou modifiez les param&egrave;tres n&eacute;cessaires pour votre serveur CAS :</b></td>";
   print "</tr></table>";
   print "<br><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='frcas' method='post' action='$PHP_SELF' onsubmit='return etabok();'>\n";
   print "<table>";
   print "<tr><td>*&nbsp;Nom d'h&ocirc;te du serveur CAS :</td>\n";
   print "<td><input type='text' name='CAS_SERVEUR' value='$CAS_SERVEUR' size=25></td></tr>\n";
   print "<tr><td>*&nbsp;Port d'&eacute;coute du serveur CAS :</td>\n";
   print "<td><input type='text' name='CAS_PORT' value='$CAS_PORT' size=6></td></tr>\n";
   print "<tr><td>&nbsp;&nbsp;&nbsp;URI sur le serveur CAS :</td>";
   print "<td><input type='text' name='CAS_URI' value='$CAS_URI' size=10></td></tr>\n";
   print "<tr><td>*&nbsp;Destination après la sortie de GiSCCo (ou ../exit.php) :</td>\n";
   print "<td><input type='text' name='CAS_RETOUR' value='$CAS_RETOUR' size=25></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,'CAS_SERVEUR','s','".secs($CAS_SERVEUR)."','Adresse du serveur CAS',-1)");
   query("INSERT INTO _params_auth VALUES (DEFAULT,$etab_id,'CAS_PORT','i','".secs($CAS_PORT)."','Port du serveur CAS',-1)");
   query("INSERT INTO _params_auth VALUES (DEFAULT,$etab_id,'CAS_URI','s','".secs($CAS_URI)."','URI sur le serveur CAS',-1)");
   query("INSERT INTO _params_auth VALUES (DEFAULT,$etab_id,'CAS_RETOUR','s','".secs($CAS_RETOUR)."','URL de retour',-1)");
   //Et hop, on sauve en prime le type d'authentification de l'étab !
   query("UPDATE etablissements SET typauth_id=3 WHERE etab_id=$etab_id");
   print "<div align='center'>\n";
   print "Param&egrave;tres correctement enregistr&eacute;s...";
   print "<p><font color='red' size='+1'><b>ATTENTION !</b></font></p>";
   print "<p>L'acc&egrave;s 'El&egrave;ve' ou 'Prof' se fera maintenant à l'adresse :";
   print "<br><i>(Depuis la racine de GiSCCo)</i></p>";
   print "<b>index.php?CAS=1&CAS_SERVEUR=$CAS_SERVEUR&CAS_PORT=$CAS_PORT&CAS_URI=$CAS_URI</b><br>";
   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>";
}

?>