-
Notifications
You must be signed in to change notification settings - Fork 1
/
ajax_recipes.php
134 lines (114 loc) · 3.78 KB
/
ajax_recipes.php
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
<?php
$require_petload = 'no';
$invisible = 'yes';
$AJAX = true;
require_once 'commons/dbconnect.php';
require_once 'commons/sessions.php';
require_once 'commons/utility.php';
require_once 'commons/formatting.php';
$house = $database->FetchSingle('SELECT * FROM monster_houses WHERE userid=' . $user['idnum'] . ' LIMIT 1');
if(strlen($house['curroom']) > 0)
{
$curroom = $house['curroom'];
$curlocation = 'home/' . $curroom;
}
else
{
$curroom = 'Common';
$curlocation = 'home';
}
$favorite_recipes = $database->FetchMultiple('
SELECT recipeid
FROM psypets_known_recipes
WHERE userid=' . $user['idnum'] . '
ORDER BY favorite DESC,times_prepared DESC
LIMIT 20
');
if(count($favorite_recipes) > 0)
{
foreach($favorite_recipes as $recipe)
{
$ingredients = $database->FetchSingle('SELECT ingredients,makes FROM monster_recipes WHERE idnum=' . $recipe['recipeid'] . ' LIMIT 1');
$ingreident_list = explode(',', $ingredients['ingredients']);
$requires = array();
foreach($ingreident_list as $item)
$requires[$item]++;
$okay = true;
$these_ingredients = array();
$max = 999;
foreach($requires as $itemname=>$quantity)
{
$command = 'SELECT COUNT(*) AS c FROM monster_inventory WHERE user=' . quote_smart($user['user']) . ' AND location=' . quote_smart($curlocation) . ' AND itemname=' . quote_smart($itemname) . ' LIMIT ' . $quantity;
$data = $database->FetchSingle($command, 'checking house for ingredients');
if($data['c'] < $quantity)
{
$okay = false;
$these_ingredients[] = '<span class="failure">' . $itemname . '</span>';
$max = 0;
}
else
{
$these_ingredients[] = $itemname;
if($max > (int)($data['c'] / $quantity))
$max = (int)($data['c'] / $quantity);
}
}
$make_list = explode(',', $ingredients['makes']);
$makes = array();
foreach($make_list as $item)
$makes[$item]++;
$products = array();
foreach($makes as $item=>$quantity)
$products[] = $quantity . '× ' . $item;
$recipes[$recipe['recipeid']] = array($okay, implode('<br />', $these_ingredients), implode('<br />', $products), $max);
}
}
else
$recipes = array();
$rowclass = begin_row_class();
?>
<?php
if(count($recipes) > 0)
{
?>
<form action="/moveinventory2.php?confirm=1" method="post">
<div>
<table>
<thead>
<tr><th></th><th>Ingredients</th><th>Prepares</th><th>Max Batches</th></tr>
</thead>
<tbody>
<?php
$max_max = 0;
foreach($recipes as $index=>$recipe)
{
echo '<tr class="' . $rowclass . '">';
$ingredients = $recipe[1];
$makes = $recipe[2];
$max = $recipe[3];
$max_max = max($max, $max_max);
if($recipe[0])
echo '<td><input type="radio" name="recipe1" value="' . $index . '" /></td>';
else
echo '<td><input type="radio" name="recipe1" disabled /></td>';
echo '<td>' . $ingredients . '</td><td>' . $makes . '</td><td class="centered">' . $max . '</td></tr>';
$rowclass = alt_row_class($rowclass);
}
?>
</tbody>
</table>
</div>
<p>Quantity: <input type="number" min="0" max="<?= $max_max ?>" name="quantity" size="3" maxlength="3" value="1" /> <input type="submit" name="submit" value="Prepare" /> <input type="button" onclick="closepreparewindow();" value="Cancel" /></p>
<p style="margin-bottom:0;"><i>(If you do not have enough ingredients to make the quantity desired, you will make as many as possible.)</i></p>
</form>
<?php
}
else
{
?>
<p>This window shows you your top 20 recipes, however you have not prepared anything yet!</p>
<p>Once you've prepared something, you can prepare the recipe repeatedly here, without the tedium of checking all the items over and over again! Useful!</p>
<p style="margin-bottom:0;"><input type="button" onclick="closepreparewindow();" value="Close" /></p>
<?php
}
?>