<?php
// カレンダー     by ToR http://php.s3.to
//
// 2001/08/23
//
/* 使用法   <? include "cal.php"; ?> */
$PHP_SELF "cal.php";
// ***.php?20030101 クエリー受信
$qry $_SERVER['QUERY_STRING'];

// 指定日
if(ereg("^[0-9]{8}",$qry)){
  
$yr substr($qry,0,4);
  
$mon substr($qry,4,2);
  
$dy substr($qry,6,2);

  
$today getdate(mktime(0,0,0,$mon,$dy,$yr));
// 普通は今日
}else{
  
$today getdate();
}
$m_num $today[mon];
$d_num $today[mday];
$year $today[year];
// 1日目の曜日
$f_today getdate(mktime(0,0,0,$m_num,1,$year));
$wday $f_today[wday];
// 月表示
$m_name "$year ".substr($today[month],0,3);
// 前次
$prev_month date("Ymd"mktime(0,0,0,$m_num,0,$year));
$next_month date("Ymd"mktime(0,0,0,$m_num+1,1,$year));
$prev_day date("Ymd"mktime(0,0,0,$m_num,$d_num-1,$year));
$next_day date("Ymd"mktime(0,0,0,$m_num,$d_num+1,$year));

echo <<<HEAD
<table bordercolor=#ffffff cellpadding=1 cellspacing=1 width=150 border=0>
        <tbody> 
        <tr> 
          <td align=middle bgcolor=#e0e0e0 height=15> 
            <div align="center"><font size="1" face="Verdana"><b><a href="
$PHP_SELF?$prev_month">≪</a></b></font></div>
          </td>
          <td align=middle bgcolor=#e0e0e0 height=15> 
            <div align="center"><font size="1" face="Verdana"><b><a href="
$PHP_SELF?$prev_day"><</a></b></font></div>
          </td>
          <td align=middle bgcolor=#e0e0e0 colspan=3 height=15>
            <div align="center"><font size="1" face="Verdana"><b>
$m_name</b></font></div>
          </td>
          <td align=middle bgcolor=#e0e0e0 height=15> 
            <div align="center"><font size="1" face="Verdana"><b><a href="
$PHP_SELF?$next_day">></a></b></font></div>
          </td>
          <td align=middle bgcolor=#e0e0e0 height=15> 
            <div align="center"><font size="1" face="Verdana"><b><a href="
$PHP_SELF?$next_month">≫</a></font></div>
          </td>
        </tr>
        <tr> 
          <td align=middle bgcolor=#e0e0e0 height=15> 
            <div align="center"><font size="1" face="Verdana"><b>S</b></font></div>
          </td>
          <td align=middle bgcolor=#e0e0e0 height=15> 
            <div align="center"><font size="1" face="Verdana"><b>M</b></font></div>
          </td>
          <td align=middle bgcolor=#e0e0e0 height=15> 
            <div align="center"><font size="1" face="Verdana"><b>T</b></font></div>
          </td>
          <td align=middle bgcolor=#e0e0e0 height=15> 
            <div align="center"><font size="1" face="Verdana"><b>W</b></font></div>
          </td>
          <td align=middle bgcolor=#e0e0e0 height=15> 
            <div align="center"><font size="1" face="Verdana"><b>T</b></font></div>
          </td>
          <td align=middle bgcolor=#e0e0e0 height=15> 
            <div align="center"><font size="1" face="Verdana"><b>F</b></font></div>
          </td>
          <td bordercolor=#ffffff align=middle bgcolor=#e0e0e0 height=15> 
            <div align="center"><font size="1" face="Verdana"><b>S</b></font></div>
          </td>
        </tr>
        <tr>
HEAD;

for (
$i=0$i<$wday$i++) { // Blank
  
echo "<td width=14% align=center bgcolor=#F3F3F8 height=19> </td>\n"
}
$day 1;
while(
checkdate($m_num,$day,$year)){
  
$link sprintf("%4d%02d%02d"$year$m_num$day);
  if((
$day == $today[mday]) && ($m_num == $today[mon]) && ($year == $today[year])){ 
    
//  Today 
    
echo "<td width=14% align=center bgcolor=#E0E0E0 height=19><font face=Verdana size=1><a href=$PHP_SELF?$link><b>$day</b></a></font></td>\n"
  }elseif(
$wday == 0){ 
    
//  Sunday
    
echo "<td width=14% align=center bgcolor=#FFCCCC height=19><font face=Verdana size=1><a href=$PHP_SELF?$link>$day</a></font></td>\n";
  }elseif(
$wday == 6){ 
    
//  Saturday
    
echo "<td width=14% align=center bgcolor=#AACCFF height=19><font face=Verdana size=1><a href=$PHP_SELF?$link>$day</a></font></td>\n";
  }else{ 
    
// Weekday
    
echo "<td width=14% align=center bgcolor=#EFEFEF height=19><font face=Verdana size=1><a href=$PHP_SELF?$link>$day</a></font></td>\n";
  }
  if(
$wday == 6) echo "</tr><tr>";
  
$day++;
  
$wday++;
  
$wday $wday 7;
}
if(
$wday 0){
  while(
$wday 7) { // Blank
    
echo "<td width=14% align=center bgcolor=#F3F3F8 height=19> </td>\n";
    
$wday++;
  }
}
else {
  echo 
"<td colspan=7></td>\n";
}
echo 
"</tr></table>";
?>