Guest User

Untitled

a guest
Feb 20th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.48 KB | None | 0 0
  1. <?php
  2. ## change to the previous month
  3. if ($command == "prev_month") {
  4.     if (--$month == 0) {
  5.         $month = 12;
  6.         $year--;
  7.     }
  8. }
  9. ## change to the next month
  10. else if ($command == "next_month") {
  11.     if (++$month == 13) {
  12.         $month = 1;
  13.         $year++;
  14.     }
  15. }
  16.  
  17. ## if no month has been passed
  18. if ($month == "") {
  19.     $year = date("Y");
  20.     $month = date("n");
  21.     $month_name = date("F", mktime(0, 0, 0, $month, 1, $year));
  22. }
  23. ## use current date if no month is passed
  24. else {
  25.     $year = date("Y", mktime(0, 0, 0, $month, 1, $year));
  26.     $month = date("n", mktime(0, 0, 0, $month, 1, $year));
  27.     $month_name = date("F", mktime(0, 0, 0, $month, 1, $year));
  28. }
  29.  
  30.  
  31. $dow = date("w", mktime(0, 0, 0, $month, 1, $year));  //which day 1 falls on in the week  (0 = Sun)
  32. $dim = date("d", mktime(0, 0, 0, $month + 1, 0, $year)); //days in the current month
  33. ## modification to only print the number of weeks in a month
  34. $wim = ceil(($dim + $dow) / 7); //weeks in month
  35.  
  36. $ct = 0;
  37.  
  38. echo "<br>
  39. <table border='0' cellpadding='1' cellspacing='1' width='425' align='center'>
  40. <tr>
  41.  <td align='center'><h1><a href='index.php?
  42. command=prev_month&month=$month&year=$year'><<</a> $month_name $year <a
  43. href='index.php?command=next_month&month=$month&year=$year'>>></a></h1></td>
  44. </tr>
  45. </table>
  46. <table border='1' cellpadding='1' cellspacing='1' width='425' align='center'>
  47. <tr>
  48.  <td  align='center'><b>Sun</td>
  49.  <td  align='center'><b>Mon</td>
  50.  <td  align='center'><b>Tue</td>
  51.  <td  align='center'><b>Wed</td>
  52.  <td  align='center'><b>Thu</td>
  53.  <td  align='center'><b>Fri</td>
  54.  <td  align='center'><b>Sat</td>
  55. </tr>";
  56.  
  57. ## print only the number of weeks needed
  58. for ($row = 1; $row < $wim + 1; $row++) {
  59.     echo "<tr height='60'>";
  60.  
  61.     ## prints week (Sun to Sat)
  62.    for ($week = 1; $week < 8; $week++) {
  63.         $ct++;
  64.         $value = mktime(0, 0, 0, $month, $ct - $dow, $year);
  65.  
  66.         ## if $value is part of current month
  67.        if (date("m", $value) == $month) {
  68.             echo "<td align='center' class='body' width='85' valign='top'> <div align='right'><b>" . date("j", $value) . "</a></b></div><br> </td>";
  69.         }
  70.         ## print previous and next month dates, but grayed out
  71.        else {
  72.             echo "<td align='center' class='body' width='85' valign='top' bgcolor='#CCCCCC'><div align='right'><b>" . date("j", $value) . "</a></b></div><br></td>";
  73.         }
  74.     }
  75.  
  76.     echo "</tr>";
  77. }
  78.  
  79. echo "</table>";
  80.  
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment