0));
//Set the location to be the known location of the service (In case the wsdl file
//returns an invalid location (like an internal address for instance).
$client->__setLocation($connectionLocation);
//Call the webservice method with the parameters (As defined by the wsdl)
$result = $client->getContracts(array("arg0"=>$myUsername, "arg1"=>$myPasword));
//Convert the result to a string and parse it
$resultStr = (string)$result->return;
$xml = new xml($resultStr);
//If no errors have been found so far continue
if ($xml->dom["return"]["@attributes"]["error"] == "0")
{
//Retrieve the first contract "id" attribute from the parsed xml
$contractId = $xml->dom["return"]["contracts"]["contract"][0]["@attributes"]["id"];
//Using the contract "id" attribute generate an API key for further API calls
$result = $client->generateKey(array("arg0"=>$myUsername, "arg1"=>$myPasword, "arg2"=>$contractId));
//Convert the result to a string and parse it
$resultStr = (string)$result->return;
$xml = new xml($resultStr);
//If no errors have been found so far continue
if ($xml->dom["return"]["@attributes"]["error"] == "0")
{
//Retrieve the text of the return tag as the key
$key = $xml->dom["return"]["@data"];
//Set up the remaining arguments for the createTicket method
$company = 0; //Company code (Customers.getCompanies())
$contact = 0; //Contact code (Customers.getContacts())
$product = 0; //Product code (Contracts.getProducts())
$productVersion = 0; //Product Version code (Contracts.getProducts())
$ticketStatus = 0; //Ticket Status code (Contracts.getStatusTypes())
$priority = 0; //Priority code (Contracts.getPriorities())
$platform = 0; //Platform code (Contracts.getProducts())
$platformVersion = 0; //Platform version code (Contracts.getProducts())
$errorType = 0; //Error type code (Contracts.getErrorTypes())
$receivedBy = 0; //received by method (Contracts.getReceivedByMethods())
$timeSpent = 0; //Number of seconds spent recording this ticket (For reporting)
$supplierRef = ""; //Stored in the supplier reference field
$clientRef = ""; //Stored in the client reference field
$internalNotes = ""; //Agent only visible notes
$issue = ""; //Issue description
$summary = ""; //Short summary of issue
//Create an array of values to pass into the method
$values = array("arg0"=>$key, "arg1"=>$company, "arg2"=>$contact, "arg3"=>$product, "arg4"=>$productVersion, "arg5"=>$ticketStatus, "arg6"=>$priority, "arg7"=>$supplierRef, "arg8"=>$clientRef, "arg9"=>$internalNotes, "arg10"=>$platform, "arg11"=>$platformVersion, "arg12"=>$errorType, "arg13"=>$receivedBy, "arg14"=>$issue, "arg15"=>$timeSpent, "arg16"=>$summary);
//Setup the SoapClient for the ticket service
$client = new SoapClient($ticketLocation."?wsdl", array('exceptions' => 0));
//Set the location to be the know location of the service (In case the wsdl file
//returns an invalid location (like an internal address for instance).
$client->__setLocation($ticketLocation);
//call the function with the arguments set up previously
$result = $client->createTicket($values);
//Convert the result to a string
$resultStr = (string)$result->return;
//Print out the result to screen
print_r("
".$resultStr);
}
else
{
print_r($resultStr);
print("
".$xml->dom["return"]["@data"]);
}
}
else
{
print_r($resultStr);
print("
".$xml->dom["return"]["@data"]);
}
}
catch (SoapFault $result)
{
print_r($result);
}
//A quick class for handling / parsing XML strings and turning them into associative arrays
class xml
{
private $parser;
private $pointer;
public $dom;
public function __construct($data) {
$this->pointer =& $this->dom;
$this->parser = xml_parser_create();
xml_set_object($this->parser, $this);
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($this->parser, "tag_open", "tag_close");
xml_set_character_data_handler($this->parser, "cdata");
xml_parse($this->parser, $data);
}
private function tag_open($parser, $tag, $attributes)
{
if (isset($this->pointer[$tag]['@attributes'])) {
$content = $this->pointer[$tag];
$this->pointer[$tag] = array(0 => $content);
$idx = 1;
} else if (isset($this->pointer[$tag]))
$idx = count($this->pointer[$tag]);
if (isset($idx)) {
$this->pointer[$tag][$idx] = Array(
'@idx' => $idx,
'@parent' => &$this->pointer);
$this->pointer =& $this->pointer[$tag][$idx];
} else {
$this->pointer[$tag] = Array(
'@parent' => &$this->pointer);
$this->pointer =& $this->pointer[$tag];
}
if (!empty($attributes))
$this->pointer['@attributes'] = $attributes;
}
private function cdata($parser, $cdata) {
$this->pointer['@data'] = $cdata;
}
private function tag_close($parser, $tag) {
$current = & $this->pointer;
if (isset($this->pointer['@idx']))
unset($current['@idx']);
$this->pointer = & $this->pointer['@parent'];
unset($current['@parent']);
if (isset($current['@data']) && count($current) == 1)
$current = $current['@data'];
else if (empty($current['@data'])||$current['@data']==0)
unset($current['@data']);
}
}
?>