function pageController($dbc)
{
    if (isset($_GET['ad-id'])) {
        $oneAd = Ad::adWithAllFields($_GET['ad-id']);
    } else {
        header("Location: ads.index.php");
        die;
    }
    $ad = $oneAd->getAttributes();
    $ad['keywords'] = implode(', ', $ad['keywords']);
    $ad['price'] = '$' . number_format($ad['price'], 2, '.', ',');
    $ad['date_posted'] = new DateTime($ad['date_posted']);
    $ad['date_posted'] = $ad['date_posted']->format('F d, Y');
    // var_dump($ad);
    return array('ad' => $ad);
}
function pageController($dbc)
{
    $errors = [];
    $keywords = [];
    $categoryResults = Ad::getAllCategories();
    foreach ($categoryResults as $category) {
        $categories[] = $category['category'];
    }
    if (Input::has('ad-id')) {
        $oneAd = Ad::adWithAllFields(Input::getNumber('ad-id'));
    } else {
        header("Location: ads.index.php");
        die;
    }
    $ad = $oneAd->getAttributes();
    $keyword = array_values($ad);
    var_dump('$_POST');
    var_dump($_POST);
    if (isset($_POST)) {
        try {
            $title = Input::getString('title');
        } catch (Exception $e) {
            array_push($errors, $e->getMessage());
        }
        try {
            $description = Input::getString('description');
        } catch (Exception $e) {
            array_push($errors, $e->getMessage());
        }
        try {
            $price = Input::getNumber('price');
        } catch (Exception $e) {
            array_push($errors, $e->getMessage());
        }
        try {
            $keyword_1 = Input::getString('keyword_1');
        } catch (Exception $e) {
            array_push($errors, $e->getMessage());
        }
        try {
            $keyword_2 = Input::getString('keyword_2');
        } catch (Exception $e) {
            array_push($errors, $e->getMessage());
        }
        try {
            $keyword_3 = Input::getString('keyword_3');
        } catch (Exception $e) {
            array_push($errors, $e->getMessage());
        }
    }
    if (isset($_POST['keyword_1'])) {
        $keywords[0] = $_POST['keyword_1'];
    } else {
        if (isset($keyword[7][1])) {
            $keywords[0] = $keyword[7][1];
        } else {
            $keywords[0] = '';
        }
    }
    if (isset($_POST['keyword_2'])) {
        $keywords[1] = $_POST['keyword_2'];
    } else {
        if (isset($keyword[7][2])) {
            $keywords[1] = $keyword[7][2];
        } else {
            $keywords[1] = '';
        }
    }
    if (isset($_POST['keyword_3'])) {
        $keywords[2] = $_POST['keyword_3'];
    } else {
        if (isset($keyword[7][3])) {
            $keywords[2] = $keyword[7][3];
        } else {
            $keywords[2] = '';
        }
    }
    var_dump('$ad');
    var_dump($ad);
    var_dump('$errors');
    var_dump($errors);
    if (empty($errors)) {
        try {
            Ad::updateAds(Input::getNumber('ad-id'), $title, $description, $price);
            Keyword::updateKeywords(Input::getNumber('ad-id'), $keywords[0], $keywords[1], $keywords[2]);
            var_dump($keywords);
        } catch (Exception $e) {
            echo 'Error';
            // $_SESSION
        }
    }
    return array('ad' => $ad, 'categories' => $categories, 'keywords' => $keywords, 'errors' => $errors);
}