3 * Project Management Facility : Display Calendar
5 * Copyright 2002 GForge, LLC
6 * Copyright 2016, Franck Villaume - TrivialDev
7 * http://fusionforge.org
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 * This file displays various sorts of calendars.
30 * @todo some locales start the week with "Monday", and not "Sunday".
31 * @todo display holidays.
34 require_once '../env.inc.php';
35 require_once $gfcommon.'include/pre.php';
36 require_once $gfwww.'pm/include/ProjectGroupHTML.class.php';
38 $group_id = getIntFromRequest('group_id');
39 $group_project_id = getIntFromRequest('group_project_id');
40 $year = getIntFromRequest('year');
41 $month = getIntFromRequest('month');
42 $day = getIntFromRequest('day');
43 $type = getStringFromRequest('type');
45 // Some sanity checks first.
46 if ($year && ($year < 1990 || $year > 2020)) {
47 exit_error(_('Invalid year: Not between 1990 and 2020'),'pm');
50 if ($month && ($month < 1 || $month > 12)) {
51 exit_error(_('Invalid month: Not between 1 and 12'),'pm');
54 if ($day && ($day < 1 || $day > 31)) {
55 exit_error(_('Invalid day: Not between 1 and 31'),'pm');
58 if ($year && isset($month) && isset($day)) {
59 if (!checkdate($month, $day, $year)) {
60 exit_error(_('Invalid date')._(': ')."$year-$month-$day",'pm');
64 if ($type && $type != 'onemonth' && $type != 'threemonth' && $type != 'currentyear' && $type != 'comingyear') {
65 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'];
87 $months = array(1 => _('January'), _('February'), _('March'), _('April'), _('May'), _('June'),
88 _('July'), _('August'), _('September'), _('October'), _('November'), _('December'));
90 if ($group_id && $group_project_id) {
91 require_once $gfcommon.'pm/ProjectTaskFactory.class.php';
92 require_once $gfcommon.'pm/ProjectGroup.class.php';
94 $g = group_get_object($group_id);
95 if (!$g || !is_object($g)) {
97 } elseif ($g->isError()) {
98 exit_error($g->getErrorMessage(),'pm');
100 $pg = new ProjectGroup($g, $group_project_id);
101 if (!$pg || !is_object($pg)) {
102 exit_error(_('Error: Could Not Get Factory'),'pm');
103 } elseif ($pg->isError()) {
104 exit_error($pg->getErrorMessage(),'pm');
107 $ptf = new ProjectTaskFactory($pg);
108 if (!$ptf || !is_object($ptf)) {
109 exit_error(_('Error: Could Not Get ProjectTaskFactory'),'pm');
110 } elseif ($ptf->isError()) {
111 exit_error($ptf->getErrorMessage(),'pm');
113 // Violate all known laws about OOP here
115 $ptf->order='start_date';
120 $pt_arr =& $ptf->getTasks();
121 if ($ptf->isError()) {
122 exit_error($ptf->getErrorMessage(),'pm');
126 pm_header(array('title'=>_('Calendar'),'group'=>$group_id));
129 * Create link to a task.
130 * This returns a string that is a link to a particular task.
132 * @author Ryan T. Sammartino <ryants at shaw dot ca>
133 * @param object $task the task to make a link for.
134 * @param string $type either 'begin' for beginning of a task or 'end' for end of a task.
139 function make_task_link($task, $type) {
140 global $group_id, $group_project_id;
141 return '<a title="'. util_html_secure(sprintf(_('Task summary: %s'), $task->getSummary()))
142 . '" href="'.util_make_url ('/pm/task.php?func=detailtask&project_task_id=' . $task->getID() . '&group_id=' . $group_id . '&group_project_id=' .$group_project_id)
143 . '">' . ($type == 'begin' ?
144 sprintf(_('Task %d begins'), $task->getID()) :
145 sprintf(_('Task %d ends'), $task->getID()) )
151 * This displays one month. m may be less than 0 and greater than 12: display_month
152 * uses mktime() to readjust it and the year in such cases.
154 * @author Ryan T. Sammartino <ryants at shaw dot ca>
155 * @param int $m month
160 function display_month($m, $y) {
161 global $today, $month, $day, $year, $pt_arr, $HTML;
162 $dow = array(_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday'));
164 $tstamp = mktime(0, 0, 0, $m + 1, 0, $y) ;
166 $date = getdate($tstamp);
167 $days_in_month = $date['mday'];
169 $date = getdate($tstamp);
170 $first_dow = $date['wday'];
175 <table class="centered fullwidth bordered">
177 <th colspan="7"><?php echo date (_('F Y'), $tstamp); ?></th>
182 while (list ($key, $val) = each ($dow)) {
183 print "<th style=\"width:14%\">$val</th>\n";
191 while ($curr_dow != $first_dow) {
195 while ($curr_date <= $days_in_month) {
196 while ($curr_dow < 7) {
197 if ($curr_date <= $days_in_month) {
199 if ($curr_date == $today['mday']
200 && $y == $today['year']
201 && $m == $today['mon']) {
203 } elseif ($curr_date == $day
208 print "<td class=\"top " . $colour . "\">$curr_date";
210 $rows = count($pt_arr);
211 for ($i = 0; $i < $rows; $i++) {
212 $start_date = getdate($pt_arr[$i]->getStartDate());
213 $end_date = getdate($pt_arr[$i]->getEndDate());
214 if ($curr_date == $start_date['mday']
215 && $y == $start_date['year']
216 && $m == $start_date['mon']) {
217 $cell_contents .= make_task_link($pt_arr[$i], 'begin');
218 } elseif ($curr_date == $end_date['mday']
219 && $y == $end_date['year']
220 && $m == $end_date['mon']) {
221 $cell_contents .= make_task_link($pt_arr[$i], 'end');
224 if ($cell_contents == '') {
225 $cell_contents = '<br />';
227 print "$cell_contents</td>\n";
235 if ($curr_date <= $days_in_month) {
246 echo $HTML->openForm(array('action' => '/pm/calendar.php', 'method' => 'get'));
248 <table class="fullwidth">
250 <td><?php echo _('Period'); ?><br />
254 <option value="onemonth"' . ($type == 'onemonth' ? ' selected="selected"' : '') . '>'. _('One month') . '</option>';
256 <option value="threemonth"' . ($type == 'threemonth' ? ' selected="selected"' : '') . '>'. _('Three month') . '</option>';
258 <option value="currentyear"' . ($type == 'currentyear' ? ' selected="selected"' : '') . '>' . _('Current year') . '</option>';
260 <option value="comingyear"' . ($type == 'comingyear' ? ' selected="selected"' : '') . '>' . _('Coming year') . '</option>';
264 <td><?php echo _('Date'); ?><br />
268 for ($i = 1990; $i < 2020; $i++) {
269 print "<option value=\"$i\"" . ($year == $i ? ' selected="selected"' : '') . ">$i</option>\n";
273 <select name="month">
275 for ($i = 1; $i <= 12; $i++) {
276 print "<option value=\"$i\"" . ($month == $i ? ' selected="selected"' : '') . ">" . $months[$i] . "</option>\n";
282 for ($i = 1; $i <= 31; $i++) {
283 print "<option value=\"$i\"" . ($day == $i ? ' selected="selected"' : '') . ">$i</option>\n";
289 <input type="submit" value="<?php echo _('Update') ?>" />
294 if (isset($group_id) && isset($group_project_id)) {
296 <input type="hidden" name="group_id" value="'. $group_id .'" />
297 <input type="hidden" name="group_project_id" value="'. $group_project_id .'" />';
299 echo $HTML->closeForm();
302 <table class="fullwidth">
304 <td style="width:20px" class="selected"></td>
305 <td><?php echo _('today\'s date') ?></td>
308 <td style="width:20px"></td>
309 <td><?php echo _('selected date') ?></td>
314 if ($type == 'onemonth') {
315 display_month($month, $year);
316 } elseif ($type == 'threemonth') {
317 display_month($month - 1, $year);
319 display_month($month, $year);
321 display_month($month + 1, $year);
322 } elseif ($type == 'currentyear') {
323 for ($i = 1; $i <= 12; $i++) {
324 display_month($i, $year);
327 } elseif ($type == 'comingyear') {
328 for ($i = 0; $i < 12; $i++) {
329 display_month($month + $i, $year);
338 // c-file-style: "bsd"