codigo calendar


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. /************************************************************
  3. * PHP Calendar by Scott Richardson, ScanOnline June 2002 *
  4. ************************************************************/
  5.  
  6. //date sent to calendar
  7. if( !isset($_REQUEST["CurrentMonth"]) ) {
  8. $WorkDate = date("m/d/Y");
  9. }
  10. else{
  11. $WorkDate = $_REQUEST['CurrentMonth'];
  12. }
  13. $PrevMonth = date("m/d/Y", strtotime($WorkDate . "-1 month"));
  14. $NextMonth = date("m/d/Y", strtotime($WorkDate . "+1 month"));
  15.  
  16. //page that called the calendar
  17. if( !isset($_REQUEST["ParentPage"]) ) {
  18. $ParentPage = "";
  19. }
  20. else{
  21. $ParentPage = $_REQUEST["ParentPage"];
  22. }
  23.  
  24. $Today = date("j",strtotime($WorkDate));
  25. $DaysThisMonth = DaysInMonth(date("m/d/Y",strtotime($WorkDate)));
  26. $DaysLastMonth = DaysInMonth(date("m/d/Y", strtotime ($PrevMonth)));
  27. $InThisMonth = 0;
  28. $CurrentDate = GetStartingPoint($DaysLastMonth);
  29.  
  30. //Head
  31. echo "<html><head></head>";
  32.  
  33. //Body
  34. echo "<body topmargin='100' leftmargin='100' marginheight='100' marginwidth='100'>";
  35.  
  36.  
  37. echo "<table bgcolor='B0C4DE' height='100%' width='100%' border='1'><tr>";
  38. echo "<td colspan='7' height='8%' align='center' >";
  39.  
  40. echo "<table height='100%' width='100%' border='0'><tr>";
  41. echo "<td align='left'><b><font size='2'><a href='http://localhost/calendar/cal.php?CurrentMonth=".$PrevMonth."&ParentPage=".$ParentPage."'>Mês<br>Anterior</a></font></b></td>";
  42. echo "<td align='center'>";
  43. echo "<font size='5'><b>".date("F Y",strtotime($WorkDate))."</b></font><br><a href='http://localhost/calendar/cal.php?CurrentMonth=".date("m/d/Y")."&ParentPage=".$ParentPage."'>Data de Hoje</a></td>";
  44. echo "<td align='right'><b><font size='2'><a href='http://localhost/calendar/cal.php?CurrentMonth=".$NextMonth."&ParentPage=".$ParentPage."'>Próximo<br>Mês</a></font></b></td></tr></table>";
  45.  
  46. echo "</td></tr>";
  47. echo "<td height='8%' align='center' valign='top' width='15%' bgcolor='B0C4DE'><font size='4'><b>Su</b></font></td>";
  48. echo "<td align='center' valign='top' width='14%' bgcolor='B0C4DE'><font size='4'><b>Mo</b></font></td>";
  49. echo "<td align='center' valign='top' width='14%' bgcolor='B0C4DE'><font size='4'><b>Tu</b></font></td>";
  50. echo "<td align='center' valign='top' width='14%' bgcolor='B0C4DE'><font size='4'><b>We</b></font></td>";
  51. echo "<td align='center' valign='top' width='14%' bgcolor='B0C4DE'><font size='4'><b>Th</b></font></td>";
  52. echo "<td align='center' valign='top' width='14%' bgcolor='B0C4DE'><font size='4'><b>Fr</b></font></td>";
  53. echo "<td align='center' valign='top' width='15%' bgcolor='B0C4DE'><font size='4'><b>Sa</b></font></td></tr>";
  54.  
  55. for($x=1;$x<7;$x++){
  56. echo "<tr>";
  57. for($i=1;$i<8;$i++){
  58. echo "<td align='left' valign='top' height='14%' ";
  59.  
  60. if($InThisMonth==0){
  61. echo "bgcolor='#D3D3D3'>";
  62. echo $CurrentDate++;
  63. }
  64. else{
  65. if( $CurrentDate == date("j") && date("n",strtotime($WorkDate)) == date("n") && date("y",strtotime($WorkDate)) == date("y") ){
  66. echo "bgcolor='FFFACD'>";
  67. }
  68. else{
  69. echo "bgcolor='#FFFFFF'>";
  70. }
  71.  
  72. if( $ParentPage ){
  73. echo "<a href='".$ParentPage."?CalendarDate=".GetThisDate($CurrentDate)."'>".$CurrentDate++."</a>";
  74. }
  75. else{
  76. echo $CurrentDate++;
  77. }
  78. }
  79.  
  80. echo "</td>";
  81.  
  82. if( $InThisMonth == 0 && $CurrentDate > $DaysLastMonth ){
  83. $CurrentDate = 1;
  84. $InThisMonth = 1;
  85. }
  86. elseif($InThisMonth == 1 && $CurrentDate > $DaysThisMonth ){
  87. $CurrentDate = 1;
  88. $InThisMonth = 0;
  89. }
  90.  
  91. }
  92. echo "</tr>";
  93. }
  94.  
  95. echo "</table></body></html>";
  96.  
  97.  
  98. function DaysInMonth($dt) {
  99. return date("t",strtotime($dt));
  100. }
  101.  
  102. function GetStartingPoint($DLM){
  103. $today = getdate(strtotime($GLOBALS['WorkDate']));
  104. $mday = $today['mday'];
  105. $mday-=1;
  106. $FirstOfMonth = date("m/d/Y",strtotime($GLOBALS['WorkDate'] . "-" . $mday . " days"));
  107.  
  108. switch(date("l",strtotime($FirstOfMonth))){
  109. case "Sunday":
  110. $CD = 1;
  111. $GLOBALS["InThisMonth"] = 1;
  112. break;
  113.  
  114. case "Monday":
  115. $CD = $DLM;
  116. break;
  117.  
  118. case "Tuesday":
  119. $CD = $DLM-1;
  120. break;
  121.  
  122. case "Wednesday":
  123. $CD = $DLM-2;
  124. break;
  125.  
  126. case "Thursday":
  127. $CD = $DLM-3;
  128. break;
  129.  
  130. case "Friday":
  131. $CD = $DLM-4;
  132. break;
  133.  
  134. case "Saturday":
  135. $CD = $DLM-5;
  136. }
  137.  
  138. return $CD;
  139. }
  140.  
  141. function GetThisDate($SelectedDay){
  142. $today = getdate(strtotime($GLOBALS['WorkDate']));
  143. $mon = $today['mon'];
  144. $myear = $today['year'];
  145. return date("m/d/Y", strtotime($mon."/".$SelectedDay."/".$myear));
  146. }
  147. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.