-
-
Save xeoncross/9552088 to your computer and use it in GitHub Desktop.
Simple PHP calendar using bootstrap
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 | |
function build_calendar($month, $year) { | |
$daysOfWeek = array('S','M','T','W','T','F','S'); | |
$firstDayOfMonth = mktime(0,0,0,$month,1,$year); | |
$numberDays = date('t',$firstDayOfMonth); | |
$dateComponents = getdate($firstDayOfMonth); | |
$monthName = $dateComponents['month']; | |
$dayOfWeek = $dateComponents['wday']; | |
$calendar = "<table class='calendar table table-condensed table-bordered'>"; | |
$calendar .= "<caption>$monthName $year</caption>"; | |
$calendar .= "<tr>"; | |
foreach($daysOfWeek as $day) { | |
$calendar .= "<th class='header'>$day</th>"; | |
} | |
$currentDay = 1; | |
$calendar .= "</tr><tr>"; | |
if ($dayOfWeek > 0) { | |
$calendar .= "<td colspan='$dayOfWeek'> </td>"; | |
} | |
$month = str_pad($month, 2, "0", STR_PAD_LEFT); | |
while($currentDay <= $numberDays){ | |
if($dayOfWeek == 7){ | |
$dayOfWeek = 0; | |
$calendar .= "</tr><tr>"; | |
} | |
$currentDayRel = str_pad($currentDay, 2, "0", STR_PAD_LEFT); | |
$date = "$year-$month-$currentDayRel"; | |
// Is this today? | |
if(date('Y-m-d') == $date) { | |
$calendar .= "<td class='day success' rel='$date'><b>$currentDay</b></td>"; | |
} else { | |
$calendar .= "<td class='day' rel='$date'>$currentDay</td>"; | |
} | |
$currentDay++; | |
$dayOfWeek++; | |
} | |
if($dayOfWeek != 7){ | |
$remainingDays = 7 - $dayOfWeek; | |
$calendar .= "<td colspan='$remainingDays'> </td>"; | |
} | |
$calendar .= "</tr>"; | |
$calendar .= "</table>"; | |
return $calendar; | |
} | |
$calendar = build_calendar(3, 2014); | |
$calendar = '<div style="width:200px">' . $calendar . '</div>'; | |
$calendar .= '<style type="text/css">table tbody tr td, table tbody tr th { text-align: center; }</style>'; | |
require('layout.php'); |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta name="description" content=""> | |
<meta name="author" content=""> | |
<link rel="shortcut icon" href="favicon.png"> | |
<title>Sticky Footer Navbar Template for Bootstrap</title> | |
<!-- Bootstrap core CSS --> | |
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"> | |
<!-- Custom styles for this template --> | |
<link href="http://getbootstrap.com/examples/sticky-footer-navbar/sticky-footer-navbar.css" rel="stylesheet"> | |
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --> | |
<!--[if lt IE 9]> | |
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> | |
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script> | |
<![endif]--> | |
</head> | |
<body> | |
<!-- Wrap all page content here --> | |
<div id="wrap"> | |
<!-- Fixed navbar --> | |
<div class="navbar navbar-default navbar-fixed-top" role="navigation"> | |
<div class="container"> | |
<div class="navbar-header"> | |
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> | |
<span class="sr-only">Toggle navigation</span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
</button> | |
<a class="navbar-brand" href="#">Project name</a> | |
</div> | |
<div class="collapse navbar-collapse"> | |
<ul class="nav navbar-nav"> | |
<li class="active"><a href="#">Home</a></li> | |
<li><a href="#about">About</a></li> | |
<li><a href="#contact">Contact</a></li> | |
<li class="dropdown"> | |
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a> | |
<ul class="dropdown-menu"> | |
<li><a href="#">Action</a></li> | |
<li><a href="#">Another action</a></li> | |
<li><a href="#">Something else here</a></li> | |
<li class="divider"></li> | |
<li class="dropdown-header">Nav header</li> | |
<li><a href="#">Separated link</a></li> | |
<li><a href="#">One more separated link</a></li> | |
</ul> | |
</li> | |
</ul> | |
</div><!--/.nav-collapse --> | |
</div> | |
</div> | |
<!-- Begin page content --> | |
<div class="container"> | |
<div class="page-header"> | |
<h1>PHP Calendar</h1> | |
</div> | |
<?php print $calendar; ?> | |
</div> | |
</div> | |
<div id="footer"> | |
<div class="container"> | |
<p class="text-muted">Place sticky footer content here.</p> | |
</div> | |
</div> | |
<!-- Bootstrap core JavaScript | |
================================================== --> | |
<!-- Placed at the end of the document so the pages load faster --> | |
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script> | |
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.0/backbone-min.js"></script> | |
<!-- | |
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.syphon/0.4.1/backbone.syphon.min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.modelbinder/1.0.4/Backbone.ModelBinder.min.js"></script> | |
--> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://gamereplays.org/reference/strtotime.php