0 && $createTimeFrom != "") : // Init arrays $deliveryAddress = 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]); if ($trackingID != "") : // 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" . " tratp.tratp_createtime >= '" . $createTimeFrom . "' 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); 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(); // ------------------------------------- // 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); 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; endfor; // End loop tracking IDs // ********************* // * Generate response * // ********************* $response .= ""; $response .= ""; $response .= "3.1"; // List tracking events $eventResponse = ""; for ($j = 0; $j < $trackingIDsLen; $j++) : $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++) : // Get event number of current (tourarticle)process entry mapped to IFTSTA $tmpEventNo = $mapEventNo[$tratpType[$j][$i]]; if ($tmpEventNo != "" && is_numeric($tmpEventNo)) : $eventResponse .= ""; $eventResponse .= "EVENT_" . $tmpEventNo . ""; $eventResponse .= "" . $eventMsgIFTSTA[$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 .= "" . "" . ""; $eventResponse .= "" . $trSignname[$j][$i] . ""; $eventResponse .= ""; endif; endfor; $eventResponse .= ""; endfor; if ($eventResponse != "") : $response .= ""; $response .= $eventResponse; $response .= ""; endif; $response .= ""; // $response = urlencode($response); $responseLen = strlen($response); endif; return $response; } // ************************************************************************************************************************************ // Generate response for TEST $response = generateTrackingIFTSTA(array("123456789"), "2011-09-08 00:00:00"); echo $response; // ************************************************************************************************************************************ ?>