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 UpdateMainVacactionRequest($fields)
{
    $success = false;
    $statusMessage = "";
    //-------------------------------------------------------------------------
    // Validate Input parameters
    //--------------------------------------------------------------------------
    $inputIsValid = TRUE;
    $validID = false;
    $countOfFields = 0;
    foreach ($fields as $key => $value) {
        if ($key == MAIN_VACATION_REQ_ID) {
            $record = RetrieveMainVacationRequestByID($value);
            if ($record != NULL) {
                $validID = true;
                $countOfFields++;
            }
        } else {
            if ($key == MAIN_VACATION_EMP_ID) {
                $countOfFields++;
                $record = RetrieveEmployeeByID($value);
                if ($record == NULL) {
                    $statusMessage .= "Invalid Main Vacation Employee ID</br>";
                    error_log("Invalid MAIN_VACATION_EMP_ID passed to " . "UpdateMainVacationRequest.");
                    $inputIsValid = FALSE;
                }
            } else {
                if ($key == MAIN_VACATION_1ST_START) {
                    $countOfFields++;
                    if (!isValidDate($value)) {
                        $statusMessage .= "Invalid 1st Choice Start Date</br>";
                        error_log("Invalid MAIN_VACATION_1ST_START passed to " . "UpdateMainVacationRequest.");
                        $inputIsValid = FALSE;
                    }
                } else {
                    if ($key == MAIN_VACATION_1ST_END) {
                        $countOfFields++;
                        if (!isValidDate($value)) {
                            $statusMessage .= "Invalid 1st Choice Finish Date/br>";
                            error_log("Invalid MAIN_VACATION_1ST_END passed to " . "UpdateMainVacationRequest.");
                            $inputIsValid = FALSE;
                        }
                    } else {
                        if ($key == MAIN_VACATION_2ND_START) {
                            $countOfFields++;
                            if (!isValidDate($value)) {
                                $statusMessage .= "Invalid 2nd Choice Start Date/br>";
                                error_log("Invalid MAIN_VACATION_2ND_START passed to " . "UpdateMainVacationRequest.");
                                $inputIsValid = FALSE;
                            }
                        } else {
                            if ($key == MAIN_VACATION_2ND_END) {
                                $countOfFields++;
                                if (!isValidDate($value)) {
                                    $statusMessage .= "Invalid 2nd Choice Finish Date/br>";
                                    error_log("Invalid MAIN_VACATION_2ND_END passed to " . "UpdateMainVacationRequest.");
                                    $inputIsValid = FALSE;
                                }
                            } else {
                                $statusMessage .= "Invalid Field encountered./br>";
                                error_log("Invalid field passed to " . "UpdateMainVacationRequest. {$key}=" . $key);
                                $inputIsValid = FALSE;
                            }
                        }
                    }
                }
            }
        }
    }
    $firstChoiceStartDate = $fields[MAIN_VACATION_1ST_START];
    $firstChoiceEndDate = $fields[MAIN_VACATION_1ST_END];
    $secondChoiceStartDate = $fields[MAIN_VACATION_2ND_START];
    $secondChoiceEndDate = $fields[MAIN_VACATION_2ND_END];
    if (strtotime($firstChoiceEndDate) < strtotime($firstChoiceStartDate)) {
        $statusMessage .= "1st Choice End Date is before 1st Choice Start Date.</br>";
        error_log("First Choice End Date is before First Choice Start Date.");
        $inputIsValid = FALSE;
    }
    if (strtotime($secondChoiceEndDate) < strtotime($secondChoiceStartDate)) {
        $statusMessage .= "2nd Choice End Date is before 2nd Choice Start Date.</br>";
        error_log("Second Choice End Date is before Second Choice Start Date.");
        $inputIsValid = FALSE;
    }
    if (!$validID) {
        $statusMessage .= "No valid record ID found/br>";
        error_log("No valid ID supplied in call to UpdateMainVacationRequest.");
        $inputIsValid = FALSE;
    }
    if ($countOfFields < 2) {
        $statusMessage .= "You must modify at least one of the fields of the record./br>";
        error_log("Insufficent fields supplied in call to UpdateMainVacationRequest.");
        $inputIsValid = FALSE;
    }
    //--------------------------------------------------------------------------
    // Only attempt to update a record in the database if the input parameters
    // are ok.
    //--------------------------------------------------------------------------
    if ($inputIsValid) {
        $success = performSQLUpdate(MAIN_VACATION_REQUEST_TABLE, MAIN_VACATION_REQ_ID, $fields);
        if ($success) {
            $statusMessage .= "Record successfully modified.";
        } else {
            $inputIsValid = false;
            $statusMessage .= "Error encountered when updating the database. " . "Contact system administrator.</br>";
        }
    }
    GenerateStatus($inputIsValid, $statusMessage);
    return $success;
}
function UpdateCompanyRole($fields)
{
    //-------------------------------------------------------------------------
    // Validate Input parameters
    //-------------------------------------------------------------------------
    $statusMessage = "";
    $inputIsValid = TRUE;
    $validID = false;
    $countOfFields = 0;
    foreach ($fields as $key => $value) {
        if ($key == COMP_ROLE_ID) {
            $record = RetrieveCompanyRoleByID($value);
            if ($record != NULL) {
                $validID = true;
                $countOfFields++;
            } else {
                $statusMessage .= "Unable to locate Company Role in the database.";
                error_log("No valid ID supplied in call to UpdateCompanyRole.");
                $inputIsValid = FALSE;
            }
        } else {
            if ($key == COMP_ROLE_NAME) {
                $countOfFields++;
                if (isNullOrEmptyString($value)) {
                    $statusMessage .= "You must enter a company role name.";
                    error_log("Invalid COMP_ROLE_NAME passed to UpdateCompanyRole.");
                    $inputIsValid = FALSE;
                }
            } else {
                if ($key == COMP_ROLE_MIN_STAFF) {
                    $countOfFields++;
                    if (!is_numeric($value)) {
                        $statusMessage .= "You must enter a numeric value for minimum staff";
                        error_log("Invalid COMP_ROLE_MIN_STAFF passed to UpdateCompanyRole.");
                        $inputIsValid = FALSE;
                    }
                } else {
                    $statusMessage .= "Invalid field.";
                    error_log("Invalid field passed to UpdateCompanyRole. {$key}=" . $key);
                    $inputIsValid = FALSE;
                }
            }
        }
    }
    if ($countOfFields < 2) {
        $statusMessage .= "You must alter at least one field before updating.";
        error_log("Insufficent fields supplied in call to UpdateCompanyRole.");
        $inputIsValid = FALSE;
    }
    //-------------------------------------------------------------------------
    // Only attempt to update a record in the database if the input parameters
    // are ok.
    //-------------------------------------------------------------------------
    $success = false;
    if ($inputIsValid) {
        $success = performSQLUpdate(COMPANY_ROLE_TABLE, COMP_ROLE_ID, $fields);
        $statusMessage .= "Record has been updated successfully.";
    }
    GenerateStatus($inputIsValid, $statusMessage);
    return $success;
}
function UpdatePublicHoliday($fields)
{
    $statusMessage = "";
    //-------------------------------------------------------------------------
    // Validate Input parameters
    //-------------------------------------------------------------------------
    $inputIsValid = TRUE;
    $validID = false;
    $countOfFields = 0;
    $oldDateRecord = NULL;
    foreach ($fields as $key => $value) {
        if ($key == PUB_HOL_ID) {
            $record = RetrievePublicHolidayByID($value);
            if ($record != NULL) {
                $validID = true;
                $countOfFields++;
                $oldDateRecord = RetrieveDateByID($record[PUB_HOL_DATE_ID]);
            }
        } else {
            if ($key == PUB_HOL_NAME) {
                $countOfFields++;
                if (isNullOrEmptyString($value)) {
                    $statusMessage .= "Public holiday name must be entered.</br>";
                    error_log("Invalid PUB_HOL_NAME passed to UpdatePublicHoliday.");
                    $inputIsValid = FALSE;
                }
            } else {
                if ($key == PUB_HOL_DATE_ID) {
                    $countOfFields++;
                    $record = RetrieveDateByID($value);
                    if ($record == NULL) {
                        $statusMessage .= "Unable to located date in database.</br>";
                        error_log("Invalid  PUB_HOL_DATE_ID passed to UpdatePublicHoliday.");
                        $inputIsValid = FALSE;
                    }
                } else {
                    $statusMessage .= "Unexpected field encountered in input.</br>";
                    error_log("Invalid field passed to UpdatePublicHoliday.");
                    $inputIsValid = FALSE;
                }
            }
        }
    }
    if (!$validID) {
        $statusMessage .= "No valid ID supplied in call to UpdatePublicHoliday.</br>";
        error_log("No valid ID supplied in call to UpdatePublicHoliday.");
        $inputIsValid = FALSE;
    }
    if ($countOfFields < 2) {
        $statusMessage .= "Insufficent fields supplied in call to UpdatePublicHoliday.</br>";
        error_log("Insufficent fields supplied in call to UpdatePublicHoliday.");
        $inputIsValid = FALSE;
    }
    //--------------------------------------------------------------------------
    // Only attempt to update a record in the database if the input parameters
    // are ok.
    //--------------------------------------------------------------------------
    $success = false;
    if ($inputIsValid) {
        $success = performSQLUpdate(PUBLIC_HOLIDAY_TABLE, PUB_HOL_ID, $fields);
        if ($success) {
            $oldDateRecord[DATE_TABLE_PUBLIC_HOL_ID] = NULL;
            $success = UpdateDate($oldDateRecord);
            $dateRecord = RetrieveDateByID($fields[PUB_HOL_DATE_ID]);
            //-------------------------------------------------------------
            // Update the date records public holiday ID field.
            //-------------------------------------------------------------
            $dateRecord[DATE_TABLE_PUBLIC_HOL_ID] = $fields[PUB_HOL_ID];
            $success = UpdateDate($dateRecord);
            $statusMessage .= "Record successfully updated.</br>";
        } else {
            $statusMessage .= "Unexpected error when updating the database.</br>";
            $inputIsValid = false;
        }
    }
    GenerateStatus($inputIsValid, $statusMessage);
    return $success;
}
function UpdateApprovedAbsenceBooking($fields)
{
    $statusMessage = "";
    //--------------------------------------------------------------------------------
    // Validate Input parameters
    //--------------------------------------------------------------------------------
    $inputIsValid = TRUE;
    $validID = false;
    $countOfFields = 0;
    foreach ($fields as $key => $value) {
        if ($key == APPR_ABS_BOOKING_ID) {
            $record = RetrieveApprovedAbsenceBookingByID($value);
            if ($record != NULL) {
                $validID = true;
                $countOfFields++;
            }
        } else {
            if ($key == APPR_ABS_EMPLOYEE_ID) {
                $countOfFields++;
                $record = RetrieveEmployeeByID($value);
                if ($record == NULL) {
                    $statusMessage .= "Unable to locate employee in database</br>";
                    error_log("Invalid EMP_ID passed to " . "UpdateApprovedAbsenceBooking. Value=" . $value);
                    $inputIsValid = FALSE;
                }
            } else {
                if ($key == APPR_ABS_START_DATE) {
                    $countOfFields++;
                    if (!isValidDate($value)) {
                        $statusMessage .= "Start date is not a valid date.</br>";
                        error_log("Invalid APPR_ABS_START_DATE passed to " . "UpdateApprovedAbsenceBooking. Value=" . $value);
                        $inputIsValid = FALSE;
                    }
                } else {
                    if ($key == APPR_ABS_END_DATE) {
                        $countOfFields++;
                        if (!isValidDate($value)) {
                            $statusMessage .= "End date is not a valid date.</br>";
                            error_log("Invalid APPR_ABS_END_DATE passed to " . "UpdateApprovedAbsenceBooking. Value=" . $value);
                            $inputIsValid = FALSE;
                        }
                    } else {
                        if ($key == APPR_ABS_ABS_TYPE_ID) {
                            $countOfFields++;
                            $record = RetrieveAbsenceTypeByID($value);
                            if ($record == NULL) {
                                $statusMessage .= "Unable to locate absence type in database</br>";
                                error_log("Invalid APPR_ABS_ABS_TYPE_ID passed to " . "UpdateApprovedAbsenceBooking. Value=" . $value);
                                $inputIsValid = FALSE;
                            }
                        } else {
                            $statusMessage .= "Unexpected field found in input</br>";
                            error_log("Invalid field passed to UpdateApprovedAbsenceBooking." . " {$key}=" . $key);
                            $inputIsValid = FALSE;
                        }
                    }
                }
            }
        }
    }
    $absenceStartDate = $fields[APPR_ABS_START_DATE];
    $absenceEndDate = $fields[APPR_ABS_END_DATE];
    if (strtotime($absenceEndDate) < strtotime($absenceStartDate)) {
        $statusMessage .= "end Date is before start Date.</br>";
        error_log("End Date is before Start Date.");
        $inputIsValid = FALSE;
    }
    if (!$validID) {
        $statusMessage .= "No valid ID supplied</br>";
        error_log("No valid ID supplied in call to UpdateApprovedAbsenceBooking.");
        $inputIsValid = FALSE;
    }
    if ($countOfFields < 2) {
        $statusMessage .= "Insufficent fields supplied</br>";
        error_log("Insufficent fields supplied in call to UpdateApprovedAbsenceBooking.");
        $inputIsValid = FALSE;
    }
    //--------------------------------------------------------------------------------
    // Only attempt to update a record in the database if the input parameters are ok.
    //--------------------------------------------------------------------------------
    $success = false;
    if ($inputIsValid) {
        $success = performSQLUpdate(APPROVED_ABSENCE_BOOKING_TABLE, APPR_ABS_BOOKING_ID, $fields);
        if ($success) {
            $statusMessage .= "Record updated successfully.</br>";
        } else {
            $statusMessage .= "Unexpected error encountered when updating database.</br>";
            $inputIsValid = false;
        }
    }
    GenerateStatus($inputIsValid, $statusMessage);
    return $success;
}
function UpdateAdHocAbsenceRequest($fields)
{
    $statusMessage = "";
    //-------------------------------------------------------------------------
    // Validate Input parameters
    //-------------------------------------------------------------------------
    $inputIsValid = TRUE;
    $validID = false;
    $countOfFields = 0;
    foreach ($fields as $key => $value) {
        if ($key == AD_HOC_REQ_ID) {
            $record = RetrieveAdHocAbsenceRequestByID($value);
            if ($record != NULL) {
                $validID = true;
                $countOfFields++;
            }
        } else {
            if ($key == AD_HOC_EMP_ID) {
                $countOfFields++;
                $record = RetrieveEmployeeByID($value);
                if ($record == NULL) {
                    $statusMessage .= "Employee specified can not be found in the " . "database.</br>";
                    error_log("Invalid AD_HOC_EMP_ID passed to " . "UpdateAdHocAbsenceRequest." . " Value=" . $value);
                    $inputIsValid = FALSE;
                }
            } else {
                if ($key == AD_HOC_START) {
                    $countOfFields++;
                    if (!isValidDate($value)) {
                        $statusMessage .= "Start date entered is not a valid date.</br>";
                        error_log("Invalid AD_HOC_START passed to UpdateAdHocAbsenceRequest." . " Value=" . $value);
                        $inputIsValid = FALSE;
                    }
                } else {
                    if ($key == AD_HOC_END) {
                        $countOfFields++;
                        if (!isValidDate($value)) {
                            $statusMessage .= "End date entered is not a valid date.</br>";
                            error_log("Invalid AD_HOC_END passed to UpdateAdHocAbsenceRequest." . " Value=" . $value);
                            $inputIsValid = FALSE;
                        }
                    } else {
                        if ($key == AD_HOC_ABSENCE_TYPE_ID) {
                            $countOfFields++;
                            $record = RetrieveAbsenceTypeByID($value);
                            if ($record == NULL) {
                                $statusMessage .= "Absence Type selected can not be found in the " . "database.</br>";
                                error_log("Invalid  AD_HOC_ABSENCE_TYPE_ID passed to " . "UpdateAdHocAbsenceRequest. Value=" . $value);
                                $inputIsValid = FALSE;
                            }
                        } else {
                            $statusMessage .= "Unknown field encountered.</br>";
                            error_log("Invalid field passed to UpdateAdHocAbsenceRequest." . " {$key}=" . $key);
                            $inputIsValid = FALSE;
                        }
                    }
                }
            }
        }
    }
    $startDate = $fields[AD_HOC_START];
    $endDate = $fields[AD_HOC_END];
    if (strtotime($endDate) < strtotime($startDate)) {
        $statusMessage .= "end Date is before start Date.</br>";
        error_log("End Date is before Start Date.");
        $inputIsValid = FALSE;
    }
    if (!$validID) {
        $statusMessage .= "No valid record ID found.</br>";
        error_log("No valid ID supplied in call to UpdateAbsenceType.");
        $inputIsValid = FALSE;
    }
    if ($countOfFields < 2) {
        $statusMessage .= "Insufficent fields supplied in call to UpdateAbsenceType.</br>";
        error_log("Insufficent fields supplied in call to UpdateAbsenceType.");
        $inputIsValid = FALSE;
    }
    //-------------------------------------------------------------------------
    // Only attempt to update a record in the database if the input parameters
    // are ok.
    //-------------------------------------------------------------------------
    $success = false;
    if ($inputIsValid) {
        $success = performSQLUpdate(ADHOC_ABSENCE_REQUEST_TABLE, AD_HOC_REQ_ID, $fields);
        if ($success) {
            $statusMessage .= "Record successfully updated.</br>";
        } else {
            $statusMessage .= "Unexpected error encountered when updating database." . "Contact your system administrator.</br>";
            $inputIsValid = false;
        }
    }
    GenerateStatus($inputIsValid, $statusMessage);
    return $success;
}
function UpdateDate($fields)
{
    //--------------------------------------------------------------------------------
    // Validate Input parameters
    //--------------------------------------------------------------------------------
    $inputIsValid = TRUE;
    $validID = false;
    $countOfFields = 0;
    foreach ($fields as $key => $value) {
        if ($key == DATE_TABLE_DATE_ID) {
            $record = RetrieveDateByID($value);
            if ($record != NULL) {
                $validID = true;
                $countOfFields++;
            }
        } else {
            if ($key == DATE_TABLE_DATE) {
                $countOfFields++;
                if (!isValidDate($value)) {
                    error_log("Invalid DATE_TABLE_DATE passed to UpdateDate.");
                    $inputIsValid = FALSE;
                }
            } else {
                if ($key == DATE_TABLE_PUBLIC_HOL_ID) {
                    $countOfFields++;
                    if ($value != NULL) {
                        $record = RetrievePublicHolidayByID($value);
                        if ($record == NULL) {
                            error_log("Invalid DATE_TABLE_PUBLIC_HOL_ID passed to UpdateDate.");
                            $inputIsValid = FALSE;
                        }
                    }
                } else {
                    error_log("Invalid field passed to UpdateDate. {$key}=" . $key);
                    $inputIsValid = FALSE;
                }
            }
        }
    }
    if (!$validID) {
        error_log("No valid ID supplied in call to UpdateDate.");
        $inputIsValid = FALSE;
    }
    if ($countOfFields < 2) {
        error_log("Insufficent fields supplied in call to UpdateDate.");
        $inputIsValid = FALSE;
    }
    //--------------------------------------------------------------------------------
    // Only attempt to update a record in the database if the input parameters are ok.
    //--------------------------------------------------------------------------------
    $success = false;
    if ($inputIsValid) {
        $success = performSQLUpdate(DATE_TABLE, DATE_TABLE_DATE_ID, $fields);
    }
    return $success;
}
function UpdateAbsenceType($fields)
{
    $statusMessage = "";
    //-------------------------------------------------------------------------
    // Validate Input parameters
    //-------------------------------------------------------------------------
    $inputIsValid = TRUE;
    $validID = false;
    $countOfFields = 0;
    foreach ($fields as $key => $value) {
        if ($key == ABS_TYPE_ID) {
            $record = RetrieveAbsenceTypeByID($value);
            if ($record != NULL) {
                $validID = true;
                $countOfFields++;
            }
        } else {
            if ($key == ABS_TYPE_NAME) {
                $countOfFields++;
                if (isNullOrEmptyString($value)) {
                    $statusMessage .= "Invalid absence type name. Can not be empty.</br>";
                    error_log("Invalid ABS_TYPE_NAME passed to UpdateAbsenceType.");
                    $inputIsValid = FALSE;
                }
            } else {
                if ($key == ABS_TYPE_USES_LEAVE) {
                    $countOfFields++;
                    if ($value != 0 and $value != 1) {
                        $statusMessage .= "Invalid uses annual leave flag value.</br>";
                        error_log("Invalid ABS_TYPE_USES_LEAVE passed to UpdateAbsenceType.");
                        $inputIsValid = FALSE;
                    }
                } else {
                    if ($key == ABS_TYPE_CAN_BE_DENIED) {
                        $countOfFields++;
                        if ($value != 0 and $value != 1) {
                            $statusMessage .= "Invalid can be denied flag value.</br>";
                            error_log("Invalid ABS_TYPE_CAN_BE_DENIED passed to UpdateAbsenceType.");
                            $inputIsValid = FALSE;
                        }
                    } else {
                        $statusMessage .= "Invalid field encountered.</br>";
                        error_log("Invalid field passed to UpdateAbsenceType. {$key}=" . $key);
                        $inputIsValid = FALSE;
                    }
                }
            }
        }
    }
    if (!$validID) {
        $statusMessage .= "No valid ID supplied.</br>";
        error_log("No valid ID supplied in call to UpdateAbsenceType.");
        $inputIsValid = FALSE;
    }
    if ($countOfFields < 2) {
        $statusMessage .= "Insufficent fields supplied in call.</br>";
        error_log("Insufficent fields supplied in call to UpdateAbsenceType.");
        $inputIsValid = FALSE;
    }
    //--------------------------------------------------------------------------------
    // Only attempt to update a record in the database if the input parameters are ok.
    //--------------------------------------------------------------------------------
    $success = false;
    if ($inputIsValid) {
        $success = performSQLUpdate(ABSENCE_TYPE_TABLE, ABS_TYPE_ID, $fields);
        if ($success) {
            $statusMessage .= "Record successfully created in Database.</br>";
        } else {
            $statusMessage .= "Unexpected database error encountered when " . "trying to perform update.</br>";
            $inputIsValid = false;
        }
    }
    GenerateStatus($inputIsValid, $statusMessage);
    return $success;
}
function UpdateApprovedAbsenceBookingDate($fields)
{
    //--------------------------------------------------------------------------------
    // Validate Input parameters
    //--------------------------------------------------------------------------------
    $inputIsValid = TRUE;
    $validID = false;
    $countOfFields = 0;
    foreach ($fields as $key => $value) {
        if ($key == APPR_ABS_BOOK_DATE_ID) {
            $record = RetrieveApprovedAbsenceBookingDateByID($value);
            if ($record != NULL) {
                $validID = true;
                $countOfFields++;
            }
        } else {
            if ($key == APPR_ABS_BOOK_DATE_DATE_ID) {
                $countOfFields++;
                $record = RetrieveDateByID($value);
                if ($record == NULL) {
                    error_log("Invalid APPR_ABS_BOOK_DATE_DATE_ID passed to " . "UpdateApprovedAbsenceBookingDate. Value=" . $value);
                    $inputIsValid = FALSE;
                }
            } else {
                if ($key == APPR_ABS_BOOK_DATE_ABS_BOOK_ID) {
                    $countOfFields++;
                    $record = RetrieveApprovedAbsenceBookingByID($value);
                    if ($record == NULL) {
                        error_log("Invalid APPR_ABS_BOOKING_ID passed to " . "UpdateApprovedAbsenceBookingDate. Value=" . $value);
                        $inputIsValid = FALSE;
                    }
                } else {
                    error_log("Invalid field passed to UpdateApprovedAbsenceBookingDate." . " {$key}=" . $key);
                    $inputIsValid = FALSE;
                }
            }
        }
    }
    if (!$validID) {
        error_log("No valid ID supplied in call to UpdateApprovedAbsenceBookingDate.");
        $inputIsValid = FALSE;
    }
    if ($countOfFields < 2) {
        error_log("Insufficent fields supplied in call to UpdateApprovedAbsenceBookingDate.");
        $inputIsValid = FALSE;
    }
    //--------------------------------------------------------------------------------
    // Only attempt to update a record in the database if the input parameters are ok.
    //--------------------------------------------------------------------------------
    $success = false;
    if ($inputIsValid) {
        $success = performSQLUpdate(APPROVED_ABSENCE_BOOKING_DATE, APPR_ABS_BOOK_DATE_ID, $fields);
    }
    return $success;
}