PHP Classes

File: class_calendar

Recommend this page to a friend!
  Classes of Frits Bergman   Calendar   class_calendar   Download  
File: class_calendar
Role: Class source
Content type: text/plain
Description: Calendar
Class: Calendar
Generate HTML to display a calendar month
Author: By
Last change: There was a small html-typo as follows inside the class: "color=>"
That means the color-statement is redundant and will be ignored.
Date: 19 years ago
Size: 5,418 bytes
 

Contents

Class file image Download
<?php

class Calendar
{
   
// Description: Small and nice calendar.
    // Chosen date is transmitted via _GET-variables.
    // Hints: Choose <body text=404040 link=404040 vlink=404040> for nice linkcoloring.
    // Last changes: Month-handling up/down debugged.
    // History: 29-10-2003 release version 1.4
    // History: 17-02-2003 release version 1.3

   
var $PageName;
    var
$Day;
    var
$Month ;
    var
$Year;
    var
$fontsize = 1;
    var
$cellcolor = "F3F3F3";
    var
$headcellcolor = "CFCFCF";
    var
$edgecolor = "A8A8A8";
    var
$topcolor = "6394CE";
    var
$ChosenDayColor = "D0C0F5";
    var
$ExtraURI = "";

    function
Calendar($PageNameInput)
    {
       
$this->PageName = $PageNameInput; // Set page-name
   
}

    function
Show()
    {
       
$maand = $this->Month;
       
$jaar = $this->Year;

       
$laatstedag = date ("d", mktime (0,0,0,$maand+1,0,$jaar)); // Laatste dag van deze maand (0 van volgende).
       
$maandnr = date ("n", mktime (0,0,0,$maand+1,0,$jaar)); // Maandnr.
       
$maandnaam = $this->GetMonthName($maandnr);
       
$aantalrijen = 1;
       
$headfont = "<font size=1>";
       
$headfontend = "</font>";

       
// Hoover links.
       
print"<style>\n";
        print
"<!--\n";
        print
"a {text-decoration:none}\n";
        print
"A:hover {text-decoration:underline}\n";
        print
"-->\n";
        print
"</style>\n";

       
// Toon kalender.
       
print "<font face=Verdana>";
       
// Month-handling up/down.
       
if (($this->Month-1) == 0)
        {
           
$MaandTerug = 12;
           
$JaarTerug = $this->Year-1;
        }
        else
        {
           
$MaandTerug = $this->Month-1;
           
$JaarTerug = $this->Year;
        }

        if ((
$this->Month+1) == 13)
        {
           
$MaandVerder = 1;
           
$JaarVerder = $this->Year+1;
        }
        else
        {
           
$MaandVerder = $this->Month+1;
           
$JaarVerder = $this->Year;
        }

        print
"<table border=0 cellpadding=2 cellspacing=1 bgcolor=".$this->edgecolor."><tr><td bgcolor=".$this->topcolor."><a href='".$this->PageName."?ChosenDay=1&ChosenMonth=".$MaandTerug."&ChosenYear=".$JaarTerug.$this->ExtraURI."'><img src='../images/l.gif' border=0></a></td><td bgcolor=".$this->topcolor." width=94 align=center><font color=white size=1>".$maandnaam."&nbsp;".$jaar."</font></td><td bgcolor=".$this->topcolor.">";
        print
"<a href='".$this->PageName."?ChosenDay=1&ChosenMonth=".$MaandVerder."&ChosenYear=".$JaarVerder.$this->ExtraURI."'><img src='../images/r.gif' border=0></td></tr></table>";
       
        print
"<table bgcolor=".$this->edgecolor." border=0 cellpadding=2 cellspacing=1><tr>"; // Toon header.
       
print"<td align=center bgcolor=".$this->headcellcolor.">".$headfont."M".$headfontend."</td><td align=center bgcolor=".$this->headcellcolor.">".$headfont."D".$headfontend."</td><td align=center bgcolor=".$this->headcellcolor.">".$headfont."W".$headfontend."</td><td align=center bgcolor=".$this->headcellcolor.">".$headfont."D".$headfontend."</td><td align=center bgcolor=".$this->headcellcolor.">".$headfont."V".$headfontend."</td><td align=center bgcolor=".$this->headcellcolor.">".$headfont."Z".$headfontend."</td><td align=center bgcolor=".$this->headcellcolor.">".$headfont."Z".$headfontend."</td></tr><tr>";

       
// Voorgaande cellen invoegen.
       
$dagnr = date ("w", mktime (0,0,0,$maand,1,$jaar)); // 0 = zondag
       
if ($dagnr == 0) $dagnr = 7;
        for (
$i = 1; $i < $dagnr; $i++) print "<td bgcolor=".$this->cellcolor."><font size=".$this->fontsize.">&nbsp;</font></td>";

       
// Toon dagen.
       
$toondag = 1;
        while (
$toondag <= $laatstedag)
        {
           
$printdag = date ("j", mktime (0,0,0,$maand,$toondag,$jaar));
            print
"<td align=center bgcolor=";
            if (
$printdag == $this->Day) print $this->ChosenDayColor;
                else print
$this->cellcolor;
   
            print
"><font size=".$this->fontsize."><a href='".$this->PageName."?ChosenDay=".$printdag."&ChosenMonth=".$maand."&ChosenYear=".$jaar.$this->ExtraURI."'>".$printdag."</a></font>";
            print
"</td>";
           
$dagnr = date ("w", mktime (0,0,0,$maand,$toondag,$jaar));
            if (
$dagnr == 0) $dagnr = 7;
            if (
$dagnr == 7)
            {
                print
"</tr><tr>"; // Einde rij, zondag. Start nieuwe rij.
               
$aantalrijen++;
            }
           
$toondag++;
        }

       
// Insert vervolg cellen
       
if ($dagnr == 7)
        {
           
$dagnr = 1;
            print
"<td bgcolor=".$this->cellcolor."><font size=".$this->fontsize.">&nbsp;</font></td>";
        }
        for (
$i = $dagnr; $i <= 6; $i++) print "<td bgcolor=".$this->cellcolor."><font size=".$this->fontsize.">&nbsp;</font></td>";
        print
"</tr>";

       
// Eventueel 6e lege rij.
       
if ($aantalrijen == 5)
        {
            print
"<tr>";
            for (
$i = 0; $i < 7;$i++) print "<td bgcolor=".$this->cellcolor."><font size=".$this->fontsize.">&nbsp;</font></td>";
            print
"</tr>";
        }

        print
"</table>";
        print
"</font>";
    }

    function
GetMonthName($maandnr)
    {
        switch(
$maandnr)
        {
            case
1:
               
$maandnaam = 'Januari';
                break;
            case
2:
               
$maandnaam = 'Februari';
                break;
            case
3:
               
$maandnaam = 'Maart';
                break;
            case
4:
               
$maandnaam = 'April';
                break;
            case
5:
               
$maandnaam = 'Mei';
                break;
            case
6:
               
$maandnaam = 'Juni';
                break;
            case
7:
               
$maandnaam = 'Juli';
                break;
            case
8:
               
$maandnaam = 'Augustus';
                break;
            case
9:
               
$maandnaam = 'September';
                break;
            case
10:
               
$maandnaam = 'Oktober';
                break;
            case
11:
               
$maandnaam = 'November';
                break;
            case
12:
               
$maandnaam = 'December';
                break;
        }
        return
$maandnaam;
    }
}

?>