当前位置:Gxlcms > PHP教程 > 日历表格

日历表格

时间:2021-07-01 10:21:17 帮助过:5人阅读

";
  • }
  • public function getEndTR() {
  • $this->retunrhtml .= "
  • ";
  • }
  • 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() . "";
  • }
  • public function getTDWeekend() {
  • $class = '';
  • $td = "td";
  • if ($this->isCurrent()) {
  • $class = 'today';
  • }
  • $this->retunrhtml .= "<$td class=\"$class\">" . $this->getTDHref() . "";
  • }
  • 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 .= "
  • ";
  • }
  • }
  • $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 = "";
  • }
  • else {
  • $font = "";
  • }
  • return "" . $font . parent::getDay() . "";
  • }
  • }
  • 使用例子:
    $cal = new CalendarForm(2012, 5);
    $cal->showCodeMonth();
    1. class CalendarForm {
    2. protected $year;
    3. protected $month;
    4. protected $day;
    5. protected $weekend;
    6. protected $currentdate;
    7. protected $dayofmonth;
    8. protected $day_count;
    9. protected $num;
    10. protected $week = array();
    11. protected $retunrhtml = "";
    12. function __construct($year, $month) {
    13. $this->makeWeeks($year, $month);
    14. }
    15. public function setYearMonth($year, $month) {
    16. $this->year = $year;
    17. $this->month = $month;
    18. }
    19. private function resetDayCount() {
    20. $this->day_count = 1;
    21. }
    22. private function setFirstWeek() {
    23. $this->num = 0;
    24. }
    25. public function getDayOfMonth($year, $month) {
    26. $this->resetDayCount();
    27. return date('t', mktime(0, 0, 0, $month, $this->day_count, $year));
    28. }
    29. private function setDayOfMonth($year, $month) {
    30. $this->dayofmonth = $this->getDayOfMonth($year, $month);
    31. }
    32. private function getDayOfWeek() {
    33. return date('w', mktime(0, 0, 0, $this->month, $this->day_count, $this->year));
    34. }
    35. public function getNextMonth() {
    36. return date('m', mktime(0, 0, 0, $this->month, 28, $this->year) + 432000);
    37. }
    38. public function getNextYear() {
    39. return date('Y', mktime(0, 0, 0, $this->month, 28, $this->year) + 432000);
    40. }
    41. public function getPrevMonth() {
    42. return date('m', mktime(0, 0, 0, $this->month, 1, $this->year) - 432000);
    43. }
    44. public function getPrevYear() {
    45. return date('Y', mktime(0, 0, 0, $this->month, 1, $this->year) - 432000);
    46. }
    47. private function makeWeeks($year, $month) {
    48. $this->setYearMonth($year, $month);
    49. $this->setDayOfMonth($this->year, $this->month);
    50. $this->setFirstWeek();
    51. $this->num = 0;
    52. for ($i = 0; $i < 7; $i++) {
    53. $dayofweek = $this->getDayOfWeek();
    54. $dayofweek = $dayofweek - 1;
    55. if ($dayofweek == -1) {
    56. $dayofweek = 6;
    57. }
    58. if ($dayofweek == $i) {
    59. $this->week[$this->num][$i] = $this->day_count;
    60. $this->day_count++;
    61. }
    62. else {
    63. $this->week[$this->num][$i] = "";
    64. }
    65. }
    66. while (TRUE) {
    67. $this->num++;
    68. for ($i = 0; $i < 7; $i++) {
    69. $this->week[$this->num][$i] = $this->day_count;
    70. $this->day_count++;
    71. if ($this->day_count > $this->dayofmonth) {
    72. break;
    73. }
    74. }
    75. if ($this->day_count > $this->dayofmonth) {
    76. break;
    77. }
    78. }
    79. }
    80. public function getCalendarHeader() {
    81. $this->retunrhtml =
    82. "" .
    83. "
    84. " .
    85. "
    86. " .
    87. "
    88. " .
    89. "
    90. " .
    91. "
    92. " .
    93. "
    94. " .
    95. "
    96. " .
    97. "
    98. " .
    99. "
    100. " .
    101. "
    102. " .
    103. "
    104. ";
    105. }
    106. public function getCalendarFooter() {
    107. $this->retunrhtml .= "
    108. " . $this->month . "/" . $this->year . "
      MondayTuesdayWednesdayThursdayFridaySaturdaySunday
      ";
    109. }
    110. public function getBeginTR() {
    111. $this->retunrhtml .= "

    人气教程排行