<?php
#=
include("../include/vars_adm.php");
include("../include/util.inc.php");
include("./dedoub.inc.php");


function afficher_radiolignes($passe2) {
global $individu;
global $deid,$dan,$detab_id,$dprecdate,$dident_nat,$dcid,$dlogin;
global $ok_eid,$ok_cid;
global $id;

$nbdoublons=count($deid);
for ($i=1;$i<=$nbdoublons;$i++) {
    $eid=$deid[$i];$an=$dan[$i];$etab_id=$detab_id[$i];
    $precdate=$dprecdate[$i];$ident_nat=$dident_nat[$i];
    $cid=$dcid[$i];$login=$dlogin[$i];
    print "<tr>\n";
    if ($passe2) {
        if ($eid==$ok_eid) {$eid_strong1="<strong>";$eid_strong2="</strong>"; }
        else {$eid_strong1="";$eid_strong2="";}
        if ($cid==$ok_cid) {$cid_strong1="<strong>";$cid_strong2="</strong>"; }
        else {$cid_strong1="";$cid_strong2="";}
        print "<td class=\"eleve\">$eid_strong1$eid$eid_strong2&nbsp;</td>\n";
        print "<td class=\"compte\">$cid_strong1$cid$cid_strong2&nbsp;</td>\n";
        print "<td class=\"compte\">$cid_strong1$login$cid_strong2&nbsp;</td>\n";
        print "<td class=\"eleve\">$eid_strong1$precdate$eid_strong2&nbsp;</td>\n";
        print "<td class=\"eleve\">$eid_strong1$ident_nat$eid_strong2&nbsp;</td>\n";
        print "<td class=\"eleve\">$eid_strong1$an$eid_strong2&nbsp;</td>\n";
        print "<td class=\"eleve\">$eid_strong1$etab_id$eid_strong2&nbsp;</td>\n";
        }
    else {
        print "<td class=\"eleve\"><input type=\"radio\" name=\"eleve\" value=\"$i\" ";
        if ($eid==$ok_eid) print "checked=\"checked\"";
        print " /> $eid&nbsp;</td>\n";
        print "<td class=\"compte\"><input type=\"radio\" name=\"compte\" value=\"$i\" ";
        if ($cid==$ok_cid) print "checked=\"checked\"";
        print " /> $cid&nbsp;</td>\n";
        print "<td class=\"compte\">$login&nbsp;</td>\n";
        print "<td class=\"eleve\">$precdate&nbsp;</td>\n";
        print "<td class=\"eleve\">$ident_nat&nbsp;</td>\n";
        print "<td class=\"eleve\">$an&nbsp;</td>\n";
        print "<td class=\"eleve\">$etab_id&nbsp;</td>\n";
        }
    if ($individu=='e') {
        print "<td>\n";
        //recherche des items obtenus par $eid
        $res3=query("SELECT item_id FROM resultats WHERE eleve_id=$eid");
        while (list($item_id)=mysql_fetch_array($res3)) print $item_id.' ';
        mysql_free_result($res3);
        print "&nbsp;</td>\n";
        }
    print "</tr>\n";
    }
}


///////////////////////////////////////////////////////////////////////////////
//Programme principal
///////////////////////////////////////////////////////////////////////////////

connecte($host,$user,$mdp,$db);
opensession('Sadmin',false);
if ($sess_login=='admstats') {
	aneantir_session();
	goto("./index.php");
	}
set_time_limit(0);
entete();
$PHP_SELF=basename($_SERVER['PHP_SELF']);

if (!isset($_REQUEST['id'])) exit(); //passé en GET (première fois), puis en POST
$id=$_REQUEST['id'];
if (!isset($_REQUEST['individu'])) exit(); //passé en GET (première fois), puis en POST
$individu=$_REQUEST['individu'];

if ($individu=='e') {
    $table="eleves";
    $champ="eleve_id";
    }
else {
    $table="profs";
    $champ="prof_id";
    }

$nb=recuperer_donnees($id);
if (!$nb) {
    menu_retour();
    exit();
    }
traiter_doublons(); //trouve les meilleures données

print "<br /><form method=\"post\" name=\"changer\" action=\"$PHP_SELF\">\n";
print "<strong> $Nom, $Prenom, $Dnaiss\n</strong>&nbsp;&nbsp;&nbsp;&nbsp;";
$passe2=isset($_POST['modifok']);
if ($passe2) { //modifier éventuellement les index en fonction
    $ok_eidbl=$_POST['eleve'];
    $ok_cidbl=$_POST['compte'];
    }
else {
    print "<input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
    print "<input type=\"hidden\" name=\"individu\" value=\"$individu\" />\n";
    print "<input type=\"submit\" name=\"modifok\" value=\"Traiter avec les choix ci-dessous\" />\n";
    print "&nbsp;&nbsp;&nbsp;&nbsp;\n";
    print "<input type=\"button\" name=\"annuler\" value=\"Revenir sans rien modifier\" onclick=\"window.location.href='dedoublonner.php?passe=1'\"/>\n";
    }
$ok_eid=$deid[$ok_eidbl];
$ok_cid=$dcid[$ok_cidbl];

print "<br /><br />";
print "<table width=\"100%\" border=\"1\">\n";
afficher_en_tete();
afficher_radiolignes($passe2);

print "</table>\n";
print "</form>\n";

if ($passe2) {
    //effectuer les modifs de la base
    $fpcsv=fopen("../prive/dupdates.csv","a");
    updates();  //modifie $deid et $dcid en enlevant le ok_ de chacune
    fclose($fpcsv);
    suppressions($deid,$dcid);
    menu_retour();
    }

?>

</body>

</html>