function ApproveMainVacationRequest($requestID, $useFirst) { $statusMessage = ""; $succeeded = true; $absenceType = GetAnnualLeaveAbsenceTypeID(); $request = RetrieveMainVacationRequestByID($requestID); if ($request != NULL) { $start = $request[MAIN_VACATION_1ST_START]; $end = $request[MAIN_VACATION_1ST_END]; if (!$useFirst) { $start = $request[MAIN_VACATION_2ND_START]; $end = $request[MAIN_VACATION_2ND_END]; } $succeeded = ProcessAbsenceRequest($request[MAIN_VACATION_EMP_ID], $start, $end, $absenceType, $statusMessage); if ($succeeded) { DeleteMainVacationRequest($requestID); } } else { $statusMessage .= "Error: Unable to process your request." . "The MainVacationRequest ID of {$requestID} " . "could not be found in the database. Please " . "contact your system administrator.</br>"; $succeeded = false; } GenerateStatus($succeeded, $statusMessage); }
function ProcessMainVacationRequests(&$statusMessage) { $stoppedAtEmployeeID = NULL; //-------------------------------------------------------------------------- // Need to get all main vacation requests in an order based on the employees // length of service, so use the bespoke SQL query below. //-------------------------------------------------------------------------- $conn = $GLOBALS["connection"]; $sql = "SELECT * FROM mainVacationRequestTable JOIN EmployeeTable " . "WHERE mainVacationRequestTable.EmployeeID = EmployeeTable.EmployeeID " . "ORDER BY EmployeeTable.dateJoinedTheCompany;"; $result = mysqli_query($conn, $sql); if (!$result) { $statusMessage .= "SQL Error when accessing database.</br>"; error_log("PerformSQL failed. Sql = {$sql}"); } else { $row = mysqli_fetch_array($result, MYSQLI_ASSOC); $lastRequestGranted = TRUE; //--------------------------------------------------------------------- // Process each request in turn until either all have been processed, // or we reach a request that can't be granted. //--------------------------------------------------------------------- while ($row and $lastRequestGranted) { $id = $row[MAIN_VACATION_REQ_ID]; $employeeID = $row[MAIN_VACATION_EMP_ID]; $firstChoiceStartDate = $row[MAIN_VACATION_1ST_START]; $firstChoiceEndDate = $row[MAIN_VACATION_1ST_END]; $secondChoiceStartDate = $row[MAIN_VACATION_2ND_START]; $secondChoiceEndDate = $row[MAIN_VACATION_2ND_END]; $absenceTypeID = GetAnnualLeaveAbsenceTypeID(); $Employee = RetrieveEmployeeByID($employeeID); $statusMessage .= "<b>[Processing main vacation request for " . $Employee[EMP_NAME] . "]</b><br/>"; $statusMessage .= "Attempting first choice from {$firstChoiceStartDate} " . "to {$firstChoiceEndDate}.</br>"; //Try and approve first choice request. if (ProcessAbsenceRequest($employeeID, $firstChoiceStartDate, $firstChoiceEndDate, $absenceTypeID, $statusMessage) == FALSE) { //First choice denied. Try and approve second choice request. $statusMessage .= "Attempting second choice from " . "{$secondChoiceStartDate} to {$secondChoiceEndDate}.</br>"; if (ProcessAbsenceRequest($employeeID, $secondChoiceStartDate, $secondChoiceEndDate, $absenceTypeID, $statusMessage) == FALSE) { //second choice denied. Mail employee to instruct them to //submit a new booking. $statusMessage .= "Neither first nor second choice could be " . "granted. Employee has been emailed to ask " . "for new dates.</br>"; SendResubmitMainVacationRequest($employeeID); //set the ID of the employee who needs to resubmit, to //pass back to the calling function. $lastRequestGranted = FALSE; $stoppedAtEmployeeID = $employeeID; } } //Delete the main vacation request. DeleteMainVacationRequest($id); $row = mysqli_fetch_array($result, MYSQLI_ASSOC); } } return $stoppedAtEmployeeID; }