Calendar
[ class tree: Calendar ] [ index: Calendar ] [ all elements ]

Source for file 3.php

Documentation is available at 3.php

  1. <?php
  2. /**
  3. * Description: Performs same behaviour as 2.php but uses Month::buildWeekDays()
  4. * and is faster
  5. */
  6. function getmicrotime(){
  7.     list($usec$secexplode(" ",microtime());
  8.     return ((float)$usec + (float)$sec);
  9. }
  10. $start getmicrotime();
  11.  
  12. if !@include 'Calendar/Calendar.php' {
  13.     define('CALENDAR_ROOT','../../');
  14. }
  15. require_once CALENDAR_ROOT.'Month/Weekdays.php';
  16. require_once CALENDAR_ROOT.'Day.php';
  17.  
  18. if (!isset($_GET['y'])) $_GET['y'date('Y');
  19. if (!isset($_GET['m'])) $_GET['m'date('m');
  20. if (!isset($_GET['d'])) $_GET['d'date('d');
  21.  
  22. // Build the month
  23. $Month = new Calendar_Month_Weekdays($_GET['y'],$_GET['m']);
  24.  
  25. // Construct strings for next/previous links
  26. $PMonth $Month->prevMonth('object')// Get previous month as object
  27. $prev $_SERVER['PHP_SELF'].'?y='.$PMonth->thisYear().'&m='.$PMonth->thisMonth().'&d='.$PMonth->thisDay();
  28. $NMonth $Month->nextMonth('object');
  29. $next $_SERVER['PHP_SELF'].'?y='.$NMonth->thisYear().'&m='.$NMonth->thisMonth().'&d='.$NMonth->thisDay();
  30. ?>
  31. <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
  32. <html>
  33. <head>
  34. <title> Calendar </title>
  35. <style text="text/css">
  36. table {
  37.     background-color: silver;
  38. }
  39. caption {
  40.     font-family: verdana;
  41.     font-size: 12px;
  42.     background-color: while;
  43. }
  44. .prevMonth {
  45.     font-size: 10px;
  46.     text-align: left;
  47. }
  48. .nextMonth {
  49.     font-size: 10px;
  50.     text-align: right;
  51. }
  52. th {
  53.     font-family: verdana;
  54.     font-size: 11px;
  55.     color: navy;
  56.     text-align: right;
  57. }
  58. td {
  59.     font-family: verdana;
  60.     font-size: 11px;
  61.     text-align: right;
  62. }
  63. .selected {
  64.     background-color: yellow;
  65. }
  66. </style>
  67. </head>
  68.  
  69. <body>
  70.  
  71. <?php
  72. $selectedDays = array (
  73.     new Calendar_Day($_GET['y'],$_GET['m'],$_GET['d']),
  74.     new Calendar_Day($_GET['y'],12,25),
  75.     );
  76.  
  77. // Build the days in the month
  78. $Month->build($selectedDays);
  79. ?>
  80. <h2>Built with Calendar_Month_Weekday::build()</h2>
  81. <table class="calendar">
  82. <caption>
  83. <?php echo date('F Y',$Month->getTimeStamp()))?>
  84. </caption>
  85. <tr>
  86. <th>M</th>
  87. <th>T</th>
  88. <th>W</th>
  89. <th>T</th>
  90. <th>F</th>
  91. <th>S</th>
  92. <th>S</th>
  93. </tr>
  94. <?php
  95. while $Day $Month->fetch() ) {
  96.  
  97.     // Build a link string for each day
  98.     $link $_SERVER['PHP_SELF'].
  99.                 '?y='.$Day->thisYear().
  100.                 '&m='.$Day->thisMonth().
  101.                 '&d='.$Day->thisDay();
  102.  
  103.     // isFirst() to find start of week
  104.     if $Day->isFirst() )
  105.         echo "<tr>\n" );
  106.  
  107.     if $Day->isSelected() ) {
  108.        echo "<td class=\"selected\">".$Day->thisDay()."</td>\n" );
  109.     else if $Day->isEmpty() ) {
  110.         echo "<td>&nbsp;</td>\n" );
  111.     else {
  112.         echo "<td><a href=\"".$link."\">".$Day->thisDay()."</a></td>\n" );
  113.     }
  114.  
  115.     // isLast() to find end of week
  116.     if $Day->isLast() )
  117.         echo "</tr>\n" );
  118. }
  119. ?>
  120. <tr>
  121. <td>
  122. <a href="<?php echo ($prev);?>" class="prevMonth"><< </a>
  123. </td>
  124. <td colspan="5">&nbsp;</td>
  125. <td>
  126. <a href="<?php echo ($next);?>" class="nextMonth"> >></a>
  127. </td>
  128. </tr>
  129. </table>
  130. <?php
  131. echo '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' );
  132. ?>
  133. </body>
  134. </html>

Documentation generated on Mon, 11 Mar 2019 15:37:47 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.