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