881cd9d692437f053da250daea8f387be27dbf45
[squirrelmail.git] / plugins / calendar / calendar.php
1 <?php
2
3 /**
4 * calendar.php
5 *
6 * Copyright (c) 2002-2003 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 $title = '['. $calfoo['key']. '] ' .$calbar['message'];
120 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";
121 $i=$i+1;
122 if($i==2){
123 break;
124 }
125 }
126 }
127 echo "\n</td>\n";
128 $aday++;
129 }
130 echo '</tr>';
131 }
132 }
133
134 //end of monthly view and form to jump to any month and year
135 function endcalendar() {
136 global $year, $month, $day, $color;
137
138 echo html_tag( 'tr' ) ."\n" .
139 html_tag( 'td', '', 'left', '', 'colspan="7"' ) ."\n" .
140 " <FORM NAME=caljump ACTION=\"calendar.php\" METHOD=POST>\n".
141 " <SELECT NAME=\"year\">\n";
142 select_option_year($year);
143 echo " </SELECT>\n".
144 " <SELECT NAME=\"month\">\n";
145 select_option_month($month);
146 echo " </SELECT>\n".
147 ' <INPUT TYPE=SUBMIT VALUE="' . _("Go") . "\">\n".
148 " </FORM>\n".
149 " </TD></TR>\n".
150 "</TABLE></TD></TR></TABLE>\n";
151 }
152
153
154 if( !isset( $month ) || $month <= 0){
155 $month = date( 'm' );
156 }
157 if( !isset($year) || $year <= 0){
158 $year = date( 'Y' );
159 }
160 if( !isset($day) || $day <= 0){
161 $day = date( 'd' );
162 }
163
164 $todayis = date( 'mdY' );
165 $calself=basename($PHP_SELF);
166
167 displayPageHeader($color, 'None');
168 calendar_header();
169 readcalendardata();
170 startcalendar();
171 drawmonthview();
172 endcalendar();
173
174 ?>
175 </body></html>