PHP - Customizable Calandar class


SUBMITTED BY: efbee

DATE: Oct. 3, 2016, 4:01 p.m.

FORMAT: PHP

SIZE: 5.2 kB

HITS: 699

  1. Customizable Calendar Class
  2. <?
  3. class calendar {
  4. var
  5. $daynamefont,$daynamebgcolor,$daynamecolor,$daynamesize,$daynamebold,$daynameitalic
  6. ,
  7. $dayfont,$daybgcolor,$daycolor,$dayactivecolor,$daysize,$daybold,$dayitalic,
  8. $showdate,$bordersize,$timestamp;
  9. function calendar(){
  10. if(empty($this->daynamefont)==true)$this->daynamefont="Arial, sans-serif";
  11. if(empty($this->daynamebgcolor)==true)$this->daynamebgcolor="#000060";
  12. if(empty($this->daynamecolor)==true)$this->daynamecolor="#FFFFFF";
  13. if(empty($this->daynamesize)==true)$this->daynamesize="3";
  14. if(empty($this->daynamebold)==true)$this->daynamebold=true;
  15. if(empty($this->daynameitalic)==true)$this->daynameitalic=false;
  16. if(empty($this->dayfont)==true)$this->dayfont="Arial, sans-serif";
  17. if(empty($this->daybgcolor)==true)$this->daybgcolor="#FFCA00";
  18. if(empty($this->daycolor)==true)$this->daycolor="#000000";
  19. if(empty($this->dayactivecolor)==true)$this->dayactivecolor="#FF0000";
  20. if(empty($this->daysize)==true)$this->daysize="3";
  21. if(empty($this->daybold)==true)$this->daybold=true;
  22. if(empty($this->dayitalic)==true)$this->dayitalic=false;
  23. if(empty($this->showdate)==true)$this->showdate=true;
  24. if(empty($this->bordersize)==true)$this->bordersize="2";
  25. if(empty($this->timestamp)==true)$this->timestamp=time();
  26. }
  27. function show(){
  28. $day=date("j",$this->timestamp);
  29. $month=date("n",$this->timestamp);
  30. $year=date("Y",$this->timestamp);
  31. if($this->daynamebold==true){
  32. $daynametextprefix="<b>";
  33. $daynametextsuffix="</b>";
  34. }
  35. if($this->daynameitalic==true){
  36. $daynametextprefix.="<i>";
  37. $daynametextsuffix="</i>".$daynametextsuffix;
  38. }
  39. if($this->daybold==true){
  40. $daytextprefix="<b>";
  41. $daytextsuffix="</b>";
  42. }
  43. if($this->dayitalic==true){
  44. $daytextprefix.="<i>";
  45. $daytextsuffix="</i>".$daytextsuffix;
  46. }
  47. if(checkdate($month,$day,$year)==true){
  48. $maxdays=31;
  49. while(checkdate($month,$maxdays,$year)==false)$maxdays--;
  50. $startday=1-date("w",mktime(0,0,0,$month,1,$year));
  51. print("<table border='".$this->bordersize."' cellspacing='0' cellpadding='0'><tr
  52. bgcolor='".$this->daybgcolor."'><td>\n");
  53. print(" <table border='0' cellspacing='0' cellpadding='2'>\n");
  54. if($this->showdate==true)print(" <tr bgcolor='".$this->daynamebgcolor."'><td
  55. colspan='7'><font face='".$this->daynamefont."' color='".$this->daynamecolor."' size='".$this-
  56. >daynamesize."'><div align='center'>".$daynametextprefix.date("F",mktime
  57. (0,0,0,$month,$day,$year))." $year".$daynametextsuffix."</div></font></td></tr>\n");
  58. print(" <tr bgcolor='".$this->daynamebgcolor."'><td align='center'><font face='".$this-
  59. >daynamefont."' color='".$this->daynamecolor."' size='".$this-
  60. >daynamesize."'>".$daynametextprefix." S ".$daynametextsuffix."</font></td><td
  61. align='center'><font face='".$this->daynamefont."' color='".$this->daynamecolor."'
  62. size='".$this->daynamesize."'>".$daynametextprefix."
  63. M ".$daynametextsuffix."</font></td><td align='center'><font face='".$this->daynamefont."'
  64. color='".$this->daynamecolor."' size='".$this->daynamesize."'>".$daynametextprefix."
  65. T ".$daynametextsuffix."</font></td><td align='center'><font face='".$this->daynamefont."'
  66. color='".$this->daynamecolor."' size='".$this->daynamesize."'>".$daynametextprefix."
  67. W ".$daynametextsuffix."</font></td><td align='center'><font face='".$this->daynamefont."'
  68. color='".$this->daynamecolor."' size='".$this->daynamesize."'>".$daynametextprefix."
  69. T ".$daynametextsuffix."</font></td><td align='center'><font face='".$this->daynamefont."'
  70. color='".$this->daynamecolor."' size='".$this->daynamesize."'>".$daynametextprefix."
  71. F ".$daynametextsuffix."</font></td><td align='center'><font face='".$this->daynamefont."'
  72. color='".$this->daynamecolor."' size='".$this->daynamesize."'>".$daynametextprefix."
  73. S ".$daynametextsuffix."</font></td>");
  74. $weekdaycount=0;
  75. for($daycount=$startday;$daycount<=$maxdays;$daycount++){
  76. if(($weekdaycount%7)==0)print("</tr>\n <tr bgcolor='".$this->daybgcolor."'>");
  77. if($daycount>0){
  78. print("<td align='right'>");
  79. if($daycount!=$day){
  80. print("<font face='".$this->dayfont."' color='".$this->daycolor."' size='".$this-
  81. >daysize."'>".$daytextprefix." ".$daycount." ".$daytextsuffix."</font>");
  82. } else print("<font face='".$this->dayfont."' color='".$this->dayactivecolor."'
  83. size='".$this->daysize."'>".$daytextprefix." ".$daycount." ".$daytextsuffix."</font>");
  84. } else print("<td>");
  85. print("</td>");
  86. $weekdaycount++;
  87. }
  88. while($weekdaycount%7<>0){
  89. print("<td></td>");
  90. $weekdaycount++;
  91. }
  92. print("</tr>\n </table>\n");
  93. print("</td></tr></table>\n");
  94. } else print("Incorrect date");
  95. }
  96. }
  97. ?>

comments powered by Disqus