Zend - The PHP Company




Calendars

Add Code


Calendar with Holidays  

Type: application
Added by: bun
Entered: 29/05/2000
Last modified: 06/12/2000
Rating: **** (9 votes)
Views: 15486
Calendar of current month that uses some of template files which one of them is a file contains list of holidays and also can move to next/prev month or next/prev year with timezone difference between server time and your local time.


<?
/* calendar.php */

$gmt=0;
$item="
        <tr>
          <td width="
14%" bgcolor="#FFFFFF">
            
<p align="center"><b><font color="#1COLOR" size="1" face="helvetica, arial, verdana">1X&nbsp;</font></b></td>
          <
td width="14%" bgcolor="#FFFFFF">
            <
p align="center"><b><font color="#2COLOR" size="1" face="helvetica, arial, verdana">2X&nbsp;</font></b></td>
          <
td width="14%" bgcolor="#FFFFFF">
            <
p align="center"><b><font color="#3COLOR" size="1" face="helvetica, arial, verdana">3X&nbsp;</font></b></td>
          <
td width="14%" bgcolor="#FFFFFF">
            <
p align="center"><b><font color="#4COLOR" size="1" face="helvetica, arial, verdana">4X&nbsp;</font></b></td>
          <
td width="14%" bgcolor="#FFFFFF">
            <
p align="center"><b><font color="#5COLOR" size="1" face="helvetica, arial, verdana">5X&nbsp;</font></b></td>
          <
td width="15%" bgcolor="#FFFFFF">
            <
p align="center"><b><font color="#6COLOR" size="1" face="helvetica, arial, verdana">6X&nbsp;</font></b></td>
          <
td width="15%" bgcolor="#FFFFFF">
            <
p align="center"><b><font color="#7COLOR" size="1" face="helvetica, arial, verdana">7X&nbsp;</font></b></td>
        </
tr>
";

function checkholiday(
$date,$month){
  global 
$strholiday;
  
$f=file("holidays.txt");
  for(
$i=0;$i<sizeof($f);$i++){
    
$l=$f[$i];
    list(
$strdate,$strholiday)=explode(":",$l);
    
$strholiday=chop($strholiday);
    list(
$xdate,$xmonth)=explode("-",$strdate);
    if(
$date==$xdate && $month==$xmonth) return 1;
  }
  return 0;
}

$date=date("g-i-s-n-j-Y");
list(
$hour,$min,$sec,$month,$day,$year)=explode("-",$date);

$date=date("j",mktime($hour+$gmt,$min,$sec,$month,$day,$year));
list(
$day)=explode("-",$date);

