Login   Register  
PHP Classes
elePHPant
Icontem

File: class.calendar.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Suranga Niroshan Fernando  >  Calendar Display  >  class.calendar.php  >  Download  
File: class.calendar.php
Role: Class source
Content type: text/plain
Description: class file
Class: Calendar Display
Display calendar months with special day marks
Author: By
Last change: uploading the file
Date: 2011-06-21 02:16
Size: 3,539 bytes
 

Contents

Class file image Download
<?php
/*
@Author - W W Suranga Niroshan Fernando.
@Description -  Prints the month calendar foa given month and year
                Prints marked dates like reminders holidays and 
                and Week Ends

*/
class calendar{
    
    private 
$markedDates;
    public 
$month;
    public 
$year;
    public 
$monthPrefix =array(
        
'0'=>'Jan',
        
'1'=>'Feb',
        
'2'=>'Mar',
        
'3'=>'Apr',
        
'4'=>'May',
        
'5'=>'Jun',
        
'6'=>'Jul',
        
'7'=>'Aug',
        
'8'=>'Sep',
        
'9'=>'Oct',
        
'10'=>'Nov',
        
'11'=>'Dec'
    
);
    
    function 
__construct(){    
    }
    
/*
        Set Month and year for calendar write 
    */
    
function setDate($month$year){
        
$this->month=$month;
        
$this->year=$year;
    }
    
/* 
        Set marked dates array to bind when writing the calendar
        
    */
    
function setMarkedDates($markedDates){
        
$this->markedDates=$markedDates;
    }
    
/* 
        Writting the calander to the out put        
    */
    
function writeCalander(){
        
        
/* 
        Setting next and prev months in case month is last or first this sets the prev year accordingly
        */
        
if($this->month==null or $this->year==null or $this->month >12 or $this->month <or $this->year ){
            Throw new 
Exception("Calander Exception :::::::: Given monthand year is not valid"); 
            die();
        }
        
$prevMonthNum = ($this->month==1)? 12$this->month-1;
        
$prevYearNum = ($this->month==1)? $this->year-1$this->year;
        
        
$nextMonthNum = ($this->month==12)? 1$this->month+1;
        
$nextYearNum = ($this->month==12)? $this->year+1$this->year;
        
        
// get the number of dates in the month
        
$numOfDates cal_days_in_month(CAL_GREGORIAN$this->month$this->year) ;
        
        
$numOfDatesPrevMonth cal_days_in_month(CAL_GREGORIAN$prevMonthNum$prevYearNum);
        
$timeStamps mktime(000$this->month1$this->year);
        
$timeStampe mktime(000$this->month$numOfDates$this->year);
        
// Starting day of the month this returns int between 0 - 6 
        
$sdate("w"$timeStamps) ;
        
// End day of the month this returns int between 0 - 6 
        
$e=date("w"$timeStampe) ;
        
        
// intializing array to contain all the dates which needs to display include prev and next months dates
        
$datesArray = array();
        
        
$begin = ($s==0)?1:1-$s;
        
$end = ($e==0)? ($numOfDates+1): $numOfDates + (7-$e);
        
        
$a=0;
        for(
$i=$begin;$i<$end;$i++){
            
$datesArray[$a] =date("Y-m-d"mktime(000$this->month$i$this->year));
            
$a++;
        }
        echo <<<EOD
        <table border="1">
        <tr>
            <th>Sunday</th>
            <th>Monday</th>
            <th>Tuesday</th>
            <th>Wendsday</th>
            <th>Thursday</th>
            <th>Friday</th>
            <th>Staurday</th>
        </tr>
EOD;
        
$j=0;
        for(
$i=0;$i<(count($datesArray)/7); $i++){
            echo <<<EOD
            <tr>
EOD;
            for(
$x=0;$x<7;$x++){
            
$classes;
            
$rel;
            
/*     Check for marked dates
                If This date is a marked dtae print information togeather with the date
            */
            
if (array_key_exists($datesArray[$j],$this->markedDates)){
                
$classes $this->markedDates[$datesArray[$j]]['type'] ." ";
                
$rel $this->markedDates[$datesArray[$j]]['title'];
            }else {
                
            }
            
$date explode("-",$datesArray[$j]);
    
            if(
$date[1]==$this->month){
                
$classes .="current_month";
            }else{
                
$classes .="other-months";
            }
            echo <<<EOD
                <td class="$classes" alt="" rel="$rel">{$date[2]}</td>
EOD;
                
$classes=null;
                
$j++;
            }
        echo <<<EOD
            </tr>
EOD;
        }
        
    echo <<<EOD
        </table>
EOD;
    }
    function 
setCurrentDetails(){
        echo 
"<h2>".$this->monthPrefix[$this->month-1]." - " $this->year ."</h2>";
    }

?>