add customer fields option with agent, display_custnum, status and name, RT#73721
[freeside.git] / ng_selfservice / freeside.class.php
1 <?php
2
3 #pre-php 5.4 compatible version?
4 function flatten($hash) {
5   if ( !is_array($hash) ) return $hash;
6   $flat = array();
7
8   array_walk($hash, function($value, $key, &$to) { 
9     array_push($to, $key, $value);
10   }, $flat);
11
12   if ( PHP_VERSION_ID >= 50400 ) {
13
14     #php 5.4+ (deb 7+)
15     foreach ($hash as $key => $value) {
16       $flat[] = $key;
17       $flat[] = $value;
18     }
19
20   }
21
22   return($flat);
23 }
24
25 #php 5.4+?
26 #function flatten($hash) {
27 #  if ( !is_array($hash) ) return $hash;
28 #
29 #  $flat = array();
30 #
31 #  foreach ($hash as $key => $value) {
32 #    $flat[] = $key;
33 #    $flat[] = $value;
34 #  }
35 #
36 #  return($flat);
37 #}
38
39 class FreesideSelfService  {
40
41     //Change this to match the location of your selfservice xmlrpc.cgi or daemon
42     #var $URL = 'https://localhost/selfservice/xmlrpc.cgi';
43     #var $URL = 'http://localhost/selfservice/xmlrpc.cgi';
44     var $URL = 'http://localhost:8080/';
45
46     function FreesideSelfService() {
47       $this;
48     }
49
50     public function __call($name, $arguments) {
51
52         error_log("[FreesideSelfService] $name called, sending to ". $this->URL);
53
54         $request = xmlrpc_encode_request("FS.ClientAPI_XMLRPC.$name", flatten($arguments[0]));
55         $context = stream_context_create( array( 'http' => array(
56             'method' => "POST",
57             'header' => "Content-Type: text/xml",
58             'content' => $request
59         )));
60         $file = file_get_contents($this->URL, false, $context);
61         $response = xmlrpc_decode($file);
62         // uncomment to trace everything
63         //error_log(print_r($response, true));
64         if (xmlrpc_is_fault($response)) {
65             trigger_error("[FreesideSelfService] XML-RPC communication error: $response[faultString] ($response[faultCode])");
66         } else {
67             //error_log("[FreesideSelfService] $response");
68             return $response;
69         }
70     }
71
72 }
73
74 ?>