/
daily.php
442 lines (392 loc) · 18.2 KB
/
daily.php
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
<?php
// $Header: /cvsroot/tsheet/timesheet.php/daily.php,v 1.7 2005/05/10 11:42:53 vexil Exp $
// Authenticate
require("class.AuthenticationManager.php");
require("class.CommandMenu.php");
if (!$authenticationManager->isLoggedIn()) {
Header("Location: login.php?redirect=$_SERVER[PHP_SELF]");
exit;
}
// Connect to database.
$dbh = dbConnect();
$contextUser = strtolower($_SESSION['contextUser']);
if (empty($contextUser))
errorPage("Could not determine the context user");
//define the command menu
include("timesheet_menu.inc");
//check that the client id is valid
if ($client_id == 0)
$client_id = getFirstClient();
//check that project id is valid
if ($proj_id == 0)
$task_id = 0;
//calculate tomorrow and yesterday for "prev" & "next" buttons
$yesterday = mktime(0,0,0,$month,$day,$year) - 24*60*60;
$tomorrow = mktime(0,0,0,$month,$day,$year) + 24*60*60;
function getDailyTimes($month, $day, $year, $id, $proj_id) {
include("table_names.inc");
list($qhq, $numq) = dbQuery("select timeformat from $CONFIG_TABLE where config_set_id = '1'");
$configData = dbResult($qhq);
$query = "select date_format(start_time,'%d') as day_of_month, trans_num, ";
if ($configData["timeformat"] == "12")
$query .= "date_format(end_time, '%l:%i%p') as endd, date_format(start_time, '%l:%i%p') as start, ";
else
$query .= "date_format(end_time, '%k:%i') as endd, date_format(start_time, '%k:%i') as start, ";
$query .= "unix_timestamp(end_time) - unix_timestamp(start_time) as diff_sec, " .
"unix_timestamp(start_time) as start_time, " .
"unix_timestamp(end_time) as end_time, " .
"end_time as end_time_str, " .
"start_time as start_time_str, ".
"$PROJECT_TABLE.title as project_title, " .
"$TASK_TABLE.name, $TIMES_TABLE.proj_id, $TIMES_TABLE.task_id " .
"FROM $TIMES_TABLE, $TASK_TABLE, $PROJECT_TABLE " .
"WHERE $TASK_TABLE.proj_id=$PROJECT_TABLE.proj_id AND " .
"uid='$id' AND ";
$query .= "$TASK_TABLE.task_id = $TIMES_TABLE.task_id AND " .
"((start_time >= '$year-$month-$day 00:00:00' AND start_time <= '$year-$month-$day 23:59:59') " .
" OR (end_time >= '$year-$month-$day 00:00:00' AND end_time <= '$year-$month-$day 23:59:59') " .
" OR (start_time < '$year-$month-$day 00:00:00' AND end_time > '$year-$month-$day 23:59:59')) " .
" order by day_of_month, start_time";
list($my_qh, $num) = dbQuery($query);
return array($num, $my_qh);
}
//include date input classes
include "form_input.inc";
list($num, $qh) = getDailyTimes($month, $day, $year, $contextUser, $proj_id);
?>
<html>
<head>
<title>Update timesheet for <? echo $contextUser; ?></title>
<?
include("header.inc");
include("client_proj_task_javascript.inc");
?>
<script language="Javascript">
function delete_entry(transNum) {
if (confirm('Are you sure you want to delete this time entry?'))
location.href = 'delete.php?client_id=<?php echo $client_id; ?>&proj_id=<?php echo $proj_id; ?>&task_id=<?php echo $task_id; ?>&trans_num=' + transNum;
}
</script>
</HEAD>
<BODY <? include ("body.inc"); ?> onload="doOnLoad();">
<?
include ("banner.inc");
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" class="face_padding_cell">
<!-- include the timesheet face up until the heading start section -->
<? include("timesheet_face_part_1.inc"); ?>
<table width="100%" border="0">
<tr>
<td align="left" nowrap class="outer_table_heading" nowrap>
Daily Timesheet
</td>
<td align="left" nowrap class="outer_table_heading">
<? echo strftime("%A %B %d, %Y", mktime(0,0,0,$month, $day, $year)); ?>
</td>
<td align="right" nowrap>
<a href="<? echo $_SERVER["PHP_SELF"]; ?>?month=<? echo date("m",$yesterday); ?>&year=<? echo date("Y",$yesterday); ?>&day=<? echo date("d",$yesterday); ?>&proj_id=<? echo $proj_id; ?>" class="outer_table_action">Prev</a>
<a href="<? echo $_SERVER["PHP_SELF"]; ?>?month=<? echo date("m",$tomorrow); ?>&year=<? echo date("Y",$tomorrow); ?>&day=<? echo date("d",$tomorrow); ?>&proj_id=<? echo $proj_id; ?>" class="outer_table_action">Next</a>
</td>
</tr>
</table>
<!-- include the timesheet face up until the heading start section -->
<? include("timesheet_face_part_2.inc"); ?>
<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" class="outer_table">
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_body">
<tr class="inner_table_head">
<td class="inner_table_column_heading" align="center">Project</td>
<td class="inner_table_column_heading" align="center">Task</td>
<td class="inner_table_column_heading" align="center">Start</td>
<td class="inner_table_column_heading" align="center">End</td>
<td class="inner_table_column_heading" align="center">Total</td>
<td class="inner_table_column_heading" align="center"><i>Actions</i></td>
</tr>
<?
if ($num == 0) {
print " <tr>\n";
print " <td class=\"calendar_cell_middle\"><i>No hours recorded.</i></td>\n";
print " <td class=\"calendar_cell_middle\"> </td>\n";
print " <td class=\"calendar_cell_middle\"> </td>\n";
print " <td class=\"calendar_cell_middle\"> </td>\n";
print " <td class=\"calendar_cell_middle\"> </td>\n";
print " <td class=\"calendar_cell_disabled_right\"> </td>\n";
print " </tr>\n";
print "</table>\n";
}
else {
$last_task_id = -1;
$today_total_sec = 0;
$total_diff_sec = 0;
while ($data = dbResult($qh)) {
//Due to an inconsistency with mysql and php with converting to unix timestamp from the string,
//we are going to use php's strtotime to make the timestamp from the string.
//the problem has something to do with timezones.
$data["start_time"] = strtotime($data["start_time_str"]);
$data["end_time"] = strtotime($data["end_time_str"]);
//get the project title and task name
$projectTitle = stripslashes($data["project_title"]);
$taskName = stripslashes($data["name"]);
//start printing details of the task
print "<tr>\n";
print "<td class=\"calendar_cell_middle\"><a href=\"javascript:void(0)\" onclick=\"javascript:window.open('proj_info.php?proj_id=$data[proj_id]','Project Info','location=0,directories=no,status=no,scrollbar=yes,menubar=no,resizable=1,width=500,height=200')\">$projectTitle</a></td>\n";
print "<td class=\"calendar_cell_middle\"><a href=\"javascript:void(0)\" onclick=\"javascript:window.open('task_info.php?task_id=$data[task_id]','Task Info','location=0,directories=no,status=no,scrollbar=yes,menubar=no,resizable=1,width=300,height=150')\">$taskName</a></td>\n";
if ($data["diff_sec"] > 0) {
//if both start and end time are not today
if ($data["start_time"] < mktime(0,0,0,$month,$day,$year) &&
$data["end_time"] > mktime(23,59,59,$month,$day,$year))
{
$today_diff_sec = 24*60*60; //all day - no one should work this hard!
echo "<td class=\"calendar_cell_middle\" align=\"right\"><font color=\"#909090\"><i>" . $data["start"] . "," .
"<a href=\"daily.php?month=" . date("m",$data["start_time"]) .
"&year=" . date("Y",$data["start_time"]) .
"&day=" . date("d",$data["start_time"]) .
"&proj_id=$proj_id\"><i>" . date("d-M",$data["start_time"]) .
"</a></i></font>" .
"</td>" .
"<td class=\"calendar_cell_middle\" align=\"right\"><font color=\"#909090\"><i>" . $data["endd"] . "," .
"<a href=\"daily.php?month=" . date("m",$data["end_time"]) .
"&year=" . date("Y",$data["end_time"]) .
"&day=" . date("d",$data["end_time"]) .
"&proj_id=$proj_id\"><i>" . date("d-M",$data["end_time"]) .
"</a></i></font>" .
"</td>" .
"<td class=\"calendar_cell_middle\" align=\"right\">" . formatSeconds($today_diff_sec). "<font color=\"#909090\"><i> of " .
formatSeconds($data["diff_sec"]) . "</i></font></TD>\n";
}
//if end time is not today
elseif ($data["end_time"] > mktime(23,59,59,$month,$day,$year)) {
$today_diff_sec = mktime(0,0,0, $month,$day,$year) + 24*60*60 - $data["start_time"];
echo "<td class=\"calendar_cell_middle\" align=\"right\">" . $data["start"] . "</td>" .
"<td class=\"calendar_cell_middle\" align=\"right\"><font color=\"#909090\"><i>" . $data["endd"] . "," .
"<a href=\"daily.php?month=" . date("m",$data["end_time"]) .
"&year=" . date("Y",$data["end_time"]) .
"&day=" . date("d",$data["end_time"]) .
"&proj_id=$proj_id\"><i>" . date("d-M",$data["end_time"]) .
"</a></i></font>" .
"</td>" .
"<td class=\"calendar_cell_middle\" align=\"right\">" . formatSeconds($today_diff_sec). "<font color=\"#909090\"><i> of " . formatSeconds($data["diff_sec"]) . "</i></font></td>\n";
}
//elseif start time is not today
elseif ($data["start_time"] < mktime(0,0,0,$month,$day,$year)) {
$today_diff_sec = $data["end_time"] - mktime(0,0,0, $month,$day,$year);
echo "<td class=\"calendar_cell_middle\" align=\"right\"><font color=\"#909090\"><i>" . $data["start"] . "," .
"<a href=\"daily.php?month=" . date("m",$data["start_time"]) .
"&year=" . date("Y",$data["start_time"]) .
"&day=" . date("d",$data["start_time"]) .
"&proj_id=$proj_id\"><i>" . date("d-M",$data["start_time"]) .
"</a></i></font>" .
"</td>" .
"<td class=\"calendar_cell_middle\" align=\"right\">" . $data["endd"] . "</td>" .
"<td class=\"calendar_cell_middle\" align=\"right\">" . formatSeconds($today_diff_sec). "<font color=\"#909090\"><i> of " .
formatSeconds($data["diff_sec"]) . "</i></font></td>\n";
}
else {
$today_diff_sec = $data["diff_sec"];
print "<td class=\"calendar_cell_middle\" align=\"right\">$data[start]</td>\n";
print "<td class=\"calendar_cell_middle\" align=\"right\">$data[endd]</td>\n";
print "<td class=\"calendar_cell_middle\" align=\"right\">" . formatSeconds($data["diff_sec"]) . "</td>\n";
}
print "<td class=\"calendar_cell_disabled_right\" align=\"right\">\n";
print " <a href=\"edit.php?client_id=$client_id&proj_id=$proj_id&task_id=$task_id&trans_num=$data[trans_num]&year=$year&month=$month&day=$day\" class=\"action_link\">Details</a>, \n";
//print " <a href=\"delete.php?client_id=$client_id&proj_id=$proj_id&task_id=$task_id&trans_num=$data[trans_num]\" class=\"action_link\">Delete</a>\n";
print " <a href=\"javascript:delete_entry($data[trans_num]);\" class=\"action_link\">Delete</a>\n";
print "</td>";
//add to todays total
$today_total_sec += $today_diff_sec;
}
else {
print "<td class=\"calendar_cell_middle\" align=\"right\">$data[start]</td>\n";
print "<td class=\"calendar_cell_middle\" align=\"right\"> </td>\n";
print "<td class=\"calendar_cell_middle\" align=\"right\"> </td>\n";
print "<td class=\"calendar_cell_disabled_right\" align=\"right\">\n";
print " <a href=\"javascript:delete_entry($data[trans_num]);\" class=\"action_link\">Delete</a>\n";
print "</td>";
}
print "</tr>";
}
print "<tr>\n";
print " <td class=\"calendar_totals_line_weekly_right\" colspan=\"5\" align=\"right\">";
print " Daily Total: <span class=\"calendar_total_value_weekly\">" . formatSeconds($today_total_sec) . "</span></td>\n";
print " <td class=\"calendar_cell_disabled_right\" align=\"right\"> </td>\n";
print "</tr>\n";
print "</table>";
}
?>
</td>
</tr>
</table>
<!-- include the timesheet face up until the end -->
<? include("timesheet_face_part_3.inc"); ?>
</td>
</tr>
</table>
<table width="436" align="center" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" class="face_padding_cell">
<!-- include the timesheet face up until the heading start section -->
<? include("timesheet_face_part_1.inc"); ?>
<table width="100%" border="0">
<tr>
<td align="left" nowrap class="outer_table_heading" nowrap>
Clock On / Off
</td>
</tr>
</table>
<!-- include the timesheet face up until the next start section -->
<? include("timesheet_face_part_2.inc"); ?>
<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" class="outer_table">
<form action="action.php" method="post" name="addForm" id="theForm">
<input type="hidden" name="destination" value="daily">
<input type="hidden" name="year" value="<?echo $year; ?>">
<input type="hidden" name="month" value="<?echo $month; ?>">
<input type="hidden" name="day" value="<?echo $day; ?>">
<input type="hidden" id="client_id" name="client_id" value="<?echo $client_id; ?>">
<input type="hidden" id="proj_id" name="proj_id" value="<?echo $proj_id; ?>">
<input type="hidden" id="task_id" name="task_id" value="<?echo $task_id; ?>">
<input type="hidden" name="origin" value="<? echo $_SERVER["PHP_SELF"]; ?>">
<input type="hidden" name="destination" value="<? echo $_SERVER["PHP_SELF"]; ?>">
<tr>
<td>
<table width="100%" border="0" cellpadding="1" cellspacing="2" class="table_body">
<tr>
<td>
<table width="100%" border="0">
<tr>
<td align="left" width="100%" nowrap>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="50"><tr><td>Client:</td></tr></table></td>
<td width="100%">
<select id="clientSelect" name="clientSelect" onChange="onChangeClientSelect();" style="width: 100%;" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="left" width="100%" nowrap>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="50"><tr><td>Project:</td></tr></table></td>
<td width="100%">
<select id="projectSelect" name="projectSelect" onChange="onChangeProjectSelect();" style="width: 100%;" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="left" width="100%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="50"><tr><td>Task:</td></tr></table></td>
<td width="100%">
<select id="taskSelect" name="taskSelect" onChange="onChangeTaskSelect();" style="width: 100%;" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0">
<tr>
<td align="center">
<table width="300" border="0" class="clock_on_box">
<tr>
<td valign="top" align="left" class="clock_on_text">
<input type="checkbox" name="clock_on_check" id="clock_on_check" onclick="enableClockOn();">Clock on at:
</td>
<td valign="middle">
<? // If the current day is today:
if (($year == date('Y')) && ($month == date('m')) && ($day == date('j'))): ?>
<input type="radio" name="clock_on_radio" value="date" id="clock_on_radio_date" onclick="enableClockOn();" checked>
<? endif; ?>
<? $hourInput = new HourInput("clock_on_time_hour");
$hourInput->create(10); ?>
:
<? $minuteInput = new MinuteInput("clock_on_time_min");
$minuteInput->create(); ?>
</td>
<td>
<img src="images/clock-green-sml.gif" border="0">
</td>
</tr>
<? // If the current day is today:
if (($year == date('Y')) && ($month == date('m')) && ($day == date('j'))): ?>
<tr>
<td> </td>
<td valign="middle" align="left" class="clock_on_text">
<input type="radio" name="clock_on_radio" value="now" id="clock_on_radio_now" onclick="enableClockOn();"> now
</td>
<td> </td>
</tr>
<? endif; ?>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="300" border="0" class="clock_off_box">
<tr>
<td valign="top" align="left" class="clock_off_text">
<input type="checkbox" name="clock_off_check" id="clock_off_check" onclick="enableClockOff();">Clock off at:
</td>
<td valign="middle">
<? // If the current day is today:
if (($year == date('Y')) && ($month == date('m')) && ($day == date('j'))): ?>
<input type="radio" name="clock_off_radio" id="clock_off_radio_date" value="date" onclick="enableClockOff();">
<? endif; ?>
<? $hourInput = new HourInput("clock_off_time_hour");
$hourInput->create(17); ?>
:
<? $minuteInput = new MinuteInput("clock_off_time_min");
$minuteInput->create(); ?>
</td>
<td>
<img src="images/clock-red-sml.gif" border="0">
</td>
</tr>
<? // If the current day is today:
if (($year == date('Y')) && ($month == date('m')) && ($day == date('j'))): ?>
<tr>
<td> </td>
<td valign="middle" align="left" class="clock_off_text">
<input type="radio" name="clock_off_radio" id="clock_off_radio_now" value="now" onclick="enableClockOff();" checked>now
</td>
<td> </td>
</tr>
<? endif; ?>
</table>
</td>
</tr>
<tr>
<td align="center">
<input type="button" value="Clock on and/or off" name="submitButton" id="submitButton" onClick="onSubmit();">
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<!-- include the timesheet face up until the end -->
<? include("timesheet_face_part_3.inc"); ?>
</td>
</tr>
</table>
<?
include ("footer.inc");
?>
</BODY>
</HTML>