calendar.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * Displays the main calendar page (month view).
  4. *
  5. * @copyright &copy; 2002-2007 The SquirrelMail Project Team
  6. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  7. * @version $Id$
  8. * @package plugins
  9. * @subpackage calendar
  10. */
  11. /**
  12. * Include the SquirrelMail initialization file.
  13. */
  14. require('../../include/init.php');
  15. /* load date_intl() */
  16. include_once(SM_PATH . 'functions/date.php');
  17. /* Calendar plugin required files. */
  18. include_once(SM_PATH . 'plugins/calendar/calendar_data.php');
  19. include_once(SM_PATH . 'plugins/calendar/functions.php');
  20. /* get globals */
  21. if (! sqgetGlobalVar('month',$month,SQ_FORM) || ! is_numeric($month)) {
  22. unset($month);
  23. }
  24. if (! sqgetGlobalVar('year',$year,SQ_FORM) || ! is_numeric($year)) {
  25. unset($year);
  26. }
  27. /* got 'em */
  28. /**
  29. * display upper part of month calendar view
  30. * @return void
  31. * @access private
  32. */
  33. function startcalendar() {
  34. global $year, $month, $color;
  35. $prev_date = mktime(0, 0, 0, $month - 1, 1, $year);
  36. $act_date = mktime(0, 0, 0, $month, 1, $year);
  37. $next_date = mktime(0, 0, 0, $month + 1, 1, $year);
  38. $prev_month = date( 'm', $prev_date );
  39. $next_month = date( 'm', $next_date);
  40. $prev_year = date( 'Y', $prev_date);
  41. $next_year = date( 'Y', $next_date );
  42. $self = 'calendar.php';
  43. echo html_tag( 'tr', "\n".
  44. html_tag( 'td', "\n".
  45. html_tag( 'table', '', '', $color[0], 'width="100%" border="0" cellpadding="2" cellspacing="1"' ) .
  46. html_tag( 'tr', "\n".
  47. html_tag( 'th',
  48. "<a href=\"$self?year=".($year-1)."&amp;month=$month\">&lt;&lt;&nbsp;".($year-1)."</a>"
  49. ) . "\n".
  50. html_tag( 'th',
  51. "<a href=\"$self?year=$prev_year&amp;month=$prev_month\">&lt;&nbsp;" .
  52. date_intl( 'M', $prev_date). "</a>"
  53. ) . "\n".
  54. html_tag( 'th', date_intl( 'F Y', $act_date ), '', $color[0], 'colspan="3"') .
  55. html_tag( 'th',
  56. "<a href=\"$self?year=$next_year&amp;month=$next_month\">" .
  57. date_intl( 'M', $next_date) . "&nbsp;&gt;</a>"
  58. ) . "\n".
  59. html_tag( 'th',
  60. "<a href=\"$self?year=".($year+1)."&amp;month=$month\">".($year+1)."&nbsp;&gt;&gt;</a>"
  61. )
  62. ) . "\n".
  63. html_tag( 'tr',
  64. html_tag( 'th', _("Sunday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
  65. html_tag( 'th', _("Monday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
  66. html_tag( 'th', _("Tuesday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
  67. html_tag( 'th', _("Wednesday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
  68. html_tag( 'th', _("Thursday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
  69. html_tag( 'th', _("Friday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
  70. html_tag( 'th', _("Saturday"), '', $color[5], 'width="14%" width="90"' ) ."\n"
  71. )
  72. ) ,
  73. '', $color[0] ) ."\n";
  74. }
  75. /**
  76. * main logic for month view of calendar
  77. * @return void
  78. * @access private
  79. */
  80. function drawmonthview() {
  81. global $year, $month, $color, $calendardata, $todayis;
  82. $aday = 1 - date('w', mktime(0, 0, 0, $month, 1, $year));
  83. $days_in_month = date('t', mktime(0, 0, 0, $month, 1, $year));
  84. while ($aday <= $days_in_month) {
  85. echo html_tag( 'tr' );
  86. for ($j=1; $j<=7; $j++) {
  87. $cdate="$month";
  88. ($aday<10)?$cdate=$cdate."0$aday":$cdate=$cdate."$aday";
  89. $cdate=$cdate."$year";
  90. if ( $aday <= $days_in_month && $aday > 0){
  91. echo html_tag( 'td', '', 'left', $color[4], 'height="50" valign="top"' ) ."\n".
  92. html_tag( 'div', '', 'right' );
  93. echo(($cdate==$todayis) ? '<font size="-1" color="'.$color[1].'">[ ' . _("TODAY") . " ] " : '<font size="-1">');
  94. echo "<a href=day.php?year=$year&amp;month=$month&amp;day=";
  95. echo(($aday<10) ? "0" : "");
  96. echo "$aday>$aday</a></font></div>";
  97. } else {
  98. echo html_tag( 'td', '', 'left', $color[0]) ."\n".
  99. "&nbsp;";
  100. }
  101. if (isset($calendardata[$cdate])){
  102. $i=0;
  103. while ($calfoo = each($calendardata[$cdate])) {
  104. $calbar = $calendardata[$cdate][$calfoo['key']];
  105. // FIXME: how to display multiline task
  106. $title = '['. $calfoo['key']. '] ' .
  107. str_replace(array("\r","\n"),array(' ',' '),htmlspecialchars($calbar['message']));
  108. // FIXME: link to nowhere
  109. echo "<a href=\"#\" style=\"text-decoration:none; color: "
  110. .($calbar['priority']==1 ? $color[1] : $color[6])
  111. ."\" title=\"$title\">".htmlspecialchars($calbar['title'])."</a><br />\n";
  112. $i=$i+1;
  113. if($i==2){
  114. break;
  115. }
  116. }
  117. }
  118. echo "\n</td>\n";
  119. $aday++;
  120. }
  121. echo '</tr>';
  122. }
  123. }
  124. /**
  125. * end of monthly view and form to jump to any month and year
  126. * @return void
  127. * @access private
  128. */
  129. function endcalendar() {
  130. global $year, $month, $day, $color;
  131. echo html_tag( 'tr' ) ."\n" .
  132. html_tag( 'td', '', 'left', '', 'colspan="7"' ) ."\n" .
  133. " <form name=\"caljump\" action=\"calendar.php\" method=\"post\">\n".
  134. " <select name=\"year\">\n";
  135. select_option_year($year);
  136. echo " </select>\n".
  137. " <select name=\"month\">\n";
  138. select_option_month($month);
  139. echo " </select>\n".
  140. ' <input type="submit" value="' . _("Go") . "\" />\n".
  141. " </form>\n".
  142. " </td></tr>\n".
  143. "</table></td></tr></table>\n";
  144. }
  145. if( !isset( $month ) || $month <= 0){
  146. $month = date( 'm' );
  147. }
  148. if( !isset($year) || $year <= 0){
  149. $year = date( 'Y' );
  150. }
  151. if( !isset($day) || $day <= 0){
  152. $day = date( 'd' );
  153. }
  154. $todayis = date( 'mdY' );
  155. $calself=basename($PHP_SELF);
  156. displayPageHeader($color, 'None');
  157. calendar_header();
  158. readcalendardata();
  159. startcalendar();
  160. drawmonthview();
  161. endcalendar();
  162. ?>
  163. </body></html>