www/includes/db_recipes.php

Wed, 07 Nov 2018 22:52:39 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 07 Nov 2018 22:52:39 +0100
changeset 80
75b9227fb98c
parent 77
a9f8de2d7b2b
child 94
295c3af2a421
permissions
-rw-r--r--

Added beginning of recipe print.

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

mercurial