Thu, 30 May 2019 23:19:43 +0200
Version 0.4.1
12 | 1 | <?php |
2 | ||
3 | require($_SERVER['DOCUMENT_ROOT']."/config.php"); | |
4 | require($_SERVER['DOCUMENT_ROOT']."/version.php"); | |
5 | ||
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
6 | |
12 | 7 | #Connect to the database |
8 | $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); | |
9 | if (! $connect) { | |
10 | die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); | |
11 | } | |
77
a9f8de2d7b2b
Fixed most charset problems. Added fpdf library. Added inventory pdf creation.
Michiel Broek <mbroek@mbse.eu>
parents:
37
diff
changeset
|
12 | mysqli_set_charset($connect, "utf8" ); |
12 | 13 | |
196
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
14 | if (isset($_POST['insert']) || isset($_POST['update'])) { |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
15 | if (isset($_POST['insert'])) { |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
16 | $sql = "INSERT INTO `inventory_hops` SET "; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
17 | } |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
18 | if (isset($_POST['update'])) { |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
19 | $sql = "UPDATE `inventory_hops` SET "; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
20 | } |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
21 | |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
22 | $sql .= "name='" . mysqli_real_escape_string($connect, $_POST['name']); |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
23 | $sql .= "', alpha='" . $_POST['alpha']; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
24 | $sql .= "', beta='" . $_POST['beta']; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
25 | $sql .= "', humulene='" . $_POST['humulene']; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
26 | $sql .= "', caryophyllene='" . $_POST['caryophyllene']; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
27 | $sql .= "', cohumulone='" . $_POST['cohumulone']; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
28 | $sql .= "', myrcene='" . $_POST['myrcene']; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
29 | $sql .= "', hsi='" . $_POST['hsi']; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
30 | $sql .= "', type='" . $_POST['type']; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
31 | $sql .= "', form='" . $_POST['form']; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
32 | $sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']); |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
33 | $sql .= "', origin='" . mysqli_real_escape_string($connect, $_POST['origin']); |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
34 | $sql .= "', substitutes='" . mysqli_real_escape_string($connect, $_POST['substitutes']); |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
35 | ($_POST['always_on_stock'] == 'true') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
36 | $sql .= "', inventory='" . floatval($_POST['inventory']) / 1000.0; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
37 | $sql .= "', cost='" . $_POST['cost'] . "'"; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
38 | if ($_POST['production_date'] == '') |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
39 | $sql .= ", production_date=NULL"; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
40 | else |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
41 | $sql .= ", production_date='" . $_POST['production_date'] . "'"; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
42 | if ($_POST['tht_date'] == '') |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
43 | $sql .= ", tht_date=NULL"; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
44 | else |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
45 | $sql .= ", tht_date='" . $_POST['tht_date'] . "'"; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
46 | $sql .= ", total_oil='" . $_POST['total_oil']; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
47 | if (isset($_POST['insert'])) { |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
48 | $sql .= "';"; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
49 | } |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
50 | if (isset($_POST['update'])) { |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
51 | $sql .= "' WHERE record='" . $_POST['record'] . "';"; |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
52 | } |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
53 | syslog(LOG_NOTICE, $sql); |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
54 | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
55 | $result = mysqli_query($connect, $sql); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
56 | if (! $result) { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
57 | syslog(LOG_NOTICE, "db_inventory_hops: ".$sql." result: ".mysqli_error($connect)); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
58 | } else { |
196
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
59 | if (isset($_POST['update'])) { |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
60 | syslog(LOG_NOTICE, "db_inventory_hops: updated record ".$_POST['record']); |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
61 | } else { |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
62 | $lastid = mysqli_insert_id($connect); |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
63 | syslog(LOG_NOTICE, "db_inventory_hops: inserted record ".$lastid); |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
64 | } |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
65 | } |
12 | 66 | echo $result; |
67 | ||
196
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
68 | } else if (isset($_POST['delete'])) { |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
69 | // DELETE COMMAND |
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
70 | $sql = "DELETE FROM `inventory_hops` WHERE record='".$_POST['record']."';"; |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
71 | $result = mysqli_query($connect, $sql); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
72 | if (! $result) { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
73 | syslog(LOG_NOTICE, "db_inventory_hops: ".$sql." result: ".mysqli_error($connect)); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
74 | } else { |
196
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
75 | syslog(LOG_NOTICE, "db_inventory_hops: deleted record ".$_POST['record']); |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
76 | } |
12 | 77 | echo $result; |
78 | ||
79 | } else { | |
80 | // SELECT COMMAND | |
196
531d5458782f
Hops database bool to int types. Dropdown lists are using tables with indexes. Dropdown lists display in Dutch. Save and delete in the database now use POST instead of GET. Removed the useat field. Redesigned the web page. Code cleanup.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
81 | $query = "SELECT * FROM inventory_hops ORDER BY origin,name"; |
12 | 82 | $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); |
83 | while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { | |
84 | $hops[] = array( | |
85 | 'record' => $row['record'], | |
86 | 'name' => $row['name'], | |
87 | 'alpha' => $row['alpha'], | |
88 | 'beta' => $row['beta'], | |
89 | 'humulene' => $row['humulene'], | |
90 | 'caryophyllene' => $row['caryophyllene'], | |
91 | 'cohumulone' => $row['cohumulone'], | |
92 | 'myrcene' => $row['myrcene'], | |
13 | 93 | 'hsi' => $row['hsi'], |
12 | 94 | 'type' => $row['type'], |
95 | 'form' => $row['form'], | |
96 | 'notes' => $row['notes'], | |
97 | 'origin' => $row['origin'], | |
98 | 'substitutes' => $row['substitutes'], | |
99 | 'always_on_stock' => $row['always_on_stock'], | |
33
2ee6ad5d6f14
More weight/volmes standards in the database.
Michiel Broek <mbroek@mbse.eu>
parents:
30
diff
changeset
|
100 | 'inventory' => floatval($row['inventory']) * 1000.0, |
12 | 101 | 'cost' => $row['cost'], |
102 | 'production_date' => $row['production_date'], | |
103 | 'tht_date' => $row['tht_date'], | |
13 | 104 | 'total_oil' => $row['total_oil'] |
12 | 105 | ); |
106 | } | |
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:
196
diff
changeset
|
107 | header("Content-type: application/json"); |
12 | 108 | echo json_encode($hops); |
109 | } | |
110 | ?> |