I have a function that works great the first time it is called. On any subsequent use it fails.
Any assistance is appreciated.
<?php
function GetInv($prod,$rand) {
$UserName = "xxxxxx";
$Password = "xxxxxx";
$CustTransmissionID = "1111";
$CustID = "xxxxxx";
$timestamp = time();
$TransmissionTimeUTC = gmdate("Y-m-d H:i:s", $timestamp);
$TransmissionTimeLocal = date("Y-m-d H:i:s", $timestamp);
$rawhash = $UserName . "|" . $CustTransmissionID . "|" . $TransmissionTimeUTC . "|" . $Password;
$hash = md5($rawhash);
foreach ($prod as $value) {
$item .= "<QryItem>
<ProdID>$value</ProdID>
<LocID></LocID>
</QryItem>";
}
$xmlstr = <<<XML
<InvQtyQry>
<CustTransmissionID>$CustTransmissionID</CustTransmissionID>
<TransmissionTimeUTC>$TransmissionTimeUTC</TransmissionTimeUTC>
<TransmissionTimeLocal>$TransmissionTimeLocal</TransmissionTimeLocal>
<UserName>$UserName</UserName>
<PasswordHash>$hash</PasswordHash>
<CustID>$CustID</CustID>
<QryList>
$item
</QryList>
</InvQtyQry>
XML;
$URL = "http://www.xxxxxx.com/edi/xmlin.aspx?Process=InvQtyQry";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xmlstr");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
class xml2array {
function xml2array($xml) {
if (is_string($xml)) {
$this->dom = new DOMDocument;
$this->dom->loadXml($xml);
}
return FALSE;
}
function _process($node) {
$occurance = array();
foreach($node->childNodes as $child) {
$occurance[$child->nodeName]++;
}
if($node->nodeType == XML_TEXT_NODE) {
$result = html_entity_decode(htmlentities($node->nodeValue, ENT_COMPAT, 'UTF-8'),
ENT_COMPAT,'ISO-8859-15');
}
else {
if($node->hasChildNodes()){
$children = $node->childNodes;
for($i=0; $i<$children->length; $i++) {
$child = $children->item($i);
if($child->nodeName != '#text') {
if($occurance[$child->nodeName] > 1) {
$result[$child->nodeName][] = $this->_process($child);
}
else {
$result[$child->nodeName] = $this->_process($child);
}
}
else if ($child->nodeName == '#text') {
$text = $this->_process($child);
if (trim($text) != '') {
$result[$child->nodeName] = $this->_process($child);
}
}
}
}
if($node->hasAttributes()) {
$attributes = $node->attributes;
if(!is_null($attributes)) {
foreach ($attributes as $key => $attr) {
$result["@".$attr->name] = $attr->value;
}
}
}
}
return $result;
}
function getResult() {
return $this->_process($this->dom);
}
}
$obj = new xml2array($output);
$XML_array = $obj->getResult();
$qty_free = $XML_array['InvQtyQryResp']['ResponseList']['ResponseItem'];
return $qty_free;
}
?>