Пример #1
0
function getcomments($m)
{
    global $xmlrpcerruser;
    $err = "";
    $ra = array();
    // get the first param
    if (XMLRPC_EPI_ENABLED == '1') {
        $msgID = xmlrpc_decode($m->getParam(0));
    } else {
        $msgID = php_xmlrpc_decode($m->getParam(0));
    }
    $dbh = dba_open("/tmp/comments.db", "r", "db2");
    if ($dbh) {
        $countID = "{$msgID}_count";
        if (dba_exists($countID, $dbh)) {
            $count = dba_fetch($countID, $dbh);
            for ($i = 0; $i < $count; $i++) {
                $name = dba_fetch("{$msgID}_name_{$i}", $dbh);
                $comment = dba_fetch("{$msgID}_comment_{$i}", $dbh);
                // push a new struct onto the return array
                $ra[] = array("name" => $name, "comment" => $comment);
            }
        }
    }
    // if we generated an error, create an error return response
    if ($err) {
        return new xmlrpcresp(0, $xmlrpcerruser, $err);
    } else {
        // otherwise, we create the right response
        // with the state name
        return new xmlrpcresp(php_xmlrpc_encode($ra));
    }
}
Пример #2
0
 public function syncStoreAtOdoo($store_data)
 {
     $response = 0;
     $auto_warehouse_generation = Mage::getStoreConfig('magerpsync/mobmultishop/auto_warehouse_generation');
     $auto_pricelist_generation = Mage::getStoreConfig('magerpsync/mobmultishop/auto_pricelist_generation');
     $store_data['auto_warehouse'] = $auto_warehouse_generation;
     $store_data['auto_pricelist'] = $auto_pricelist_generation;
     $store_array = php_xmlrpc_encode($store_data);
     $helper = Mage::helper('magerpsync/connection');
     $context = $helper->getOdooContext();
     $client = $helper->getClientConnect();
     $userId = Mage::getSingleton('adminhtml/session')->getUserId();
     $msg = new xmlrpcmsg('execute');
     $msg->addParam(new xmlrpcval($helper::$odoo_db, "string"));
     $msg->addParam(new xmlrpcval($userId, "int"));
     $msg->addParam(new xmlrpcval($helper::$odoo_pwd, "string"));
     $msg->addParam(new xmlrpcval("magento.store.view", "string"));
     $msg->addParam(new xmlrpcval("sync_store_view", "string"));
     $msg->addParam($store_array);
     $msg->addParam(new xmlrpcval($context, "struct"));
     $resp = $client->send($msg);
     if ($resp->faultCode()) {
         $error = "Sync Error, Store " . $store_data['name'] . " >>" . $resp->faultString();
         Mage::log($error, null, 'odoo_connector.log');
     } else {
         $response = 1;
         $odoo_id = $resp->value()->me["int"];
         $store = Mage::getModel("mobmultishop/mobmultishop");
         $store->setOdooStoreId($odoo_id);
         $store->setMageStoreId($store_data['store_id']);
         $store->setCreatedBy($helper::$mage_user);
         $store->save();
     }
     return $response;
 }
Пример #3
0
 function call($method_name, &$args)
 {
     $xmlrpc_args = array();
     foreach ($args as $arg) {
         $xmlrpc_args[] = php_xmlrpc_encode($arg);
     }
     $xmlrpc_return = $this->client->send(new xmlrpcmsg($method_name, $xmlrpc_args), 300);
     return $xmlrpc_return->value();
 }
Пример #4
0
 /**
  * addArg adds an argument to the args array to pass to the function
  *
  * @param variable args - Either a single argument or an array of arguments
  */
 function addArg()
 {
     $func_args = func_get_args();
     $func_args = $func_args[0];
     if (is_array($func_args)) {
         foreach ($func_args as $arg) {
             $this->_args[] = php_xmlrpc_encode($arg);
         }
     } else {
         $this->_args[] = php_xmlrpc_encode($func_args);
     }
 }
Пример #5
0
 function exec($method, $params = NULL)
 {
     $message = new xmlrpcmsg($method);
     if ($params && is_array($params)) {
         foreach ($params as $value) {
             $message->addParam(php_xmlrpc_encode($value));
         }
     }
     $result = $this->db->send($message, 15);
     if ($result->faultCode()) {
         throw new Exception($result->faultString());
     }
     return $result->value();
 }
function getTagId($tag)
{
    global $client, $key;
    $call = new xmlrpcmsg("DataService.query", array(php_xmlrpc_encode($key), php_xmlrpc_encode("ContactGroup"), php_xmlrpc_encode(5000), php_xmlrpc_encode(0), php_xmlrpc_encode(array('Id' => '%')), php_xmlrpc_encode(array('Id', 'GroupName')), php_xmlrpc_encode('GroupName'), php_xmlrpc_encode(true)));
    ###Send the call###
    $result = $client->send($call);
    $tagArray = $result->val;
    for ($i = 0; $i < count($tagArray); ++$i) {
        if ($tagArray[$i]["GroupName"] == $tag) {
            $tagId = $tagArray[$i]["Id"];
        }
    }
    return $tagId;
}
Пример #7
0
 /**
  * <MethodDescription>
  *
  * @param string <description>
  *
  * @return mixed <description>
  */
 function dispatch($msg = NULL)
 {
     # ensure correct invocation
     if (is_null($msg) || !is_a($msg, 'xmlrpcmsg')) {
         return $this->throw_exception('functions_parameters_type must not be ' . 'phpvals.');
     }
     # get decoded parameters
     $len = $msg->getNumParams();
     $argument_array = array();
     for ($i = 0; $i < $len; ++$i) {
         $argument_array[] = php_xmlrpc_decode($msg->getParam($i));
     }
     # return result
     return new xmlrpcresp(php_xmlrpc_encode($this->invoke($msg->method(), $argument_array)));
 }
