-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindividual_hours_log.php
269 lines (243 loc) · 13.3 KB
/
individual_hours_log.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
<?php
require_once('Connections/YBDB.php');
require_once('Connections/database_functions.php');
$page_edit_contact = PAGE_EDIT_CONTACT;
mysql_select_db($database_YBDB, $YBDB);
if($_GET['visit_id']>0){
$visit_id = $_GET['visit_id'];
} else {
$visit_id =-1;}
if($_GET['new_user_id']>0){
$new_user_id = $_GET['new_user_id'];
} else {
$new_user_id = -1;
}
//shop_date
if(ISSET($_GET['shop_date'])){
$shop_date_filter = $_GET['shop_date'];
} else {
$shop_date_filter = current_date();}
//dayname
if($_GET['shop_dayname']=='alldays'){
$shop_dayname = '';
} elseif(isset($_GET['shop_dayname'])) {
$shop_dayname = "AND DAYNAME(DATE(time_in)) = '" . $_GET['shop_dayname'] . "'";
} else {
$shop_dayname = '';
}
//record_count
if($_GET['record_count']>0){
$record_count = $_GET['record_count'];
} else {
$record_count = 10;}
$individual_shop_id = 90;
$query_Recordset1 = "SELECT shop_hours.shop_visit_id, shop_hours.contact_id, shop_hours.shop_user_role, shop_hours.project_id, DATE(shop_hours.time_in) AS date, shop_hours.time_in, shop_hours.time_out, TIME_FORMAT(TIMEDIFF(time_out, time_in),'%k:%i') as et, shop_hours.comment, CONCAT(contacts.last_name, ', ', contacts.first_name, ' ',contacts.middle_initial) AS full_name, contacts.first_name FROM shop_hours
LEFT JOIN shop_user_roles ON shop_hours.shop_user_role=shop_user_roles.shop_user_role_id
LEFT JOIN contacts ON shop_hours.contact_id=contacts.contact_id
WHERE shop_hours.shop_id = 90 AND DATE(shop_hours.time_in) <= '{$shop_date_filter}' {$shop_dayname} ORDER BY time_in DESC
LIMIT 0, {$record_count};";
$Recordset1 = mysql_query($query_Recordset1, $YBDB) or die(mysql_error());
//$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
mysql_select_db($database_YBDB, $YBDB);
$query_Recordset2 = "SELECT * FROM shops WHERE shop_id = $individual_shop_id;";
$Recordset2 = mysql_query($query_Recordset2, $YBDB) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
$shop_date = $row_Recordset2['date'];
$shop_location = $row_Recordset2['shop_location'];
$shop_type = $row_Recordset2['shop_type'];
//sets the default time for users to sign in
$shop_start_time = current_datetime();
$current_date = current_date();
//Action on form update
//shop_log2.php?shop_id=2&visit_id=4
$editFormAction = $_SERVER['PHP_SELF'] . "?shop_id=$individual_shop_id&visit_id=$visit_id";
$editFormAction_novisit = $_SERVER['PHP_SELF'] . "?shop_id=$individual_shop_id";
//if (isset($_SERVER['QUERY_STRING'])) {
// $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
//}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form_new") && ($_POST["contact_id"] == "no_selection")){
//if no contact is selected
$error_message = '<span class="yb_heading3red">Please Select a User</span><br />';
} elseif ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form_new")) {
$insertSQL = sprintf("INSERT INTO shop_hours (contact_id, shop_id, shop_user_role, time_in, comment, project_id) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['contact_id'], "int"),
GetSQLValueString($individual_shop_id, "int"),
GetSQLValueString($_POST['user_role'], "text"),
GetSQLValueString(dateandtimein($_POST['date'], $_POST['time_in']), "date"),
GetSQLValueString($_POST['comment'], "text"),
GetSQLValueString($_POST['project'], "text"));
mysql_select_db($database_YBDB, $YBDB);
$Result1 = mysql_query($insertSQL, $YBDB) or die(mysql_error());
$insertGoTo = "shop_log2.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $editFormAction_novisit));
}
//$_POST["MM_insert"] is in the form: FormUpdate_$VisitID OR FormUpdate_142. This line seperates the visit id from the
//list($is_UpdateForm, $visit_id) = split('[_]', $_POST["MM_insert"]);
//Update Record isset($_POST["MM_update"])
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "FormUpdate")) {
$updateSQL = sprintf("UPDATE shop_hours SET time_out=%s WHERE shop_visit_id=%s",
GetSQLValueString($_POST['time_out'], "date"),
GetSQLValueString($_POST['shop_visit_id'], "int"));
//"2006-10-12 18:15:00"
mysql_select_db($database_YBDB, $YBDB);
$Result1 = mysql_query($updateSQL, $YBDB) or die(mysql_error());
$gotopage = "index.html";
header(sprintf("Location: %s",$editFormAction )); //$editFormAction
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "FormEdit")) {
$updateSQL = sprintf("UPDATE shop_hours SET contact_id=%s, shop_user_role=%s, project_id=%s, time_in=%s, time_out=%s, comment=%s WHERE shop_visit_id=%s",
GetSQLValueString($_POST['contact_id'], "int"),
GetSQLValueString($_POST['user_role'], "text"),
GetSQLValueString($_POST['project'], "text"),
GetSQLValueString(dateandtimein($_POST['date'], $_POST['time_in']), "date"),
GetSQLValueString($_POST['time_out'], "date"),
GetSQLValueString($_POST['comment'], "text"),
GetSQLValueString($_POST['shop_visit_id'], "int"));
//"2006-10-12 18:15:00"
mysql_select_db($database_YBDB, $YBDB);
$Result1 = mysql_query($updateSQL, $YBDB) or die(mysql_error());
header(sprintf("Location: %s",$editFormAction_novisit )); //$editFormAction
}
//Change Date isset($_POST["MM_update"])
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ChangeDate")) {
$editFormAction = $_SERVER['PHP_SELF'] . "?shop_date={$_POST['shop_date']}&shop_dayname={$_POST['dayname']}&record_count={$_POST['record_count']}";
header(sprintf("Location: %s",$editFormAction )); //$editFormAction
}
?>
<?php include("include_header.html"); ?>
<table border="0" cellpadding="1" cellspacing="0">
<tr>
<td align="left" valign="bottom"><?php echo $error_message;?>
Shop ID: <span class="yb_standarditalics"><?php echo $individual_shop_id;?></span>; Location: <span class="yb_standarditalics"><?php echo $shop_location;?></span>; Date: <span class="yb_standarditalics"><?php echo $shop_date;?></span>; Shop Type: <span class="yb_standarditalics"><?php echo $shop_type;?></span> </td>
</tr>
<tr>
<td>
<table border="1" cellpadding="1" cellspacing="0" bordercolor="#CCCCCC">
<tr bordercolor="#CCCCCC" bgcolor="#99CC33" class="yb_heading3">
<td height="35">Shop User </td>
<td>Date</td>
<td height="35">Status</td>
<td height="35">Time In </td>
<td height="35" bgcolor="#99CC33">Time Out </td>
<td height="35">Update Hours </td>
<td height="35">Edit Data </td>
</tr>
<form method="post" name="form_new" action="<?php echo $editFormAction; ?>">
<tr bordercolor="#CCCCCC">
<td height="40" valign="bottom"><strong>New User:</strong><br>
<span class="yb_standard_small"> Not in the list: Create <a href="<?php echo $page_edit_contact; ?>?contact_id=new_contact&shop_id=<?php echo $individual_shop_id?>">New User</a></span>
<?php list_contacts_select_user('contact_id', $new_user_id); ?></td>
<td valign="bottom"><input name="date" type="text" value="<?php echo current_date(); ?>" size="10" maxlength="10" /></td>
<td valign="bottom"><strong>
<?php list_shop_user_roles('user_role','Volunteer'); ?>
</strong></td>
<td valign="bottom"><strong>
<?php list_time("{$current_date} 08:00:00",'0000-00-00 00:00:00','time_in',-15, 0, 'none',16); ?>
</strong></td>
<td valign="bottom"><img src="150_10.jpg" width="150" height="10" /></td>
<td valign="bottom"><input name="Submit" type="submit" value="Sign In" /></td>
<td valign="bottom"> </td>
</tr>
<tr valign="bottom" bordercolor="#CCCCCC">
<td height="25" colspan="7" bordercolor="#CCCCCC">
<table border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="125"><div align="right">Project:</div></td>
<td><?php list_projects_collective('project'); ?></td>
</tr>
<tr>
<td><div align="right">Work Description :</div></td>
<td><input name="comment" type="text" value="<?php echo $row_Recordset1['comment']; ?>" size="90" /></td>
</tr>
</table> </td>
</tr>
<input type="hidden" name="MM_insert" value="form_new">
</form>
<tr valign="bottom" bordercolor="#CCCCCC" bgcolor="#99CC33">
<td height="25" colspan="7" bgcolor="#99CC33"> Existing Shop Users:</td>
</tr>
<?php while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)) { //do {
if($visit_id == $row_Recordset1['shop_visit_id']) {?>
<form method="post" name="FormUpdate_<?php echo $row_Recordset1['shop_visit_id']; ?>" action="<?php echo $editFormAction; ?>">
<tr valign="bottom" bordercolor="#CCCCCC" bgcolor="#CCCC33">
<td>Edit Record: <br>
<?php list_contacts('contact_id', $row_Recordset1['contact_id']); ?></td>
<td><input name="date" type="text" value="<?php echo $row_Recordset1['date']; ?>" size="10" maxlength="10" /></td>
<td><?php list_shop_user_roles('user_role', $row_Recordset1['shop_user_role']); ?></td>
<td><?php list_time("{$current_date} 08:00:00",'0000-00-00 00:00:00','time_in',-60,0,$row_Recordset1['time_in'],16); ?></td>
<td><?php
if ($row_Recordset1['time_out'] <> '0000-00-00 00:00:00'){
list_time($row_Recordset1['time_in'],$row_Recordset1['time_out'],'time_out',0,1,$row_Recordset1['time_out']);
} ?></td>
<td><input type="submit" name="Submit" value="Update Changes" /></td>
<td></td>
</tr>
<tr bordercolor="#CCCCCC" bgcolor="#CCCC33">
<td colspan="7"><table border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="125"><div align="right">Project:</div></td>
<td><?php list_projects_collective('project', $row_Recordset1['project_id']); ?></td>
</tr>
<tr>
<td><div align="right">Comment:</div></td>
<td><input name="comment" type="text" value="<?php echo $row_Recordset1['comment']; ?>" size="90" /></td>
</tr>
<tr>
<td><div align="right">Delete:</div></td>
<td>Click to Delete this Shop User's Visit: <a href="<?php echo PAGE_SHOP_LOG_DELETE_VISIT . "?visit_id={$visit_id}&shop_id={$individual_shop_id}";?>">Delete</a> </td>
</tr>
</table> </td>
</tr>
<input type="hidden" name="MM_insert" value="FormEdit">
<input type="hidden" name="shop_visit_id" value="<?php echo $row_Recordset1['shop_visit_id']; ?>">
</form>
<?php } else { //This section executes if it is not the visit_id selected NOT FOR EDIT ?>
<form method="post" name="FormUpdate_<?php echo $row_Recordset1['shop_visit_id']; ?>" action="<?php echo $editFormAction; ?>">
<tr bordercolor="#CCCCCC">
<td><?php echo $row_Recordset1['full_name']; ?></td>
<td><?php echo $row_Recordset1['date']; ?></td>
<td><?php echo $row_Recordset1['shop_user_role']; ?></td>
<td><?php echo date_to_time($row_Recordset1['time_in']); ?></td>
<td><?php echo list_time($row_Recordset1['time_in'],$row_Recordset1['time_out'],'time_out',0,1,'none', 8,$row_Recordset1['et']); ?></td>
<td><?php sign_out($row_Recordset1['time_out'], $row_Recordset1['first_name']); ?></td>
<td><?php echo "<a href=\"{$_SERVER['PHP_SELF']}?shop_id={$individual_shop_id}&visit_id={$row_Recordset1['shop_visit_id']}\">edit</a>"; ?></td>
</tr>
<input type="hidden" name="MM_insert" value="FormUpdate">
<input type="hidden" name="shop_visit_id" value="<?php echo $row_Recordset1['shop_visit_id']; ?>">
</form>
<?php } // if
} //while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); // while Recordset1 ?>
</table> </tr>
</table>
<form id="form1" name="form1" method="post" action="">
<br />
Show
<input name="record_count" type="text" value="10" size="3" maxlength="3" />
shops on or before:
<input name="shop_date" type="text" id="shop_date" value="<?php echo current_date(); ?>" size="10" maxlength="10" />
Day of week:
<select name="dayname">
<option value="alldays" selected="selected">All Days</option>
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="Saturday">Saturday</option>
<option value="Sunday">Sunday</option>
</select>
<input type="submit" name="Submit" value="Submit" />
(date format YYYY-MM-DD)
<input type="hidden" name="MM_insert" value="ChangeDate" />
</form>
<p> </p>
<?php include("include_footer.html"); ?>
<?php
mysql_free_result($Recordset1);
?>