Fri, 28 Sep 2018 17:29:23 +0200
Added category and type to the recipe style. Added tooltips in the edit screen. Added Alcohol and Carbonation to the recipe style. Redesigned the main edit window and added the style limits.
11 | 1 | <?php |
2 | ||
3 | require($_SERVER['DOCUMENT_ROOT']."/config.php"); | |
4 | require($_SERVER['DOCUMENT_ROOT']."/version.php"); | |
5 | ||
6 | ||
7 | #Connect to the database | |
8 | $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); | |
9 | if (! $connect) { | |
10 | die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); | |
11 | } | |
12 | ||
13 | // get data and store in a json array | |
37
9362eb9e9e5b
Sorting the inventory and changes some grid tables.
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
14 | $query = "SELECT * FROM inventory_fermentables ORDER BY supplier,name"; |
11 | 15 | if (isset($_GET['insert'])) { |
16 | // INSERT COMMAND | |
17 | $sql = "INSERT INTO `inventory_fermentables` SET name='" . mysqli_real_escape_string($connect, $_GET['name']); | |
18 | $sql .= "', type='" . $_GET['type']; | |
19 | $sql .= "', yield='" . $_GET['yield']; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
20 | $sql .= "', color='" . $_GET['color']; |
11 | 21 | ($_GET['add_after_boil'] == 'true') ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0"; |
22 | $sql .= "', origin='" . mysqli_real_escape_string($connect, $_GET['origin']); | |
23 | $sql .= "', supplier='" . mysqli_real_escape_string($connect, $_GET['supplier']); | |
24 | $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); | |
25 | $sql .= "', coarse_fine_diff='" . $_GET['coarse_fine_diff']; | |
26 | $sql .= "', moisture='" . $_GET['moisture']; | |
27 | $sql .= "', diastatic_power='" . $_GET['diastatic_power']; | |
28 | $sql .= "', protein='" . $_GET['protein']; | |
29 | $sql .= "', max_in_batch='" . $_GET['max_in_batch']; | |
30 | ($_GET['recommend_mash'] == 'true') ? $sql .= "', recommend_mash='1" : $sql .= "', recommend_mash='0"; | |
31 | $sql .= "', ibu_gal_per_lb='" . $_GET['ibu_gal_per_lb']; | |
32 | ($_GET['always_on_stock'] == 'true') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; | |
33 | $sql .= "', di_ph='" . $_GET['di_ph']; | |
34 | $sql .= "', acid_to_ph_57='" . $_GET['acid_to_ph_57']; | |
35 | $sql .= "', graintype='" . mysqli_real_escape_string($connect, $_GET['graintype']); | |
36 | $sql .= "', inventory='" . $_GET['inventory']; | |
37 | $sql .= "', cost='" . $_GET['cost']; | |
38 | $sql .= "', production_date='" . $_GET['production_date']; | |
39 | $sql .= "', tht_date='" . $_GET['tht_date']; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
40 | //$sql .= "', supplier_rec='" . $_GET['supplier_rec']; |
11 | 41 | $sql .= "';"; |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
42 | $result = mysqli_query($connect, $sql); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
43 | if (! $result) { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
44 | syslog(LOG_NOTICE, "db_inventory_fermentables: ".$sql." result: ".mysqli_error($connect)); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
45 | } else { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
46 | syslog(LOG_NOTICE, "db_inventory_fermentables: inserted ".$_GET['name']); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
47 | } |
11 | 48 | echo $result; |
49 | ||
50 | } else if (isset($_GET['update'])) { | |
51 | // UPDATE COMMAND | |
52 | $sql = "UPDATE `inventory_fermentables` SET name='" . mysqli_real_escape_string($connect, $_GET['name']); | |
53 | $sql .= "', type='" . $_GET['type']; | |
54 | $sql .= "', yield='" . $_GET['yield']; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
55 | $sql .= "', color='" . $_GET['color']; |
11 | 56 | ($_GET['add_after_boil'] == 'true') ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0"; |
57 | $sql .= "', origin='" . mysqli_real_escape_string($connect, $_GET['origin']); | |
58 | $sql .= "', supplier='" . mysqli_real_escape_string($connect, $_GET['supplier']); | |
59 | $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); | |
60 | $sql .= "', coarse_fine_diff='" . $_GET['coarse_fine_diff']; | |
61 | $sql .= "', moisture='" . $_GET['moisture']; | |
62 | $sql .= "', diastatic_power='" . $_GET['diastatic_power']; | |
63 | $sql .= "', protein='" . $_GET['protein']; | |
64 | $sql .= "', max_in_batch='" . $_GET['max_in_batch']; | |
65 | ($_GET['recommend_mash'] == 'true') ? $sql .= "', recommend_mash='1" : $sql .= "', recommend_mash='0"; | |
66 | $sql .= "', ibu_gal_per_lb='" . $_GET['ibu_gal_per_lb']; | |
67 | ($_GET['always_on_stock'] == 'true') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; | |
68 | $sql .= "', di_ph='" . $_GET['di_ph']; | |
69 | $sql .= "', acid_to_ph_57='" . $_GET['acid_to_ph_57']; | |
70 | $sql .= "', graintype='" . mysqli_real_escape_string($connect, $_GET['graintype']); | |
71 | $sql .= "', inventory='" . $_GET['inventory']; | |
72 | $sql .= "', cost='" . $_GET['cost']; | |
73 | $sql .= "', production_date='" . $_GET['production_date']; | |
74 | $sql .= "', tht_date='" . $_GET['tht_date']; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
75 | //$sql .= "', supplier_rec='" . $_GET['supplier_rec']; |
11 | 76 | $sql .= "' WHERE record='" . $_GET['record'] . "';"; |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
77 | $result = mysqli_query($connect, $sql); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
78 | if (! $result) { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
79 | syslog(LOG_NOTICE, "db_inventory_fermentables: ".$sql." result: ".mysqli_error($connect)); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
80 | } else { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
81 | syslog(LOG_NOTICE, "db_inventory_fermentables: updated record ".$_GET['record']); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
82 | } |
11 | 83 | echo $result; |
84 | ||
85 | } else if (isset($_GET['delete'])) { | |
86 | // DELETE COMMAND | |
87 | $sql = "DELETE FROM `inventory_fermentables` WHERE record='".$_GET['record']."';"; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
88 | $result = mysqli_query($connect, $sql); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
89 | if (! $result) { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
90 | syslog(LOG_NOTICE, "db_inventory_fermentables: ".$sql." result: ".mysqli_error($connect)); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
91 | } else { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
92 | syslog(LOG_NOTICE, "db_inventory_fermentables: deleted record ".$_GET['record']); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
93 | } |
11 | 94 | echo $result; |
95 | ||
96 | } else { | |
97 | // SELECT COMMAND | |
98 | $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); | |
99 | while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { | |
100 | $fermentables[] = array( | |
101 | 'record' => $row['record'], | |
102 | 'name' => $row['name'], | |
103 | 'type' => $row['type'], | |
104 | 'yield' => $row['yield'], | |
105 | 'color' => $row['color'], | |
106 | 'add_after_boil' => $row['add_after_boil'], | |
107 | 'origin' => $row['origin'], | |
108 | 'supplier' => $row['supplier'], | |
109 | 'notes' => $row['notes'], | |
110 | 'coarse_fine_diff' => $row['coarse_fine_diff'], | |
111 | 'moisture' => $row['moisture'], | |
112 | 'diastatic_power' => $row['diastatic_power'], | |
113 | 'protein' => $row['protein'], | |
114 | 'max_in_batch' => $row['max_in_batch'], | |
115 | 'recommend_mash' => $row['recommend_mash'], | |
116 | 'ibu_gal_per_lb' => $row['ibu_gal_per_lb'], | |
117 | 'always_on_stock' => $row['always_on_stock'], | |
118 | 'di_ph' => $row['di_ph'], | |
119 | 'acid_to_ph_57' => $row['acid_to_ph_57'], | |
120 | 'graintype' => $row['graintype'], | |
121 | 'inventory' => $row['inventory'], | |
122 | 'cost' => $row['cost'], | |
123 | 'production_date' => $row['production_date'], | |
39 | 124 | 'tht_date' => $row['tht_date'] |
11 | 125 | ); |
126 | } | |
127 | echo json_encode($fermentables); | |
128 | } | |
129 | ?> |