diff options
Diffstat (limited to 'kalorien_zaehler/lebensmittel_hinzufuegen.php')
| -rwxr-xr-x | kalorien_zaehler/lebensmittel_hinzufuegen.php | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/kalorien_zaehler/lebensmittel_hinzufuegen.php b/kalorien_zaehler/lebensmittel_hinzufuegen.php new file mode 100755 index 0000000..51f61c8 --- /dev/null +++ b/kalorien_zaehler/lebensmittel_hinzufuegen.php @@ -0,0 +1,139 @@ +<?php +/* error_reporting(E_ALL); +ini_set('display_errors', 1); */ + +if ($lebensmittel_id = $_POST['lebensmittel_auswahl']) { + + $datenbank = new mysqli('localhost', 'root', 'sexyweyer', 'Annapurna'); + $response = $datenbank->query("SELECT * FROM lebensmittel WHERE lebensmittel_id = '$lebensmittel_id';"); + + if ($result = $response->fetch_assoc()) { + $namen = $result['namen']; + $kalorien = $result['kalorien']; + $kohlenhydrate = $result['kohlenhydrate']; + $fett = $result['fett']; + $protein = $result['protein']; + $zucker = $result['zucker']; + } else { + $url = 'https://api.webapp.prod.blv.foodcase-services.com/BLV_WebApp_WS/webresources/BLV-api/food/' . $lebensmittel_id . '?lang=de'; + + $ch = curl_init(); + $curl_options = [ + CURLOPT_URL => $url, + CURLOPT_HEADER => false, + CURLOPT_RETURNTRANSFER => true, + ]; + curl_setopt_array($ch, $curl_options); + $response = curl_exec($ch); + + curl_close($ch); + + $result = json_decode($response, true); + + $namen = $result['name']; + $werte = $result['values']; + + foreach ($werte as $wert) { + if ($wert['component']['code'] == 'ENERCC') { + $kalorien = $wert['value']; + } else if ($wert['component']['code'] == 'CHO') { + $kohlenhydrate = $wert['value']; + } else if ($wert['component']['code'] == 'FAT') { + $fett = $wert['value']; + } else if ($wert['component']['code'] == 'PROT625') { + $protein = $wert['value']; + } else if ($wert['component']['code'] == 'SUGAR') { + $zucker = $wert['value']; + } + } + $datenbank->query("INSERT INTO lebensmittel VALUES ('$lebensmittel_id', '$namen', '$kalorien', '$kohlenhydrate', '$fett', '$protein', '$zucker')"); + } +} +?> + +<!DOCTYPE html> +<html lang="de"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Lebensmittel hinzufügen</title> + <link rel="icon" type="image/x-icon" href="/style/avocado.png"> + <link rel="stylesheet" type="text/css" href="/style/style.css"> +</head> + +<body> + +<nav class="medium_box"> + <ul class="hor_spacing"> + <li class="hor_spacing_item"> + <a class="small_box color_inverse_on_hover" href="/login">Login</a> + </li> + <li class="hor_spacing_item"> + <a class="small_box color_inverse_on_hover" href="/kalorien_rechner">Kalorien-rechner</a> + </li> + <li class="hor_spacing_item"> + <a class="small_box tertiary_color_style" href="/kalorien_zaehler">Kalorien-zähler</a> + </li> + <li class="hor_spacing_item"> + <a class="small_box color_inverse_on_hover" href="/rezepte">Rezepte</a> + </li> + <li class="hor_spacing_item"> + <a class="small_box color_inverse_on_hover" href="/workouts">Workouts</a> + </li> + </ul> +</nav> + +<main class="big_box hor_spacing"> + + <h1><?= $namen ?></h1> + + <div class="hor_spacing"> + <div class="flexbox hor_spacing_item"> + <div class="medium_box" style="flex: 1"> + <h2 style="margin: 0">Kohlenhydrate</h2> + <div style="font-size: 100px"><?= $kohlenhydrate ?></div> + <h2 style="margin: 0">gramm / 100 gramm</h2> + </div> + <div class="medium_box" style="flex: 1"> + <h2 style="margin: 0">Protein</h2> + <div style="font-size: 100px"><?= $protein ?></div> + <h2 style="margin: 0">gramm / 100 gramm</h2> + </div> + <div class="medium_box" style="flex: 1"> + <h2 style="margin: 0">Fett</h2> + <div style="font-size: 100px"><?= $fett ?></div> + <h2 style="margin: 0">gramm / 100 gramm</h2> + </div> + </div> + <div class="flexbox hor_spacing_item"> + <div class="medium_box" style="flex: 1"> + <h2 style="margin: 0">Zucker</h2> + <div style="font-size: 100px"><?= $zucker ?></div> + <h2 style="margin: 0">gramm / 100 gramm</h2> + </div> + <div class="medium_box" style="flex: 2"> + <h2 style="margin: 0">Kalorien</h2> + <div style="font-size: 100px"><?= $kalorien ?></div> + <h2 style="margin: 0">gramm / 100 gramm</h2> + </div> + <a class="medium_box color_inverse_on_hover" style="flex: 1" href="<?= 'https://api.webapp.prod.blv.foodcase-services.com/BLV_WebApp_WS/webresources/BLV-api/food/' . $lebensmittel_id . '?lang=de' ?>" target="_blank"> + <h2 style="margin: 0">auf</h2> + <div style="font-size: 100px">API</div> + <h2 style="margin: 0">zugreifen</h2> + </a> + </div> + </div> +</main> + +<main class="big_box"> + <h1><?= $namen ?> hinzufügen</h1> + <form class="flexbox" action="./index.php" method="POST"> + <div class="medium_box" style="flex: 1"> + <h2 style="display: inline">Menge (in gramm): </h2><input class="small_box color_inverse_on_hover" type="number" name="menge" min="1" max="10000" step="1" required> g + </div> + <button class="medium_box color_inverse_on_hover" style="flex: 1" type="submit" name="lebensmittel_hinzufuegen" value="<?= $lebensmittel_id ?>"><h2 style="margin: 0">Mahlzeit hinzufügen</h2></button> + </form> +</main> + +</body> +</html> |
