<?php
#=
/****************************************************************************
Copyright 2002, Daniel Deycard, Jacques Messines, Alain Pomirol
(CATICE Académie de Bordeaux)

This file is part of Gibii.

Gibii 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 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; 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("../incorporation/individus.class.php");
include("../incorporation/importation.php");
include("../incorporation/enluminures.inc.php");
include("../include/utiljs.php");
include("../include/html.class.php");
include("./verifie.inc.php");

opensession('Admin',false);
connecte($host,$user,$mdp,$db);
//dbg();
function traitercompte0($elvprof) {
global $etab_id,$qui;
$table=$elvprof.'s';
if ($elvprof=='eleve') {$indiv='Élèves'; $indivmin='élèves'; }
else {$indiv='Professeurs';$indivmin='professeurs'; }
$indivminsing=substr($indivmin,-1);
$quidam=new $elvprof();
$existe=$quidam->findfirst("(compte_id<=0 OR compte_id IS NULL) and tag=0 and etab_id=$etab_id");
if (!$existe) return false;
entete("$indiv qui ont un compte inexistant ou enterré");

print $quidam->findcount." $indiv concerné";if ($quidam->findcount>1) print 's';
print "<br /><font size=\"4\">\n";
print "<form name=\"incorp\" action=\"verifie_compte_2.php?qui=$qui&url=verifie_compte_nul.php\" method=\"post\">";

$html=new htmlcreator();
$html->begintable();
$auto=0;$manuel=0;
while($existe) {
    $nid=$quidam->id;
    $resc=query("SELECT compte_id,login FROM comptes WHERE $quidam->champ_id=$nid");
    if (mysql_num_rows($resc)==1) {
        list($compte_id,$quidam->login)=mysql_fetch_array($resc);
        query("UPDATE $table SET compte_id=".seci($compte_id)." , etab_id=$etab_id
                WHERE $quidam->champ_id=".seci($nid));
        $tquidams[]=$quidam;
        $auto++;
        $quidam->findnext();
        //print "--- $quidam->nom $quidam->prenom<br>";
        continue;
        }
    $manuel++;
    $html->beginrow();
    $html->colonnes(
             "<input name=\"box[]\" type=\"checkbox\" value=\"$nid\">",
             $quidam->nom,
             $quidam->prenom,
             $quidam->civil,
             " d. naiss : $quidam->dnaiss",
             " ".$quidam->getgroupname().' : '.$quidam->getgroupvalue(),
             " id_gep : $quidam->ident_nat",
             "<a href=\"verifie_compte_2.php?elvprof=$elvprof&nid=$nid&op=creer&qui=$qui&url=verifie_compte_nul.php\" title=\"Créer un nouveau compte\">Créer compte</a>",
             "<a href=\"verifie_compte_2.php?elvprof=$elvprof&nid=$nid&op=supprimer&qui=$qui&url=verifie_compte_nul.php\" title=\"Ne pas garder cet individu\">Supprimer élève</a>"
             );
    $html->endrow();
    $existe=$quidam->findnext();
    }
$quidam->findclose();
if ($manuel) {
        coches_tout_rien($indivmin);
        } //if $manuel
$html->endtable();
print "<input name=\"elvprof\" type=\"hidden\" value=\"$elvprof\">\n";
print "<input name=\"op\" type=\"hidden\" value=\"multiple\">\n";
print "</form></font>\n";
if ($auto) {
    if ($auto>1) {
            $pluriel1="s";
            $pluriel2='ont';
            }
    else {
            $pluriel1="";
            $pluriel2='a';
    }
    print "<br /><b>$auto individu$pluriel1 $pluriel2 eu leur compte déterré automatiquement :</b><br /><br />";

    $html->begintable();
    for ($q=0;$q<count($tquidams);$q++) {
        $html->beginrow();
        $html->colonnes($quidam->nom,
                        $quidam->prenom,
                        $quidam->civil,
                        $quidam->dnaiss,
                        $quidam->getgroupname().' : '.$quidam->getgroupvalue(),
                        " id_gep : ".$quidam->ident_nat,
                        "login : ".$quidam->login);
        $html->endrow();
        }
    $html->endtable();
    }
if ($manuel==0) {
    print "Plus de cas à traiter.";
    retour("../outils/verifie_base.php");  //plus rien à faire
    }
else {
    print "<br /><font size=\"3\">\n";
    print "<a href=\"../outils/verifie_base.php\" title=\"Si vous n'avez pas le temps maintenant\nou pas assez d'éléments pour décider,\nvous trouverez un lien dans le menu principal\npour régler ultérieurement le sort des incertains\">";
    print "[Remettre à plus tard la gestion des cas ci-dessus]</a>";
    print "</font>\n";
    }
return true;
}


//##############################################################################



if ($qui=='e') {
    if (!traitercompte0('eleve'))
        plusrien("Il ne reste plus d'élève ayant un champ `compte` anormal.");
    }
else {
    if (!traitercompte0('prof'))
        plusrien("Il ne reste plus de prof ayant un champ `compte` anormal.");
    }
print enqueue();
?>