6 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); |
6 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); |
7 if (! $connect) { |
7 if (! $connect) { |
8 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); |
8 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); |
9 } |
9 } |
10 mysqli_set_charset($connect, "utf8" ); |
10 mysqli_set_charset($connect, "utf8" ); |
|
11 |
|
12 $response = array( |
|
13 'error' => false, |
|
14 'msg' => 'Ok', |
|
15 ); |
11 |
16 |
12 if (isset($_POST['insert']) || isset($_POST['update'])) { |
17 if (isset($_POST['insert']) || isset($_POST['update'])) { |
13 if (isset($_POST['insert'])) { |
18 if (isset($_POST['insert'])) { |
14 // INSERT COMMAND |
19 // INSERT COMMAND |
15 $sql = "INSERT INTO `inventory_equipments` SET "; |
20 $sql = "INSERT INTO `inventory_equipments` SET "; |
49 $sql .= "' WHERE record='" . $_POST['record'] . "';"; |
54 $sql .= "' WHERE record='" . $_POST['record'] . "';"; |
50 } |
55 } |
51 $result = mysqli_query($connect, $sql); |
56 $result = mysqli_query($connect, $sql); |
52 if (! $result) { |
57 if (! $result) { |
53 syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); |
58 syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); |
54 //} else { |
59 $response['error'] = true; |
55 // if (isset($_POST['update'])) { |
60 $response['msg'] = "SQL fout: ".mysqli_error($link); |
56 // syslog(LOG_NOTICE, "db_inventory_equipment: updated record ".$_POST['record']); |
|
57 // } else { |
|
58 // $lastid = mysqli_insert_id($connect); |
|
59 // syslog(LOG_NOTICE, "db_inventory_equipment: inserted record ".$lastid); |
|
60 // } |
|
61 } |
61 } |
62 echo $result; |
62 exit(json_encode($response)); |
63 |
63 |
64 } else if (isset($_POST['delete'])) { |
64 } else if (isset($_POST['delete'])) { |
65 // DELETE COMMAND |
65 // DELETE COMMAND. check if this record is in use. |
66 // FIXME: need to check if the record is in use |
66 $sql = "SELECT name FROM `inventory_equipments` WHERE record='".$_POST['record']."';"; |
|
67 $result = mysqli_query($connect, $sql) or die("SQL Error 1: " . mysqli_error($connect)); |
|
68 if (! $result) { |
|
69 syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); |
|
70 $response['error'] = true; |
|
71 $response['msg'] = "SQL fout: ".mysqli_error($link); |
|
72 exit(json_encode($response)); |
|
73 } |
|
74 if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { |
|
75 $sql = "SELECT eq_name FROM products WHERE eq_name='" . $row['name'] . "';"; |
|
76 $result2 = mysqli_query($connect, $sql); |
|
77 $ar = mysqli_affected_rows($connect); |
|
78 if ($ar > 0) { |
|
79 $response['error'] = true; |
|
80 $response['msg'] = "Installatie wordt ".$ar." maal gebruikt."; |
|
81 exit(json_encode($response)); |
|
82 } |
|
83 } |
|
84 // Record not used, delete it. |
67 $sql = "DELETE FROM `inventory_equipments` WHERE record='".$_POST['record']."';"; |
85 $sql = "DELETE FROM `inventory_equipments` WHERE record='".$_POST['record']."';"; |
68 $result = mysqli_query($connect, $sql); |
86 $result = mysqli_query($connect, $sql); |
69 if (! $result) { |
87 if (! $result) { |
70 syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); |
88 syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); |
71 } else { |
89 $response['error'] = true; |
72 syslog(LOG_NOTICE, "db_inventory_equipment: deleted record ".$_POST['record']); |
90 $response['msg'] = "SQL fout: ".mysqli_error($link); |
73 } |
91 } |
74 echo $result; |
92 exit(json_encode($response)); |
75 |
93 |
76 } else { |
94 } else { |
77 // SELECT COMMAND |
95 // SELECT COMMAND |
78 $query = "SELECT * FROM inventory_equipments ORDER BY name"; |
96 $query = "SELECT * FROM inventory_equipments ORDER BY name"; |
79 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); |
97 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); |
105 'mash_max' => $row['mash_max'], |
123 'mash_max' => $row['mash_max'], |
106 'efficiency' => $row['efficiency'] |
124 'efficiency' => $row['efficiency'] |
107 ); |
125 ); |
108 } |
126 } |
109 header("Content-type: application/json"); |
127 header("Content-type: application/json"); |
110 echo json_encode($equipments); |
128 exit(json_encode($equipments)); |
111 } |
129 } |
|
130 |
|
131 syslog(LOG_NOTICE, "db_inventory_equipment: missing arguments"); |
|
132 $response['error'] = true; |
|
133 $response['msg'] = "missing arguments"; |
|
134 echo json_encode($response); |
|
135 |
112 ?> |
136 ?> |