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 $group_id = getIntFromRequest('group_id');
19 $group_project_id = getIntFromRequest('group_project_id');
20 $year = getIntFromRequest('year');
21 $month = getIntFromRequest('month');
22 $day = getIntFromRequest('day');
23 $type = getStringFromRequest('type');
25 // Some sanity checks first.
26 if ($year && ($year < 1990 || $year > 2020)) {
27 exit_error($Language->getText("calendar", "invalidyear"),
28 $Language->getText("calendar", "invalidyearexplain"));
31 if ($month && ($month < 1 || $month > 12)) {
32 exit_error($Language->getText("calendar", "invalidmonth"),
33 $Language->getText("calendar", "invalidmonthexplain"));
36 if ($day && ($day < 1 || $day > 31)) {
37 exit_error($Language->getText("calendar", "invalidday"),
38 $Language->getText("calendar", "invaliddayexplain"));
41 if ($year && isset($month) && isset($day)) {
42 if (!checkdate($month, $day, $year)) {
43 exit_error($Language->getText("calendar", "invaliddate"),
44 $Language->getText("calendar", "invaliddateexplain", "$year-$month-$day"));
48 if ($type && $type != 'onemonth' && $type != 'threemonth' && $type != 'currentyear' && $type != 'comingyear') {
49 exit_error($Language->getText("calendar", "invalidtype"),
50 $Language->getText("calendar", "invalidtypeexplain"));
59 $today = getdate(time());
62 $year = $today['year'];
66 $month = $today['mon'];
70 $day = $today['mday'];
74 $months = array(1 => 'january', 'february', 'march', 'april', 'may', 'june',
75 'july', 'august', 'september', 'october', 'november', 'december');
77 if ($group_id && $group_project_id) {
78 require_once('common/pm/ProjectTaskFactory.class');
79 require_once('common/pm/ProjectGroup.class');
81 $g =& group_get_object($group_id);
82 if (!$g || !is_object($g)) {
84 } elseif ($g->isError()) {
85 exit_error($Language->getText('global', 'error'), $g->getErrorMessage());
87 $pg = new ProjectGroup($g, $group_project_id);
88 if (!$pg || !is_object($pg)) {
89 exit_error($Language->getText('global', 'error'), 'BUG: Could Not Get Factory');
90 } elseif ($pg->isError()) {
91 exit_error($Language->getText('global', 'error'), $pg->getErrorMessage());
94 $ptf = new ProjectTaskFactory($pg);
95 if (!$ptf || !is_object($ptf)) {
96 exit_error($Language->getText('global', 'error'), 'BUG: Could Not Get ProjectTaskFactory');
97 } elseif ($ptf->isError()) {
98 exit_error($Language->getText('global', 'error'), $ptf->getErrorMessage());
100 // Violate all known laws about OOP here
102 $ptf->order='start_date';
107 $pt_arr =& $ptf->getTasks();
108 if ($ptf->isError()) {
109 exit_error($Language->getText('global', 'error'), $ptf->getErrorMessage());
113 $HTML->header(array('title'=>$Language->getText("calendar", "title"),'group'=>$group_id));
116 * Create link to a task.
117 * This returns a string that is a link to a particular task.
119 * @author Ryan T. Sammartino <ryants at shaw dot ca>
120 * @param $task the task to make a link for.
121 * @param $type either 'begin' for beginning of a task or 'end' for
126 function make_task_link($task, $type) {
127 global $HTML, $Language, $group_id, $group_project_id;
128 return '<span class="calendar-tasklink"><a title="'. $Language->getText('calendar', 'task_link_title', $task->getSummary())
129 . '" href="/pm/task.php?func=detailtask&project_task_id=' . $task->getID()
130 . '&group_id=' . $group_id
131 . '&group_project_id=' .$group_project_id
132 . '">' . ($type == 'begin' ?
133 $Language->getText('calendar', 'task_begins', $task->getID()) :
134 $Language->getText('calendar', 'task_ends', $task->getID()))
141 * This displays one month. m may be less than 0 and greater than 12: display_month
142 * uses mktime() to readjust it and the year in such cases.
144 * @author Ryan T. Sammartino <ryants at shaw dot ca>
150 function display_month($m, $y) {
151 global $months, $today, $month, $day, $year, $Language, $HTML,
152 $pt_arr, $group_id, $group_project_id;
153 $dow = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
155 $date = getdate(mktime(0, 0, 0, $m + 1, 0, $y));
156 $days_in_month = $date['mday'];
158 $date = getdate(mktime(0, 0, 0, $m, 1, $y));
159 $first_dow = $date['wday'];
164 <table align="center" cellpadding="1" cellspacing="1" border="1" width="100%">
166 <th colspan="7"><?php echo $Language->getText("calendar", $months[$m]) . " $y"; ?></th>
171 while (list ($key, $val) = each ($dow)) {
172 print "\t\t\t<th width=\"14%\">" . $Language->getText("calendar", $val) . "</th>\n";
180 while ($curr_dow != $first_dow) {
181 print "\t\t\t<td></td>\n";
184 while ($curr_date <= $days_in_month) {
185 while ($curr_dow < 7) {
186 if ($curr_date <= $days_in_month) {
188 if ($curr_date == $today['mday']
189 && $y == $today['year']
190 && $m == $today['mon']) {
192 } elseif ($curr_date == $day
197 print "\t\t\t<td valign=\"top\" class=" . $colour . ">$curr_date";
199 $rows = count($pt_arr);
200 for ($i = 0; $i < $rows; $i++) {
201 $start_date = getdate($pt_arr[$i]->getStartDate());
202 $end_date = getdate($pt_arr[$i]->getEndDate());
203 if ($curr_date == $start_date['mday']
204 && $y == $start_date['year']
205 && $m == $start_date['mon']) {
206 $cell_contents .= make_task_link($pt_arr[$i], 'begin');
207 } elseif ($curr_date == $end_date['mday']
208 && $y == $end_date['year']
209 && $m == $end_date['mon']) {
210 $cell_contents .= make_task_link($pt_arr[$i], 'end');
213 if ($cell_contents == '') {
214 $cell_contents = '<br /><br /><br />';
216 print "$cell_contents</td>\n";
218 print "\t\t\t<td></td>\n";
224 if ($curr_date <= $days_in_month) {
237 <form action="/pm/calendar.php" method="get">
240 <td><?php echo $Language->getText("calendar", "view"); ?><br />
244 <option value="onemonth"' . ($type == 'onemonth' ? ' selected="selected"' : '') . '>'. $Language->getText("calendar", "onemonth") . '</option>';
246 <option value="threemonth"' . ($type == 'threemonth' ? ' selected="selected"' : '') . '>'. $Language->getText("calendar", "threemonth") . '</option>';
248 <option value="currentyear"' . ($type == 'currentyear' ? ' selected="selected"' : '') . '>' . $Language->getText("calendar", "currentyear") . '</option>';
250 <option value="comingyear"' . ($type == 'comingyear' ? ' selected="selected"' : '') . '>' . $Language->getText("calendar", "comingyear") . '</option>';
254 <td><?php echo $Language->getText("calendar", "fordate"); ?><br />
258 for ($i = 1990; $i < 2020; $i++) {
259 print "\t\t\t\t<option value=\"$i\"" . ($year == $i ? ' selected="selected"' : '') . ">$i</option>\n";
263 <select name="month">
265 for ($i = 1; $i <= 12; $i++) {
266 print "\t\t\t\t<option value=\"$i\"" . ($month == $i ? ' selected="selected"' : '') . ">" . $Language->getText("calendar", $months[$i]) . "</option>\n";
272 for ($i = 1; $i <= 31; $i++) {
273 print "\t\t\t\t<option value=\"$i\"" . ($day == $i ? ' selected="selected"' : '') . ">$i</option>\n";
279 <input type="submit" value="<?php echo $Language->getText("calendar", "update") ?>" />
284 if (isset($group_id) && isset($group_project_id)) {
286 <input type="hidden" name="group_id" value="'. $group_id .'" />
287 <input type="hidden" name="group_project_id" value="'. $group_project_id .'" />';
294 <td width="20px" class="calendar-today"></td>
295 <td><?php echo $Language->getText("calendar", "todaysdate") ?></td>
298 <td width="20px" class="calendar-day"></td>
299 <td><?php echo $Language->getText("calendar", "selecteddate") ?></td>
304 if ($type == 'onemonth') {
305 display_month($month, $year);
306 } elseif ($type == 'threemonth') {
307 display_month($month - 1, $year);
308 print "\t<br />\n\n";
309 display_month($month, $year);
310 print "\t<br />\n\n";
311 display_month($month + 1, $year);
312 } elseif ($type == 'currentyear') {
313 for ($i = 1; $i <= 12; $i++) {
314 display_month($i, $year);
315 print "\t<br />\n\n";
317 } elseif ($type == 'comingyear') {
318 for ($i = 0; $i < 12; $i++) {
319 display_month($month + $i, $year);
320 print "\t<br />\n\n";
324 $HTML->footer(array());