Jump to content

Recommended Posts

hi there,

i have written this code where i get teh xml file from ups servers,parse it and then insert the values in Database from the xml array which i get along the way.But when i run the code... i get a blank screen...it doesnt attempt to contact server...dont know what is must be wrong.looks like its not initiating the init fucntion.any ideas?

here is the code:

<?php
require_once 'lib.xml.php';
require_once 'inc.config.php';
class ups_xml {

var $wo_fields = array (
"SubscriptionFile" => "text",
"FileName" => "text",
"StatusType" => "text",
"Code" => "text",
"Description" => "text",
"Manifest" => "text",
"Shipper" => "text",
"ShipperNumber" => "text",
"Address" => "text",
"ShipTo" => "text",
"ConsigneeName" => "text",
"AddressLine1" => "text",
"City" => "text",
"StateProvinceCode" => "text",
"PostalCode" => "text",
"CountryCode" => "text",
"ReferenceNumber" => "text",
"Service" => "text",
"Code" => "text",
"PickupDate" => "text",
"ScheduledDeliveryDate" => "text",
"Package " => "text",
"Activity " => "text",
"Date" => "text",
"Time" => "text",
"TrackingNumber" => "text",
"PackageServiceOptions" => "text",
"BillToAccount" => "text",
"Option" => "text",
"Number" => "text"
);


Function Init()
{
$fp =@fsockopen("ssl://www.ups.com",443, $errno, $errstr);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else
$upstr = "POST /ups.app/xml/QVEvents HTTP/1.0\r\n";
$upstr .= "Host: www.ups.com\r\n";
$upstr .= "Content-Type: application/xml\r\n";
$upstr .= "Content-Length: 512\r\n\r\n";
$upstr .= '<?xml version="1.0"?>
<AccessRequest xml:lang="en-US">
<AccessLicenseNumber>xxxx</AccessLicenseNumber>
<UserId>xxxb</UserId>
<Password>cxxxr</Password>
</AccessRequest>
<?xml version="1.0" encoding="UTF-8"?>
<QuantumViewRequest xml:lang="en-US">
<Request>
<TransactionReference>
<CustomerContext>Test XML</CustomerContext>
<XpciVersion>1.0007</XpciVersion>
</TransactionReference>
<RequestAction>QVEvents</RequestAction>
</Request>
</QuantumViewRequest>';

fputs($fp,$upstr,strlen($upstr));

while (!feof($fp)) {

$soap_in .= fgets($fp,100);
}
$data = preg_replace('/.*?\r\n\r\n(.*)/s', '$1', $soap_in);
}

Function Parse_File($import_file)
{
global $post;
$lastpo = -1;
$import = array();

// echo "<xmp>$data</xmp>";
$xmldata = XML_To_Array($data);
$this->Walk_XML($xmldata);
}
Function Write_WO ($wo)
{
global $db;
$this->Add_Rec($query_type="insert","am_ups_xml",$this- >wo_fields,$wo);

}
Function Add_Rec( $query_type = "insert", $table, $fields, $data)
{
global $db;

foreach($fields AS $field => $type) {
if ( IsSet($data[$field]) || $query_type != "update" ) {
$value = $data[$field];
switch($type) {
case 'id':
if ( IsBlank($value) )
$value = 0;
else
$value = intval($value);
break;
case 'text':
if ( IsBlank($value) )
$value = "NULL";
else
$value = "'" . addslashes($value) . "'";
break;
case 'int':
if ( IsBlank($value) )
$value = "NULL";
else
$value = intval(preg_replace("/,/", "", $value));
break;
case 'decimal':
if ( IsBlank($value) )
$value = "NULL";
else
$value = doubleval(preg_replace("/,/", "", $value));
break;
case 'timestamp':
$y = $mo = $d = $h = $mi = $s = 0;

$timestamp_rx = "/^([ 0-9]*)\/([ 0-9]*)\/([ 0-9]*) " .
"([ 0-9]*)Sad[ 0-9]*) ([AP])M$/";
$date_rx = "/^([ 0-9]*)\/([ 0-9]*)\/([ 0-9]*)/";

$matches = array();

if ( preg_match($timestamp_rx, $value, $matches ) ) {
$mo = intval(trim($matches[1]));
$d = intval(trim($matches[2]));
$y = 2000 + intval(trim($matches[3]));
$h = intval(trim($matches[4]));
$mi = intval(trim($matches[5]));
$s = 0;
if ( $matches[6] == "P" )
$m += 12;
} elseif ( preg_match($date_rx, $value, $matches ) ) {
$mo = intval(trim($matches[1]));
$d = intval(trim($matches[2]));
$y = 2000 + intval(trim($matches[3]));
}

if ( $y > 2050 )
$y = $y - 100;

if ( $mo && $d ) {
$value = sprintf(
"'%04d-%02d-%02d %02d:%02d:%02d'::TIMESTAMP",
$y, $mo, $d, $h, $mi, $s);
} else {
$value = "NULL";
}
break;
case 'boolean':
if ( isBlank($value) )
$value = "NULL";
else
$value = ($value?"True":"False") . "::BOOLEAN";
break;
}
$keyval[$field] = $value;
$updates[] = "$field = $value";
$insert_fields[] = $field;
$insert_values[] = $value;
}
}

if ( $query_type == "insert" ) {
$query = "INSERT INTO $table ( " .
join(",", $insert_fields) . " ) VALUES ( " .
join(",", $insert_values) . " );";
}
$r = $db->Query($query);
}



Function Walk_XML($xmldata)
{
if ( Is_Array($xmldata) ) {
foreach ( $xmldata AS $k => $v ) {
if ( Is_Array($v) ) {
if ( $v["TAG"] == "SubscriptionFile" ) {
$this->Parse_XML_WO($v);
return;
}
$this->Walk_XML($v);
}
}
}
return;
}
Function Parse_XML_WO($woarr)
{
$wo = array();


if ( Is_Array($woarr)) {
foreach ( $woarr AS $k => $v ) {
if ( Is_Array($v) && isset($v["TAG"]) ) {
switch ( $v["TAG"] ) {
case "SubscriptionFile":
$wo["SubscriptionFile"] = $v["VALUE"];
break;
case "FileName":
$wo["FileName"] = $v["VALUE"];
break;
case "StatusType":
$wo["StatusType"] = $v["VALUE"];
break;
case "Code":
$wo["Code"] =$v["VALUE"];
break;
case "Description":
$wo["Description"] = $v["VALUE"];
break;
case "Manifest":
$wo["Manifest"] = $v["VALUE"];
break;
case "Shipper":
$wo["Shipper"] = $v["VALUE"];
break;
case "Name":
$wo["Name"] = $v["VALUE"];
break;
case "ShipperNumber":
$wo["ShipperNumber"] = $v["VALUE"];
break;
case "Address":
$wo["Address"] =$v["VALUE"];
break;
case "AddressLine1":
$wo["AddressLine1"] = $v["VALUE"];
break;
case "City":
$wo["City"] =$v["VALUE"];
break;
case "StateProvinceCode":
$wo["StateProvinceCode"] = doubleval($v["VALUE"]);
break;
case "PostalCode":
$wo["PostalCode"] = doubleval($v["VALUE"]);
break;
case "CountryCode":
$wo["CountryCode"] = doubleval($v["VALUE"]);
break;
case "ShipTo":
$wo["ShipTo"] = doubleval($v["VALUE"]);
break;
case "Address":
$wo["Address"] = doubleval($v["VALUE"]);
break;
case "ConsigneeName":
$wo["ConsigneeName"] = $v["VALUE"];
break;
case "ReferenceNumber":
$wo["ReferenceNumber"] = doubleval($v["VALUE"]);
break;
case "Value":
$wo["Value"] = doubleval($v["VALUE"]);
break;
case "Service":
$wo["Service"] = doubleval($v["VALUE"]);
break;

case "PickupDate":
$wo["PickupDate"] = $v["VALUE"];
break;
case "ScheduledDeliveryDate":
$wo["ScheduledDeliveryDate"] = $v["VALUE"];
break;
case "Package":
$wo["Package"] =$v["VALUE"];
break;
case "Activity":
$wo["Activity"] = $v["VALUE"];
break;
case "Date":
$this->$v["VALUE"];
break;
case "Time":
$wo["Time"] = $v["VALUE"];
break;
case "TrackingNumber":
$wo["TrackingNumber"] = $v["VALUE"];
break;
case "PackageServiceOptions":
$wo["PackageServiceOptions"] = $v["VALUE"];
break;
case "BillToAccount":
$wo["BillToAccount"] = $v["VALUE"];
break;
case "Option":
$wo["Option"] = $v["VALUE"];
break;
case "Number":
$wo["Number"] = $v["VALUE"];
break;


}
}
}
}
$this->Write_WO($wo);
}

}

?>

 

EDITED BY WILDTEEN88: Please use code tags (


) when posting large amounts of code. PHP tags (


) are acceptable for posting a short amount of code (5 lines max).

You have an error on line 89 according to my editor, which is this line:

$this->Add_Rec($query_type="insert","am_ups_xml",$this- >wo_fields,$wo);

Notice the bit highlighted in red. You'll see there is a space between - and > that space is causing the error. remove the space and your script should work.

 

Also it is a good idea to add the following two lines of code at the beginning of your script if you get problems like this again:

error_reporting(E_ALL);
ini_set('display_errors', 'On');

 

Remove those lines when you have finished sorting out the error.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.