Bonjour,
Je viens vers vous pour m'aider à implémenter le système prev/next sur mon calendrier.
Ayant cherché sur grafikart, j'ai pu trouver une adaptation faite par "estragon" dans les commentaires de la vidéo.
Mais il y a un grand HIC, c'est que ça n'affiche que les mois de l'année en cours et s'arrête en décebre 2014 sans aller à janvier 2015 ,et pas les années précédentes ni suivantes, bien qu'il y a des évènements dans les mois de 2013 et 2015 dans la bdd.
voici les codes:
index.php
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html"; charset="UTF-8">
<title>calendrier</title>
<link type="text/css" rel="stylesheet" href="style.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
jQuery(function($){
var Tmonth = new Date();
var month = Tmonth.getMonth()+1
$('.month').hide();
$('#month'+month).show();
$('.months a').hide();
$('#linkMonth'+month).show();
$('#linkMonth'+month).addClass('active');
var current = month;
var up = current+1;
$('#month'+current).slideUp();
$('#month'+up).slideDown();
$('.month').hide();
$('#month'+up).show();
$('#linkMonth'+current).hide();
$('#linkMonth'+up).show();
$('.months a#linkMonth'+current).removeClass('active');
$('.months a#linkMonth'+up).addClass('active');
current = up;
if($('.months a:last').hasClass('active').toString() == 'true'){
$('#up').hide();
}else $('#up').show();
$('#down').show();
return false;
});
$('#down').click(function(){
var down = current-1;
$('#month'+current).slideUp();
$('#month'+down).slideDown();
$('.month').hide();
$('#month'+down).show();
$('#linkMonth'+current).hide();
$('#linkMonth'+down).show();
$('.months a#linkMonth'+current).removeClass('active');
$('.months a#linkMonth'+down).addClass('active');
current = down;
if($('.months a:first').hasClass('active').toString() == 'true'){
$('#down').hide();
}else $('#down').show();
$('#up').show();
return false;
});
});
</script>
</head>
<body>
<?php
require ('date.php');
require ('config.php');
$date = new Date();
$year = date('Y');
$dates = $date->getAll($year);
$events = $date->getevents($year);
?>
<div class="periods">
<div class="year"><?php echo $year; ?></div>
<!--- rajout -->
<div id="mois">
<a href="#" id="down"> < </a>
<div class="months">
<ul>
<?php foreach ($date->months as $id=>$m): ?>
<li><a href="#" id="linkMonth<?php echo $id+1; ?>"><?php echo utf8_encode(utf8_decode($m)); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<a href="#" id="up"> > </a>
</div>
<!--- rajout -->
<div class="clear"></div>
<?php $dates = current($dates); ?>
<?php foreach ($dates as $m => $days): ?>
<div class="month relative" id="month<?php echo $m; ?>">
<table>
<thead>
<tr>
<?php foreach ($date->days as $d): ?>
<th><?php echo substr($d,0,8); ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<tr>
<?php $end = end($days); foreach($days as $d => $w): ?>
<?php $time = strtotime("$year-$m-$d"); ?>
<?php if ($d == 1 and $w != 1): ?>
<td colspan="<?php echo $w - 1; ?>" class="padding"></td>
<?php endif; ?>
<td <?php if ($time == strtotime(date('Y-m-d'))): ?> class="today" <?php endif; ?>>
<div class="relative">
<div class="day"><?php echo $d; ?></div>
</div>
<div class="daytitle">
<?php echo $date->days[$w-1] ?> <?php echo $d ?> <?php echo $date->months[$m-1] ?>
</div>
<ul class="events">
<?php if (isset ($events[$time])): foreach($events[$time] as $e):?>
<li ><?php echo $e ?> </li>
<?php endforeach; endif; ?>
</ul>
</td>
<?php if ($w == 7): ?>
</tr>
<tr>
<?php endif; ?>
<?php endforeach; ?>
<?php if ($end != 7): ?>
<td colspan="<?php echo 7 - $end; ?>" class="padding"></td>
<?php endif; ?>
</tr>
</tbody>
</table>
</div>
<?php endforeach; ?>
</div>
</body>
</html>
date.php
class Date{
var $days = array('Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi','Dimanche');
var $months = array('Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre');
function getEvents($year){
global $DB;
// Pour la requete ajoutez heure dans le select
$req = $DB->query('SELECT id,title,date FROM events WHERE YEAR(date)='.$year);
$r = array();
while($d = $req->fetch(PDO::FETCH_OBJ))
{
$r[strtotime($d->date)][$d->id]=$d->title ;
}
return $r;
}
function getAll($year){
$r = array();
$date = new DateTime($year.'-01-01');
while($date->format('Y') <= $year){
$y=$date->format('Y') ;
$m=$date->format('n') ;
$d=$date->format('j') ;
$w=str_replace('0','7', $date->format('w') );
$r[$y][$m][$d]= $w;
$date->add(new DateInterval('P1D'));
}
return $r;
}
}
?>
Le tutoriel est très bien fait et j'ai cherché sur le web, il n'y a pas d"équivalent. Seulement, cette possibilitè de naviguer à trevers des liens mois-précedent/mois-suivant sur plusieures années lui fait défaut. Et ce serais le bouquet final si , avec votre aide on pourrait lui apporter cette touche.
Y-a-t-il possibilité de fusionner la div id="mois" et la div class="year" en une seule genre
<< Décembre 2014 >>
Bonjour.
C'est normal puisque déjà là :
$year = date('Y');
C'est défini à l'année courante et vu que dans la requête de la BDD :
WHERE YEAR(date)='.$year
Il est indiqué de retourner tous les enregistrements de l'année courante, tu ne peux donc pas avoir des enregistrements retournés ni pour l'année précédente, ni pour la suivante.
Bonjour Lartak
Merci pour ton éclaircissement et ta réactivité.
et comment faire alors? stp
Au vu de tes remarques, peut-être qu'il faudrait chambouler tout le code?
De rien.
Pour commencer, tu ne dois pas restreindre au niveau de la requête en BDD les enregistrements à l'année courante.
Il faudrait que tu modifies le système, mais je ne peux pas te donner un exemple spécifique, il y a deux possibilités.
possibilité 1: signifie-t-elle un rechargement de page à chaque prev ou next ?
Excuse-moi, je suis assez débutant ,alors la 2ème possibilité me donne des frissons car je n'y connais strictement rien en ajax/json.
Grosso modo, avec le script de grafikart, y a-t-il moyen de faire comme cet agenda:
`http://www.faccnyc.org/`` ?
Oui, le premier cas il y a rechargement de la page pour que le/les paramètre(s) passés par l'URL soient interprétés par le serveur.
Oui, c'est possible, sauf que si tu veux faire à quelque chose près le même système, tu vas avoir plus de chose à modifier.
À savoir que sur le site que tu me montre, à chaque clic pour un changement de mois, le serveur fait une requête de type post, ce qui veut dire qu'il n'y a que les données d'un mois qui sont retournés, contrairement au code du Tutoriel qui retourne toutes les données pour une année complète.
Tu aurais donc des modifications à faire autant du côté javascript, que du côté PHP.
Merci Lartak.
Je crois que je vais sursoir à ce module d'agenda, faute de pouvoir avancer.
Pour récapituler , si je ne veux pas rafraîchir toute ma page pour un module somme toute petit, je dois passer mes paramètres en post, et pour cela, j'aurais besoin de Ajax et Json ? Est-ce exact ?
En attendant, je cherche sur le web un script similaire à celui du site en exemple (www.faccnyc.org) et si vous avez des pistes, n'hésitez pas à partager.
Bien à vous.
Passer une requête en post n'est pas obligatoire, elle peut aussi être passée en get, je t'ai juste dit la manière qu'ils utilsaient sur le site dont tu m'as montré en exemple.
Mon souci est que ma page (d'accueil) est bourrée de modules( 4 slideshows, lecteur vidéo html, formulaires,et plus...) qui consomment beaucoup de requêtes, et je ne veux pas qu'elle se rafraîchisse juste pour des prev next de l'agenda. Donc la méthode get est à éviter autant que possible.
Je me penche sur les tutos de grafikart et sdz pour voir si je pourrais m'en sortir avec de l'Ajax/Json
bonjour?Tu peux mettre ta page d'acceuil en cache ou soit faire un lien vers une autre page qui charge le calendrier ou faire une requête ajax que ce soit en get ou en post ca devrait marcher.Et puis le post c'est généralement pour les sauvegardes en base de donné et autre .Pour afficher des données en les prenant dans une base de données,je pense que le get te suffit amplement puisque c'est ca moi j'utilise depuis
Bonjour Lartak, bonjour daemon24
Ok , vous m'avez bien expliqué et convaincu de la méthode get, ce dont je vous remercie .
Alors une ébauche d'adaptation du script de grafikart pour un système mois précédent / mois suivant sur 2 années antécédentes et 2 années ultérieures à 2015 m'aiderait beaucoup.
Je ne demande pas un code complet car , en cherchant à apprendre , on arrive à faire des adaptations personnelles et je suis prêt à y aller de ma part.
Je peux te poser une question stp?Pourquoi tu n'utilise pas celui de jquery ui .Il le propose par defaut je me trompe pas.Et puis il a l'air tres complet
Petite question: jquery ui datepicker ou jquery fullcalendar?
NB: ce n'est pas d'un datepicker dont j'ai besoin à moins qu'il fasse aussi fonction de calendrier (agenda)
Je viens à l'instant de le classer car il n'interagit pas avec une bdd, les events sont fixés dans le script dans le <head> ou dans un fichier events.json pour la version defaul.html
Je dois pouvoir dénicher un script php avec des évènements stockés dans une base de données.
le seul qui ,à mon avis, fait l'affaire est www.calendarix.com pour le minical.php, mais il est trop compliqué, fait intervenir une dizaine de fichiers, et n'est plus à jour depuis 2008.
Bonjour,
J'ai trouvé un tutoriel : [https://www.youtube.com/watch?v=xjrVf_kMFl8]
mais au format US commençant par Sunday , et je voudrais le convertir au format français où la semaine commence par Lundi.
Quelqu'un pourrait-il me montrer comment?
Merci.
<!DOCTYPE html>
<html >
<head>
<meta charset="utf-8"/>
<!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<title> </title>
</head>
<body >
<?php
$day = date("j");
$month = date("n");
$year = date("Y");
//calendar variable
$currentTimeStamp = strtotime("$year-$month-$day");
//get current month name
$monthName = date("F",$currentTimeStamp);
//get how many days are there in the current month
$numDays = date("t",$currentTimeStamp);
//we need to set a variable to count cel in the loop later
$counter = 0;
?>
<table border='1'>
<tr>
<td><input style='width:50px;' type='button' value='<' name='previousbutton'></td>
<td colspan='5'><?php echo $monthName." , ".$year;?></td>
<td><input style='width:50px;' type='button' value='>' name='nextbutton'></td>
</tr>
<tr>
<!--<td width='50px'>Sun</td><td width='50px'>Mon</td><td width='50px'>Tue</td>
<td width='50px'>Wed</td><td width='50px'>Thu</td><td width='50px'>Fri</td><td width='50px'>Sat</td>-->
<td width='50px'>Lun</td><td width='50px'>Mar</td><td width='50px'>Mer</td>
<td width='50px'>Jeu</td><td width='50px'>Ven</td><td width='50px'>Sam</td><td width='50px'>Dim</td>
</tr>
<?php
echo "<tr>";
//make a for loop,looping from 1 to the number of days in the month
for($i = 1;$i < $numDays+1;$i++,$counter++){
//make timestamp for each day in the loop
$timeStamp = strtotime("$year-$month-$i");
//make a check if it is 'day 1'
if($i == 1){
//get witch day where 'day 1' fall on
$firstDay = date("w",$timeStamp);
/*
$firstDay = date("N",$timeStamp);
$firstDay=str_replace('1','0', date('w',$timeStamp));
*/
//make a loop and make a blank cell if it is not the first day
for($j = 0;$j < $firstDay;$j++,$counter++){
//blank space
echo "<td> </td>";
}
}
//make a check if the day is in the last column. If so ,we make a new row
if($counter % 7 == 0){
echo "</tr><tr>";
}
echo"<td align='cente'>".$i."</td>";
}
echo "</tr>";
?>
</table>
</body>
</html>
Je n'arrive pas à faire décaler les jours de la semaine d'un jour
Bonjour.
Si je comprends bien, tu n'as pas compris tous le code que tu as fais dans la page index.php du tutoriel du Calendrier en PHP, car il y a la manière de faire ce que tu demandes là, dans l'index.php du tutoriel.
Un conseil, avant de vouloir améliorer, modifier ou autre un script d'un tutoriel que tu as suivi, fais d'abord en sorte de comprendre ce que tu fais en relation au tutoriel.
Ok ok !, je reprends le tout doucement.
C'était juste histoire de gagner du temps. Mais de grâce, un début de solution ou une indication
Déjà , en modifiant cette ligne:
for($j = 0;$j < $firstDay;$j++,$counter++){
par:
for($j = 0;$j < $firstDay-1;$j++,$counter++){
ça marche pour certains mois.
Je creuse....et ne désépère pas
si je remplace:
if($i == 1){
//get witch day where 'day 1' fall on
$firstDay = date("w",$timeStamp);
//make a loop and make a blank cell if it is not the first day
for($j = 0;$j < $firstDay;$j++,$counter++){
//blank space
echo "<td> </td>";
}
}
par :
``
if($i == 1){
//get witch day where 'day 1' fall on
$firstDay = str_replace('0','1', date("w",$timeStamp));
//make a loop and make a blank cell if it is not the first day
for($j = 0;$j < $firstDay-1;$j++,$counter++){
//blank space
echo "<td> </td>";
}
}
ça marche pour certains mois.
Le problème se pose pour les mois débutant Dimanche.
Par exemple, pour 2015: février, mars et novembre.
Enfin, j'ai trouvé la solution :
if($i == 1){
//get witch day where 'day 1' fall on
$firstDay = date("N",$timeStamp);
//make a loop and make a blank cell if it is not the first day
for($j = 0;$j < $firstDay-1;$j++,$counter++){
//blank space
echo "<td> </td>";
}
}
Le sujet est résolu. Merci aux contributeurs
Je reprend le sujet pour poster un code complet que je pense pourrait aider les novices comme moi, tout en demandant une aide pour enlever une petite poussière ( un >) qui apparaîit sur les dates qui ont un event.
Après une semaine de labeur, j'ose espérer qu'une âme charitable m'ôterait ce grain disgrâcieux.
Sql:
``CREATE TABLE IF NOT EXISTS
eventcalender(
IDint(11) NOT NULL AUTO_INCREMENT,
Titlevarchar(65) NOT NULL,
Detailvarchar(255) NOT NULL,
eventDatevarchar(10) NOT NULL,
dateAddeddate NOT NULL, PRIMARY KEY (
ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=17 ;
INSERT INTO eventcalender
(ID
, Title
, Detail
, eventDate
, dateAdded
) VALUES
(1, 'testing add 31', 'this is a testing....', '01/25/2015', '2015-01-03'),
(2, 'testing add 31', 'this is a testing....', '12/31/2014', '2015-01-03'),
(4, 'testing add for 17 janvier 2015', 'tsssst tssssssst tsst', '01/17/2015', '2015-01-04'),
(14, 'first event in february', 'more details here', '02/12/2015', '2015-01-04'),
(15, 'second event in february', 'test 2 feb', '02/27/2015', '2015-01-04'),
(16, 'Second event du 17/01/2015', 'Here more details.....', '01/17/2015', '2015-01-07');
Calender.php:
```<?php
mysql_connect("localhost", "root", "") or die (mysql_error());
mysql_select_db("ghost03") or die (mysql_error());
?>
<html>
<head>
<link href="css/calender.css" media="screen" rel="stylesheet" type="text/css" />
<script>
function goLastMonth(month, year){
if(month == 1) {
--year;
month = 13;
}
--month
var monthstring= ""+month+"";
var monthlength = monthstring.length;
if(monthlength <=1){
monthstring = "0" + monthstring;
}
document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year;
}
function goNextMonth(month, year){
if(month == 12) {
++year;
month = 0;
}
++month
var monthstring= ""+month+"";
var monthlength = monthstring.length;
if(monthlength <=1){
monthstring = "0" + monthstring;
}
document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year;
}
</script>
</head>
<body>
<?php
if (isset($_GET['day'])){$day = $_GET['day'];} else {$day = date("j");}
if(isset($_GET['month'])){$month = $_GET['month'];} else {$month = date("n");}
if(isset($_GET['year'])){$year = $_GET['year'];}else{$year = date("Y");}
$currentTimeStamp = strtotime( "$day-$month-$year");
$mois = array("January"=>"Janvier", "February"=>"Février", "March"=>"Mars", "April"=>"Avril", "May"=>"Mai", "June"=>"Juin",
"July"=>"Juillet", "August"=>"Août", "September"=>"Septembre", "October"=>"Octobre", "November"=>"Novembre", "December"=>"Décembre");
$monthName = $mois[date("F", $currentTimeStamp)];
$numDays = date("t", $currentTimeStamp);
$counter = 0;
//get previous month
$prevMonth = $month - 1;
$prevYear = $year;
if($prevMonth <= 0){
$prevMonth = 12;
$prevYear--;
}
$pMonthStr = "" + $prevMonth;
if(strlen($pMonthStr) <= 1)
$pMonthStr = "0" + $pMonthStr;
//get num of day for previous month
$previousTimeStamp = strtotime( "01-$pMonthStr-$prevYear");
$prevNumDays = date("t", $previousTimeStamp);
//get the number of days in the current month and year
?>
<table>
<tr class="head-agenda">
<td class="prvnxt"><img src="css/prev-agenda-button.png" name='previousbutton' onclick ="goLastMonth(<?php echo $month.",".$year?>)"></td>
<td colspan='5'><?php echo $monthName." ".$year; ?></td>
<td class="prvnxt"><img src="css/next-agenda-button.png" name='nextbutton' onclick ="goNextMonth(<?php echo $month.",".$year?>)"></td>
</tr>
<tr class="days-agenda">
<td>LUN</td><td>MAR</td><td>MER</td><td>JEU</td><td>VEN</td><td>SAM</td><td>DIM</td>
</tr>
<tr class="all-agenda">
<?php
for($i = 1; $i < $numDays+1; $i++, $counter++){
$timeStamp = strtotime("$year-$month-$i");
if($i == 1) {
$firstDay = date("N", $timeStamp);
for($j = 0; $j < $firstDay-1; $j++, $counter++) {
$prevDay = $prevNumDays-$firstDay+$j+2;
echo "<td class='noactualmonth'>$prevDay</td>";
}
}
if($counter % 7 == 0) {
echo"</tr><tr class='all-agenda'>";
}
$monthstring = $month;
$monthlength = strlen($monthstring);
$daystring = $i;
$daylength = strlen($daystring);
if($monthlength <= 1){
$monthstring = "0".$monthstring;
}
if($daylength <=1){
$daystring = "0".$daystring;
}
$todaysDate = date("m/d/Y");
$dateToCompare = $monthstring. '/' . $daystring. '/' . $year;
echo "<td ";
if ($todaysDate == $dateToCompare){
echo "class ='today' ";
} else{
$sqlCount = "select * from eventcalender where eventDate='".$dateToCompare."'";
$noOfEvent = mysql_num_rows(mysql_query($sqlCount));
if($noOfEvent >= 1){
echo "class='event' ";
$sqlCount2 = "select * from eventcalender where eventDate='".$dateToCompare."'";
$resultat=mysql_query($sqlCount2);
echo "><ul>";
while($donnee=mysql_fetch_assoc($resultat)){
echo "<li>
<a href=\"agenda.php?id=".$donnee['ID']." \"> ".$donnee['Title']."</a>
</li>";
}
echo "</ul>";
}
}
echo ">".$i."</td>";
}
//fill counter
$fillCounter = 1;
//fill up the leftover cells of the table
while($counter % 7 != 0) {
//echo next month day
echo "<td class='noactualmonth'>$fillCounter</td>";
$fillCounter++;
$counter++;
}
?>
</tr>
</table>
</body>
</html>
Css:
table{ float:right;margin-right:25px;border-collapse:collapse;}
.today{color: red;}
.event{position: relative;background-color: #d5d5d5;}
.event:hover{background-color: #ea4744;color: #fff;}
td{text-align:center;width:40px;height:40px;}
tr.head-agenda{background-color:#0084b4;color:white;font-size: 1.3em;font-weight:bold;
font-family: oswald,'Source Sans Pro', OpenSans, DroidSans, 'Trebuchet MS', Arial, verdana, sans-serif;
}
td.noactualmonth{color:d9d9d9;}
tr.days-agenda{background-color: #d5d5d5;font-size: 14px;color: #333;
font-family: oswald,'Source Sans Pro', OpenSans, DroidSans, 'Trebuchet MS', Arial, verdana, sans-serif;
}
tr.all-agenda td{border: 1px solid #d9d9d9;
font-family: 'Source Sans Pro', OpenSans, DroidSans, 'Trebuchet MS', Arial, verdana, sans-serif;
}
td.prvnxt{cursor:pointer;}
td.prvnxt img{margin:0;padding:0;border:none;width:40px;}
td.event:hover ul {display: block;opacity: 1; visibility: visible;}
td.event ul {padding: 5px 5px;position: absolute;top: 16px;left: -163px;width: 150px;background: #fff;
box-shadow: -2px 2px 2px #b1b1b1;border: 1px solid #a9a9a9; display: none;opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
z-index:99999;
}
td.event ul li {background: #fff;display: block;text-align:left;padding: 5px 5px;}
td.event ul li a{text-decoration:none;color: #333;font-size: 14px;}
td.event ul li a:hover { text-decoration:underline;}
Je reprécise mon problème: sur chaque case de journée ayant une classe event apparaît un ">". Comment l'enlever?
Merci
On dirait que tu as l'air soulagé lol.Selon le rendu chez toi ceci est correcte?
echo "<td class='noactualmonth'>$fillCounter</td>";
ou
echo "<td class='noactualmonth'>".$fillCounter."</td>"
Pas tout à fait soulagé tant que ce ">" ne disparaît pas. Pour ta drenière ligne, j'ai rectifié, mais comme je t'ai dit, ça décale les dates class event d'un cran.
Je ne me suis pas bien expliqué.
en faisant:
echo "<td>".$i."</td>";
ça enlève le > mais décale les dates ayant une classe event d'un cran.
en faisant:
echo "td> $i </td>";
ça donne des journées ayant un event comme ceci: td>17 et td>25 (pour janvier 2015)
Ceci :
echo "<td> $i </td>";
C'est la même chose que :
echo "<td>$i</td>";
Ce sont deux codes que tu as proposé daemon24.
Enfin, le code php final qui marche impec :
<?php
mysql_connect("localhost", "root", "") or die (mysql_error());
mysql_select_db("ghost03") or die (mysql_error());
?>
<html>
<head>
<link href="css/calender.css" media="screen" rel="stylesheet" type="text/css" />
<script>
function goLastMonth(month, year){
if(month == 1) {
--year;
month = 13;
}
--month
var monthstring= ""+month+"";
var monthlength = monthstring.length;
if(monthlength <=1){
monthstring = "0" + monthstring;
}
document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year;
}
function goNextMonth(month, year){
if(month == 12) {
++year;
month = 0;
}
++month
var monthstring= ""+month+"";
var monthlength = monthstring.length;
if(monthlength <=1){
monthstring = "0" + monthstring;
}
document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year;
}
</script>
</head>
<body>
<?php
if (isset($_GET['day'])){$day = $_GET['day'];} else {$day = date("j");}
if(isset($_GET['month'])){$month = $_GET['month'];} else {$month = date("n");}
if(isset($_GET['year'])){$year = $_GET['year'];}else{$year = date("Y");}
$currentTimeStamp = strtotime( "$day-$month-$year");
$mois = array("January"=>"Janvier", "February"=>"Février", "March"=>"Mars", "April"=>"Avril", "May"=>"Mai", "June"=>"Juin",
"July"=>"Juillet", "August"=>"Août", "September"=>"Septembre", "October"=>"Octobre", "November"=>"Novembre", "December"=>"Décembre");
$monthName = $mois[date("F", $currentTimeStamp)];
$numDays = date("t", $currentTimeStamp);
$counter = 0;
//get previous month
$prevMonth = $month - 1;
$prevYear = $year;
if($prevMonth <= 0){
$prevMonth = 12;
$prevYear--;
}
$pMonthStr = "" + $prevMonth;
if(strlen($pMonthStr) <= 1)
$pMonthStr = "0" + $pMonthStr;
//get num of day for previous month
$previousTimeStamp = strtotime( "01-$pMonthStr-$prevYear");
$prevNumDays = date("t", $previousTimeStamp);
//get the number of days in the current month and year
?>
<table>
<tr class="head-agenda">
<td class="prvnxt"><img src="css/prev-agenda-button.png" name='previousbutton' onclick ="goLastMonth(<?php echo $month.",".$year?>)"></td>
<td colspan='5'><?php echo $monthName." ".$year; ?></td>
<td class="prvnxt"><img src="css/next-agenda-button.png" name='nextbutton' onclick ="goNextMonth(<?php echo $month.",".$year?>)"></td>
</tr>
<tr class="days-agenda">
<td>LUN</td><td>MAR</td><td>MER</td><td>JEU</td><td>VEN</td><td>SAM</td><td>DIM</td>
</tr>
<tr class="all-agenda">
<?php
for($i = 1; $i < $numDays+1; $i++, $counter++){
$timeStamp = strtotime("$year-$month-$i");
if($i == 1) {
$firstDay = date("N", $timeStamp);
for($j = 0; $j < $firstDay-1; $j++, $counter++) {
$prevDay = $prevNumDays-$firstDay+$j+2;
echo "<td class='noactualmonth'>$prevDay</td>";
}
}
if($counter % 7 == 0) {
echo"</tr><tr class='all-agenda'>";
}
$monthstring = $month;
$monthlength = strlen($monthstring);
$daystring = $i;
$daylength = strlen($daystring);
if($monthlength <= 1){
$monthstring = "0".$monthstring;
}
if($daylength <=1){
$daystring = "0".$daystring;
}
$todaysDate = date("m/d/Y");
$dateToCompare = $monthstring. '/' . $daystring. '/' . $year;
echo "<td ";
if ($todaysDate == $dateToCompare){
echo "class ='today' >";
} else{
$sqlCount = "select * from eventcalender where eventDate='".$dateToCompare."'";
$noOfEvent = mysql_num_rows(mysql_query($sqlCount));
$resultat=mysql_query($sqlCount);
if($noOfEvent >= 1){
echo "class='event' ><ul>";
}
while($donnee=mysql_fetch_assoc($resultat)){
echo "<li>
<a href=\"agenda.php?id=".$donnee['ID']." \"> ".$donnee['Title']."</a>
</li>";
}
echo "</ul>";
}
echo $i."</td>";
}
//fill counter
$fillCounter = 1;
//fill up the leftover cells of the table
while($counter % 7 != 0) {
//echo next month day
//echo "<td class='noactualmonth'>$fillCounter</td>";
echo "<td class='noactualmonth'>".$fillCounter."</td>";
$fillCounter++;
$counter++;
}
?>
</tr>
</table>
</body>
</html>
Cette fois le sujet est résolu pour de bon. J'espère que ça aidera quelques uns. Merci aux contributeurs.