summaryrefslogtreecommitdiff
path: root/ng_selfservice/freeside.class.php
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2013-07-02 11:53:40 -0700
committerIvan Kohler <ivan@freeside.biz>2014-04-23 23:55:29 -0700
commit2f7688b1b21d92b406d60d09cdd8edcd7a99e842 (patch)
treee04534ffbf06424205b977abaee34ff4e9f42653 /ng_selfservice/freeside.class.php
parent7d26901e658bd61078f10c0713676f94375f3283 (diff)
selfservice, TNG, RT#22193
Diffstat (limited to 'ng_selfservice/freeside.class.php')
-rw-r--r--ng_selfservice/freeside.class.php72
1 files changed, 72 insertions, 0 deletions
diff --git a/ng_selfservice/freeside.class.php b/ng_selfservice/freeside.class.php
new file mode 100644
index 000000000..9815d3fd5
--- /dev/null
+++ b/ng_selfservice/freeside.class.php
@@ -0,0 +1,72 @@
+<?php
+
+#pre-php 5.4 compatible version?
+function flatten($hash) {
+ if ( !is_array($hash) ) return $hash;
+ $flat = array();
+
+ array_walk($hash, function($value, $key, &$to) {
+ array_push($to, $key, $value);
+ }, $flat);
+
+ if ( PHP_VERSION_ID >= 50400 ) {
+
+ #php 5.4+ (deb 7+)
+ foreach ($hash as $key => $value) {
+ $flat[] = $key;
+ $flat[] = $value;
+ }
+
+ }
+
+ return($flat);
+}
+
+#php 5.4+?
+#function flatten($hash) {
+# if ( !is_array($hash) ) return $hash;
+#
+# $flat = array();
+#
+# foreach ($hash as $key => $value) {
+# $flat[] = $key;
+# $flat[] = $value;
+# }
+#
+# return($flat);
+#}
+
+class FreesideSelfService {
+
+ //Change this to match the location of your selfservice xmlrpc.cgi or daemon
+ #var $URL = 'https://localhost/selfservice/xmlrpc.cgi';
+ #var $URL = 'http://localhost/selfservice/xmlrpc.cgi';
+ var $URL = 'http://localhost:8080/';
+
+ function FreesideSelfService() {
+ $this;
+ }
+
+ public function __call($name, $arguments) {
+
+ error_log("[FreesideSelfService] $name called, sending to ". $this->URL);
+
+ $request = xmlrpc_encode_request("FS.ClientAPI_XMLRPC.$name", flatten($arguments[0]));
+ $context = stream_context_create( array( 'http' => array(
+ 'method' => "POST",
+ 'header' => "Content-Type: text/xml",
+ 'content' => $request
+ )));
+ $file = file_get_contents($this->URL, false, $context);
+ $response = xmlrpc_decode($file);
+ if (xmlrpc_is_fault($response)) {
+ trigger_error("[FreesideSelfService] XML-RPC communication error: $response[faultString] ($response[faultCode])");
+ } else {
+ //error_log("[FreesideSelfService] $response");
+ return $response;
+ }
+ }
+
+}
+
+?>