PHP Classes

File: calendar.php

Recommend this page to a friend!
  Classes of Alessandro Rosa   Simple Calendar   calendar.php   Download  
File: calendar.php
Role: Class source
Content type: text/plain
Description: class code for generating the calendar
Class: Simple Calendar
Displays month calendars
Author: By
Last change: none
Date: 17 years ago
Size: 6,400 bytes
 

Contents

Class file image Download
<?php

require_once( "dateclass.php" );

# calendar class
# coded by Alessandro Rosa
# e-mail : zandor_zz@yahoo.it
# site : http://malilla.supereva.it

# Copyright (C) 2006 Alessandro Rosa

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

# Compiled with PHP 4.4.0

$seasons_colors = array( 1 => "#F0F8FF",
                        
2 => "#ECF1EF",
                        
3 => "#CD3278",
                        
4 => "#B4EEB4",
                        
5 => "#B22222",
                        
6 => "#FF6347",
                        
7 => "#00C5CD",
                        
8 => "#7AC5CD",
                        
9 => "#B3EE3A",
                        
10 => "#CD9B1D",
                        
11 => "#8B0000",
                        
12 => "#8B8B00" ) ;

# REMARK : refer to the global arrays in dateclass.php for months and days names

class calendar
{
      function
calendar()
      {
      }
     
      function
build_it()
      {
            
$dclass = new date();

             echo
"<table class=\"calendar\">";
            
            
$a = getdate();
            
$this->today_d = $day = $a['mday'] ;
            
$week_day = $a['wday'] ;
            
$this->today_m = $month = $a['mon'] ;
            
$this->today_y = $year = $a['year'] ;
            
$this->today_full_name = $GLOBALS['name_days'][$week_day];
            
            
$season_clr = $GLOBALS['seasons_colors'][$month] ;
            
            
$dclass->set_start_date( 1, $month, $year ) ;
            
            
$month_name = $dclass->get_start_month_name();
            
$first_day_index = $dclass->get_start_day_index() ;
            
             echo
"<tr><td style=\"background-color:$season_clr;\" class=\"month\" colspan=\"7\">$month_name</td></tr>\r\n";
             echo
"<tr class=\"weekdays\">\r\n";
            
             if (
$this->bSundayStart === true ) echo "\t\t\t\t<td class=\"weekdays\">".(( $week_day == 0 ) ? "<b>".$GLOBALS['short_name_days']['7']."</b>" : $GLOBALS['short_name_days']['0'])."</td>";
             echo
"\t\t\t\t<td class=\"weekdays\">".(( $week_day == 1 ) ? "<b>".$GLOBALS['short_name_days']['1']."</b>" : $GLOBALS['short_name_days']['1'])."</td>";
             echo
"\t\t\t\t<td class=\"weekdays\">".(( $week_day == 2 ) ? "<b>".$GLOBALS['short_name_days']['2']."</b>" : $GLOBALS['short_name_days']['2'])."</td>";
             echo
"\t\t\t\t<td class=\"weekdays\">".(( $week_day == 3 ) ? "<b>".$GLOBALS['short_name_days']['3']."</b>" : $GLOBALS['short_name_days']['3'])."</td>";
             echo
"\t\t\t\t<td class=\"weekdays\">".(( $week_day == 4 ) ? "<b>".$GLOBALS['short_name_days']['4']."</b>" : $GLOBALS['short_name_days']['4'])."</td>";
             echo
"\t\t\t\t<td class=\"weekdays\">".(( $week_day == 5 ) ? "<b>".$GLOBALS['short_name_days']['5']."</b>" : $GLOBALS['short_name_days']['5'])."</td>";
             echo
"\t\t\t\t<td class=\"weekdays\">".(( $week_day == 6 ) ? "<b>".$GLOBALS['short_name_days']['6']."</b>" : $GLOBALS['short_name_days']['6'])."</td>";
             if (
$this->bSundayStart === false ) echo "\t\t\t\t<td class=\"weekdays\">".(( $week_day == 0 ) ? "<b>".$GLOBALS['short_name_days']['7']."</b>" : $GLOBALS['short_name_days']['0'])."</td>";

             echo
"</tr>\r\n";
             echo
"\t\t\t\t<tr><td style=\"height:5px;\"></td></tr>\r\n";

            
$cell_current_index = ( $this->bSundayStart ) ? $first_day_index : $first_day_index - 1 ;
            
$cell_current_index = ( $cell_current_index == 7 ) ? 0 : $cell_current_index ;
            
             echo
"<tr>\r\n" ;
            
             for (
$i = 0; $i < $cell_current_index; $i++ )
             {
                 echo
"\t<td class=\"calendar\"></td>\r\n" ;
             }
            
            
$cell_current_index = $i ;
            
            
$month_days = $dclass->get_month_days( $month, $year ) ;
            
             for(
$i = 1 ; $i <= $month_days; $i++ )
             {
                 if (
$i == $day ) echo "\t<td style=\"font-weight:bold;\" class=\"calendar\">$i</td>\r\n" ;
                 else echo
"\t<td class=\"calendar\">$i</td>\r\n" ;
            
                
$cell_current_index++ ;
            
                
$cell_current_index %= 7 ;
                
                 if (
$cell_current_index == 0 ) echo "</tr>\r\n\t<tr>\r\n" ;
             }
            
             echo
"\t\t\t\t<tr><td style=\"height:5px;\"></td></tr>\r\n";
            
             if (
$this->get_display_today() ) echo "<tr><td colspan=\"7\" class=\"today\">Today is : ".$this->get_today_full_name()." ".$this->get_today_date()."</td></tr>" ;
            
             echo
"</table>\r\n";
      }
     
      function
display_english_date( $bED ) { $this->bEngDate = $bED ; }
      function
get_display_english_date_opt( $bED ) { return $this->bEngDate ; }

      function
get_sunday_start() { return $this->bSundayStart ; }
      function
set_sunday_start( $bS ) { $this->bSundayStart = $bS ; }

      function
get_display_today() { return $this->bDisplayToday ; }
      function
set_display_today( $bDt ) { $this->bDisplayToday = $bDt ; }

      function
get_today_date() { return ( ( $this->bEngDate ) ? $this->today_m."-".$this->today_d : $this->today_d."-".$this->today_m ) . "-".$this->today_y ; }
      function
get_today_full_name() { return $this->today_full_name ; }

      var
$bSundayStart = TRUE ;
      var
$bDisplayToday = TRUE ;
      var
$bEngDate = TRUE ;

      var
$today_d ;
      var
$today_m ;
      var
$today_y ;
      var
$today_full_name ;
}