0) :
// Get the content of the tag
$tagContent = substr($strToParse, $pos1, $pos2 - $pos1);
endif;
endwhile;
return $tagContent;
};
function getTagContent ($strToParse, $tagBegin, $tagEnd) {
$tagContentArray = array();
$repeat = TRUE;
while ($repeat && !(strpos($strToParse, $tagBegin) === FALSE) && !(strpos($strToParse, $tagEnd) === FALSE)) :
$pos0 = strpos($strToParse, $tagBegin); // begin of tagBegin (first occurrence)
$pos1 = strpos($strToParse, $tagBegin) + strlen($tagBegin); // end of tagBegin (first occurrence)
$pos2 = strpos($strToParse, $tagEnd); // begin of tagEnd (first occurrence)
$pos3 = strpos($strToParse, $tagEnd) + strlen($tagEnd); // end of tagEnd (first occurrence)
if ($pos2 - $pos1 > 0) :
// Get the content of the tag
$tmpContent = substr($strToParse, $pos1, $pos2 - $pos1);
$tagContentArray[] = $tmpContent;
$strToParse = str_replace($tagBegin . $tmpContent . $tagEnd, "", $strToParse);
endif;
endwhile;
return $tagContentArray;
}
function getTrackingIDOfRequest ($req) {
global $apiVersion, $trackingUserID, $trackingPassword, $trackingIDs;
$apiVersion = getSingleTagContent($req, "", ""); // API Version
$trackingUserID = getSingleTagContent($req, "", ""); // User ID
$trackingPassword = getSingleTagContent($req, "", ""); // Password
$trackingIDs = getTagContent($req, "", ""); // Tracking IDs
};
// ---------------------------------------------------------------------------
// Generate a response for a specified tracking ID with existing tracking data
function generateTrackingResponseXML () {
global $tratId, $jbId, $trSort, $tratState, $tratRemark, $tratpType, $tratpState, $tratpRemark, $tratpCreatetime, $trSignname, $trHsno, $adStreet, $adZipcode, $adCity, $adCountry;
global $trackingIDs, $eventCounter, $trackingIDErrorState, $deliveryAddress, $eventMsgArray, $errMsgArray;
$trackingIDsLen = count($trackingIDs);
$response = "";
$response .= "";
$response .= "";
$response .= "3.5";
// List tracking events
$eventResponse = "";
for ($j = 0; $j < $trackingIDsLen; $j++) :
if ($trackingIDErrorState[$j] == "0") :
$eventResponse .= "" . $trackingIDs[$j] . "";
$eventResponse .= "";
$eventResponse .= "" . $deliveryAddress["ad_city"] . "";
$eventResponse .= "";
$eventResponse .= "" . $deliveryAddress["ad_zipcode"] . "";
$eventResponse .= "" . $deliveryAddress["ad_country"] . "";
$eventResponse .= "";
$eventResponse .= "";
for ($i = 0; $i < $eventCounter[$j]; $i++) :
$tmpEventNo = $tratpType[$j][$i]; // Get event number of current process entry
if ($tmpEventNo != "" && is_numeric($tmpEventNo)) :
$eventResponse .= "";
$eventResponse .= "EVENT_" . $tmpEventNo . "";
$eventResponse .= "" . $eventMsgArray["EVENT_" . $tmpEventNo] . "";
$eventResponse .= "" . substr($tratpCreatetime[$j][$i],0,10) . "T" . substr($tratpCreatetime[$j][$i],11,8) . "+01:00" . "";
$eventResponse .= "";
$eventResponse .= "" . $adCity[$j][$i] . "";
$eventResponse .= "" . "" . "";
$eventResponse .= "" . $adZipcode[$j][$i] . "";
$eventResponse .= "" . ($adCountry[$j][$i] == "" ? "DE" : $adCountry[$j][$i]) . "";
$eventResponse .= "";
$eventResponse .= "" . $tratpRemark[$j][$i] . "";
$eventResponse .= "" . $trSignname[$j][$i] . "";
$eventResponse .= "";
endif;
endfor;
$eventResponse .= "";
endif;
endfor;
if ($eventResponse != "") :
$response .= "";
$response .= $eventResponse;
$response .= "";
endif;
// List tracking errors
for ($j = 0; $j < $trackingIDsLen; $j++) :
if ($trackingIDErrorState[$j] != "0") :
$response .= "";
$response .= "" . $trackingIDs[$j] . "";
$response .= "";
$response .= "ERROR_" . $trackingIDErrorState[$j] . "";
$response .= "" . $errMsgArray["ERROR_" . $trackingIDErrorState[$j]] . "";
$response .= "";
$response .= "";
endif;
endfor;
$response .= "";
// $response = urlencode($response);
$responseLen = strlen($response);
return $response;
};
// Generate a response for an invalid specified tracking ID
function generateTrackingErrorResponse () {
global $tratId, $jbId, $trSort, $tratState, $tratRemark, $tratpType, $tratpState, $tratpRemark, $tratpCreatetime, $trSignname, $trHsno, $adStreet, $adZipcode, $adCity, $adCountry;
global $trackingIDs, $eventCounter, $trackingIDErrorState, $deliveryAddress, $eventMsgArray, $errMsgArray;
$response = "";
$response .= "";
$response .= "";
$response .= "3.5";
for ($j = 0; $j < $trackingIDsLen; $j++) :
if ($trackingIDErrorState[$j] != "0") :
$response .= "";
$response .= "" . $trackingIDs[$j] . "";
$response .= "";
$response .= "ERROR_" . $trackingIDErrorState[$j] . "";
$response .= "" . $errMsgArray["ERROR_" . $trackingIDErrorState[$j]] . "";
$response .= "";
$response .= "";
endif;
endfor;
$response .= "";
return $response;
};
// ---------------------------------------------------------------------------
// ******************************************
// * Get the tracking ID out of the request *
// ******************************************
getTrackingIDOfRequest($trackingReq); // Set global parameters: $trackingIDs, $trackingUserID, $trackingPassword
global $db, $PHP_SELF;
$trackingIDsLen = count($trackingIDs);
if ($apiVersion == "3.5") :
if ($trackingUserID == "stbx" && $trackingPassword == "cagtmv2924") :
// Initial code
$generalErrorState = "0";
if ($trackingIDsLen > 0) :
// Get the array for formatting the database-values for the output according to the defined type
$outputFormatField = defineOutputFormats();
// Init global arrays
$deliveryAddress = array();
$trackingIDErrorState = array();
$eventCounter = array();
$tratId = array();
$jbId = array();
$trSort = array();
$tratState = array();
$tratRemark = array();
$tratpType = array();
$tratpState = array();
$tratpRemark = array();
$tratpCreatetime = array();
$trSignname = array();
$trHsno = array();
$adStreet = array();
$adZipcode = array();
$adCity = array();
$adCountry = array();
for ($j = 0; $j < $trackingIDsLen; $j++) :
$trackingID = trim($trackingIDs[$j]);
// Init with "INVALID TRACKING NUMBER"
$trackingIDErrorState[$j] = "101";
if ($trackingID != "") :
// Ckeck validity of the tracking ID
// ... here ...
if (true) :
// Check existence of the hash value
// if (existsEntry("meta_object.metaobject",array("mo_hash",$trackingID))) :
if (existsEntry("phoenix.tourarticle",array("trat_serialno",$trackingID))) :
/*
$moId = getFieldValueFromId("meta_object.metaobject", "mo_hash", $trackingID, "mo_id");
$moIdRefDB = getFieldValueFromId("meta_object.metaobject", "mo_id", $moId, "mo_id_ref_db");
$objType = getFieldValueFromId("meta_object.metaobject", "mo_id", $moId, "mo_obj_type");
$objId = getFieldValueFromId("meta_object.metaobject", "mo_id", $moId, "mo_obj_id");
*/
if (true || $moId != "" && $moId > "0") :
// Get database instance
// $dbInst = getFieldValueFromId("meta_object.metaobject", "mo_id", $moIdRefDB, "mo_value");
if (true || $dbInst != "") :
// Get database connection
// $db_conn = getDbConnectionSpecial($dbInst, $dbname, $dblogin, $dbpassword);
if (true || $objType == "track") :
// Get tracking ID from "tourarticle"
$sqlquery = "SELECT trat.trat_id, trat.jb_id, trat.tr_sort, trat.trat_state, trat.trat_remark,"
. " tratp.tratp_type, tratp.tratp_state, tratp.tratp_remark, tratp.tratp_createtime,"
. " tr.tr_signname, tr.tr_hsno,"
. " ad.ad_street, ad.ad_zipcode, ad.ad_city, ad.ad_country"
. " FROM phoenix.tourarticle AS trat, phoenix.tourarticleprocess AS tratp, phoenix.tour AS tr, phoenix.address AS ad"
. " WHERE trat.trat_serialno = '" . $trackingID . "' AND"
. " trat.trat_id = tratp.trat_id AND"
. " trat.jb_id = tr.jb_id AND"
. " trat.tr_sort = tr.tr_sort AND"
. " tr.ad_id = ad.ad_id"
. " ORDER BY tratp.tratp_createtime";
// $result = $db_conn->query($sqlquery);
$result = $db->query($sqlquery);
if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
$i = 0;
$eventCounter[$j] = 0;
while ($row = $result->fetch_assoc()):
$tratId[$j][$i] = $row["trat_id"]; // [$j] = Index per tracking ID in "trat_serialno"
$jbId[$j][$i] = $row["jb_id"];
$trSort[$j][$i] = $row["tr_sort"];
$tratState[$j][$i] = $row["trat_state"];
$tratRemark[$j][$i] = $row["trat_remark"];
$tratpType[$j][$i] = $row["tratp_type"];
$tratpState[$j][$i] = $row["tratp_state"];
$tratpRemark[$j][$i] = $row["tratp_remark"];
$tratpCreatetime[$j][$i] = $row["tratp_createtime"];
$trSignname[$j][$i] = $row["tr_signname"];
$trHsno[$j][$i] = $row["tr_hsno"];
$adStreet[$j][$i] = $row["ad_street"];
$adZipcode[$j][$i] = $row["ad_zipcode"];
$adCity[$j][$i] = $row["ad_city"];
$adCountry[$j][$i] = $row["ad_country"];
$i++;
$eventCounter[$j]++; // How many events per tracking ID
endwhile;
$result->free();
// Check if no tracking data is found according to the current tracking ID
$trackingIDErrorState[$j] = "0"; // Init: OK
if ($i == 0) :
$trackingIDErrorState[$j] = "102"; // "NO TRACKING DATA FOUND"
endif;
// -------------------------------------
// Get delivery address and data of the end customer
$sqlquery = "SELECT trat.jb_id, trat.tr_sort,"
. " tr.tr_signname, tr.tr_hsno, tr.tr_person,"
. " ad.ad_street, ad.ad_zipcode, ad.ad_city, ad.ad_country"
. " FROM phoenix.tourarticle AS trat, phoenix.tour AS tr, phoenix.address AS ad"
. " WHERE trat.trat_serialno = '" . $trackingID . "' AND"
. " trat.jb_id = tr.jb_id AND"
. " trat.tr_sort = tr.tr_sort AND"
. " tr.ad_id = ad.ad_id"
. " ORDER BY trat.jb_id, trat.tr_sort";
// $result = $db_conn->query($sqlquery);
$result = $db->query($sqlquery);
if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
// The last row is the youngest order with the corresponding station no.
while ($row = $result->fetch_assoc()):
$deliveryAddress["jb_id"] = $row["jb_id"];
$deliveryAddress["tr_sort"] = $row["tr_sort"];
$deliveryAddress["ad_street"] = $row["ad_street"];
$deliveryAddress["tr_hsno"] = $row["tr_hsno"];
$deliveryAddress["ad_zipcode"] = $row["ad_zipcode"];
$deliveryAddress["ad_city"] = $row["ad_city"];
$deliveryAddress["ad_country"] = $row["ad_country"];
$deliveryAddress["tr_person"] = $row["tr_person"];
endwhile;
$result->free();
endif;
endif;
endif;
endif;
endif;
endif;
endfor; // End loop tracking IDs
else :
// No tracking ID has been sent
for ($j = 0; $j < $trackingIDsLen; $j++) :
$trackingIDErrorState[$j] = "204";
endfor;
endif;
else :
// UserId or password not correct (for ALL tracking IDs!!!)
for ($j = 0; $j < $trackingIDsLen; $j++) :
$trackingIDErrorState[$j] = "201";
endfor;
endif;
else :
// API version not correct (for ALL tracking IDs!!!)
for ($j = 0; $j < $trackingIDsLen; $j++) :
$trackingIDErrorState[$j] = "202";
endfor;
endif;
// Generate response
$response = generateTrackingResponseXML();
?>