3 * Project Management Facility : Display Calendar
5 * Copyright 2002 GForge, LLC
6 * http://fusionforge.org
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * This file displays various sorts of calendars.
29 * @todo some locales start the week with "Monday", and not "Sunday".
30 * @todo display holidays.
33 require_once('../env.inc.php');
34 require_once $gfcommon.'include/pre.php';
35 require_once $gfwww.'pm/include/ProjectGroupHTML.class.php';
37 $group_id = getIntFromRequest('group_id');
38 $group_project_id = getIntFromRequest('group_project_id');
39 $year = getIntFromRequest('year');
40 $month = getIntFromRequest('month');
41 $day = getIntFromRequest('day');
42 $type = getStringFromRequest('type');
44 // Some sanity checks first.
45 if ($year && ($year < 1990 || $year > 2020)) {
46 exit_error(_('Invalid year: Not between 1990 and 2020'),'pm');
49 if ($month && ($month < 1 || $month > 12)) {
50 exit_error(_('Invalid month: Not between 1 and 12'),'pm');
53 if ($day && ($day < 1 || $day > 31)) {
54 exit_error(_('Invalid day: Not between 1 and 31'),'pm');
57 if ($year && isset($month) && isset($day)) {
58 if (!checkdate($month, $day, $year)) {
59 exit_error(_('Invalid date').sprintf(_('Date not valid'), "$year-$month-$day"),'pm');
63 if ($type && $type != 'onemonth' && $type != 'threemonth' && $type != 'currentyear' && $type != 'comingyear') {
64 exit_error(_('Invalid type: Type not in onemonth, threemonth, currentyear, comingyear'),'pm');
73 $today = getdate(time());
76 $year = $today['year'];
80 $month = $today['mon'];
84 $day = $today['mday'];
88 $months = array(1 => _('January'), _('February'), _('March'), _('April'), _('May'), _('June'),
89 _('July'), _('August'), _('September'), _('October'), _('November'), _('December'));
91 if ($group_id && $group_project_id) {
92 require_once $gfcommon.'pm/ProjectTaskFactory.class.php';
93 require_once $gfcommon.'pm/ProjectGroup.class.php';
95 $g = group_get_object($group_id);
96 if (!$g || !is_object($g)) {
98 } elseif ($g->isError()) {
99 exit_error($g->getErrorMessage(),'pm');
101 $pg = new ProjectGroup($g, $group_project_id);
102 if (!$pg || !is_object($pg)) {
103 exit_error(_('Error: Could Not Get Factory'),'pm');
104 } elseif ($pg->isError()) {
105 exit_error($pg->getErrorMessage(),'pm');
108 $ptf = new ProjectTaskFactory($pg);
109 if (!$ptf || !is_object($ptf)) {
110 exit_error(_('Error: Could Not Get ProjectTaskFactory'),'pm');
111 } elseif ($ptf->isError()) {
112 exit_error($ptf->getErrorMessage(),'pm');
114 // Violate all known laws about OOP here
116 $ptf->order='start_date';
121 $pt_arr =& $ptf->getTasks();
122 if ($ptf->isError()) {
123 exit_error($ptf->getErrorMessage(),'pm');
127 pm_header(array('title'=>_('Calendar'),'group'=>$group_id));
130 * Create link to a task.
131 * This returns a string that is a link to a particular task.
133 * @author Ryan T. Sammartino <ryants at shaw dot ca>
134 * @param $task the task to make a link for.
135 * @param $type either 'begin' for beginning of a task or 'end' for
140 function make_task_link($task, $type) {
141 global $HTML, $group_id, $group_project_id;
142 return '<a title="'. sprintf(_('Task summary: %s'), $task->getSummary())
143 . '" href="'.util_make_url ('/pm/task.php?func=detailtask&project_task_id=' . $task->getID() . '&group_id=' . $group_id . '&group_project_id=' .$group_project_id)
144 . '">' . ($type == 'begin' ?
145 sprintf(_('Task %d begins'), $task->getID()) :
146 sprintf(_('Task %d ends'), $task->getID()) )
153 * This displays one month. m may be less than 0 and greater than 12: display_month
154 * uses mktime() to readjust it and the year in such cases.
156 * @author Ryan T. Sammartino <ryants at shaw dot ca>
162 function display_month($m, $y) {
163 global $months, $today, $month, $day, $year, $HTML,
164 $pt_arr, $group_id, $group_project_id;
165 $dow = array(_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday'));
167 $tstamp = mktime(0, 0, 0, $m + 1, 0, $y) ;
169 $date = getdate($tstamp);
170 $days_in_month = $date['mday'];
172 $date = getdate($tstamp);
173 $first_dow = $date['wday'];
178 <table align="center" cellpadding="1" cellspacing="1" border="1" width="100%">
180 <th colspan="7"><?php echo date (_('F Y'), $tstamp); ?></th>
185 while (list ($key, $val) = each ($dow)) {
186 print "\t\t\t<th width=\"14%\">$val</th>\n";
194 while ($curr_dow != $first_dow) {
195 print "\t\t\t<td></td>\n";
198 while ($curr_date <= $days_in_month) {
199 while ($curr_dow < 7) {
200 if ($curr_date <= $days_in_month) {
202 if ($curr_date == $today['mday']
203 && $y == $today['year']
204 && $m == $today['mon']) {
206 } elseif ($curr_date == $day
211 print "\t\t\t<td valign=\"top\" class=\"" . $colour . "\">$curr_date";
213 $rows = count($pt_arr);
214 for ($i = 0; $i < $rows; $i++) {
215 $start_date = getdate($pt_arr[$i]->getStartDate());
216 $end_date = getdate($pt_arr[$i]->getEndDate());
217 if ($curr_date == $start_date['mday']
218 && $y == $start_date['year']
219 && $m == $start_date['mon']) {
220 $cell_contents .= make_task_link($pt_arr[$i], 'begin');
221 } elseif ($curr_date == $end_date['mday']
222 && $y == $end_date['year']
223 && $m == $end_date['mon']) {
224 $cell_contents .= make_task_link($pt_arr[$i], 'end');
227 if ($cell_contents == '') {
228 $cell_contents = '<br /><br /><br />';
230 print "$cell_contents</td>\n";
232 print "\t\t\t<td></td>\n";
238 if ($curr_date <= $days_in_month) {
251 <form action="/pm/calendar.php" method="get">
254 <td><?php echo _('Period'); ?><br />
258 <option value="onemonth"' . ($type == 'onemonth' ? ' selected="selected"' : '') . '>'. _('One month') . '</option>';
260 <option value="threemonth"' . ($type == 'threemonth' ? ' selected="selected"' : '') . '>'. _('Three month') . '</option>';
262 <option value="currentyear"' . ($type == 'currentyear' ? ' selected="selected"' : '') . '>' . _('Current year') . '</option>';
264 <option value="comingyear"' . ($type == 'comingyear' ? ' selected="selected"' : '') . '>' . _('Coming year') . '</option>';
268 <td><?php echo _('Date'); ?><br />
272 for ($i = 1990; $i < 2020; $i++) {
273 print "\t\t\t\t<option value=\"$i\"" . ($year == $i ? ' selected="selected"' : '') . ">$i</option>\n";
277 <select name="month">
279 for ($i = 1; $i <= 12; $i++) {
280 print "\t\t\t\t<option value=\"$i\"" . ($month == $i ? ' selected="selected"' : '') . ">" . $months[$i] . "</option>\n";
286 for ($i = 1; $i <= 31; $i++) {
287 print "\t\t\t\t<option value=\"$i\"" . ($day == $i ? ' selected="selected"' : '') . ">$i</option>\n";
293 <input type="submit" value="<?php echo _('Update') ?>" />
298 if (isset($group_id) && isset($group_project_id)) {
300 <input type="hidden" name="group_id" value="'. $group_id .'" />
301 <input type="hidden" name="group_project_id" value="'. $group_project_id .'" />';
308 <td width="20px" class="selected"></td>
309 <td><?php echo _('today\'s date') ?></td>
312 <td width="20px"></td>
313 <td><?php echo _('selected date') ?></td>
318 if ($type == 'onemonth') {
319 display_month($month, $year);
320 } elseif ($type == 'threemonth') {
321 display_month($month - 1, $year);
322 print "\t<br />\n\n";
323 display_month($month, $year);
324 print "\t<br />\n\n";
325 display_month($month + 1, $year);
326 } elseif ($type == 'currentyear') {
327 for ($i = 1; $i <= 12; $i++) {
328 display_month($i, $year);
329 print "\t<br />\n\n";
331 } elseif ($type == 'comingyear') {
332 for ($i = 0; $i < 12; $i++) {
333 display_month($month + $i, $year);
334 print "\t<br />\n\n";
342 // c-file-style: "bsd"