Location: PHPKode > scripts > QBRDS Client > qbrdsclient.class.php
// start cut here and go to end of file.
<?php

$standalone=true;
if ($standalone)
{
	// hard code these values for standalone testing
	$POSTArray['QBRDS_WSDL'] = "https://...";
	$POSTArray['QBRDS_loginName'] = "...";
	$POSTArray['QBRDS_password'] = "...";
	$POSTArray['QBRDS_appID'] = "...";
	$POSTArray['QBRDS_appName'] = "...";
	$POSTArray['QBRDS_qbFileName'] = "...";
	$POSTArray['QBRDS_reqFileMod']="...";
	$POSTArray["QBXMLrq_fileSpec"]="...";
else
{
	// called from http server with post method.
	$POSTArray = $_POST; 
}

// build new object with initial values
$q = new QBRDSClient
	(	$POSTArray['QBRDS_WSDL'],
		$POSTArray['QBRDS_loginName'],
		$POSTArray['QBRDS_password'],
		$POSTArray['QBRDS_appID'],
		$POSTArray['QBRDS_appName'],
		$POSTArray['QBRDS_qbFileName'],
		$POSTArray['QBRDS_reqFileMod']
	);

$q->ConnectToQBRDSServer();
$q->GetQBXMLRPReleaseInfo();

$q->OpenConnectionAndBeginSession();
$q->GetCurrentCompanyFileName();

$q->qbXMLrq = file_get_contents($POSTArray["QBXMLrq_fileSpec"] );
$q->ProcessRequest();
$qbXMLrs = $q->qbXMLrs;
$BytesWrote=file_put_contents($RQfilename, $qbXMLrs);

$q->EndSession();
$q->CloseConnection(); 

return(0);

/****************************************************************
* author:   Bill McCuistion - 2-26-05
* pupose:   Provides class definition for the QBRDSClient.
****************************************************************/
class QBRDSClient
{
    // variables from xml processing instruction.
    public $xml_version = "";

    // additional variables from qbxml element tag.
    public $qbxml_version = "";

    // additional variables from QBXMLMsgsRq element tag
    public $onError = "";

    // additional variables to create new SoapClient object
    public $wsdl = "";
    public $loginName = '';
    public $password = '';
    public $trace = 1;
    public $exceptions = 0;
    public $_soap_version = 1;
    public $encoding = "";

    // additional variables returned from create new SoapClient object
    public $mySoapClient; // will be new SoapClient object

    // additional variables to call OpenConnectionAndBeginSession
    public $appID = "";
    public $appName = "";
    public $qbFileName = "";
    public $reqFileMod = "";

    // these two do not need the $instance variable and can be queried
    // as soon as the SOAP connection is made.
    public $QBXMLRPReleaseInfo = "";
    public $ReleaseInfo = "";

    // additional variables returned from OpenConnection
    public $instance = "";

    // these two need the $instance variable
    public $CurrentCompanyFileName = "";
    public $QBXMLVersionsForSession = "";

    // additional variables to ProcessRequest()
    public $qbXMLrq = ""; // string QBXML
    public $qbXMLrs = "";

    // additional variables to EndSession()
    public $EndSessionResult = "";

    // additional variables to BeginSession()
    public $BeginSessionResult = "";

    // additional variables to CloseConnection()
    public $CloseConnectionResult = "";

    /************************************************
    * contructor function
    * Allows parms to be passed at construction time.
    ************************************************/
    function __construct(
        $wsdl = "",
        $loginName = "",
        $password = "",
        $appID = "",
        $appName = "",
        $qbFileName = "",
        $reqFileMod = ""
    )
    {
        $this->wsdl = $wsdl;
        $this->loginName = $loginName;
        $this->password = $password;
        $this->appID = $appID;
        $this->appName = $appName;
        $this->qbFileName = $qbFileName;
        $this->reqFileMod = $reqFileMod;
        
        echo $this->wsdl;
        
        return ("__construct():ok");
    }
    
    /************************************************
    * This function
    * 1. creates a new php SoapClient object
    * 2. establishes a SOAP-level connection with the QBRDS Server
    *
    * Note that the $instance variable is not yet created
    * and that the connection with the QBRDS application-layer
    * is not yet achieved, just the SOAP-layer connection.
    ************************************************/
    function ConnectToQBRDSServer(){

        $this->mySoapClient = new SoapClient($this->wsdl,
            array(
                "loginName" => $this->loginName,
                "password" => $this->password,
                "trace" => $this->trace,
                "exceptions" => $this->exceptions,
                "_soap_version" => $this->_soap_version,
                'encoding'=>$this->encoding
                )
            );

        return(1);
    }

    /************************************************
    * The next several functions correspond directly
    * to the SOAP-level wsdl response.
    *
    * They are, by design, thin wrappers around the PHP5 SOAP
    * __soapcall() function, but *might* add the try...catch framework
    * for error and exception handling at the class level.
    *
    * Please refer to the wsdl response for clarification
    * on the function's parameters and return values.
    ************************************************/
    function OpenConnectionAndBeginSession()
    {
        $this->instance = $this->mySoapClient->__soapcall(
            "OpenConnectionAndBeginSession",
            array(
                "loginName" => $this->loginName,
                "password" => $this->password,
                "appID" => $this->appID,
                "appName" => $this->appName,
                "qbFileName" => $this->qbFileName,
                "reqFileMod" => $this->reqFileMod
                )
            );
        return(1);
    }

    /***********************************************/
    function GetQBXMLrPReleaseInfo()
    {
        $this->QBXMLRPReleaseInfo = $this->mySoapClient->__soapcall(
            "GetQBXMLRPReleaseInfo",
            array());
        return(1);
    }

    /***********************************************/
    function GetReleaseInfo()
    {
        $this->ReleaseInfo = $this->mySoapClient->__soapcall(
            "GetReleaseInfo",
            array());
        return(1);
    }

    /***********************************************/
    function GetCurrentCompanyFileName()
    {
        $this->CurrentCompanyFileName = $this->mySoapClient->__soapcall(
            "GetCurrentCompanyFileName",
            array('instance'=>$this->instance));
        return(1);
    }

    /***********************************************/
    function GetQBXMLVersionsForSession()
    {
        $this->QBXMLVersionsForSession = $this->mySoapClient->__soapcall(
            "QBXMLVersionsForSession",
            array('instance'=>$this->instance));
        return(1);
    }

    /***********************************************/
    function EndSession(){
        $this->EndSessionResult = $this->mySoapClient->__soapcall(
            "EndSession",
            array('instance'=>$this->instance));
        return(1);
    }

    /***********************************************/
    function BeginNewSession($BeginSessionArray){
        $this->BeginNewSessionResult = $this->mySoapClient->__soapcall(
            "BeginNewSession",
            $BeginSessionArray);
        return(1);
    }

    /***********************************************/
    function CloseConnection(){
        $this->CloseConnectionResult = $this->mySoapClient->__soapcall(
            "CloseConnection",
            array('instance'=>$this->instance));
        return(1);
    }

    /***********************************************
    * This the core function of the QBXML message model.
    ***********************************************/
    function ProcessRequest(){
        $this->qbXMLrs = $this->mySoapClient->__soapcall(
            "ProcessRequest",
            array(
                "instance" => $this->instance,
                "qbXMLrq" => $this->qbXMLrq));
        return(1);
    }
}
?>
// end of file.
Return current item: QBRDS Client