1 | <?php |
---|
2 | // +-------------------------------------------------+ |
---|
3 | // © 2002-2005 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net) |
---|
4 | // +-------------------------------------------------+ |
---|
5 | // $Id: remote_procedure_client.class.php,v 1.4.8.1 2014-06-19 07:25:09 mbertin Exp $ |
---|
6 | |
---|
7 | if (stristr($_SERVER['REQUEST_URI'], ".class.php")) die("no access"); |
---|
8 | |
---|
9 | class remote_procedure_client { |
---|
10 | var $server_adress=""; |
---|
11 | var $server_username=""; |
---|
12 | var $server_key=""; |
---|
13 | |
---|
14 | function array_to_object($array, $recursive=false) { |
---|
15 | $return = new stdClass(); |
---|
16 | foreach ($array as $k => $v) { |
---|
17 | if ($recursive && is_array($v)) { |
---|
18 | $return->$k = $this->array_to_object($v); |
---|
19 | } |
---|
20 | else { |
---|
21 | $return->$k = $v; |
---|
22 | } |
---|
23 | } |
---|
24 | |
---|
25 | return $return; |
---|
26 | } |
---|
27 | |
---|
28 | function remote_procedure_client($server_adress, $server_username, $server_key) { |
---|
29 | $this->server_adress = $server_adress; |
---|
30 | $this->server_username = $server_username; |
---|
31 | $this->server_key = $server_key; |
---|
32 | } |
---|
33 | |
---|
34 | function get_procs($type="", $set="") { |
---|
35 | global $charset, $class_path, $pmb_version_brut; |
---|
36 | global $msg; |
---|
37 | global $pmb_curl_proxy; |
---|
38 | |
---|
39 | $params = array("credentials" => array("user"=>$this->server_username, "key" => $this->server_key)); |
---|
40 | if ($set) |
---|
41 | $params["set"] = $set; |
---|
42 | if ($type) |
---|
43 | $params["type"] = $type; |
---|
44 | $params["pmbversion"] = $pmb_version_brut; |
---|
45 | |
---|
46 | //Utilisons php_soap si disponible |
---|
47 | if (extension_loaded("soap")) { |
---|
48 | $soap_client_parameters = array(); |
---|
49 | if($pmb_curl_proxy!=''){ |
---|
50 | $param_proxy = explode(',',$pmb_curl_proxy); |
---|
51 | $adresse_proxy = $param_proxy[0]; |
---|
52 | $port_proxy = $param_proxy[1]; |
---|
53 | $user_proxy = $param_proxy[2]; |
---|
54 | $pwd_proxy = $param_proxy[3]; |
---|
55 | $soap_client_parameters = array('proxy_host' => $adresse_proxy, |
---|
56 | 'proxy_port' => $port_proxy, |
---|
57 | 'proxy_login' => $user_proxy, |
---|
58 | 'proxy_password' => $pwd_proxy); |
---|
59 | } |
---|
60 | |
---|
61 | $soap_client_parameters['features'] = SOAP_SINGLE_ELEMENT_ARRAYS; |
---|
62 | try { |
---|
63 | @$client = new SoapClient($this->server_adress, $soap_client_parameters); |
---|
64 | if (!$client) { |
---|
65 | return (object)array("error_information" => ((object)array("error_code" => 1 ,"error_string" => $msg["remote_procedures_error_client"]))); |
---|
66 | } |
---|
67 | @$result = $client->get_procs($params); |
---|
68 | } |
---|
69 | catch (Exception $e) { |
---|
70 | return (object)array("error_information" => ((object)array("error_code" => 1 ,"error_string" => $e->getMessage()))); |
---|
71 | } |
---|
72 | |
---|
73 | if ($charset != 'utf-8') { |
---|
74 | if (isset($result->elements)) { |
---|
75 | if (!is_array($result->elements)) |
---|
76 | $result->elements = array($result->elements); |
---|
77 | |
---|
78 | foreach ($result->elements as $index => $aprocedure) { |
---|
79 | $result->elements[$index]->name = utf8_decode($aprocedure->name); |
---|
80 | $result->elements[$index]->comment = utf8_decode($aprocedure->comment); |
---|
81 | $result->elements[$index]->sql = utf8_decode($aprocedure->sql); |
---|
82 | $result->elements[$index]->params = utf8_decode($aprocedure->params); |
---|
83 | $result->elements[$index]->current_attached_set = utf8_decode($aprocedure->current_attached_set); |
---|
84 | if (isset($aprocedure->sets)) { |
---|
85 | if (!is_array($aprocedure->sets)) |
---|
86 | $result->elements[$index]->sets = array($result->elements[$index]->sets); |
---|
87 | foreach($result->elements[$index]->sets as $set_index => $aset) { |
---|
88 | $result->elements[$index]->sets[$set_index]->set_caption = utf8_decode($result->elements[$index]->sets[$set_index]->set_caption); |
---|
89 | } |
---|
90 | } |
---|
91 | } |
---|
92 | } |
---|
93 | } |
---|
94 | } |
---|
95 | //Sinon, utilisons le client nusoap |
---|
96 | else { |
---|
97 | $adresse_proxy = false; |
---|
98 | $port_proxy = false; |
---|
99 | $user_proxy = false; |
---|
100 | $pwd_proxy = false; |
---|
101 | if($pmb_curl_proxy!=''){ |
---|
102 | $param_proxy = explode(',',$pmb_curl_proxy); |
---|
103 | $adresse_proxy = $param_proxy[0]; |
---|
104 | $port_proxy = $param_proxy[1]; |
---|
105 | $user_proxy = $param_proxy[2]; |
---|
106 | $pwd_proxy = $param_proxy[3]; |
---|
107 | } |
---|
108 | |
---|
109 | require_once($class_path."/nusoap/nusoap.php"); |
---|
110 | $client = new nusoapclient($this->server_adress, true, $adresse_proxy, $port_proxy, $user_proxy, $pwd_proxy); |
---|
111 | $client->decode_utf8 = ($charset != 'utf-8'); |
---|
112 | if ($err=$client->getError()) { |
---|
113 | return (object)array("error_information" => ((object)array("error_code" => 1 ,"error_string" => $err))); |
---|
114 | } |
---|
115 | $result = $client->call("get_procs", array("parameters" => $params), "http://www.sigb.net/pmb/"); |
---|
116 | //Si une seule procédure est renvoyée, soap ne renvoi pas un tableau, et alors elements contient directement une procedure |
---|
117 | //Mais nous voulons un tableau, donc nous devons traiter le cas |
---|
118 | if (isset($result["elements"]["id"])) |
---|
119 | $result["elements"] = array($result["elements"]); |
---|
120 | |
---|
121 | $result = $this->array_to_object($result); |
---|
122 | if (isset($result->elements)) |
---|
123 | foreach ($result->elements as $index => $value) |
---|
124 | $result->elements[$index] = $this->array_to_object($result->elements[$index], true); |
---|
125 | } |
---|
126 | |
---|
127 | return $result; |
---|
128 | } |
---|
129 | |
---|
130 | function get_proc($proc_id,$type="") { |
---|
131 | global $msg; |
---|
132 | $result = array("error_message" => "", "procedure" => NULL); |
---|
133 | $procedures = $this->get_procs($type); |
---|
134 | $the_procedure = ""; |
---|
135 | |
---|
136 | if ($procedures) { |
---|
137 | if ($procedures->error_information->error_code) { |
---|
138 | $result["error_message"] = $procedures->error_information->error_string; |
---|
139 | return $result; |
---|
140 | } |
---|
141 | else { |
---|
142 | if (isset($procedures->elements)) |
---|
143 | foreach ($procedures->elements as $aprocedure) { |
---|
144 | if ($aprocedure->id == $proc_id) { |
---|
145 | $the_procedure = $aprocedure; |
---|
146 | break; |
---|
147 | } |
---|
148 | } |
---|
149 | } |
---|
150 | } |
---|
151 | if ($the_procedure) |
---|
152 | $result["procedure"] = $the_procedure; |
---|
153 | else |
---|
154 | $result["error_message"] = $msg["remote_procedures_proc_notfound"]; |
---|
155 | return $result; |
---|
156 | } |
---|
157 | |
---|
158 | function parse_parameters($parameters) { |
---|
159 | $parsed_parameters=array(); |
---|
160 | if (!$parameters || $parameters == "NULL") return; |
---|
161 | $pp = _parser_text_no_function_($parameters); |
---|
162 | if (isset($pp["FIELDS"][0]["FIELD"])) { |
---|
163 | foreach($pp["FIELDS"][0]["FIELD"] as $afield) { |
---|
164 | $parsed_parameters[$afield["NAME"]] = array("type" => $afield["TYPE"][0], "options" => $afield["OPTIONS"][0], 'title' => $afield["ALIAS"][0]); |
---|
165 | } |
---|
166 | } |
---|
167 | return $parsed_parameters; |
---|
168 | } |
---|
169 | } |
---|
170 | |
---|
171 | ?> |
---|