Sat, 15 Dec 2018 21:27:01 +0100
During hops load an extra weight in grams field is generated for the grid. Edit the amount is done on the weight field and the amount field is updated too. During save to the database the extra field is removed.
14 | 1 | <?php |
2 | ||
3 | require($_SERVER['DOCUMENT_ROOT']."/config.php"); | |
4 | require($_SERVER['DOCUMENT_ROOT']."/version.php"); | |
5 | ||
6 | #Connect to the database | |
7 | $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); | |
8 | if (! $connect) { | |
9 | die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); | |
10 | } | |
77
a9f8de2d7b2b
Fixed most charset problems. Added fpdf library. Added inventory pdf creation.
Michiel Broek <mbroek@mbse.eu>
parents:
37
diff
changeset
|
11 | mysqli_set_charset($connect, "utf8" ); |
14 | 12 | |
13 | // get data and store in a json array | |
37
9362eb9e9e5b
Sorting the inventory and changes some grid tables.
Michiel Broek <mbroek@mbse.eu>
parents:
33
diff
changeset
|
14 | $query = "SELECT * FROM inventory_yeasts ORDER BY laboratory,product_id,name"; |
14 | 15 | if (isset($_GET['insert'])) { |
16 | // INSERT COMMAND | |
17 | $sql = "INSERT INTO `inventory_yeasts` SET name='" . mysqli_real_escape_string($connect, $_GET['name']); | |
18 | $sql .= "', type='" . $_GET['type']; | |
19 | $sql .= "', form='" . $_GET['form']; | |
20 | $sql .= "', laboratory='" . mysqli_real_escape_string($connect, $_GET['laboratory']); | |
21 | $sql .= "', product_id='" . mysqli_real_escape_string($connect, $_GET['product_id']); | |
22 | $sql .= "', min_temperature='" . $_GET['min_temperature']; | |
23 | $sql .= "', max_temperature='" . $_GET['max_temperature']; | |
24 | $sql .= "', flocculation='" . $_GET['flocculation']; | |
25 | $sql .= "', attenuation='" . $_GET['attenuation']; | |
26 | $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); | |
27 | $sql .= "', best_for='" . mysqli_real_escape_string($connect, $_GET['best_for']); | |
28 | $sql .= "', max_reuse='" . $_GET['max_reuse']; | |
33
2ee6ad5d6f14
More weight/volmes standards in the database.
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
29 | $sql .= "', inventory='" . floatval($_GET['inventory']) / 1000.0; |
14 | 30 | $sql .= "', cost='" . $_GET['cost']; |
31 | $sql .= "', production_date='" . $_GET['production_date']; | |
32 | $sql .= "', tht_date='" . $_GET['tht_date']; | |
33 | $sql .= "';"; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
34 | $result = mysqli_query($connect, $sql); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
35 | if (! $result) { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
36 | syslog(LOG_NOTICE, "db_inventory_yeasts: ".$sql." result: ".mysqli_error($connect)); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
37 | } else { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
38 | syslog(LOG_NOTICE, "db_inventory_yeasts: inserted ".$_GET['name']); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
39 | } |
14 | 40 | echo $result; |
41 | ||
42 | } else if (isset($_GET['update'])) { | |
43 | // UPDATE COMMAND | |
44 | $sql = "UPDATE `inventory_yeasts` SET name='" . mysqli_real_escape_string($connect, $_GET['name']); | |
45 | $sql .= "', type='" . $_GET['type']; | |
46 | $sql .= "', form='" . $_GET['form']; | |
47 | $sql .= "', laboratory='" . mysqli_real_escape_string($connect, $_GET['laboratory']); | |
48 | $sql .= "', product_id='" . mysqli_real_escape_string($connect, $_GET['product_id']); | |
49 | $sql .= "', min_temperature='" . $_GET['min_temperature']; | |
50 | $sql .= "', max_temperature='" . $_GET['max_temperature']; | |
51 | $sql .= "', flocculation='" . $_GET['flocculation']; | |
52 | $sql .= "', attenuation='" . $_GET['attenuation']; | |
53 | $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); | |
54 | $sql .= "', best_for='" . mysqli_real_escape_string($connect, $_GET['best_for']); | |
55 | $sql .= "', max_reuse='" . $_GET['max_reuse']; | |
33
2ee6ad5d6f14
More weight/volmes standards in the database.
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
56 | $sql .= "', inventory='" . floatval($_GET['inventory']) / 1000.0; |
14 | 57 | $sql .= "', cost='" . $_GET['cost']; |
58 | $sql .= "', production_date='" . $_GET['production_date']; | |
59 | $sql .= "', tht_date='" . $_GET['tht_date']; | |
60 | $sql .= "' WHERE record='" . $_GET['record'] . "';"; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
61 | $result = mysqli_query($connect, $sql); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
62 | if (! $result) { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
63 | syslog(LOG_NOTICE, "db_inventory_yeasts: ".$sql." result: ".mysqli_error($connect)); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
64 | } else { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
65 | syslog(LOG_NOTICE, "db_inventory_yeasts: updated record ".$_GET['record']); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
66 | } |
14 | 67 | echo $result; |
68 | ||
69 | } else if (isset($_GET['delete'])) { | |
70 | // DELETE COMMAND | |
71 | $sql = "DELETE FROM `inventory_yeasts` WHERE record='".$_GET['record']."';"; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
72 | $result = mysqli_query($connect, $sql); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
73 | if (! $result) { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
74 | syslog(LOG_NOTICE, "db_inventory_yeasts: ".$sql." result: ".mysqli_error($connect)); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
75 | } else { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
76 | syslog(LOG_NOTICE, "db_inventory_yeasts: deleted record ".$_GET['record']); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
77 | } |
14 | 78 | echo $result; |
79 | ||
80 | } else { | |
81 | // SELECT COMMAND | |
82 | $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); | |
83 | while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { | |
84 | $yeasts[] = array( | |
85 | 'record' => $row['record'], | |
86 | 'name' => $row['name'], | |
87 | 'type' => $row['type'], | |
88 | 'form' => $row['form'], | |
89 | 'laboratory' => $row['laboratory'], | |
90 | 'product_id' => $row['product_id'], | |
91 | 'min_temperature' => $row['min_temperature'], | |
92 | 'max_temperature' => $row['max_temperature'], | |
93 | 'flocculation' => $row['flocculation'], | |
94 | 'attenuation' => $row['attenuation'], | |
95 | 'notes' => $row['notes'], | |
96 | 'best_for' => $row['best_for'], | |
97 | 'max_reuse' => $row['max_reuse'], | |
33
2ee6ad5d6f14
More weight/volmes standards in the database.
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
98 | 'inventory' => floatval($row['inventory']) * 1000.0, |
14 | 99 | 'cost' => $row['cost'], |
100 | 'production_date' => $row['production_date'], | |
101 | 'tht_date' => $row['tht_date'] | |
102 | ); | |
103 | } | |
104 | echo json_encode($yeasts); | |
105 | } | |
106 | ?> |