Your IP : 216.73.217.93


Current Path : /home/sunflowe/www/calendar/include/
Upload File :
Current File : /home/sunflowe/www/calendar/include/calendar.inc.php

<?
/*
 +-------------------------------------------------------------------+
 |                  P H P - C A L E N D A R   (v2.1)                 |
 |                                                                   |
 | Copyright Gerd Tentler               www.gerd-tentler.de/tools    |
 | Created: May 27, 2003                Last modified: Dec. 29, 2005 |
 | Modified by Gaetan Bibler            Last modified: Fev. 27, 2007 |
 +-------------------------------------------------------------------+
 | This program may be used and hosted free of charge by anyone for  |
 | personal purpose as long as this copyright notice remains intact. |
 |                                                                   |
 | Obtain permission before selling the code for this program or     |
 | hosting this software on a commercial website or redistributing   |
 | this software over the Internet or in any other medium. In all    |
 | cases copyright must remain intact.                               |
 +-------------------------------------------------------------------+

 EXAMPLE #1:  $myCal = new CALENDAR();
              echo $myCal->create();

 EXAMPLE #2:  $myCal = new CALENDAR("2004-12");
              echo $myCal->create();

 EXAMPLE #3:  $myCal = new CALENDAR();
              $myCal->year = 2004;
              $myCal->month = 12;
              echo $myCal->create();
==========================================================================================================
*/

  class CALENDAR {
//========================================================================================================
// Configuration
//========================================================================================================
    var $link = '';                      // page to link to when day is clicked
    var $offset = 1;                     // week start: 0 - 6 (0 = Saturday, 1 = Sunday, 2 = Monday ...)

    // weekdays: must start with Saturday because January 1st of year 1 was a Saturday
    var $weekdays = array('S', 'S', 'M', 'T', 'W', 'T', 'F');

    // months: must start with January
    var $months = array('January', 'February', 'March', 'April', 'May', 'June','July', 'August', 'September', 'October', 'November', 'December');

    var $disableExpiredDays = true;     // grays days before today : true / false
    var $disableMixedDays = true;				// hide swap rents

    // don't change from here
    var $year, $month;
    var $mDays = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    var $mBDays = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
    var $styleSet = false;
//========================================================================================================
// Functions
//========================================================================================================
    function CALENDAR($date = '') {
      if(!$date) $date = date('Y-m');
      $d = explode('-', $date);
      $this->year = $d[0];
      $this->month = $d[1];
    }

    function leap_year($year) {
      return (!($year % 4) && ($year < 1582 || $year % 100 || !($year % 400))) ? true : false;
    }

    function get_weekday($year, $days) {
      $a = $days;
      if($year) $a += ($year - 1) * 365;
      for($i = 1; $i < $year; $i++) if($this->leap_year($i)) $a++;
      if($year > 1582 || ($year == 1582 && $days >= 277)) $a -= 10;
      if($a) $a = ($a - $this->offset) % 7;
      else if($this->offset) $a += 7 - $this->offset;

      return $a;
    }

    function get_week($year, $days) {
      $firstWDay = $this->get_weekday($year, 0);
      return floor(($days + $firstWDay) / 7) + ($firstWDay <= 3);
    }

    function table_cell($content, $class, $date = '') {
      $html = '<td class="' . $class . '"';
      if($this->link && $content != '&nbsp;' && stristr($class, 'day')) {
        $html .= ' onMouseOver="this.className=\'cssHilight\'"';
        $html .= ' onMouseOut="this.className=\'' . $class . '\'"';
        $html .= ' onClick="document.location.href=\'' . $this->link . '?date=' . $date . '\'"';
      }
      $html .= '>' . $content . '</td>';
      return $html;
    }

    function table_head($title) {
      $html = '<tr><th colspan=8 class="cssTitle"><b>' . $title . '</b></th></tr><tr>';
      for($i = 0; $i <= 6; $i++) {
        $ind = ($i + $this->offset) % 7;
        $wDay = $this->weekdays[$ind];
        $html .= $this->table_cell($wDay, 'cssHeading');
      }
      $html .= $this->table_cell('&nbsp;', 'cssHeading');
      $html .= '</tr>';
      return $html;
    }

    function create() {
      $curDate = date('Y-m-d');
      //$curDate = '2007-03-21';
      $d = explode('-', $curDate);
      $curYear = $d[0];
      $curMonth = $d[1];
      $curDay = $d[2];
      if($this->year < 1 || $this->year > 3999) $html = '<b>Year must be 1 - 3999!</b>';
      else {
        $html = "";
        //if($this->leap_year($this->year)) $this->mDays[1] = 29;
        $this->leap_year($this->year) ? $this->mDays[1] = 29 : $this->mDays[1] = 28;
        for($i = $days = 0; $i < $this->month - 1; $i++) $days += $this->mDays[$i];
        $start = $this->get_weekday($this->year, $days);
        $stop = $this->mDays[$this->month-1];
        $html .= '<table border=0 cellspacing=0 cellpadding=0><tr>';
        $html .= '<td class="cssCalendar">';
        $html .= '<table border=0 cellspacing=1 cellpadding=0>';
        $title = htmlentities($this->months[$this->month-1]) . ' ' . $this->year;
        $html .= $this->table_head($title);
        $daycount = 1;
        if(($this->year == $curYear) && ($this->month == $curMonth)) $inThisMonth = true;
        else $inThisMonth = false;
        $weekNr = $this->get_week($this->year, $days);
        while($daycount <= $stop) {
          $html .= '<tr>';
          for($i = $wdays = 0; $i <= 6; $i++) {
            $date = '';
            $class = 'cssDays';
            if(($daycount == 1 && $i < $start) || $daycount > $stop) {
              $class = 'cssEmpty';
              $content = '&nbsp;';
            } else {
              $content = $daycount;
              $date = $this->year . '-' . str_pad($this->month, 2, "0", STR_PAD_LEFT) . '-' . str_pad($daycount, 2, "0", STR_PAD_LEFT);
              $daycount--;
              if ((($date < $curDate) && ($this->disableExpiredDays)) || ($this->mBDays[$daycount] == 1)) $class = 'cssUnavailableDays';
              else
                switch ($this->mBDays[$daycount]) {
                  case 2:
                    $class = 'cssPStartDays';
                    break;
                  case 3:
                    $class = 'cssPendingDays';
                    break;
                  case 4:
                    $class = 'cssPStopDays';
                    break;
                  case 5:
                    $class = 'cssBStartDays';
                    break;
                  case 6:
                    $class = 'cssBookedDays';
                    break;
                  case 7:
                    $class = 'cssBStopDays';
                    break;
                  case 8:
                  	$class = 'cssPBMixedDays';
                    break;
                  case 9:
                  	$class = 'cssBPMixedDays';
                    break;
                  case 10:
                  	$this->disableMixedDays ? $class = 'cssBookedDays' : $class = 'cssBBMixedDays';
                    break;
                  case 11:
                  	$this->disableMixedDays ? $class = 'cssBookedDays' : $class = 'cssPPMixedDays';
                    break;
                  default:
                  $ind = ($i + $this->offset) % 7;
                  if($ind == 0) $class = 'cssSaturdays';
                  else if($ind == 1) $class = 'cssSundays';
                }
              $daycount++;
              if($inThisMonth && $daycount == $curDay) $class = 'cssToday';
              else if($this->year == 1582 && $this->month == 10 && $daycount == 4) $daycount = 14;
              $daycount++;
              $wdays++;
            }
            $html .= $this->table_cell($content, $class, $date);
          }
          if(!$weekNr) {
            if($this->year == 1) $content = '&nbsp;';
            else if($this->year == 1583) $content = 52;
            else $content = $this->get_week($this->year - 1, 365);
          }
          else if($this->month == 12 && $weekNr >= 52 && $wdays < 4) $content = 1;
          else $content = $weekNr;
          $html .= $this->table_cell($content, 'cssWeeks');
          $html .= '</tr>';
          $weekNr++;
        }
        $html .= '</table></td></tr></table>'.$dummy;
        // Fin de calendrier mensuel
      }
      return $html;
    }
  }
?>