Bonjour à tous, j'ai suivi un tuto pour réaliser un calendrier avec la possibilité de mettre des événements mais j'ai un petit problème. Le calendrier s'affiche le 01/01/ de l'année en cours comme je lui ai demandé mais quand je clique sur un autre mois plus rien ne s'affiche. Je peux seulement consulter le mois de Janvier.
page index :
page class date :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Calendrier</title> <link rel="stylesheet" type="text/css" href="designCalendrier.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($){ $('.month').hide(); $('.month:first').show(); $('.months a:first').addClass('active'); var current = 1; $('.months a').click(function(){ var month = $(this).attr('id').replace('linkMonth',''); if(month != current){ $('#month'+current).slideUp(); $('#month'+month).slideDown(); $('.months a').removeClass('active'); $('.months a#linkMonth'+month).addClass('active'); current = month; } return false; }); }); </script> </head> <body> <?php require ('date.php'); require ('connect_bdd.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> <div class="months"> <ul> <?php foreach ($date->months as $id => $m): ?> <li><a href="#" id="linkMonth"<?php echo $id + 1; ?>"><?php echo utf8_encode(substr(utf8_decode($m), 0, 3)); ?></a></li> <?php endforeach; ?> </ul> </div> <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>
Merci par avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 <?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 $bdd; $req = $bdd->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 = strtotime($year.'-01-01'); while(date('Y',$date) <= $year){ $y=date('Y',$date); $m=date('n',$date); $d=date('j',$date); $w=str_replace('0','7', date('w',$date)); $r[$y][$m][$d]= $w; $date = strtotime(date('Y-m-d', $date).'+1 DAY'); } */ $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; } }
Partager