function addCamp($CID, $CMP)
{
    ###Set up global variables###
    global $client, $key;
    ###Set up the call to add to the campaign###
    $call = new xmlrpcmsg("ContactService.addToCampaign", array(php_xmlrpc_encode($key), php_xmlrpc_encode($CID), php_xmlrpc_encode($CMP)));
    ###Send the call###
    $result = $client->send($call);
    if (!$result->faultCode()) {
        print "Contact added to Campaign " . $CMP;
        print "<BR>";
    } else {
        print $result->faultCode() . "<BR>";
        print $result->faultString() . "<BR>";
    }
}
Пример #9
0
 function sendXmlRpc($sMessage, $aParam)
 {
     $r_client = new xmlrpc_client(ADDR_XMLRPC_ENTERPOINT, ADDR_XMLRPC_SERVER, 80);
     foreach ($aParam as $k => $v) {
         $aParam[$k] = php_xmlrpc_encode($v);
     }
     $r_message = new xmlrpcmsg($sMessage, $aParam);
     //$c->setDebug(1);
     $response =& $r_client->send($r_message);
     if ($response->faultCode()) {
         return $response;
         return 'xmlrpc-error: ' . $file . ' [' . $r->faultCode() . '] ' . $r->faultString();
     }
     $value = $response->value();
     return php_xmlrpc_decode($value);
 }
function addCard($CC)
{
    global $client, $key;
    ###Set up the call to add the card###
    $call = new xmlrpcmsg("DataService.add", array(php_xmlrpc_encode($key), php_xmlrpc_encode("CreditCard"), php_xmlrpc_encode($CC)));
    ###Send the call###
    $result = $client->send($call);
    if (!$result->faultCode()) {
        $cardID = $result->value();
        print "Credit Card added - ID: " . $cardID;
        print "<BR>";
    } else {
        print $result->faultCode() . "<BR>";
        print $result->faultString() . "<BR>";
    }
    return $cardID;
}
Пример #11
0
function addOrderItem($oID, $pID, $Type, $Price, $qty, $desc, $notes)
{
    global $client, $key;
    ###   Set up the call to add an item   ###
    $call = new xmlrpcmsg("InvoiceService.addOrderItem", array(php_xmlrpc_encode($key), php_xmlrpc_encode($oID), php_xmlrpc_encode($pID), php_xmlrpc_encode($Type), php_xmlrpc_encode($Price), php_xmlrpc_encode($qty), php_xmlrpc_encode($desc), php_xmlrpc_encode($notes)));
    ###Send the call###
    $result = $client->send($call);
    if (!$result->faultCode()) {
        $itemID = $result->value();
        print "Order Item added: " . $desc;
        print "<BR>";
        return $itemID;
    } else {
        print $result->faultCode() . "<BR>";
        print $result->faultString() . "<BR>";
    }
}
function buildOrder($cID, $desc, $oDate, $leadAff, $saleAff)
{
    global $client, $key;
    ###Set up the call to add an order to a contact###
    $call = new xmlrpcmsg("InvoiceService.createBlankOrder", array(php_xmlrpc_encode($key), php_xmlrpc_encode($cID), php_xmlrpc_encode($desc), php_xmlrpc_encode($oDate, array('auto_dates')), php_xmlrpc_encode($leadAff), php_xmlrpc_encode($saleAff)));
    ###Send the call###
    $result = $client->send($call);
    if (!$result->faultCode()) {
        $ordID = $result->value();
        print "Blank order built - ID: " . $ordID;
        print "<BR>";
        return $ordID;
    } else {
        print $result->faultCode() . "<BR>";
        print $result->faultString() . "<BR>";
    }
}
/**
 * Takes a client object, a remote method name, and a variable numbers of
 * php values, and calls the method with the supplied parameters. The 
 * parameters are native php values and the result is an xmlrpcresp object.
 *
 * Notes:
 * The function encodes the received parameters using php_xmlrpc_encode:
 * the limitations of automatic encoding apply to this function too);
 *
 * the type of the value returned by the function can be changed setting
 * beforehand the 'return_type' member of the client object to 'phpvals' -
 * see the manual for more details about this capability).
 *
 *
 * @author Toth Istvan
 *
 * @param xmlrpc_client client object, properly set up to connect to server
 * @param string remote function name
 * @param mixed $parameter1
 * @param mixed $parameter2
 * @param mixed $parameter3 ...
 * @return xmlrpcresp or false on error
 */
function xmlrpccall_simple()
{
    if (func_num_args() < 2) {
        // Incorrect
        return false;
    } else {
        $varargs = func_get_args();
        $client = array_shift($varargs);
        $remote_function_name = array_shift($varargs);
        if (!is_a($client, 'xmlrpc_client') || !is_string($remote_function_name)) {
            return false;
        }
        $xmlrpcval_array = array();
        foreach ($varargs as $parameter) {
            $xmlrpcval_array[] = php_xmlrpc_encode($parameter);
        }
        return $client->send(new xmlrpcmsg($remote_function_name, $xmlrpcval_array));
    }
}
Пример #14
0
 public function sendWithoutAddingKey($method, $args, $retry = false)
 {
     $encoded_arguments = array();
     foreach ($args as $argument) {
         $encoded_arguments[] = php_xmlrpc_encode($argument, array('auto_dates'));
     }
     $call = new xmlrpcmsg($method, $encoded_arguments);
     $attempts = 0;
     $start = time();
     $req = null;
     do {
         if ($attempts > 0) {
             if (class_exists('CakeLog') && $attempts > 1) {
                 $lastAttemptFaultCode = $req->faultCode();
                 $lastAttemptFaultString = $req->faultString();
             }
             sleep(5);
         }
         $attempts++;
         $req = $this->client->send($call, $this->timeout, 'https');
     } while ($retry && ($req->faultCode() == $GLOBALS['xmlrpcerr']['invalid_return'] || $req->faultCode() == $GLOBALS['xmlrpcerr']['curl_fail'] || strpos($req->faultString(), 'com.infusionsoft.throttle.ThrottlingException: Maximum number of threads throttled') !== false) && $attempts < 3);
     $this->totalHttpCalls += $attempts;
     if (!$req->faultCode()) {
         $result = php_xmlrpc_decode($req->value());
     } else {
         $result = array();
     }
     if (is_object($this->Logger)) {
         $this->Logger->log(array('time' => date('Y-m-d H:i:s'), 'duration' => time() - $start, 'method' => $method, 'args' => $args, 'attempts' => $attempts, 'result' => $req->faultCode() ? 'Failed' : count($result) . ' Records Returned', 'error_message' => $req->faultCode() ? $req->faultString() : null));
     }
     if ($req->faultCode()) {
         $exception = new Infusionsoft_Exception($req->faultString() . "\nAttempted: {$attempts} time(s).", $method, $args);
         $this->addException($exception);
         throw $exception;
         return FALSE;
     }
     if ($attempts > 2) {
         CakeLog::write('notice', "Infusionsoft call required {$attempts} calls to receive a successful response. Method: {$method} FaultCode: {$lastAttemptFaultCode} FaultString: {$lastAttemptFaultString}");
     }
     return $result;
 }
