5 * This file displays various sorts of calendars.
7 * Copyright 2002 (c) GForge Development Team
9 * @todo some locales start the week with "Monday", and not "Sunday".
10 * @todo display holidays.
13 require_once('../env.inc.php');
14 require_once $gfwww.'include/pre.php';
16 $group_id = getIntFromRequest('group_id');
17 $group_project_id = getIntFromRequest('group_project_id');
18 $year = getIntFromRequest('year');
19 $month = getIntFromRequest('month');
20 $day = getIntFromRequest('day');
21 $type = getStringFromRequest('type');
23 // Some sanity checks first.
24 if ($year && ($year < 1990 || $year > 2020)) {
25 exit_error(_('Invalid year'),
26 _('Not between 1990 and 2000'));
29 if ($month && ($month < 1 || $month > 12)) {
30 exit_error(_('Invalid month'),
31 _('Not between 1 and 12'));
34 if ($day && ($day < 1 || $day > 31)) {
35 exit_error(_('Invalid day'),
36 _('Not between 1 and 31'));
39 if ($year && isset($month) && isset($day)) {
40 if (!checkdate($month, $day, $year)) {
41 exit_error(_('Invalid date'),
42 sprintf(_('Date not valid'), "$year-$month-$day"));
46 if ($type && $type != 'onemonth' && $type != 'threemonth' && $type != 'currentyear' && $type != 'comingyear') {
47 exit_error(_('Invalid type'),
48 _('Type not in onemonth, threemonth, currentyear, comingyear'));
57 $today = getdate(time());
60 $year = $today['year'];
64 $month = $today['mon'];
68 $day = $today['mday'];
72 $months = array(1 => _('January'), _('February'), _('March'), _('April'), _('May'), _('June'),
73 _('July'), _('August'), _('September'), _('October'), _('November'), _('December'));
75 if ($group_id && $group_project_id) {
76 require_once $gfcommon.'pm/ProjectTaskFactory.class.php';
77 require_once $gfcommon.'pm/ProjectGroup.class.php';
79 $g =& group_get_object($group_id);
80 if (!$g || !is_object($g)) {
82 } elseif ($g->isError()) {
83 exit_error(_('ERROR'), $g->getErrorMessage());
85 $pg = new ProjectGroup($g, $group_project_id);
86 if (!$pg || !is_object($pg)) {
87 exit_error(_('ERROR'), 'BUG: Could Not Get Factory');
88 } elseif ($pg->isError()) {
89 exit_error(_('ERROR'), $pg->getErrorMessage());
92 $ptf = new ProjectTaskFactory($pg);
93 if (!$ptf || !is_object($ptf)) {
94 exit_error(_('ERROR'), 'BUG: Could Not Get ProjectTaskFactory');
95 } elseif ($ptf->isError()) {
96 exit_error(_('ERROR'), $ptf->getErrorMessage());
98 // Violate all known laws about OOP here
100 $ptf->order='start_date';
105 $pt_arr =& $ptf->getTasks();
106 if ($ptf->isError()) {
107 exit_error(_('ERROR'), $ptf->getErrorMessage());
111 $HTML->header(array('title'=>_('Calendar'),'group'=>$group_id));
114 * Create link to a task.
115 * This returns a string that is a link to a particular task.
117 * @author Ryan T. Sammartino <ryants at shaw dot ca>
118 * @param $task the task to make a link for.
119 * @param $type either 'begin' for beginning of a task or 'end' for
124 function make_task_link($task, $type) {
125 global $HTML, $group_id, $group_project_id;
126 return '<a title="'. sprintf(_('Task summary: %s'), $task->getSummary())
127 . '" href="'.util_make_url ('/pm/task.php?func=detailtask&project_task_id=' . $task->getID() . '&group_id=' . $group_id . '&group_project_id=' .$group_project_id)
128 . '">' . ($type == 'begin' ?
129 sprintf(_('Task %d begins'), $task->getID()) :
130 sprintf(_('Task %d ends'), $task->getID()) )
137 * This displays one month. m may be less than 0 and greater than 12: display_month
138 * uses mktime() to readjust it and the year in such cases.
140 * @author Ryan T. Sammartino <ryants at shaw dot ca>
146 function display_month($m, $y) {
147 global $months, $today, $month, $day, $year, $HTML,
148 $pt_arr, $group_id, $group_project_id;
149 $dow = array(_('Sunday'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday'));
151 $tstamp = mktime(0, 0, 0, $m + 1, 0, $y) ;
153 $date = getdate($tstamp);
154 $days_in_month = $date['mday'];
156 $date = getdate($tstamp);
157 $first_dow = $date['wday'];
162 <table align="center" cellpadding="1" cellspacing="1" border="1" width="100%">
164 <th colspan="7"><?php echo date (_('F Y'), $tstamp); ?></th>
169 while (list ($key, $val) = each ($dow)) {
170 print "\t\t\t<th width=\"14%\">$val</th>\n";
178 while ($curr_dow != $first_dow) {
179 print "\t\t\t<td></td>\n";
182 while ($curr_date <= $days_in_month) {
183 while ($curr_dow < 7) {
184 if ($curr_date <= $days_in_month) {
186 if ($curr_date == $today['mday']
187 && $y == $today['year']
188 && $m == $today['mon']) {
190 } elseif ($curr_date == $day
195 print "\t\t\t<td valign=\"top\" class=" . $colour . ">$curr_date";
197 $rows = count($pt_arr);
198 for ($i = 0; $i < $rows; $i++) {
199 $start_date = getdate($pt_arr[$i]->getStartDate());
200 $end_date = getdate($pt_arr[$i]->getEndDate());
201 if ($curr_date == $start_date['mday']
202 && $y == $start_date['year']
203 && $m == $start_date['mon']) {
204 $cell_contents .= make_task_link($pt_arr[$i], 'begin');
205 } elseif ($curr_date == $end_date['mday']
206 && $y == $end_date['year']
207 && $m == $end_date['mon']) {
208 $cell_contents .= make_task_link($pt_arr[$i], 'end');
211 if ($cell_contents == '') {
212 $cell_contents = '<br /><br /><br />';
214 print "$cell_contents</td>\n";
216 print "\t\t\t<td></td>\n";
222 if ($curr_date <= $days_in_month) {
235 <form action="/pm/calendar.php" method="get">
238 <td><?php echo _('Period'); ?><br />
242 <option value="onemonth"' . ($type == 'onemonth' ? ' selected="selected"' : '') . '>'. _('One month') . '</option>';
244 <option value="threemonth"' . ($type == 'threemonth' ? ' selected="selected"' : '') . '>'. _('Three month') . '</option>';
246 <option value="currentyear"' . ($type == 'currentyear' ? ' selected="selected"' : '') . '>' . _('Current year') . '</option>';
248 <option value="comingyear"' . ($type == 'comingyear' ? ' selected="selected"' : '') . '>' . _('Coming year') . '</option>';
252 <td><?php echo _('Date'); ?><br />
256 for ($i = 1990; $i < 2020; $i++) {
257 print "\t\t\t\t<option value=\"$i\"" . ($year == $i ? ' selected="selected"' : '') . ">$i</option>\n";
261 <select name="month">
263 for ($i = 1; $i <= 12; $i++) {
264 print "\t\t\t\t<option value=\"$i\"" . ($month == $i ? ' selected="selected"' : '') . ">" . $months[$i] . "</option>\n";
270 for ($i = 1; $i <= 31; $i++) {
271 print "\t\t\t\t<option value=\"$i\"" . ($day == $i ? ' selected="selected"' : '') . ">$i</option>\n";
277 <input type="submit" value="<?php echo _('Update') ?>" />
282 if (isset($group_id) && isset($group_project_id)) {
284 <input type="hidden" name="group_id" value="'. $group_id .'" />
285 <input type="hidden" name="group_project_id" value="'. $group_project_id .'" />';
292 <td width="20px" class="selected"></td>
293 <td><?php echo _('today\'s date') ?></td>
296 <td width="20px"></td>
297 <td><?php echo _('selected date') ?></td>
302 if ($type == 'onemonth') {
303 display_month($month, $year);
304 } elseif ($type == 'threemonth') {
305 display_month($month - 1, $year);
306 print "\t<br />\n\n";
307 display_month($month, $year);
308 print "\t<br />\n\n";
309 display_month($month + 1, $year);
310 } elseif ($type == 'currentyear') {
311 for ($i = 1; $i <= 12; $i++) {
312 display_month($i, $year);
313 print "\t<br />\n\n";
315 } elseif ($type == 'comingyear') {
316 for ($i = 0; $i < 12; $i++) {
317 display_month($month + $i, $year);
318 print "\t<br />\n\n";
322 $HTML->footer(array());
326 // c-file-style: "bsd"