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
52 (SELECT ctid FROM rep_time_tracking
55 AND project_task_id=$3
64 if (!$res || db_affected_rows($res) < 1) {
65 exit_error(db_error());
67 $feedback=_('Successfully Deleted.');
70 $error_msg = _('Delete failed')._(': ').$project_task_id.' && '.$report_date.' && '.$old_time_code;
73 } elseif (getStringFromRequest('add')) {
74 $days_adjust = getIntFromRequest('days_adjust');
76 if ($project_task_id && $week && $time_code && $hours) { # && $days_adjust has always a valid number. No need to prove.
78 //$date_list = split('[- :]',$report_date,5);
79 //$report_date = mktime($date_list[3],$date_list[4],0,$date_list[1],$date_list[2],$date_list[0]);
80 //make it 12 NOON of the report_date
81 $report_date=($week + ($days_adjust*REPORT_DAY_SPAN))+(12*60*60);
82 $res = db_query_params ('INSERT INTO rep_time_tracking (user_id,week,report_date,project_task_id,time_code,hours)
83 VALUES ($1,$2,$3,$4,$5,$6)',
90 if (!$res || db_affected_rows($res) < 1) {
91 exit_error(db_error());
93 $feedback.=_('Successfully Added');
96 exit_error(_('All fields are required!'));
102 $group_project_id = getIntFromRequest('group_project_id');
104 report_header(_('Time tracking'));
106 if (!$group_project_id) {
107 $project_ids = array () ;
108 foreach (session_get_user()->getGroups() as $p) {
109 $project_ids[] = $p->getID() ;
112 $respm = db_query_params ('SELECT pgl.group_project_id,g.group_name || $1 || pgl.project_name
113 FROM groups g, project_group_list pgl
114 WHERE g.group_id=ANY($2)
115 AND g.group_id=pgl.group_id
116 ORDER BY group_name,project_name',
118 db_int_array_to_any_clause($project_ids)));
121 <h2><?php printf(_('Time Entries For The Week Starting %s'), date(_('Y-m-d'),$week)) ?></h2>
123 $res = db_query_params ('SELECT pt.project_task_id, pgl.project_name || $1 || pt.summary AS name,
124 rtt.hours, rtt.report_date, rtc.category_name, rtt.time_code
125 FROM groups g, project_group_list pgl, project_task pt, rep_time_tracking rtt,
126 rep_time_category rtc
128 AND rtt.time_code=rtc.time_code
130 AND g.group_id=pgl.group_id
131 AND pgl.group_project_id=pt.group_project_id
132 AND pt.project_task_id=rtt.project_task_id
133 ORDER BY rtt.report_date',
138 $rows=db_numrows($res);
139 if ($group_project_id || $rows) {
141 $title_arr[]=_('Project/Task');
142 $title_arr[]=_('Date');
143 $title_arr[]=_('Hours worked');
144 $title_arr[]=_('Category');
150 echo $HTML->listTableTop ($title_arr);
151 while ($r=db_fetch_array($res)) {
152 echo '<tr '.$HTML->boxGetAltRowStyle($xi++).'>
153 <td class="align-center">'.$r['name'].'</td>
154 <td class="align-center">'. date( 'D, M d, Y',$r['report_date']) .'</td>
155 <td class="align-center"><!-- <input type="text" name="hours" value="'. $r['hours'] .'" size="3" maxlength="3" /> -->'.$r['hours'].'</td>
156 <td class="align-center"><!-- '.report_time_category_box('time_code',$r['time_code']).' -->'.$r['category_name'].'</td>
157 <td class="align-center"><!-- <input type="submit" name="update" value="Update" /> -->
158 <form action="'.getStringFromServer('PHP_SELF').'?week='.$week.'&project_task_id='.$r['project_task_id'].'" method="post">
159 <input type="hidden" name="submit" value="1" />
160 <input type="hidden" name="report_date" value="'.$r['report_date'] .'" />
161 <input type="hidden" name="old_time_code" value="'.$r['time_code'] .'" />
162 <input type="hidden" name="hours" value="'.$r['hours'].'" />
163 <input type="submit" name="delete" value="'. _('Delete').'" />
167 $total_hours += $r['hours'];
169 if ($group_project_id) {
171 $respt=db_query_params ('SELECT project_task_id,summary FROM project_task WHERE group_project_id=$1',
172 array($group_project_id));
174 echo '<form action="'.getStringFromServer('PHP_SELF').'?week='.$week.'" method="post">
175 <input type="hidden" name="submit" value="1" />
176 <input type="hidden" name="week" value="'.$week.'" />
177 <tr '.$HTML->boxGetAltRowStyle($xi++).'>
178 <td class="align-center">'. html_build_select_box ($respt,'project_task_id',false,false) .'</td>
179 <td class="align-center">'.report_day_adjust_box().'</td>
180 <td class="align-center"><input type="text" name="hours" value="" size="3" maxlength="3" /></td>
181 <td class="align-center">'.report_time_category_box('time_code',false).'</td>
182 <td class="align-center"><input type="submit" name="add" value="'.
183 _('Add').'" /><input type="submit" name="cancel" value="'._('Cancel').'" /></td>
186 if (!isset($total_hours)) $total_hours = '';
187 echo '<tr '.$HTML->boxGetAltRowStyle($xi++).'><td colspan="2"><strong>'._('Total Hours')._(':').'</strong></td>';
188 echo '<td class="align-center"><strong>'.$total_hours.'</strong></td><td colspan="2"></td></tr>';
189 echo $HTML->listTableBottom();
191 if (!$group_project_id) {
193 <h2><?php echo _('Add Entry'); ?></h2>
194 <p><?php echo _('Choose a Project/Subproject in the Tasks. You will then have to choose a Task and category to record your time in.'); ?></p>
195 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>" method="get">
196 <input type="hidden" name="week" value="<?php echo $week; ?>" />
199 <td><strong><?php echo _("Tasks Project")._(':'); ?></strong></td>
200 <td><?php echo html_build_select_box ($respm,'group_project_id',false,false); ?></td>
201 <td><input type="submit" name="submit"
202 value="<?php echo _('Next'); ?>" /></td>
207 <h2><?php echo _('Change Week') ?></h2>
209 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>"
210 method="get"><?php echo report_weeks_box($report,'week'); ?><input
211 type="submit" name="submit" value="<?php echo _('Change Week'); ?>" />
216 // First Choose A Week to add/update/delete time sheet info
220 report_header(_('Time tracking'));
223 <h2><?php echo _('Choose A Week to Record Or Edit Your Time.'); ?></h2>
225 <p><?php echo _("After you choose a week, you will be prompted to choose a Project/Subproject in the Tasks."); ?></p>
226 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>"
228 <p><strong><?php echo _('Week Starting')._(':'); ?></strong></p>
229 <?php echo report_weeks_box($report,'week'); ?>
230 <p><input type="submit" name="submit" value="<?php echo _('Next'); ?>" /></p>
240 // c-file-style: "bsd"