<?php
if($i==1) {
	mysqli_query($bdd,"INSERT INTO ".$prefix."_edtevent (uid, dtstart, dtend, hor_id, hor_name, week, brik_id, seq_id, specifique, duration) VALUES ('', '".$_POST['dtstart'.$h.$j.$usercode.$espid.'']."', '".$_POST['dtend'.$h.$j.$usercode.$espid.'']."', '".$_POST['hor_id'.$h.$j.$usercode.$espid.'']."', '".$_POST['hor_name'.$h.$j.$usercode.$espid.'']."', '".$_POST['week'.$h.$j.$usercode.$espid.'']."', '".$idbrik."', '".$seq_id."', 0, 10)");
	if($i==1) {
		// récupération de l'uid pour passage dans table ".$prefix."_userevent :
		$uidup_select = "SELECT uid, dtstart, dtend FROM ".$prefix."_edtevent WHERE dtstart = '".$_POST['dtstart'.$h.$j.$usercode.$espid.'']."' AND dtend = '".$_POST['dtend'.$h.$j.$usercode.$espid.'']."' AND hor_id = '".$_POST['hor_id'.$h.$j.$usercode.$espid.'']."' AND week = '".$_POST['week'.$h.$j.$usercode.$espid.'']."' AND brik_id = '".$idbrik."' AND $seq_id = '".$seq_id."'";
	}
	else {
		// récupération de l'uid pour passage dans table ".$prefix."_userevent :
		$uidup_select = "SELECT uid, dtstart, dtend FROM ".$prefix."_edtevent WHERE dtstart = '".$dtstartplus."' AND dtend = '".$dtendplus."' AND hor_id = '".$_POST['hor_id'.$h.$j.$usercode.$espid.'']."' AND week = '".$moisplus."' AND brik_id = '".$idbrik."' AND $seq_id = '".$seq_id."'";
	}
	$uidup = mysqli_query($bdd,$uidup_select);
	$uid_info = mysqli_fetch_assoc($uidup);
	$uid = $uid_info['uid'];
	
	include('edt_userevent.php');
	include('edt_specevent.php');
}
else {
	
	//vérification que le jour est ouvré
	$statut = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT * FROM ".$prefix."_calendrier WHERE date = '".substr($dtstartplus,0,4)."-".substr($dtstartplus,4,2)."-".substr($dtstartplus,6,2)."'"));
	if($statut['statut']==1) {
		//insertion si jour ouvré
		mysqli_query($bdd,"INSERT INTO ".$prefix."_edtevent (uid, dtstart, dtend, hor_id, hor_name, week, brik_id, seq_id, specifique, duration) VALUES ('', '".$dtstartplus."', '".$dtendplus."', '".$_POST['hor_id'.$h.$j.$usercode.$espid.'']."', '".$_POST['hor_name'.$h.$j.$usercode.$espid.'']."', '".$moisplus."', '".$idbrik."', '".$seq_id."',0, 10)");
		if($i==1) {
			// récupération de l'uid pour passage dans table ".$prefix."_userevent :
			$uidup_select = "SELECT uid, dtstart, dtend FROM ".$prefix."_edtevent WHERE dtstart = '".$_POST['dtstart'.$h.$j.$usercode.$espid.'']."' AND dtend = '".$_POST['dtend'.$h.$j.$usercode.$espid.'']."' AND hor_id = '".$_POST['hor_id'.$h.$j.$usercode.$espid.'']."' AND week = '".$_POST['week'.$h.$j.$usercode.$espid.'']."' AND brik_id = '".$idbrik."' AND $seq_id = '".$seq_id."'";
		}
		else {
			// récupération de l'uid pour passage dans table ".$prefix."_userevent :
			$uidup_select = "SELECT uid, dtstart, dtend FROM ".$prefix."_edtevent WHERE dtstart = '".$dtstartplus."' AND dtend = '".$dtendplus."' AND hor_id = '".$_POST['hor_id'.$h.$j.$usercode.$espid.'']."' AND week = '".$moisplus."' AND brik_id = '".$idbrik."' AND $seq_id = '".$seq_id."'";
		}
		$uidup = mysqli_query($bdd,$uidup_select);
		$uid_info = mysqli_fetch_assoc($uidup);
		$uid = $uid_info['uid'];
		include('edt_userevent.php');
		include('edt_specevent.php');
	}
}
?>
