www/includes/db_setup.php

Sat, 17 Nov 2018 15:58:13 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 17 Nov 2018 15:58:13 +0100
changeset 99
f433193f7bb6
child 289
4082c41f45e9
permissions
-rw-r--r--

Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.

99
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 <?php
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 require($_SERVER['DOCUMENT_ROOT']."/config.php");
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 require($_SERVER['DOCUMENT_ROOT']."/version.php");
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 #Connect to the database
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 if (! $connect) {
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 }
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 mysqli_set_charset($connect, "utf8" );
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 $escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 $replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b");
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 $query = "SELECT * FROM profile_setup WHERE record='1'";
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 if (isset($_POST['update'])) {
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 /* Search water record */
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 $result = mysqli_query($connect, "SELECT record FROM inventory_waters WHERE name='".$_POST['default_water']."';");
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 $default_water = $row['record'];
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 else
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 $default_water = 0;
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 $sql = "UPDATE `profile_setup` SET ";
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 $sql .= "brewery_name='" . mysqli_real_escape_string($connect, $_POST['brewery_name']);
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 $sql .= "', factor_mashhop='" . $_POST['factor_mashhop'];
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 $sql .= "', factor_fwh='" . $_POST['factor_fwh'];
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 $sql .= "', factor_pellet='" . $_POST['factor_pellet'];
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 $sql .= "', factor_plug='" . $_POST['factor_plug'];
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 $sql .= "', color_method='" . mysqli_real_escape_string($connect, $_POST['color_method']);
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 $sql .= "', ibu_method='" . mysqli_real_escape_string($connect, $_POST['ibu_method']);
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 $sql .= "', brix_correction='" . $_POST['brix_correction'];
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 $sql .= "', grain_absorbtion='" . $_POST['grain_absorbtion'];
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 $sql .= "', default_water='" . $default_water;
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 $sql .= "' WHERE record='1';";
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 // syslog(LOG_NOTICE, $sql);
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 $result = mysqli_query($connect, $sql);
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 if (! $result) {
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 syslog(LOG_NOTICE, "db_profile_setup: ".$sql." result: ".mysqli_error($connect));
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 } else {
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 syslog(LOG_NOTICE, "db_profile_setup: updated record 1");
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 }
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 echo $result;
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 } else {
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 /* search water name */
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 $wresult = mysqli_query($connect, "SELECT name FROM inventory_waters WHERE record='".$row['default_water']."';");
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 if ($wrow = mysqli_fetch_array($wresult, MYSQLI_ASSOC))
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 $default_water = $wrow['name'];
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 else
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 $default_water = '';
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 $data = '{"record":' . $row['record'];
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 $data .= ',"brewery_name":"' . str_replace($escapers, $replacements, $row['brewery_name']);
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 $data .= '","factor_mashhop":' . $row['factor_mashhop'];
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 $data .= ',"factor_fwh":' . $row['factor_fwh'];
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 $data .= ',"factor_pellet":' . $row['factor_pellet'];
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 $data .= ',"factor_plug":' . $row['factor_plug'];
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 $data .= ',"ibu_method":"' . str_replace($escapers, $replacements, $row['ibu_method']);
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 $data .= '","color_method":"' . str_replace($escapers, $replacements, $row['color_method']);
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 $data .= '","brix_correction":' . floatval($row['brix_correction']);
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 $data .= ',"grain_absorbtion":' . floatval($row['grain_absorbtion']);
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 $data .= ',"default_water":"' . str_replace($escapers, $replacements, $default_water);
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 $data .= '"}';
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 }
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 header("Content-type: application/json");
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 echo $data;
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 }
f433193f7bb6 Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 ?>

mercurial