PHP Calendar Class Calendar control

Source: Internet
Author: User
  • }
  • }
  • }
  • Public Function Getendtr () {
  • $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 (). "";
  • }
  • Copy the Code
  • "; ";
  • 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. = "
  • ";
    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, $this->year) + 432000);
    37. }
    38. Public Function Getnextyear () {
    39. Return date (' Y ', mktime (0, 0, 0, $this->month, $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. Public Function Getcalendarfooter () {
    96. $this->retunrhtml. = "
    97. " . " . " . " . ". ". ". ". ". ". ". ";
      " . $this->month. "/" . $this->year. "
      MondayTuesdayWednesdayThursdayFridaySaturdaySunday
      ";
    98. }
    99. Public Function getbegintr () {
    100. $this->retunrhtml. = "
    Php
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.