Posted By

others on 09/27/07


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

skywalker
yoren


codigo calendar


 / Published in: PHP
 

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

Report this snippet  

You need to login to post a comment.