beginner here for some help with php, I am creating a service that runs through an api using a SOAP connection, collects data from xml and searches for PODImage which is a base64 code that I then run a function on to convert it into a gif file, it then creates that file and saves it to a different server using curl. This process worked on a test version of the page I created and still does but despite the code being exactly the same it does not return any values only the else statement I implemented. Please see the code below to gain a better understanding of what is happening:
// Build XML to be submitted to the API
$xmlPOST = '
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<GetConsignments xmlns="http://tempuri.org/">
<userName>user</userName>
<password>pass</password>
<fromManifestDate>2014-08-05</fromManifestDate>
<toManifestDate>2014-08-11</toManifestDate>
<exportType>All</exportType>
</GetConsignments>
</Body>
</Envelope>';
$action = "http://tempuri.org/IThirdPartyServices/GetConsignments";
$connection = new SoapConnection( $xmlPOST, $action, $useDevConnection );
$xml = $connection->fetchViaSOAP();
// Find and register the Namespacing within the XML
$xml->registerXPathNamespace( "a", "http://schemas.datacontract.org/2004/07/ConnectSystem.Models.Integration" );
// Filter the returned XML to only the returned consignments
$part = $xml->xpath( "//a:ListOfConsignments" );
$consignments = $part[0]->children( "a", true );
// Create an empty array to store any returned consignments IDs
$consignmentNumbers = array();
// If there are any consignments filter through them
if( count($consignments) > 0 )
{
foreach ( $consignments as $consignment ) {
// Add the consignment ID to the array
array_push($consignmentNumbers, array($consignment->ConsignmentNumber, $consignment->RequestDepotNumber));
}
}
else
{
echo "<pre>XML Result: " . $xml->asXML() . "</pre><br/>";
echo "There were no consignments returned.<hr/>";
// End the output buffer & stop execution
ob_end_flush();
die();
}
// Create a blank array ready for the CSV data
$csv_data = array();
$image_data = array();
$podAction = "http://tempuri.org/IThirdPartyServices/GetProofOfDelivery";
// If there are consignments check for a POD
if( count($consignmentNumbers) > 0 )
{
foreach ( $consignmentNumbers as $consignment ) {
// Build the XML to be submitted to the API
$podXmlPOST = '
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<GetProofOfDelivery xmlns="http://tempuri.org/">
<userName>019ORTIGA</userName>
<password>019ORTIGA</password>
<consignmentNumber>' . $consignment[0] . '</consignmentNumber>
</GetProofOfDelivery>
</Body>
</Envelope>';
$second_connection = new SoapConnection( $podXmlPOST, $podAction, $useDevConnection );
$podXml = $second_connection->fetchViaSOAP();
// Find and register the Namespacing within the XML
$podXml->registerXPathNamespace( "a", "http://schemas.datacontract.org/2004/07/ConnectSystem.Models.Integration" );
// Filter the returned XML to the PODs
$second_part = $podXml->xpath( "//a:connectPODs" );
$pods = $second_part[0]->children( "a" , true );
// If there are any PODs filter through them
if( count($pods) > 0 )
{
$lastPodID = "";
foreach ($pods as $pod) {
if ( $pod->PODImage !== null )
{
$depotRef = $consignmentNumbers[array_search($pod->ConsignmentNumber, $consignmentNumbers)];
$imageFileName = (string)$pod->ConsignmentNumber;
if( (string)$pod->ConsignmentNumber === $lastPodID ) {
$imageFileName = (string)$pod->ConsignmentNumber . "-" . rand(1, 99999);
}
array_push( $csv_data, array("{$pod->ConsignmentNumber}", "{$imageFileName}.gif", "{$depotRef[1]}") );
array_push( $image_data, "{$pod->PODImage}" );
$lastPodID = (string)$pod->ConsignmentNumber;
}
}
}
else
{
echo "<pre>XML Result: " . $podXml->asXML() . "</pre><br/>";
echo "None of the consignments returned have PODs<hr/>";
// End the output buffer & stop execution
ob_end_flush();
die();
}
}
}
// Build the headers for the CSV
$csv_headers = array("Consignment Number", "Image Name", "Depot Reference");
// Create a CSV File (Sets up data)
$csv = new CSVFile( $csv_headers, $csv_data );
// Run an action with the CSV - downloadCSV, or writeCSV (Writes the file to the remote server)
$csv_file = $csv->writeCSV();
for ($i=0; $i < count($csv_data); $i++) {
$image = new ImageToServer( $image_data[$i], $csv_data[$i][1]);
$image->setFTPConnectionDetails();
$image->saveImageToServer();
}
// End the output buffer
ob_end_flush();
Sorry if this is a little much I'm just incredibly stuck on this and will accept any advice or help regarding the matter. The short problem is that all code returns is "None of the consignments returned have PODs" despite all of the necessary values being in place at the right time and in the right place (to my knowledge). I have used print_r() and var_dump() to check if values are being carried to where they need to be and outputted in the right way and as far as I can tell everything is in place. Hope this all makes sense, Please help me!