用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - php代码库

php 日历类 日历控件

2014-11-28 作者: php源代码大全举报

[php]代码库

<?php
class CalendarForm {

  protected $year;
  protected $month;
  protected $day;
  protected $weekend;
  protected $currentdate;
  protected $dayofmonth;
  protected $day_count;
  protected $num;
  protected $week = array();
  protected $retunrhtml = "";

  function __construct($year, $month) {
    $this->makeWeeks($year, $month);
  }

  public function setYearMonth($year, $month) {
    $this->year = $year;
    $this->month = $month;
  }

  private function resetDayCount() {
    $this->day_count = 1;
  }

  private function setFirstWeek() {
    $this->num = 0;
  }

  public function getDayOfMonth($year, $month) {
    $this->resetDayCount();
    return date('t', mktime(0, 0, 0, $month, $this->day_count, $year));
  }

  private function setDayOfMonth($year, $month) {
    $this->dayofmonth = $this->getDayOfMonth($year, $month);
  }

  private function getDayOfWeek() {
    return date('w', mktime(0, 0, 0, $this->month, $this->day_count, $this->year));
  }

  public function getNextMonth() {
    return date('m', mktime(0, 0, 0, $this->month, 28, $this->year) + 432000);
  }

  public function getNextYear() {
    return date('Y', mktime(0, 0, 0, $this->month, 28, $this->year) + 432000);
  }

  public function getPrevMonth() {
    return date('m', mktime(0, 0, 0, $this->month, 1, $this->year) - 432000);
  }

  public function getPrevYear() {
    return date('Y', mktime(0, 0, 0, $this->month, 1, $this->year) - 432000);
  }

  private function makeWeeks($year, $month) {

    $this->setYearMonth($year, $month);
    $this->setDayOfMonth($this->year, $this->month);
    $this->setFirstWeek();

    $this->num = 0;
    for ($i = 0; $i < 7; $i++) {
      $dayofweek = $this->getDayOfWeek();
      $dayofweek = $dayofweek - 1;
      if ($dayofweek == -1) {
        $dayofweek = 6;
      }
      if ($dayofweek == $i) {
        $this->week[$this->num][$i] = $this->day_count;
        $this->day_count++;
      }
      else {
        $this->week[$this->num][$i] = "";
      }
    }
    while (TRUE) {
      $this->num++;
      for ($i = 0; $i < 7; $i++) {
        $this->week[$this->num][$i] = $this->day_count;
        $this->day_count++;
        if ($this->day_count > $this->dayofmonth) {
          break;
        }
      }
      if ($this->day_count > $this->dayofmonth) {
        break;
      }
    }

  }

  public function getCalendarHeader() {
    $this->retunrhtml =
      "<table class=\\"calendar-table\\">" .
      "<tbody>" .
      "<tr><th colspan=\\"7\\">" . $this->month . "/" . $this->year . "</th></tr>" .
      "<tr>" .
      "<th style=\\"text-align: center;\\">Monday</th>" .
      "<th style=\\"text-align: center;\\">Tuesday</th>" .
      "<th style=\\"text-align: center;\\">Wednesday</th>" .
      "<th style=\\"text-align: center;\\">Thursday</th>" .
      "<th style=\\"text-align: center;\\">Friday</th>" .
      "<th style=\\"text-align: center;\\">Saturday</th>" .
      "<th style=\\"text-align: center;\\">Sunday</th>" .
      "</tr>";
  }

  public function getCalendarFooter() {
    $this->retunrhtml .= "</tbody></table>";
  }

  public function getBeginTR() {
    $this->retunrhtml .= "<tr>";
  }

  public function getEndTR() {
    $this->retunrhtml .= "</tr>";
  }

  protected function getDay() {
    return $this->day;
  }

  protected function getMonth() {
    return $this->month;
  }

  protected function getYear() {
    return $this->year;
  }

  protected function isWeekend() {
    return $this->weekend;
  }

  protected function isCurrent() {
    return $this->currentdate;
  }

  public function getTDHref() {
    return $this->getDay();
  }

  public function getTD() {
    $class = '';
    $td = "td";
    if ($this->isCurrent()) {
      $class = 'today';
    }
    $this->retunrhtml .= "<$td class=\\"$class\\">" . $this->getTDHref() . "</$td>";
  }

  public function getTDWeekend() {
    $class = '';
    $td = "td";
    if ($this->isCurrent()) {
      $class = 'today';
    }
    $this->retunrhtml .= "<$td class=\\"$class\\">" . $this->getTDHref() . "</$td>";
  }

  protected function makeCodeMonth($year, $month) {
    $this->makeWeeks($year, $month);
    $this->getCalendarHeader();
    for ($i = 0; $i < count($this->week); $i++) {
      $this->getBeginTR();
      for ($j = 0; $j < 7; $j++) {

        if (!empty($this->week[$i][$j])) {
          $this->day = $this->week[$i][$j];
          $this->currentdate = 0;
          if ($this->year == date('Y') && $this->month == date('m') && $this->day == date('j')) {
            $this->currentdate = 1;
          }
          if ($j == 5 || $j == 6) {
            $this->weekend = 1;
            $this->getTDWeekend();
          }
          else {
            $this->weekend = 0;
            $this->getTD();
          }

        }
        else {
          $this->retunrhtml .= "<td> </td>";
        }

      }
      $this->getEndTR();
    }
    $this->getCalendarFooter();
  }

  public function getCodeMonth() {
    $this->makeCodeMonth($this->year, $this->month);
    return $this->retunrhtml;
  }

  public function showCodeMonth() {
    echo $this->getCodeMonth();
  }

}

class TechCalendarForm extends CalendarForm {
  public function getTDHref() {
    if ($this->isWeekend()) {
      $font = "<font color=\\"#FF3F4F\\">";
    }
    else {
      $font = "<font color=\\"#4A5B6C\\">";
    }
    return "<a href=\\"" . $_SERVER["PHP_SELF"] . "?action=showdate&date=" . parent::getYear() . "-" . parent::getMonth() . "-" . parent::getDay() . "\\">" . $font . parent::getDay() . "</font></a>";
  }
}



网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...