summaryrefslogtreecommitdiff
path: root/kalorien_zaehler/lebensmittel_hinzufuegen.php
blob: 51f61c8ef80141959bcf842d38602d4157f8683d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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>