calendar.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * calendar.php
  4. *
  5. * Copyright (c) 2002-2004 The SquirrelMail Project Team
  6. * Licensed under the GNU GPL. For full terms see the file COPYING.
  7. *
  8. * Originally contrubuted by Michal Szczotka <michal@tuxy.org>
  9. *
  10. * Displays the main calendar page (month view).
  11. *
  12. * $Id$
  13. * @package plugins
  14. * @subpackage calendar
  15. */
  16. /**
  17. */
  18. define('SM_PATH','../../');
  19. /* Calender plugin required files. */
  20. require_once(SM_PATH . 'plugins/calendar/calendar_data.php');
  21. require_once(SM_PATH . 'plugins/calendar/functions.php');
  22. /* SquirrelMail required files. */
  23. require_once(SM_PATH . 'include/validate.php');
  24. require_once(SM_PATH . 'functions/strings.php');
  25. require_once(SM_PATH . 'functions/date.php');
  26. require_once(SM_PATH . 'config/config.php');
  27. require_once(SM_PATH . 'functions/page_header.php');
  28. require_once(SM_PATH . 'include/load_prefs.php');
  29. require_once(SM_PATH . 'functions/html.php');
  30. /* get globals */
  31. if (isset($_GET['month'])) {
  32. $month = $_GET['month'];
  33. }
  34. if (isset($_GET['year'])) {
  35. $year = $_GET['year'];
  36. }
  37. if (isset($_POST['year'])) {
  38. $year = $_POST['year'];
  39. }
  40. if (isset($_POST['month'])) {
  41. $month = $_POST['month'];
  42. }
  43. /* got 'em */
  44. //display upper part of month calendar view
  45. function startcalendar() {
  46. global $year, $month, $day, $color;
  47. $prev_date = mktime(0, 0, 0, $month - 1, 1, $year);
  48. $act_date = mktime(0, 0, 0, $month, 1, $year);
  49. $next_date = mktime(0, 0, 0, $month + 1, 1, $year);
  50. $prev_month = date( 'm', $prev_date );
  51. $next_month = date( 'm', $next_date);
  52. $prev_year = date( 'Y', $prev_date);
  53. $next_year = date( 'Y', $next_date );
  54. $self = 'calendar.php';
  55. echo html_tag( 'tr', "\n".
  56. html_tag( 'td', "\n".
  57. html_tag( 'table', '', '', $color[0], 'width="100%" border="0" cellpadding="2" cellspacing="1"' ) .
  58. html_tag( 'tr', "\n".
  59. html_tag( 'th',
  60. "<a href=\"$self?year=".($year-1)."&amp;month=$month\">&lt;&lt;&nbsp;".($year-1)."</a>"
  61. ) . "\n".
  62. html_tag( 'th',
  63. "<a href=\"$self?year=$prev_year&amp;month=$prev_month\">&lt;&nbsp;" .
  64. date_intl( 'M', $prev_date). "</a>"
  65. ) . "\n".
  66. html_tag( 'th', date_intl( 'F Y', $act_date ), '', $color[0], 'colspan="3"') .
  67. html_tag( 'th',
  68. "<a href=\"$self?year=$next_year&amp;month=$next_month\">" .
  69. date_intl( 'M', $next_date) . "&nbsp;&gt;</a>"
  70. ) . "\n".
  71. html_tag( 'th',
  72. "<a href=\"$self?year=".($year+1)."&amp;month=$month\">".($year+1)."&nbsp;&gt;&gt;</a>"
  73. )
  74. ) . "\n".
  75. html_tag( 'tr',
  76. html_tag( 'th', _("Sunday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
  77. html_tag( 'th', _("Monday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
  78. html_tag( 'th', _("Tuesday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
  79. html_tag( 'th', _("Wednesday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
  80. html_tag( 'th', _("Thursday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
  81. html_tag( 'th', _("Friday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
  82. html_tag( 'th', _("Saturday"), '', $color[5], 'width="14%" width="90"' ) ."\n"
  83. )
  84. ) ,
  85. '', $color[0] ) ."\n";
  86. }
  87. //main logic for month view of calendar
  88. function drawmonthview() {
  89. global $year, $month, $day, $color, $calendardata, $todayis;
  90. $aday = 1 - date('w', mktime(0, 0, 0, $month, 1, $year));
  91. $days_in_month = date('t', mktime(0, 0, 0, $month, 1, $year));
  92. while ($aday <= $days_in_month) {
  93. echo html_tag( 'tr' );
  94. for ($j=1; $j<=7; $j++) {
  95. $cdate="$month";
  96. ($aday<10)?$cdate=$cdate."0$aday":$cdate=$cdate."$aday";
  97. $cdate=$cdate."$year";
  98. if ( $aday <= $days_in_month && $aday > 0){
  99. echo html_tag( 'td', '', 'left', $color[4], 'height="50" valign="top"' ) ."\n".
  100. html_tag( 'div', '', 'right' );
  101. echo(($cdate==$todayis) ? "<font size=-1 color=$color[1]>[ " . _("TODAY") . " ] " : "<font size=-1>");
  102. echo "<a href=day.php?year=$year&amp;month=$month&amp;day=";
  103. echo(($aday<10) ? "0" : "");
  104. echo "$aday>$aday</a></font></div>";
  105. } else {
  106. echo html_tag( 'td', '', 'left', $color[0]) ."\n".
  107. "&nbsp;";
  108. }
  109. if (isset($calendardata[$cdate])){
  110. $i=0;
  111. while ($calfoo = each($calendardata[$cdate])) {
  112. $calbar = $calendardata[$cdate][$calfoo['key']];
  113. $title = '['. $calfoo['key']. '] ' .$calbar['message'];
  114. echo ($calbar['priority']==1) ? "<a href=\"#\" style=\"text-decoration:none; color: $color[1]\" title=\"$title\">$calbar[title]</a><br>\n" : "<a href=\"#\" style=\"text-decoration:none; color: $color[6]\" title=\"$title\">$calbar[title]</a><br>\n";
  115. $i=$i+1;
  116. if($i==2){
  117. break;
  118. }
  119. }
  120. }
  121. echo "\n</td>\n";
  122. $aday++;
  123. }
  124. echo '</tr>';
  125. }
  126. }
  127. //end of monthly view and form to jump to any month and year
  128. function endcalendar() {
  129. global $year, $month, $day, $color;
  130. echo html_tag( 'tr' ) ."\n" .
  131. html_tag( 'td', '', 'left', '', 'colspan="7"' ) ."\n" .
  132. " <FORM NAME=caljump ACTION=\"calendar.php\" METHOD=POST>\n".
  133. " <SELECT NAME=\"year\">\n";
  134. select_option_year($year);
  135. echo " </SELECT>\n".
  136. " <SELECT NAME=\"month\">\n";
  137. select_option_month($month);
  138. echo " </SELECT>\n".
  139. ' <INPUT TYPE=SUBMIT VALUE="' . _("Go") . "\">\n".
  140. " </FORM>\n".
  141. " </TD></TR>\n".
  142. "</TABLE></TD></TR></TABLE>\n";
  143. }
  144. if( !isset( $month ) || $month <= 0){
  145. $month = date( 'm' );
  146. }
  147. if( !isset($year) || $year <= 0){
  148. $year = date( 'Y' );
  149. }
  150. if( !isset($day) || $day <= 0){
  151. $day = date( 'd' );
  152. }
  153. $todayis = date( 'mdY' );
  154. $calself=basename($PHP_SELF);
  155. displayPageHeader($color, 'None');
  156. calendar_header();
  157. readcalendardata();
  158. startcalendar();
  159. drawmonthview();
  160. endcalendar();
  161. ?>
  162. </body></html>