
<?php
#=
/****************************************************************************
Copyright 2002, Daniel Deycard, Jacques Messines, Stéphanie Roussel, Jean-Marie Treins
                      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/get.inc.php");
include("../include/utiljs.php");
$statut=$_REQUEST['statut'];
opensession("$statut",false);
$PHP_SELF=basename($_SERVER['PHP_SELF']);
$compte_id=$sess_compte_id;
//on veut voir l'effet du theme choisi
if (isset($btn_voir)) $etab_theme=$perso_theme;
//on sort sans changer le theme
if (isset($btn_quitter)) {
    get_theme_user_defaut($compte_id); // récupère le theme par défaut
    $etab_theme=$theme_user_defaut;
    session_puts('etab_theme');
close_window();
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<TITLE>Changer le thème personnel</TITLE>
<link rel="stylesheet" href="<?php echo "../themes/".$etab_theme."/b2i.css" ?>">
</head>

 <?php
 //On sauve ou on saisit ?
 if (isset($btn_sauver)) {
        $sqlsauve="UPDATE comptes
                  SET theme='".secs($perso_theme)."'
                  WHERE compte_id=".seci($compte_id );
        query($sqlsauve);
        $etab_theme=$perso_theme;
        //Remplacer le thème courant
        session_puts('etab_theme');
        //Rafraîchir la page mère et partir
        js('window.opener.parent.location.reload();');
        close_window();
        }
    else {
?>
<body>
<table width='80%' border='0' align='center'>
<tr>
<td style="text-align:center;"><img src="<?php echo "../themes/".$etab_theme."/b2i_".strtolower($statut).".gif" ?>" width="50%"></td>
</tr>
</table>
<br />

 <form name="choix_theme"  method="post"  action="<?php echo $PHP_SELF; ?>">
 <p align="center">Choix du thème personnel : <select name="perso_theme" size="1">
 <?php
        $def_theme=$etab_theme;
        $themelist="";
        $nb_theme_dispo=0;
        $filtre_theme_eleve="e_";
        $prefixe="";
        $fin="";
        $handle=opendir('../themes');
        while ($file = readdir($handle)) {
              if ( (!ereg("[.]",$file)) ) {
              $themelist .= "$file ";
              }
        }
        closedir($handle);
        $themelist = explode(" ", $themelist);
        sort($themelist);
        for ($i=0; $i < sizeof($themelist); $i++) {
        $prefixe=substr($themelist[$i],0,strlen($filtre_theme_eleve));
        $fin=substr($themelist[$i],strlen($filtre_theme_eleve));
             if($themelist[$i]!="CVS") {
                if($themelist[$i]!="") {
                   if ($statut=="Eleve") {
                    if ($etab_theme_eleve_limite==1){
                       if ($prefixe==$filtre_theme_eleve){  // l'élève ne voit que les thèmes dont le nom commence par $filtre
                       $themelist[$i]=$fin;
                       echo "<option name=\"def_theme\" value=\"$themelist[$i]\" ";
                            if($themelist[$i]==$def_theme) echo "selected";
                       echo ">$themelist[$i]\n";
                       $nb_theme_dispo++;
                       }
                    }// fin eleve limite
                    else { // élève autorisé à utiliser liste entière
                    echo "<option name=\"def_theme\" value=\"$themelist[$i]\" ";
                         if($themelist[$i]==$def_theme) echo "selected";
                    echo ">$themelist[$i]\n";
                    $nb_theme_dispo++;
                    }
                   }// fin statut eleve
                   else { //on n'est pas un élève
                       if ($prefixe!=$filtre_theme_eleve){  // on ne voit pas les thèmes dont le nom commence par $filtre
                   echo "<option name=\"def_theme\" value=\"$themelist[$i]\" ";
                                 if($themelist[$i]==$def_theme) echo "selected";
                   echo ">$themelist[$i]\n";
                   $nb_theme_dispo++;
                       }
                   }// fin else statut
                 }// fin vide
             }// fin cvs
         } //fin for
         echo "</select></p>";
         ?>
 <table width='200' align='center' border='0'>
 <tr>
 <input type='hidden' name='statut' value="<?php echo $statut; ?>">
 <?php
     if ($nb_theme_dispo!=0) {
     print " <td class='centre'> <input type=\"submit\" class=\"coul\" name=\"btn_sauver\" value=\"Sauver et Quitter\"></td>";
     print "<td class='centre'><input type=\"submit\" class=\"coul\" name=\"btn_voir\" value=\"Voir le thème\"></td> ";
     }
     else print "<p align='center'>Pas de thèmes disponibles</p>";
 ?>
 <td class='centre'><input type="submit" class="coul" name="btn_quitter" value="Annuler"></td>
 </tr>
 </table>
 </p>
 </form>
 <?php
 }  
 ?>
</body>

</html>