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