' . "\n" .
'' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
'' . "\n" .
"\n";
$res = xmlRequest($XS_HOST, $XS_PORT, $XS_SERVICE, $out);
$vals = $res[0];
$index = $res[1];
$log_txt = "********************************************************************************\n" . $out;
$retA = array();
if (array_key_exists('SOAP:FAULT', $index)):
echo $vals[$index['FAULTCODE'][0]]['value'] . " : " . $vals[$index['FAULTSTRING'][0]]['value'] . "\n";
writeLog($log_txt);
die();
else:
$log_txt .= "ERRORCODE=" . $vals[$index['RESULT'][0]]['attributes']['ERRORCODE'] . "\n";
$i = 0;
for ($i = 0, $j = 0; $i < count($index['NS6:POINT']); $i++, $j += 2):
$log_txt .= "\n";
foreach ($vals[$index['NS2:RESULTADDRESS'][$j]]['attributes'] AS $attr => $val) {
$log_txt .= "$attr: " . $val . "\n";
}
$score = $vals[$index['NS2:RESULTADDRESS'][$j]]['attributes']['TOTALSCORE'];
$X = round($vals[$index['NS6:POINT'][$i]]['attributes']['X']) / 100000;
$Y = round($vals[$index['NS6:POINT'][$i]]['attributes']['Y']) / 100000;
$log_txt .= "Y, X = " . $X . ", " . $Y . "\n";
$retA[] = array($score, $X, $Y);
if ($score == 100 && count($retA) == 1):
$ad_id = "";
$sqlquery = "SELECT ad_id FROM address WHERE ad_street = '$ad_street' AND ad_zipcode = '$ad_zipcode' AND ad_city = '$ad_city' AND ad_country = '$ad_country'";
$res = mysql_query($sqlquery) or die ($sqlquery);
if ($row = mysql_fetch_array($res, MYSQL_ASSOC)):
$ad_id = $row["ad_id"];
endif;
mysql_free_result($res);
if ($ad_id == ""):
$sqlquery = "INSERT INTO address (ad_street, ad_zipcode, ad_city, ad_country) VALUES ('$ad_street', '$ad_zipcode', '$ad_city', '$ad_country')";
mysql_query($sqlquery) or die ($sqlquery);
$ad_id = mysql_insert_id();
endif;
$sqlquery = "INSERT INTO address_geo (ad_id, adg_hsno, adg_gps_long, adg_gps_lat) VALUES ('$ad_id', '$tr_hsno', '" . $X . "', '" . $Y . "')";
mysql_query($sqlquery) or die ($sqlquery);
endif;
endfor;
// echo "Index array\n";
// print_r($index);
// echo "\nVals array\n";
// print_r($vals);
endif;
writeLog($log_txt);
return $retA;
}
function XSplanTour($stopCoordinates)
{
// $XS_HOST = 'localhost';
$XS_HOST = '172.16.0.154';
$XS_PORT = 50050;
$XS_SERVICE = '/xsequence/ws/XSequence';
$outStops = '';
$subStops = '';
foreach ($stopCoordinates as $idx => $pair) {
$outStops .=
' ' . "\n" .
' ' . "\n" .
' ' . "\n";
$subStops .= ' ' . "\n";
}
// $planningParams->costDistanceKm = 10;
// $planningParams->costPeriodMinute = 50;
// $planningParams->maxProcessorPeriod = 5;
// $planningParams->distanceCalculation->dimaCoordFormat = 'GEODECIMAL';
$out =
'' . "\n" .
'' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
$outStops .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
$subStops .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
' ' . "\n" .
'' . "\n" .
"\n";
//echo $out;
$res = xmlRequest($XS_HOST, $XS_PORT, $XS_SERVICE, $out);
$vals = $res[0];
$index = $res[1];
$log_txt = "********************************************************************************\n" . $out;
$retA = array();
if (array_key_exists('SOAP:FAULT', $index)) {
echo $vals[$index['FAULTCODE'][0]]['value'] . " : " . $vals[$index['FAULTSTRING'][0]]['value'] . "\n";
die();
} else {
$log_txt .= "RESULT=" . $vals[$index['NS2:RESULT'][0]]['attributes']['RESULT'] . "\n\n";
foreach ($vals[$index['NS17:TOUR'][0]]['attributes'] AS $attr => $val) {
$log_txt .= "$attr: $val\n";
}
foreach ($index['NS17:OUTPUTTOURPOINT'] AS $otp) {
$log_txt .= "\n";
$retA[] = $vals[$otp]['attributes']['STOPID'];
foreach ($vals[$otp]['attributes'] AS $attr => $val) {
$log_txt .= "$attr: $val\n";
}
}
// echo "Index array\n";
// print_r($index);
// echo "\nVals array\n";
// print_r($vals);
}
writeLog($log_txt);
return $retA;
}
function XSplanTourJob($jb_id_plan)
{
global $mysql_db;
$stopCoordinates = array();
$sqlquery = "SELECT ad_country, ad_zipcode, ad_city, ad_street, tr_hsno FROM phoenix.tour As tr, phoenix.address AS ad WHERE jb_id = $jb_id_plan AND tr.ad_id = ad.ad_id ORDER BY tr_sort";
$res = mysql_query($sqlquery, $mysql_db) or die ($sqlquery . ": " . mysql_error($mysql_db));
$i = 0;
while ($row = mysql_fetch_array($res, MYSQL_ASSOC)):
$coords = XSfindAddress("D", $row["ad_zipcode"], $row["ad_city"], $row["ad_street"], $row["tr_hsno"]);
if ($coords[0][0] != 100) {
echo " kein exakter Match
\n"; flush();
echo "Routenoptmierung nicht möglich!
\n";
die();
// } else {
// echo " ok
\n"; flush();
}
$stopCoordinates[$i++] = array($coords[0][1] * 100000, $coords[0][2] * 100000);
endwhile;
mysql_free_result($res);
//print_r($stopCoordinates);
//die();
$planTour = XSplanTour($stopCoordinates);
if (count($planTour) > 0):
// bestehenden tr_sort mit 100 addieren
for ($i = 0; $i < count($planTour); $i++) {
exec_query("UPDATE phoenix.tour SET tr_sort = " . (100 + $i + 1) . " WHERE jb_id = $jb_id_plan AND tr_sort = " . ($i+1));
exec_query("UPDATE phoenix.tourarticle SET tr_sort = " . (100 + $i + 1) . " WHERE jb_id = $jb_id_plan AND tr_sort = " . ($i+1));
}
// jetzt k�n die neuen tr_sort geschrieben werden
for ($i = 0; $i < count($planTour); $i++) {
exec_query("UPDATE phoenix.tour SET tr_sort = " . ($i + 1) . " WHERE jb_id = $jb_id_plan AND tr_sort = " . (100 + $planTour[$i]));
exec_query("UPDATE phoenix.tourarticle SET tr_sort = " . ($i + 1) . " WHERE jb_id = $jb_id_plan AND tr_sort = " . (100 + $planTour[$i]));
}
return true;
endif;
return false;
}
function xmlRequest($host, $port, $service, $xmlReq)
{
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)
\n";
} else {
fputs ($fp, "POST $service HTTP/1.1\r\n");
fputs ($fp, "Host: localhost\r\n");
fputs ($fp, "Content-type: text/xml; charset=utf-8\r\n");
fputs ($fp, "Content-length: " . strlen($xmlReq) . "\r\n");
fputs ($fp, "Connection: close\r\n\r\n");
fputs ($fp, $xmlReq);
$line = "";
while (substr($line, 0, 14) != "