function addRecipe()
{
    if (isset($_POST['namn_ratt']) and isset($_POST['namn_ratt']) and isset($_POST['namn_ratt']) and isset($_POST['namn_ratt']) and isset($_POST['namn_ratt']) and isset($_POST['namn_ratt']) and isset($_POST['procedure']) and isset($_POST['description'])) {
        echo "Rätt:" . $_POST['namn_ratt'];
        echo "<br/>";
        echo "Kategori:" . $_POST['category'];
        echo "<br/>";
        echo "Tillagningstid:" . $_POST['Tillagningstid'];
        echo "<br/>";
        echo "Serveringsmangd_antal:" . $_POST['Serveringsmangd_antal'];
        echo "<br/>";
        echo "Serveringsmangd_enhet:" . $_POST['Serveringsmangd_enhet'];
        echo "<br/>";
        echo "Svarighet:" . $_POST['Svarighet'];
        echo "<br/>";
        $query = insertNewFoodQuery($_POST['namn_ratt'], $_POST['category'], $_POST['Svarighet'], $_POST['Tillagningstid'], $_POST['description'], $_POST['procedure']);
        $id = executeInsertQuery($query);
        /*echo "Ingrediens:" . $_POST['Ingrediens'][0];
        		echo "<br/>";
        		echo "Ingrediens:" . $_POST['Ingrediens'][1];
        		echo "<br/>";*/
        //echo "Antal Ingredienser: " . sizeof($_POST['Ingrediens']);
        //echo "Ingredient: " . $_POST['Ingrediens'][0][0] ."<br/>";
        if (isset($_POST['Ingrediens'])) {
            $c = count($_POST['Ingrediens']);
            for ($i = 0; $i < $c; $i++) {
                if (!empty($_POST['Ingrediens'][0][$i])) {
                    if ($id > 0) {
                        $query = insertIngredientForFoodByIdQuery($id, $_POST['Ingrediens'][0][$i], $_POST['Ingrediens'][1][$i], $_POST['Ingrediens'][2][$i]);
                        executeInsertQuery($query);
                        echo "<br/>";
                        echo "Ingrediens nr {$i} <br/>";
                        echo "Namn: " . $_POST['Ingrediens'][0][$i] . "<br/>";
                        echo "Mängd: " . $_POST['Ingrediens'][1][$i] . "<br/>";
                        echo "Måttenhet: " . $_POST['Ingrediens'][2][$i] . "<br/>";
                        echo "<br/>";
                    }
                }
            }
        }
        checkForRecipeImage();
    } else {
        echo "Invalid form!";
    }
}
Esempio n. 2
0
function getFoodValues()
{
    $food_values = null;
    if (isset($_SESSION['food'])) {
        //testa om användare tryckte på ångra eller Spara Recept if(
        $food_values = $_SESSION['food'];
        //
        if (isset($_REQUEST['saveRecipe'])) {
            $food_values['save'] = "save";
            unset($_SESSION['food']);
        }
        if (isset($_SESSION['food']['image'])) {
            if (file_exists($_SESSION['food']['image'])) {
                unlink($_SESSION['food']['image']);
            }
        }
        unset($_SESSION['food']);
        /*else
        		{
        			if(isset($_SESSION['food']['image']))
        			{
        				unlink($_SESSION['food']['image']);
        			}
        			unset($_SESSION['food']);
        		}*/
        /*else if(isset($_REQUEST['changeRecipe']))
        		{
        			$food_values['reverse'] = "reverse";
        			//unlink($_SESSION['food']['image']);
        			unset($_SESSION['food']);
        		}*/
    }
    //Om användaren har speciefierat ett recepts innehåll
    if (isset($_POST['namn_ratt']) and isset($_POST['namn_ratt']) and isset($_POST['namn_ratt']) and isset($_POST['namn_ratt']) and isset($_POST['namn_ratt']) and isset($_POST['namn_ratt']) and isset($_POST['procedure']) and isset($_POST['description'])) {
        $food_values['category'] = $_POST['category'];
        $food_values['name'] = $_POST['namn_ratt'];
        $food_values['difficulty'] = $_POST['Svarighet'];
        $food_values['cookingTime'] = $_POST['Tillagningstid'];
        $food_values['description'] = $_POST['description'];
        $food_values['procedure'] = $_POST['procedure'];
        $food_values['image'] = checkForRecipeImage();
        $food_values['added'] = "2013-12-04";
        //TODO fixa till
        $food_values['portions'] = $_POST['Serveringsmangd_antal'];
        $food_values['portionType'] = $_POST['Serveringsmangd_enhet'];
        //Om ingredienser finns tillagda för receptet
        if (isset($_POST['Ingrediens'])) {
            $food_values['ingredient'] = $_POST['Ingrediens'];
        }
        if (isset($_SESSION['food'])) {
            //ta bort sessions bilden
            //TODO ta bort bild från server
        }
        $_SESSION['food'] = $food_values;
    } elseif (isset($_REQUEST['site']) and isset($_REQUEST['byId'])) {
        $food_values['identifier'] = $_REQUEST['byId'];
    } elseif (isset($_POST['searchRecipe'])) {
        $food_values['searchRecipe'] = true;
        if (isset($_POST['sok_kategori']) and isset($_POST['Tillagningstid']) and isset($_POST['Svarighet']) and isset($_POST['har_bild'])) {
            $food_values['category'] = $_POST['sok_kategori'];
            $food_values['cookingTime'] = $_POST['Tillagningstid'];
            $food_values['difficulty'] = $_POST['Svarighet'];
            $food_values['has_image'] = $_POST['har_bild'];
        }
        $food_values['name'] = "";
        $food_values['description'] = "ff";
        $food_values['procedure'] = "aadad";
        if (isset($_POST['Ingrediens'])) {
            $food_values['ingredient'] = $_POST['Ingrediens'];
        }
    }
    /*elseif(isset($_REQUEST['submit']))
    		{
    			if($_REQUEST['submit'] == "Visa")
    			{
    				$food_values['searchRecipe'] = true;
    			}
    		}*/
    return $food_values;
}