-
Notifications
You must be signed in to change notification settings - Fork 120
/
Employees.php
365 lines (311 loc) · 12.1 KB
/
Employees.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
<?php
/* Defines the employees that require timesheets */
include('includes/session.php');
$Title = _('Employee Maintenance');// Screen identification.
$ViewTopic = 'Labour';// Filename's id in ManualContents.php's TOC.
$BookMark = 'Employees';// Anchor's id in the manual's html document.
include('includes/header.php');
echo '<p class="page_title_text"><img alt="" src="', $RootPath, '/css/', $Theme,
'/images/user.png" title="',// Icon image.
_('Employee'), '" /> ',// Icon title.
_('Employee Maintenance'), '</p>';// Page title.
if(isset($_GET['SelectedEmployee'])) {
$SelectedEmployee = $_GET['SelectedEmployee'];
} elseif(isset($_POST['SelectedEmployee'])) {
$SelectedEmployee = $_POST['SelectedEmployee'];
}
if(isset($_POST['submit'])) {
//initialise no input errors assumed initially before we test
$InputError = 0;
/* actions to take once the user has clicked the submit button
ie the page has called itself with some user input */
if(trim($_POST['Surname']) == '') {
$InputError = 1;
prnMsg(_('The employee\'s surname must not be empty'), 'error');
}
if($_POST['FirstName'] =='') {
$InputError = 1;
prnMsg(_('The employee\'s first name must not be empty'), 'error');
}
//end of checking the input
if(isset($SelectedEmployee) AND $InputError !=1) {
$SQL = "UPDATE employees SET surname='" . $_POST['Surname'] . "',
firstname='" . $_POST['FirstName'] . "',
stockid='" . $_POST['StockID'] . "',
manager='" . $_POST['Manager'] . "',
normalhours='" . $_POST['NormalHours'] . "',
userid='" . $_POST['UserID'] . "',
email='" . $_POST['Email'] . "'
WHERE id = '" . $SelectedEmployee . "'";
$ErrMsg = _('An error occurred updating the') . ' ' . $SelectedEmployee . ' ' . _('employee record because');
$DbgMsg = _('The SQL used to update the employee record was');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg);
prnMsg(_('The employee record has been updated'),'success');
} elseif($InputError !=1) {
/*SelectedEmployee is null cos no employee selected on first time round so must be adding a record must be submitting a new employee form */
$SQL = "INSERT INTO employees ( surname,
firstname,
stockid,
manager,
normalhours,
userid,
email )
VALUES ('" . $_POST['Surname'] . "',
'" . $_POST['FirstName'] . "',
'" . $_POST['StockID'] . "',
'" . $_POST['Manager'] . "',
'" . $_POST['NormalHours'] . "',
'" . $_POST['UserID'] . "',
'" . $_POST['Email'] . "')";
$ErrMsg = _('An error occurred inserting the new employee record because');
$DbgMsg = _('The SQL used to insert the employee record was');
$Result = DB_query($SQL,$ErrMsg,$DbgMsg);
prnMsg(_('The new employee record has been added'),'success');
}
unset($_POST['Surname']);
unset($_POST['FirstName']);
unset($_POST['StockID']);
unset($_POST['Manager']);
unset($_POST['NormalHours']);
unset($_POST['UserID']);
unset($_POST['Email']);
unset($SelectedEmployee);
} elseif(isset($_GET['delete'])) {
//the link to delete a selected record was clicked instead of the submit button
$CancelDelete = 0;
// PREVENT DELETES IF DEPENDENT RECORDS
/* once timesheets are defined
$SQL= "SELECT COUNT(*) FROM timesheets WHERE employeeid='". $SelectedEmployee . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_row($Result);
if($MyRow[0]>0) {
$CancelDelete = 1;
prnMsg(_('Cannot delete this employee because timesheets have been created for this person'),'warn');
echo _('There are') . ' ' . $MyRow[0] . ' ' . _('timesheet records for this person');
}
*/
if(! $CancelDelete) {
$Result = DB_query("DELETE FROM employees WHERE id='" . $SelectedEmployee . "'");
prnMsg(_('Employee') . ' ' . $SelectedEmployee . ' ' . _('has been deleted') . '!', 'success');
unset ($SelectedEmployee);
}//end if Delete Location
unset($SelectedEmployee);
unset($_GET['delete']);
}
/*
echo '<br /> Selected employee = ' . $SelectedEmployee;
if (isset($SelectedEmployee)) {
echo '<br /> Selected employee is actually set!!!!';
}
*/
if(!isset($SelectedEmployee)) {
/* It could still be the second time the page has been run and a record has been selected for modification - SelectedEmployee will exist because it was sent with the new call. If its the first time the page has been displayed with no parameters
then none of the above are true and the list of employees will be displayed with
links to delete or edit each. These will call the same page again and allow update/input
or deletion of the records*/
$SQL = "SELECT employees.id,
employees.surname,
employees.firstname,
employees.stockid,
employees.manager,
employees2.firstname as managerfirstname,
employees2.surname as managersurname,
employees.normalhours,
employees.email,
employees.userid
FROM employees LEFT JOIN employees AS employees2
ON employees.manager=employees2.id";
$Result = DB_query($SQL);
if (DB_num_rows($Result) > 0) {
echo '<table class="selection">
<thead>
<tr>
<th class="SortedColumn">', _('ID'), '</th>
<th class="SortedColumn">', _('First name'), '</th>
<th class="SortedColumn">', _('Surname'), '</th>
<th class="SortedColumn">', _('Type'), '</th>
<th class="SortedColumn">', _('Manager'), '</th>
<th class="SortedColumn">', _('Email'), '</th>
<th class="noPrint" colspan="2"> </th>
</tr>
</thead>
<tbody>';
while ($MyRow = DB_fetch_array($Result)) {
printf('<tr class="striped_row">
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td><a href="mailto:%s">%s</a></td>
<td class="noPrint"><a href="%sSelectedEmployee=%s">' . _('Edit') . '</a></td>
<td class="noPrint"><a href="%sSelectedEmployee=%s&delete=1" onclick="return confirm(\'' . _('Are you sure you wish to remove this employee?') . '\');">' . _('Delete') . '</a></td>
</tr>',
$MyRow['id'],
$MyRow['firstname'],
$MyRow['surname'],
$MyRow['stockid'],
$MyRow['managerfirstname'] . ' ' . $MyRow['managersurname'],
$MyRow['email'],
$MyRow['email'],
htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?',
$MyRow['id'],
htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '?',
$MyRow['id']);
}
//END WHILE LIST LOOP
echo '</tbody></table>';
} else {
prnMsg(_('No employees have been set up yet'),'info');
}
}
//end of ifs and buts!
echo '<br />';
if(isset($SelectedEmployee)) {
echo '<a href="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">' . _('Review Employees') . '</a>';
}
echo '<br />';
if(!isset($_GET['delete'])) {
echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">
<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
if(isset($SelectedEmployee)) {
//editing an existing Location
$SQL = "SELECT id,
surname,
firstname,
stockid,
manager,
normalhours,
userid,
email
FROM employees
WHERE employees.id='" . $SelectedEmployee . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_array($Result);
$_POST['Surname'] = $MyRow['surname'];
$_POST['FirstName'] = $MyRow['firstname'];
$_POST['StockID'] = $MyRow['stockid'];
$_POST['NormalHours'] = $MyRow['normalhours'];
$_POST['Manager'] = $MyRow['manager'];
$_POST['UserID'] = $MyRow['userid'];
$_POST['Email'] = $MyRow['email'];
echo '<input type="hidden" name="SelectedEmployee" value="' . $SelectedEmployee . '" />';
echo '<fieldset>';
echo '<legend>' . _('Amend Employee details') . '</legend>';
echo '<field>
<label for="SelectedEmployee">' . _('Employee Code') . ':</label>
<fieldtext>' . $SelectedEmployee . '</fieldtext>
</field>';
} else {//end of if $SelectedEmployee only do the else when a new record is being entered
if(!isset($_POST['LocCode'])) {
$_POST['SelectedEmployee'] = '';
}
echo '<fieldset>
<legend>' . _('New Employee details') . '</legend>';
}
if(!isset($_POST['Surname'])) {
$_POST['Surname'] = '';
}
if(!isset($_POST['FirstName'])) {
$_POST['FirstName'] = '';
}
if(!isset($_POST['StockID'])) {
$_POST['StockID'] = ' ';
}
if(!isset($_POST['NormalHours'])) {
$_POST['NormalHours'] = '40';
}
if(!isset($_POST['Manager'])) {
$_POST['Manager'] = '';
}
if(!isset($_POST['UserID'])) {
$_POST['UserID'] = '';
}
if(!isset($_POST['Email'])) {
$_POST['Email'] = '';
}
echo '<field>
<label for="FirstName">' . _('First Name') . ':' . '</label>
<input type="text" name="FirstName" required="required" value="' . $_POST['FirstName'] . '" title="" size="21" maxlength="20" />
<fieldhelp>' . _('Enter the employee\'s first name') . '</fieldhelp>
</field>
<field>
<label for="Surname">' . _('Surname') . ':' . '</label>
<input type="text" name="Surname" required="required" value="'. $_POST['Surname'] . '" title="" namesize="21" maxlength="20" />
<fieldhelp>' . _('Enter the employee\'s surname') . '</fieldhelp>
</field>
<field>
<label for="StockID">' . _('Labour Type') . ':</label>
<select name="StockID" />';
$LabourTypeItemsResult = DB_query("SELECT stockid, description FROM
stockmaster INNER JOIN stockcategory
ON stockmaster.categoryid = stockcategory.categoryid
WHERE stockcategory.stocktype='L'
ORDER BY stockid");
while ($MyRow=DB_fetch_array($LabourTypeItemsResult)) {
if($_POST['StockID']==$MyRow['stockid']) {
echo '<option selected="selected" value="' , $MyRow['stockid'] , '">' , $MyRow['description'] , '</option>';
} else {
echo '<option value="' , $MyRow['stockid'] . '">' , $MyRow['description'] , '</option>';
}
}
echo '</select>
</field>
<field>
<label for="Email">', _('Email'), ':</label>
<input id="Email" maxlength="55" name="Email" size="31" type="email" value="', $_POST['Email'], '" />
<fieldhelp>', _('The email address should be an email format such as [email protected]'), '</fieldhelp>
</field>
<field>
<label for="NormalHours">' . _('Normal Weekly Hours') . ':' . '</label>
<input class="number" type="text" name="NormalHours" value="' , $_POST['NormalHours'] , '" title="" size="3" maxlength="2" />
<fieldhelp>' , _('Enter the employee\'s normal hours per week') , '</fieldhelp>
</field>
<field>
<label for="Manager">' , _('Manager') , ':' , '</label>
<select name="Manager" />';
$ManagersResult = DB_query("SELECT id, CONCAT(firstname, ' ', surname) AS managername
FROM employees
WHERE id != '" . $SelectedEmployee . "'
ORDER BY surname");
if($_POST['Manager']==''){
echo '<option selected="selected" value="0">' , _('Not Managed') , '</option>';
} else {
echo '<option value="0">' , _('Not Managed') , '</option>';
}
while ($MyRow=DB_fetch_array($ManagersResult)) {
if($_POST['Manager']==$MyRow['id']) {
echo '<option selected="selected" value="' , $MyRow['id'] , '">' , $MyRow['managername'] , '</option>';
} else {
echo '<option value="' , $MyRow['id'] , '">' , $MyRow['managername'] , '</option>';
}
}
echo '</select>
</field>';
echo '<field>
<label for="UserID">' , _('webERP User') , ':' , '</label>
<select name="UserID" title=""/>';
if($_POST['UserID']==''){
echo '<option selected="selected" value="">' , _('Not a webERP User') , '</option>';
} else {
echo '<option value="">' , _('Not a webERP User') , '</option>';
}
$UsersResult = DB_query("SELECT userid, realname FROM www_users");
while ($MyRow=DB_fetch_array($UsersResult)) {
if($_POST['UserID']==$MyRow['userid']) {
echo '<option selected="selected" value="' . $MyRow['userid'] . '">' . $MyRow['realname'] . '</option>';
} else {
echo '<option value="' . $MyRow['userid'] . '">' . $MyRow['realname'] . '</option>';
}
}
echo '</select>
<fieldhelp>' , _('Select the employee\'s system user account so when the user logs in to enter a time sheet the system knows the employee record to use') , '</fieldhelp>
</field>';
echo '</fieldset>
<div class="centre">
<input type="submit" name="submit" value="' , _('Enter Information') , '" />
</div>
</form>';
}//end if record deleted no point displaying form to add record
include('includes/footer.php');
?>