<?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("Admin",true);
$PHP_SELF=basename($_SERVER['PHP_SELF']);

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>Title here!</title>
       <link rel="stylesheet" href="<?php echo "../themes/".$etab_theme."/b2i.css" ?>">
</head>


<?php
  if (!isset($choixqui)) {
    print "<body class=\"arialadmin\">";
    print "<form mode='POST' action='$PHP_SELF'>";
    print "<input type='hidden' name='choixqui' value=1>";
    print "<p class='sous_titre'>Réinitialiser les mots de passe :</p>";
    print "<p align='center'><input type='radio' name='radio_qui' value=0>Des professeurs &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    print "<input type='radio' name='radio_qui' value=1 checked>Des élèves</p>";
    print "<p align='center'><input class = \"coul\" type='submit' name='btn_qui'></p>";

  } else {
    if ($radio_qui==1) $qui='élèves';
        else $qui='professeurs';
?>
   <body class="arialadmin"
      onload="if (confirm('Les mots de passe de tous les <?php  echo $qui; ?> vont être changés\n et il faudra les prévenir...\n Etes-vous sûr de vouloir réinitialiser les mots de passe des <?php echo $qui;  ?> ?'))
      location='reinit_mdp.php?op=1&choixqui=1&radio_qui=<?php echo $radio_qui; ?>';
      else location='../admin/admin_bas.php';
      return true;">

<?php

      if (isset($op)) {
      print "Travail en cours....";
      connecte($host,$user,$mdp,$db);
      if ($radio_qui==1) { //Elèves
          $reselv=query("SELECT eleves.eleve_id, dnaiss FROM eleves,comptes ".
                      "WHERE eleves.eleve_id=comptes.eleve_id ".
                      " and eleves.etab_id=$etab_id and eleves.annee='$sess_ascol'".
                      " and comptes.login<>'00000'");
          while (list($elev_id,$dnaiss)=mysql_fetch_array($reselv)) {
          $passwd=md5($dnaiss);
          if ($IMPOSE_CHGT_MDP) $chg_mdp=", actif='0' ";
        	else $chg_mdp="";
          query("UPDATE comptes SET mdp='$passwd' $chg_mdp WHERE eleve_id=".seci($elev_id));
          }
          } else {  //Profs
          $resprof=query("SELECT profs.prof_id, dnaiss FROM profs,comptes ".
                      "WHERE profs.prof_id=comptes.prof_id ".
                      " and profs.etab_id=$etab_id and profs.annee='$sess_ascol'".
                      " and comptes.login<>'proftest'");
          while (list($prof_id,$dnaiss)=mysql_fetch_array($resprof)) {
          $passwd=md5($dnaiss);
          if ($IMPOSE_CHGT_MDP) $chg_mdp=", actif='0' ";
        	else $chg_mdp="";
          query("UPDATE comptes SET mdp='$passwd' $chg_mdp WHERE prof_id=".seci($prof_id));
          }
      }

      alert("Réinitialisation  des mots de passe des $qui effectuée");
      goto("../admin/admin_bas.php");
      }
}
?>

</body>
</html>
