www/includes/db_profile_mash.php

Sun, 27 Jan 2019 17:39:26 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 27 Jan 2019 17:39:26 +0100
changeset 215
83cee005d2d9
parent 214
3e240fd7ef13
child 716
57118e6a4bdb
permissions
-rw-r--r--

Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.

23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 <?php
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 require($_SERVER['DOCUMENT_ROOT']."/config.php");
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 require($_SERVER['DOCUMENT_ROOT']."/version.php");
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 #Connect to the database
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 if (! $connect) {
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
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: 50
diff changeset
11 mysqli_set_charset($connect, "utf8" );
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12
50
6d94167c2697 Next steps to implement a recipe editor
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
13 $escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");
6d94167c2697 Next steps to implement a recipe editor
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
14 $replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b");
120
b28a3d6143bc Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
15 $rescapers = array("'");
b28a3d6143bc Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
16 $rreplacements = array("\\'");
b28a3d6143bc Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
17 $disallowed = array('visibleindex','uniqueid','boundindex','uid');
50
6d94167c2697 Next steps to implement a recipe editor
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
18
213
b0d484a5525e First step to make profile mash work with indexes and make the edit screen universal.
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
19 if (isset($_POST['insert']) || isset($_POST['update'])) {
b0d484a5525e First step to make profile mash work with indexes and make the edit screen universal.
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
20 if (isset($_POST['insert'])) {
120
b28a3d6143bc Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
21 $sql = "INSERT INTO";
b28a3d6143bc Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
22 }
213
b0d484a5525e First step to make profile mash work with indexes and make the edit screen universal.
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
23 if (isset($_POST['update'])) {
120
b28a3d6143bc Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
24 $sql = "UPDATE";
b28a3d6143bc Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
25 }
213
b0d484a5525e First step to make profile mash work with indexes and make the edit screen universal.
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
26 $sql .= " `profile_mash` SET name='" . mysqli_real_escape_string($connect, $_POST['name']);
b0d484a5525e First step to make profile mash work with indexes and make the edit screen universal.
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
27 $sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']);
b0d484a5525e First step to make profile mash work with indexes and make the edit screen universal.
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
28 $array = $_POST['steps'];
215
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
29 $comma = FALSE;
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
30 $steps = '[';
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
31 foreach($array as $key => $item) {
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
32 /*
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
33 * Manual encode to json. This eliminates the wrong UTF-8 encodings
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
34 * but also removes the unwanted fields.
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
35 */
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
36 if ($comma)
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
37 $steps.= ',';
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
38 $steps .= '{"step_name":"' . str_replace($rescapers,$rreplacements,$item['step_name']);
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
39 $steps .= '","step_type":' . $item['step_type'];
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
40 $steps .= ',"step_temp":' . $item['step_temp'];
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
41 $steps .= ',"end_temp":' . $item['end_temp'];
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
42 $steps .= ',"step_time":' . $item['step_time'];
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
43 $steps .= ',"ramp_time":' . $item['ramp_time'] . '}';
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
44 $comma = TRUE;
120
b28a3d6143bc Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
45 }
215
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
46 $steps .= ']';
83cee005d2d9 Fixed the utf-8 problems when storing json arrays on the server by using manual encoding. The json-encode function sucks for this project. Added step detail edit screen instead of on grid cell editing. This must go into the product and recipe editors too.
Michiel Broek <mbroek@mbse.eu>
parents: 214
diff changeset
47 $sql .= "', steps='" . $steps;
213
b0d484a5525e First step to make profile mash work with indexes and make the edit screen universal.
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
48 if (isset($_POST['insert'])) {
120
b28a3d6143bc Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
49 $sql .= "';";
b28a3d6143bc Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
50 }
213
b0d484a5525e First step to make profile mash work with indexes and make the edit screen universal.
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
51 if (isset($_POST['update'])) {
b0d484a5525e First step to make profile mash work with indexes and make the edit screen universal.
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
52 $sql .= "' WHERE record='" . $_POST['record'] . "';";
120
b28a3d6143bc Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
53 }
214
3e240fd7ef13 Prep debug logs
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
54 syslog(LOG_NOTICE, $sql);
3e240fd7ef13 Prep debug logs
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
55
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 $result = mysqli_query($connect, $sql);
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 if (! $result) {
45
95251bedfab4 Moved three inventory tables and screens to profiles
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
58 syslog(LOG_NOTICE, "db_profile_mash: ".$sql." result: ".mysqli_error($connect));
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 } else {
213
b0d484a5525e First step to make profile mash work with indexes and make the edit screen universal.
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
60 if (isset($_POST['update'])) {
b0d484a5525e First step to make profile mash work with indexes and make the edit screen universal.
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
61 syslog(LOG_NOTICE, "db_profile_mash: updated record ".$_POST['record']);
120
b28a3d6143bc Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
62 } else {
b28a3d6143bc Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
63 $lastid = mysqli_insert_id($connect);
b28a3d6143bc Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
64 syslog(LOG_NOTICE, "db_profile_mash: inserted record ".$lastid);
b28a3d6143bc Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
65 }
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 }
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 echo $result;
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68
213
b0d484a5525e First step to make profile mash work with indexes and make the edit screen universal.
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
69 } else if (isset($_POST['delete'])) {
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 // DELETE COMMAND
213
b0d484a5525e First step to make profile mash work with indexes and make the edit screen universal.
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
71 $sql = "DELETE FROM `profile_mash` WHERE record='".$_POST['record']."';";
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 $result = mysqli_query($connect, $sql);
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 if (! $result) {
45
95251bedfab4 Moved three inventory tables and screens to profiles
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
74 syslog(LOG_NOTICE, "db_profile_mash: ".$sql." result: ".mysqli_error($connect));
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 } else {
213
b0d484a5525e First step to make profile mash work with indexes and make the edit screen universal.
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
76 syslog(LOG_NOTICE, "db_profile_mash: deleted record ".$_POST['record']);
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 }
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 echo $result;
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 } else {
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 // SELECT COMMAND
213
b0d484a5525e First step to make profile mash work with indexes and make the edit screen universal.
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
82 $query = "SELECT * FROM profile_mash ORDER BY name";
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
38
b7d44c98d609 Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
84 $mashprofiles = '[';
b7d44c98d609 Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
85 $comma = FALSE;
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
38
b7d44c98d609 Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
87 // Manual encode to JSON.
b7d44c98d609 Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
88 if ($comma) {
b7d44c98d609 Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
89 $mashprofiles .= ',';
b7d44c98d609 Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
90 }
b7d44c98d609 Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
91 $comma = TRUE;
b7d44c98d609 Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
92 $mashprofiles .= '{"record":' . $row['record'];
50
6d94167c2697 Next steps to implement a recipe editor
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
93 $mashprofiles .= ',"name":"' . str_replace($escapers, $replacements, $row['name']);
6d94167c2697 Next steps to implement a recipe editor
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
94 $mashprofiles .= '","notes":"' . str_replace($escapers, $replacements, $row['notes']);
38
b7d44c98d609 Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
95 $mashprofiles .= '","steps":' . $row['steps'];
b7d44c98d609 Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
96 $mashprofiles .= '}';
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 }
38
b7d44c98d609 Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
98 $mashprofiles .= ']';
b7d44c98d609 Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
99 header("Content-type: application/json");
b7d44c98d609 Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
100 echo $mashprofiles;
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 }
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 ?>

mercurial