PHP customizable calender example


SUBMITTED BY: amankalsi22

DATE: Oct. 3, 2016, 5:41 p.m.

FORMAT: Text only

SIZE: 5.2 kB

HITS: 948

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

comments powered by Disqus