www/includes/db_profile_water.php

Thu, 10 Feb 2022 22:15:10 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 10 Feb 2022 22:15:10 +0100
changeset 785
aa79acfdf8a9
parent 768
ae1195153fa2
permissions
-rw-r--r--

Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.

22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 <?php
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 require($_SERVER['DOCUMENT_ROOT']."/config.php");
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 require($_SERVER['DOCUMENT_ROOT']."/version.php");
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 #Connect to the database
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 if (! $connect) {
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
99c02fa797f9 Added inventory water profiles
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: 45
diff changeset
11 mysqli_set_charset($connect, "utf8" );
22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12
768
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
13 $response = array(
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
14 'error' => false,
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
15 'msg' => 'Ok',
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
16 );
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
17
211
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
18 if (isset($_POST['insert']) || isset($_POST['update'])) {
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
19 if (isset($_POST['insert'])) {
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
20 $sql = "INSERT INTO `profile_water` SET ";
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
21 }
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
22 if (isset($_POST['update'])) {
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
23 $sql = "UPDATE `profile_water` SET ";
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
24 }
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
25
785
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 768
diff changeset
26 if (isset($_POST['uuid']) && (strlen($_POST['uuid']) == 36)) {
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 768
diff changeset
27 $sql .= "uuid='" . $_POST['uuid'];
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 768
diff changeset
28 } else {
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 768
diff changeset
29 $uuid = str_replace("\n", "", file_get_contents('/proc/sys/kernel/random/uuid'));
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 768
diff changeset
30 $sql .= "uuid='" . $uuid;
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 768
diff changeset
31 }
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 768
diff changeset
32 $sql .= "', name='" . mysqli_real_escape_string($connect, $_POST['name']);
211
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
33 $sql .= "', calcium='" . $_POST['calcium'];
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
34 $sql .= "', bicarbonate='" . $_POST['bicarbonate'];
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
35 $sql .= "', sulfate='" . $_POST['sulfate'];
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
36 $sql .= "', chloride='" . $_POST['chloride'];
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
37 $sql .= "', sodium='" . $_POST['sodium'];
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
38 $sql .= "', magnesium='" . $_POST['magnesium'];
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
39 $sql .= "', ph='" . $_POST['ph'];
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
40 $sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']);
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
41 $sql .= "', total_alkalinity='" . $_POST['total_alkalinity'];
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
42 if (isset($_POST['insert'])) {
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
43 $sql .= "';";
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
44 }
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
45 if (isset($_POST['update'])) {
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
46 $sql .= "' WHERE record='" . $_POST['record'] . "';";
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
47 }
22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 $result = mysqli_query($connect, $sql);
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 if (! $result) {
45
95251bedfab4 Moved three inventory tables and screens to profiles
Michiel Broek <mbroek@mbse.eu>
parents: 37
diff changeset
50 syslog(LOG_NOTICE, "db_profile_water: ".$sql." result: ".mysqli_error($connect));
768
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
51 $response['error'] = true;
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
52 $response['msg'] = "SQL fout: ".mysqli_error($connect);
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
53 }
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
54 exit(json_encode($response));
22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55
211
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
56 } else if (isset($_POST['delete'])) {
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
57 // DELETE COMMAND
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
58 $sql = "DELETE FROM `profile_water` WHERE record='".$_POST['record']."';";
22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 $result = mysqli_query($connect, $sql);
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 if (! $result) {
45
95251bedfab4 Moved three inventory tables and screens to profiles
Michiel Broek <mbroek@mbse.eu>
parents: 37
diff changeset
61 syslog(LOG_NOTICE, "db_profile_water: ".$sql." result: ".mysqli_error($connect));
768
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
62 $response['error'] = true;
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
63 $response['msg'] = "SQL fout: ".mysqli_error($connect);
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
64 }
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
65 exit(json_encode($response));
22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 } else {
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 // SELECT COMMAND
211
63d0e40c58b9 Water profile uses POST instead of GET. Added tooltips to the editor screen. Updated the editor screen. Total alkalinity and Bicarbonate update each other. More and smaller columns in the listing screen. Rearranged the editor screen.
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
69 $query = "SELECT * FROM profile_water ORDER BY name";
22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 $waters[] = array(
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 'record' => $row['record'],
785
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 768
diff changeset
74 'uuid' => $row['uuid'],
22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 'name' => $row['name'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 'calcium' => $row['calcium'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 'bicarbonate' => $row['bicarbonate'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 'sulfate' => $row['sulfate'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 'chloride' => $row['chloride'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 'sodium' => $row['sodium'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 'magnesium' => $row['magnesium'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 'ph' => $row['ph'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 'notes' => $row['notes'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 'total_alkalinity' => $row['total_alkalinity']
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 );
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 }
296
69fadd1aded2 Updated design document. Add content header application/json to all scripts that produce json output. Chart prints show the beer code and name in the header. Charts don't display the menu anymore.
Michiel Broek <mbroek@mbse.eu>
parents: 211
diff changeset
87 header("Content-type: application/json");
768
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
88 exit(json_encode($waters));
22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 }
768
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
90
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
91 syslog(LOG_NOTICE, "db_profile_water: missing arguments");
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
92 $response['error'] = true;
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
93 $response['msg'] = "missing arguments";
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
94 echo json_encode($response);
ae1195153fa2 Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
95
22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 ?>

mercurial