function DisplayEmployeeDetailsListItems($userID) { $employee = RetrieveEmployeeByID($userID); $companyRole = RetrieveCompanyRoleByID($employee[EMP_COMPANY_ROLE]); echo '<li class="list-group-item ">ID: ' . $employee[EMP_ID] . '</li>'; echo '<li class="list-group-item ">Name: ' . $employee[EMP_NAME] . '</li>'; echo '<li class="list-group-item ">Email: ' . $employee[EMP_EMAIL] . '</li>'; echo '<li class="list-group-item ">Date Joined: ' . $employee[EMP_DATEJOINED] . '</li>'; echo '<li class="list-group-item ">Company Role: ' . $companyRole[COMP_ROLE_NAME] . '</li>'; echo '<li class="list-group-item ">Is Admin: ' . $employee[EMP_ADMIN_PERM] . '</li>'; echo '<li class="list-group-item ">Is Manager: ' . $employee[EMP_MANAGER_PERM] . '</li>'; echo '<li class="list-group-item ">Leave Entitlement: ' . $employee[EMP_LEAVE_ENTITLEMENT] . '</li>'; echo '<li class="list-group-item ">Annual leave remaining:' . CalculateRemainingAnnualLeave($employee[EMP_ID]) . '</li>'; }
function DisplayEmployeeTableBody() { $employees = RetrieveEmployees(); if ($employees != NULL) { foreach ($employees as $employee) { $role = RetrieveCompanyRoleByID($employee[EMP_COMPANY_ROLE]); echo "<tr>"; echo "<td>" . $employee[EMP_ID] . "</td>"; echo "<td>" . $employee[EMP_NAME] . "</td>"; echo "<td>" . $employee[EMP_EMAIL] . "</td>"; echo "<td>" . $employee[EMP_DATEJOINED] . "</td>"; echo "<td>" . $employee[EMP_LEAVE_ENTITLEMENT] . "</td>"; echo "<td>" . $role[COMP_ROLE_NAME] . "</td>"; echo "<td>" . $employee[EMP_MAIN_VACATION_REQ_ID] . "</td>"; echo "<td>" . $employee[EMP_ADMIN_PERM] . "</td>"; echo "<td>" . $employee[EMP_MANAGER_PERM] . "</td>"; echo '<td> <button type="submit" class="btn btn-success" ' . 'name="amend" id="amend" value="' . $employee[EMP_ID] . '">Amend</button></td>'; echo '<td> <button type="submit" class="btn btn-danger" ' . 'name="delete" id="delete" value="' . $employee[EMP_ID] . '">Delete</button></td>'; echo "</tr>"; } } }
function SendShortfallAlertToOfficeManager($employeeID, $startDate, $endDate, $absenceTypeID) { $employee = RetrieveEmployeeByID($employeeID); $employeeName = $employee[EMP_NAME]; $absenceType = RetrieveAbsenceTypeByID($absenceTypeID); $absenceName = $absenceType[ABS_TYPE_NAME]; $role = RetrieveCompanyRoleByID($employee[EMP_COMPANY_ROLE]); $roleName = $role[COMP_ROLE_NAME]; $minimumStaff = $role[COMP_ROLE_MIN_STAFF]; $from = "*****@*****.**"; $subject = "URGENT: STAFF SHORTFALL"; $message = "Between {$startDate} and {$endDate} the number of staff performing the " . "role of {$roleName} will be below {$minimumStaff}." . "This is due to {$employeeName} being absent with {$absenceName}."; $filter[EMP_MANAGER_PERM] = 1; $managers = RetrieveEmployees($filter); $success = TRUE; foreach ($managers as $manager) { if (!mail($manager[EMP_EMAIL], $subject, $message)) { $success = FALSE; } } return $success; }
function SufficentStaffInRoleToGrantRequest($employeeID, $startDate, $endDate) { $sufficentStaffInRole = TRUE; // Get the employee record from the database. $Employee = RetrieveEmployeeByID($employeeID); if ($Employee != NULL) { // Get the associated Company Role record from the database. $employeeRole = RetrieveCompanyRoleByID($Employee[EMP_COMPANY_ROLE]); if ($employeeRole != NULL) { $minimumStaffingLevel = $employeeRole[COMP_ROLE_MIN_STAFF]; //Calculate the total number of employees in this role. $filter[EMP_COMPANY_ROLE] = $Employee[EMP_COMPANY_ROLE]; $employeesInRole = RetrieveEmployees($filter); $numEmployeesInRole = count($employeesInRole); //Check staffing levels for each day in the period requested. $tempDate = strtotime($startDate); $endTime = strtotime($endDate); $underMinimumStaffing = FALSE; while ($tempDate <= $endTime and $underMinimumStaffing == FALSE) { // 2010-05-01, 2010-05-02, etc $strDate = date('Y-m-d', $tempDate); //Calculate the number of staff in this role that are on leave //on this date. $staffOnLeave = CountStaffOnLeave($Employee[EMP_COMPANY_ROLE], $strDate); //Q.Would granting this leave would take us below the minimum //staffing level for the role. $availableStaff = $numEmployeesInRole - $staffOnLeave; if ($availableStaff <= $minimumStaffingLevel) { //Y.Granting the request would take us below the minimum //staffing level for the role. $underMinimumStaffing = TRUE; $sufficentStaffInRole = FALSE; } //move temp date onto the next day. Note tempdate is in seconds. //86400 = 60 seconds * 60 minutes * 24 hours. $tempDate = $tempDate + 86400; } } else { error_log("Unknown company role identifier of " . $employee[EMP_COMPANY_ROLE]); } } else { error_log("Unknown employee identifier of {$employeeID}"); } return $sufficentStaffInRole; }
function UpdateEmployee($fields) { $statusMessage = ""; //------------------------------------------------------------------------- // Validate Input parameters //------------------------------------------------------------------------- $inputIsValid = TRUE; $validID = false; $countOfFields = 0; foreach ($fields as $key => $value) { if ($key == EMP_ID) { $record = RetrieveEmployeeByID($value); if ($record != NULL) { $validID = true; $countOfFields++; } } else { if ($key == EMP_NAME) { $countOfFields++; if (isNullOrEmptyString($value)) { $statusMessage .= "Employee name can not be blank.</br>"; error_log("Invalid EMP_NAME passed to UpdateEmployee."); $inputIsValid = FALSE; } } else { if ($key == EMP_EMAIL) { $countOfFields++; if (!filter_var($value, FILTER_VALIDATE_EMAIL)) { $statusMessage .= "Email address is not in a valid format.</br>"; error_log("Invalid email address passed to UpdateEmployee."); $inputIsValid = FALSE; } } else { if ($key == EMP_PASSWORD) { //No validation on password, since this is an MD5 encoded string. $countOfFields++; } else { if ($key == EMP_DATEJOINED) { $countOfFields++; if (!isValidDate($value)) { $statusMessage .= "Date Joined value is not a valid date</br>"; error_log("Invalid EMP_DATEJOINED passed to UpdateEmployee."); $inputIsValid = FALSE; } } else { if ($key == EMP_LEAVE_ENTITLEMENT) { $countOfFields++; if (!is_numeric($value)) { $statusMessage .= "Employee Leave Entitlement must be a numeric value.</br>"; error_log("Invalid EMP_LEAVE_ENTITLEMENT passed to UpdateEmployee."); $inputIsValid = FALSE; } } else { if ($key == EMP_MAIN_VACATION_REQ_ID) { if ($value != NULL) { $record = RetrieveMainVacationRequestByID($value); if ($record == NULL) { $statusMessage .= "Main Vacation Request ID not found in database.</br>"; error_log("Invalid EMP_MAIN_VACATION_REQ_ID passed to UpdateEmployee."); $inputIsValid = FALSE; } } } else { if ($key == EMP_COMPANY_ROLE) { $countOfFields++; $record = RetrieveCompanyRoleByID($value); if ($record == NULL) { $statusMessage .= "Company Role ID not found in database.</br>"; error_log("Invalid EMP_COMPANY_ROLE passed to UpdateEmployee."); $inputIsValid = FALSE; } } else { if ($key == EMP_ADMIN_PERM) { $countOfFields++; } else { if ($key == EMP_MANAGER_PERM) { $countOfFields++; } else { $statusMessage .= "Unrecognised field of {$key} encountered.</br>"; error_log("Invalid field passed to UpdateEmployee. {$key}=" . $key); $inputIsValid = FALSE; } } } } } } } } } } } if (!$validID) { $statusMessage .= "No valid ID supplied.</br>"; error_log("No valid ID supplied in call to UpdateEmployee."); $inputIsValid = FALSE; } if ($countOfFields < 2) { $statusMessage .= "Insufficent fields supplied.</br>"; error_log("Insufficent fields supplied in call to UpdateEmployee."); $inputIsValid = FALSE; } //------------------------------------------------------------------------- // Only attempt to update a record in the database if the input parameters // are ok. //------------------------------------------------------------------------- $success = false; if ($inputIsValid) { $success = performSQLUpdate(EMPLOYEE_TABLE, EMP_ID, $fields); if ($success) { $statusMessage .= "Record has been successfully updated."; } else { $inputIsValid = false; $statusMessage .= "Unexpected Database error encountered. Please " . "contact your system administrator."; } } GenerateStatus($inputIsValid, $statusMessage); return $success; }
function DeleteCompanyRole($ID) { $statusMessage = ""; $result = 0; $record = RetrieveCompanyRoleByID($ID); if ($record != NULL) { $filter[EMP_COMPANY_ROLE] = $ID; $employees = RetrieveEmployees($filter); if ($employees != NULL) { foreach ($employees as $employee) { DeleteEmployee($employee[EMP_ID]); } } $sql = "DELETE FROM companyroletable WHERE companyRoleID=" . $ID . ";"; $result = performSQL($sql); $statusMessage = "Role Deleted.</br>"; GenerateStatus(true, $statusMessage); } return $result; }
<?php include 'sessionmanagement.php'; if (!$isAdministrator) { header('Location: index.php'); exit; } if ($_GET["roleID"] != NULL) { $role = RetrieveCompanyRoleByID($_GET["roleID"]); } if (isset($_POST["cancel"])) { $url = "Location:adminCompanyRoles.php"; header($url); } if (isset($_POST["update"])) { $role[COMP_ROLE_ID] = $_GET["roleID"]; $role[COMP_ROLE_NAME] = $_POST["roleName"]; $role[COMP_ROLE_MIN_STAFF] = $_POST["minStaff"]; $result = UpdateCompanyRole($role); if ($result) { $url = "Location:adminCompanyRoles.php"; header($url); } } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Amend Company Role</title>