function addCamp($CID, $FUS)
{
    ###Set up global variables###
    global $client, $key;
    ################################################################################
    ### Note: at the time that the API was written "Campaigns" were actually     ###
    ### Follow up sequences. This is why the action to add a user to a Follow up ###
    ### sequence is called "addToCampaign".										 ###
    ###                                                                          ###
    ################################################################################
    ###Set up the call to add to the Follow up sequence###
    $call = new xmlrpcmsg("ContactService.addToCampaign", array(php_xmlrpc_encode($key), php_xmlrpc_encode($CID), php_xmlrpc_encode($FUS)));
    ###Send the call###
    $result = $client->send($call);
    if (!$result->faultCode()) {
        print "Contact added to Follow up sequence " . $CMP;
        print "<BR>";
    } else {
        print $result->faultCode() . "<BR>";
        print $result->faultString() . "<BR>";
    }
}
 protected static function executeWebServiceRequest($eschool, $func, $params = array())
 {
     global $CFG;
     $result = false;
     $server = array();
     $params = php_xmlrpc_encode($params);
     $wwwroot = $eschool->getAppUrl();
     if ($server[$wwwroot] = $eschool->getWebServicesToken()) {
         $xmlrpc_client = new xmlrpc_client("{$wwwroot}/webservice/xmlrpc/server.php?wstoken={$server[$wwwroot]}");
         $xmlrpc_msg = new xmlrpcmsg($func, array($params));
         $xmlrpc_resp = $xmlrpc_client->send($xmlrpc_msg);
         if ($xmlrpc_resp == false) {
             $CFG->current_app->gcError('GcrWebService call failed: ' . $func);
         }
         if (!$xmlrpc_resp->faultCode()) {
             $result = php_xmlrpc_decode($xmlrpc_resp->value());
         }
         if (!empty($xmlrpc_resp->errstr)) {
             $CFG->current_app->gcError('GcrWebService call error: ' . $xmlrpc_resp->errstr);
         }
     }
     return $result;
 }
