a0db34881c66c02088266e5a614d8665c9bd5102
[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 define('SM_PATH','../');
21
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
31 //display upper part of month calendar view
32 function startcalendar() {
33 global $year, $month, $day, $color;
34
35 $prev_date = mktime(0, 0, 0, $month - 1, 1, $year);
36 $act_date = mktime(0, 0, 0, $month, 1, $year);
37 $next_date = mktime(0, 0, 0, $month + 1, 1, $year);
38 $prev_month = date( 'm', $prev_date );
39 $next_month = date( 'm', $next_date);
40 $prev_year = date( 'Y', $prev_date);
41 $next_year = date( 'Y', $next_date );
42 $self = 'calendar.php';
43
44 echo html_tag( 'tr', "\n".
45 html_tag( 'td', "\n".
46 html_tag( 'table', '', '', $color[0], 'width="100%" border="0" cellpadding="2" cellspacing="1"' ) .
47 html_tag( 'tr', "\n".
48 html_tag( 'th',
49 "<a href=\"$self?year=".($year-1)."&month=$month\">&lt;&lt;&nbsp;".($year-1)."</a>"
50 ) . "\n".
51 html_tag( 'th',
52 "<a href=\"$self?year=$prev_year&month=$prev_month\">&lt;&nbsp;" .
53 date_intl( 'M', $prev_date). "</a>"
54 ) . "\n".
55 html_tag( 'th', date_intl( 'F Y', $act_date ), '', $color[0], 'colspan="3"') .
56 html_tag( 'th',
57 "<a href=\"$self?year=$next_year&month=$next_month\">" .
58 date_intl( 'M', $next_date) . "&nbsp;&gt;</a>"
59 ) . "\n".
60 html_tag( 'th',
61 "<a href=\"$self?year=".($year+1)."&month=$month\">".($year+1)."&nbsp;&gt;&gt;</a>"
62 )
63 ) . "\n".
64 html_tag( 'tr',
65 html_tag( 'th', _("Sunday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
66 html_tag( 'th', _("Monday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
67 html_tag( 'th', _("Tuesday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
68 html_tag( 'th', _("Wednesday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
69 html_tag( 'th', _("Thursday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
70 html_tag( 'th', _("Friday"), '', $color[5], 'width="14%" width="90"' ) ."\n" .
71 html_tag( 'th', _("Saturday"), '', $color[5], 'width="14%" width="90"' ) ."\n"
72 )
73 ) ,
74 '', $color[0] ) ."\n";
75 }
76
77 //main logic for month view of calendar
78 function drawmonthview() {
79 global $year, $month, $day, $color, $calendardata, $todayis;
80
81 $aday = 1 - date('w', mktime(0, 0, 0, $month, 1, $year));
82 $days_in_month = date('t', mktime(0, 0, 0, $month, 1, $year));
83 while ($aday <= $days_in_month) {
84 echo html_tag( 'tr' );
85 for ($j=1; $j<=7; $j++) {
86 $cdate="$month";
87 ($aday<10)?$cdate=$cdate."0$aday":$cdate=$cdate."$aday";
88 $cdate=$cdate."$year";
89 if ( $aday <= $days_in_month && $aday > 0){
90 echo html_tag( 'td', '', 'left', $color[4], 'height="50" valign="top"' ) ."\n".
91 html_tag( 'div', '', 'right' );
92 echo(($cdate==$todayis) ? "<font size=-1 color=$color[1]>[ " . _("TODAY") . " ] " : "<font size=-1>");
93 echo "<a href=day.php?year=$year&month=$month&day=";
94 echo(($aday<10) ? "0" : "");
95 echo "$aday>$aday</a></font></div>";
96 } else {
97 echo html_tag( 'td', '', 'left', $color[0]) ."\n".
98 "&nbsp;";
99 }
100 if (isset($calendardata[$cdate])){
101 $i=0;
102 while ($calfoo = each($calendardata[$cdate])) {
103 $calbar = $calendardata[$cdate][$calfoo['key']];
104 echo ($calbar['priority']==1) ? "<FONT COLOR=\"$color[1]\">$calbar[title]</FONT><br>\n" : "$calbar[title]<br>\n";
105 $i=$i+1;
106 if($i==2){
107 break;
108 }
109 }
110 }
111 echo "\n</td>\n";
112 $aday++;
113 }
114 echo '</tr>';
115 }
116 }
117
118 //end of monthly view and form to jump to any month and year
119 function endcalendar() {
120 global $year, $month, $day, $color;
121
122 echo html_tag( 'tr' ) ."\n" .
123 html_tag( 'td', '', 'left', '', 'colspan="7"' ) ."\n" .
124 " <FORM NAME=caljump ACTION=\"calendar.php\" METHOD=POST>\n".
125 " <SELECT NAME=\"year\">\n";
126 select_option_year($year);
127 echo " </SELECT>\n".
128 " <SELECT NAME=\"month\">\n";
129 select_option_month($month);
130 echo " </SELECT>\n".
131 ' <INPUT TYPE=SUBMIT VALUE="' . _("Go") . "\">\n".
132 " </FORM>\n".
133 " </TD></TR>\n".
134 "</TABLE></TD></TR></TABLE>\n";
135 }
136
137
138 if( !isset( $month ) || $month <= 0){
139 $month = date( 'm' );
140 }
141 if( !isset($year) || $year <= 0){
142 $year = date( 'Y' );
143 }
144 if( !isset($day) || $day <= 0){
145 $day = date( 'd' );
146 }
147
148 $todayis = date( 'mdY' );
149 $calself=basename($PHP_SELF);
150
151 displayPageHeader($color, 'None');
152 calendar_header();
153 readcalendardata();
154 startcalendar();
155 drawmonthview();
156 endcalendar();
157
158 ?>
159 </body></html>