www/includes/db_inventory_suppliers.php

Wed, 10 Aug 2022 11:43:19 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 10 Aug 2022 11:43:19 +0200
changeset 834
00e610fc3571
parent 785
aa79acfdf8a9
permissions
-rw-r--r--

Reinstalled the product archives menus

10
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 <?php
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 require($_SERVER['DOCUMENT_ROOT']."/config.php");
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 require($_SERVER['DOCUMENT_ROOT']."/version.php");
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 #Connect to the database
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 if (! $connect) {
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 }
77
a9f8de2d7b2b Fixed most charset problems. Added fpdf library. Added inventory pdf creation.
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
11 mysqli_set_charset($connect, "utf8" );
10
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12
767
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
13 $response = array(
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
14 'error' => false,
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
15 'msg' => 'Ok',
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
16 );
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
17
10
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 // get data and store in a json array
64
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
19 $query = "SELECT * FROM inventory_suppliers ORDER BY name";
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
20 if (isset($_POST['insert'])) {
10
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 // INSERT COMMAND
785
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 767
diff changeset
22 $sql = "INSERT INTO `inventory_suppliers` SET ";
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 767
diff changeset
23 if (isset($_POST['uuid']) && (strlen($_POST['uuid']) == 36)) {
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 767
diff changeset
24 $sql .= "uuid='" . $_POST['uuid'];
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 767
diff changeset
25 } else {
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 767
diff changeset
26 $uuid = str_replace("\n", "", file_get_contents('/proc/sys/kernel/random/uuid'));
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 767
diff changeset
27 $sql .= "uuid='" . $uuid;
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 767
diff changeset
28 }
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 767
diff changeset
29 $sql .= "', name='" . mysqli_real_escape_string($connect, $_POST['name']);
64
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
30 $sql .= "', address='" . mysqli_real_escape_string($connect, $_POST['address']);
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
31 $sql .= "', city='" . mysqli_real_escape_string($connect, $_POST['city']);
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
32 $sql .= "', zip='" . mysqli_real_escape_string($connect, $_POST['zip']);
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
33 $sql .= "', country='" . mysqli_real_escape_string($connect, $_POST['country']);
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
34 $sql .= "', website='" . mysqli_real_escape_string($connect, $_POST['website']);
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
35 $sql .= "', email='" . mysqli_real_escape_string($connect, $_POST['email']);
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
36 $sql .= "', phone='" . mysqli_real_escape_string($connect, $_POST['phone']);
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
37 $sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']);
10
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 $sql .= "';";
18
395833e20f88 Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents: 10
diff changeset
39 $result = mysqli_query($connect, $sql);
395833e20f88 Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents: 10
diff changeset
40 if (! $result) {
395833e20f88 Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents: 10
diff changeset
41 syslog(LOG_NOTICE, "db_inventory_suppliers: ".$sql." result: ".mysqli_error($connect));
767
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
42 $response['error'] = true;
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
43 $response['msg'] = "SQL fout: ".mysqli_error($connect);
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
44 }
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
45 exit(json_encode($response));
10
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46
64
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
47 } else if (isset($_POST['update'])) {
10
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 // UPDATE COMMAND
785
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 767
diff changeset
49 $sql = "UPDATE `inventory_suppliers` SET uuid='" . $_POST['uuid'];
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 767
diff changeset
50 $sql .= "', name='" . mysqli_real_escape_string($connect, $_POST['name']);
64
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
51 $sql .= "', address='" . mysqli_real_escape_string($connect, $_POST['address']);
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
52 $sql .= "', city='" . mysqli_real_escape_string($connect, $_POST['city']);
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
53 $sql .= "', zip='" . mysqli_real_escape_string($connect, $_POST['zip']);
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
54 $sql .= "', country='" . mysqli_real_escape_string($connect, $_POST['country']);
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
55 $sql .= "', website='" . mysqli_real_escape_string($connect, $_POST['website']);
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
56 $sql .= "', email='" . mysqli_real_escape_string($connect, $_POST['email']);
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
57 $sql .= "', phone='" . mysqli_real_escape_string($connect, $_POST['phone']);
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
58 $sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']);
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
59 $sql .= "' WHERE record='" . $_POST['record'] . "';";
18
395833e20f88 Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents: 10
diff changeset
60 $result = mysqli_query($connect, $sql);
395833e20f88 Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents: 10
diff changeset
61 if (! $result) {
395833e20f88 Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents: 10
diff changeset
62 syslog(LOG_NOTICE, "db_inventory_suppliers: ".$sql." result: ".mysqli_error($connect));
767
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
63 $response['error'] = true;
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
64 $response['msg'] = "SQL fout: ".mysqli_error($connect);
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
65 }
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
66 exit(json_encode($response));
10
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67
64
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
68 } else if (isset($_POST['delete'])) {
10
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 // DELETE COMMAND
64
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 18
diff changeset
70 $sql = "DELETE FROM `inventory_suppliers` WHERE record='".$_POST['record']."';";
18
395833e20f88 Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents: 10
diff changeset
71 $result = mysqli_query($connect, $sql);
395833e20f88 Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents: 10
diff changeset
72 if (! $result) {
395833e20f88 Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents: 10
diff changeset
73 syslog(LOG_NOTICE, "db_inventory_suppliers: ".$sql." result: ".mysqli_error($connect));
767
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
74 $response['error'] = true;
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
75 $response['msg'] = "SQL fout: ".mysqli_error($connect);
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
76 }
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
77 exit(json_encode($response));
10
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 } else {
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 // SELECT COMMAND
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 $suppliers[] = array(
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 'record' => $row['record'],
785
aa79acfdf8a9 Added uuid field in inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts. Added uuid field in profiles mash, styles and water.
Michiel Broek <mbroek@mbse.eu>
parents: 767
diff changeset
85 'uuid' => $row['uuid'],
10
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 'name' => $row['name'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 'address' => $row['address'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 'city' => $row['city'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 'zip' => $row['zip'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 'country' => $row['country'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 'website' => $row['website'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 'email' => $row['email'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 'phone' => $row['phone'],
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 'notes' => $row['notes']
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 );
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 }
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: 77
diff changeset
97 header("Content-type: application/json");
767
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
98 exit(json_encode($suppliers));
10
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 }
767
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
100
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
101 syslog(LOG_NOTICE, "db_inventory_suppliers: missing arguments");
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
102 $response['error'] = true;
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
103 $response['msg'] = "missing arguments";
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
104 echo json_encode($response);
08c0343b622b Improved error handling for inventory equipments, fermentables, hops, miscs, suppliers, water and yeasts.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
105
10
606b4af8f918 Start of the merge with another unfinished project
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 ?>

mercurial