Location: PHPKode > projects > OrgCharter > orgchart_calendar.bkp.php
<?php 

function calendar($file){ 

    if((isset($_GET['d']))?$day=$_GET['d']:$day = date("d")); 
    if((isset($_GET['m']))?$month=$_GET['m']:$month = date("m")); 
    if((isset($_GET['y']))?$year=$_GET['y']:$year = date("Y")); 
	
	if(isset($_GET['pastDate'])){
		$tmpDate=explode("-",$_GET['pastDate']);
		$year=$tmpDate[0];
		$month=$tmpDate[1];
		$day=$tmpDate[2];
	}
	
	
	
//create arrays for the calendar 

    $months_days = array("31","28","31","30","31","30","31","31", 
                         "30","31","30","31"); 
    $months_name = array("Jan","Feb","Mar","Apr","May","Jun","Jul", 
                         "Aug","Sep","Oct","Nov","Dec"); 
    $days_array = array("Mon","Tue","Wed","Thu","Fri","Sat","Sun"); 

//removes the 0 from start of month - can't find array key with 0 

    if(strlen($month)==1){ 
        $month= str_replace("0","",$month); 
    } 
    else{ 
        $month=$month; 
    } 

//reset month to the array key match (array starts at 0) 

    $month= $month-1; 

//find the days in the month 

    $days_in_month = $months_days[$month]; 

//And convert the month number to name 

    $month_name = $months_name[$month]; 

//$m is used to find month 

    $m = $month+1; 

//find the first day of the month      
  
    $time = date("M D Y H:i:s", mktime(0, 0, 0, $m, 1, $year)); 
    $first_day = explode(" ",$time); 
    $time = $first_day[1]; 

//create the links to next and previous months 

    $next = $month+2; 
    $x = $year; 

//if month is 13 then new year 

    if($next==13){ 
        $next=1; 
        $x = $x+1; 
    } 
    $prev = $month; 
    $y = $year; 

//if month is 0, then previous year 

    if($prev==0){ 
        $prev=12; 
        $y=$y-1; 
    } 

    $calendar = ""; 

//Build the calendar with css 
//links to next and previous month 

    $calendar .=' 
				<link rel="stylesheet" href="orgchart_calendar.css" type="text/css" />
                <div id="orgchart_calendar" class="calendar" style="'.((preg_match('|MSIE ([0-9].[0-9]{1,2})|',$_SERVER['HTTP_USER_AGENT']))?"width:135px; margin-left:17px;":"").'"> 
                  <div class="calhead"> 
                    <div class="right"> 
                      <a href="'.$file.'?m='.$next.'&y='.$x.'&d='.$day.'&parentElement='.$_GET["parentElement"].'">>></a> 
                    </div> 
                    <div class="left"> 
                      <a href="'.$file.'?m='.$prev.'&y='.$y.'&d='.$day.'&parentElement='.$_GET["parentElement"].'"><<</a> 
                    </div>    
                    <div class="middle"><span>'.$month_name.'/'.$year.'</span></div> 
                   </div> 
                    <div class="caldays"> 
                      <ul class="days"> 
                        <li>M</li> 
                        <li>T</li> 
                        <li>W</li> 
                        <li>T</li> 
                        <li>F</li> 
                        <li>S</li> 
                        <li>S</li> 
                      </ul> 
                    </div> 
                    <div class="caldates"> 
                      <ul class="dates"> 
              '; 
                
    //checks for leap years and add 1 to February 

    if(($year % 4 =="") && ($month==1)){ 
        $days_in_month=$days_in_month+1; 
    } 

    else{ 
        $days_in_month=$days_in_month; 
    } 

    $new_time=""; 
      
    //find how many blank spaces at beginning of the month 
      
    foreach($days_array as $key=>$value){ 
      
        if($value == $time){ 
            $new_time .= $key+1; 
        } 
        else{ 
            $new_time .=""; 
        } 
    } 
      
    //loop through the days in the month 
              
    for($k=1;$k<($days_in_month+$new_time);$k++){    
      
            //blank space 
      
        if($k<$new_time){ 
            $calendar.='<li class="blank"></li> 
            '; 
            continue; 
        } 
          
        //start the actual days 
              
        $n = $k-$new_time+1; 
                  
        if($n==$day){ 
            $calendar .= '<li><a href="'.PROJECT_SERVER.$_SERVER["SCRIPT_NAME"].'?parentElement='.$_GET["parentElement"].'&pastDate='.$y.'-'.$m.'-'.$n.'"><b>'.$n.'</b></a></li> 
                         ';    
        } 
        else{ 
            $calendar .= '<li><a href="'.PROJECT_SERVER.$_SERVER["SCRIPT_NAME"].'?parentElement='.$_GET["parentElement"].'&pastDate='.$y.'-'.$m.'-'.$n.'">'.$n.'</a></li> 
                         '; 
        }      
    } 
    $calendar .= '</ul> 
                 '; 

    $calendar .=' <div class="today"><a href="'.PROJECT_SERVER.$_SERVER["SCRIPT_NAME"].'?parentElement='.$_GET["parentElement"].'">close</a></div></div></div>'; 
    return($calendar); 
} 
?> 
Return current item: OrgCharter