5 * This file displays various sorts of calendars.
7 * Copyright 2002 (c) GForge Development Team
11 * @todo Remove hardcoded colours etc. and move into style sheet.
12 * @todo some locales start the week with "Monday", and not "Sunday".
15 require_once('pre.php');
17 // Some sanity checks first.
18 if (isset($year) && ($year < 1990 || $year > 2020)) {
19 exit_error($Language->getText("calendar", "invalidyear"),
20 $Language->getText("calendar", "invalidyearexplain"));
23 if (isset($month) && ($month < 1 || $month > 12)) {
24 exit_error($Language->getText("calendar", "invalidmonth"),
25 $Language->getText("calendar", "invalidmonthexplain"));
28 if (isset($day) && ($day < 1 || $day > 31)) {
29 exit_error($Language->getText("calendar", "invalidday"),
30 $Language->getText("calendar", "invaliddayexplain"));
33 if (isset($year) && isset($month) && isset($day)) {
34 if (!checkdate($month, $day, $year)) {
35 exit_error($Language->getText("calendar", "invaliddate"),
36 $Language->getText("calendar", "invaliddateexplain", "$year-$month-$day"));
40 if (isset($type) && $type != 'onemonth' && $type != 'threemonth' && $type != 'currentyear' && $type != 'comingyear') {
41 exit_error($Language->getText("calendar", "invalidtype"),
42 $Language->getText("calendar", "invalidtypeexplain"));
45 $HTML->header(array(title=>$Language->getText("calendar", "title")));
54 $today = getdate(time());
57 $year = $today['year'];
61 $month = $today['mon'];
65 $day = $today['mday'];
69 $months = array(1 => 'january', 'february', 'march', 'april', 'may', 'june',
70 'july', 'august', 'september', 'october', 'november', 'december');
74 * This displays one month. m may be less than 0 and greater than 12: display_month
75 * uses mktime() to readjust it and the year in such cases.
77 * @author Ryan T. Sammartino <ryants at shaw dot ca>
83 function display_month($m, $y) {
84 global $months, $today, $month, $day, $year, $Language;
85 $dow = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
87 $date = getdate(mktime(0, 0, 0, $m + 1, 0, $y));
88 $days_in_month = $date['mday'];
90 $date = getdate(mktime(0, 0, 0, $m, 1, $y));
91 $first_dow = $date['wday'];
96 <TABLE ALIGN="CENTER" CELLPADDING=1 CELLSPACING=1 BORDER=1 WIDTH=100%>
98 <TH COLSPAN=7><?php echo $Language->getText("calendar", $months[$m]) . " $y"; ?></TH>
103 while (list ($key, $val) = each ($dow)) {
104 print "\t\t\t<TH WIDTH=14%>" . $Language->getText("calendar", $val) . "</TH>\n";
112 while ($curr_dow != $first_dow) {
113 print "\t\t\t<TD></TD>\n";
116 while ($curr_date <= $days_in_month) {
117 while ($curr_dow < 7) {
118 if ($curr_date <= $days_in_month) {
120 if ($curr_date == $today['mday']
121 && $y == $today['year']
122 && $m == $today['mon']) {
123 $colour = " BGCOLOR=\"RED\"";
124 } elseif ($curr_date == $day
127 $colour = " BGCOLOR=\"GRAY\"";
129 print "\t\t\t<TD" . $colour . ">$curr_date<BR><BR><BR></TD>\n";
131 print "\t\t\t<TD></TD>\n";
147 <FORM ACTION="/pm/calendar.php" METHOD="GET">
150 <TD><?php echo $Language->getText("calendar", "view"); ?><BR>
154 <OPTION VALUE="onemonth"' . ($type == 'onemonth' ? ' SELECTED' : '') . '>'. $Language->getText("calendar", "onemonth") . '</OPTION>';
156 <OPTION VALUE="threemonth"' . ($type == 'threemonth' ? ' SELECTED' : '') . '>'. $Language->getText("calendar", "threemonth") . '</OPTION>';
158 <OPTION VALUE="currentyear"' . ($type == 'currentyear' ? ' SELECTED' : '') . '>' . $Language->getText("calendar", "currentyear") . '</OPTION>';
160 <OPTION VALUE="comingyear"' . ($type == 'comingyear' ? ' SELECTED' : '') . '>' . $Language->getText("calendar", "comingyear") . '</OPTION>';
164 <TD><?php echo $Language->getText("calendar", "fordate"); ?><BR>
168 for ($i = 1990; $i < 2020; $i++) {
169 print "\t\t\t\t<OPTION VALUE=\"$i\"" . ($year == $i ? ' SELECTED' : '') . ">$i</OPTION>\n";
173 <SELECT NAME="month">
175 for ($i = 1; $i <= 12; $i++) {
176 print "\t\t\t\t<OPTION VALUE=\"$i\"" . ($month == $i ? ' SELECTED' : '') . ">" . $Language->getText("calendar", $months[$i]) . "</OPTION>\n";
182 for ($i = 1; $i <= 31; $i++) {
183 print "\t\t\t\t<OPTION VALUE=\"$i\"" . ($day == $i ? ' SELECTED' : '') . ">$i</OPTION>\n";
189 <INPUT TYPE="submit" VALUE="<?php echo $Language->getText("calendar", "update") ?>">
195 <TD WIDTH=20px BGCOLOR="RED"></TD>
196 <TD><?php echo $Language->getText("calendar", "todaysdate") ?></TD>
199 <TD WIDTH=20px BGCOLOR="GRAY"</TD>
200 <TD><?php echo $Language->getText("calendar", "selecteddate") ?></TD>
205 if ($type == 'onemonth') {
206 display_month($month, $year);
207 } elseif ($type == 'threemonth') {
208 display_month($month - 1, $year);
210 display_month($month, $year);
212 display_month($month + 1, $year);
213 } elseif ($type == 'currentyear') {
214 for ($i = 1; $i <= 12; $i++) {
215 display_month($i, $year);
218 } elseif ($type == 'comingyear') {
219 for ($i = 0; $i < 12; $i++) {
220 display_month($month + $i, $year);
225 $HTML->footer(array());