PX : code

Calendar by Andrey Korlyakov
Download this code


<?php
/*
 Copyright 1999, Andrey Korlyakov v.1.0 
 Simle Calendar
  One more calendar. Here there are two functions prCalendar and prMonth
  Each data has the reference with variable d=YYYYMMDD;
*/
 
function prCalendar($fromyear,$frommonth,$fromday,$href) {
  (int)
$fromyear;
  (int)
$frommonth;
  (int)
$fromday;
  global 
$maincolumn,$maxcolumn;
  
$maincolumn=1;
  
$maxcolumn=5;
  
$pred=time()-86400;
  
$curyear=(int)date("Y",$pred);
  
$curmonth=(int)date("m",$pred);
  
$curday=(int)date("d",$pred);
  print 
"<table align=center>";
  if (
$curyear==$fromyear)  {
    if (
$curmonth==$frommonthprMonth($curyear,$curmonth,$href,$fromday,$curday);
    else {
      
prMonth($fromyear,$frommonth,$href,$fromday,32);
      for (
$m=$frommonth+1;$m<$curmonth;$m++) prMonth($fromyear,$m,$href,0,32);
      
prMonth($curyear,$curmonth,$href,0,$curday);
    }
  } else {
    
prMonth($fromyear,$frommonth,$href,$fromday,32);
    if (
$frommont != 12 ) for ($m=$frommonth+1;$m<=12;$m++) prMonth($fromyear,$m,$href,0,32);
    for (
$y=$fromyear+1;$y<$curyear;$y++) { for ($m=1;$m<=12;$m++) prMonth($y,$m,$href,0,32);}
    for (
$m=1;$m<$curmonth;$m++) prMonth($curyear,$m,$href,0,32);
    
prMonth($curyear,$curmonth,$href,0,$curday);
  }
print 
"</table>\n";
}

 function 
prMonth($year,$month,$href,$fd,$cd) {
    global 
$maincolumn,$maxcolumn;
    if (
$maincolumn == ) print "<tr valign=\"top\">"
    
$first=mktime(0,0,0,$month,1,$year);
    print 
"<td><table border=1><td colspan=\"7\" align=\"center\">";
    print (
date("F Y",$first));
    print 
"</td><tr><td>M</td><td>T</td><td>W</td><td>T</td><td>F</td><td>S</td><td>S</td></tr>\n";
    
$wd=date("w",$first);
    if (
$wd==0) { $wd=7;}
    
$lastday=date("d",mktime(0,0,0,$month+1,0,$year));
    
$cur=-$wd+1;
    for (
$k=0;$k<6;$k++) {
       print 
"<tr>";
       for (
$i=0;$i<7;$i++ ) {
          
$cur++;
          if ((
$cur<=0) || ($cur>$lastday) ) print "<td>&nbsp</td>"
          elseif ((
$cur>=$fd) && ($cur<=$cd)) printf ("<td><a href=%s%04d%02d%02d>%d</a></td>",$href,$year,$month,$cur,$cur);
          else print 
"<td>$cur</td>"
       }  
       print 
"</tr>\n";
    }
    print 
"</table></td>\n";
    if (
$maincolumn == $maxcolumn) { $maincolumn=1; print "</tr>";}
    else { 
$maincolumn++; } 
};

$href="display.php3?d=";
print 
"<HTML><HEAD></HEAD><BODY>\n";
print 
"<BR>\n";
prCalendar(1999,1,28,$href);
print 
"</BODY></HTML>\n";
?>


Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.