5 * Copyright 2004 (c) GForge LLC - Tim Perdue
6 * Copyright (C) 2011-2012 Alain Peyrat - Alcatel-Lucent
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.
25 require_once('../env.inc.php');
26 require_once $gfcommon.'include/pre.php';
27 require_once $gfcommon.'reporting/report_utils.php';
28 require_once $gfcommon.'reporting/Report.class.php';
30 if (!session_loggedin()) {
35 if ($report->isError()) {
36 exit_error($report->getErrorMessage());
39 $week = getIntFromRequest('week');
40 $project_task_id = getIntFromRequest('project_task_id');
42 if (getStringFromRequest('submit')) {
43 $report_date = getStringFromRequest('report_date');
44 $time_code = getStringFromRequest('time_code');
45 $old_time_code = getStringFromRequest('old_time_code');
46 $hours = getStringFromRequest('hours');
48 if (getStringFromRequest('delete')) {
49 if ($project_task_id && $report_date && $old_time_code) {
50 $res=db_query_params ('DELETE FROM rep_time_tracking
53 AND project_task_id=$3
59 if (!$res || db_affected_rows($res) < 1) {
60 exit_error(db_error());
62 $feedback=_('Successfully Deleted');
65 $error_msg = _('INTERNAL ERROR: delete: ').$project_task_id.' && '.$report_date.' && '.$old_time_code;
68 } elseif (getStringFromRequest('add')) {
69 $days_adjust = getIntFromRequest('days_adjust');
71 if ($project_task_id && $week && $time_code && $hours) { # && $days_adjust has always a valid number. No need to prove.
73 //$date_list = split('[- :]',$report_date,5);
74 //$report_date = mktime($date_list[3],$date_list[4],0,$date_list[1],$date_list[2],$date_list[0]);
75 //make it 12 NOON of the report_date
76 $report_date=($week + ($days_adjust*REPORT_DAY_SPAN))+(12*60*60);
77 $res = db_query_params ('INSERT INTO rep_time_tracking (user_id,week,report_date,project_task_id,time_code,hours)
78 VALUES ($1,$2,$3,$4,$5,$6)',
85 if (!$res || db_affected_rows($res) < 1) {
86 exit_error(db_error());
88 $feedback.=_('Successfully Added');
91 exit_error(_('All Fields Are Required.'));
97 $group_project_id = getIntFromRequest('group_project_id');
99 report_header(_('Time tracking'));
101 if (!$group_project_id) {
102 $project_ids = array () ;
103 foreach (session_get_user()->getGroups() as $p) {
104 $project_ids[] = $p->getID() ;
107 $respm = db_query_params ('SELECT pgl.group_project_id,g.group_name || $1 || pgl.project_name
108 FROM groups g, project_group_list pgl
109 WHERE g.group_id=ANY($2)
110 AND g.group_id=pgl.group_id
111 ORDER BY group_name,project_name',
113 db_int_array_to_any_clause($project_ids)));
116 <h2><?php printf(_('Time Entries For The Week Starting %s'), date(_('Y-m-d'),$week)) ?></h2>
118 $res = db_query_params ('SELECT pt.project_task_id, pgl.project_name || $1 || pt.summary AS name,
119 rtt.hours, rtt.report_date, rtc.category_name, rtt.time_code
120 FROM groups g, project_group_list pgl, project_task pt, rep_time_tracking rtt,
121 rep_time_category rtc
123 AND rtt.time_code=rtc.time_code
125 AND g.group_id=pgl.group_id
126 AND pgl.group_project_id=pt.group_project_id
127 AND pt.project_task_id=rtt.project_task_id
128 ORDER BY rtt.report_date',
133 $rows=db_numrows($res);
134 if ($group_project_id || $rows) {
136 $title_arr[]=_('Project/Task');
137 $title_arr[]=_('Date');
138 $title_arr[]=_('Hours worked');
139 $title_arr[]=_('Category');
145 echo $HTML->listTableTop ($title_arr);
146 while ($r=db_fetch_array($res)) {
147 echo '<form action="'.getStringFromServer('PHP_SELF').'?week='.$week.'&project_task_id='.$r['project_task_id'].'" method="post">
148 <input type="hidden" name="submit" value="1" />
149 <input type="hidden" name="report_date" value="'.$r['report_date'] .'" />
150 <input type="hidden" name="old_time_code" value="'.$r['time_code'] .'" />
151 <tr '.$HTML->boxGetAltRowStyle($xi++).'>
152 <td align="middle">'.$r['name'].'</td>
153 <td align="middle">'. date( 'D, M d, Y',$r['report_date']) .'</td>
154 <td align="middle"><!-- <input type="text" name="hours" value="'. $r['hours'] .'" size="3" maxlength="3" /> -->'.$r['hours'].'</td>
155 <td align="middle"><!-- '.report_time_category_box('time_code',$r['time_code']).' -->'.$r['category_name'].'</td>
156 <td align="middle"><!-- <input type="submit" name="update" value="Update" /> -->
157 <input type="submit" name="delete" value="'. _('Delete').'" /></td>
159 $total_hours += $r['hours'];
161 if ($group_project_id) {
163 $respt=db_query_params ('SELECT project_task_id,summary FROM project_task WHERE group_project_id=$1',
164 array($group_project_id));
166 echo '<form action="'.getStringFromServer('PHP_SELF').'?week='.$week.'" method="post">
167 <input type="hidden" name="submit" value="1" />
168 <tr '.$HTML->boxGetAltRowStyle($xi++).'>
169 <td class="align-center">'. html_build_select_box ($respt,'project_task_id',false,false) .'</td>
170 <td class="align-center"><input type="text" name="report_date" value="'. date('Y-m-d',$week) .'" size="10" maxlength="10" /></td>
171 <td class="align-center"><input type="text" name="hours" value="" size="3" maxlength="3" /></td>
172 <td class="align-center">'.report_time_category_box('time_code',false).'</td>
173 <td class="align-center"><input type="submit" name="add" value="'.
174 _('Add').'" /><input type="submit" name="cancel" value="'._('Cancel').'" /></td>
178 if (!isset($total_hours)) $total_hours = '';
179 echo '<tr '.$HTML->boxGetAltRowStyle($xi++).'><td colspan="2"><strong>'._('Total Hours').':</strong></td><td><strong>'.$total_hours.'</strong></td><td colspan="2"></td></tr>';
181 echo $HTML->listTableBottom();
184 if (!$group_project_id) {
187 <h3><?php echo _('Add Entry'); ?></h3>
188 <p><?php echo _('Choose a Project/Subproject in the Task Manager. You will then have to choose a Task and category to record your time in.'); ?>
190 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>"
191 method="get" /><input type="hidden" name="week"
192 value="<?php echo $week; ?>" />
195 <td><strong><?php echo _("Tasks Project"); ?>:</strong></td>
196 <td><?php echo html_build_select_box ($respm,'group_project_id',false,false); ?></td>
197 <td><input type="submit" name="submit"
198 value="<?php echo _('Next'); ?>" /></td>
203 <h2><?php echo _('Change week') ?></h2>
205 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>"
206 method="get" /><?php echo report_weeks_box($report,'week'); ?><input
207 type="submit" name="submit" value="<?php echo _('Change Week'); ?>" />
212 // First Choose A Week to add/update/delete time sheet info
216 /* report_header(_('Time tracking')); Outcommented the report_header().
217 * Do not get the reason of the report_header() in here. */
220 <h2><?php echo _('Choose A Week to Record Or Edit Your Time.'); ?></h2>
222 <p><?php echo _("After you choose a week, you will be prompted to choose a Project/Subproject in the Tasks."); ?></p>
223 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>"
225 <p><strong><?php echo _('Week Starting'); ?>:</strong></p>
226 <?php echo report_weeks_box($report,'week'); ?>
227 <p><input type="submit" name="submit" value="<?php echo _('Next'); ?>" /></p>
237 // c-file-style: "bsd"