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