-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhours.php
254 lines (233 loc) · 13.3 KB
/
hours.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
<?php include 'begin.php'; ?>
<?php $page_name = 'Hours'; ?>
<?
if (isset($_GET['action'])){
if (($_GET['action'] == 'clockin') && isset($_POST['clockin-form-userid'])){
mysql_query("INSERT INTO hours (userid, start, end) VALUES ('".$_POST['clockin-form-userid']."', now(), '0')");
}else if ($_GET['action'] == 'clockout'){
mysql_query("UPDATE hours SET end = now() WHERE id = '".$_GET['clockoutid']."'");
}
}
$allUsers = false;
$fulltimeUsers = false;
if (isset($_GET['action']) && $_GET['action'] == 'date-range'){
if ($_GET['date-range-form-user'] == "all"){
//select all users with total hours column
$allUsers = true;
if ($_GET['date-range-form-dates'] == "all"){
$result_hours_list = mysql_query("SELECT users.id AS id, email, SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(end,start)))) AS total FROM hours, users WHERE users.id = hours.userid GROUP BY email ORDER BY email");
}else{
//date range
$date_range_dates = explode("^", $_GET['date-range-form-dates']);
$result_hours_list = mysql_query("SELECT users.id AS id, email, SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(end,start)))) AS total FROM hours, users WHERE users.id = hours.userid AND start>='".$date_range_dates[0]."' AND end<'".$date_range_dates[1]."' GROUP BY email ORDER BY email");
$result_user_email = mysql_query("SELECT * FROM users WHERE id='".$_GET['date-range-form-user']."'");
$row_user_email = mysql_fetch_array( $result_user_email );
$begindate = $date_range_dates[0];
$fulltimeUsers = true;
//people have vacation within the selected dates
$query_vacation_people = "SELECT users.id FROM users, requests WHERE hours<0 AND status='ok' AND users.hourly = 0 AND users.id = requests.userid AND datebegin>='".$date_range_dates[0]."' AND (dateend<='".$date_range_dates[1]."' OR dateend='0000-00-00') GROUP BY id";
//total hours
//$query_fulltime_total = "SELECT users.id AS id, email, SUM(hours) AS total FROM users,requests WHERE users.id = requests.userid AND users.id IN(".$query_vacation_people.") AND datebegin<='".$date_range_dates[1]."' AND (dateend<='".$date_range_dates[1]."' OR dateend='0000-00-00') GROUP BY email ORDER BY email ASC";
$query_fulltime_total = "SELECT users.id AS id, email, SUM(hours) AS total FROM users,requests WHERE users.id = requests.userid AND users.id IN(".$query_vacation_people.") AND datebegin>='2012-01-01' AND datebegin<='".$date_range_dates[1]."' AND (dateend<='".$date_range_dates[1]."' OR dateend='0000-00-00') GROUP BY email ORDER BY email ASC";
$query_fulltime_list = "SELECT email, SUM(hours) AS total FROM users,requests WHERE users.id = requests.userid AND users.id IN(".$query_vacation_people.") AND datebegin>='".$date_range_dates[0]."' AND (dateend<='".$date_range_dates[1]."' OR dateend='0000-00-00') GROUP BY email ORDER BY email ASC";
$result_fulltime_total = mysql_query($query_fulltime_total);
$result_fulltime_list = mysql_query($query_fulltime_list);
/*
echo $query_vacation_people.'<br><br>';
echo $query_fulltime_total.'<br><br>';
echo $query_fulltime_list.'<br><br>';
*/
}
}else{
if ($_GET['date-range-form-dates'] == "all"){
$result_hours_list = mysql_query("SELECT id, start,end, TIMEDIFF(end,start) AS total FROM hours WHERE userid = '".$_GET['date-range-form-user']."' ORDER BY start DESC");
}else{
$date_range_dates = explode("^", $_GET['date-range-form-dates']);
$query = "SELECT id, start,end, TIMEDIFF(end,start) AS total FROM hours WHERE userid = '".$_GET['date-range-form-user']."' AND start>='".$date_range_dates[0]."' AND end<'".$date_range_dates[1]."' AND end!='0000-00-00 00:00:00' ORDER BY start ASC";
$result_hours_list = mysql_query($query);
}
}
if (isset($_GET['date-range-form-dates'])){
if (($_GET['date-range-form-dates'] != 'all') && ($_GET['date-range-form-user'] != 'all')){
$begindate = $date_range_dates[0];
$enddate = $date_range_dates[1];
}
}
}else{
$begindate = date( 'Y-m-d', $_SESSION['paydate'] - (60*60*24*14));
$enddate = date( 'Y-m-d', $_SESSION['paydate']);
$thequery = "SELECT id, start,end, TIMEDIFF(end,start) AS total FROM hours WHERE userid = '".$_SESSION['userid']."' AND start>='".$begindate."' AND end<'".$enddate."' ORDER BY start DESC";
$result_hours_list = mysql_query($thequery);
} ?>
<?php include 'inc-page-top.php'; ?>
<div class="content-wide">
<ul id="content-ul" class="flo">
<?php include 'inc-form-date-range.php'; ?>
<li class="content-li">
<div class="drawer">
<ul id="requests_headings" class="requests flo bor">
<li class="h">
<? if ($allUsers) { ?>
<div class="user">
user
</div>
<div class="total">
hours
</div>
<? } else { ?>
<div class="clockin">
IN
</div>
<div class="clockout">
Out
</div>
<div class="total">
Total
</div>
<? } ?>
</li>
</ul>
<ul id="requests" class="admin_requests requests flo bor">
<?
$count = 0;
$daytotal = 0;
if ($allUsers) {
while($row_hours_list = mysql_fetch_array($result_hours_list)){
$count ++;
?>
<li id="edit-item-<? echo $row_hours_list['id']; ?>" class="<? if ($count%2==0)echo' libg '; ?>">
<div class="user">
<?php echo $row_hours_list['email']; ?>
</div>
<div class="total">
<?
echo $row_hours_list['total'];
?>
</div>
</li>
<?
}
}else{
$now = date("Ymd");
$totalseconds = 0;
$currentday = '';
?>
<?
while($row_hours_list = mysql_fetch_array($result_hours_list)){
$count ++;
?>
<?
$thisday = date('l', strtotime ($row_hours_list['start']));
if ($currentday == ''){
$currentday = $thisday;
echo '<li class="dayofweek">';
echo '<h3>'.$thisday." (".date('m/d/Y', strtotime ($row_hours_list['start'])).") ".'</h3>';
echo '<ul>';
}else if ($currentday != $thisday){
$currentday = $thisday;
echo '</ul>';
echo '</li>';
echo '<li class="dayofweek">';
echo '<h3>'.$thisday." (".date('m/d/Y', strtotime ($row_hours_list['start'])).") ".'</h3>';
echo '<ul>';
}
$totalseconds += time_to_sec($row_hours_list['total']);
?>
<li id="edit-item-<? echo $row_hours_list['id']; ?>" class="<? if ($count%2==0)echo' libg '; ?>">
<div class="clockin">
<a href="admin-hours.php?user=<?php echo $_GET['date-range-form-user']; ?>&timeid=<?php echo $row_hours_list['id']; ?>"><?php echo date('g:i:s', strtotime ($row_hours_list['start'])); ?></a>
</div>
<div class="clockout">
<? if($row_hours_list['end'] == '0000-00-00 00:00:00'){ ?>
<a href="hours.php?action=clockout&clockoutid=<? echo $row_hours_list['id']; ?>">Clock Out</a>
<? } else {
echo date('g:i:s', strtotime ($row_hours_list['end']));
} ?>
</div>
<div class="total">
<? echo sec_to_time(time_to_sec($row_hours_list['total']));?>
</div>
<? if (!$allUsers) { ?><div class="running-total"><? echo sec_to_time($totalseconds); ?></div><? } ?>
</li>
<?
}
?>
<?
}
?>
</ul>
<? if ($fulltimeUsers) { ?>
<div style="clear:both; float:left; width:100%; padding-top:30px;">
<h3>Vacation Overages</h3>
<ul id="requests_headings" class="requests flo bor">
<li class="h">
<? if ($allUsers) { ?>
<div class="user">
user
</div>
<div class="status">
Used
</div>
<div class="status">
Total
</div>
<div class="status">
Form
</div>
<? } ?>
</li>
</ul>
<ul id="requests" class="admin_requests requests flo bor">
<?
$count = 0;
if (isset($_GET['date-range-form-dates'])){
$date_range_dates = explode("^", $_GET['date-range-form-dates']);
}
while($row_fulltime_total = mysql_fetch_array($result_fulltime_total)){
$row_fulltime_list = mysql_fetch_array($result_fulltime_list);
$count ++;
if ($row_fulltime_total['email'] == $row_fulltime_list['email']){
?>
<li id="edit-item-<? echo $row_fulltime_total['id']; ?>" class="<? if ($count%2==0)echo' libg '; ?>">
<div class="user"><?php echo $row_fulltime_total['email']; ?></div>
<div class="status"><?php echo $row_fulltime_list['total']; ?></div>
<div class="status"><?php echo $row_fulltime_total['total']; ?></div>
<? if ($row_fulltime_total['total'] < 0){ ?>
<div class="status">
<form name="request_form" id="request_form_<?php echo $row_fulltime_total['id']; ?>" method="post" class="vacation-overage-form">
<input id="requesting_off_date" name="requesting_off_date" type="hidden" value="<?php echo $date_range_dates[1]; ?>">
<input id="requesting_off_user" name="requesting_off_user" type="hidden" value="<?php echo $row_fulltime_total['id']; ?>">
<input id="request_off_area" name="request_off_area" type="hidden" value="<? echo $page_name; ?>" />
<input id="requesting_off_created_by" name="requesting_off_created_by" type="hidden" value="<? echo $_SESSION['userid']; ?>" />
<input id="requesting_off_amount_input" name="requesting_off_amount_input" type="hidden" value="<?php echo $row_fulltime_total['total']*-1; ?>" />
<input type="submit" value="Add <? echo $row_fulltime_total['total']*-1; ?>" />
</form>
<script type="text/javascript">
$(function() {
$('#request_form_<?php echo $row_fulltime_total['id']; ?>').ajaxForm({
url: 'php-request-vacation-overage.php',
resetForm: true // reset the form after successful submit
});
});
</script>
</div>
<? } ?>
</li>
<?
}else{
?>
<li id="edit-item-<? echo $row_fulltime_total['id']; ?>" class="<? if ($count%2==0)echo' libg '; ?>">
<?php echo $row_fulltime_total['email'].' <> '.$row_fulltime_list['email']; ?>
</li>
<?
}
}
?>
</ul>
</div>
<? } ?>
</div>
</li>
</ul>
</div>
<?php include 'inc-page-bottom.php'; ?>