if(!
$mdiff$mdiff=0;
if(!
$ydiff$ydiff=0;
$year2=date("Y",mktime($hour,$min,$sec,$month+$mdiff,$day,$year+$ydiff));

$date2=date("j-F-Y-n",mktime($hour+$gmt,$min,$sec,$month+$mdiff,$day,$year+$ydiff));
list(
$strdate,$strmonth,$stryear,$month2)=explode("-",$date2);

$dateone=date("w-t",mktime(0+$gmt,0,0,$month2,1,$year2));
list(
$first,$sumofday)=explode("-",$dateone);
$last=date("w",mktime(0+$gmt,0,0,$month2,$sumofday,$year2));

if(
$first){
  
$sunday=1+(7-$first);
  if(
$sunday==7) $sunday=0;
} else {
  
$sunday=1;
}

$sumofdaybefore=date("t",mktime(0+$gmt,0,0,($month2-1),1,$year2));
for(
$i=0;$i<$first;$i++){
  
$datelist[$i]=$sumofdaybefore - $first + $i + 1;
  
$color[$i]="C0C0C0";
}

for(
$i=$first,$t=1;$t<=$sumofday;$i++,$t++){
  
$datelist[$i]=$t;
  if((
$t%7)==$sunday) { $color[$i]="FF0000"; }
  else { 
$color[$i]="000000"; }
  if(checkholiday(
$t,$month2)){
    
$color[$i]="CC00CC";
    
$datelist[$i]="<a name="$strholidayhref="javascript:holiday('$strholiday')">$t</a>";
  }
  if(
$t==$strdate$color[$i]="00BB00";
}

$sumofdatenow=sizeof($datelist);
for(
$i=$sumofdatenow,$s=0;$s<(6-$last);$i++,$s++){
  
$datelist[$i]=$s+1;
  
$color[$i]="C0C0C0";
}

$sumofweek=sizeof($datelist)/7;
for(
$i=0;$i<$sumofweek;$i++){
  
$idx=$i*7;
  
$idx1=$idx+1;
  
$idx2=$idx+2;
  
$idx3=$idx+3;
  
$idx4=$idx+4;
  
$idx5=$idx+5;
  
$idx6=$idx+6;
  
$temp=$item;
  
$temp=ereg_replace("1X","$datelist[$idx]",$temp);
  
$temp=ereg_replace("1COLOR",$color[$idx],$temp);
  
$temp=ereg_replace("2X","$datelist[$idx1]",$temp);
  
$temp=ereg_replace("2COLOR",$color[$idx+1],$temp);
  
$temp=ereg_replace("3X","$datelist[$idx2]",$temp);
  
$temp=ereg_replace("3COLOR",$color[$idx+2],$temp);
  
$temp=ereg_replace("4X","$datelist[$idx3]",$temp);
  
$temp=ereg_replace("4COLOR",$color[$idx+3],$temp);
  
$temp=ereg_replace("5X","$datelist[$idx4]",$temp);
  
$temp=ereg_replace("5COLOR",$color[$idx+4],$temp);
  
$temp=ereg_replace("6X","$datelist[$idx5]",$temp);
  
$temp=ereg_replace("6COLOR",$color[$idx+5],$temp);
  
$temp=ereg_replace("7X","$datelist[$idx6]",$temp);
  
$temp=ereg_replace("7COLOR",$color[$idx+6],$temp);

  
$calendarlist.=$temp;
}

$mdiffmin=$mdiff-1;
$mdiffplus=$mdiff+1;
$ydiffmin=$ydiff-1;
$ydiffplus=$ydiff+1;

$f=file("calendar.htm");
for(
$i=0;$i<sizeof($f);$i++){
  
$line=$f[$i];
  
$line=ereg_replace("__MONTH__",$strmonth,$line);
  
$line=ereg_replace("__YEAR__",$stryear,$line);
  
$line=ereg_replace("__MDIFF__","$mdiff",$line);
  
$line=ereg_replace("__YDIFF__","$ydiff",$line);
  
$line=ereg_replace("__MDIFFMIN__","$mdiffmin",$line);
  
$line=ereg_replace("__MDIFFPLUS__","$mdiffplus",$line);
  
$line=ereg_replace("__YDIFFMIN__","$ydiffmin",$line);
  
$line=ereg_replace("__YDIFFPLUS__","$ydiffplus",$line);
  
$line=ereg_replace("__CALENDARLIST__",$calendarlist,$line);
  echo 
$line;
}
?>

/****************************************************************/
/* THESE ARE TEMPLATE AND HOLIDAYS LIST FILES */
/****************************************************************/
/* template file calendar.htm */
/*
<style type="
text/css">
  a:link {text-decoration: none;color: #CC00CC;}
  a:hover {text-decoration: none;color: #CC00CC;}
  a:active {text-decoration: none;color: #CC00CC;}
  a:visited {text-decoration: none;color: #CC00CC;}
</style>

<script language=javascript>
  function holiday(str){
    window.status="
str";
  }
</script>

     <table border="
1" width="140" cellspacing="0" cellpadding="2" bordercolor="#808080">
      
<tr>
       <
td width="100%" valign="middle" align="center">
        <
table border="0" width="100%" cellspacing="0" cellpadding="0">
         <
tr>
          <
td width="100%" colspan="7" bgcolor="#6666FF">
            <
p align="center"><a href="calendar.php?mdiff=__MDIFFMIN__&ydiff=__YDIFF__"><b><font size="2" face="arial, helvetica, verdana" color="#FF0000">&lt;&lt;</font></b></a>
            <
font size="2" face="arial, helvetica, verdana" color="#FFFFFF"__MONTH__ </font><a href="calendar.php?mdiff=__MDIFFPLUS__&ydiff=__YDIFF__"><b><font size="2" face="arial, helvetica, verdana" color="#FF0000">&gt;&gt;<br>
            </
font></b></a><img border="0" src="images/spacer.gif" width="100" height="1"></p>
          </
td>
         </
tr>
         <
tr>
          <
td width="100%" colspan="7" bgcolor="#CCCCFF">
            <
p align="center"><a href="calendar.php?ydiff=__YDIFFMIN__&mdiff=__MDIFF__"><b><font size="2" face="arial, helvetica, verdana" color="#FF0000">&lt;&lt;</font></b></a><font size="2" face="arial, helvetica, verdana" color="#000000">
            
__YEAR__</font><a href="calendar.php?ydiff=__YDIFFPLUS__&mdiff=__MDIFF__"><b><font size="2" face="arial, helvetica, verdana" color="#FF0000">&gt;&gt;</font></b></a></td>
         </
tr>
         <
tr>
          <
td width="15%" bgcolor="#FFFFFF">
            <
p align="center"><b><font size="1" face="helvetica, arial, verdana" color="#AA0000">S</font></b></td>
          <
td width="14%" bgcolor="#FFFFFF">
            <
p align="center"><b><font size="1" face="helvetica, arial, verdana" color="#0000FF">M</font></b></td>
          <
td width="14%" bgcolor="#FFFFFF">
            <
p align="center"><b><font size="1" face="helvetica, arial, verdana" color="#0000FF">T</font></b></td>
          <
td width="14%" bgcolor="#FFFFFF">
            <
p align="center"><b><font size="1" face="helvetica, arial, verdana" color="#0000FF">W</font></b></td>
          <
td width="14%" bgcolor="#FFFFFF">
            <
p align="center"><b><font size="1" face="helvetica, arial, verdana" color="#0000FF">T</font></b></td>
          <
td width="14%" bgcolor="#FFFFFF">
            <
p align="center"><b><font size="1" face="helvetica, arial, verdana" color="#0000FF">F</font></b></td>
          <
td width="15%" bgcolor="#FFFFFF">
            <
p align="center"><b><font size="1" face="helvetica, arial, verdana" color="#0000FF">S</font></b></td>
         </
tr>
__CALENDARLIST__
        
</table>
       </
td>
      </
tr>
     </
table>
*/
/* end of template file calendar.htm */

/* holidays list file holidays.txt */
/* format : dd-mm:holiday name */
/*
01-01:Tahun Baru
05-03:Idul Adha 1421 H
25-03:Hari Raya Nyepi
26-03:1 Muharram 1422 H
13-04:Wafat Isa Al Masih
07-05:Hari Raya Waisak
24-05:Kenaikan Isa Al Masih
04-06:Maulid Nabi Muhammad SAW 1422H
17-08:Proklamasi Kemerdekaan RI
15-10:Isra Miraj Nabi Muhammad SAW 1422 H
16-12:Idul Fitri 1422 H
17-12:Idul Fitri 1422 H
25-12:Hari Natal
*/
/* end of holidays list file holidays.txt */


Usage Example


See the example


Rate This Script





Search



This Category All Categories