Динамичен календар

Автоматичен календар ( използва PHP ) :

calendar.php :


<?Php

$day = 1;

if(isset($_GET['month'])){
$month_num = $_GET['month'];
}else{
$month_num = date('n');
}

$day_num = date('j');

$start = mktime(0,0,0,$month_num,1,date('Y'));

$last_month = mktime(0,0,0,$month_num-1,1,date('Y'));
$last_month = date('M', $last_month);

$next_month = mktime(0,0,0,$month_num+1,1,date('Y'));
$next_month = date('M', $next_month);

$year_num = date('Y', $start);
$month = date('F', $start);
$first_day = date('w', $start);
$days_in_month = date('t', $start);
?>

<html>

<head>
<title>Calendar</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>
<h1>Calendar</h1>
<h3><?Php echo $month . " " . $year_num; ?></h3>
<br />
<table>
<tr class="days_of_week">
<td title="Sunday">S</td>
<td title="Monday">M</td>
<td title="Tuesday">T</td>
<td title="Wednesday">W</td>
<td title="Thursday">T</td>
<td title="Friday">F</td>
<td title="Saturday">S</td>
</tr>
<tr>
<?Php for ($i=0; $i<=6; $i++){
if($first_day<=$i){
if($day==$day_num){
if($month_num == date('n')){
echo '<td title="Today"><b>' . $day . '</b></td>';
}else{
echo '<td title="Today">' . $day . '</td>';
}
}else{
echo '<td>' . $day . '</td>';
}
$day++;
}else{
echo "<td> - </td>";
}
}
echo "</tr>";
while($day<=$days_in_month){
echo "<tr>";
for ($i=0; $i<=6; $i++){
if($day<=$days_in_month){
if($day==$day_num){
if($month_num == date('n')){
echo '<td title="Today"><b>' . $day . '</b></td>';
}else{
echo '<td title="Today">' . $day . '</td>';
}
}else{
echo '<td>' . $day . '</td>';
}
$day++;
}else{
echo "<td> - </td>";
}
}
echo "</tr>";
} ?>
<tr>
<td id="back" colspan='3'><a href="calendar.php?month=<?Php echo $month_num -1; ?>" title="Back">« <?Php echo $last_month; ?></td>
<td id="pad"></td>
<td id="next" colspan='3'><a href="calendar.php?month=<?Php echo $month_num +1; ?>" title="Next"><?Php echo $next_month; ?> »</td>
</tr>
</table>

</body>

</html>


style.css ( за стилизиране на календара ) :

body {
background: #E8E8E8;
color: #787878;
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 14px;
}

h1, h2, h3 {
margin: 0;
text-transform: uppercase;
letter-spacing: .15em;
font-family: Arial, Helvetica, sans-serif;
}

h1 {
font-size: 1.8em;
}

h3 {
font-size: 1em;
}

table {
text-align: center;
padding: 20px;
border-collapse: collapse;
font-size: 12px;
}

.days_of_week {
font-weight: bold;
font-size: 14px;
}

td {

padding: 7px;
}

a {
text-decoration: none;
color: #C0BFBF;
}

a:hover {
background: none;
}

#next {
text-align: right;
}

#back {
text-align: left;
}


Източник: http://www.mr-experts.co.uk/2008/10/basic-php-calendar/


/ Трябва да сте регистриран за да напишете коментар /