File: timeadd.php

package info (click to toggle)
gforge 4.5.14-22etch13
  • links: PTS
  • area: main
  • in suites: etch
  • size: 13,004 kB
  • ctags: 11,918
  • sloc: php: 36,047; sql: 29,050; sh: 10,538; perl: 6,496; xml: 3,810; makefile: 341; python: 263; ansic: 256
file content (226 lines) | stat: -rw-r--r-- 8,380 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
/**
 * Reporting System
 *
 * Copyright 2004 (c) GForge LLC
 *
 * @version   $Id: timeadd.php 3253 2004-08-04 16:50:45Z kikov $
 * @author Tim Perdue tim@gforge.org
 * @date 2003-03-16
 *
 * This file is part of GForge.
 *
 * GForge is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * GForge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GForge; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

require_once('pre.php');
require_once('common/reporting/report_utils.php');
require_once('common/reporting/Report.class');

if (!session_loggedin()) {
	exit_not_logged_in();
}

global $Language;

$days_adjust = getIntFromRequest('days_adjust');

$report=new Report();
if ($report->isError()) {
	exit_error('Error',$report->getErrorMessage());
}

if ($submit) {
/*
	if ($update) {
		
		if ($project_task_id && $report_date && $time_code) {
			$res=db_query("UPDATE rep_time_tracking 
				SET time_code='$time_code', hours='$hours'
				WHERE user_id='".user_getid()."'
				AND report_date='$report_date'
				AND project_task_id='$project_task_id'
				AND time_code='$old_time_code'");
			if (!$res || db_affected_rows($res) < 1) {
				exit_error('Error',db_error());
			} else {
				$feedback='Successfully Updated';
			}
		}

	} else
*/
	if ($delete) {

		if ($project_task_id && $report_date && $old_time_code) {
			$res=db_query("DELETE FROM rep_time_tracking 
				WHERE user_id='".user_getid()."'
				AND report_date='$report_date'
				AND project_task_id='$project_task_id'
				AND time_code='$old_time_code'");
			if (!$res || db_affected_rows($res) < 1) {
				exit_error('Error',db_error());
			} else {
				$feedback=$Language->getText('reporting_ta','successfully_deleted');
			}
		} else {
			echo "$project_task_id && $report_date && $old_time_code";
		}

	} elseif ($add) {
		if ($project_task_id && $week && $days_adjust && $time_code && $hours) {

			//$date_list = split('[- :]',$report_date,5);
        	//$report_date = mktime($date_list[3],$date_list[4],0,$date_list[1],$date_list[2],$date_list[0]);
			//make it 12 NOON of the report_date
			$report_date=($week + ($days_adjust*REPORT_DAY_SPAN))+(12*60*60);
			$res=db_query("INSERT INTO rep_time_tracking (user_id,week,report_date,project_task_id,time_code,hours) 
				VALUES ('".user_getid()."','$week','$report_date','$project_task_id','$time_code','$hours')");
			if (!$res || db_affected_rows($res) < 1) {
				exit_error('Error',db_error());
			} else {
				$feedback.=$Language->getText('reporting_ta','successfully_added');
			}
		} else {
			echo "$project_task_id && $week && $days_adjust && $time_code && $hours";
			exit_error('Error',$Language->getText('reporting_ta','error_field_required'));
		}

	}
}

if ($week) {

	report_header($Language->getText('reporting_ta','title'));

	if (!$group_project_id) {
		$respm=db_query("SELECT pgl.group_project_id,g.group_name || '**' || pgl.project_name
		FROM groups g, project_group_list pgl, user_group ug
		WHERE ug.user_id='".user_getid()."' 
		AND ug.group_id=g.group_id
		AND g.group_id=pgl.group_id
		ORDER BY group_name,project_name");
	}
	?>
	<h3><?php echo $Language->getText('reporting_ta','time_entries',date('Y-m-d',$week)); ?></h3>
	<p>
	<?php
	$res=db_query("SELECT pt.project_task_id, pgl.project_name || '**' || pt.summary AS name, 
			rtt.hours, rtt.report_date, rtc.category_name, rtt.time_code
			FROM groups g, project_group_list pgl, project_task pt, rep_time_tracking rtt,
			rep_time_category rtc
			WHERE rtt.week='$week'
			AND rtt.time_code=rtc.time_code
			AND rtt.user_id='".user_getid()."'
			AND g.group_id=pgl.group_id
			AND pgl.group_project_id=pt.group_project_id
			AND pt.project_task_id=rtt.project_task_id 
			ORDER BY rtt.report_date");
	$rows=db_numrows($res);
	if ($group_project_id || $rows) {

		$title_arr[]=$Language->getText('reporting_ta','project_task');
		$title_arr[]=$Language->getText('reporting_ta','date');
		$title_arr[]=$Language->getText('reporting_ta','hours');
		$title_arr[]=$Language->getText('reporting_ta','category');
		$title_arr[]=' ';

		echo $HTML->listTableTop ($title_arr);

		while ($r=&db_fetch_array($res)) {
			echo '<form action="'.$PHP_SELF.'?week='.$week.'&project_task_id='.$r['project_task_id'].'" method="post" />
			<input type="hidden" name="submit" value="1" />
			<input type="hidden" name="report_date" value="'.$r['report_date'] .'" />
			<input type="hidden" name="old_time_code" value="'.$r['time_code'] .'" />
			<tr '.$HTML->boxGetAltRowStyle($xi++).'>
				<td align="middle">'.$r['name'].'</td>
				<td align="middle">'. date( 'D, M d, Y',$r['report_date']) .'</td>
				<td align="middle"><!-- <input type="text" name="hours" value="'. $r['hours'] .'" size="3" maxlength="3" /> -->'.$r['hours'].'</td>
				<td align="middle"><!-- '.report_time_category_box('time_code',$r['time_code']).' -->'.$r['category_name'].'</td>
				<td align="middle"><!-- <input type="submit" name="update" value="Update" /> -->
				<input type="submit" name="delete" value="'. $Language->getText('reporting_ta','delete').'" /></td>
			</tr></form>';
			$total_hours += $r['hours'];
		}
		if ($group_project_id) {

			$respt=db_query("SELECT project_task_id,summary FROM project_task WHERE group_project_id='$group_project_id'");

			echo '<form action="'.$PHP_SELF.'?week='.$week.'" method="post" />
			<input type="hidden" name="submit" value="1" />
			<tr '.$HTML->boxGetAltRowStyle($xi++).'>
				<td align="middle">'. html_build_select_box ($respt,'project_task_id',false,false) .'</td>
				<td align="middle"><input type="text" name="report_date" value="'. date('Y-m-d',$week) .'" size="10" maxlength="10" /></td>
				<td align="middle"><input type="text" name="hours" value="" size="3" maxlength="3" /></td>
				<td align="middle">'.report_time_category_box('time_code',false).'</td>
				<td align="middle"><input type="submit" name="add" value="'.
				$Language->getText('reporting','add').'" /><input type="submit" name="cancel" value="'.$Language->getText('reporting_ta','cancel').'" /></td>
			</tr></form>';

		}
		echo '<tr '.$HTML->boxGetAltRowStyle($xi++).'><td colspan="2"><strong>'.$Language->getText('reporting_ta','total_hours').':</strong></td><td><strong>'.$total_hours.'</strong></td><td colspan="2"></td></tr>';
		echo $HTML->listTableBottom();

	}
	if (!$group_project_id) {
		?>
		<p>
		<h3><?php echo $Language->getText('reporting_ta','add_entry'); ?></h3>
		<p>
		<?php echo $Language->getText('reporting_ta','add_entry_description'); ?>
		<p>
		<form action="<?php echo $PHP_SELF; ?>" method="get" />
		<input type="hidden" name="week" value="<?php echo $week; ?>" />
		<table>
		<tr>
			<td><strong><?php echo $Language->getText('reporting_ta','task_mgr_project'); ?>:</strong></td>
			<td><?php echo html_build_select_box ($respm,'group_project_id',false,false); ?></td>
			<td><input type="submit" name="submit" value="<?php echo $Language->getText('reporting','next'); ?>" /></td>
		</tr>
		</table>
		</form>
		<p>
		<h3>Change Week</h3>
		<p>
		<form action="<?php echo $PHP_SELF; ?>" method="get" />
		<?php echo report_weeks_box($report,'week'); ?><input type="submit" name="submit" value="<?php echo $Language->getText('reporting_ta','change_week'); ?>" />
		</form>
		<?php
	}
//
//	First Choose A Week to add/update/delete time sheet info
//
} else {

	report_header($Language->getText('reporting_ta','title'));

	?>
	<h3><?php echo $Language->getText('reporting_ta','choose_entry'); ?></h3>
	<p>
	<?php echo $Language->getText('reporting_ta','choose_entry_description'); ?>
	<p>
	<form action="<?php echo $PHP_SELF; ?>" method="get" />
	<strong><?php echo $Language->getText('reporting_ta','week_starting'); ?>:</strong><br />
	<?php echo report_weeks_box($report,'week'); ?>
	<p>
	<input type="submit" name="submit" value="<?php echo $Language->getText('reporting','next'); ?>" />
	</form>
	<?php

}

report_footer();

?>