<?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/creerlogin.inc.php");

opensession("Admin");
?>
<!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>Nouveau compte  d'administration</title>

<script language='javascript'>
         function verif(message) {
           var formu=window.document.form_log;
           if  (formu.mdp1.value!==formu.mdp2.value)
               {
               alert(message);
               return false;
               } else
               if (formu.monlogin.value=='')
                  {
                   alert('Saisissez  un login !');
                   return false;
                   }
                   else
                   return true;
         }
</script>

<link rel="stylesheet" href="<?php echo "../themes/".$etab_theme."/b2i.css" ?>">
<meta name="generator" content="amaya">
</head>

<body class="arialadmin" onload="if (document.form_log==undefined) ; else document.form_log.monlogin.focus();" >
<?php


if (! isset($monlogin)) {
   print "<p class='sous_titre'>Création d'un nouveau compte</p>";

?>

<form name="form_log" target="_self" method="post" action="new_cpte.php" onsubmit="return verif('Mots de passe différents !');">
    <table border="1" align="center">
        <tr>
            <td width="537">
                <p align="center" >&nbsp;Nouveau compte &nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" name="statut_cpte" value="Admin"> Administrateur&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="statut_cpte" value="Gest" checked>   Gestionnaire&nbsp;</p>
            </td>
        </tr>
        <tr>
            <td width="537">
                <p align="center" >&nbsp;&nbsp;&nbsp;&nbsp;Login : &nbsp;<input type="text" name="monlogin" maxlength="15" size="15"></p>
            </td>
        </tr>
        <tr>
            <td width="537">
                <p align="center">Mot de passe : <input type="password" name="mdp1" maxlength="10" size="10"></p>
            </td>
        </tr>
        <tr>
            <td width="537">
                <p align="center">&nbsp;&nbsp;Confirmation : <input type="password" name="mdp2" maxlength="10" size="10"></p>
            </td>
        </tr>
        <tr>
            <td width="537">
                <p align="center"><input type="submit" class="coul" name="btn_log" value="Valider">    &nbsp;&nbsp;&nbsp;&nbsp;
                <input type="reset" class="coul" name="btn_reset" value="Vider"></p>
            </td>
        </tr>
    </table>
</form>

<?php

} //fin de la saisie, il reste à contrôler les entrées

else {  //début traitement

$conn  = connecte($host, $user, $mdp, $db);

//recherche compte existant déjà ?
$monlogin=LoginUnique($monlogin);
$monloginquot=addslashes($monlogin);
$mdp1=md5($mdp1);

if ($IMPOSE_CHGT_MDP) $actif=0; else $actif=1;

if ($statut_cpte=='Admin' || $statut_cpte=='Gest') {
	//security !
	$resquery = query("INSERT INTO comptes
	                      SET login      = '$monloginquot',
	                          statut     = '$statut_cpte',
	                          mdp        = '$mdp1',
	                          actif      = $actif,
	                          nbsessions = 0,
	                          etab_id    = $etab_id");
	
	
	print "</br><p align = \"center\">Le compte $statut_cpte :<b> $monlogin </b>&nbsp;a été créé avec succès</br></p>";
	}
?>
 <center><table border = "0"><tr><td>
<form action="admin_bas.php" method="post">
     <input type ="submit" class="coul" name="btn_retour" value="Retour menu">
</form> </td></tr></table> </center>

<?php


}
?>


<p>&nbsp;</p>
</body>

</html>
