function CreateAbsenceTypeTable()
{
    $sql = "CREATE TABLE IF NOT EXISTS `mydb`.`absenceTypeTable` (\n         `absenceTypeID` INT NOT NULL AUTO_INCREMENT,\n         `absenceTypeName` VARCHAR(20) NOT NULL,\n         `usesAnnualLeave` TINYINT(1) NOT NULL,\n         `canBeDenied` TINYINT(1) NOT NULL,\n         PRIMARY KEY (`absenceTypeID`));";
    $success = performSQL($sql);
    if ($success) {
        //Check to see if the table is empty
        if (GetAbsenceTypeCount() == 0) {
            //Table is empty. Create some default absence types.
            CreateAbsenceType(ANNUAL_LEAVE, TRUE, TRUE);
        }
    }
}
function DeleteMainVacationRequest($ID)
{
    $result = 0;
    $record = RetrieveMainVacationRequestByID($ID);
    if ($record != NULL) {
        $employee = RetrieveEmployeeByID($record[MAIN_VACATION_EMP_ID]);
        if ($employee) {
            $employee[EMP_MAIN_VACATION_REQ_ID] = NULL;
            UpdateEmployee($employee);
        }
        $sql = "DELETE FROM mainVacationRequestTable WHERE mainVacationRequestID=" . $ID . ";";
        $result = performSQL($sql);
    }
    return $result;
}
function DeleteEmployee($ID)
{
    $result = 0;
    $statusMessage = "";
    $employee = RetrieveEmployeeByID($ID);
    if ($employee != NULL) {
        if ($employee[EMP_MAIN_VACATION_REQ_ID] != NULL) {
            DeleteMainVacatioNRequest($employee[EMP_MAIN_VACATION_REQ_ID]);
        }
        $filter[AD_HOC_EMP_ID] = $ID;
        $adHocAbsenceRequests = RetrieveAdHocAbsenceRequests($filter);
        foreach ((array) $adHocAbsenceRequests as $value) {
            DeleteAdHocAbsenceRequest($value[AD_HOC_REQ_ID]);
        }
        unset($filter);
        $filter[APPR_ABS_EMPLOYEE_ID] = $ID;
        $approvedAbsenceBookings = RetrieveApprovedAbsenceBookings($filter);
        if ($approvedAbsenceBookings != NULL) {
            foreach ($approvedAbsenceBookings as $value) {
                DeleteApprovedAbsenceBooking($value[APPR_ABS_BOOKING_ID]);
            }
        }
        $sql = "DELETE FROM employeeTable WHERE employeeID=" . $ID . ";";
        $result = performSQL($sql);
        $statusMessage .= "Record deleted.</br>";
        GenerateStatus(true, $statusMessage);
    }
    return $result;
}
function DeletePublicHoliday($ID)
{
    $result = 0;
    $record = RetrievePublicHolidayByID($ID);
    if ($record != NULL) {
        $date = RetrieveDateByID($record[PUB_HOL_DATE_ID]);
        $date[DATE_TABLE_PUBLIC_HOL_ID] = NULL;
        UpdateDate($date);
        $sql = "DELETE FROM publicHolidayTable WHERE publicHolidayID=" . $ID . ";";
        $result = performSQL($sql);
    }
    GenerateStatus(true, "Record successfully deleted.");
    return $result;
}
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;
}
function DeleteApprovedAbsenceBooking($ID)
{
    $result = 0;
    $approvedAbsenceBooking = RetrieveApprovedAbsenceBookingByID($ID);
    if ($approvedAbsenceBooking != NULL) {
        $sql = "DELETE FROM approvedAbsenceBookingTable WHERE approvedAbsenceBookingID=" . $ID . ";";
        $result = performSQL($sql);
        $filter[APPR_ABS_BOOK_DATE_ABS_BOOK_ID] = $ID;
        $approvedAbsenceBookingDates = RetrieveApprovedAbsenceBookingDates($filter);
        foreach ((array) $approvedAbsenceBookingDates as $approvedAbsenceBookingDate) {
            DeleteApprovedAbsenceBookingDate($approvedAbsenceBookingDate[APPR_ABS_BOOK_DATE_ID]);
        }
    }
    GenerateStatus(true, "Record successfully deleted.");
    return $result;
}
function DeleteAdHocAbsenceRequest($ID)
{
    $sql = "DELETE FROM adHocAbsenceRequestTable WHERE adHocAbsenceRequestID=" . $ID . ";";
    GenerateStatus(true, "Record successfully deleted");
    return performSQL($sql);
}
function CreateDB()
{
    $sql = "CREATE SCHEMA IF NOT EXISTS `mydb`" . "DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;";
    performSQL($sql);
}
function DeleteDate($ID)
{
    $result = 0;
    $date = RetrieveDateByID($ID);
    if ($date != NULL) {
        $filter[APPR_ABS_BOOK_DATE_DATE_ID] = $date[DATE_TABLE_DATE_ID];
        $approvedAbsenceBookingDates = RetrieveApprovedAbsenceBookingDates($filter);
        if ($approvedAbsenceBookingDates != NULL) {
            foreach ($approvedAbsenceBookingDates as $value) {
                DeleteApprovedAbsenceBooking($value[APPR_ABS_BOOK_DATE_ABS_BOOK_ID]);
            }
        }
        if ($date[DATE_TABLE_PUBLIC_HOL_ID] != NULL) {
            DeletePublicHoliday($date[DATE_TABLE_PUBLIC_HOL_ID]);
        }
        $sql = "DELETE FROM dateTable WHERE dateID=" . $ID . ";";
        $result = performSQL($sql);
    }
    return $result;
}
function DeleteApprovedAbsenceBookingDate($ID)
{
    $result = 0;
    $record = RetrieveApprovedAbsenceBookingDateByID($ID);
    if ($record != NULL) {
        $sql = "DELETE FROM approvedAbsenceBookingDate WHERE approvedAbsenceBookingDateID=" . $ID . ";";
        $result = performSQL($sql);
    }
    return $result;
}