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".
13 * @todo display holidays.
16 require_once('pre.php');
18 // Some sanity checks first.
19 if (isset($year) && ($year < 1990 || $year > 2020)) {
20 exit_error($Language->getText("calendar", "invalidyear"),
21 $Language->getText("calendar", "invalidyearexplain"));
24 if (isset($month) && ($month < 1 || $month > 12)) {
25 exit_error($Language->getText("calendar", "invalidmonth"),
26 $Language->getText("calendar", "invalidmonthexplain"));
29 if (isset($day) && ($day < 1 || $day > 31)) {
30 exit_error($Language->getText("calendar", "invalidday"),
31 $Language->getText("calendar", "invaliddayexplain"));
34 if (isset($year) && isset($month) && isset($day)) {
35 if (!checkdate($month, $day, $year)) {
36 exit_error($Language->getText("calendar", "invaliddate"),
37 $Language->getText("calendar", "invaliddateexplain", "$year-$month-$day"));
41 if (isset($type) && $type != 'onemonth' && $type != 'threemonth' && $type != 'currentyear' && $type != 'comingyear') {
42 exit_error($Language->getText("calendar", "invalidtype"),
43 $Language->getText("calendar", "invalidtypeexplain"));
52 $today = getdate(time());
55 $year = $today['year'];
59 $month = $today['mon'];
63 $day = $today['mday'];
67 $months = array(1 => 'january', 'february', 'march', 'april', 'may', 'june',
68 'july', 'august', 'september', 'october', 'november', 'december');
70 if (isset($group_id) && isset($group_project_id)) {
71 require_once('common/pm/ProjectTaskFactory.class');
72 require_once('common/pm/ProjectGroup.class');
74 $g =& group_get_object($group_id);
75 if (!$g || !is_object($g)) {
77 } elseif ($g->isError()) {
78 exit_error($Language->getText('global', 'error'), $g->getErrorMessage());
80 $pg = new ProjectGroup($g, $group_project_id);
81 if (!$pg || !is_object($pg)) {
82 exit_error($Language->getText('global', 'error'), 'BUG: Could Not Get Factory');
83 } elseif ($pg->isError()) {
84 exit_error($Language->getText('global', 'error'), $pg->getErrorMessage());
87 $ptf = new ProjectTaskFactory($pg);
88 if (!$ptf || !is_object($ptf)) {
89 exit_error($Language->getText('global', 'error'), 'BUG: Could Not Get ProjectTaskFactory');
90 } elseif ($ptf->isError()) {
91 exit_error($Language->getText('global', 'error'), $ptf->getErrorMessage());
93 // Violate all known laws about OOP here
95 $ptf->order='start_date';
100 $pt_arr =& $ptf->getTasks();
101 if ($ptf->isError()) {
102 exit_error($Language->getText('global', 'error'), $ptf->getErrorMessage());
106 $HTML->header(array('title'=>$Language->getText("calendar", "title"),'group'=>$group_id));
109 * Create link to a task.
110 * This returns a string that is a link to a particular task.
112 * @author Ryan T. Sammartino <ryants at shaw dot ca>
113 * @param $task the task to make a link for.
114 * @param $type either 'begin' for beginning of a task or 'end' for
119 function make_task_link($task, $type) {
120 global $HTML, $Language, $group_id, $group_project_id;
121 return '<p style="font-size: ' . $HTML->FONTSIZE_SMALLEST
122 . '"><a title="'. $Language->getText('calendar', 'task_link_title', $task->getSummary())
123 . '" href="/pm/task.php?func=detailtask&project_task_id=' . $task->getID()
124 . '&group_id=' . $group_id
125 . '&group_project_id=' .$group_project_id
126 . '">' . ($type == 'begin' ?
127 $Language->getText('calendar', 'task_begins', $task->getID()) :
128 $Language->getText('calendar', 'task_ends', $task->getID()))
135 * This displays one month. m may be less than 0 and greater than 12: display_month
136 * uses mktime() to readjust it and the year in such cases.
138 * @author Ryan T. Sammartino <ryants at shaw dot ca>
144 function display_month($m, $y) {
145 global $months, $today, $month, $day, $year, $Language, $HTML,
146 $pt_arr, $group_id, $group_project_id;
147 $dow = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
149 $date = getdate(mktime(0, 0, 0, $m + 1, 0, $y));
150 $days_in_month = $date['mday'];
152 $date = getdate(mktime(0, 0, 0, $m, 1, $y));
153 $first_dow = $date['wday'];
158 <table align="center" cellpadding="1" cellspacing="1" border="1" width="100%">
160 <th colspan="7"><?php echo $Language->getText("calendar", $months[$m]) . " $y"; ?></th>
165 while (list ($key, $val) = each ($dow)) {
166 print "\t\t\t<th width=\"14%\">" . $Language->getText("calendar", $val) . "</th>\n";
174 while ($curr_dow != $first_dow) {
175 print "\t\t\t<td></td>\n";
178 while ($curr_date <= $days_in_month) {
179 while ($curr_dow < 7) {
180 if ($curr_date <= $days_in_month) {
182 if ($curr_date == $today['mday']
183 && $y == $today['year']
184 && $m == $today['mon']) {
185 $colour = " bgcolor=\"red\"";
186 } elseif ($curr_date == $day
189 $colour = " bgcolor=\"gray\"";
191 print "\t\t\t<td valign=\"top\"" . $colour . ">$curr_date";
193 $rows = count($pt_arr);
194 for ($i = 0; $i < $rows; $i++) {
195 $start_date = getdate($pt_arr[$i]->getStartDate());
196 $end_date = getdate($pt_arr[$i]->getEndDate());
197 if ($curr_date == $start_date['mday']
198 && $y == $start_date['year']
199 && $m == $start_date['mon']) {
200 $cell_contents .= make_task_link($pt_arr[$i], 'begin');
201 } elseif ($curr_date == $end_date['mday']
202 && $y == $end_date['year']
203 && $m == $end_date['mon']) {
204 $cell_contents .= make_task_link($pt_arr[$i], 'end');
207 if ($cell_contents == '') {
208 $cell_contents = '<br /><br /><br />';
210 print "$cell_contents</td>\n";
212 print "\t\t\t<td></td>\n";
218 if ($curr_date <= $days_in_month) {
231 <form action="/pm/calendar.php" method="get">
234 <td><?php echo $Language->getText("calendar", "view"); ?><br />
238 <option value="onemonth"' . ($type == 'onemonth' ? ' selected="selected"' : '') . '>'. $Language->getText("calendar", "onemonth") . '</option>';
240 <option value="threemonth"' . ($type == 'threemonth' ? ' selected="selected"' : '') . '>'. $Language->getText("calendar", "threemonth") . '</option>';
242 <option value="currentyear"' . ($type == 'currentyear' ? ' selected="selected"' : '') . '>' . $Language->getText("calendar", "currentyear") . '</option>';
244 <option value="comingyear"' . ($type == 'comingyear' ? ' selected="selected"' : '') . '>' . $Language->getText("calendar", "comingyear") . '</option>';
248 <td><?php echo $Language->getText("calendar", "fordate"); ?><br />
252 for ($i = 1990; $i < 2020; $i++) {
253 print "\t\t\t\t<option value=\"$i\"" . ($year == $i ? ' selected="selected"' : '') . ">$i</option>\n";
257 <select name="month">
259 for ($i = 1; $i <= 12; $i++) {
260 print "\t\t\t\t<option value=\"$i\"" . ($month == $i ? ' selected="selected"' : '') . ">" . $Language->getText("calendar", $months[$i]) . "</option>\n";
266 for ($i = 1; $i <= 31; $i++) {
267 print "\t\t\t\t<option value=\"$i\"" . ($day == $i ? ' selected="selected"' : '') . ">$i</option>\n";
273 <input type="submit" value="<?php echo $Language->getText("calendar", "update") ?>" />
278 if (isset($group_id) && isset($group_project_id)) {
280 <input type="hidden" name="group_id" value="'. $group_id .'" />
281 <input type="hidden" name="group_project_id" value="'. $group_project_id .'" />';
288 <td width="20px" bgcolor="red"></td>
289 <td><?php echo $Language->getText("calendar", "todaysdate") ?></td>
292 <td width="20px" bgcolor="gray"></td>
293 <td><?php echo $Language->getText("calendar", "selecteddate") ?></td>
298 if ($type == 'onemonth') {
299 display_month($month, $year);
300 } elseif ($type == 'threemonth') {
301 display_month($month - 1, $year);
302 print "\t<br />\n\n";
303 display_month($month, $year);
304 print "\t<br />\n\n";
305 display_month($month + 1, $year);
306 } elseif ($type == 'currentyear') {
307 for ($i = 1; $i <= 12; $i++) {
308 display_month($i, $year);
309 print "\t<br />\n\n";
311 } elseif ($type == 'comingyear') {
312 for ($i = 0; $i < 12; $i++) {
313 display_month($month + $i, $year);
314 print "\t<br />\n\n";
318 $HTML->footer(array());