<?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");

$style="arial_sadmin";
opensession("Sadmin",false);
if ($sess_login=='admstats') {
	aneantir_session();
	goto("./index.php");
	}
$PHP_SELF=basename($_SERVER['PHP_SELF']);

if (!isset($traite_mess)) {  //premier passage : on affiche le formulaire
?>
<?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>Message aux Administrateurs</title>
  <link rel="stylesheet" href="../include/general.css"  />

<script language="javascript">
function messageestbon() { //vérifie le formulaire avant envoi
 var frm=document.form_mess;
 if (!frm.mess.value) {
     alert("Le message est vide.");
     return false;
 }
 if (!frm.date_mess.value) {
     alert("La date de fin est absente.");
     return false;
 }
 return true;
}

function confirmer() {
    return (confirm('Supprimer vraiment ce message ?'));
}

</script>
</head>
<body class="arial_sadmin" onload="document.form_mess.mess.focus();">
    <p class="titre">Message aux administrateurs des établissements</p><hr width="30%">
    <form name="form_mess" method="post" action="<?php echo "$PHP_SELF?statut=$statut"; ?>" onsubmit='return messageestbon();' >
    <input type="hidden" name="traite_mess" value=1>
    <table border="0" cellspacing="0" bordercolordark="white" bordercolorlight="black" align="center" width="80%">
    <tr><td><p>Vous pouvez saisir un message système qui sera accessible à tous les administrateurs des différents sites,
    jusqu'à la date que vous saisirez au-dessous.</p></td></tr>
    <tr><td><p align='center'>
    <?php
      if (isset($MESSAGE_ADMIN))
         $m=str_replace("_n","\n",str_replace("_r","\r",stripslashes($MESSAGE_ADMIN)));
         //$m=str_replace("_n","\n",str_replace("_r","\r",$MESSAGE_ADMIN));

         else $m="";

      $ta="<textarea name=\"mess\" rows=6 cols=75 >";
      print $ta.$m."</textarea>";
    ?>
    </p></td>
    </tr>
    <tr><td align="center">Saisissez la date de péremption au format JJ/MM/AA :
    <input type="text" size=8 maxlength=8 name="date_mess" <?php if (isset($MESSAGE_DATE)) print "value=\"$MESSAGE_DATE\""; ?> ></td>
    </tr>
    <tr><td>&nbsp;</td></tr>
    <tr><td align="center">
            <input type="submit" class="coul" name="btn_sauver" value="Enregistrement du message">
            <input type="reset" class="coul" name="btn_reset" value="Retour aux valeurs précédentes">
        </td>
    </tr>
    <tr><td align="center">
            <input type="submit" class="coul" name="btn_suppr" value="Suppression du message actuel" onclick="return confirmer();">
            <input type="submit" class="coul" name="btn_retour" value="Retour sans enregistrement">
        </td>
    </tr>
     </table>
     </form>

<?php        } else { //traitement formulaire
    //========================
    connexion("$db");
    //print_r($_POST);
    $mess=str_replace("\n","_n",str_replace("\r","_r",$mess));
    $mess=htmlentities($mess);
    if (isset($btn_sauver)) {

      if (isset($MESSAGE_ADMIN)) {

      $sqlsauve_mess="UPDATE _params_globaux SET param_val='".secs($mess)."' ".
                        " WHERE param_nom='MESSAGE_ADMIN' ;";
      query($sqlsauve_mess);
      $sqlsauve_date="UPDATE _params_globaux SET param_val='".secs($date_mess)."' ".
                        " WHERE param_nom='MESSAGE_DATE' ;";
      query($sqlsauve_date);
      } else {
      $sqlsauve_mess="INSERT INTO _params_globaux ".
            " SET  param_nom='MESSAGE_ADMIN', ".
            "   param_type='s' , ".
            "   param_val='".secs($mess)."' , ".
            "   param_desc='Message administrateur' , ".
            "   param_tag=-1 ;";
      query($sqlsauve_mess);
      $sqlsauve_date="INSERT INTO _params_globaux ".
            " SET  param_nom='MESSAGE_DATE', ".
            "   param_type='s' , ".
            "   param_val='".secs($date_mess)."' , ".
            "   param_desc='Date de péremption du  message' , ".
            "   param_tag=-1 ;";
      query($sqlsauve_date);
        }
      getparams();

      //on peut envoyer la purée HTML à partir de là
      print "<html><head>\n";
      print "<title>Message admin</title>\n";
      print "<link rel=\"stylesheet\" href=\"../include/general.css\">\n";
      print "</head>";
      print "<body class=\"arial_sadmin\">\n";
      print "<h2 align=\"center\">Message administratif</h2>\n";
      print "<p>&nbsp;</p>\n";
      print "Le message a &eacute;t&eacute; sauvegard&eacute;
             avec succ&egrave;s<br>";
      print "<form name=\"form1\" method=\"post\" action=\"sadmin_bas.php\">";
      print "<p align=\"center\">";
      print "<input type=\"submit\" class=\"coul\" name=\"envoi\" value=\"Suite\">";
      print "</p></form></body></html>";
    }
    else {
      if (isset($btn_suppr)) {
      print "<html><head>\n";
      print "<title>Message admin</title>\n";
      print "<link rel=\"stylesheet\" href=\"../include/general.css\">\n";
      print "</head>";
      print "<body class=\"arial_sadmin\">\n";

      $sqlsauve_mess="UPDATE _params_globaux SET param_val='' ".
                        " WHERE param_nom='MESSAGE_ADMIN' ;";
      query($sqlsauve_mess);
      $sqlsauve_date="UPDATE _params_globaux SET param_val='' ".
                        " WHERE param_nom='MESSAGE_DATE' ;";
      query($sqlsauve_date);
      alert("Message administratif supprimé");
      print "</body></html>";
	  getparams();
        }

        $cible="sadmin_bas.php?statut=$statut";
        goto($cible);
    }
} //fin traitement

 ?>
</body>
</html>
