Split out functionality that gathers system specs
[squirrelmail.git] / plugins / calendar / calendar.php
CommitLineData
d61a01d4 1<?php
7c67a5e8 2
3/**
4 * calendar.php
d61a01d4 5 *
82d304a0 6 * Copyright (c) 2002-2004 The SquirrelMail Project Team
7c67a5e8 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
d61a01d4 8 *
7c67a5e8 9 * Originally contrubuted by Michal Szczotka <michal@tuxy.org>
d61a01d4 10 *
7c67a5e8 11 * Displays the main calendar page (month view).
d61a01d4 12 *
2c85de8f 13 * $Id$
ea5f4b8e 14 * @package plugins
15 * @subpackage calendar
d61a01d4 16 */
ea5f4b8e 17
18/**
19*/
8d6a115b 20define('SM_PATH','../../');
d61a01d4 21
8d6a115b 22/* Calender plugin required files. */
23require_once(SM_PATH . 'plugins/calendar/calendar_data.php');
24require_once(SM_PATH . 'plugins/calendar/functions.php');
cf1efdce 25
26/* SquirrelMail required files. */
27require_once(SM_PATH . 'include/validate.php');
28require_once(SM_PATH . 'functions/strings.php');
29require_once(SM_PATH . 'functions/date.php');
30require_once(SM_PATH . 'config/config.php');
31require_once(SM_PATH . 'functions/page_header.php');
aa7fb30c 32require_once(SM_PATH . 'include/load_prefs.php');
cf1efdce 33require_once(SM_PATH . 'functions/html.php');
d61a01d4 34
95dcee50 35/* get globals */
36
37if (isset($_GET['month'])) {
38 $month = $_GET['month'];
39}
40if (isset($_GET['year'])) {
41 $year = $_GET['year'];
42}
43if (isset($_POST['year'])) {
44 $year = $_POST['year'];
45}
46if (isset($_POST['month'])) {
47 $month = $_POST['month'];
48}
49/* got 'em */
50
d61a01d4 51//display upper part of month calendar view
52function startcalendar() {
53 global $year, $month, $day, $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 );
88cb1b4d 62 $self = 'calendar.php';
d61a01d4 63
b01b21d0 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',
1ba8cd6b 69 "<a href=\"$self?year=".($year-1)."&amp;month=$month\">&lt;&lt;&nbsp;".($year-1)."</a>"
b01b21d0 70 ) . "\n".
71 html_tag( 'th',
1ba8cd6b 72 "<a href=\"$self?year=$prev_year&amp;month=$prev_month\">&lt;&nbsp;" .
b01b21d0 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',
1ba8cd6b 77 "<a href=\"$self?year=$next_year&amp;month=$next_month\">" .
b01b21d0 78 date_intl( 'M', $next_date) . "&nbsp;&gt;</a>"
79 ) . "\n".
80 html_tag( 'th',
1ba8cd6b 81 "<a href=\"$self?year=".($year+1)."&amp;month=$month\">".($year+1)."&nbsp;&gt;&gt;</a>"
b01b21d0 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";
d61a01d4 95}
96
97//main logic for month view of calendar
98function drawmonthview() {
99 global $year, $month, $day, $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) {
b01b21d0 104 echo html_tag( 'tr' );
d61a01d4 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){
b01b21d0 110 echo html_tag( 'td', '', 'left', $color[4], 'height="50" valign="top"' ) ."\n".
111 html_tag( 'div', '', 'right' );
d61a01d4 112 echo(($cdate==$todayis) ? "<font size=-1 color=$color[1]>[ " . _("TODAY") . " ] " : "<font size=-1>");
1ba8cd6b 113 echo "<a href=day.php?year=$year&amp;month=$month&amp;day=";
d61a01d4 114 echo(($aday<10) ? "0" : "");
115 echo "$aday>$aday</a></font></div>";
116 } else {
b01b21d0 117 echo html_tag( 'td', '', 'left', $color[0]) ."\n".
d61a01d4 118 "&nbsp;";
119 }
120 if (isset($calendardata[$cdate])){
121 $i=0;
122 while ($calfoo = each($calendardata[$cdate])) {
88cb1b4d 123 $calbar = $calendardata[$cdate][$calfoo['key']];
5d01bcce 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";
d61a01d4 126 $i=$i+1;
127 if($i==2){
128 break;
129 }
130 }
131 }
b01b21d0 132 echo "\n</td>\n";
d61a01d4 133 $aday++;
134 }
135 echo '</tr>';
136 }
137}
138
139//end of monthly view and form to jump to any month and year
140function endcalendar() {
141 global $year, $month, $day, $color;
142
b01b21d0 143 echo html_tag( 'tr' ) ."\n" .
144 html_tag( 'td', '', 'left', '', 'colspan="7"' ) ."\n" .
d61a01d4 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
88cb1b4d 159if( !isset( $month ) || $month <= 0){
d61a01d4 160 $month = date( 'm' );
161}
88cb1b4d 162if( !isset($year) || $year <= 0){
d61a01d4 163 $year = date( 'Y' );
164}
88cb1b4d 165if( !isset($day) || $day <= 0){
d61a01d4 166 $day = date( 'd' );
167}
168
169$todayis = date( 'mdY' );
170$calself=basename($PHP_SELF);
171
172displayPageHeader($color, 'None');
173calendar_header();
174readcalendardata();
175startcalendar();
176drawmonthview();
177endcalendar();
178
179?>
dcc1cc82 180</body></html>