-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
311 lines (268 loc) · 10.1 KB
/
Copy pathindex.php
File metadata and controls
311 lines (268 loc) · 10.1 KB
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<?php
$timesheet_id = isset($_GET['timesheet_id']) ? $_GET['timesheet_id'] : 0;
// check permissions
$denyRead = getDenyRead( $m, $timesheet_id );
$denyEdit = getDenyEdit( $m, $timesheet_id );
if ($denyRead) {
$AppUI->redirect( "m=help&a=access_denied" );
}
$AppUI->savePlace();
require_once( "./classes/date.class.php" );
$df = $AppUI->getPref( 'SHDATEFORMAT' );
$rollover_day = LOCALE_FIRST_DAY; // set the start of the week. 1 for monday, 0 for sunday.
#################################### [ view section UI code ] ########################
/**
* Gets the start of the week based on date passed
* @param $date date to find start of week
* @param $rollover_day day on which week starts. 1 for monday, 0 for sunday.
* @return object Date the new Date object
*/
function getStartOfWeek($date, $rollover_day) {
$today_weekday = $date -> getDayOfWeek();
$new_start_offset = $rollover_day - (int)$today_weekday;
$date -> subtractSeconds($new_start_offset * 24 * 60 * 60 * -1);
return $date;
}
/**
* Convert hours to time, add leading zeroes.
* @param $hours hours to convert to time
* @return string of the hours and minutes (00:00)
*/
function hoursToTime($total_hours) {
//since we're trying to convert an unknown float to an integer
//we need to round number to a safe amount of decimal digits
//to avoid floating point arithmetic mishaps. In particular
//without rounding intval( 1.9999... ) gives 1
//supposedly 7 is a safe number of digits(?) -- it will allow
//precision of up to 0.000006 minutes (0.00036 sec)
$total_hours = round( $total_hours, 7 );
$hours = intval( $total_hours );
$minutes = (($total_hours - $hours) * 60);
$time['hour'] = $hours;
$time['minute'] = $minutes;
return padTime( (object) $time );
}
function splitTime( $time ) {
$hhmm = explode( ":", $time );
if ( count($hhmm) > 1 ) {
$hhmm['hour'] = $hhmm[0];
$hhmm['minute'] = $hhmm[1];
}
return (object) $hhmm;
}
function padTime( $time ) {
return sprintf( "%02.0f:%02.0f", $time->hour, $time->minute );
}
/**
* truncate() Simple function to shorten a string and add an ellipsis
*
* @param string $string Origonal string
* @param integer $max Maximum length
* @param string $rep Replace with... (Default = '' - No elipsis -)
* @return string
* @author David Duong and Alex :)
**/
function truncate ($string, $max = 50, $rep = '') {
if ( strlen($string) < $max + strlen($rep) ) {
return $string;
} else {
$leave = $max - strlen ($rep);
return substr_replace($string, $rep, $leave);
}
}
?>
<script language="JavaScript" type="text/javascript">
function sendIt() {
if (confirm( "Is all the information and time on this timesheet correct and accurate?\n" )) {
var form = document.TIDedit;
form.submit();
}
}
</script>
<table width="98%" border="0" cellpadding="0" cellspacing="2">
<tr>
<td><img src="./images/icons/projects.gif" alt="" border="0" width=42 height=42></td>
<td nowrap>
<span class="title"><?php echo $AppUI->_( 'Timesheet' );?></span>
</td>
<td align="right" width="100%"></td>
<td nowrap="nowrap" width="20" align="right"><?php echo contextHelp( '<img src="./images/obj/help.gif" width="14" height="16" border="0" alt="'.$AppUI->_( 'Help' ).'">' );?></td>
</tr>
</table>
<!-- ################# Bad HTML Code -->
<?php
//get week to be displayed (#weeks ago current week being 0)
if (isset( $_GET['wk'] ) ) {
$AppUI->setState( 'TmsWk', $_GET['wk'] );
}
$wk = $AppUI->getState( 'TmsWk') !== NULL && $wk >= 0 ? $AppUI->getState( 'TmsWk' ) : 0;
if ( $wk == 0 )
$week_text = $AppUI->_("Current week");
else if ( $wk == 1 )
$week_text = $AppUI->_("Last week");
else
$week_text = "$wk " . $AppUI->_("weeks ago");
if (isset( $_GET['tab'] )) {
$AppUI->setState( 'TmsVwTab', $_GET['tab'] );
}
$tab = $AppUI->getState( 'TmsVwTab' ) !== NULL ? $AppUI->getState( 'TmsVwTab' ) : 0;
$tabBox = new CTabBox( "?m=timesheet", "./modules/timesheet/", $tab );
$tabBox->add( 'vw_general', 'General' );
$tabBox->add( 'vw_tasks_todo', 'Tasks' );
$tabBox->show();
?>
<form name="TIDedit" action="./index.php?m=timesheet&a=dosql" method="post">
<table width="100%" border="0" bgcolor="#f4efe3" cellpadding="3" cellspacing="1" class="tbl">
<tr>
<th norap="nowrap" colspan="7"><?php echo $week_text ?></th>
</tr>
<tr>
<th nowrap="nowrap"><?php echo $AppUI->_('Date') ?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('In') ?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('Out') ?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('Break') ?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('Total') ?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('Total Logged') ?></th>
<th nowrap="nowrap" width="65%"> <br></th>
</tr>
<?php
$time_set = new CDate ();
$time_set->addDays( -7 * $wk );
$time_set = getStartOfWeek($time_set, $rollover_day);
$date_start = $time_set -> format("%Y-%m-%d");
$total_time_worked = new CDate('0000-00-00 00:00:00');
$total_hours_logged = 0;
// loop through the week
for ($day = 0; $day < 7; $day++) {
$date_temp = $time_set -> format("%Y-%m-%d");
//pull data for this timesheet
$timesheet_sql = "
SELECT timesheet.*
from timesheet
WHERE timesheet_date = '$date_temp'
AND user_id = $AppUI->user_id
";
$result = db_exec ( $timesheet_sql );
$timesheet_row = db_fetch_assoc ( $result );
$log_sql = "
SELECT task_log.*, user_username, tasks.task_name, tasks.task_id, tasks.task_description, projects.project_short_name, projects.project_id, projects.project_description, companies.company_name
FROM task_log
LEFT JOIN users ON user_id = task_log_creator
LEFT JOIN tasks ON task_id = task_log_task
LEFT JOIN projects ON project_id = task_project
LEFT JOIN companies ON company_id = project_company
WHERE task_log_date = '$date_temp'and user_id = $AppUI->user_id
ORDER BY task_log_date
";
$logs = db_loadList( $log_sql );
$s = '';
$logged_hours = 0;
foreach ($logs as $log_row) {
$logged_hours += $log_row["task_log_hours"];
$s .= "<tr>";
$s .= "\n\t\t<td><a href=\"?m=tasks&a=view&task_id=${log_row['task_log_task']}&tab=1&task_log_id=".@$log_row['task_log_id'].'" style="cursor: hand;" title="edit log">'
. "\n\t\t\t". dPshowImage( './images/icons/stock_edit-16.png', 16, 16, 'edit log' )
. "\n\t\t</a></td>";
$s .= "<td nowrap=\"nowrap\" align=\"left\"><a href=\"index.php?m=projects&a=view&project_id=${log_row['project_id']}\" title=\"${log_row['project_description']}\">${log_row['project_short_name']}</a> -> ";
$s .= "<a href=\"index.php?m=tasks&a=view&task_id=${log_row['task_id']}\" title=\"${log_row['task_description']}\">" . truncate($log_row["task_name"], 30, '...') . "</a> -> " . truncate($log_row["task_log_name"], 30, '...') . "</td>\n\t";
$s .= '<td nowrap="nowrap" class="numerical">' . sprintf("%.2f", $log_row["task_log_hours"]) . "</td>\n";
$s .= '</tr>';
}
?>
<tr>
<td nowrap><?php
echo $time_set->format("%A %b %e, %Y");
echo '<input type="hidden" name="timesheet_date[]" value="' . ($timesheet_row["timesheet_date"] ? $timesheet_row["timesheet_date"] : $time_set->format("%Y-%m-%d")) . '">';
?>
<input name="timesheet_id[]" value="<?php echo $timesheet_row["timesheet_id"] ?>" type="hidden">
</td>
<td nowrap><input type="text" size="5" name="timesheet_time_in[]" value="<?php
if (db_num_rows($result)) {
$timeIn = splitTime( $timesheet_row["timesheet_time_in"] );
if (intval($timeIn->hour) or intval($timeIn->minute)) echo "$timeIn->hour:$timeIn->minute";
}
?>">
</td>
<td nowrap><input type="text" size="5" name="timesheet_time_out[]" value="<?php
if (db_num_rows($result)) {
$timeOut = splitTime( $timesheet_row["timesheet_time_out"] );
if (intval($timeOut->hour) or intval($timeOut->minute)) echo "$timeOut->hour:$timeOut->minute";
}
?>">
</td>
<td nowrap><input type="text" size="5" name="timesheet_time_break[]" value="<?php
if (db_num_rows($result)) {
$timeBreak = splitTime( $timesheet_row["timesheet_time_break"] );
if (intval($timeBreak->hour) or intval($timeBreak->minute)) echo "$timeBreak->hour:$timeBreak->minute";
}
?>">
</td>
<td nowrap align="center"><?php
if ((intval($timeOut->hour) or intval($timeOut->minute)) and (intval($timeIn->hour) or intval($timeIn->minute))) {
$minutes_daily = ($timeOut->hour - $timeIn->hour - $timeBreak->hour)*60 + ($timeOut->minute - $timeIn->minute - $timeBreak->minute);
$time_daily->hour = (int)( $minutes_daily / 60 );
$time_daily->minute = $minutes_daily % 60;
//echo $timeOut->format("%H:%M");
echo padTime( $time_daily );
} else echo '--';
?>
</td>
<td nowrap align="center">
<?php
if ($logged_hours) {
// convert hours logged to time logged...
echo hoursToTime($logged_hours);
} else echo '--';
?>
</td>
<td nowrap align="center">
<table border="0" bgcolor="#f4efe3" cellpadding="3" cellspacing="1" class="tbl" width="100%">
<tr>
<td colspan="2" nowrap="nowrap" width="100%"><b>Task</b></td>
<td nowrap="nowrap"><b>Hours</b></td>
</tr>
<?php echo $s ?>
</table>
</td>
</tr>
<?php
// total the total hours
$time_set -> addSeconds(24 * 60 * 60);
//$total_time_worked->addSeconds($timeOut->hour * 60 * 60 + $timeOut->minute * 60);
$total_time_worked->hour += $time_daily->hour + floor( ($total_time_worked->minute + $time_daily->minute) / 60 );
$total_time_worked->minute = ( $total_time_worked->minute + $time_daily->minute ) % 60;
$total_hours_logged += $logged_hours;
// reset times
$timeIn = null;
$timeOut = null;
$timeBreak = null;
$time_daily = null;
}
?>
<tr>
<td nowrap><br></td>
<td nowrap align="left" colspan="3"><b>Total:</b></td>
<td nowrap align="center"><b><?php echo padTime( $total_time_worked ); ?></b></td>
<td nowrap align="center"><b><?php echo hoursToTime($total_hours_logged); ?></b></td>
<td nowrap align="right"><input type="submit" name="update" value="Update" class="button"></td>
</tr>
<?php
if ($tg_data['tt_active'] > 0 ) {
?>
<tr>
<td colspan="8" align="right">
<a href="index.php?m=timesheet&a=addedit×heet_id=<?php echo $timesheet_id;?>&addrow=1&tid=0">Add New Row</a>
</td>
</tr>
<?php
}
if ($tg_data['tt_active'] > 0 ) {
?>
<tr bgcolor="#FFFFFF">
<td colspan="8" bgcolor="#FFFFFF" align="right">
<input class="button" type="Button" value="Send In" onClick="sendIt();">
</td>
</tr>
<?php } ?>
</table>
</form>