corrade-http-templates – Diff between revs 72 and 82
?pathlinks?
Rev 72 | Rev 82 | |||
---|---|---|---|---|
1 | <?php |
1 | <?php |
|
2 | |
2 | |
|
3 | ########################################################################### |
3 | ########################################################################### |
|
4 | ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## |
4 | ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## |
|
5 | ########################################################################### |
5 | ########################################################################### |
|
6 | ## This is a script that can be used to retrieve information on an ## |
6 | ## This is a script that can be used to retrieve information on an ## |
|
7 | ## inventory item by calling the "getinventorydata" Corrade command. ## |
7 | ## inventory item by calling the "getinventorydata" Corrade command. ## |
|
8 | ########################################################################### |
8 | ########################################################################### |
|
9 | |
9 | |
|
10 | if(!isset($_POST['uuid']) || !isset($_POST['data'])) return; |
10 | if(!isset($_POST['uuid']) || !isset($_POST['data'])) return; |
|
11 | |
11 | |
|
12 | $uuid = $_POST['uuid']; |
12 | $uuid = $_POST['uuid']; |
|
13 | $data = $_POST['data']; |
13 | $data = $_POST['data']; |
|
14 | |
14 | |
|
15 | ########################################################################### |
15 | ########################################################################### |
|
16 | ## CONFIGURATION ## |
16 | ## CONFIGURATION ## |
|
17 | ########################################################################### |
17 | ########################################################################### |
|
18 | |
18 | |
|
19 | require_once('config.php'); |
19 | require_once('config.php'); |
|
20 | require_once('vendor/was/utilities/src/formats/kvp/kvp.php'); |
20 | require_once('vendor/was/utilities/src/formats/kvp/kvp.php'); |
|
21 | require_once('vendor/was/utilities/src/collections/arrays/arrays.php'); |
21 | require_once('vendor/was/utilities/src/collections/arrays/arrays.php'); |
|
22 | require_once('vendor/was/utilities/src/formats/csv/csv.php'); |
22 | require_once('vendor/was/utilities/src/formats/csv/csv.php'); |
|
23 | |
23 | |
|
24 | ########################################################################### |
24 | ########################################################################### |
|
25 | ## INTERNALS ## |
25 | ## INTERNALS ## |
|
26 | ########################################################################### |
26 | ########################################################################### |
|
27 | |
27 | |
|
28 | #### |
28 | #### |
|
29 | # I. Resolve the inventory UUID to an asset UUID. |
29 | # I. Resolve the inventory UUID to an asset UUID. |
|
30 | $params = array( |
30 | $params = array( |
|
31 | 'command' => 'getinventorydata', |
31 | 'command' => 'getinventorydata', |
|
32 | 'group' => $GROUP, |
32 | 'group' => $GROUP, |
|
33 | 'password' => $PASSWORD, |
33 | 'password' => $PASSWORD, |
|
34 | 'item' => $uuid, |
34 | 'item' => $uuid, |
|
35 | 'data' => wasArrayToCSV($data) |
35 | 'data' => wasArrayToCSV($data) |
|
36 | ); |
36 | ); |
|
37 | array_walk($params, |
37 | array_walk($params, |
|
38 | function(&$value, $key) { |
38 | function(&$value, $key) { |
|
39 | $value = rawurlencode($key)."=".rawurlencode($value); |
39 | $value = urlencode($key)."=".urlencode($value); |
|
40 | } |
40 | } |
|
41 | ); |
41 | ); |
|
42 | $postvars = implode('&', $params); |
42 | $postvars = implode('&', $params); |
|
43 | if (!($curl = curl_init())) { |
43 | if (!($curl = curl_init())) { |
|
44 | print 0; |
44 | print 0; |
|
45 | return; |
45 | return; |
|
46 | } |
46 | } |
|
47 | curl_setopt($curl, CURLOPT_URL, $URL); |
47 | curl_setopt($curl, CURLOPT_URL, $URL); |
|
48 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
48 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
49 | curl_setopt($curl, CURLOPT_POST, true); |
49 | curl_setopt($curl, CURLOPT_POST, true); |
|
50 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
50 | curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); |
|
51 | curl_setopt($curl, CURLOPT_ENCODING, true); |
51 | curl_setopt($curl, CURLOPT_ENCODING, true); |
|
52 | $result = curl_exec($curl); |
52 | $result = curl_exec($curl); |
|
53 | curl_close($curl); |
53 | curl_close($curl); |
|
54 | |
54 | |
|
55 | $success = urldecode( |
55 | $success = urldecode( |
|
56 | wasKeyValueGet( |
56 | wasKeyValueGet( |
|
57 | "success", |
57 | "success", |
|
58 | $result |
58 | $result |
|
59 | ) |
59 | ) |
|
60 | ); |
60 | ); |
|
61 | |
61 | |
|
62 | if($success == 'False') { |
62 | if($success == 'False') { |
|
63 | echo 'Unable to get inventory UUID: '.urldecode( |
63 | echo 'Unable to get inventory UUID: '.urldecode( |
|
64 | wasKeyValueGet( |
64 | wasKeyValueGet( |
|
65 | "error", |
65 | "error", |
|
66 | $result |
66 | $result |
|
67 | ) |
67 | ) |
|
68 | ); |
68 | ); |
|
69 | die; |
69 | die; |
|
70 | } |
70 | } |
|
71 | |
71 | |
|
72 | #### |
72 | #### |
|
73 | # II. Get the returned data and build an associative array. |
73 | # II. Get the returned data and build an associative array. |
|
74 | $data = str_getcsv( |
74 | $data = str_getcsv( |
|
75 | urldecode( |
75 | urldecode( |
|
76 | wasKeyValueGet( |
76 | wasKeyValueGet( |
|
77 | "data", |
77 | "data", |
|
78 | $result |
78 | $result |
|
79 | ) |
79 | ) |
|
80 | ) |
80 | ) |
|
81 | ); |
81 | ); |
|
82 | |
82 | |
|
83 | $data = array_combine( |
83 | $data = array_combine( |
|
84 | wasArrayStride( |
84 | wasArrayStride( |
|
85 | $data, |
85 | $data, |
|
86 | 2 |
86 | 2 |
|
87 | ), |
87 | ), |
|
88 | wasArrayStride( |
88 | wasArrayStride( |
|
89 | array_slice( |
89 | array_slice( |
|
90 | $data, |
90 | $data, |
|
91 | 1 |
91 | 1 |
|
92 | ), |
92 | ), |
|
93 | 2 |
93 | 2 |
|
94 | ) |
94 | ) |
|
95 | ); |
95 | ); |
|
96 | |
96 | |
|
97 | #### |
97 | #### |
|
98 | # III. Dump the JSON for AJAX. |
98 | # III. Dump the JSON for AJAX. |
|
99 | echo json_encode( |
99 | echo json_encode( |
|
100 | array( |
100 | array( |
|
101 | $data |
101 | $data |
|
102 | ) |
102 | ) |
|
103 | ); |
103 | ); |
|
104 | |
104 | |
|
105 | ?> |
105 | ?> |
|
106 | |
106 | |
|
107 | |
107 | |