Location: PHPKode > projects > EmploiNet : a timetable web manager > EmploiNet/v0.8.0/Administration/vacances.php3
<?

/* --- F. Nolot : De nombreuses modifications ont été faites pour les affichages des calendriers */
function affiche_month($first_day, $last_day, $month,$year,$id_promotion) { 
	// Auteur : F. Nolot
	// Paramètre : si $last_day == -1, affiche jusqu'au dernier jour du mois
    $holidays_days     = "#00FF00"; 

	setlocale(LC_TIME,"fr");	
	echo "<table align=\"center\" border=\"1\">\n";
     echo "<tr class=\"vacances\">\n<th colspan=\"8\">" . strftime("%B",mktime(0,0,0,$month,$first_day,$year)) . " " . strftime("%Y",mktime(0,0,0,$month,$first_day,$year)) . "</th>\n</tr>\n";
     echo "<tr class=\"vacances\">\n<th>Sem.</th>\n";
     echo "<th>Lu</th>\n";
     echo "<th>Ma</th>\n";
     echo "<th>Me</th>\n";
     echo "<th>Je</th>\n";
     echo "<th>Ve</th>\n";
     echo "<th>Sa</th>\n";
     echo "<th>Di</th>\n</tr>\n";
	 
	$num_day_week=strftime("%w",mktime(0,0,0,$month,$first_day,$year)); // numero du jour de la semaine (Lu=1, ... Sa=6, Dim=0)
	if ($num_day_week==0) $num_day_week=7;
	$num_week=strftime("%W",mktime(0,0,0,$month,1,$year))+1; //numero de la premiere semaine du mois
	
	//Calcul du nombre de jour dans le mois
			$jourmois[1]=31;
	    	$jourmois[2]=31+29;
			if (moisx($jourmois[2],$year) == 2) $jourmois[2]=29; else $jourmois[2]=28;
			$jourmois[3]=31;
			$jourmois[4]=30;
			$jourmois[5]=31;
			$jourmois[6]=30;
			$jourmois[7]=31;
			$jourmois[8]=31;
			$jourmois[9]=30;
			$jourmois[10]=31;
			$jourmois[11]=30;
			$jourmois[12]=31;

	$nb_gris=strftime("%w",mktime(0,0,0,$month,1,$year));
	if ($nb_gris==0) $nb_gris=7;
	$j=1; //pour compter le nombre de cases grises placées au début du calendrier
	$day=2-$nb_gris;
	
	if ($last_day == -1) $last_day=$jourmois[$month];
	while ($day<=$jourmois[$month]) {
		$i=1;
		echo "<tr class=\"vacances\">\n<td>$num_week </td>\n";
		while ($i<8) {
			if ( ($day <= $last_day) && ($day >= $first_day)) {
				$currdate=mktime(0,0,0,$month,$day,$year);
				// calcul des jours de vacances
				$k=date("j",$currdate);
			   	$m=date("m",$currdate);
			   	$a=date("Y",$currdate);
			
				// Recherche dans la base
				$madate="$a/$m/$k";
			 	$result=mysql_query("SELECT * FROM vacances,suivrevacances WHERE suivrevacances.id_promotion=$id_promotion[0] AND vacances.id_vacances=suivrevacances.id_vacances AND TO_DAYS('$madate')<=TO_DAYS(date_fin) AND TO_DAYS('$madate')>=TO_DAYS(date_debut)");
		 		$found=(mysql_num_rows($result)>0);
				
			 	if ($found) {
					$bgcolor=$holidays_days;
					echo "<td bgcolor=\"$bgcolor\">";
					echo "<a href=\"javascript:document.f1.selected.value=1;";
				}
			 	else {
					echo "<td>";
					echo "<a href=\"javascript:document.f1.selected.value=0;"; 
				}
		     	echo "document.f1.choix.value=1; ";
			 	echo "document.f1.jour.value=$k; document.f1.mois.value=$m; document.f1.annee.value=$a; ";
			 	echo "document.f1.submit();\">";
				echo "$day</a></td>\n";
				
				}
			else { // le jour ne fait pas parti de la période
				if ($j<$nb_gris || $day >$jourmois[$month] ) {
					echo "<td><img src=\"img/gris.gif\"></td>\n";
					$j++;
				} else { if ($day < $first_day || ($day>$last_day)) echo "<td bgcolor=\"#C0C0C0\">$day</td>\n"; }
			}
			$i++;
			$day++;
		}
		$num_week++;
		echo "</tr>\n";
	}
	echo "</table>\n";
}

