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