Zend - The PHP Company




Calendars

Add Code


Simple Calendar  

Type: code fragment
Added by: wallgren
Entered: 08/08/2003
Last modified: 09/12/2002
Rating: - (fewer than 3 votes)
Views: 4965
A very simple calendar. Can easily be extended with new functions.


<?php

// make_calendar.php, version 1.0

// Written by Martin Wallgren 2003
// This code is free to use.

// Week starts on Monday in Sweden, and
// so does it in this calendar.

function makeCalendar($year$month$day 1$printweek false$printheader false$bold_today false) {

    if (
$day == 0) {
        
$day 1;
        
$bold false;
    }

    
$timestamp mktime(000$month$day$year);
    
    
$days_in_month date("t"$timestamp);
    
$month_starts_on date("w"mktime(000$month1$year));
    
    
$day_name = array("Su""Mo""Tu""We""Th""Fr""Sa");
    
$month_name = array("January""February""March""April""May""June""July""August""September""October""November""December");
    
    print(
"<table>n");
    
    if (
$printheader) {
        print(
"  <tr>n");
        print(
"    <td colspan="" . ($printweek ? "8" : "7") . "" align="middle"><b>" $month_name[$month 1] . " " $year "</b></td>n");
        print(
"  </tr>n");
    }
    
    print(
"  <tr>n");
    
    if (
$printweek)
        print(
"    <td>&nbsp;</td>n");
    
    for (
$i 1$i <= 7$i++)
        print(
"    <td align="middle">" $day_name[$i 7] . "</td>n");
        
    print(
"  </tr>n");

    if (
$month_starts_on == 0)
        
$month_starts_on 7;

    for (
$i 1$j 1$j <= $days_in_month$i++, $j++) {
        while (
$i $month_starts_on)
            
$out[$i++] = 0;
            
        
$out[$i] = $j;
    }
    
    while (
count($out) % != 0)
        
array_push($out0);
    
    for (
$i 1$i <= count($out); $i++) {
        if ((
$i 1) % == 0) {
            print(
"  <tr>n");
            
            if (
$printweek) {
                for (
$j 0$j 7$j++)
                    if (
$out[$i $j] != 0) {
                        
$week_num date("W"mktime(000$month$out[$i $j], $year));
                        break;
                    }
                print(
"    <td>$week_num</td>n");
            }
        }
        
        print(
"    <td align="middle">");
        
        print(
$out[$i] != ? ($out[$i] == $day ? (($bold_today "<b>" "") . $out[$i] . ($bold_today "</b>" "")) : $out[$i]) : "&nbsp;");
        
        print(
"</td>n");
        
        if (
$i == 0)
            print(
"  </tr>n");
    }

    print(
"</table>n");

}

?>


Usage Example


require_once("make_calendar");
makeCalendar(2003, 8, 6);


Rate This Script





Search



This Category All Categories