예제 #1
0
 $action = $_POST['action'];
 switch ($action) {
     case 'getRecipe':
         getRecipeById();
         break;
     case 'getByCategory':
         getRecipesByCategory();
         break;
     case 'getWeeklyRecipe':
         getWeeklyRecipe();
         break;
     case 'getTopWriters':
         getTopWriters();
         break;
     case 'saveRecipe':
         saveRecipe();
         break;
     case 'like':
         addFavorite();
         break;
     case 'getFavorites':
         getFavorites();
         break;
     case 'getMyRecipes':
         getMyRecipes();
         break;
     case 'logout':
         logout();
         break;
 }
 if (isset($connection)) {
예제 #2
0
                    searchRecipes($type);
                }
            }
            break;
        case 'getRecipesList':
            recipes($username);
            break;
        case 'recipeDetails':
            getRecipe($recipeId);
            break;
        case 'saveRecipe':
            $id = $_POST['id'];
            $name = $_POST['name'];
            $ingredients = stripslashes($_POST['ingredients']);
            $pic_url = $_POST['pic'];
            saveRecipe($id, $name, $username, $pic_url, $ingredients);
            break;
        case 'getOuickRecipes':
            quickRecipes(15);
            break;
        case 'searchRecipes':
            $searchParam = $_POST['search'];
            searchRecipes($searchParam);
            break;
    }
}
$data;
$prods = array();
$amount = array();
$unit = array();
$expiry = array();
예제 #3
0
//run the correct methods for each action
//GET(slug), GET, POST, PUT(SLUG) and DROP(SLUG)
//Post: Add one new recipe, takes a json object
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    //Angular and ajax calls sends json files via with: file_get_contents("php://input")
    $recipe = file_get_contents("php://input");
    $recipe = json_decode($recipe, true);
    /*Writes to file "input-data.json"*/
    /*$test = $recipe['recipeTitle'];
    	$json_string = $test;
    	$file_handle = fopen('input-data.json', 'w');
    	fwrite($file_handle, $json_string);
    	fclose($file_handle);*/
    require_once "saveRecipe.php";
    saveRecipe($recipe);
    //Get: get one or all recipes
} else {
    if ($_SERVER['REQUEST_METHOD'] == 'GET') {
        //(GET) Return ONE recipe in json
        if (isset($_GET["slug"])) {
            require_once "oneRecipe.php";
            $recipe = array();
            //run getRecipe(slug) from oneRecipe.php
            $recipe = getRecipe($_GET["slug"]);
            echo json_encode($recipe, JSON_PRETTY_PRINT);
            /*Testdata
            	$recipe['slug'] = $_GET["slug"];
            	$recipe['description'] = "Vestibulum ullamcorper dolor at consectetur sagittis. Integer suscipit quis erat nec auctor. Proin sit amet nunc sit amet elit dignissim aliquam. Nullam euismod in diam a tristique. Nulla at leo non turpis interdum bibendum eget cursus magna. Integer pulvinar suscipit eros a suscipit. Vivamus finibus commodo ligula, a vehicula sem efficitur non. Nullam neque odio, mollis sit amet faucibus in, vehicula at ipsum.";*/
            //(GET) Return ALL the recipes in json
        } else {