case 'byRating': if ($type == "myFridge") { recipes($username); } else { if ($type == "quick") { quickRecipes(15); } else { 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;
} //PUT: Update a recipe } else { if ($_SERVER['REQUEST_METHOD'] == 'PUT') { $recipe = file_get_contents("php://input"); $recipe = json_decode($recipe, true); require_once "updateRecipe.php"; $recipe = putRecipe($recipe); //DROP: drop one recipe(takes slug) } else { if ($_SERVER['REQUEST_METHOD'] == 'DELETE') { //Angular and ajax calls sends json files via with: file_get_contents("php://input") //explode splits up an array, this will split it at each slash (/) so that recipe[4] contains the slug $recipe = explode("/", $_SERVER['REQUEST_URI']); //saves the slug into recipe $recipeSlug = $recipe[4]; $recipe = json_encode($recipe); /*Writes to file "input-data.json"*/ /*If we want to keep backup of deleted files we can get them now and print to file before deleting*/ require_once "oneRecipe.php"; $backup = getRecipe($recipeSlug); $backup = json_encode($backup, JSON_PRETTY_PRINT); $file_handle = fopen('backup.json', 'a+'); fwrite($file_handle, $backup); fclose($file_handle); require_once "dropRecipe.php"; dropRecipe($recipeSlug); } } } }