<?php 
session_start();
require_once(dirname(__DIR__, 2) . '/config.php');
require_once(BASE_PATH . '/db/idl_connect.php');
if(isset($_SESSION['user_droits'])) {
	if($_REQUEST['param']=='exclusup') {
		mysqli_query($bdd,"DELETE FROM ".$prefix."_exclusions WHERE exclusion_id = '".$_REQUEST['exclu_id']."'");
	}
	else if($_REQUEST['param']=='exclumod') {
		$string_activs = "";
		$activ = mysqli_query($bdd,"SELECT * FROM ".$prefix."_freqactiv WHERE code_activ <> 'ZERO' ORDER BY nom_activ ASC");
		foreach($activ as $check_activ) {
			if($_REQUEST[$check_activ['code_activ']]==1) {
				$string_activs .= $check_activ['code_activ'].'-';
			}
		}		
		mysqli_query($bdd,"UPDATE ".$prefix."_exclusions SET exclucause_id = '".$_REQUEST['excraison']."', date_info = '".$_REQUEST['date_info']."', date_fin = '".$_REQUEST['date_fin']."', excluactivs = '".$string_activs."' WHERE exclusion_id = '".$_REQUEST['exclu_id']."'");				
	}
	else if($_REQUEST['param']=='limitsup') {
		mysqli_query($bdd,"DELETE FROM ".$prefix."_limits WHERE limit_id = '".$_REQUEST['limit_id']."'");
	}
	else if($_REQUEST['param']=='limitmod') {
		if(mysqli_num_rows(mysqli_query($bdd,"SELECT * FROM ".$prefix."_limitstxt WHERE limits_txt = '".$_REQUEST['limraison']."' AND espace_id = '".$_REQUEST['limlieu']."'"))==0) {						
			$texte = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT * FROM ".$prefix."_limitstxt WHERE limits_txt = '".$_REQUEST['limraison']."'"));
			mysqli_query($bdd,"INSERT ".$prefix."_limitstxt (limittxt_id, limits_txt, espace_id) VALUES ('', '".$texte['limits_txt']."', '".$_REQUEST['limlieu']."')");
			$checked = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT * FROM ".$prefix."_limitstxt WHERE limits_txt = '".$texte['limits_txt']."' AND espace_id = '".$_REQUEST['limlieu']."'"));
			mysqli_query($bdd,"UPDATE ".$prefix."_limits SET limittxt_id = '".$checked['limittxt_id']."', date_fin = '".$_REQUEST['date_fin']."' WHERE limit_id = '".$_REQUEST['limit_id']."'");
		}
		else {
			$checked = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT * FROM ".$prefix."_limitstxt WHERE limits_txt = '".$_REQUEST['limraison']."' AND espace_id = '".$_REQUEST['limlieu']."'"));
			mysqli_query($bdd,"UPDATE ".$prefix."_limits SET limittxt_id = '".$checked['limittxt_id']."', date_fin = '".$_REQUEST['date_fin']."' WHERE limit_id = '".$_REQUEST['limit_id']."'");
		}		
	}
	else if($_REQUEST['param']=='supfreq') {
		mysqli_query($bdd,"DELETE FROM ".$prefix."_freq WHERE freq_id = '".$_REQUEST['freq_id']."'");
	}
	else if($_REQUEST['param']=='delfromgr') {
		mysqli_query($bdd,"DELETE FROM ".$prefix."_groupele WHERE eleves_id = '".$_REQUEST['eleve_id']."' AND groupe_id = '".$_REQUEST['groupe_id']."'");
	}
}
mysqli_close($bdd);
?>