www/includes/db_inventory_fermentables.php

changeset 11
d341f0a91a91
child 18
395833e20f88
equal deleted inserted replaced
10:606b4af8f918 11:d341f0a91a91
1 <?php
2
3 require($_SERVER['DOCUMENT_ROOT']."/config.php");
4 require($_SERVER['DOCUMENT_ROOT']."/version.php");
5
6
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 }
12
13 // get data and store in a json array
14 $query = "SELECT * FROM inventory_fermentables";
15 if (isset($_GET['insert'])) {
16 // INSERT COMMAND
17 $sql = "INSERT INTO `inventory_fermentables` SET name='" . mysqli_real_escape_string($connect, $_GET['name']);
18 $sql .= "', type='" . $_GET['type'];
19 $sql .= "', yield='" . $_GET['yield'];
20 $sql .= "', color='" . ebc_to_srm($_GET['color']);
21 ($_GET['add_after_boil'] == 'true') ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0";
22 $sql .= "', origin='" . mysqli_real_escape_string($connect, $_GET['origin']);
23 $sql .= "', supplier='" . mysqli_real_escape_string($connect, $_GET['supplier']);
24 $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']);
25 $sql .= "', coarse_fine_diff='" . $_GET['coarse_fine_diff'];
26 $sql .= "', moisture='" . $_GET['moisture'];
27 $sql .= "', diastatic_power='" . $_GET['diastatic_power'];
28 $sql .= "', protein='" . $_GET['protein'];
29 $sql .= "', max_in_batch='" . $_GET['max_in_batch'];
30 ($_GET['recommend_mash'] == 'true') ? $sql .= "', recommend_mash='1" : $sql .= "', recommend_mash='0";
31 $sql .= "', ibu_gal_per_lb='" . $_GET['ibu_gal_per_lb'];
32 ($_GET['always_on_stock'] == 'true') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0";
33 $sql .= "', di_ph='" . $_GET['di_ph'];
34 $sql .= "', acid_to_ph_57='" . $_GET['acid_to_ph_57'];
35 $sql .= "', graintype='" . mysqli_real_escape_string($connect, $_GET['graintype']);
36 $sql .= "', inventory='" . $_GET['inventory'];
37 $sql .= "', cost='" . $_GET['cost'];
38 $sql .= "', production_date='" . $_GET['production_date'];
39 $sql .= "', tht_date='" . $_GET['tht_date'];
40 $sql .= "', supplier_rec='" . $_GET['supplier_rec'];
41 $sql .= "';";
42 error_log("\"$sql\"");
43 $result = mysqli_query($connect, $sql) or die("SQL Error 1: " . mysqli_error($connect));
44 error_log("result " . $result);
45 echo $result;
46
47 } else if (isset($_GET['update'])) {
48 // UPDATE COMMAND
49 $sql = "UPDATE `inventory_fermentables` SET name='" . mysqli_real_escape_string($connect, $_GET['name']);
50 $sql .= "', type='" . $_GET['type'];
51 $sql .= "', yield='" . $_GET['yield'];
52 $sql .= "', color='" . ebc_to_srm($_GET['color']);
53 ($_GET['add_after_boil'] == 'true') ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0";
54 $sql .= "', origin='" . mysqli_real_escape_string($connect, $_GET['origin']);
55 $sql .= "', supplier='" . mysqli_real_escape_string($connect, $_GET['supplier']);
56 $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']);
57 $sql .= "', coarse_fine_diff='" . $_GET['coarse_fine_diff'];
58 $sql .= "', moisture='" . $_GET['moisture'];
59 $sql .= "', diastatic_power='" . $_GET['diastatic_power'];
60 $sql .= "', protein='" . $_GET['protein'];
61 $sql .= "', max_in_batch='" . $_GET['max_in_batch'];
62 ($_GET['recommend_mash'] == 'true') ? $sql .= "', recommend_mash='1" : $sql .= "', recommend_mash='0";
63 $sql .= "', ibu_gal_per_lb='" . $_GET['ibu_gal_per_lb'];
64 ($_GET['always_on_stock'] == 'true') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0";
65 $sql .= "', di_ph='" . $_GET['di_ph'];
66 $sql .= "', acid_to_ph_57='" . $_GET['acid_to_ph_57'];
67 $sql .= "', graintype='" . mysqli_real_escape_string($connect, $_GET['graintype']);
68 $sql .= "', inventory='" . $_GET['inventory'];
69 $sql .= "', cost='" . $_GET['cost'];
70 $sql .= "', production_date='" . $_GET['production_date'];
71 $sql .= "', tht_date='" . $_GET['tht_date'];
72 $sql .= "', supplier_rec='" . $_GET['supplier_rec'];
73 $sql .= "' WHERE record='" . $_GET['record'] . "';";
74 error_log("\"$sql\"");
75 $result = mysqli_query($connect, $sql) or die("SQL Error 1: " . mysqli_error($connect));
76 error_log("result " . $result);
77 echo $result;
78
79 } else if (isset($_GET['delete'])) {
80 // DELETE COMMAND
81 $sql = "DELETE FROM `inventory_fermentables` WHERE record='".$_GET['record']."';";
82 error_log("\"$sql\"");
83 $result = mysqli_query($connect, $sql) or die("SQL Error 1: " . mysqli_error($connect));
84 error_log("result " . $result);
85 echo $result;
86
87 } else {
88 // SELECT COMMAND
89 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
90 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
91 $fermentables[] = array(
92 'record' => $row['record'],
93 'name' => $row['name'],
94 'type' => $row['type'],
95 'yield' => $row['yield'],
96 'color' => $row['color'],
97 'add_after_boil' => $row['add_after_boil'],
98 'origin' => $row['origin'],
99 'supplier' => $row['supplier'],
100 'notes' => $row['notes'],
101 'coarse_fine_diff' => $row['coarse_fine_diff'],
102 'moisture' => $row['moisture'],
103 'diastatic_power' => $row['diastatic_power'],
104 'protein' => $row['protein'],
105 'max_in_batch' => $row['max_in_batch'],
106 'recommend_mash' => $row['recommend_mash'],
107 'ibu_gal_per_lb' => $row['ibu_gal_per_lb'],
108 'always_on_stock' => $row['always_on_stock'],
109 'di_ph' => $row['di_ph'],
110 'acid_to_ph_57' => $row['acid_to_ph_57'],
111 'graintype' => $row['graintype'],
112 'inventory' => $row['inventory'],
113 'cost' => $row['cost'],
114 'production_date' => $row['production_date'],
115 'tht_date' => $row['tht_date'],
116 'supplier_rec' => $row['supplier_rec']
117 );
118 }
119 echo json_encode($fermentables);
120 }
121 ?>

mercurial