calendar.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /*
  3. *
  4. * calendar.php
  5. *
  6. * Copyright (c) 2001 Michal Szczotka <michal@tuxy.org>
  7. * Licensed under the GNU GPL. For full terms see the file COPYING.
  8. *
  9. * Displays the main calendar page (month view).
  10. *
  11. * $Id$
  12. */
  13. require_once('calendar_data.php');
  14. require_once('functions.php');
  15. chdir('..');
  16. require_once('../src/validate.php');
  17. require_once('../functions/strings.php');
  18. require_once('../functions/date.php');
  19. require_once('../config/config.php');
  20. require_once('../functions/page_header.php');
  21. require_once('../src/load_prefs.php');
  22. //display upper part of month calendar view
  23. function startcalendar() {
  24. global $year, $month, $day, $color;
  25. $prev_date = mktime(0, 0, 0, $month - 1, 1, $year);
  26. $act_date = mktime(0, 0, 0, $month, 1, $year);
  27. $next_date = mktime(0, 0, 0, $month + 1, 1, $year);
  28. $prev_month = date( 'm', $prev_date );
  29. $next_month = date( 'm', $next_date);
  30. $prev_year = date( 'Y', $prev_date);
  31. $next_year = date( 'Y', $next_date );
  32. $self = 'calendar.php';
  33. echo "<TR BGCOLOR=\"$color[0]\"><TD>" .
  34. "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[0]\">" .
  35. '<tr>'.
  36. "<th><a href=\"$self?year=".($year-1)."&month=$month\">&lt;&lt;&nbsp;".($year-1)."</a></th>\n".
  37. "<th><a href=\"$self?year=$prev_year&month=$prev_month\">&lt;&nbsp;" .
  38. date_intl( 'M', $prev_date). "</a></th>\n".
  39. "<th bgcolor=$color[0] colspan=3>" .
  40. date_intl( 'F Y', $act_date ) . "</th>\n" .
  41. "<th><a href=\"$self?year=$next_year&month=$next_month\">" .
  42. date_intl( 'M', $next_date) . "&nbsp;&gt;</a></th>".
  43. "<th><a href=\"$self?year=".($year+1)."&month=$month\">".($year+1)."&nbsp;&gt;&gt;</a></th>".
  44. '</tr><tr>'.
  45. "<th WIDTH=\"14%\" bgcolor=$color[5] width=90>" . _("Sunday") . '</th>'.
  46. "<th WIDTH=\"14%\" bgcolor=$color[5] width=90>" . _("Monday") . '</th>'.
  47. "<th WIDTH=\"14%\" bgcolor=$color[5] width=90>" . _("Tuesday") . '</th>'.
  48. "<th WIDTH=\"14%\" bgcolor=$color[5] width=90>" . _("Wednesday") . '</th>'.
  49. "<th WIDTH=\"14%\" bgcolor=$color[5] width=90>" . _("Thursday") . '</th>'.
  50. "<th WIDTH=\"14%\" bgcolor=$color[5] width=90>" . _("Friday") . '</th>'.
  51. "<th WIDTH=\"14%\" bgcolor=$color[5] width=90>" . _("Saturday") . '</th>'.
  52. '</tr>';
  53. }
  54. //main logic for month view of calendar
  55. function drawmonthview() {
  56. global $year, $month, $day, $color, $calendardata, $todayis;
  57. $aday = 1 - date('w', mktime(0, 0, 0, $month, 1, $year));
  58. $days_in_month = date('t', mktime(0, 0, 0, $month, 1, $year));
  59. while ($aday <= $days_in_month) {
  60. echo '<tr>';
  61. for ($j=1; $j<=7; $j++) {
  62. $cdate="$month";
  63. ($aday<10)?$cdate=$cdate."0$aday":$cdate=$cdate."$aday";
  64. $cdate=$cdate."$year";
  65. if ( $aday <= $days_in_month && $aday > 0){
  66. echo "<TD BGCOLOR=\"$color[4]\" height=50 valign=top>\n" .
  67. "<div align=right>";
  68. echo(($cdate==$todayis) ? "<font size=-1 color=$color[1]>[ " . _("TODAY") . " ] " : "<font size=-1>");
  69. echo "<a href=day.php?year=$year&month=$month&day=";
  70. echo(($aday<10) ? "0" : "");
  71. echo "$aday>$aday</a></font></div>";
  72. } else {
  73. echo "<TD BGCOLOR=\"$color[0]\">\n".
  74. "&nbsp;";
  75. }
  76. if (isset($calendardata[$cdate])){
  77. $i=0;
  78. while ($calfoo = each($calendardata[$cdate])) {
  79. $calbar = $calendardata[$cdate][$calfoo['key']];
  80. echo ($calbar['priority']==1) ? "<FONT COLOR=\"$color[1]\">$calbar[title]</FONT><br>\n" : "$calbar[title]<br>\n";
  81. $i=$i+1;
  82. if($i==2){
  83. break;
  84. }
  85. }
  86. }
  87. echo "\n</TD>\n";
  88. $aday++;
  89. }
  90. echo '</tr>';
  91. }
  92. }
  93. //end of monthly view and form to jump to any month and year
  94. function endcalendar() {
  95. global $year, $month, $day, $color;
  96. echo " <TR><TD COLSPAN=7>\n".
  97. " <FORM NAME=caljump ACTION=\"calendar.php\" METHOD=POST>\n".
  98. " <SELECT NAME=\"year\">\n";
  99. select_option_year($year);
  100. echo " </SELECT>\n".
  101. " <SELECT NAME=\"month\">\n";
  102. select_option_month($month);
  103. echo " </SELECT>\n".
  104. ' <INPUT TYPE=SUBMIT VALUE="' . _("Go") . "\">\n".
  105. " </FORM>\n".
  106. " </TD></TR>\n".
  107. "</TABLE></TD></TR></TABLE>\n";
  108. }
  109. if( !isset( $month ) || $month <= 0){
  110. $month = date( 'm' );
  111. }
  112. if( !isset($year) || $year <= 0){
  113. $year = date( 'Y' );
  114. }
  115. if( !isset($day) || $day <= 0){
  116. $day = date( 'd' );
  117. }
  118. $todayis = date( 'mdY' );
  119. $calself=basename($PHP_SELF);
  120. displayPageHeader($color, 'None');
  121. calendar_header();
  122. readcalendardata();
  123. startcalendar();
  124. drawmonthview();
  125. endcalendar();
  126. ?>
  127. </body></html>