// INCLUDE 
    
    include("../BarreDeMenu.php3");
    
    include("../date.php3");
    include("../Session/security.php");

// Définition de variables globales
	$G_id_promotion;
	$G_id_periode;

// Entete
    buildHeader("Vacances");

// Verification de la session
	$autorisation_list[0]=0; // Administrateur
	$autorisation_list[1]=3; // Gestionnaire
	$user_type = validateSession($id_session);
	if ($user_type == -1 || !security($id_session,$autorisation_list)) print("Accès refusé");
    else
    {
// Barre de menu
		buildMenuBar($id_session,$user_type,"vacances.php3",false);
// Determination du user_id
		$user_id = getUserID($id_session);
// Ouverture de la connexion avec la base de donnees
	    $connection = openConnection($databaseName);

	if (isset($id_promotion)) $n = count($id_promotion); // nombre de promotions selectionnees
    else $n = 0;
	
	switch ($choice)
	{
		case -1: // changement de promotion
		{
			unset($id_periode);
			break;
		}
	}

		echo "<form action=vacances.php3 method=post>\n";
		echo "	<input type=hidden name=\"choix\" value=\"0\">\n";
		echo "	<input type=hidden name=\"choice\" value=\"-1\">\n";
		echo "	<input type=hidden name=\"id_session\" value=\"$id_session\">\n";

		print("  <table align=\"center\" border=\"0\" cellspacing=\"0\" cellpading=\"0\" width=\"700\" bgcolor=\"#C0C000\">\n");
		print("        <tr>\n");
// Liste des promotions	
        print("          <td valign=top width=100 nowrap ><font size=3><i>Promotion :</i></font></td>\n");
	    print("          <td width=250 >\n");
        include("../Liste/liste_promotion.php");
	    print("          </td>\n");
// Periode
	    print("          <td valign=top width=100 nowrap><font size=3><i>P&eacute;riode :</i></font></td>\n");
        print("          <td valign=top width=250>\n");
        include("../Liste/liste_periode.php");
	    print("          </td>\n");
	    print("        </tr>\n"); 

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

// Traitement des modifications des vacances	
		if ($choix==1) // Clic sur un jour => mise a jour de la base
 		{
			if ($mois<10)
				$madate="'$annee-0$mois-$jour'";
			else
				$madate="'$annee-$mois-$jour'";
				
// Ce jour n'est pas encore un jour de vacances			
			if ($selected==0)
			{
// Existe-t-il une periode de vacances juste avant le jour selectionne ?
				$result1=mysql_query("SELECT vacances.id_vacances FROM vacances,suivrevacances WHERE suivrevacances.id_promotion=$id_promotion[0] AND vacances.id_vacances=suivrevacances.id_vacances AND TO_DAYS($madate)-1=TO_DAYS(date_fin)");
// Oui				
				if (mysql_num_rows($result1)>0)
				{
// Existe-t-il une periode de vacances juste apres le jour selectionne ?
					$result2=mysql_query("SELECT vacances.id_vacances,vacances.date_debut,vacances.date_fin FROM vacances,suivrevacances WHERE suivrevacances.id_promotion=$id_promotion[0] AND vacances.id_vacances=suivrevacances.id_vacances AND TO_DAYS($madate)+1=TO_DAYS(date_debut)");
// Oui, alors fusion de deux periodes de vacances
					if (mysql_num_rows($result2)>0)
					{
						$row1=mysql_fetch_row($result1);
						$row2=mysql_fetch_row($result2);
						mysql_query("UPDATE vacances SET date_fin='".$row2[2]."' WHERE id_vacances=$row1[0]");
						mysql_query("DELETE FROM vacances WHERE id_vacances=$row2[0]");					
						mysql_query("DELETE FROM suivrevacances WHERE id_vacances=$row2[0]");					
					}
					else
					{
						$row=mysql_fetch_row($result1);
						$result=mysql_query("UPDATE vacances SET date_fin=$madate WHERE id_vacances=$row[0]");
					}
				}
// Non
				else
				{
// Existe-t-il une periode de vacances juste apres le jour selectionne ?
					$result2=mysql_query("SELECT vacances.id_vacances FROM vacances,suivrevacances WHERE suivrevacances.id_promotion=$id_promotion[0] AND vacances.id_vacances=suivrevacances.id_vacances AND TO_DAYS($madate)+1=TO_DAYS(date_debut)");
// Oui				
					if (mysql_num_rows($result2)>0)
					{
						$row=mysql_fetch_row($result2);
						$result=mysql_query("UPDATE vacances SET date_debut=$madate WHERE id_vacances=$row[0]");
					}	
// Non, alors c'est une nouvelle periode de vacances !
					else
					{
						$res=mysql_query("SELECT id_vacances from id");
						$row=mysql_fetch_row($res);
						$id=$row[0]+1;
						mysql_query("UPDATE id SET id_vacances=$id");
						
						mysql_query("INSERT INTO vacances values ($id,$madate,$madate)");
						mysql_query("INSERT INTO suivrevacances values ($id_promotion[0],$id)");
					}	
				}
			}
// Ce jour est deja un jour de vacances			
			else
			{
// Le jour deselectionne correspond-t-il a une fin de periode ?
				$result1=mysql_query("SELECT vacances.id_vacances FROM vacances,suivrevacances WHERE suivrevacances.id_promotion=$id_promotion[0] AND vacances.id_vacances=suivrevacances.id_vacances AND TO_DAYS($madate)=TO_DAYS(date_fin)");
// Oui
				if (mysql_num_rows($result1)>0)
				{
					$row=mysql_fetch_row($result1);
					$result=mysql_query("UPDATE vacances SET date_fin=FROM_DAYS(TO_DAYS($madate)-1) WHERE id_vacances=$row[0]");
				}
// Non
				else
				{
// Le jour deselectionne correspond-t-il a une fin de periode ?
					$result2=mysql_query("SELECT vacances.id_vacances FROM vacances,suivrevacances WHERE suivrevacances.id_promotion=$id_promotion[0] AND vacances.id_vacances=suivrevacances.id_vacances AND TO_DAYS($madate)=TO_DAYS(date_debut)");
// Oui
					if (mysql_num_rows($result2)>0)
					{
						$row=mysql_fetch_row($result2);
						$result=mysql_query("UPDATE vacances SET date_debut=FROM_DAYS(TO_DAYS($madate)+1) WHERE id_vacances=$row[0]");
					}	
// Non alors la periode est divisee en deux
					else
					{
						$result3=mysql_query("SELECT vacances.date_debut,vacances.id_vacances FROM vacances,suivrevacances WHERE suivrevacances.id_promotion=$id_promotion[0] AND vacances.id_vacances=suivrevacances.id_vacances AND TO_DAYS($madate)<TO_DAYS(date_fin) AND TO_DAYS($madate)>TO_DAYS(date_debut)");
						if (mysql_num_rows($result3)>0)
						{
							$res=mysql_query("SELECT id_vacances from id");
							$row=mysql_fetch_row($res);
							$id=$row[0]+1;
							mysql_query("UPDATE id SET id_vacances=$id");
							
							$row=mysql_fetch_row($result3);
// Creation de la premiere plage
							mysql_query("INSERT INTO vacances values ($id,'$row[0]',FROM_DAYS(TO_DAYS($madate)-1))");
							mysql_query("INSERT INTO suivrevacances values ($id_promotion[0],$id)");
// Modification de la date de debut pour la creation de la deuxieme plage
							mysql_query("UPDATE vacances SET date_debut=FROM_DAYS(TO_DAYS($madate)+1) WHERE id_vacances=$row[1]");
						}		
					}
				}
			}
		}
		if (isset($id_promotion) && isset($id_periode)) {
			echo "<form action=vacances.php3 name=\"f1\" method=post>";
			echo "<input type=hidden name=\"jour\">\n";
			echo "<input type=hidden name=\"mois\">\n";
			echo "<input type=hidden name=\"annee\">\n";
			echo "<input type=hidden name=\"choix\" value=0>\n";
			echo "<input type=hidden name=\"selected\">\n";
			echo "<input type=hidden name=\"styear\" value=$styear>\n";
			echo "<input type=hidden name=\"stsem\" value=$stsem>\n";
			echo "<input type=hidden name=\"id_session\" value=$id_session>\n";
			echo "<input type=hidden name=\"id_promotion\" value=$id_promotion[0]>\n";
			echo "<input type=hidden name=\"id_periode\" value=$id_periode>\n";

			print("<TABLE align=\"center\"><TR>\n");
// Determination de l'annee courante
			$result=mysql_query("SELECT annee FROM global");
			$row=mysql_fetch_row($result);
			$year=$row[0];
// Determination des semaines de la periode selectionne
			$request = "SELECT numero_semaine_debut,nb_semaines FROM periode WHERE id_periode = $id_periode";
			$result = mysql_query($request);
			$a_record = mysql_fetch_array($result);
// Determination du premier et du dernier mois
			$first_week = $a_record["numero_semaine_debut"];
			$last_week = $first_week+$a_record["nb_semaines"];
			if ($last_week>52) $last_week-=52;
			
// --- Auteur : F. Nolot	
			$first_day = strftime("%w",mktime(0,0,0,1,1,$year));
			if ( $first_day == 0 ) $first_day=7;
			if ($first_week>1) { 
				$first_day = 7-$first_day+2+($first_week-2)*7; // eieme jour de la periode
				$first_month=moisx($first_day,$year);		
			}
			else {
				$first_day=1;
				$first_month=1;
			}
			$first_day=jourmoisx($first_day,$year); // retourne le numero du jour dans le mois
			
			$last_day = strftime("%w",mktime(0,0,0,1,1,$year));
			if ( $last_day == 0 ) $first_day=7;
			if ($last_week>1) { 
				$last_day = 7-$last_day+2+($last_week-2)*7; // eieme jour de la periode
				$last_month=moisx($last_day,$year);		
			}
			else {
				$last_day=1;
				$last_month=1;
			}
			$last_day=jourmoisx($last_day,$year)-1; // retourne le dernier jour de la derniere semaine de la periode
			
// Affichage des calendriers
			$j = $first_month;
			$m = 0;
			$nb_cal = 0;
			$stop=false;
			while (!$stop)
			{
				if ($m==0) echo "<tr>";
				print("<TD>");
				if ($nb_cal == 0 ) affiche_month($first_day, -1, $j,$year,$id_promotion);
				else { 
					if ($j==$last_month)
						affiche_month(1, $last_day, $j,$year,$id_promotion);
					else 
						affiche_month(1, -1, $j,$year,$id_promotion);
				}
    			print("</TD>");
				$m++;
				$nb_cal++;
				if ($m==3)
				{
					print("</TR>");
					$m=0;
				}	
				$stop=($j==$last_month);
				$j++;
				if ($j>12) 
				{
					$j=1;
					$year++;
				}
	 		}
		echo "</table>";

// ---			

		}
	}
	
	buildEndOfPage();
?>
Return current item: EmploiNet : a timetable web manager