www/includes/db_recipes.php

Fri, 28 Sep 2018 17:29:23 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 28 Sep 2018 17:29:23 +0200
changeset 72
93a0be4f5be3
parent 71
e1c50b21b7e3
child 77
a9f8de2d7b2b
permissions
-rw-r--r--

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.

49
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 <?php
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2
50
6d94167c2697 Next steps to implement a recipe editor
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
3 require($_SERVER['DOCUMENT_ROOT']."/config.php");
6d94167c2697 Next steps to implement a recipe editor
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
4 require($_SERVER['DOCUMENT_ROOT']."/version.php");
49
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 #Connect to the database
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 if (! $connect) {
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 }
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11
50
6d94167c2697 Next steps to implement a recipe editor
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
12 $escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");
6d94167c2697 Next steps to implement a recipe editor
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
13 $replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b");
61
3469979f83be Added inline yeast editor
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
14 $rescapers = array("'");
3469979f83be Added inline yeast editor
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
15 $rreplacements = array("\\'");
57
bb9a06aa9acd Completed framework inline fermentables editor
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
16 $disallowed = array('visibleindex','uniqueid','boundindex','uid');
50
6d94167c2697 Next steps to implement a recipe editor
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
17
49
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 // get data and store in a json array
51
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
19 $query = "SELECT * FROM recipes ORDER BY st_guide,st_letter,st_name,name";
60
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
20 if (isset($_POST['insert']) || isset($_POST['update'])) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
21 if (isset($_POST['insert'])) {
52
b1f2a893572f More progress on the recipes design
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
22 // INSERT COMMAND
60
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
23 $sql = "INSERT INTO `recipes` SET ";
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
24 }
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
25 if (isset($_POST['update'])) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
26 // UPDATE COMMAND
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
27 $sql = "UPDATE `recipes` SET ";
52
b1f2a893572f More progress on the recipes design
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
28 }
60
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
29 // Basic settings
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
30 $sql .= "st_name='" . mysqli_real_escape_string($connect, $_POST['st_name']);
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
31 $sql .= "', st_letter='" . mysqli_real_escape_string($connect, $_POST['st_letter']);
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
32 $sql .= "', st_guide='" . mysqli_real_escape_string($connect, $_POST['st_guide']);
72
93a0be4f5be3 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.
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
33 $sql .= "', st_type='" . mysqli_real_escape_string($connect, $_POST['st_type']);
93a0be4f5be3 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.
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
34 $sql .= "', st_category='" . mysqli_real_escape_string($connect, $_POST['st_categpry']);
93a0be4f5be3 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.
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
35 $sql .= "', st_category_number='" . $_POST['st_category_number'];
60
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
36 $sql .= "', st_og_min='" . $_POST['st_og_min'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
37 $sql .= "', st_og_max='" . $_POST['st_og_max'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
38 $sql .= "', st_fg_min='" . $_POST['st_fg_min'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
39 $sql .= "', st_fg_max='" . $_POST['st_fg_max'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
40 $sql .= "', st_ibu_min='" . $_POST['st_ibu_min'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
41 $sql .= "', st_ibu_max='" . $_POST['st_ibu_max'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
42 $sql .= "', st_color_min='" . $_POST['st_color_min'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
43 $sql .= "', st_color_max='" . $_POST['st_color_max'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
44 $sql .= "', st_carb_min='" . $_POST['st_carb_min'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
45 $sql .= "', st_carb_max='" . $_POST['st_carb_max'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
46 $sql .= "', st_abv_min='" . $_POST['st_abv_min'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
47 $sql .= "', st_abv_max='" . $_POST['st_abv_max'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
48 $sql .= "', name='" . mysqli_real_escape_string($connect, $_POST['name']);
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
49 $sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']);
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
50 $sql .= "', type='" . $_POST['type'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
51 $sql .= "', batch_size='" . $_POST['batch_size'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
52 $sql .= "', boil_time='" . $_POST['boil_time'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
53 $sql .= "', efficiency='" . $_POST['efficiency'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
54 $sql .= "', est_og='" . $_POST['est_og'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
55 $sql .= "', est_fg='" . $_POST['est_fg'];
72
93a0be4f5be3 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.
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
56 $sql .= "', est_abv='" . $_POST['est_abv'];
93a0be4f5be3 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.
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
57 $sql .= "', est_carb='" . $_POST['est_carb'];
60
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
58 $sql .= "', est_color='" . $_POST['est_color'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
59 $sql .= "', color_method='" . $_POST['color_method'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
60 $sql .= "', est_ibu='" . $_POST['est_ibu'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
61 $sql .= "', ibu_method='" . $_POST['ibu_method'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
62 $sql .= "', mash_sparge_temp='" . $_POST['mash_sparge_temp'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
63 $sql .= "', mash_ph='" . $_POST['mash_ph'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
64 $sql .= "', mash_name='" . $_POST['mash_name'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
65 syslog(LOG_NOTICE, $sql);
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
66
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
67 if (isset($_POST['fermentables'])) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
68 $array = $_POST['fermentables'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
69 foreach($array as $key => $item){
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
70 foreach ($disallowed as $disallowed_key) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
71 unset($array[$key]["$disallowed_key"]);
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
72 }
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
73 }
61
3469979f83be Added inline yeast editor
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
74 syslog(LOG_NOTICE, "json_fermentables=: ".str_replace($rescapers,$rreplacements,json_encode($array)));
3469979f83be Added inline yeast editor
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
75 $sql .= "', json_fermentables='" . str_replace($rescapers,$rreplacements,json_encode($array));
52
b1f2a893572f More progress on the recipes design
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
76 }
60
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
77
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
78 if (isset($_POST['hops'])) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
79 $array = $_POST['hops'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
80 foreach($array as $key => $item){
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
81 foreach ($disallowed as $disallowed_key) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
82 unset($array[$key]["$disallowed_key"]);
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
83 }
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
84 }
61
3469979f83be Added inline yeast editor
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
85 syslog(LOG_NOTICE, "json_hops: ".str_replace($rescapers,$rreplacements,json_encode($array)));
3469979f83be Added inline yeast editor
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
86 $sql .= "', json_hops='" . str_replace($rescapers,$rreplacements,json_encode($array));
60
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
87 }
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
88
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
89 if (isset($_POST['miscs'])) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
90 $array = $_POST['miscs'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
91 foreach($array as $key => $item){
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
92 foreach ($disallowed as $disallowed_key) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
93 unset($array[$key]["$disallowed_key"]);
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
94 }
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
95 }
61
3469979f83be Added inline yeast editor
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
96 syslog(LOG_NOTICE, "json_miscs: ".str_replace($rescapers,$rreplacements,json_encode($array)));
3469979f83be Added inline yeast editor
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
97 $sql .= "', json_miscs='" . str_replace($rescapers,$rreplacements,json_encode($array));
60
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
98 }
52
b1f2a893572f More progress on the recipes design
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
99
60
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
100 if (isset($_POST['yeasts'])) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
101 $array = $_POST['yeasts'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
102 foreach($array as $key => $item){
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
103 foreach ($disallowed as $disallowed_key) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
104 unset($array[$key]["$disallowed_key"]);
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
105 }
57
bb9a06aa9acd Completed framework inline fermentables editor
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
106 }
61
3469979f83be Added inline yeast editor
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
107 syslog(LOG_NOTICE, "json_yeasts: ". str_replace($rescapers,$rreplacements,json_encode($array)));
3469979f83be Added inline yeast editor
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
108 $sql .= "', json_yeasts='" . str_replace($rescapers,$rreplacements,json_encode($array));
57
bb9a06aa9acd Completed framework inline fermentables editor
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
109 }
bb9a06aa9acd Completed framework inline fermentables editor
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
110
60
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
111 if (isset($_POST['waters'])) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
112 $array = $_POST['waters'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
113 foreach($array as $key => $item){
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
114 foreach ($disallowed as $disallowed_key) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
115 unset($array[$key]["$disallowed_key"]);
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
116 }
57
bb9a06aa9acd Completed framework inline fermentables editor
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
117 }
61
3469979f83be Added inline yeast editor
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
118 syslog(LOG_NOTICE, "json_waters: ".str_replace($rescapers,$rreplacements,json_encode($array)));
3469979f83be Added inline yeast editor
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
119 $sql .= "', json_waters='" . str_replace($rescapers,$rreplacements,json_encode($array));
57
bb9a06aa9acd Completed framework inline fermentables editor
Michiel Broek <mbroek@mbse.eu>
parents: 52
diff changeset
120 }
52
b1f2a893572f More progress on the recipes design
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
121
60
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
122 if (isset($_POST['mashs'])) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
123 $array = $_POST['mashs'];
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
124 foreach($array as $key => $item){
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
125 foreach ($disallowed as $disallowed_key) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
126 unset($array[$key]["$disallowed_key"]);
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
127 }
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
128 }
61
3469979f83be Added inline yeast editor
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
129 syslog(LOG_NOTICE, "json_mashs: ".str_replace($rescapers,$rreplacements,json_encode($array)));
3469979f83be Added inline yeast editor
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
130 $sql .= "', json_mashs='" . str_replace($rescapers,$rreplacements,json_encode($array));
60
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
131 }
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
132
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
133 if (isset($_POST['insert'])) {
52
b1f2a893572f More progress on the recipes design
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
134 $sql .= "';";
b1f2a893572f More progress on the recipes design
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
135 }
60
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
136 if (isset($_POST['update'])) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
137 $sql .= "' WHERE record='" . $_POST['record'] . "';";
52
b1f2a893572f More progress on the recipes design
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
138 }
49
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139
52
b1f2a893572f More progress on the recipes design
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
140 $result = mysqli_query($connect, $sql);
b1f2a893572f More progress on the recipes design
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
141 if (! $result) {
61
3469979f83be Added inline yeast editor
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
142 syslog(LOG_NOTICE, "db_recipes: result: ".mysqli_error($connect));
52
b1f2a893572f More progress on the recipes design
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
143 } else {
60
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
144 if (isset($_POST['update'])) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
145 syslog(LOG_NOTICE, "db_recipes: updated record ".$_POST['record']);
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
146 } else {
72
93a0be4f5be3 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.
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
147 $lastid = mysqli_insert_id($connect);
93a0be4f5be3 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.
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
148 syslog(LOG_NOTICE, "db_recipes: inserted record ".$lastid);
60
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
149 }
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
150 }
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
151 echo $result;
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
152
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
153 } else if (isset($_POST['delete'])) {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
154 // DELETE COMMAND
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
155 $sql = "DELETE FROM `recipes` WHERE record='".$_POST['record']."';";
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
156 $result = mysqli_query($connect, $sql);
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
157 if (! $result) {
61
3469979f83be Added inline yeast editor
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
158 syslog(LOG_NOTICE, "db_recipes: result: ".mysqli_error($connect));
60
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
159 } else {
dbbe408108ea Added miscs inline editor. Switched to http POST because of GET limitations.
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
160 syslog(LOG_NOTICE, "db_recipes: deleted record ".$_POST['record']);
52
b1f2a893572f More progress on the recipes design
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
161 }
b1f2a893572f More progress on the recipes design
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
162 echo $result;
49
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 } else {
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 // SELECT COMMAND
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 $recipes = '[';
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 $comma = FALSE;
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 // Manual encode to JSON.
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 if ($comma) {
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 $recipes .= ',';
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173 }
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 $comma = TRUE;
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 $recipes .= '{"record":' . $row['record'];
51
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
176 $recipes .= ',"st_guide":"' . str_replace($escapers, $replacements, $row['st_guide']);
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
177 $recipes .= '","st_letter":"' . str_replace($escapers, $replacements, $row['st_letter']);
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
178 $recipes .= '","st_name":"' . str_replace($escapers, $replacements, $row['st_name']);
72
93a0be4f5be3 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.
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
179 $recipes .= '","st_type":"' . str_replace($escapers, $replacements, $row['st_type']);
93a0be4f5be3 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.
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
180 $recipes .= '","st_category":"' . str_replace($escapers, $replacements, $row['st_category']);
93a0be4f5be3 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.
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
181 $recipes .= '","st_category_number":' . floatval($row['st_category_number']);
93a0be4f5be3 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.
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
182 $recipes .= ',"st_og_min":' . floatval($row['st_og_min']);
51
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
183 $recipes .= ',"st_og_max":' . floatval($row['st_og_max']);
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
184 $recipes .= ',"st_fg_min":' . floatval($row['st_fg_min']);
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
185 $recipes .= ',"st_fg_max":' . floatval($row['st_fg_max']);
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
186 $recipes .= ',"st_ibu_min":' . floatval($row['st_ibu_min']);
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
187 $recipes .= ',"st_ibu_max":' . floatval($row['st_ibu_max']);
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
188 $recipes .= ',"st_color_min":' . floatval($row['st_color_min']);
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
189 $recipes .= ',"st_color_max":' . floatval($row['st_color_max']);
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
190 $recipes .= ',"st_carb_min":' . floatval($row['st_carb_min']);
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
191 $recipes .= ',"st_carb_max":' . floatval($row['st_carb_max']);
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
192 $recipes .= ',"st_abv_min":' . floatval($row['st_abv_min']);
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
193 $recipes .= ',"st_abv_max":' . floatval($row['st_abv_max']);
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
194 $recipes .= ',"name":"' . str_replace($escapers, $replacements, $row['name']);
50
6d94167c2697 Next steps to implement a recipe editor
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
195 $recipes .= '","notes":"' . str_replace($escapers, $replacements, $row['notes']);
49
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 $recipes .= '","type":"' . $row['type'];
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 $recipes .= '","batch_size":' . floatval($row['batch_size']);
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198 $recipes .= ',"boil_time":' . floatval($row['boil_time']);
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199 $recipes .= ',"efficiency":' . floatval($row['efficiency']);
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200 $recipes .= ',"est_og":' . floatval($row['est_og']);
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201 $recipes .= ',"est_fg":' . floatval($row['est_fg']);
72
93a0be4f5be3 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.
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
202 $recipes .= ',"est_abv":' . floatval($row['est_abv']);
93a0be4f5be3 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.
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
203 $recipes .= ',"est_carb":' . floatval($row['est_carb']);
49
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204 $recipes .= ',"est_color":' . floatval($row['est_color']);
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 $recipes .= ',"color_method":"' . $row['color_method'];
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206 $recipes .= '","est_ibu":' . floatval($row['est_ibu']);
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207 $recipes .= ',"ibu_method":"' . $row['ibu_method'];
51
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
208 $recipes .= '","mash_sparge_temp":' . $row['mash_sparge_temp'];
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
209 $recipes .= ',"mash_ph":' . $row['mash_ph'];
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
210 $recipes .= ',"mash_name":"' . $row['mash_name'];
49
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211 $recipes .= '","fermentables":' . $row['json_fermentables'];
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
212 $recipes .= ',"hops":' . $row['json_hops'];
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213 $recipes .= ',"miscs":' . $row['json_miscs'];
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214 $recipes .= ',"yeasts":' . $row['json_yeasts'];
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215 $recipes .= ',"waters":' . $row['json_waters'];
51
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
216 $recipes .= ',"mashs":' . $row['json_mashs'];
49
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217 $recipes .= '}';
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218 }
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
219 $recipes .= ']';
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 header("Content-type: application/json");
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221 echo $recipes;
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 }
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 ?>

mercurial