enable CardFortress in test database, #71513
[freeside.git] / fs_selfservice / php / freeside.class.new.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
45     function FreesideSelfService() {
46       $this;
47     }
48
49     public function __call($name, $arguments) {
50
51         error_log("[FreesideSelfService] $name called, sending to ". $this->URL);
52
53         $request = xmlrpc_encode_request("FS.ClientAPI_XMLRPC.$name", flatten($arguments[0]));
54         $context = stream_context_create( array( 'http' => array(
55             'method' => "POST",
56             'header' => "Content-Type: text/xml",
57             'content' => $request
58         )));
59         $file = file_get_contents($this->URL, false, $context);
60         $response = xmlrpc_decode($file);
61         if (xmlrpc_is_fault($response)) {
62             trigger_error("[FreesideSelfService] XML-RPC communication error: $response[faultString] ($response[faultCode])");
63         } else {
64             //error_log("[FreesideSelfService] $response");
65             return $response;
66         }
67     }
68
69 }
70
71 ?>