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

function traiter_pas_indivividu($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();
$nomid=$quidam->champ_id;
$res=query("SELECT comptes.compte_id
              FROM comptes LEFT JOIN $table ON comptes.$nomid=$table.$nomid
			 WHERE $table.$nomid IS NULL
			   AND comptes.statut='$elvprof'
			   AND comptes.etab_id=$etab_id");
print "<br>";
if (!mysql_num_rows($res)) return false;
entete("comptes $indivmin perdus (pas d'enregistrement associé dans la table $table)");
print "<br />";
$liste="";$nb=0;
while (list($compte_id)=mysql_fetch_array($res)) {
	$liste.=",$compte_id";
	$nb++;
	}
if ($nb) {
	$liste='('.substr($liste,1).')';
	query("DELETE FROM comptes WHERE compte_id IN $liste");
	}

print "Suppression de $nb compte";if ($nb>1) print 's';
print '.<br />';
retour("verifie_base.php");
}


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

if ($qui=='e') traiter_pas_indivividu('eleve');
else traiter_pas_indivividu('prof');
print enqueue();
?>