Пример #17
0
*  Free Software Foundation; either version 2 of the License, or (at your  *
*  option) any later version.                                              *
\**************************************************************************/
/* $Id$ */
$GLOBALS['phpgw_info'] = array();
$GLOBALS['phpgw_info']['flags'] = array('currentapp' => 'xmlrpc', 'noheader' => False, 'noappheader' => False, 'nonavbar' => False);
include '../header.inc.php';
phpgw::import_class('phpgwapi.xmlrpc_client');
if ($_POST['stateno'] != '') {
    $username = '******';
    $password = '******';
    $phpgw_domain = 'default';
    $stateno = phpgw::get_var('stateno', 'int', 'POST', 0);
    $c = new xmlrpc_client("{$GLOBALS['phpgw_info']['server']['webserver_url']}/xmlrpc.php?domain={$phpgw_domain}", $_SERVER['HTTP_HOST'], 80);
    $c->setCredentials($username, $password);
    $f = new xmlrpcmsg('xmlrpc.examples.findstate', array(php_xmlrpc_encode($stateno)));
    //		print "<pre>" . htmlentities($f->serialize('UTF-8')) . "</pre>\n";
    //		$c->setDebug(1);
    $r =& $c->send($f);
    //		$cookies = $r->cookies();
    if (!$r->faultCode()) {
        $v = $r->value();
        print "</pre><br/>State number " . $stateno . " is " . htmlspecialchars($v->scalarval()) . "<br/>";
        // print "<HR>I got this value back<BR><PRE>" .
        //  htmlentities($r->serialize()). "</PRE><HR>\n";
    } else {
        print "An error occurred: ";
        print "Code: " . htmlspecialchars($r->faultCode()) . " Reason: '" . htmlspecialchars($r->faultString()) . "'</pre><br/>";
    }
} else {
    $stateno = "";
Пример #18
0
/**
 * Takes native php types and encodes them into xmlrpc PHP object format.
 * It will not re-encode xmlrpcval objects.
 *
 * Feature creep -- could support more types via optional type argument
 * (string => datetime support has been added, ??? => base64 not yet)
 *
 * If given a proper options parameter, php object instances will be encoded
 * into 'special' xmlrpc values, that can later be decoded into php objects
 * by calling php_xmlrpc_decode() with a corresponding option
 *
 * @author Dan Libby (dan@libby.com)
 *
 * @param mixed $php_val the value to be converted into an xmlrpcval object
 * @param array $options	can include 'encode_php_objs', 'auto_dates', 'null_extension' or 'extension_api'
 * @return xmlrpcval
 */
function php_xmlrpc_encode($php_val, $options = array())
{
    $type = gettype($php_val);
    switch ($type) {
        case 'string':
            if (in_array('auto_dates', $options) && preg_match('/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $php_val)) {
                $xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcDateTime']);
            } else {
                $xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcString']);
            }
            break;
        case 'integer':
            $xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcInt']);
            break;
        case 'double':
            $xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcDouble']);
            break;
            // <G_Giunta_2001-02-29>
            // Add support for encoding/decoding of booleans, since they are supported in PHP
        // <G_Giunta_2001-02-29>
        // Add support for encoding/decoding of booleans, since they are supported in PHP
        case 'boolean':
            $xmlrpc_val = new xmlrpcval($php_val, $GLOBALS['xmlrpcBoolean']);
            break;
            // </G_Giunta_2001-02-29>
        // </G_Giunta_2001-02-29>
        case 'array':
            // PHP arrays can be encoded to either xmlrpc structs or arrays,
            // depending on wheter they are hashes or plain 0..n integer indexed
            // A shorter one-liner would be
            // $tmp = array_diff(array_keys($php_val), range(0, count($php_val)-1));
            // but execution time skyrockets!
            $j = 0;
            $arr = array();
            $ko = false;
            foreach ($php_val as $key => $val) {
                $arr[$key] = php_xmlrpc_encode($val, $options);
                if (!$ko && $key !== $j) {
                    $ko = true;
                }
                $j++;
            }
            if ($ko) {
                $xmlrpc_val = new xmlrpcval($arr, $GLOBALS['xmlrpcStruct']);
            } else {
                $xmlrpc_val = new xmlrpcval($arr, $GLOBALS['xmlrpcArray']);
            }
            break;
        case 'object':
            if (is_a($php_val, 'xmlrpcval')) {
                $xmlrpc_val = $php_val;
            } else {
                if (is_a($php_val, 'DateTime')) {
                    $xmlrpc_val = new xmlrpcval($php_val->format('Ymd\\TH:i:s'), $GLOBALS['xmlrpcStruct']);
                } else {
                    $arr = array();
                    reset($php_val);
                    while (list($k, $v) = each($php_val)) {
                        $arr[$k] = php_xmlrpc_encode($v, $options);
                    }
                    $xmlrpc_val = new xmlrpcval($arr, $GLOBALS['xmlrpcStruct']);
                    if (in_array('encode_php_objs', $options)) {
                        // let's save original class name into xmlrpcval:
                        // might be useful later on...
                        $xmlrpc_val->_php_class = get_class($php_val);
                    }
                }
            }
            break;
        case 'NULL':
            if (in_array('extension_api', $options)) {
                $xmlrpc_val = new xmlrpcval('', $GLOBALS['xmlrpcString']);
            } else {
                if (in_array('null_extension', $options)) {
                    $xmlrpc_val = new xmlrpcval('', $GLOBALS['xmlrpcNull']);
                } else {
                    $xmlrpc_val = new xmlrpcval();
                }
            }
            break;
        case 'resource':
            if (in_array('extension_api', $options)) {
                $xmlrpc_val = new xmlrpcval((int) $php_val, $GLOBALS['xmlrpcInt']);
            } else {
                $xmlrpc_val = new xmlrpcval();
            }
            // catch "user function", "unknown type"
        // catch "user function", "unknown type"
        default:
            // giancarlo pinerolo <*****@*****.**>
            // it has to return
            // an empty object in case, not a boolean.
            $xmlrpc_val = new xmlrpcval();
            break;
    }
    return $xmlrpc_val;
}
Пример #19
0
/**
 * Takes native php types and encodes them into xmlrpc PHP object format.
 * It will not re-encode xmlrpcval objects.
 * Feature creep -- could support more types via optional type argument
 * (string => datetime support has been added, ??? => base64 not yet)
 *
 * @author Dan Libby (dan@libby.com)
 *
 * @param mixed $php_val the value to be converted into an xmlrpcval object
 * @param array $options	can include 'encode_php_objs' and 'auto_dates'
 * @return xmlrpcval
 */
function &php_xmlrpc_encode($php_val, $options = '')
{
    $type = gettype($php_val);
    $xmlrpc_val =& new xmlrpcval();
    switch ($type) {
        case 'array':
            // PHP arrays can be encoded to either xmlrpc structs or arrays,
            // depending on wheter they are hashes or plain 0..n integer indexed
            // A shorter one-liner would be
            // $tmp = array_diff(array_keys($php_val), range(0, count($php_val)-1));
            // but execution time skyrockets!
            $j = 0;
            $arr = array();
            $ko = false;
            foreach ($php_val as $key => $val) {
                $arr[$key] =& php_xmlrpc_encode($val, $options);
                if (!$ko && $key !== $j) {
                    $ko = true;
                }
                $j++;
            }
            if ($ko) {
                $xmlrpc_val->addStruct($arr);
            } else {
                $xmlrpc_val->addArray($arr);
            }
            break;
        case 'object':
            if (is_a($php_val, 'xmlrpcval')) {
                $xmlrpc_val = $php_val;
            } else {
                $arr = array();
                while (list($k, $v) = each($php_val)) {
                    $arr[$k] = php_xmlrpc_encode($v, $options);
                }
                $xmlrpc_val->addStruct($arr);
                if (@in_array('encode_php_objs', $options)) {
                    // let's save original class name into xmlrpcval:
                    // might be useful later on...
                    $xmlrpc_val->_php_class = get_class($php_val);
                }
            }
            break;
        case 'integer':
            $xmlrpc_val->addScalar($php_val, $GLOBALS['xmlrpcInt']);
            break;
        case 'double':
            $xmlrpc_val->addScalar($php_val, $GLOBALS['xmlrpcDouble']);
            break;
        case 'string':
            if (@in_array('auto_dates', $options) && ereg("^[0-9]{8}\\T{1}[0-9]{2}\\:[0-9]{2}\\:[0-9]{2}\$", $php_val)) {
                $xmlrpc_val->addScalar($php_val, $GLOBALS['xmlrpcDateTime']);
            } else {
                $xmlrpc_val->addScalar($php_val, $GLOBALS['xmlrpcString']);
            }
            break;
            // <G_Giunta_2001-02-29>
            // Add support for encoding/decoding of booleans, since they are supported in PHP
        // <G_Giunta_2001-02-29>
        // Add support for encoding/decoding of booleans, since they are supported in PHP
        case 'boolean':
            $xmlrpc_val->addScalar($php_val, $GLOBALS['xmlrpcBoolean']);
            break;
            // </G_Giunta_2001-02-29>
            // catch "resource", "NULL", "user function", "unknown type"
            //case 'unknown type':
        // </G_Giunta_2001-02-29>
        // catch "resource", "NULL", "user function", "unknown type"
        //case 'unknown type':
        default:
            // giancarlo pinerolo <*****@*****.**>
            // it has to return
            // an empty object in case (which is already
            // at this point), not a boolean.
            break;
    }
    return $xmlrpc_val;
}
Пример #20
0
 public function getProductArray($product_id)
 {
     $type = 'product';
     $product = Mage::getModel('catalog/product')->load($product_id);
     $ean = $product->getEan();
     $website_ids = $product->getWebsiteIds();
     $product_scope = Mage::getStoreConfig('catalog/price/scope');
     $website_ids = php_xmlrpc_encode($website_ids);
     $keys = array('simple', 'grouped', 'configurable', 'virtual', 'bundle', 'downloadable');
     $product_type = $product->getTypeID();
     if (!in_array($product_type, $keys)) {
         $product_type = "";
     }
     if (!in_array($product_type, array('simple', 'configurable'))) {
         $type = 'service';
     }
     $status = true;
     $status = urlencode($product->getStatus());
     if ($status == '2') {
         $status = false;
     }
     $sku = urlencode($product->getSku());
     $xmlrpc_array = array('type' => new xmlrpcval($type, "string"), 'default_code' => new xmlrpcval($sku, "string"), 'mage_id' => new xmlrpcval($product_id, "int"), 'sale_ok' => new xmlrpcval($status, "boolean"));
     $xmlrpc_array['wk_websites_id'] = $website_ids;
     if ($product_scope) {
         $price_list = array();
         $stores = Mage::getModel('core/store_api')->items();
         foreach ($stores as $store_data) {
             $store_id = $store_data['store_id'];
             $website_id = $store_data['website']['website_id'];
             $product_price = Mage::getModel('catalog/product')->setStoreId($store_id)->load($product_id)->getPrice();
             $price_list[$website_id] = $product_price;
         }
         $price_list = php_xmlrpc_encode($price_list);
         $xmlrpc_array['wk_price_list'] = $price_list;
     }
     $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product_id);
     if (!$parentIds) {
         $set_id = $product->getAttributeSetId();
         $name = urlencode($product->getName());
         $description = urlencode($product->getDescription());
         $short_description = urlencode($product->getShortDescription());
         $odoo_category_array = $this->getProductCategoryArray($product->getCategoryIds());
         $odoo_set_id = Mage::getModel('magerpsync/attributeset')->getOdooAttributeSetId($set_id);
         $xmlrpc_array['name'] = new xmlrpcval($name, "string");
         $xmlrpc_array['attribute_set_id'] = new xmlrpcval($odoo_set_id, "int");
         $xmlrpc_array['description'] = new xmlrpcval($description, "string");
         $xmlrpc_array['description_sale'] = new xmlrpcval($short_description, "string");
         $xmlrpc_array['list_price'] = new xmlrpcval($product->getPrice(), "string");
         $xmlrpc_array['prod_type'] = new xmlrpcval($product_type, "string");
         $xmlrpc_array['category_ids'] = new xmlrpcval($odoo_category_array, "array");
         $xmlrpc_array['weight_net'] = new xmlrpcval($product->getWeight(), "double");
     }
     if ($product->getImage() != 'no_selection') {
         try {
             $image_path = 'media/catalog/product' . $product->getImage();
             $image = file_get_contents($image_path);
         } catch (Exception $e) {
             $image = false;
         }
         if ($image) {
             $pro_image = base64_encode($image);
             $xmlrpc_array['image'] = new xmlrpcval($pro_image, "string");
             $xmlrpc_array['image_variant'] = new xmlrpcval($pro_image, "string");
         }
     }
     if ($ean) {
         $check_ean = Mage::getModel('magerpsync/commonsocket')->validate_ean13($ean);
         if ($check_ean) {
             $xmlrpc_array['ean13'] = new xmlrpcval($ean, "string");
         }
     }
     return $xmlrpc_array;
 }
Пример #21
0
<html>
<head><title>xmlrpc</title></head>
<body>
<h1>Getstatename demo</h1>
<h2>Send a U.S. state number to the server and get back the state name</h2>
<h3>The code demonstrates usage of the php_xmlrpc_encode function</h3>
<?php 
include "xmlrpc.inc";
// Play nice to PHP 5 installations with REGISTER_LONG_ARRAYS off
if (!isset($HTTP_POST_VARS) && isset($_POST)) {
    $HTTP_POST_VARS = $_POST;
}
if (isset($HTTP_POST_VARS["stateno"]) && $HTTP_POST_VARS["stateno"] != "") {
    $stateno = (int) $HTTP_POST_VARS["stateno"];
    $f = new xmlrpcmsg('examples.getStateName', array(php_xmlrpc_encode($stateno)));
    print "<pre>Sending the following request:\n\n" . htmlentities($f->serialize()) . "\n\nDebug info of server data follows...\n\n";
    $c = new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80);
    $c->setDebug(1);
    $r =& $c->send($f);
    if (!$r->faultCode()) {
        $v = $r->value();
        print "</pre><br/>State number " . $stateno . " is " . htmlspecialchars($v->scalarval()) . "<br/>";
        // print "<HR>I got this value back<BR><PRE>" .
        //  htmlentities($r->serialize()). "</PRE><HR>\n";
    } else {
        print "An error occurred: ";
        print "Code: " . htmlspecialchars($r->faultCode()) . " Reason: '" . htmlspecialchars($r->faultString()) . "'</pre><br/>";
    }
} else {
    $stateno = "";
}
    $FailureStyle = 'style="color:red; font-weight:bold"';
    echo '<table>
			<tr><th>' . _('Account Section') . '</th>
				<th>' . _('Result') . '</th>
				<th>' . _('Comments') . '</th>
			</tr>';
    $successes = 0;
    $failures = 0;
    while (!feof($fp)) {
        $buffer = fgets($fp, 4096);
        $FieldValues = explode(',', $buffer);
        if ($FieldValues[0] != '') {
            for ($i = 0; $i < sizeof($FieldValues); $i++) {
                $AccountSectionDetails[$FieldNames[$i]] = $FieldValues[$i];
            }
            $accountsection = php_xmlrpc_encode($AccountSectionDetails);
            $user = new xmlrpcval($webERPUser);
            $password = new xmlrpcval($weberppassword);
            $msg = new xmlrpcmsg("weberp.xmlrpc_InsertGLAccountSection", array($accountsection, $user, $password));
            $client = new xmlrpc_client($ServerURL);
            $client->setDebug($DebugLevel);
            $response = $client->send($msg);
            $answer = php_xmlrpc_decode($response->value());
            if ($answer[0] == 0) {
                echo '<tr ' . $SuccessStyle . '><td>' . $AccountSectionDetails['sectionname'] . '</td><td>' . 'Success' . '</td></tr>';
                $successes++;
            } else {
                echo '<tr ' . $FailureStyle . '><td>' . $AccountSectionDetails['sectionname'] . '</td><td>' . 'Failure' . '</td><td>';
                for ($i = 0; $i < sizeof($answer); $i++) {
                    echo 'Error no ' . $answer[$i] . ' - ' . $ErrorDescription[$answer[$i]] . '<br />';
                }
Пример #23
0
function i_whichToolkit($m)
{
    global $xmlrpcName, $xmlrpcVersion, $SERVER_SOFTWARE;
    $ret = array("toolkitDocsUrl" => "http://phpxmlrpc.sourceforge.net/", "toolkitName" => $xmlrpcName, "toolkitVersion" => $xmlrpcVersion, "toolkitOperatingSystem" => isset($SERVER_SOFTWARE) ? $SERVER_SOFTWARE : $_SERVER['SERVER_SOFTWARE']);
    return new xmlrpcresp(php_xmlrpc_encode($ret));
}
Пример #24
0
include '../../xmlrpc/lib/xmlrpc.inc';
include '../../api/api_errorcodes.php';
$Title = 'API documentation';
echo '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>' . $Title . '</title>';
echo '<link REL="shortcut icon" HREF="' . $RootPath . '/favicon.ico">';
echo '<link REL="icon" HREF="' . $RootPath . '/favicon.ico">';
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
//echo '<link href="'.$RootPath. '/../../css/'. $_SESSION['Theme'] .'/default.css" REL="stylesheet" TYPE="text/css">';
echo '</head>';
echo '<body>';
$ServerString = $_SERVER['HTTP_HOST'] . $RootPath;
$FirstBitOfURL = mb_substr($ServerString, 0, mb_strpos($ServerString, '/doc/Manual'));
$ServerURL = "http://" . $FirstBitOfURL . "/api/api_xml-rpc.php";
$DebugLevel = 0;
//Set to 0,1, or 2 with 2 being the highest level of debug info
$msg = new xmlrpcmsg("system.listMethods", array());
$client = new xmlrpc_client($ServerURL);
$client->setDebug($DebugLevel);
$response = $client->send($msg);
$answer = php_xmlrpc_decode($response->value());
for ($i = 0; $i < sizeof($answer); $i++) {
    echo '<br /><table border="1" width="80%"><tr><th colspan="3"><h4>' . _('Method name') . _('  -  ') . '<b>' . $answer[$i] . '</b></h4></th></tr>';
    $method = php_xmlrpc_encode($answer[$i]);
    $msg = new xmlrpcmsg("system.methodHelp", array($method));
    $client = new xmlrpc_client($ServerURL);
    $client->setDebug($DebugLevel);
    $response = $client->send($msg);
    $signature = php_xmlrpc_decode($response->value());
    echo $signature . '<br />';
}
echo '</body>';
Пример #25
0
 /**
  * Execute a method invoked by the client, checking parameters used
  * @param mixed $m either an xmlrpcmsg obj or a method name
  * @param array $params array with method parameters as php types (if m is method name only)
  * @param array $paramtypes array with xmlrpc types of method parameters (if m is method name only)
  * @return xmlrpcresp
  * @access private
  */
 function execute($m, $params = null, $paramtypes = null)
 {
     if (is_object($m)) {
         $methName = $m->method();
     } else {
         $methName = $m;
     }
     $sysCall = $this->allow_system_funcs && strpos($methName, "system.") === 0;
     $dmap = $sysCall ? $GLOBALS['_xmlrpcs_dmap'] : $this->dmap;
     if (!isset($dmap[$methName]['function'])) {
         // No such method
         return new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['unknown_method'], $GLOBALS['xmlrpcstr']['unknown_method']);
     }
     // Check signature
     if (isset($dmap[$methName]['signature'])) {
         $sig = $dmap[$methName]['signature'];
         if (is_object($m)) {
             list($ok, $errstr) = $this->verifySignature($m, $sig);
         } else {
             list($ok, $errstr) = $this->verifySignature($paramtypes, $sig);
         }
         if (!$ok) {
             // Didn't match.
             return new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['incorrect_params'], $GLOBALS['xmlrpcstr']['incorrect_params'] . ": {$errstr}");
         }
     }
     $func = $dmap[$methName]['function'];
     // let the 'class::function' syntax be accepted in dispatch maps
     if (is_string($func) && strpos($func, '::')) {
         $func = explode('::', $func);
     }
     // verify that function to be invoked is in fact callable
     if (!is_callable($func)) {
         error_log("XML-RPC: xmlrpc_server::execute: function {$func} registered as method handler is not callable");
         return new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['server_error'], $GLOBALS['xmlrpcstr']['server_error'] . ": no function matches method");
     }
     // If debug level is 3, we should catch all errors generated during
     // processing of user function, and log them as part of response
     if ($this->debug > 2) {
         $GLOBALS['_xmlrpcs_prev_ehandler'] = set_error_handler('_xmlrpcs_errorHandler');
     }
     if (is_object($m)) {
         if ($sysCall) {
             $r = call_user_func($func, $this, $m);
         } else {
             $r = call_user_func($func, $m);
         }
         if (!is_a($r, 'xmlrpcresp')) {
             error_log("XML-RPC: xmlrpc_server::execute: function {$func} registered as method handler does not return an xmlrpcresp object");
             if (is_a($r, 'xmlrpcval')) {
                 $r = new xmlrpcresp($r);
             } else {
                 $r = new xmlrpcresp(0, $GLOBALS['xmlrpcerr']['server_error'], $GLOBALS['xmlrpcstr']['server_error'] . ": function does not return xmlrpcresp object");
             }
         }
     } else {
         // call a 'plain php' function
         if ($sysCall) {
             array_unshift($params, $this);
             $r = call_user_func_array($func, $params);
         } else {
             // 3rd API convention for method-handling functions: EPI-style
             if ($this->functions_parameters_type == 'epivals') {
                 $r = call_user_func_array($func, array($methName, $params, $this->user_data));
                 // mimic EPI behaviour: if we get an array that looks like an error, make it
                 // an eror response
                 if (is_array($r) && array_key_exists('faultCode', $r) && array_key_exists('faultString', $r)) {
                     $r = new xmlrpcresp(0, (int) $r['faultCode'], (string) $r['faultString']);
                 } else {
                     // functions using EPI api should NOT return resp objects,
                     // so make sure we encode the return type correctly
                     $r = new xmlrpcresp(php_xmlrpc_encode($r, array('extension_api')));
                 }
             } else {
                 $r = call_user_func_array($func, $params);
             }
         }
         // the return type can be either an xmlrpcresp object or a plain php value...
         if (!is_a($r, 'xmlrpcresp')) {
             // what should we assume here about automatic encoding of datetimes
             // and php classes instances???
             $r = new xmlrpcresp(php_xmlrpc_encode($r, array('auto_dates')));
         }
     }
     if ($this->debug > 2) {
         // note: restore the error handler we found before calling the
         // user func, even if it has been changed inside the func itself
         if ($GLOBALS['_xmlrpcs_prev_ehandler']) {
             set_error_handler($GLOBALS['_xmlrpcs_prev_ehandler']);
         } else {
             restore_error_handler();
         }
     }
     return $r;
 }
