<?php
//----------------------------------------------------------------
// Voici un petit calendrier qui affiche entre autre,les numeros 
// de semaine, tous les jours feries, les week end ...
//
// Version 1.0
//
// Auteur: Patrice FROMHOLTZ
// email: webmaster@lafoireinformatique.com
// web: http://www.lafoireinformatique.com/
//
//----------------------------------------------------------------
?>

<style TYPE="text/css">
	<!--
	.titremois {
		font-family: Helvetica, Arial;
		font-size: 13px;
		font-weight: bold;
		color: #FDFC65;
		background: #1C2D67
	}

	.titremois:link {
		font-family: Helvetica, Arial;
		font-size: 13px;
		font-weight: bold;
		color: #FDFC65;
		background: #1C2D67;
		text-decoration: none
	}

	.titremois:visited {
		font-family: Helvetica, Arial;
		font-size: 13px;
		font-weight: bold;
		color: #FDFC65;
		background: #1C2D67;
		text-decoration: none
	}

	.titremois:hover {
		font-family: Helvetica, Arial;
		font-size: 13px;
		font-weight: bold;
		color: #FF0000;
		background: #1C2D67;
		text-decoration: underline
	}

	.titrejours {
		font-family: Helvetica, Arial;
		font-size: 9px;
		color: #FDFC65;
		background: #1C2D67
	}

	.titrenum {
		font-family: Helvetica, Arial;
		font-size: 11px;
		color: #FDFC65;
		background: #1C2D67
	}

	.titrenum2 {
		font-family: Helvetica, Arial;
		font-size: 11px;
		color: #AAAAAA;
		background: #1C2D67
	}

	.titreweek {
		font-family: Helvetica, Arial;
		font-size: 9px;
		color: #AAAAAA;
		background: #1C2D67
	}

	.titreweek2 {
		font-family: Helvetica, Arial;
		font-size: 11px;
		color: #AAAAAA;
		background: #1C2D67
	}

	.titrewend {
		font-family: Helvetica, Arial;
		font-size: 11px;
		color: #FDFC65;
		background: #5060A0
	}

	.titrewend2 {
		font-family: Helvetica, Arial;
		font-size: 11px;
		color: #AAAAAA;
		background: #5060A0
	}

	.titrenow {
		font-family: Helvetica, Arial;
		font-size: 11px;
		color: #FDFC65;
		background: #90A0E0
	}
	-->
</style>
<?php
function calcul_joursferies($month, $day, $year)
{
	$resultat = false;

	$jf1 = $year - 1900;
	$jf2 = $jf1 % 19;
	$jf3 = intval((7 * $jf2 + 1) / 19);
	$jf4 = (11 * $jf2 + 4 - $jf3) % 29;
	$jf5 = intval($jf1 / 4);
	$jf6 = ($jf1 + $jf5 + 31 - $jf4) % 7;
	$jfj = 25 - $jf4 - $jf6;
	$jfm = 4;
	if ($jfj <= 0) {
		$jfm = 3;
		$jfj = $jfj + 31;
	}


	$paques = (($jfm < 10) ? "0" . $jfm : $jfm) . "/" . (($jfj < 10) ? "0" . $jfj : $jfj);
	$lunpaq = date("m/d", mktime(12, 0, 0, $jfm, $jfj + 1, $year));
	$ascension = date("m/d", mktime(12, 0, 0, $jfm, $jfj + 39, $year));
	$lunpent = date("m/d", mktime(12, 0, 0, $jfm, $jfj + 50, $year));

	$JourFerie = array("01/01", "05/01", "05/08", "08/01", "08/15", "11/01", "11/11", "12/25", "$paques", "$lunpaq", "$ascension", "$lunpent");

	$nbj = 0;
	$val =	$lien = date("m/d", mktime(0, 0, 0, $month, $day, $year));
	while ($nbj <= count($JourFerie)) {

		if ($JourFerie[$nbj] == $val) {
			$resultat = true;
			$nbj = 15;
		}
		$nbj++;
	}
	return ($resultat);
}


$tabmonth  = array("Janvier", "F&eacute;vrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Ao&ucirc;t", "Septembre", "Octobre", "Novembre", "D&eacute;cembre");
$tabday  = array("Lun", "Mar", "Mer", "Jeu", "Ven", "Sam", "Dim");

// selectionne la date d aujourd hui si aucune saisie
if (!$dt) {
	$year = date("Y");
	$now   = date("Y/m/d");
	$month  = date("n");
	$day = date("d");
} else {
	$data = explode(" ", $dt);
	$year = $data[0];
	$month = $data[1];
	$day = $data[2];
	$now = date("Y/m/d", mktime(0, 0, 0, $month, $day, $year));
}
$moyear = $tabmonth[$month - 1] . "&nbsp;&nbsp;" . $year;
?>

<table WIDTH="160" BORDER="0" CELLSPACING="0" CELLPADDING="2">
	<tr>
		<td CLASS='titremois' colspan="8" ALIGN="center">
			<?php
			$lien = date("Y+m+d", mktime(0, 0, 0, $month - 1, $day, $year));
			echo "<A CLASS='titremois' href=\"?dt=$lien\"><<</a>";

			echo "<A CLASS='titremois'>&nbsp;$moyear&nbsp;</a>";

			$lien = date("Y+m+d", mktime(0, 0, 0, $month + 1, $day, $year));
			echo "<A CLASS='titremois' href=\"?dt=$lien\">>></a>";
			?>
		</td>
	</tr>

	<tr>
		<?php
		echo "<td WIDTH=20 class='titreweek' ALIGN='center'>Sem</td>\n";
		for ($i = 0; $i < 7; $i++) {
			echo "<td WIDTH=20 class='titrejours' ALIGN='center'>$tabday[$i]</td>\n";
		}
		?>
	</tr>

	<?php
	$num_day = date("w", mktime(0, 0, 0, $month, 01, $year));
	if ($num_day == 0) {
		$num_day = 7;
	}
	$max_day = date("t", mktime(0, 0, 0, $month, 01, $year));
	$cpt_day = 2;
	while ($cpt_day <= $max_day + $num_day) {
		echo "<tr>";

		// calcul le numero de semaine

		$nb_day = date("z", mktime(0, 0, 0, $month, $cpt_day - $num_day + 3, $year));
		$val = intval($nb_day / 7) + 1;
		echo "<td WIDTH=20 class='titreweek2' ALIGN='center'>" . (($val < 10) ? "0" . $val : $val) . "</td>\n";

		// affiche les jours du mois

		for ($i = 0; $i < 7; $i++) {
			$theday = date("D", mktime(0, 0, 0, $month, $cpt_day - $num_day, $year));
			$val = date("d", mktime(0, 0, 0, $month, $cpt_day - $num_day, $year));
			$jourferie = calcul_joursferies($month, $cpt_day - $num_day, $year);
			$class = "titrenum";
			if (($theday == "Sun") or ($theday == "Sat") or ($jourferie)) {
				$class = "titrewend";
			}
			if ($now == date("Y/m/d", mktime(0, 0, 0, $month, $cpt_day - $num_day, $year))) {
				$class = "titrenow";
			}
			if ((($cpt_day - $num_day) < 1) or (($cpt_day - $num_day) > $max_day)) {
				$class = "titrenum2";
				if (($theday == "Sun") or ($theday == "Sat") or ($jourferie)) {
					$class = "titrewend2";
				}
			}
			$cpt_day++;
			echo "<td WIDTH=20 class='$class'ALIGN='center'>" . $val . "</td>\n";
		}
		echo "</tr>";
	}
	?>

</table>