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
| <?php
setlocale(LC_ALL, 'FR_fr');
if(empty($_GET)){
$firstDay = date('Y-m-d', strtotime('first day of this month'));
$lastDay = date('Y-m-d', strtotime('last day of this month'));
$nextYear = date('Y-m-d', strtotime('+ 1 year'));
$prevYear = date('Y-m-d', strtotime('- 1 year'));
$currentYear = date('Y');
}
else{
$firstDay = date('Y-m-01', strtotime($_GET['month']));
$lastDay = date('Y-m-t', strtotime($_GET['month']));
$nextYear = date('Y-m-d', strtotime($_GET['month'].' + 1 year'));
$prevYear = date('Y-m-d', strtotime($_GET['month'].' - 1 year'));
$currentYear = date('Y', strtotime($_GET['month']));
}
//la variable $nextMonth = le mois suivant au mois en court
$nextMonth=DateTime::createFromFormat('Y-m-d',$firstDay)->add(new DateInterval('P1M'))->format('Y-m-d');
//la variable $prevMonth = le mois precedant au mois en court
$prevMonth=DateTime::createFromFormat('Y-m-d',$firstDay)->sub(new DateInterval('P1M'))->format('Y-m-d');
//on créer un tableau qui va récupérer tout les jours du mois
$datesMonth=array();
//on definit les dates du mois en court qui seront stockées dans la variable $period On utile DatePeriod pour définir une période qui va du début du mois ($firstDay) au dernier jour du mois ($lastDay) et ce jour par jour.
$period=new DatePeriod(
new DateTime($firstDay),
new dateInterval('P1D'),
(new DateTime($lastDay))->modify('+ 1 day'));
//on recupere toute les dates dans un tableau
foreach($period as $p){
array_push($datesMonth,$p->format('Y-m-d'));
}
//echo $firstDay.'</br>'.$lastDay.'</br>'.$nextYear.'</br>'.$prevYear.'</br>';
//echo $nextMonth.'</br>'.$prevMonth.'</br>';
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>planning</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<div id="main">
<div class="row">
<h3><?=strftime('%B',strtotime($firstDay)).' '.$currentYear;?></h3>
<a href="index.php?month=<?=$prevYear;?>" class="btn btn-warning"> << <?php echo date('Y',strtotime($prevYear));?></a>
<a href="index.php?month=<?=$prevMonth;?>" class="btn"> << <?php echo strftime('%B',strtotime($prevMonth));?></a>
<a href="index.php?month=<?=$nextYear;?>" class="btn btn-warning"> <?php echo date('Y',strtotime($nextYear));?>>></a>
<a href="index.php?month=<?=$nextMonth;?>" class="btn"><?php echo strftime('%B',strtotime($nextMonth));?>>></a>
</div>
<table class="tableau">
<thead>
<tr>
<?php foreach ($datesMonth as $d):?>
<th><?=strftime('%a',strtotime($d));?></th>
<?php endforeach ?>
</tr>
</thead>
<tbody>
<tr>
<?php foreach ($datesMonth as $d):?>
<td><?=date('d',strtotime($d));?></td>
<?php endforeach ?>
</tr>
</tbody>
</table>
</div> <!-- fin de main -->
</body>
</html> |
Partager