Пример #26
0
 /**
  * Note: syntax differs from overridden method, by adding an ID param
  * @access private
  */
 function execute($m, $params = null, $paramtypes = null, $msgID = null)
 {
     if (is_object($m)) {
         // watch out: if $m is an xmlrpcmsg obj, this will raise a warning: no id memeber...
         $methName = $m->method();
         $msgID = $m->id;
     } else {
         $methName = $m;
     }
     $sysCall = $this->allow_system_funcs && ereg("^system\\.", $methName);
     $dmap = $sysCall ? $GLOBALS['_xmlrpcs_dmap'] : $this->dmap;
     if (!isset($dmap[$methName]['function'])) {
         // No such method
         return new jsonrpcresp(0, $GLOBALS['xmlrpcerr']['unknown_method'], $GLOBALS['xmlrpcstr']['unknown_method']);
     }
     // Check signature
     if (isset($dmap[$methName]['signature'])) {
         $sig = $dmap[$methName]['signature'];
         if (is_object($m)) {
             list($ok, $errstr) = $this->verifySignature($m, $sig);
         } else {
             list($ok, $errstr) = $this->verifySignature($paramtypes, $sig);
         }
         if (!$ok) {
             // Didn't match.
             return new jsonrpcresp(0, $GLOBALS['xmlrpcerr']['incorrect_params'], $GLOBALS['xmlrpcstr']['incorrect_params'] . ": {$errstr}");
         }
     }
     $func = $dmap[$methName]['function'];
     // let the 'class::function' syntax be accepted in dispatch maps
     if (is_string($func) && strpos($func, '::')) {
         $func = explode('::', $func);
     }
     // verify that function to be invoked is in fact callable
     if (!is_callable($func)) {
         error_log("XML-RPC: jsonrpc_server::execute: function {$func} registered as method handler is not callable");
         return new jsonrpcresp(0, $GLOBALS['xmlrpcerr']['server_error'], $GLOBALS['xmlrpcstr']['server_error'] . ": no function matches method");
     }
     // If debug level is 3, we should catch all errors generated during
     // processing of user function, and log them as part of response
     if ($this->debug > 2) {
         $GLOBALS['_xmlrpcs_prev_ehandler'] = set_error_handler('_xmlrpcs_errorHandler');
     }
     if (is_object($m)) {
         if ($sysCall) {
             $r = call_user_func($func, $this, $m);
         } else {
             $r = call_user_func($func, $m);
         }
         if (!is_a($r, 'xmlrpcresp')) {
             error_log("XML-RPC: jsonrpc_server::execute: function {$func} registered as method handler does not return an xmlrpcresp object");
             if (is_a($r, 'xmlrpcval')) {
                 $r = new jsonrpcresp($r);
             } else {
                 $r = new jsonrpcresp(0, $GLOBALS['xmlrpcerr']['server_error'], $GLOBALS['xmlrpcstr']['server_error'] . ": function does not return jsonrpcresp or xmlrpcresp object");
             }
         }
     } else {
         // call a 'plain php' function
         if ($sysCall) {
             array_unshift($params, $this);
             $r = call_user_func_array($func, $params);
         } else {
             // 3rd API convention for method-handling functions: EPI-style
             if ($this->functions_parameters_type == 'epivals') {
                 $r = call_user_func_array($func, array($methName, $params, $this->user_data));
                 // mimic EPI behaviour: if we get an array that looks like an error, make it
                 // an eror response
                 if (is_array($r) && array_key_exists('faultCode', $r) && array_key_exists('faultString', $r)) {
                     $r =& new jsonrpcresp(0, (int) $r['faultCode'], (string) $r['faultString']);
                 } else {
                     // functions using EPI api should NOT return resp objects,
                     // so make sure we encode the return type correctly
                     $r =& new jsonrpcresp(php_xmlrpc_encode($r, array('extension_api')));
                 }
             } else {
                 $r = call_user_func_array($func, $params);
             }
         }
         // the return type can be either an xmlrpcresp object or a plain php value...
         if (!is_a($r, 'xmlrpcresp')) {
             // what should we assume here about automatic encoding of datetimes
             // and php classes instances???
             $r = new jsonrpcresp(php_jsonrpc_encode($r));
         }
     }
     // here $r is either an xmlrpcresp or jsonrpcresp
     if (!is_a($r, 'jsonrpcresp')) {
         // dirty trick: user has given us back an xmlrpc response,
         // since he had an existing xmlrpc server with boatloads of code.
         // Be nice to him, and serialize the xmlrpc stuff into JSON.
         // We also override the content_type of the xmlrpc response,
         // but lack knoweledge of intented response charset...
         $r->content_type = 'text/plain';
         $r->payload = serialize_jsonrpcresp($r, $msgID);
     } else {
         $r->id = $msgID;
     }
     if ($this->debug > 2) {
         // note: restore the error handler we found before calling the
         // user func, even if it has been changed inside the func itself
         if ($GLOBALS['_xmlrpcs_prev_ehandler']) {
             set_error_handler($GLOBALS['_xmlrpcs_prev_ehandler']);
         } else {
             restore_error_handler();
         }
     }
     return $r;
 }
    echo '<table>
			<tr>
				<th>' . _('Part Code') . '</th>
				<th>' . _('Result') . '</th>
				<th>' . _('Comments') . '</th>
			</tr>';
    $successes = 0;
    $failures = 0;
    while (!feof($fp)) {
        $buffer = fgets($fp, 4096);
        $FieldValues = explode(',', $buffer);
        if ($FieldValues[0] != '') {
            for ($i = 0; $i < sizeof($FieldValues); $i++) {
                $ItemDetails[$FieldNames[$i]] = $FieldValues[$i];
            }
            $stockitem = php_xmlrpc_encode($ItemDetails);
            $user = new xmlrpcval($webERPUser);
            $password = new xmlrpcval($weberppassword);
            $msg = new xmlrpcmsg("weberp.xmlrpc_InsertStockItem", array($stockitem, $user, $password));
            $client = new xmlrpc_client($ServerURL);
            $client->setDebug($DebugLevel);
            $response = $client->send($msg);
            $answer = php_xmlrpc_decode($response->value());
            if ($answer[0] == 0) {
                echo '<tr ' . $SuccessStyle . '><td>' . $ItemDetails['stockid'] . '</td><td>' . 'Success' . '</td></tr>';
                $successes++;
            } else {
                echo '<tr ' . $FailureStyle . '><td>' . $ItemDetails['stockid'] . '</td><td>' . 'Failure' . '</td><td>';
                for ($i = 0; $i < sizeof($answer); $i++) {
                    echo 'Error no ' . $answer[$i] . ' - ' . $ErrorDescription[$answer[$i]] . '<br />';
                }
Пример #28
0
 public function output(&$data)
 {
     header('Content-Type: text/xml');
     $this->resetGlobals();
     $options = array('auto_dates', 'extension_api');
     $options['base64keys'] = $this->base64Keys;
     $xmlrpcData = php_xmlrpc_encode($data, $options);
     $response = new xmlrpcresp($xmlrpcData);
     if (ob_get_length()) {
         ob_end_clean();
     }
     echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . $response->serialize('UTF-8');
     exit;
 }
Пример #29
0
<?php

include "lib/xmlrpc.inc";
include "lib/config.inc";
$namespace = 'cache';
$method = 'purge';
$url = 'http://cdn.86400.io/beta03/app/files/NetDNA-logo-withtagline-wide.png';
$authString = hash('sha256', $cur . ':' . $apiKey . ':' . $method);
$f = new xmlrpcmsg("{$namespace}.{$method}", array(php_xmlrpc_encode($apiUserId), php_xmlrpc_encode($authString), php_xmlrpc_encode($cur), php_xmlrpc_encode($url)));
print_r(php_xmlrpc_encode($values));
$c = new xmlrpc_client("/xmlrpc/cache", "api.netdna.com", 80, 'http11');
$r =& $c->send($f);
print_r($r);
Пример #30
0
function xmlrpc_GetErrorMessages($xmlrpcmsg)
{
    ob_start('ob_file_callback');
    $rtn = new xmlrpcresp(php_xmlrpc_encode(GetAPIErrorMessages(php_xmlrpc_decode($xmlrpcmsg->getParam(0)))));
    ob_end_flush();
    return $rtn;
}