summaryrefslogtreecommitdiff
path: root/index.php
blob: 840d987df9f23715fa2d798690b064381ce8b6ee (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
error_reporting(E_ALL);
$GLOBALS["days"]= array("Mon","Tue","Wed","Thur","Fri","Sat","Sun");
$GLOBALS["meals"] = array("*" ,"mj spghet", "mj curry","chilli",
                          "stir fry","jacket beans","mash",
                          "vesto/egg", "fast ramen", "ramen",
                          "tomato soup","squash soup","bean soup",
                          "gurger", "mj penne","chickpea curry");
$GLOBALS["conflicts"] = [[],[1,2,10,14],[1,2,10,14,15],[3,13],
                        [4,8,9],[5,6,13],[5,6],
                        [7],[8,9],[8,9],
                        [10,11,12,1,2],[10,11,12],[10,11,12,3],
                        [5,3,13],[1,2,10,14], [2,15]];


// 3-4x tinned tomatoes
// olive oil (ideally)
// 2x tins coconut milk
// garlic
// herbs (oregano, basil, thyme(?), rosemary(??), sage(???))
// tomato puree


$GLOBALS["mealingredients"] = [
    0 => [],
    1 => ["brocolli" => .5,
          "passata" => 1,
          "spaghetti" => .3],
    2 => ["brocolli" => .5,
          "passata" => 1,
          "rice" => .3],
    3 => [],
    4 => ["kale" => .3,
          "pak choi" => .5,
          "brocolli" => .5,
          "rice" => .3,
          "sweetcorn" => .5,
          "mangetout" => .5],
    5 => ["potatoes" => 5,
          "beans" => 2],
    6 => ["potatoes" => 5,
          "peas" => .3],
    7 => ["egg" => 2,
          "vesto" => .5,
          "black beans" => 1,
          "spaghetti" => .2],
    8 => ["instant ramen" => 2,
          "brocolli" => .5,
          "sweetcorn" => .5],
    9 => ["noodles" => .5,
          "pak choi" => .5,
          "brocolli" => .5,
          "chilli" => .5,
          "sweetcorn" => .5,
          "mangetout" => .5,
          "garlic" => 1
    ],
    10 => ["tinned tomatoes" => 3,
           "coconut milk" => 1,
           "garlic" => .5],
    11 => ["squash" => 1,
           "onion" => 1,
           "garlic" => .5,
           "vegetable stock" => .15,
           "coconut milk" => 1],
    12 => ["onion" => 1,
           "garlic" => .5,
           "pepper" => 1,
           "black beans" => 3,
           "tinned tomatoes" => 1,
           "vegetable stock" => .15,
           "lime" => 1],
    13 => ["bean burger"=>2,
           "minced meat" => .25,
           "chips" => 1,
           "egg" => 1,
           "bun" => 4],
    14 => ["brocolli" => .5,
          "passata" => 1,
          "penne" => .5],
    15 => ["chickpea" => 2,
           "chopped tomato" => 2,
           "lemon" => 1,
           "onion" => 2,
           "garlic" => .5,
           "ginger" => .5,
           "chilli" => 1]
];

$GLOBALS["ingredientsList"] = [];
$GLOBALS["ingredients"] = [];


$GLOBALS["allowance"] = [999,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2];

for($i =0;$i<14;$i++){
    if ($_POST[$i]==""){
        $_POST[$i]=0;
    }
    $GLOBALS["allowance"][$_POST[$i]]-=1;
}


function genSel($dayNum,$meal){
    $p = (int)$_POST[$dayNum*2+$meal];
    $dm = $dayNum*2 + $meal;
	$o = "<select name= \"" . ($dm) . "\" id=" . ($dm) . ">";
    $incompat = [];
    for($i=max(0,$dm-1);$i<=min($dm+1,13); $i++){
        $incompat = array_merge($incompat,$GLOBALS["conflicts"][$_POST[$i]]);
    }
	for ($i = 0; $i < count($GLOBALS["meals"]); $i++) {
        if(($_POST[$dm]=="" || !in_array($i,$incompat)) && $GLOBALS["allowance"][$i]>0){
            $o = $o . "<option value=" . $i . ">" . $GLOBALS["meals"][$i] . "</option>";
        }else if($p==$i){
            $o = $o . "<option selected=\"selected\" value=" . $i . ">" . $GLOBALS["meals"][$i] . "</option>";
        }
	}
	return $o . "</select>";
}

function genRow($dayNum){
	return "<tr><th>" . $GLOBALS["days"][($dayNum+5) % 7] . "</th><th>" . genSel($dayNum,0) . "</th><th>" . genSel($dayNum,1) . "</th></tr>";
}

for($i =0;$i<14;$i++){
    foreach($GLOBALS["mealingredients"][$_POST[$i]] as $key => $val){
        if(isset($GLOBALS["ingredients"][$key])){
            $GLOBALS["ingredients"][$key] += $val;
        }else{
            $GLOBALS["ingredients"][$key] = $val;
        }
    }
}

?>

<html class="no-js" lang="">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>Food solver</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <!-- Place favicon.ico in the root directory -->
        <style>
            th {text-align: left;}
        </style>
    </head>
    <body onload="">
        <!--[if lt IE 8]>
            <p class="browserupgrade">
            You are using an <strong>outdated</strong> browser. Please
            <a href="http://browsehappy.com/">upgrade your browser</a> to improve
            your experience.
            </p>
        <![endif]-->

        <form method="post">
		<table>
			<tr>
				<th scope="col">\</th>
				<th scope="col">Lunch</th>
				<th scope="col">Dinner</th>
			</tr>
			<?php
				for($x = 0;$x<7; $x++){
					echo genRow($x % 7);
				}
			?>
		</table>
        <input type="submit" class="button" value="Check" name="submit" />
        <input type="submit" class="button" value="Print" name="submit" />
        </form>
        <?php
            if($_POST["submit"]=="Print"){
                echo "<table><tr><th>Ingredient</th><th>Qty</th></tr>";

                foreach($GLOBALS["ingredients"] as $key => $val){
                    echo "<tr><th>" . $key . "</th><th>" . $val . "</th></tr>";
                }

                echo "</table>";
            }
        ?>
    </body>
</html>