-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdosql.php
More file actions
140 lines (118 loc) · 4.76 KB
/
dosql.php
File metadata and controls
140 lines (118 loc) · 4.76 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
<?php
$del = isset($_POST['del']) ? $_POST['del'] : 0;
$punchIn = isset($_POST['punchin']) ? 1 : 0;
$punchOut = isset($_POST['punchout']) ? 1 : 0;
$break = isset($_POST['break']) ? 1 : 0;
$update = isset($_POST['update']) ? 1 : 0;
$this_post = Array();
$timesheet_id = $_POST['timesheet_id'];
$timesheet_date = $_POST['timesheet_date'];
$timesheet_time_in = $_POST['timesheet_time_in'];
$timesheet_time_out = $_POST['timesheet_time_out'];
$timesheet_time_break = $_POST['timesheet_time_break'];
if ($punchIn) {
$timesheet = new Timesheet();
$sql = "SELECT * from timesheet where user_id = $AppUI->user_id and timesheet_date = '" . $_POST['timesheet_date'] . "'";
if (!db_loadObject($sql, $timesheet)) { // timesheet doesn't exist yet. Create it.
$timesheet->timesheet_id = "";
$timesheet->user_id = $AppUI->user_id;
$timesheet->timesheet_date = $_POST['timesheet_date'];
if (($msg = $timesheet->store())) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
$AppUI->redirect();
}
}
// set time_in
$curTime = new CDate();
$timesheet->timesheet_time_in = $curTime->format("%H:%M");
if (($msg = $timesheet->store())) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
} else {
$AppUI->setMsg( "Punched in at " . $curTime->format("%H:%M"), UI_MSG_OK );
}
} else if ($punchOut) {
$timesheet = new Timesheet();
$sql = "SELECT * from timesheet where user_id = $AppUI->user_id and timesheet_date = '" . $_POST['timesheet_date'] . "'";
if (!db_loadObject($sql, $timesheet)) { // timesheet doesn't exist yet. Create it.
$timesheet->timesheet_id = "";
$timesheet->user_id = $AppUI->user_id;
$timesheet->timesheet_date = $_POST['timesheet_date'];
if (($msg = $timesheet->store())) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
$AppUI->redirect();
}
}
// set time_out
$curTime = new CDate();
$timesheet->timesheet_time_out = $curTime->format("%H:%M");
if (($msg = $timesheet->store())) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
} else {
$AppUI->setMsg( "Punched out at " . $curTime->format("%H:%M"), UI_MSG_OK );
}
} else if ($break) {
$timesheet = new Timesheet();
$sql = "SELECT * from timesheet where user_id = $AppUI->user_id and timesheet_date = '" . $_POST['timesheet_date'] . "'";
if (!db_loadObject($sql, $timesheet)) { // timesheet doesn't exist yet. Create it.
$timesheet->timesheet_id = "";
$timesheet->user_id = $AppUI->user_id;
$timesheet->timesheet_date = $_POST['timesheet_date'];
if (($msg = $timesheet->store())) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
$AppUI->redirect();
}
}
// set current time
$curTime = new CDate();
if ($_POST['break'] == 'Back for more Fun') {
$myMsg = "Break ended on " . $curTime->format("%H:%M");
// calculate break time
$prevBreak = new CDate('0000-00-00 ' . $timesheet->timesheet_time_break);
$startTime = new CDate('0000-00-00 ' . $timesheet->timesheet_time_break_start);
$curTime->addSeconds($prevBreak->hour * 60 * 60 + $prevBreak->minute * 60);
$curTime->subtractSeconds($startTime->hour * 60 * 60 + $startTime->minute * 60);
// set time_break_start
$timesheet->timesheet_time_break = $curTime->format("%H:%M");
// reset time_break_start
$timesheet->timesheet_time_break_start = '00:00:00';
} else {
// set time_break_start
$timesheet->timesheet_time_break_start = $curTime->format("%H:%M");
}
if (($msg = $timesheet->store())) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
} else {
$AppUI->setMsg( ($myMsg ? $myMsg : "Break started on " . $curTime->format("%H:%M")), UI_MSG_OK );
}
} else if ($update) {
for ($i = 0; $i < count($_POST['timesheet_id']); $i++) {
$timesheet = new Timesheet();
list(, $this_post['timesheet_id']) = each($timesheet_id);
list(, $this_post['timesheet_date']) = each($timesheet_date);
list(, $this_post['timesheet_time_in']) = each($timesheet_time_in);
list(, $this_post['timesheet_time_out']) = each($timesheet_time_out);
list(, $this_post['timesheet_time_break']) = each($timesheet_time_break);
$this_post['user_id'] = $AppUI->user_id;
if (($this_post['timesheet_id']) or ($this_post['timesheet_time_in'] or $this_post['timesheet_time_out'] or $this_post['timesheet_time_break'])) {
/*
print "timesheet_id = " . $this_post["timesheet_id"] . "<br>";
print "time_in = " . $this_post["timesheet_time_in"] . "<br>";
print "time_out = " . $this_post["timesheet_time_out"] . "<br>";
print "time_break = " . $this_post["timesheet_time_break"] . "<br>";
print "<BR>";
*/
if (($msg = $timesheet->bind( $this_post ))) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
$AppUI->redirect();
}
// $isNotNew = @$this_post['timesheet_id'];
if (($msg = $timesheet->store())) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
$AppUI->redirect();
}
}
}
$AppUI->setMsg( "Timesheet entries updated", UI_MSG_OK );
}
$AppUI->redirect();
?>