Created
June 28, 2017 10:54
-
-
Save AladinDridi/57706c49ad1459cbbd7870901681423f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Set your timezone!! | |
$connection = mysql_connect("localhost","root"); | |
mysql_select_db("bd_events") or die("no database"); | |
// Set your timezone!! | |
date_default_timezone_set('Africa/Tunisia'); | |
// Get prev & next month | |
if (isset($_GET['ym'])) { | |
$ym = $_GET['ym']; | |
} else { | |
// This month | |
$ym = date('Y-m'); | |
} | |
// Check format | |
$timestamp = strtotime($ym,"-01"); | |
if ($timestamp === false) { | |
$timestamp = time(); | |
} | |
// Today | |
$today = date('Y-m-j', time()); | |
// For H3 title | |
$html_title = date('Y / m', $timestamp); | |
// Create prev & next month link mktime(hour,minute,second,month,day,year) | |
$prev = date('Y-m', mktime(0, 0, 0, date('m', $timestamp)-1, 1, date('Y', $timestamp))); | |
$next = date('Y-m', mktime(0, 0, 0, date('m', $timestamp)+1, 1, date('Y', $timestamp))); | |
// Number of days in the month | |
$day_count = date('t', $timestamp); | |
// 0:Sun 1:Mon 2:Tue ... | |
$str = date('w', mktime(0, 0, 0, date('m', $timestamp), 1, date('Y', $timestamp))); | |
// Create Calendar!! | |
$weeks = array(); | |
$week = ''; | |
// Add empty cell | |
$week .= str_repeat('<td></td>', $str); | |
for ( $day = 1; $day <= $day_count; $day++, $str++) { | |
$date = $ym.'-'.$day; | |
if ($today == $date) { | |
$week .= '<td class="today">'.$day; | |
} else { | |
$week .= '<td>'.$day; | |
} | |
$week .= '</td>'; | |
// End of the week OR End of the month | |
if ($str % 7 == 6 || $day == $day_count) { | |
if($day == $day_count) { | |
// Add empty cell | |
$week .= str_repeat('<td></td>', 6 - ($str % 7)); | |
} | |
$weeks[] = '<tr>'.$week.'</tr>'; | |
// Prepare for new week | |
$week = ''; | |
} | |
$allevents = mysql_query("SELECT * FROM events"); | |
$event=array(); | |
$out = ""; | |
while($event = mysql_fetch_array($allevents)or exit(mysql_error())){ | |
$description=$event['description']; | |
$datevent=$event=$event['eventdt']; | |
if($today==$datevent){ | |
$out .= '<td class="evenement">' .$description '</td>'; | |
} | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>PHP Calendar</title> | |
<!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> | |
<link href='https://fonts.googleapis.com/css?family=Noto+Sans:400,700' rel='stylesheet' type='text/css'> | |
<style> | |
<style> | |
.container{ | |
font-family: 'Noto Sans', sans-serif; | |
} | |
th ,td{ | |
border:2px solid DarkTurquoise ; | |
text-align: center; | |
font-weight:900px; | |
width :100px; | |
height: 90px; | |
} | |
th { | |
font-size: 1.4rem; | |
} | |
.today{ | |
background-color: orange; | |
} | |
th:nth-of-type(7),td:nth-of-type(7){ | |
color:blue; | |
} | |
th:nth-of-type(1),td:nth-of-type(1){ | |
color:red; | |
} | |
.evenement { | |
background-color: #F4EAA4; | |
} | |
@media (max-width: 800px) { | |
th{ | |
font-size: 0.8rem; | |
} | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<h3><a href="?ym=<?php echo $prev; ?>"><</a> <?php echo $html_title; ?> <a href="?ym=<?php echo $next; ?>">></a></h3> | |
<br> | |
<table class="table table-bordered"> | |
<tr> | |
<th>Dimanche</th> | |
<th>Lundi</th> | |
<th>Mardi</th> | |
<th>Mercredi</th> | |
<th>Jeudi</th> | |
<th>Vendredi</th> | |
<th>Samedi</th> | |
</tr> | |
<?php | |
foreach ($weeks as $week) { | |
echo $week; | |
} | |
echo $out; | |
?> | |
</table> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment