Zend - The PHP Company




Calendars

Add Code


Vertical Collapsing Calendar  

Type: code fragment
Added by: nsfmc
Entered: 01/08/2002
Last modified: 08/12/2001
Rating: - (fewer than 3 votes)
Views: 7890
A collapsable calendar that takes up little webpage real estate. By default displays current week with today highlighted.

Calendar displays an entire month by default if a different month or year are set in the querystring.

rock over london, rock on chicago!


<?php
/**********************************************************************
*    A vertical calendar that expands to show entire month on click and 
* displays full calendar for other months if set in the querystring.
**************PHP & JavaScript 2002AUG01 nsfmc@yahoo.com (Marcos Ojeda)
**********************************************************************/

    
$monthbgcolor "#cccccc";
    
$todaybgcolor "#cccccc";
    
$tbordercolor "#000000";
    
$tablebgcolor "#ffffff";
    
$numdatecolor "#666666";
    
$txtdatecolor "black";
    
$hdmonthcolor "black";

  
$month = (isset($_GET[month])) ? $_GET[month] : date("n",time());
  
$year = (isset($_GET[year])) ? $_GET[year] : date("Y",time());
  
$textmonth date("M",mktime(1,1,1,$month,1,$year));
  if(
$month == date("n",time()) && $year == date("Y",time()))
      
$today date("j"time());
  
$days date("t"mktime(0,0,0,$month,1,$year));
  
  
$nicehead  strtoupper($textmonth);
  
$nicehead .= substr($year,2);

?>
<script>
function show_weeks(rows) {
 for(i = 0; i < <?php echo $days?>; i++) {
  show_date(rows[i]);
 }
}

function show_date(secNum)
{
  if (secNum.style.display != "block" && secNum.style.display!="")
  {secNum.style.display=""}
  else if (secNum.style.display != "block")
  {secNum.style.display="none"}
}

</script>

<table bgcolor="<?php echo $tbordercolor?>" width="50" border="0" cellspacing="1" cellpadding="0">
 <tr>
  <td> 
   <table border="0" cellspacing="0" cellpadding="8" width="100%" bgcolor="<?php echo $tablebgcolor?>">
    <tr>
     <td bgcolor="<?php echo $monthbgcolor?>" align="center" onClick="show_weeks(week);" style="cursor:hand;"><font size="-6" face="Verdana, Geneva, Arial, sans-serif"><?php echo $nicehead?></font></td>
    </tr>
   </table>
  </td>
 </tr>
 <tr>
  <td>
   <table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="<?php echo $tablebgcolor?>">
<?php for($i 1$i <= $days$i++): 
$todaytoday substr(date("D",mktime(1,1,1,$month,$i,$year)),0,1);
$dayofweek date("w",mktime(1,1,1,$month,$i,$year));
if(
$dayofweek == || $i == 1):
    
$weeknumber = isset($weeknumber) ? $weeknumber 1;
    
$firstoweek $i;
    
$lastoweek $i 7;
endif;
?>
    <tr<?php echo " id="week""; if($i == $today): echo " bgcolor="$todaybgcolor""; endif; if(!isset($today) || ($today $lastoweek) && ($today >= $firstoweek)):    echo " style="display:block;""; else: echo " style="display:none;""; endif; ?>>
     <td width="40%" align="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="-7" color="<?php echo $txtdatecolor?>"><?php echo $todaytoday ?></font></td>
     <td width="20%"><font face="Verdana, Arial, Helvetica, sans-serif" size="-7"><?php if($i == $today):?>&rarr;<?php endif;?></font></td>
     <td width="40%" align="left" ><font face="Verdana, Arial, Helvetica, sans-serif" size="-7" color="<?php echo $numdatecolor?>"><?php echo $i?></font></td>
    </tr>
<?php endfor; ?>
   </table>
  </td>
 </tr>
</table>


Usage Example


include this file into a webpage, and presto!  Email me if you found this useful.  Example at: http://san.generic.cx:8080/


Rate This Script





Search



This Category All Categories