Sat, 26 Jan 2019 22:01:11 +0100
First step to make profile mash work with indexes and make the edit screen universal.
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 | 15 | $rescapers = array("'"); |
16 | $rreplacements = array("\\'"); | |
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 | 21 | $sql = "INSERT INTO"; |
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 | 24 | $sql = "UPDATE"; |
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']; |
120 | 29 | foreach($array as $key => $item){ |
30 | foreach ($disallowed as $disallowed_key) { | |
31 | unset($array[$key]["$disallowed_key"]); | |
32 | } | |
33 | } | |
34 | $sql .= "', steps='" . str_replace($rescapers,$rreplacements,json_encode($array)); | |
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
|
35 | if (isset($_POST['insert'])) { |
120 | 36 | $sql .= "';"; |
37 | } | |
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
|
38 | 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
|
39 | $sql .= "' WHERE record='" . $_POST['record'] . "';"; |
120 | 40 | } |
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
|
41 | $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
|
42 | if (! $result) { |
45
95251bedfab4
Moved three inventory tables and screens to profiles
Michiel Broek <mbroek@mbse.eu>
parents:
38
diff
changeset
|
43 | 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
|
44 | } 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
|
45 | 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
|
46 | syslog(LOG_NOTICE, "db_profile_mash: updated record ".$_POST['record']); |
120 | 47 | } else { |
48 | $lastid = mysqli_insert_id($connect); | |
49 | syslog(LOG_NOTICE, "db_profile_mash: inserted record ".$lastid); | |
50 | } | |
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
|
51 | } |
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
|
52 | 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
|
53 | |
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
|
54 | } 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
|
55 | // 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
|
56 | $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
|
57 | $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
|
58 | if (! $result) { |
45
95251bedfab4
Moved three inventory tables and screens to profiles
Michiel Broek <mbroek@mbse.eu>
parents:
38
diff
changeset
|
59 | 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
|
60 | } 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
|
61 | 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
|
62 | } |
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
|
63 | 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
|
64 | |
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
|
65 | } 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
|
66 | // 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
|
67 | $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
|
68 | $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
|
69 | $mashprofiles = '['; |
b7d44c98d609
Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents:
25
diff
changeset
|
70 | $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
|
71 | 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
|
72 | // Manual encode to JSON. |
b7d44c98d609
Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents:
25
diff
changeset
|
73 | if ($comma) { |
b7d44c98d609
Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents:
25
diff
changeset
|
74 | $mashprofiles .= ','; |
b7d44c98d609
Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents:
25
diff
changeset
|
75 | } |
b7d44c98d609
Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents:
25
diff
changeset
|
76 | $comma = TRUE; |
b7d44c98d609
Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents:
25
diff
changeset
|
77 | $mashprofiles .= '{"record":' . $row['record']; |
50
6d94167c2697
Next steps to implement a recipe editor
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
78 | $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
|
79 | $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
|
80 | $mashprofiles .= '","steps":' . $row['steps']; |
b7d44c98d609
Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents:
25
diff
changeset
|
81 | $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
|
82 | } |
38
b7d44c98d609
Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents:
25
diff
changeset
|
83 | $mashprofiles .= ']'; |
b7d44c98d609
Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents:
25
diff
changeset
|
84 | header("Content-type: application/json"); |
b7d44c98d609
Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents:
25
diff
changeset
|
85 | 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
|
86 | } |
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
|
87 | ?> |