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