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