www/includes/db_inventory_styles.php

changeset 45
95251bedfab4
parent 44
6fea20eead56
child 46
ff9be9dbcac0
equal deleted inserted replaced
44:6fea20eead56 45:95251bedfab4
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 }
11
12 // get data and store in a json array
13 $query = "SELECT * FROM inventory_styles ORDER BY name";
14 if (isset($_GET['insert'])) {
15 // INSERT COMMAND
16 $sql = "INSERT INTO `inventory_styles` SET name='" . mysqli_real_escape_string($connect, $_GET['name']);
17 $sql .= "', category='" . mysqli_real_escape_string($connect, $_GET['category']);
18 $sql .= "', category_number='" . $_GET['category_number'];
19 $sql .= "', style_letter='" . mysqli_real_escape_string($connect, $_GET['style_letter']);
20 $sql .= "', style_guide='" . mysqli_real_escape_string($connect, $_GET['style_guide']);
21 $sql .= "', type='" . $_GET['type'];
22 $sql .= "', og_min='" . $_GET['og_min'];
23 $sql .= "', og_max='" . $_GET['og_max'];
24 $sql .= "', fg_min='" . $_GET['fg_min'];
25 $sql .= "', fg_max='" . $_GET['fg_max'];
26 $sql .= "', ibu_min='" . $_GET['ibu_min'];
27 $sql .= "', ibu_max='" . $_GET['ibu_max'];
28 $sql .= "', color_min='" . $_GET['color_min'];
29 $sql .= "', color_max='" . $_GET['color_max'];
30 $sql .= "', carb_min='" . $_GET['carb_min'];
31 $sql .= "', carb_max='" . $_GET['carb_max'];
32 $sql .= "', abv_min='" . $_GET['abv_min'];
33 $sql .= "', abv_max='" . $_GET['abv_max'];
34 $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']);
35 $sql .= "', profile='" . mysqli_real_escape_string($connect, $_GET['profile']);
36 $sql .= "', ingredients='" . mysqli_real_escape_string($connect, $_GET['ingredients']);
37 $sql .= "', examples='" . mysqli_real_escape_string($connect, $_GET['examples']);
38 $sql .= "';";
39 $result = mysqli_query($connect, $sql);
40 if (! $result) {
41 syslog(LOG_NOTICE, "db_inventory_styles: ".$sql." result: ".mysqli_error($connect));
42 } else {
43 syslog(LOG_NOTICE, "db_inventory_styles: inserted ".$_GET['name']);
44 }
45 echo $result;
46
47 } else if (isset($_GET['update'])) {
48 // UPDATE COMMAND
49 $sql = "UPDATE `inventory_styles` SET name='" . mysqli_real_escape_string($connect, $_GET['name']);
50 $sql .= "', category='" . mysqli_real_escape_string($connect, $_GET['category']);
51 $sql .= "', category_number='" . $_GET['category_number'];
52 $sql .= "', style_letter='" . mysqli_real_escape_string($connect, $_GET['style_letter']);
53 $sql .= "', style_guide='" . mysqli_real_escape_string($connect, $_GET['style_guide']);
54 $sql .= "', type='" . $_GET['type'];
55 $sql .= "', og_min='" . $_GET['og_min'];
56 $sql .= "', og_max='" . $_GET['og_max'];
57 $sql .= "', fg_min='" . $_GET['fg_min'];
58 $sql .= "', fg_max='" . $_GET['fg_max'];
59 $sql .= "', ibu_min='" . $_GET['ibu_min'];
60 $sql .= "', ibu_max='" . $_GET['ibu_max'];
61 $sql .= "', color_min='" . $_GET['color_min'];
62 $sql .= "', color_max='" . $_GET['color_max'];
63 $sql .= "', carb_min='" . $_GET['carb_min'];
64 $sql .= "', carb_max='" . $_GET['carb_max'];
65 $sql .= "', abv_min='" . $_GET['abv_min'];
66 $sql .= "', abv_max='" . $_GET['abv_max'];
67 $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']);
68 $sql .= "', profile='" . mysqli_real_escape_string($connect, $_GET['profile']);
69 $sql .= "', ingredients='" . mysqli_real_escape_string($connect, $_GET['ingredients']);
70 $sql .= "', examples='" . mysqli_real_escape_string($connect, $_GET['examples']);
71 $sql .= "' WHERE record='" . $_GET['record'] . "';";
72 $result = mysqli_query($connect, $sql);
73 if (! $result) {
74 syslog(LOG_NOTICE, "db_inventory_styles: ".$sql." result: ".mysqli_error($connect));
75 } else {
76 syslog(LOG_NOTICE, "db_inventory_styles: updated record ".$_GET['record']);
77 }
78 echo $result;
79
80 } else if (isset($_GET['delete'])) {
81 // DELETE COMMAND
82 $sql = "DELETE FROM `inventory_styles` WHERE record='".$_GET['record']."';";
83 $result = mysqli_query($connect, $sql);
84 if (! $result) {
85 syslog(LOG_NOTICE, "db_inventory_styles: ".$sql." result: ".mysqli_error($connect));
86 } else {
87 syslog(LOG_NOTICE, "db_inventory_styles: deleted record ".$_GET['record']);
88 }
89 echo $result;
90
91 } else {
92 // SELECT COMMAND
93 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
94 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
95 $styles[] = array(
96 'record' => $row['record'],
97 'name' => $row['name'],
98 'category' => $row['category'],
99 'category_number' => $row['category_number'],
100 'style_letter' => $row['style_letter'],
101 'style_guide' => $row['style_guide'],
102 'type' => $row['type'],
103 'og_min' => $row['og_min'],
104 'og_max' => $row['og_max'],
105 'fg_min' => $row['fg_min'],
106 'fg_max' => $row['fg_max'],
107 'ibu_min' => $row['ibu_min'],
108 'ibu_max' => $row['ibu_max'],
109 'color_min' => $row['color_min'],
110 'color_max' => $row['color_max'],
111 'carb_min' => $row['carb_min'],
112 'carb_max' => $row['carb_max'],
113 'abv_min' => $row['abv_min'],
114 'abv_max' => $row['abv_max'],
115 'notes' => $row['notes'],
116 'profile' => $row['profile'],
117 'ingredients' => $row['ingredients'],
118 'examples' => $row['examples']
119 );
120 }
121 echo json_encode($styles);
122 }
123 ?>

mercurial