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