jhylands

Callander drawer

Feb 13th, 2013
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.40 KB | None | 0 0
  1. <?php
  2. $monthNames = Array("January", "February", "March", "April", "May", "June", "July",
  3. "August", "September", "October", "November", "December");
  4. ?>
  5. <?php
  6. if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
  7. if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
  8. ?>
  9. <?php
  10. $cMonth = $_REQUEST["month"];
  11. $cYear = $_REQUEST["year"];
  12.  
  13. $prev_year = $cYear;
  14. $next_year = $cYear;
  15. $prev_month = $cMonth-1;
  16. $next_month = $cMonth+1;
  17.  
  18. if ($prev_month == 0 ) {
  19.     $prev_month = 12;
  20.     $prev_year = $cYear - 1;
  21. }
  22. if ($next_month == 13 ) {
  23.     $next_month = 1;
  24.     $next_year = $cYear + 1;
  25. }
  26. ?>
  27. <table width="200">
  28. <tr align="center">
  29. <td bgcolor="#999999" style="color:#FFFFFF">
  30. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  31. <tr>
  32. <td width="50%" align="left">  <a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td>
  33. <td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a>  </td>
  34. </tr>
  35. </table>
  36. </td>
  37. </tr>
  38. <tr>
  39. <td align="center">
  40. <table width="100%" border="0" cellpadding="2" cellspacing="2">
  41. <tr align="center">
  42. <td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
  43. </tr>
  44. <tr>
  45. <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
  46. <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td>
  47. <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
  48. <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td>
  49. <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
  50. <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td>
  51. <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
  52. </tr>
  53. <?php
  54. //This is the main value if this code, it draws the callander
  55. $timestamp = mktime(0,0,0,$cMonth,1,$cYear);
  56. $maxday = date("t",$timestamp);
  57. $thismonth = getdate ($timestamp);
  58. $startday = $thismonth['wday'];
  59. for ($i=0; $i<($maxday+$startday); $i++) {
  60.     if(($i % 7) == 0 ) echo "<tr>";
  61.     if($i < $startday) echo "<td></td>";
  62.     else echo "<td align='center' valign='middle' height='20px'>". ($i - $startday + 1) . "</td>";
  63.     if(($i % 7) == 6 ) echo "</tr>";
  64. }
  65. ?>
  66. </table>
  67. </td>
  68. </tr>
  69. </table>
Advertisement
Add Comment
Please, Sign In to add comment