$recipes = new Recipe();
$new_recepies = new Recipe();
$order = 0;
// Keeps track of the asc, desc order.
// using the Recipe model, retrieve an array of recipes
$recipes = Recipe::findAll($dbh);
// get querystring data (part 2)
if ($_GET) {
    if (array_key_exists('sort', $_GET)) {
        // Explode the value and get the name of the column to be sorted, and the $order it should sort it.
        $arr = explode('_', $_GET['sort']);
        $column = $arr[0];
        $order = $arr[1];
        $recipes = Recipe::findAll($dbh, $column, $order);
        if ($order == 0) {
            $order = 1;
        } else {
            $order = 0;
        }
    }
}
// get form data (part 3)
if ($_POST) {
    // Get the string from $_POST, and search for that string in the database.
    if (array_key_exists("terms", $_POST)) {
        $keyWord = $_POST["terms"];
        $recipes = Recipe::findByKeyword($dbh, $keyWord);
    }
}
// require the view
require_once "views/view_recipes.php";
    }
}
//Determining whether the field is Name, Prep Time, Total Time, and Rating
if (isset($_GET['field'])) {
    if ($_GET['field'] == 'Name') {
        $fieldName = "Name";
    } else {
        if ($_GET['field'] == 'Prep') {
            $fieldName = "Prep";
        } else {
            if ($_GET['field'] == 'Total') {
                $fieldName = "Total";
            } else {
                if ($_GET['field'] == 'Rating') {
                    $fieldName = "Rating";
                }
            }
        }
    }
}
// get form data (part 3)
//If user clicks button, this happens
if ($_POST) {
    $searching = $_POST["terms"];
    $recipes = Recipe::findByKeyword($dbh, $searching, true);
    require_once "views/view_recipes.php";
} else {
    $recipes = Recipe::findAll($dbh, $sortingTitle, $fieldName, true);
    // require the view
    require_once "views/view_recipes.php";
}
Beispiel #3
0
require_once "models/Ingredient.php";
require_once "models/units_of_measure.php";
// get querystring data (part 2)
$recipe = Recipe::findAll($dbh);
$newRecipe;
if (isset($_GET['Details'])) {
    $viewID = $_GET['Details'];
    require_once "ShowRecipe.php";
    $newRecipe = 0;
    die;
} else {
    if (isset($_GET['order'])) {
        $recipe = Recipe::sortBy($dbh, $_GET['order']);
    } else {
        if (isset($_GET['addRecipe'])) {
            //$ing = Ingredient::sortIngredientASC($dbh);
            //$units = units_of_measure::sortUnitsASC($dbh);
            $ing = Ingredient::findAll($dbh);
            $units = units_of_measure::findAll($dbh);
            $newRecipe = 1;
            require_once "EditRecipe.php";
            die;
        }
    }
}
if ($_POST) {
    if (array_key_exists('terms', $_POST)) {
        $recipe = Recipe::findByKeyword($dbh, $_POST['terms']);
    }
}
require_once "views/view_recipes.php";