www/includes/db_profile_water.php

Sun, 04 Jul 2021 20:01:13 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 04 Jul 2021 20:01:13 +0200
changeset 768
ae1195153fa2
parent 716
57118e6a4bdb
child 785
aa79acfdf8a9
permissions
-rw-r--r--

Better error reporting in profiles fermentation steps, mash profiles, beer styles, water profiles and general setup.

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
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
26 $sql .= "name='" . mysqli_real_escape_string($connect, $_POST['name']);
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
27 $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
28 $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
29 $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
30 $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
31 $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
32 $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
33 $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
34 $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
35 $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
36 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
37 $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
38 }
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 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
40 $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
41 }
22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 $result = mysqli_query($connect, $sql);
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 if (! $result) {
45
95251bedfab4 Moved three inventory tables and screens to profiles
Michiel Broek <mbroek@mbse.eu>
parents: 37
diff changeset
44 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
45 $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
46 $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
47 }
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
48 exit(json_encode($response));
22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49
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
50 } 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
51 // 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
52 $sql = "DELETE FROM `profile_water` WHERE record='".$_POST['record']."';";
22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 $result = mysqli_query($connect, $sql);
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 if (! $result) {
45
95251bedfab4 Moved three inventory tables and screens to profiles
Michiel Broek <mbroek@mbse.eu>
parents: 37
diff changeset
55 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
56 $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
57 $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
58 }
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
59 exit(json_encode($response));
22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 } else {
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 // 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
63 $query = "SELECT * FROM profile_water ORDER BY name";
22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 $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
65 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 $waters[] = array(
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 'record' => $row['record'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 'name' => $row['name'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 'calcium' => $row['calcium'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 'bicarbonate' => $row['bicarbonate'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 'sulfate' => $row['sulfate'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 'chloride' => $row['chloride'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 'sodium' => $row['sodium'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 'magnesium' => $row['magnesium'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 'ph' => $row['ph'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 'notes' => $row['notes'],
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 'total_alkalinity' => $row['total_alkalinity']
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 );
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 }
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
80 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
81 exit(json_encode($waters));
22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 }
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
83
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
84 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
85 $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
86 $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
87 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
88
22
99c02fa797f9 Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 ?>

mercurial