Fri, 07 May 2021 13:20:53 +0200
Can start the daemon as root, and it will drop privileges.
27 | 1 | <?php |
2 | require($_SERVER['DOCUMENT_ROOT']."/config.php"); | |
3 | require($_SERVER['DOCUMENT_ROOT']."/version.php"); | |
4 | ||
5 | #Connect to the database | |
6 | $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); | |
7 | if (! $connect) { | |
8 | die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); | |
9 | } | |
77
a9f8de2d7b2b
Fixed most charset problems. Added fpdf library. Added inventory pdf creation.
Michiel Broek <mbroek@mbse.eu>
parents:
37
diff
changeset
|
10 | mysqli_set_charset($connect, "utf8" ); |
27 | 11 | |
209
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
12 | if (isset($_POST['insert']) || isset($_POST['update'])) { |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
13 | if (isset($_POST['insert'])) { |
115
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
14 | // INSERT COMMAND |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
15 | $sql = "INSERT INTO `inventory_equipments` SET "; |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
16 | } |
209
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
17 | if (isset($_POST['update'])) { |
115
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
18 | // UPDATE COMMAND |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
19 | $sql = "UPDATE `inventory_equipments` SET "; |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
20 | } |
209
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
21 | $sql .= "name='" . mysqli_real_escape_string($connect, $_POST['name']); |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
22 | $sql .= "', boil_size='" . $_POST['boil_size']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
23 | $sql .= "', batch_size='" . $_POST['batch_size']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
24 | $sql .= "', tun_volume='" . $_POST['tun_volume']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
25 | $sql .= "', tun_weight='" . $_POST['tun_weight']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
26 | $sql .= "', tun_specific_heat='" . $_POST['tun_specific_heat']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
27 | $sql .= "', tun_material='" . $_POST['tun_material']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
28 | $sql .= "', tun_height='" . floatval($_POST['tun_height']) / 100.0; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
29 | $sql .= "', top_up_water='" . $_POST['top_up_water']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
30 | $sql .= "', trub_chiller_loss='" . $_POST['trub_chiller_loss']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
31 | $sql .= "', evap_rate='" . $_POST['evap_rate']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
32 | $sql .= "', boil_time='" . $_POST['boil_time']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
33 | ($_POST['calc_boil_volume'] == 'true') ? $sql .= "', calc_boil_volume='1" : $sql .= "', calc_boil_volume='0"; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
34 | $sql .= "', top_up_kettle='" . $_POST['top_up_kettle']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
35 | $sql .= "', hop_utilization='" . $_POST['hop_utilization']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
36 | $sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']); |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
37 | $sql .= "', lauter_volume='" . $_POST['lauter_volume']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
38 | $sql .= "', lauter_height='" . floatval($_POST['lauter_height']) / 100.0; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
39 | $sql .= "', lauter_deadspace='" . $_POST['lauter_deadspace']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
40 | $sql .= "', kettle_volume='" . $_POST['kettle_volume']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
41 | $sql .= "', kettle_height='" . floatval($_POST['kettle_height']) / 100.0; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
42 | $sql .= "', mash_volume='" . $_POST['mash_volume']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
43 | $sql .= "', mash_max='" . $_POST['mash_max']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
44 | $sql .= "', efficiency='" . $_POST['efficiency']; |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
45 | if (isset($_POST['insert'])) { |
115
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
46 | $sql .= "';"; |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
47 | } |
209
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
48 | if (isset($_POST['update'])) { |
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
49 | $sql .= "' WHERE record='" . $_POST['record'] . "';"; |
115
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
50 | } |
27 | 51 | $result = mysqli_query($connect, $sql); |
52 | if (! $result) { | |
53 | syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); | |
715
8fb922c00a2d
Remove log messages if database inventory updates are successfull. Allways update inventory reduced stages.
Michiel Broek <mbroek@mbse.eu>
parents:
296
diff
changeset
|
54 | //} else { |
8fb922c00a2d
Remove log messages if database inventory updates are successfull. Allways update inventory reduced stages.
Michiel Broek <mbroek@mbse.eu>
parents:
296
diff
changeset
|
55 | // if (isset($_POST['update'])) { |
8fb922c00a2d
Remove log messages if database inventory updates are successfull. Allways update inventory reduced stages.
Michiel Broek <mbroek@mbse.eu>
parents:
296
diff
changeset
|
56 | // syslog(LOG_NOTICE, "db_inventory_equipment: updated record ".$_POST['record']); |
8fb922c00a2d
Remove log messages if database inventory updates are successfull. Allways update inventory reduced stages.
Michiel Broek <mbroek@mbse.eu>
parents:
296
diff
changeset
|
57 | // } else { |
8fb922c00a2d
Remove log messages if database inventory updates are successfull. Allways update inventory reduced stages.
Michiel Broek <mbroek@mbse.eu>
parents:
296
diff
changeset
|
58 | // $lastid = mysqli_insert_id($connect); |
8fb922c00a2d
Remove log messages if database inventory updates are successfull. Allways update inventory reduced stages.
Michiel Broek <mbroek@mbse.eu>
parents:
296
diff
changeset
|
59 | // syslog(LOG_NOTICE, "db_inventory_equipment: inserted record ".$lastid); |
8fb922c00a2d
Remove log messages if database inventory updates are successfull. Allways update inventory reduced stages.
Michiel Broek <mbroek@mbse.eu>
parents:
296
diff
changeset
|
60 | // } |
27 | 61 | } |
62 | echo $result; | |
63 | ||
209
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
64 | } else if (isset($_POST['delete'])) { |
27 | 65 | // DELETE COMMAND |
66 | // FIXME: need to check if the record is in use | |
209
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
67 | $sql = "DELETE FROM `inventory_equipments` WHERE record='".$_POST['record']."';"; |
27 | 68 | $result = mysqli_query($connect, $sql); |
69 | if (! $result) { | |
70 | syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); | |
71 | } else { | |
209
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
72 | syslog(LOG_NOTICE, "db_inventory_equipment: deleted record ".$_POST['record']); |
27 | 73 | } |
74 | echo $result; | |
75 | ||
76 | } else { | |
77 | // SELECT COMMAND | |
209
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
78 | $query = "SELECT * FROM inventory_equipments ORDER BY name"; |
27 | 79 | $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); |
80 | while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { | |
81 | $equipments[] = array( | |
82 | 'record' => $row['record'], | |
83 | 'name' => $row['name'], | |
84 | 'boil_size' => $row['boil_size'], | |
85 | 'batch_size' => $row['batch_size'], | |
86 | 'tun_volume' => $row['tun_volume'], | |
87 | 'tun_weight' => $row['tun_weight'], | |
115
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
88 | 'tun_specific_heat' => $row['tun_specific_heat'], |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
89 | 'tun_material' => $row['tun_material'], |
209
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
90 | 'tun_height' => floatval($row['tun_height']) * 100.0, |
27 | 91 | 'top_up_water' => $row['top_up_water'], |
92 | 'trub_chiller_loss' => $row['trub_chiller_loss'], | |
93 | 'evap_rate' => $row['evap_rate'], | |
94 | 'boil_time' => $row['boil_time'], | |
115
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
95 | 'calc_boil_volume' => $row['calc_boil_volume'], |
27 | 96 | 'top_up_kettle' => $row['top_up_kettle'], |
97 | 'hop_utilization' => $row['hop_utilization'], | |
98 | 'notes' => $row['notes'], | |
99 | 'lauter_volume' => $row['lauter_volume'], | |
209
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
100 | 'lauter_height' => floatval($row['lauter_height']) * 100.0, |
115
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
101 | 'lauter_deadspace' => $row['lauter_deadspace'], |
27 | 102 | 'kettle_volume' => $row['kettle_volume'], |
209
dc30801e6961
Import set tun_material from the specifix heat value. Equipment database uses POST instead of GET. Equipment editor screen in style with other inventory screens. In stock print now uses the type indexes to translate to text. Also show the correct unit and values of the yeast.
Michiel Broek <mbroek@mbse.eu>
parents:
149
diff
changeset
|
103 | 'kettle_height' => floatval($row['kettle_height']) * 100.0, |
27 | 104 | 'mash_volume' => $row['mash_volume'], |
149
ff45488d480e
Added some icons from Brewersfriend. They should be replaced someday. Added maximum mash weight setting to the equipment database. Usefull for brew automate and RIMS systems. During recipes import acid and base additions are translated. Brews and recipes now have 2 water sources. Added water mixer. Added basic water treatment, but not for pH yet. Redesigned the fermentables and water tabs.
Michiel Broek <mbroek@mbse.eu>
parents:
116
diff
changeset
|
105 | 'mash_max' => $row['mash_max'], |
27 | 106 | 'efficiency' => $row['efficiency'] |
107 | ); | |
108 | } | |
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:
209
diff
changeset
|
109 | header("Content-type: application/json"); |
27 | 110 | echo json_encode($equipments); |
111 | } | |
112 | ?> |