function ProcessAbsenceRequest($employeeID, $startDate, $endDate, $absenceTypeID, &$statusMessage) { //Assume that booking will be approved. Will be set to FALSE in function //if necessary. $bookingApproved = TRUE; //-------------------------------------------------------------------------- //Check to ensure if the employee has sufficent leave available to cover the //requested period. //-------------------------------------------------------------------------- if (HasSufficentAnnualLeave($employeeID, $startDate, $endDate, $absenceTypeID) == FALSE) { //Employee has insufficent leave available. Deny the request. $statusMessage .= "Insufficent Annual Leave to cover the period " . "requested.</br>"; $message = "Insufficent Annual Leave to cover the period requested."; SendDeniedEmail($employeeID, $startDate, $endDate, $message); $bookingApproved = FALSE; } else { //---------------------------------------------------------------------- //Check to ensure there are sufficent staff in the same role as employee //working to cover the request. //---------------------------------------------------------------------- if (SufficentStaffInRoleToGrantRequest($employeeID, $startDate, $endDate)) { //Sufficent staff are available, grant the request. CreateApprovedAbsenceBooking($employeeID, $startDate, $endDate, $absenceTypeID); SendApprovedEmail($employeeID, $startDate, $endDate); $statusMessage .= "Absence Approved from {$startDate} to {$endDate}. " . "Staff notifed via email.</br>"; $bookingApproved = TRUE; } else { //------------------------------------------------------------------ // Granting the request would mean going below the minimum staffing // level for the role. However, if the type of absence requested is // not deniable, then we have to grant the leave. //----------------------------------------------------------------- $absenceType = RetrieveAbsenceTypeByID($absenceTypeID); if ($absenceType[ABS_TYPE_CAN_BE_DENIED]) { //Type of leave requested can be denied. Deny the request. $bookingApproved = FALSE; $statusMessage .= "Absence Rejected from {$startDate} to {$endDate}." . "Request would leave role below minimum " . "staffing level. Staff notified via email.</br>"; $message = "Absence Rejected from {$startDate} to {$endDate}. " . "Request would leave role below minimum staffing " . "level. Staff notified via email."; SendDeniedEmail($employeeID, $startDate, $endDate, $message); } else { //-------------------------------------------------------------- //Type of leave requested can not be denied. Approve the request. //But also inform the office manager that we will be going below //the minimum staffing level. //-------------------------------------------------------------- $absenceType = RetrieveAbsenceTypeByID($absenceTypeID); $statusMessage .= "Absence Approved from {$startDate} to {$endDate}." . "Staff notifed via email.</br>"; $statusMessage .= "<em>Note that the " . $absenceType[ABS_TYPE_NAME] . " role will be under the minimum staffing level" . " during this time. </br>"; CreateApprovedAbsenceBooking($employeeID, $startDate, $endDate, $absenceTypeID); SendApprovedEmail($employeeID, $startDate, $endDate); SendShortfallAlertToOfficeManager($employeeID, $startDate, $endDate, $absenceTypeID); $bookingApproved = TRUE; } } } return $bookingApproved; }
<?php include 'sessionmanagement.php'; $request = array(); if ($_GET["ID"] != NULL) { $request = RetrieveApprovedAbsenceBookingByID($_GET["ID"]); } if (isset($_POST["cancel"])) { $url = "Location:adminApprovedAbsenceBookings.php"; header($url); } if (isset($_POST["update"])) { DeleteApprovedAbsenceBooking($_GET["ID"]); $success = CreateApprovedAbsenceBooking($_POST["employeeID"], $_POST["startDate"], $_POST["endDate"], $_POST["absenceType"]); if ($success) { $url = "Location:adminApprovedAbsenceBookings.php"; header($url); } } function GenerateEmployeeSelect($request) { $employees = RetrieveEmployees(); if ($employees != NULL) { echo '<select class="form-control" name="employeeID">'; foreach ($employees as $Employee) { if ($Employee[EMP_ID] == $request[APPR_ABS_EMPLOYEE_ID]) { echo '<option selected="selected" ' . 'value="' . $Employee[EMP_ID] . '">' . $Employee[EMP_NAME] . '</option>'; } else { echo '<option value="' . $Employee[EMP_ID] . '">' . $Employee[EMP_NAME] . '</option>'; } }
$requestID = $_POST["approve2nd"]; ApproveMainVacationRequest($requestID, false); } if (isset($_POST["reject"])) { ClearStatus(); $ID = $_POST["reject"]; DeleteMainVacationRequest($ID); } if (isset($_POST["approveadhoc"])) { $ID = $_POST["approveadhoc"]; ClearStatus(); $request = RetrieveAdHocAbsenceRequestByID($ID); $startDate = $request[AD_HOC_START]; $endDate = $request[AD_HOC_END]; $absenceTypeID = $request[AD_HOC_ABSENCE_TYPE_ID]; $success = CreateApprovedAbsenceBooking($request[AD_HOC_EMP_ID], $startDate, $endDate, $absenceTypeID); if ($success) { DeleteAdHocAbsenceRequest($ID); } } if (isset($_POST["rejectadhoc"])) { ClearStatus(); $ID = $_POST["reject"]; DeleteAdHocAbsenceRequest($ID); } function ApproveMainVacationRequest($requestID, $useFirst) { $statusMessage = ""; $succeeded = true; $absenceType = GetAnnualLeaveAbsenceTypeID(); $request = RetrieveMainVacationRequestByID($requestID);
function CreateNewDatabase($destroyExistingDB = false, $createWithTestData = false) { if ($destroyExistingDB) { DropDB(); } CreateDB(); UseDB(); CreateDateTable(); CreatePublicHolidayTable(); CreateAbsenceTypeTable(); CreateCompanyRoleTable(); CreateEmployeeTable(); CreateApprovedAbsenceBookingTable(); CreateApprovedAbsenceDateTable(); CreateAdHocAbsenceRequestTable(); CreateMainVacationRequestTable(); // CreateDefaultRecords("admin", "*****@*****.**","Zaq12wsx","2015-01-01", 19); if ($createWithTestData) { $annualLeave = CreateAbsenceType("Annual Leave", 1, 1); $training = CreateAbsenceType("Training", 0, 1); $sickness = CreateAbsenceType("Sickness", 0, 0); $compasionate = CreateAbsenceType("Compasionate Leave", 0, 1); $cashier = CreateCompanyRole("Cashier", 3); $customerAdvisor = CreateCompanyRole("Customer Advisor", 2); $manager = CreateCompanyRole("Manager", 1); $filter[COMP_ROLE_NAME] = "Admin"; $results = RetrieveCompanyRoles($filter); $admin = $results[0]; $steveBrookstein = CreateEmployee("Steve Brookstein", "*****@*****.**", "Zaq12wsx", "2005-01-01", 20, NULL, $cashier[COMP_ROLE_ID], 0, 0); $shayneWard = CreateEmployee("Shane Ward", "*****@*****.**", "Zaq12wsx", "2006-01-01", 20, NULL, $cashier[COMP_ROLE_ID], 0, 0); $leonJackson = CreateEmployee("Leon Jackson", "*****@*****.**", "Zaq12wsx", "2008-01-01", 20, NULL, $manager[COMP_ROLE_ID], 0, 0); $alexandraBurke = CreateEmployee("Alexandra Burke", "*****@*****.**", "Zaq12wsx", "2009-01-01", 20, NULL, $cashier[COMP_ROLE_ID], 0, 0); $joeMcElderry = CreateEmployee("Joe McElderry", "*****@*****.**", "Zaq12wsx", "2010-01-01", 20, NULL, $customerAdvisor[COMP_ROLE_ID], 0, 0); $mattCardle = CreateEmployee("Matt Cardle", "*****@*****.**", "Zaq12wsx", "2011-01-01", 20, NULL, $customerAdvisor[COMP_ROLE_ID], 0, 0); $jamesArthur = CreateEmployee("James Arthur", "*****@*****.**", "Zaq12wsx", "2012-01-01", 20, NULL, $customerAdvisor[COMP_ROLE_ID], 0, 0); $samBailey = CreateEmployee("Sam Bailey", "*****@*****.**", "Zaq12wsx", "2013-01-01", 20, NULL, $customerAdvisor[COMP_ROLE_ID], 0, 0); $benHaenow = CreateEmployee("Ben Haenow", "*****@*****.**", "Zaq12wsx", "2014-01-01", 20, NULL, $manager[COMP_ROLE_ID], 0, 1); $dates = RetrieveDates(); if (count($dates) == 0) { date_default_timezone_set('UTC'); // Start date $date = '2015-01-01'; // End date $end_date = '2055-12-31'; while (strtotime($date) <= strtotime($end_date)) { CreateDate($date, NULL); $date = date("Y-m-d", strtotime("+1 day", strtotime($date))); } } $dateID = RetrieveDateIDByDate("2015-04-03"); $goodFriday = CreatePublicHoliday("Good Friday", $dateID); $dateID = RetrieveDateIDByDate("2015-04-06"); $easterMonday = CreatePublicHoliday("Easter Monday", $dateID); $dateID = RetrieveDateIDByDate("2015-05-04"); $earlyMay = CreatePublicHoliday("Early May Bank Holiday", $dateID); $dateID = RetrieveDateIDByDate("2015-05-25"); $springHoliday = CreatePublicHoliday("Spring Bank Holiday", $dateID); $dateID = RetrieveDateIDByDate("2015-08-31"); $summerHoliday = CreatePublicHoliday("Summer Bank Holiday", $dateID); $dateID = RetrieveDateIDByDate("2015-12-25"); $christmasDay = CreatePublicHoliday("Christmas Day", $dateID); $dateID = RetrieveDateIDByDate("2015-12-28"); $boxingDay = CreatePublicHoliday("Boxing Day (substitute day)", $dateID); $request = CreateMainVactionRequest($steveBrookstein[EMP_ID], "2015-01-10", "2015-01-15", "2015-02-10", "2015-02-15"); $request = CreateMainVactionRequest($shayneWard[EMP_ID], "2015-01-10", "2015-01-15", "2015-02-10", "2015-02-15"); $request = CreateMainVactionRequest($leonJackson[EMP_ID], "2015-01-10", "2015-01-15", "2015-02-10", "2015-02-15"); $request = CreateMainVactionRequest($alexandraBurke[EMP_ID], "2015-01-10", "2015-01-15", "2015-02-10", "2015-02-15"); $request = CreateMainVactionRequest($joeMcElderry[EMP_ID], "2015-01-10", "2015-01-15", "2015-02-10", "2015-02-15"); $request = CreateMainVactionRequest($jamesArthur[EMP_ID], "2015-01-10", "2015-01-15", "2015-02-10", "2015-02-15"); $request = CreateMainVactionRequest($mattCardle[EMP_ID], "2015-01-10", "2015-01-15", "2015-02-10", "2015-02-15"); $request = CreateMainVactionRequest($samBailey[EMP_ID], "2015-01-10", "2015-01-15", "2015-02-10", "2015-02-15"); $request = CreateMainVactionRequest($benHaenow[EMP_ID], "2015-01-10", "2015-01-15", "2015-02-10", "2015-02-15"); $request = CreateAdHocAbsenceRequest($steveBrookstein[EMP_ID], "2015-03-10", "2015-03-15", $annualLeave[ABS_TYPE_ID]); $request = CreateAdHocAbsenceRequest($shayneWard[EMP_ID], "2015-03-10", "2015-03-15", $annualLeave[ABS_TYPE_ID]); $request = CreateAdHocAbsenceRequest($leonJackson[EMP_ID], "2015-03-10", "2015-03-15", $sickness[ABS_TYPE_ID]); $request = CreateAdHocAbsenceRequest($alexandraBurke[EMP_ID], "2015-03-10", "2015-03-15", $training[ABS_TYPE_ID]); $request = CreateAdHocAbsenceRequest($joeMcElderry[EMP_ID], "2015-03-10", "2015-03-15", $training[ABS_TYPE_ID]); $request = CreateAdHocAbsenceRequest($mattCardle[EMP_ID], "2015-03-10", "2015-03-15", $training[ABS_TYPE_ID]); $request = CreateAdHocAbsenceRequest($jamesArthur[EMP_ID], "2015-03-10", "2015-03-15", $training[ABS_TYPE_ID]); $request = CreateAdHocAbsenceRequest($samBailey[EMP_ID], "2015-03-10", "2015-03-15", $compasionate[ABS_TYPE_ID]); $request = CreateAdHocAbsenceRequest($benHaenow[EMP_ID], "2015-03-10", "2015-03-15", $compasionate[ABS_TYPE_ID]); $leonaLewis = CreateEmployee("Leona Lewis", "*****@*****.**", "Zaq12wsx", "2007-01-01", 20, NULL, $admin[COMP_ROLE_ID], 1, 1); $request = CreateAdHocAbsenceRequest($leonaLewis[EMP_ID], "2015-03-10", "2015-03-15", $sickness[ABS_TYPE_ID]); $request = CreateMainVactionRequest($leonaLewis[EMP_ID], "2015-01-10", "2015-01-15", "2015-02-10", "2015-02-15"); $request = CreateApprovedAbsenceBooking($leonaLewis[EMP_ID], "2015-04-01", "2015-04-10", $training[ABS_TYPE_ID]); } }
include 'sessionmanagement.php'; // If user is not an adminstrator, redirect them back to the home page. if (!$isAdministrator) { header('Location: index.php'); exit; } // If user has clicked the submit button, try and create the approved absence // booking if (isset($_POST["submit"])) { ClearStatus(); $employeeID = NULL; if (isset($_POST["employeeID"])) { $employeeID = $_POST["employeeID"]; } $booking = CreateApprovedAbsenceBooking($employeeID, $_POST["startDate"], $_POST["endDate"], $_POST["absenceType"]); } // If user has clicked the amend button, redirect them to the edit approvced // booking page, using a GET parameter with the ID of the record to edit. if (isset($_POST["amend"])) { ClearStatus(); $url = "Location:editApprovedAbsenceBooking.php?ID=" . $_POST["amend"]; header($url); } // If user has clicked the delete button, delete the record from the table. if (isset($_POST["delete"])) { ClearStatus(); DeleteApprovedAbsenceBooking($_POST["delete"]); } //----------------------------------------------------------------------------- // This function will generate the HTML necessary for the employee select