corrade-http-templates – Blame information for rev 82

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