$processed = false;
try {
    $dbConnection = DatabaseUtilities::getDatabaseConnection();
    //Get the current user's ID and details.
    $memberID = LoginController::getLoggedInMemberID($dbConnection);
    if ($memberID == null) {
        header("Location: login.php");
        exit;
    } else {
        $searchType = $_GET[SearchConstants::SEARCH_TYPE_INPUT_ID];
        switch ($searchType) {
            case AdvertisementSearchConstants::QUICK_SEARCH_ID:
                $advertisementSearchResults = AdvertisementSearchController::searchAdvertisements($_GET[AdvertisementSearchConstants::FOR_INPUT_ID], $_GET[AdvertisementSearchConstants::POSITION_INPUT_ID], $_GET[LocationConstants::LOCATION_COUNTRY_INPUT_ID], $_GET[LocationConstants::LOCATION_STATE_INPUT_ID], $_GET[LocationConstants::LOCATION_CITY_INPUT_ID], $_GET[LocationConstants::LOCATION_REGION_INPUT_ID], $searchType, $_GET[SearchConstants::CURRENT_PAGE_ID], $_GET[SearchConstants::PAGING_AMOUNT_ID], $dbConnection);
                break;
            case AdvertisementSearchConstants::ADVANCED_SEARCH_ID:
                $advertisementSearchResults = AdvertisementSearchController::searchAdvertisementsAdvanced($_GET[AdvertisementSearchConstants::FOR_INPUT_ID], $_GET[AdvertisementSearchConstants::POSITION_INPUT_ID], $_GET[AdvertisementSearchConstants::GENRE_INPUT_ID], $_GET[AdvertisementSearchConstants::INSPIRATIONS_INPUT_ID], $_GET[AdvertisementSearchConstants::DURATION_INPUT_ID], $_GET[AdvertisementSearchConstants::EXPERIENCE_INPUT_ID], $_GET[AdvertisementSearchConstants::GENDER_INPUT_ID], $_GET[AdvertisementSearchConstants::AGE_INPUT_ID], $_GET[LocationConstants::LOCATION_COUNTRY_INPUT_ID], $_GET[LocationConstants::LOCATION_STATE_INPUT_ID], $_GET[LocationConstants::LOCATION_CITY_INPUT_ID], $_GET[LocationConstants::LOCATION_REGION_INPUT_ID], $searchType, $_GET[SearchConstants::CURRENT_PAGE_ID], $_GET[SearchConstants::PAGING_AMOUNT_ID], $dbConnection);
                break;
        }
        //If member details cannot be obtained, error
        if ($advertisementSearchResults != null) {
            $advertisementSearchParameters = $advertisementSearchResults->getVariable(SearchResults::SEARCH_PARAMETERS);
            $processed = true;
        }
    }
} catch (Exception $ex) {
    $processed = false;
}
$dbConnection = null;
if (!$processed) {
    ErrorUtilities::errorRedirect(ErrorConstants::GENERAL_ERROR);
} else {
$processed = false;
try {
    $dbConnection = DatabaseUtilities::getDatabaseConnection();
    //Get the current user's ID and details.
    $memberID = LoginController::getLoggedInMemberID($dbConnection);
    if ($memberID == null) {
        header("Location: login.php");
        exit;
    } else {
        $searchType = $_GET[SearchConstants::SEARCH_TYPE_INPUT_ID];
        switch ($searchType) {
            case AdvertisementBrowseConstants::ADVERTISEMENT_TYPE_SEARCH_ID:
                $advertisementSearchResults = AdvertisementSearchController::browseAdvertisementsByType($_GET[AdvertisementBrowseConstants::ADVERTISEMENT_TYPE_INPUT_ID], $searchType, $_GET[SearchConstants::CURRENT_PAGE_ID], $_GET[SearchConstants::PAGING_AMOUNT_ID], $dbConnection);
                break;
            case AdvertisementBrowseConstants::LOCATION_SEARCH_ID:
                $advertisementSearchResults = AdvertisementSearchController::browseAdvertisementByLocation($_GET[LocationConstants::LOCATION_COUNTRY_INPUT_ID], $_GET[LocationConstants::LOCATION_STATE_INPUT_ID], $_GET[LocationConstants::LOCATION_CITY_INPUT_ID], $_GET[LocationConstants::LOCATION_REGION_INPUT_ID], $searchType, $_GET[SearchConstants::CURRENT_PAGE_ID], $_GET[SearchConstants::PAGING_AMOUNT_ID], $dbConnection);
                break;
        }
        if ($advertisementSearchResults != null) {
            $advertisementSearchParameters = $advertisementSearchResults->getVariable(SearchResults::SEARCH_PARAMETERS);
            $processed = true;
        }
    }
} catch (Exception $ex) {
    $processed = false;
}
$dbConnection = null;
if (!$processed) {
    ErrorUtilities::errorRedirect(ErrorConstants::ADVERTISEMENT_VIEW_ERROR);
} else {
    require_once $config->getIncludeURL(Config::INCLUDES_PATH, "views%advertisements%browse_advertisements_results_view.php");
    $dbConnection = DatabaseUtilities::getDatabaseConnection();
    //Get the current user's ID and details.
    $memberID = LoginController::getLoggedInMemberID($dbConnection);
    if ($memberID == null) {
        header("Location: login.php");
        exit;
    } else {
        $currentPage = 1;
        $pagingAmount = 10;
        if (isset($_GET[SearchConstants::PAGING_AMOUNT_ID])) {
            $pagingAmount = $_GET[SearchConstants::PAGING_AMOUNT_ID];
        }
        if (isset($_GET[SearchConstants::PAGING_AMOUNT_ID])) {
            $currentPage = $_GET[SearchConstants::CURRENT_PAGE_ID];
        }
        $advertisementSearchResults = AdvertisementSearchController::searchAdvertisementsByMemberID($memberID, $currentPage, $pagingAmount, $dbConnection);
        //If member details cannot be obtained, error
        if ($advertisementSearchResults == null) {
            $errorCode = 1;
        } else {
            $advertisementSearchParameters = $advertisementSearchResults->getVariable(SearchResults::SEARCH_PARAMETERS);
            $processed = true;
        }
    }
} catch (Exception $ex) {
    $processed = false;
    $errorCode = 1;
}
$dbConnection = null;
if (!$processed) {
    ErrorUtilities::errorRedirect($errorCode);