summaryrefslogtreecommitdiff
path: root/index.php
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-06-18 22:46:31 +0100
committerubq323 <ubq323@ubq323.website>2024-06-18 22:46:31 +0100
commit3a6c6b00eb4c62b24c5e5ca670142ac5a00d7847 (patch)
treeea841da8e25da3489f6ed0c050c2213095e981a8 /index.php
Diffstat (limited to 'index.php')
-rw-r--r--index.php188
1 files changed, 188 insertions, 0 deletions
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..840d987
--- /dev/null
+++ b/index.php
@@ -0,0 +1,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>