<?php

/*
print "<br />_GET=";print_r($_GET);
print "<br />_POST=";print_r($_POST);
print "<br />";
*/

include("../include/vars_adm.php");
include("../include/util.inc.php");
include("../include/utiljs.php");
include("../include/get.inc.php");
include("../include/eleve.inc.php");
opensession("Admin",false);

//base64_encode(serialize(array("supprimer_resultat",$old_resultat)))
//base64_encode(serialize(array("supprimer_temoin",$old_resultat, $prof_id)))
//base64_encode(serialize(array("modifier_dates")))
$getp=$_GET['p'];
$tparams=unserialize(base64_decode($getp));

$action=$tparams[0];
$index_liste=$tparams[1];
switch ($action) {
	case 'modifier_dates' : 
		foreach($_POST as $index => $valeur) {
			if (substr($index,0,3)!='mod') continue;
			$ix=(int) substr($index,3);
			$modifier=isset($_POST["mod$ix"]) && $_POST["mod$ix"];
			if (!$modifier) continue;
			$resultat_id=$_POST["res$ix"];
			$prof_id=$_POST["pro$ix"];
			$quand=$_POST["w0$ix"];
			$tqd=explode('/',substr($quand,0,10));
			$tqd=array_reverse($tqd);
			$qd=implode('-',$tqd);	//$tqd[2].'/'.$tqd[1].'/'.$tqd[0];
			//print "résultat : $resultat_id, prof : $prof_id, date : $qd<br>";
			query("UPDATE lrp SET quand='$qd' WHERE resultat_id=$resultat_id AND prof_id=$prof_id");
			}
		break;
	case 'supprimer_temoin' :
		$resultat_id=$tparams[2];
		$prof_id=$tparams[3];
		query("DELETE FROM lrp WHERE resultat_id=$resultat_id AND prof_id=$prof_id");
		break;
	case 'supprimer_resultat' :
		$resultat_id=$tparams[2];
		query("DELETE FROM lrp WHERE resultat_id=$resultat_id");
		query("DELETE FROM resultats WHERE resultat_id=$resultat_id");
		break;
		
	}
	
header("Location: eleves_form.php?id=$index_liste&alafin=1#alafin");

	


?>