1 pièce(s) jointe(s)
calendrier avec PHP/HTML.
Bonjour,
j'ai tenté de créer un calendrier avec PHP, et en fait j'ai créé trois fichiers, les voilà ci-dessous:
fichier calendar.html.php:
Code:
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 109
| <html>
<head>
<title>Calendrier</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/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('config.php');
require('date.php');
$date = new Date();
$year = date('Y');
$events=$date->getEvents($year);
$dates = $date->getAll($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 border="1">
<thead>
<tr>
<?php foreach($date->days as $d): ?>
<th>
<?php echo substr($d,0,3); ?>
</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'))): ?> classe="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>
<div class="clear">
</div>
<pre><?php print_r($events); ?></pre>
</body>
</html> |
fichier date.php :
Code:
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
| <?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;
$DB = new PDO('mysql:host=localhost;dbname=calendrier2','root','',array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'));
$req= $DB->query('SELECT id,title,date FROM events WHERE YEAR(date)='.$year);
$r= array();
//ce que je veux $r[TIMESTAMP][id] = title
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){
//ce que je veux obtenir$r[ANNEE][MOIS][JOUR]=JOUR DE LA SEMAINE
$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;
}
}
?> |
fichier config.php :
Code:
1 2 3 4 5 6 7 8 9
| <?php
try{
$DB = new PDO('mysql:host=localhost;dbname=calendrier2','root','',array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'));
}
catch(PDOException $e){
echo 'Base de données en vacance';
exit();
}
?> |
Le problème est que lorsque j'essaie d'afficher le calendrier je vois cette page (veuillez cliquer sur le lien ci-dessous pour afficher l'image):
Pièce jointe 142693
est ce qu'il y a quelqu'un qui peut m'aider??
Merci d'avance.