5 * Copyright 2004 (c) GForge LLC
7 * @author Tim Perdue tim@gforge.org
10 * This file is part of GForge.
12 * GForge is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * GForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with GForge; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 require_once('../env.inc.php');
28 require_once $gfwww.'include/pre.php';
29 require_once $gfcommon.'reporting/report_utils.php';
30 require_once $gfcommon.'reporting/Report.class.php';
32 if (!session_loggedin()) {
37 if ($report->isError()) {
38 exit_error('Error',$report->getErrorMessage());
41 $week = getIntFromRequest('week');
42 $project_task_id = getIntFromRequest('project_task_id');
44 if (getStringFromRequest('submit')) {
45 $report_date = getStringFromRequest('report_date');
46 $time_code = getStringFromRequest('time_code');
47 $old_time_code = getStringFromRequest('old_time_code');
48 $hours = getStringFromRequest('hours');
50 if (getStringFromRequest('delete')) {
51 if ($project_task_id && $report_date && $old_time_code) {
52 $res=db_query_params ('DELETE FROM rep_time_tracking
55 AND project_task_id=$3
61 if (!$res || db_affected_rows($res) < 1) {
62 exit_error('Error',db_error());
64 $feedback=_('Successfully Deleted');
67 echo "INTERNAL ERROR: delete: $project_task_id && $report_date && $old_time_code";
70 } elseif (getStringFromRequest('add')) {
71 $days_adjust = getIntFromRequest('days_adjust');
73 if ($project_task_id && $week && $time_code && $hours) { # && $days_adjust has always a valid number. No need to prove.
75 //$date_list = split('[- :]',$report_date,5);
76 //$report_date = mktime($date_list[3],$date_list[4],0,$date_list[1],$date_list[2],$date_list[0]);
77 //make it 12 NOON of the report_date
78 $report_date=($week + ($days_adjust*REPORT_DAY_SPAN))+(12*60*60);
79 $res = db_query_params ('INSERT INTO rep_time_tracking (user_id,week,report_date,project_task_id,time_code,hours)
80 VALUES ($1,$2,$3,$4,$5,$6)',
87 if (!$res || db_affected_rows($res) < 1) {
88 exit_error('Error',db_error());
90 $feedback.=_('Successfully Added');
93 exit_error('Error',_('All Fields Are Required.'));
100 $group_project_id = getStringFromRequest('group_project_id');
102 report_header(_('Time tracking'));
104 if (!$group_project_id) {
105 $respm = db_query_params ('SELECT pgl.group_project_id,g.group_name || $1 || pgl.project_name
106 FROM groups g, project_group_list pgl, user_group ug
108 AND ug.group_id=g.group_id
109 AND g.group_id=pgl.group_id
110 ORDER BY group_name,project_name',
115 <h3><?php printf(_('Time Entries For The Week Starting %s'), date(_('Y-m-d'),$week)) ?></h3>
117 $res = db_query_params ('SELECT pt.project_task_id, pgl.project_name || $1 || pt.summary AS name,
118 rtt.hours, rtt.report_date, rtc.category_name, rtt.time_code
119 FROM groups g, project_group_list pgl, project_task pt, rep_time_tracking rtt,
120 rep_time_category rtc
122 AND rtt.time_code=rtc.time_code
124 AND g.group_id=pgl.group_id
125 AND pgl.group_project_id=pt.group_project_id
126 AND pt.project_task_id=rtt.project_task_id
127 ORDER BY rtt.report_date',
132 $rows=db_numrows($res);
133 if ($group_project_id || $rows) {
135 $title_arr[]=_('Project/Task');
136 $title_arr[]=_('Date');
137 $title_arr[]=_('Hours');
138 $title_arr[]=_('Category');
141 echo $HTML->listTableTop ($title_arr);
143 while ($r=&db_fetch_array($res)) {
144 echo '<form action="'.getStringFromServer('PHP_SELF').'?week='.$week.'&project_task_id='.$r['project_task_id'].'" method="post">
145 <input type="hidden" name="submit" value="1" />
146 <input type="hidden" name="report_date" value="'.$r['report_date'] .'" />
147 <input type="hidden" name="old_time_code" value="'.$r['time_code'] .'" />
148 <tr '.$HTML->boxGetAltRowStyle($xi++).'>
149 <td align="middle">'.$r['name'].'</td>
150 <td align="middle">'. date( 'D, M d, Y',$r['report_date']) .'</td>
151 <td align="middle"><!-- <input type="text" name="hours" value="'. $r['hours'] .'" size="3" maxlength="3" /> -->'.$r['hours'].'</td>
152 <td align="middle"><!-- '.report_time_category_box('time_code',$r['time_code']).' -->'.$r['category_name'].'</td>
153 <td align="middle"><!-- <input type="submit" name="update" value="Update" /> -->
154 <input type="submit" name="delete" value="'. _('Delete').'" /></td>
156 $total_hours += $r['hours'];
158 if ($group_project_id) {
160 $respt=db_query_params ('SELECT project_task_id,summary FROM project_task WHERE group_project_id=$1',
161 array($group_project_id));
163 echo '<form action="'.getStringFromServer('PHP_SELF').'?week='.$week.'" method="post">
164 <input type="hidden" name="submit" value="1" />
165 <tr '.$HTML->boxGetAltRowStyle($xi++).'>
166 <td align="middle">'. html_build_select_box ($respt,'project_task_id',false,false) .'</td>
167 <td align="middle"><input type="text" name="report_date" value="'. date('Y-m-d',$week) .'" size="10" maxlength="10" /></td>
168 <td align="middle"><input type="text" name="hours" value="" size="3" maxlength="3" /></td>
169 <td align="middle">'.report_time_category_box('time_code',false).'</td>
170 <td align="middle"><input type="submit" name="add" value="'.
171 _('Add').'" /><input type="submit" name="cancel" value="'._('Cancel').'" /></td>
175 echo '<tr '.$HTML->boxGetAltRowStyle($xi++).'><td colspan="2"><strong>'._('Total Hours').':</strong></td><td><strong>'.$total_hours.'</strong></td><td colspan="2"></td></tr>';
176 echo $HTML->listTableBottom();
179 if (!$group_project_id) {
182 <h3><?php echo _('Add Entry'); ?></h3>
183 <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.'); ?>
185 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>"
186 method="get" /><input type="hidden" name="week"
187 value="<?php echo $week; ?>" />
190 <td><strong><?php echo _('Task Manager Project'); ?>:</strong></td>
191 <td><?php echo html_build_select_box ($respm,'group_project_id',false,false); ?></td>
192 <td><input type="submit" name="submit"
193 value="<?php echo _('Next'); ?>" /></td>
198 <h3><? echo _('Change week') ?></h3>
200 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>"
201 method="get" /><?php echo report_weeks_box($report,'week'); ?><input
202 type="submit" name="submit" value="<?php echo _('Change Week'); ?>" />
207 // First Choose A Week to add/update/delete time sheet info
211 /* report_header(_('Time tracking')); Outcommented the report_header().
212 * Do not get the reason of the report_header() in here. */
215 <h3><?php echo _('Choose A Week to Record Or Edit Your Time.'); ?></h3>
216 <p><?php echo _('After you choose a week, you will be prompted to choose a Project/Subproject in the Task Manager.'); ?>
218 <form action="<?php echo getStringFromServer('PHP_SELF'); ?>"
219 method="get" /><strong><?php echo _('Week Starting'); ?>:</strong><br />
220 <?php echo report_weeks_box($report,'week'); ?>
221 <p><input type="submit" name="submit" value="<?php echo _('Next'); ?>" />
232 // c-file-style: "bsd"