Mega Code Archive

 
Categories / Php / Date Time
 

Calendar class on the same page , suitable for reservation

<?PHP class BZ_calendar { var $me , $beg , $end ; function BZ_calendar ( $num , $beg , $end ) { $this->me = $num ; $this->beg = $beg ; $this->end = $end ; } function jj ( $goto , $c1 , $c2 ) { global $beg , $end ; $lastday = array(0,31,28,31,30,31,30,31,31,30,31,30,31); if ( $this->me == 1 ) { $t = $c1 ; } else { $t = $c2 ; } $today = getdate( $t ); $tbuff = mktime(0,0,0,$today['mon'],1,$today["year"] ) ; $tDate = getdate( $tbuff ); $firstwday= $tDate["wday"]; $ld = $lastday[$tDate['mon']]; $td = $today["mday"]; if ( ( $tDate["year"] % 4 ) == 0 ) $ld++ ; $nn=0; $n=1; $aujourduis = date("Y-m-d", time() ); echo "<tr>"; while ( $n < $ld ) { if ( ( ++$nn >= $firstwday ) ) { $value = date("Y-m-d", $tbuff); if ( ( $value> $beg && $value< $end ) || (($this->me ==1 ) && ( $value== $end ) ) || (($this->me ==2 ) && ( $value== $beg ) )) { echo "<td bgcolor=#cc6600 > " ; } elseif ( ( ($value == $beg) && ($this->me ==1 ) ) || (( $value == $end) && ( $this->me ==2 ) ) ) { echo "<td bgcolor=#000000 > " ; } else { echo "<td bgcolor=#337878 > " ; } $d = beg ; $f = $end ; if ($this->me == 1 ) { $d = $value ; if ( $d > $end ) { $f = $d ; } else { $f = $end ; } } else { $f = $value ; if ( $f < $beg ) { $d = $f ; } else { $d = $beg ; } } if($value >= $aujourduis ) echo " <a href='$goto?beg=$d&end=$f&cal=$this->me&c2=$c2&c1=$c1 ' > ".$n."</a></td>" ; else echo $n. "</td>" ; ++$n; $tbuff +=86400 ; } else { echo "<td > ? </td>" ; } if ( $nn % 7 ==0 ) echo "</tr> <tr>"; } echo "</tr>"; } function draw ( $goto , $c1 , $c2 ) { global $time , $beg , $end , $cal ; setlocale ("LC_ALL", "fr_CA"); echo "<table bgcolor=#6699CC CELLSPACING ='0' BORDER='0' > \n<tr VALIGN=CENTER ALIGN=CENTER > \n <td> " ; if ( $this->me ==1 ) { echo " <a href='$goto?cal=".$this->me."&c1=".($c1 - 86400*30) ."&c2=".$c2."&beg=$beg&end=$end'> << </a> </td> \n <th bgcolor=#336699 > ".strftime(" %B %Y" ,$c1 ) ." </th> \n <td> <a href='$goto?cal=".$this->me."&c1=".($c1 + 86400*30 )."&c2=$c2&beg=$beg&end=$end'> >> </a> </td> \n" ; } else { echo " <a href='$goto?cal=".$this->me."&c2=".($c2 - 86400*30 )."&c1=".$c1."&beg=$beg&end=$end'> << </a> </td> \n <th bgcolor=#336699 > ". strftime(" %B %Y" ,$c2 ) ." </th> \n <td> <a href='$goto?cal=".$this->me."&c2=".($c2 + 86400*30 )."&c1=$c1&beg=$beg&end=$end'> >> </a> </td> \n " ; } echo " </tr> <tr> <td COLSPAN=3 > <table BORDER=0 CELLSPACING=1 ALIGN='CENTER' WIDTH ='180' > <TR bgcolor=#336699 ><TH>L</TH><TH>M</TH><TH>M</TH><TH>J</TH><TH>V</TH><TH>S</TH><TH>D</TH></TH> "; $this->jj( $goto , $c1 , $c2 ) ; echo "</table> </td> </tr></table> "; } } // USAGE ( CODE fragment ) // if( ! defined ("BZ_calendar") ) include "lib/BZ_calendar.inc"; // if ( $time=='' ) $time = time(); // if ( !isset ($c1 )) $c1 = $time ; // if ( !isset ($c2 )) $c2 = $time ; // if (!isset ( $beg ) ) $beg = date("Y-m-d", $time); // if (!isset ( $end ) ) $end = date("Y-m-d", $time); // if ( $cal == 1 && $c2 < $c1 ) $c2 = $c1 ; // if ( $cal == 2 && $c2 < $c1 ) $c1 = $c2 ; // $cal1= new BZ_calendar ( 1 , $beg , $end ) ; // $cal2 = new BZ_calendar ( 2 , $beg , $end ) ; // // $cal1->draw("test.php3" , $c1 ,$c2 ); // // $cal2->draw("test.php3" , $c1 ,$c2 ); /// the first calendar select the start date , the second the end date ) // The query the database whith $beg and $end // enjoy ( but you have to change it a little to use the US date format )