<?php 
/*=======================================================================
 *
 * order_data_request.php
 *
 * Autor: Marc Vollmann
 *
  =======================================================================*/


include_once ("../include/mcglobal.inc.php");
// include_once ("../include/caglobal.inc.php");    // For pricing and invoice-text only
// include_once ('../include/email/htmlMimeMail.php');
// include_once ("../include/services_func.inc.php");
include_once ("../include/inc_parseXML.inc.php");
// include_once ("../include/inc_mtf_func.inc.php");
include_once ("../include/inc_customer.inc.php");
include_once ("../include/inc_job.inc.php");
// include_once ("../include/inc_vehicle.inc.php");
// include_once ("../include/inc_disposition.inc.php");
// include_once ("../include/inc_disposition_DEV.inc.php");
// include_once ("../geo/geocode.inc.php");
$standalone = "YES";
include_once ("../include/ranking.inc.php");


// Write logdata into log file
$currentTime = getDateTime("0");
$currentDate = getDateTime("3");

$debug = false;
$debugOut = "";

// $orderDataReq = file_get_contents('php://input');

// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "orderDataReq", "selectedLanguage"));

if ($orderDataReq == "") :
   if (isset($argv[1])) : 
      $orderDataReq = $argv[1];
   endif;
endif;

function orderDataRequestLogFile ($msg, $logLevel = 0) {
  XMLRequestLogFile($msg, $logLevel, $logFile = "orderDataReq.log");
}


$orderDataReq = urldecode($orderDataReq);
$orderDataReq = str_replace("'", "", $orderDataReq);
$orderDataReq = mcEncode($orderDataReq);
$orderDataReq = str_replace("'", "", $orderDataReq);
// echo $orderDataReq . "<br><br>";

orderDataRequestLogFile($currentTime);
orderDataRequestLogFile($orderDataReq);


if ($selectedLanguage == "" || !is_numeric($selectedLanguage)) : $selectedLanguage = "1"; endif;  // Default in English
$languageSelected = $selectedLanguage;

getLanguage(__FILE__);
getCurrentScript(__FILE__);

$err = array();
$orderDataResponse = "";
$xmlOrderData = "";


// ---------------------------------------------------------------------------

// GLOBAL MODE OF USAGE
$globalParUseRelatedCustomer = getParameterValue("0", "GLOBAL_USE_RELATED_CUSTOMER", "0");

// *** Parse request ***
$orderDataArray = xml2array($orderDataReq);
if ($debug) :
   echo "Order data:<br><br>\n\n";
   print_r($orderDataArray); echo "<br><br><br>";
endif;


// *** Convert result array to usable parameters ***
// * Authentication data *
// Generic fields for multiple types
$authType        = strtolower(convertSpecial($orderDataArray["xml"]["order_data"]["auth"]["auth_type"]));
if ($authType == "") : $authType = "cs"; endif;
$authId          = convertSpecial($orderDataArray["xml"]["order_data"]["auth"]["auth_id"]);
$authEid         = convertSpecial($orderDataArray["xml"]["order_data"]["auth"]["auth_eid"]);
if ($authEid == "" && $authId != "") :
   if ($authType == "cr") :
      $authEid = getFieldValueFromId("courier","cr_id",$authId,"cr_eid");
   else :
      $authEid = getFieldValueFromId("customer","cs_id",$authId,"cs_eid");
   endif;
endif;

// Classic fields for customer only because of compatibility
$csEid          = convertSpecial($orderDataArray["xml"]["order_data"]["auth"]["customer"]);
if ($csEid == "") : $csEid = $authEid; endif;
$csId           = getFieldValueFromId("customer","cs_eid",$csEid,"cs_id");

if ($authId == "") :
   if ($authType == "cr") :
      $authId = getFieldValueFromId("courier","cr_eid",$authEid,"cr_id");
   else :
      $authId = $csId;
   endif;
endif;

$usrAccount     = convertSpecial($orderDataArray["xml"]["order_data"]["auth"]["account"]);
$usrPassword    = convertSpecial($orderDataArray["xml"]["order_data"]["auth"]["password"]);
$sessionId      = convertSpecial($orderDataArray["xml"]["order_data"]["auth"]["session_id"]);
// Optional customer group data (needed to find e.g. an article price automatically). Has to be set explicitly, because a customer could belong to more groups !!!!
$csGroupId      = convertSpecial($orderDataArray["xml"]["order_data"]["auth"]["group_no"]);
$csGroupName    = convertSpecial($orderDataArray["xml"]["order_data"]["auth"]["group_name"]);
if ($csGroupId != "" && is_numeric($csGroupId)) :
   $csGroupName = getFieldValueFromId("groups","grp_id",$csGroupId,"grp_name");
elseif ($csGroupName != "") :
   $csGroupId = getFieldValueFromId("groups","grp_name",$csGroupName,"grp_id");
endif;
// Reset customer group data if it could not be identified
if ($csGroupId == "" || $csGroupName == "") :
   $csGroupId = "";
   $csGroupName = "";
endif;

$debugOut .= "usrAccount: " . $usrAccount . "<br>\n";
$debugOut .= "usrPassword: " . $usrPassword . "<br>\n";
$debugOut .= "sessionId: " . $sessionId . "<br>\n";

$doContinue = true;
if ($csId == "" || !is_numeric($csId)) :
   $err[] = array("119", getLngt("Der Authentifikations-Header ist nicht vollständig!"));
   $doContinue = false;
endif;

if ($doContinue && checkRequestAuthenticationData($usrAccount, $usrPassword, $sessionId, $authId, $authType)) :

   $debugOut .= "Authentication okay!<br><br>\n";

   // Data
   $hqId            = getFieldValueFromId("customer","cs_id",$csId,"hq_id");
   $cscName         = convertSpecial($orderDataArray["xml"]["order_data"]["auth"]["costcenter_name"]);
   $cscId = "";
   if ($cscName != "") :
      $cscId        = getFieldValueFromClause("costcenter","csc_id","cs_id = '" . $csId . "' AND csc_name = '" . $cscName . "'");
   endif;
   // if ($cscId == "" || !is_numeric($cscId)) :
   //    $cscId        = getFieldValueFromClause("costcenter","csc_id","cs_id = '" . $csId . "' AND isnull(csc_pre_id)");   // Root costcenter
   // endif;


   // Get costcenter data
   $operation = convertSpecial($orderDataArray["xml"]["order_data"]["operation"]);
   $debugOn   = convertSpecial($orderDataArray["xml"]["order_data"]["debug_on"]);
   
   $debugOut .= "operation: " . $operation . "<br>\n";
   $debugOut .= "address_type: " . $address_type . "<br>\n";
   

   if (!$debug && $debugOn == "ON" || $debugOn == "YES") :
      $debug = true;
      
      echo "csId: " . $csId . "<br>";
      echo "csEid: " . $csEid . "<br><br>";
   endif;

   // Get requested orders
   $orderNumbers = convertSpecial($orderDataArray["xml"]["order_data"]["order_numbers"]);
   $orderNumberArray = explode("|", $orderNumbers);
   $orderNumberArrayLen = count($orderNumberArray);

   $isOperationalOrder = convertSpecial($orderDataArray["xml"]["order_data"]["is_operative"]);
   $isOperationalOrderArray = array();
   if ($isOperationalOrder != "") :
      $isOperationalOrderArray = explode("|", $isOperationalOrder);
   endif;
   $isOperationalOrderArrayLen = 0;
   if (is_array($isOperationalOrderArray)) :
      $isOperationalOrderArrayLen = count($isOperationalOrderArray);
   endif;
   
   $debugOut .= "isOperationalOrder: " . $isOperationalOrder . "<br>\n";
   $debugOut .= "isOperationalOrderArrayLen: " . $isOperationalOrderArrayLen . "<br>\n";


   if ($operation == "SET") :

      // Get requested order states to be changed in
      $orderStateFields = convertSpecial($orderDataArray["xml"]["order_data"]["list_jb_status"]);
      $orderStateFieldArray = explode("|", $orderStateFields);
      $orderStateFieldArrayLen = count($orderStateFieldArray);

      // Get courier to be associated
      $crIdFields = convertSpecial($orderDataArray["xml"]["order_data"]["list_cr_id"]);
      $crIdFieldsArray = explode("|", $crIdFields);

      // Get couriervehicle to be associated
      $crvhIdFields = convertSpecial($orderDataArray["xml"]["order_data"]["list_crvh_id"]);
      $crvhIdFieldsArray = explode("|", $crvhIdFields);

      // Get invoice numbers to be associated (regarding new state equals "3" <=> "exported")
      $invNoFields = convertSpecial($orderDataArray["xml"]["order_data"]["list_inv_no"]);
      $invNoFieldsArray = explode("|", $invNoFields);
      $invNoFieldsArrayLen = count($invNoFieldsArray);

      // ATTENTION: This following structures regard the FIRST job number in $orderNumbers ONLY!
      //            Only ONE order has to be sent for special job and/or station updates (!!!!)
      // Get data for selective update of job data fields (table "job")
      $jbDataArray = $orderDataArray["xml"]["order_data"]["job"];
      // Get data for selective update of station data fields (table "tour")      
      $jbTourdata = "";
      $jbTourdataZipcode = "";
      $jbTourdataCity = "";
      $jbTourdataCountry = "";
      $numOfStations = 0;      
      if ($orderDataArray["xml"]["order_data"]["stations"]["station"]["tr_sort"] != "" && is_numeric($orderDataArray["xml"]["order_data"]["stations"]["station"]["tr_sort"])) :
         $numOfStations = 1;
      else :
         $numOfStations = count($orderDataArray["xml"]["order_data"]["stations"]["station"]);
      endif;

      if ($debug) :
         echo "orderNumberArrayLen: " . $orderNumberArrayLen . "<br>";
         print_r($orderNumberArray); echo "\n\n<br><br>";
         
         echo "isOperationalOrderArrayLen: " . $isOperationalOrderArrayLen . "<br>";
         print_r($isOperationalOrderArray); echo "\n\n<br><br>";
         
         echo "orderStateFieldArrayLen: " . $orderStateFieldArrayLen . "<br>";
         print_r($orderStateFieldArray); echo "\n\n<br><br>";

         echo "invNoFieldsArray: " . $invNoFieldsArrayLen . "<br>";
         print_r($invNoFieldsArray); echo "\n\n<br><br>";

         echo "numOfStations: " . $numOfStations . "<br>";
      endif;

      // Iterate array
      $xmlOrderData .= "<order_data>";
      for ($i = 0; $i < $orderNumberArrayLen; $i++) :

          $xmlOrderData .= "<order>";

          $jbIdOrg = $orderNumberArray[$i];
          $xmlOrderData .= "<order_no>" . $jbIdOrg . "</order_no>";

          // First check valid association between authenticated customer and requested job(s) !!!!
          // $cscIdPayer = $dbData["job"]["csc_id_payer"];
          $cscIdPayer = getFieldValueFromId("job","jb_id",$jbIdOrg,"csc_id_payer");
          $csIdPayer = getFieldValueFromId("costcenter","csc_id",$cscIdPayer,"cs_id");

          // Get operational job of requested job (!!!!)
          $jbIsOperational = false;
          if ($isOperationalOrderArrayLen > 0 && ($isOperationalOrderArray[$i] == "" || $isOperationalOrderArray[$i] == "0")) :
             // Search for operational job by FDS job
             $tmpValue = getFieldValueFromClause("phoenix.genericdatacontainer","gdc_content","gdc_obj_type = 'jb' AND gdc_gen_fieldname = 'is_operative' AND gdc_obj_id = '" . $jbIdOrg . "'");
             $tmpArray = explode("|", $tmpValue);
             $jbId = $tmpArray[0];
             $jbIsOperational = true;
          else :
             // Take operational job (classic mode)
             $jbId = $jbIdOrg;
          endif;
          $xmlOrderData .= "<order_op_no>" . $jbId . "</order_op_no>";

          if ($debug) :
             echo "jbId: " . $jbId . "<br>";
          endif;

          if ($jbId != "" && is_numeric($jbId)) :

             if ($csId == $csIdPayer) :

                if ($debug) : echo "csId == csIdPayer: YES<br><br>"; endif;

                /*
                getDBData("job", $jbId);

                if ($debug) :
                   print_r($dbData); echo "\n\n<br><br>";
                endif;
                */

                $tmpOpCode = "0";  // Init

                // [1] CHECK FOR SETTING CARRIER
                $tmpCrId = $crIdFieldsArray[$i];
                $tmpCrvhId = $crvhIdFieldsArray[$i];
                if ($tmpCrId != "" && is_numeric($tmpCrId) && $tmpCrvhId != "" && is_numeric($tmpCrvhId)) :
                   
                   // Check association between courier and couriervehicle
                   $tmpCrvhCrId = getFieldValueFromId("couriervehicle","crvh_id",$tmpCrvhId,"cr_id");
                   if ($tmpCrvhCrId == $tmpCrId) :
                      $tmpCrEid = getFieldValueFromId("courier","cr_id",$tmpCrId,"cr_eid");
                      $tmpCrvhSid = getFieldValueFromId("couriervehicle","crvh_id",$tmpCrvhId,"crvh_sid");
                      if ($tmpCrEid != "" && $tmpCrvhSid != "") :

                         // Get potential current courier
                         $tmpJbHqId = getFieldValueFromId("job","jb_id",$jbId,"hq_id");
                         // $tmpJbCrIdCurr = getFieldValueFromId("job","jb_id",$jbId,"cr_id");
                         // $tmpJbCrIdOrderCurr = getFieldValueFromId("job","jb_id",$jbId,"cr_id_order");

                         TA("B");
                         $res = updateStmt("job", "jb_id", $jbId, array("cr_id", $tmpCrId, "cr_id_order", $tmpCrId, "cr_sid", $tmpCrvhSid), "");
                         if ($db->affected_rows > 0) :

                            // Write logdata into log database
                            $currentSessionUsrId = "0";
                            $arLooseRanking = "0";
                            writeToLogDB("7",$tmpJbHqId,$jbId,$currentSessionUsrId,$tmpCrId,$tmpCrvhSid,"","LOST_RANKING=" . ($arLooseRanking == "1" ? "YES" : "NO"));
                         
                            // Survey
                            // checkJobForSurvey($jbId);
                         endif;
                         TA("C");
                         TA("E");
                      else :
                         $tmpOpCode = "113";
                         $tmpOpMsg = "Der spezifizierte Transporteur oder das spezifizierte Fahrzeug scheinen nicht zu existieren!";
                      endif;
                   else :
                      $tmpOpCode = "112";
                      $tmpOpMsg = "Das angegebene Fahrzeug scheint dem Transporteur nicht zugeordnet!";
                   endif;
                endif;


                // [2] CHECK FOR CHANGING STATE
                // Check for changing state
                if ($tmpOpCode == "0" && $orderStateFieldArrayLen > 0) :

                   $newState = $orderStateFieldArray[$i];
                   if ($debug) : echo "newState == " . $newState  . "<br><br>"; endif;
                   if ($newState != "" && is_numeric($newState)) :

                      // [Order states: 0 = open | 1 = taken | 2 = finished | 9 = to be reassigned manually | 8 = automatic assignment]
                      $jbStatusCurr = getFieldValueFromId("job","jb_id",$jbId,"jb_status");

                      $tmpOpCode = "0";
                      $tmpOpMsg = "OK";
                      if ($newState == "0") :
                         // State "Open"
                         $tmpOpCode = "199";
                         $tmpOpMsg = "Statusübernahme für OPEN z.Z. nicht implementiert!";

                      elseif ($newState == "1") :

                         // State "Taken"
                         if ($jbStatusCurr != "2") :

                             // Get potential current courier
                             $tmpJbHqId = getFieldValueFromId("job","jb_id",$jbId,"hq_id");
                             $tmpJbCrIdCurr = getFieldValueFromId("job","jb_id",$jbId,"cr_id");
                             $tmpJbCrIdOrderCurr = getFieldValueFromId("job","jb_id",$jbId,"cr_id_order");

                            if ($tmpJbCrIdCurr != "" && $tmpJbCrIdOrderCurr != "") :

                               TA("B");
                               $res = updateStmt("job", "jb_id", $jbId, array("jb_status", $newState, "jb_globaljob", "0", "jb_autoranking", "0"), "");
                               if ($db->affected_rows > 0) :

                                  // Set current assigning time for revoking a job if not taken by the courier
                                  /*
                                  if (existsEntry("autoranking",array("jb_id",$f_jb_id,"cr_id",$cr_id))) :
                                     updateStmt("autoranking", "jb_id", $f_jb_id, array("ar_challenge", "0", "ar_lastassigntime", $currentTime, "ar_looseranking", $arLooseRanking, "ar_locating", "0"),"cr_id = '" . $cr_id . "'");
                                  else :
                                     insertStmt("autoranking", array("jb_id", $f_jb_id, "cr_id", $cr_id, "ar_challenge", "0", "ar_lastassigntime", $currentTime, "ar_looseranking", $arLooseRanking, "ar_locating", "0"));
                                  endif;
                                  */

                                  // Insert PDA command to remove job (take cr_id/cr_id_order before changing)
                                  /*
                                  $currentTimePDA = getDateTime("datetime_plus_offset", array(0,0,30,0,0,0), $formatStr = "Y-m-d H:i:s");
                                  if ($tmpJbCrIdCurr != "" && $tmpJbCrIdCurr != "0") :
                                     insertPDACommand($tmpJbHqId, $tmpJbCrIdCurr, "4", "1", $jbId, $currentTimePDA, "");
                                  endif;
                                  if ($tmpJbCrIdOrderCurr != "" && $tmpJbCrIdOrderCurr != "0" && $tmpJbCrIdOrderCurr != $tmpJbCrIdCurr) :
                                     insertPDACommand($tmpJbHqId, $tmpJbCrIdOrderCurr, "4", "1", $jbId, $currentTimePDA, "");
                                  endif;
                               
                                  // Reset availabletime of the OLD courier if requested by the disposition manually
                                  if ($f_cr_availabletime_reset == "1") :
                                     updateStmt("courier", "cr_id", $tmpJbCrIdCurr, array("cr_availabletime", $currentTime));
                                  endif;
                                  */

                                  // Write logdata into log database
                                  $currentSessionUsrId = "0";
                                  $arLooseRanking = "0";
                                  writeToLogDB("7",$tmpJbHqId,$jbId,$currentSessionUsrId,$tmpCrId,$tmpCrvhSid,"","LOST_RANKING=" . ($arLooseRanking == "1" ? "YES" : "NO"));
                               
                                  // Survey
                                  // checkJobForSurvey($jbId);
                               endif;
                               TA("C");
                               TA("E");
                            else :
                               $tmpOpCode = "111";
                               $tmpOpMsg = "Es wurde kein Transporteur oder kein Fahrzeug spezifiziert!";
                            endif;
                         else :
                            $tmpOpCode = "105";
                            $tmpOpMsg = "Der neue Status darf nicht gesetzt werden!";
                         endif;

                      elseif ($newState == "2") :

                         // State "Finished"
                         if ($jbStatusCurr != "2") :

                            TA("B");
                            $res = updateStmt("job", "jb_id", $jbId, array("jb_status", $newState, "jb_finishtime", $currentTime), "");
                            if ($db->affected_rows > 0) :

                               // Write logdata into log database
                               $currentSessionUsrId = "0";
                               $tmpJbHqId = getFieldValueFromId("job","jb_id",$jbId,"hq_id");

                               writeToLogDB("5",$tmpJbHqId,$jbId,$currentSessionUsrId,$tmpCrId,$tmpCrvhSid,"","");
                            
                               // Survey
                               // checkJobForSurvey($jbId);
                            endif;
                            TA("C");
                            TA("E");
                         else :
                            $tmpOpCode = "105";
                            $tmpOpMsg = "Der neue Status darf nicht gesetzt werden!";
                         endif;
   
                      elseif ($newState == "3") :

                         // State "Exported"
                         if ($jbStatusCurr == "2") :

                            // Check for cancellation
                            $tmpJbStorno = getFieldValueFromId("job","jb_id",$jbId,"jb_storno");
                            if ($tmpJbStorno == "" || $tmpJbStorno == "0") :

                               // Check for being exported in the past
                               $tmpJbExportTime = getFieldValueFromId("job","jb_id",$jbId,"jb_export_time");
                               if ($tmpJbExportTime == "" || $tmpJbExportTime == "0000-00-00 00:00:00" || $tmpJbExportTime == "9999-12-31 23:59:59") :

                                  // Check for existence of the invoice number
                                  $jbInvNo = trim($invNoFieldsArray[$i]);
                                  if ($jbInvNo != "") :

                                     TA("B");
                                     $res = updateStmt("job", "jb_id", $jbId, array("jb_export_time", $currentTime), "");
                                     if ($db->affected_rows > 0) :
                                        // Write into invoice table
                                        if (existsEntry("invoice",array("jb_id",$jbId))) :
                                           updateStmt("invoice", "jb_id", $jbId, array("inv_no", $jbInvNo, "inv_datetime", $currentTime),"");
                                        else :
                                           insertStmt("invoice", array("jb_id", $jbId, "inv_no", $jbInvNo, "inv_datetime", $currentTime));
                                        endif;
                                     endif;
                                     TA("C");
                                     TA("E");
                                  else :
                                     $tmpOpCode = "109";
                                     $tmpOpMsg = "Dem zu exportierenden Auftrag wurde keine Rechnungsnummer mitgegeben! Der Export-Status konnte nicht gesetzt werden!";
                                  endif;
                               else :
                                  $tmpOpCode = "108";
                                  $tmpOpMsg = "Der Auftrag wurde erhielt bereits in der Vergangenheit den Export-Status!";
                               endif;
                            else :
                               $tmpOpCode = "107";
                               $tmpOpMsg = "Der Auftrag wurde storniert und darf keinen Export-Status erhalten!";
                            endif;
                         else : 
                            $tmpOpCode = "106";
                            $tmpOpMsg = "Der Auftrag ist noch nicht beendet und darf keinen Export-Status erhalten!";
                         endif;

                      elseif ($newState == "8") :
                         // State "Automatic assignment"
                         $tmpOpCode = "199";
                         $tmpOpMsg = "Statusübernahme für AUTOMATIC ASSIGNMENT z.Z. nicht implementiert!";

                      elseif ($newState == "9") :
                         // State "To be reassigned manually"
                         $tmpOpCode = "199";
                         $tmpOpMsg = "Statusübernahme für REASSIGNED MANUALLY z.Z. nicht implementiert!";

                      else :
                         $tmpOpCode = "104";
                         $tmpOpMsg = "Kein gültiger Status für eine Übernahme spezifiziert!";
                      endif;

                      $xmlOrderData .= "<op_code>" . $tmpOpCode . "</op_code>";
                      $xmlOrderData .= "<op_msg>" . getLngt($tmpOpMsg) . "</op_msg>";
                      
                   else :
                     $xmlOrderData .= "<op_code>" . "103" . "</op_code>";
                     $xmlOrderData .= "<op_msg>" . getLngt("Es wurde für den Auftrag kein neuer Status angefragt!") . "</op_msg>";
                   endif;
                else :
                  $xmlOrderData .= "<op_code>" . $tmpOpCode . "</op_code>";
                  $xmlOrderData .= "<op_msg>" . getLngt("Das Fahrzeug passt nicht zum Auftragnehmer oder es wurde kein Status für den Auftrag gesetzt!") . "</op_msg>";
                endif;


                // [3][A] Get data for selective update of "job" data
                $doUpdate = true;
                $defaultFieldArray = array();
                $setJobPrice = false;
                $jobPrice = "0.0000";

                TA("B");

                $jbDataFieldsArray = array_keys($jbDataArray);
                $jbDataFieldsArrayLen = count($jbDataFieldsArray);
                
                if ($doUpdate && $jbDataFieldsArrayLen > 0) :
                   for ($j = 0; $j < $jbDataFieldsArrayLen; $j++) :

                       if ($jbDataFieldsArray[$j] == "jb_tourname" || $jbDataFieldsArray[$j] == "jb_weight" || $jbDataFieldsArray[$j] == "jb_crvh_length" ||
                           $jbDataFieldsArray[$j] == "jb_crvh_width" || $jbDataFieldsArray[$j] == "jb_crvh_height" || $jbDataFieldsArray[$j] == "jb_crvh_position" ||
                           $jbDataFieldsArray[$j] == "jb_cr_filter" || $jbDataFieldsArray[$j] == "jb_freetext_1" || $jbDataFieldsArray[$j] == "jb_cr_remark") :

                          if ($jbDataArray[$jbDataFieldsArray[$j]] == "--DEL--") :
                             array_push($defaultFieldArray, $jbDataFieldsArray[$j], "");
                          else :
                             array_push($defaultFieldArray, $jbDataFieldsArray[$j], $jbDataArray[$jbDataFieldsArray[$j]]);
                          endif;

                       elseif ($jbDataFieldsArray[$j] == "jb_ordertime" || $jbDataFieldsArray[$j] == "jb_warningtime") :
                       
                          if ($jbDataArray[$jbDataFieldsArray[$j]] == "--DEL--") :
                             array_push($defaultFieldArray, $jbDataFieldsArray[$j], "");
                          else :
                             $jbDatetimeField = $jbDataArray[$jbDataFieldsArray[$j]];
                             if ($jbDatetimeField != "" && $jbDatetimeField != "0000-00-00 00:00:00") :
                                // $jbDatetimeField = checkDateTimeFormat($jbDatetimeField);    // DISABLED BECAUSE OF PHP VERSION ONLY !!! ACTIVATE AFTER MIGRATION !!!
                                $checkGmtdatetimeIsValid = strtotime($jbDatetimeField);
                                if ($checkGmtdatetimeIsValid != "" && is_int($checkGmtdatetimeIsValid)):
                                   $jbReserv = 1;
                                else :
                                   $xmlOrderData .= "<op_code>" . "120" . "</op_code>";
                                   $xmlOrderData .= "<op_msg>" . getLngt("Die Datumsangabe ist nicht korrekt!") . "</op_msg>";
                                   $doUpdate = false;
                                   break;
                                endif;
                             endif;
                             array_push($defaultFieldArray, $jbDataFieldsArray[$j], $jbDataArray[$jbDataFieldsArray[$j]]);
                          endif;

                       elseif ($jbDataFieldsArray[$j] == "jb_totalprice") :

                          if ($jbDataArray[$jbDataFieldsArray[$j]] == "--DEL--") :
                             $jobPrice = "0.0000";
                          else :
                             $jobPrice = $jbDataArray[$jbDataFieldsArray[$j]];
                             $jobPrice = str_replace (",", ".", $jobPrice);
                          endif;
                          if (!is_numeric($jobPrice)) :
                             $xmlOrderData .= "<op_code>" . "121" . "</op_code>";
                             $xmlOrderData .= "<op_msg>" . getLngt("Die Preisangabe ist nicht numerisch!") . "</op_msg>";
                             $doUpdate = false;
                             break;
                          endif;
                          array_push($defaultFieldArray, $jbDataFieldsArray[$j], $jobPrice);
                          $setJobPrice = true;
                       endif;
                   endfor;

                   if ($debug) :
                      echo "JOB.defaultFieldArray:<br>";
                      print_r($defaultFieldArray); echo "\n\n<br><br>";
                   endif;

                   // Update
                   if ($doUpdate && count($defaultFieldArray) > 0):

                      // Update data in "job"
                      updateStmt("job", "jb_id", $jbId, $defaultFieldArray, "");

                      // Update price data in "tourservice" if requested. The entry has to exist after order request
                      if ($setJobPrice) :
                         updateStmt("tourservice", "jb_id", $jbId, array("trs_price", $jobPrice, "trs_discount", "0.0000"), "trs_srv_name = 'Grundpreis'");
                      endif;
                   endif;
                endif;


                // [3][B] Get data for selective update of "tour" data
                if ($doUpdate && $numOfStations > 0) :
                   for ($j = 0; $j < $numOfStations; $j++) :

                       $defaultFieldArray = array();
                       $trSort = $j + 1;

                       if ($numOfStations == 1) :
                          $stationArray = $orderDataArray["xml"]["order_data"]["stations"]["station"];
                       else :
                          $stationArray = $orderDataArray["xml"]["order_data"]["stations"]["station"][$j];
                       endif;

                       $stationFieldArray = array_keys($stationArray);
                       $stationFieldArrayLen = count($stationFieldArray);

                       // * Handle standard DB fields *
                       for ($k = 0; $k < $stationFieldArrayLen; $k++) :
                           
                           if ($stationFieldArray[$k] != "ad_street" && $stationFieldArray[$k] != "ad_zipcode" && $stationFieldArray[$k] != "ad_city" &&
                               $stationFieldArray[$k] != "tr_id" && $stationFieldArray[$k] != "ad_id" && $stationFieldArray[$k] != "csc_id" && $stationFieldArray[$k] != "tr_status" && 
                               $stationFieldArray[$k] != "tr_sign" && $stationFieldArray[$k] != "tr_signame" && $stationFieldArray[$k] != "tr_modify") :

                              if ($stationArray[$stationFieldArray[$k]] == "--DEL--") :
                                 array_push($defaultFieldArray, $stationFieldArray[$k], "");
                              else :
                                 array_push($defaultFieldArray, $stationFieldArray[$k], $stationArray[$stationFieldArray[$k]]);
                              endif;
                           endif;
                       endfor;

                       if ($debug) :
                          echo "stationFieldArrayLen: " . $stationFieldArrayLen . "<br>";
                          print_r($stationFieldArray); echo "\n\n<br><br>";
                       endif;

                       // * Handle excluded DB fields like these for the address, etc. *
                       // Check for address fields either all empty or none of them empty
                       $tmpAdStr = $stationArray["ad_street"] . $stationArray["ad_zipcode"] . $stationArray["ad_city"];
                       if ($tmpAdStr != "" && ($stationArray["ad_street"] == "" || $stationArray["ad_zipcode"] == "" || $stationArray["ad_city"] == "")) :
                          $xmlOrderData .= "<op_code>" . "130" . "</op_code>";
                          $xmlOrderData .= "<op_msg>" . getLngt("Mindestens eine der Stationsadressen ist nicht vollständig!") . "</op_msg>";
                          $doUpdate = false;
                          break;
                       endif;

                       // ADD HERE "GPS"
                       // .... (!!!!) ........................................

                       // ADD HERE "ADDRESS SUPPLEMENT"
                       // .... (!!!!) ........................................

                       $trAdId    = "";
                       $trStreet  = $stationArray["ad_street"];
                       $trZipcode = $stationArray["ad_zipcode"];
                       $trCity    = $stationArray["ad_city"];
                       $trCountry = $stationArray["ad_country"];
                       if ($trCountry == "") : $trCountry = "DE"; endif;

                       if ($trStreet != "" && $trZipcode != "" && $trCity != "") :
                          $sqlStmt = "SELECT ad_id FROM address WHERE ad_street = '" . $trStreet . "' AND ad_zipcode = '" . $trZipcode . "' AND ad_city = '" . $trCity . "' AND ad_country = '" . $trCountry . "'";
                          $trAdId = $db->getOne($sqlStmt);
                          if (DB::isError($ad_id)) die ("$PHP_SELF: <br>$sqlStmt<br>" . $ad_id->getMessage());
                          if ($trAdId == ""):
                             insertStmt("address", array("ad_street", $trStreet, "ad_zipcode", $trZipcode, "ad_city", $trCity, "ad_country", "DE"));
                             $trAdId = getLastInsertID();
                          endif;
                          // $tmpArray = insertAddress($trStreet, $trZipcode, $trCity, "", "DE", true);
                          // $trAdId = $tmpArray[0];
                          array_push($defaultFieldArray, "ad_id", $trAdId);
                       endif;
                       // Get "EXTERN" costcenter of the current headquarters
                       if ($globalParUseRelatedCustomer != "1") :
                          $trCscId = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hqId);
                          array_push($defaultFieldArray, "csc_id", $trCscId);
                       endif;

                       // ADD HERE "tourarticle"
                       // .... (!!!!) ........................................

                       // Station services
                       $trServices       = $stationArray["services"];
                       $trTimeslots      = $trServices["timeslots"];
                       $trTimesunits     = $trServices["timeunits"];
                       $trShipmentMode   = $trServices["shipment_mode"];
                       $trOrderType      = $trServices["order_type"];
                       $trDeliveryInfo   = $trServices["delivery_info"];
                       $trFlagServiceDoc = $trServices["flag_service_doc"];
                       $trDocumentsURL   = $trServices["documents_URL"];
                       
                       // Write some service infos into "tr_remark"
                       // if ($trTimeslots != "")       : $trSpecialRemark  .= "\nTageszeit: " . $trTimeslots    . "\n----------"; endif;
                       if ($trOrderType != "")       : $trSpecialRemark  .= "\nOrder-Typ: " . $trOrderType    . "\n----------"; endif;
                       if ($trDeliveryInfo != "")    : $trSpecialRemark  .= "\nAuslieferinformationen: " . $trDeliveryInfo . "\n----------"; endif;
                       if ($trFlagServiceDoc == "1") : $trSpecialRemark  .= "\nINSTRUKTIONEN EXISTIEREN! "        . "\n----------"; endif;
                       if ($trDocumentsURL != "")    : $trSpecialRemark .= "\nOrder-Typ: " . $trDocumentsURL . "\n----------"; endif;
                       
                       $debugOut .= "STATION SERVICES<br>\n";
                       $debugOut .= "trTimeslots: " . $trTimeslots . "<br>\n";
                       $debugOut .= "trTimesunits: " . $trTimesunits . "<br>\n";
                       $debugOut .= "trShipmentMode: " . $trShipmentMode . "<br>\n";
                       $debugOut .= "trOrderType: " . $trOrderType . "<br>\n";
                       $debugOut .= "trDeliveryInfo: " . $trDeliveryInfo . "<br>\n";
                       $debugOut .= "trFlagServiceDoc: " . $trFlagServiceDoc . "<br>\n";
                       $debugOut .= "trDocumentsURL: " . $trDocumentsURL . "<br>\n";
                
                       // ADD HERE "jobcalculator"
                       // .... (!!!!) ........................................
                
                       // ADD HERE "genericdatacontainer"
                       // .... (!!!!) ........................................

                       // Generation parts of the field "jb_tourdata" (e.g.: "04109;04316|Leipzig;Leipzig/Mölkau|DE;DE")
                       if ($j > 0) :
                          $jbTourdataZipcode .= ";";
                          $jbTourdataCity .= ";";
                          $jbTourdataCountry .= ";";
                       endif;
                       $jbTourdataZipcode .= $trZipcode;
                       $jbTourdataCity .= $trCity;
                       $jbTourdataCountry .= $trCountry;

                       if ($debug) :
                          echo "TOUR.defaultFieldArray:<br>";
                          print_r($defaultFieldArray); echo "\n\n<br><br>";
                       endif;

                       // Update
                       if ($doUpdate && count($defaultFieldArray) > 0):
                          // Update data in "tour"
                          updateStmt("tour", "jb_id", $jbId, $defaultFieldArray, "tr_sort = '" . $trSort . "'");
                       endif;
                   endfor;
                endif;

                // Update job tour data string 
                if ($doUpdate) :
                   // Generation of the field "jb_tourdata" (e.g.: "04109;04316|Leipzig;Leipzig/Mölkau|DE;DE")
                   $jbTourdata = $jbTourdataZipcode . "|" . $jbTourdataCity . "|" . $jbTourdataCountry;                   
                   updateStmt("job", "jb_id", $jbId, array("jb_tourdata",$jbTourdata));
                endif;

                if ($doUpdate) :
                   TA("C");
                else :
                   TA("R");
                endif;
                TA("E");

                if ($doUpdate) :
                   // Generate prices
                   $makePrice = true;
                   if ($makePrice) :
//                    mk_jb_price($jbIdNew);
                   endif;

                   // Generate invoice text
                   if ($globalParUseRelatedCustomer == "1") :
                     // .............
                   else :
//                    mk_jb_invtext($jbId, false);
//                    updateStmt("job", "jb_id", $jbId, array("jb_tourdata",$jbTourdata));  // Again because of anomalie
                   endif;
                endif;

             else :
                $xmlOrderData .= "<op_code>" . "102" . "</op_code>";
                $xmlOrderData .= "<op_msg>" . getLngt("Der Auftrag passt nicht zu den Authentifizierungsdaten!") . "</op_msg>";
             endif;
          else :
             $xmlOrderData .= "<op_code>" . "101" . "</op_code>";
             $xmlOrderData .= "<op_msg>" . getLngt("Der " . ($jbIsOperational ? "operative " : "") . "Auftrag ist nicht existent!") . "</op_msg>";
          endif;
          
          $xmlOrderData .= "</order>";
      endfor;
      $xmlOrderData .= "</order_data>";

   else :

      $dataFields = convertSpecial($orderDataArray["xml"]["order_data"]["data_fields"]);
      $dataFieldArray = explode("|", $dataFields);
      $dataFieldArrayLen = count($dataFieldArray);

      $gotTourData = false;         // Get data from table "tour" if needed
      $gotTourarticleData = false;  // Get data from table "tourarticle" if needed

      if ($debug) :
         print_r($orderNumberArray); echo "\n\n<br><br>";
         echo $orderNumberArrayLen . "<br><br>";
         print_r($dataFieldArray); echo "\n\n<br><br>";
         echo $dataFieldArrayLen . "<br><br>";
      endif;

      // Iterate array
      $xmlOrderData .= "<order_data>";
      for ($i = 0; $i < $orderNumberArrayLen; $i++) :

          $xmlOrderData .= "<order>";

          $jbIdOrg = $orderNumberArray[$i];
          $xmlOrderData .= "<order_no>" . $jbIdOrg . "</order_no>";

          // First check valid association between authenticated customer and requested job(s) !!!!
          // $cscIdPayer = $dbData["job"]["csc_id_payer"];
          $cscIdPayer = getFieldValueFromId("job","jb_id",$jbIdOrg,"csc_id_payer");
          $csIdPayer = getFieldValueFromId("costcenter","csc_id",$cscIdPayer,"cs_id");

          // Get operational job of requested job (!!!!)
          if ($isOperationalOrderArrayLen > 0 && ($isOperationalOrderArray[$i] == "" || $isOperationalOrderArray[$i] == "0")) :
             // Search for operational job by FDS job
             $tmpValue = getFieldValueFromClause("phoenix.genericdatacontainer","gdc_content","gdc_obj_type = 'jb' AND gdc_gen_fieldname = 'is_operative' AND gdc_obj_id = '" . $jbIdOrg . "'");
             $tmpArray = explode("|", $tmpValue);
             $jbId = $tmpArray[0];
          else :
             // Take operational job (classic mode)
             $jbId = $jbIdOrg;
          endif;
          $xmlOrderData .= "<order_op_no>" . $jbId . "</order_op_no>";

          if ($jbId != "" && is_numeric($jbId)) :

             getDBData("job", $jbId);
             if ($debug) : print_r($dbData); echo "\n\n<br><br>"; endif;

             $xmlOrderData .= "<fields>";
             if ($csIdPayer == $csId) :

                for ($j = 0; $j < $dataFieldArrayLen; $j++) :

                    $fieldName = $dataFieldArray[$j];

                    // Get data from table "tour" if needed
                    if (!$gotTourData && substr($fieldName,0,3) == "tr_") :
                       getDBData("tour", $jbId);
                       $gotTourData = true;
                       if ($debug) : print_r($dbData); echo "\n\n<br><br>"; endif;
                    endif;
                    // Get data from table "tourarticle" if needed
                    if (!$gotTourarticleData && substr($fieldName,0,5) == "trat_") :
                       getDBData("tourarticle", $jbId);
                       $gotTourData = true;
                       if ($debug) : print_r($dbData); echo "\n\n<br><br>"; endif;
                    endif;

                    if (substr($fieldName,0,3) == "tr_") :
                       // "TOUR"
                       $dbDataTourLen = count($dbData["tour"]);

                       $xmlOrderData .= "<field>";                       
                       $xmlOrderData .= "<field_name><![CDATA[" . $fieldName . "]]></field_name>";
                       for ($k = 1; $k <= $dbDataTourLen; $k++) :
                           $fieldVal = $dbData["tour"][$k][$dataFieldArray[$j]];

                           $xmlOrderData .= "<station>";
                           $xmlOrderData .= "<no>" . $k . "</no>";
                           $xmlOrderData .= "<field_value><![CDATA[" . $fieldVal . "]]></field_value>";
                           $xmlOrderData .= "</station>";
                       endfor;
                       $xmlOrderData .= "</field>";

                    elseif (substr($fieldName,0,5) == "trat_") :
                       // "TOURARTICLE"
                       
                    else :
                       // "JOB" (default)
                       $fieldVal = $dbData["job"][$dataFieldArray[$j]];

                       if ($fieldName == "vht_id" || $fieldName == "vht_id_real") :
                          $fieldVal = getFieldValueFromClause("phoenix.metatype","mt_value","mt_type = 'vehicletype' AND mt_sort = '" . $fieldVal . "'");
                       endif;
                       
                       if ($fieldName == "search_contractors") :
                          $adId = getFieldValueFromClause("phoenix.tour","ad_id","jb_id = '" . $jbId . "' AND tr_sort = '1'");
                          if ($adId != "" && is_numeric($adId) && $adId > 0) :
                             $adZipcode = getFieldValueFromId("phoenix.address","ad_id",$adId,"ad_zipcode");
                             $currentAreaCourierArray = getCourierByRanking($adZipcode, "0101000000", $jbId, "", $hqId);
                             
                             // $fieldVal  = 
                             // $fieldVal .= 
                          endif;
                       endif;

                       $xmlOrderData .= "<field>";
                       $xmlOrderData .= "<field_name><![CDATA[" . $fieldName . "]]></field_name>";
                       $xmlOrderData .= "<field_value><![CDATA[" . $fieldVal . "]]></field_value>";
                       $xmlOrderData .= "</field>";
                    endif;
                endfor;
             else :

                $xmlOrderData .= "<field>";
                $xmlOrderData .= "<field_name><![CDATA[" . "ERR" . "]]></field_name>";
                $xmlOrderData .= "<field_value><![CDATA[" . "NOT_AUTHENTICATED" . "]]></field_value>";
                $xmlOrderData .= "</field>";
             endif;
             $xmlOrderData .= "</fields>";
          else :

             $xmlOrderData .= "<fields>";
             $xmlOrderData .= "<field>";
             $xmlOrderData .= "<field_name><![CDATA[" . "ERR" . "]]></field_name>";
             $xmlOrderData .= "<field_value><![CDATA[" . "NO_OPERATIVE_TOUR_FOUND" . "]]></field_value>";
             $xmlOrderData .= "</field>";             
             $xmlOrderData .= "</fields>";
          endif;

          $xmlOrderData .= "</order>";
      endfor;
      $xmlOrderData .= "</order_data>";

      if ($debug) :
         echo "RESPONSE: <br>" . $xmlOrderData . "<br><br>";
      endif;
   endif;

else :
  // Authentication data not ok
  $err[] = array("101", getLngt("Die Authentifizierungsdaten sind nicht in Ordnung."));
endif;
// print_r($err);

// Check existence of at least one error
$errLen = count($err);

// Output
$orderDataResponse .= "<xml>";   
if ($errLen > 0) :
   orderDataRequestLogFile("ERRORS", 1);
   $orderDataResponse .= "<state>NOT OK</state>";
   $orderDataResponse .= "<errors>";
   for ($i = 0; $i < $errLen; $i++) :
       $orderDataResponse .= "<error>";
       $orderDataResponse .= "<err_no>" . $err[$i][0] . "</err_no>";
       $orderDataResponse .= "<err_desc><![CDATA[" . mcEncode($err[$i][1]) . "]]></err_desc>";
       $orderDataResponse .= "</error>";
       if ($debug) :
          $orderDataResponse .= "<debug>" . $debugOut . "</debug>";
       endif;
       orderDataRequestLogFile($err[$i][0] . " : " . mcEncode($err[$i][1]), 1);
   endfor;
   $orderDataResponse .= "</errors>";
else :
   $orderDataResponse .= "<state>OK</state>" . $xmlOrderData;
   if ($debug) :
      $orderDataResponse .= "<debug>" . $debugOut . "</debug>";
   endif;
endif;
$orderDataResponse .= "</xml>";

// Log entries
orderDataRequestLogFile($orderDataResponse);    // Write response into log
orderDataRequestLogFile("___________________________________________________________________________________");

// Return output
echo $orderDataResponse;



/*
// REQUEST
<xml>
  <order_data>                                         // Request for all orderData of the customer
    <auth>                                             // Object (e.g. customer [default]) to be authenticated
      <auth_type>...</auth_type>                       // Object type ("cs" [or "empty"] = customer, "cr" = contractor, etc.).
      <auth_id>...</auth_id>                           // Object ID (internal ID) regarding the type
      <auth_eid>...</auth_eid>                         // Object EID (unique) regarding the type
      <customer>...</customer>                         // Kundennummer (EID) {"STBxxxxxx", ...} => csc_id_payer
      <account>...</account>                           // Eingetragener Benutzer für den Kunden => cs.cs_admin => emp.emp_id => emp.usr_id => usr.usr_id => usr.usr_account
      <password>...</password>                         // Passwort für den Benutzer             => usr.usr_password
      <session_id>...</session_id>                     // Zusätzliche Session-ID, die mit dem Kunden ausgehandelt wurde   [mandatory]
      <costcenter_name>...</costcenter_name>           // Kostenstellenname {"abcd", "efgh", ...} => Mapping csc_id   [optional]
      <group_no>...</group_no>                         // Nummer der Kundengruppe (Bei einer automatischen Preisfindung muss entweder <group_no> oder <group_name> gesetzt sein)
      <group_name>...</group_name>                     // Name der Kundengruppe (Bei einer automatischen Preisfindung muss entweder <group_name> oder <group_no> gesetzt sein)
    </auth>                                            
                                                       
    <debug_on>...</debug_on>                           // Activates debug output ("ON" or "YES")
                                                       
    <operation>GET|SET</operation>                     // Operation (GET or SET costcenter(s), default is "GET" if emty tag)

    <order_numbers><![CDATA[....]]></order_numbers>    // List of votian order numbers "17310234|17310296|17310242|...."
    <is_operative><![CDATA[....]]></is_operative>      // List of flags "0|0|1|...." being an operational order, corresponding with order number in TAG <order_numbers>
    <data_fields><![CDATA[....]]></data_fields>        // List of data fields like "vh_id_real|jb_finishtime|...."
    
    <list_jb_status><![CDATA[....]]></list_jb_status>  // List of order states "0|0|1|...." of each order, corresponding with order number in TAG <order_numbers>
                                                       // [Order states: 0 = open | 1 = taken | 2 = finished | 9 = to be reassigned manually | 8 = automatic assignment]
    <list_cr_id>...</list_cr_id>                       // List of courier IDs of each order, corresponding with order number in TAG <order_numbers>
    <list_crvh_id>...</list_crvh_id>                   // List of vehicle IDs of each order, corresponding with order number in TAG <order_numbers>
    <list_inv_no>...</list_inv_no>                     // List of invoice numbers of each order, corresponding with order number in TAG <order_numbers>

    <job>                                              // "job" equals "order" ;-)
      <jb_tourname></jb_tourname>                      // Optional tour name

      <jb_weight></jb_weight>                          // Restriction for weight regarding the vehicle types to be disposed
      <jb_crvh_length></jb_crvh_length>                // Restriction for length....
      <jb_crvh_width></jb_crvh_width>                  // Restriction for width....
      <jb_crvh_height></jb_crvh_height>                // Restriction for height....
      <jb_crvh_position></jb_crvh_position>            // Restriction for positions....

      <jb_ordertime></jb_ordertime>                    // (New) order time of the job
      <jb_warningtime></jb_warningtime>                // (New) warning time the job has to be finished
     
      <jb_cr_filter></jb_cr_filter>                    // Optional filter (regarding restrictions for [automatic] disposition)

      <jb_totalprice></jb_totalprice>                  // Price of the job [needed for statistic requests]

      <jb_freetext_1></jb_freetext_1>                  // Freetext field containing the job remark of the order request
      
      <jb_cr_remark></jb_cr_remark>                    // Freetext for courier remark
      ....
    </job>

    <stations>
      <station>
        <tr_comp></tr_comp>                            // Company name
        <tr_comp2></tr_comp2>                          // Company name

        <ad_street></ad_street>                        // Street
        <ad_zipcode></ad_zipcode>                      // Zipcode
        <ad_city></ad_city>                            // City
        <ad_country></ad_country>                      // Country (wenn leer, dann "DE")

        <tr_hsno></tr_hsno>                            // House number
        <tr_floor></tr_floor>                          // Floor
        <tr_remark></tr_remark>                        // Station remark
        <tr_person></tr_person>                        // Person for special contact
        <tr_phone></tr_phone>                          // Station phone number
        ....                                           // MORE FIELDS PRESENTLY NOT RELEVANT
      </station>
      <station>
        ....
      </station>
      ....
    </stations>
  </order_data>
</xml>


// RESPONSE for GET
<xml>
  <state>OK</state>

  <order_data>

    <order>                                   // Single order
      <order_no>....</order_no>               // votian (requested) order number
      <order_op_no>....</order_op_no>         // votian operational order number with real vehicle id
      <fields>
        <field>
          <field_name>....</field_name>       // (Requested) field name
          <field_value>....</field_value>     // Field value
        </field>
        
        <field>
          ....
        </field>
      </fields>
    </order>
    
    <order>                                   // Next single order
      ....
    </order>

  </order_data>
</xml>


// RESPONSE for SET
<xml>
  <state>OK</state>

  <order_data>

    <order>                                   // Single order
      <order_no>....</order_no>               // votian (requested) order number
      <order_op_no>....</order_op_no>         // votian operational order number with real vehicle id

                                              // In case of request for changing state
      <op_code>....</op_code>                 // Empty or "0" or "ok" <=> Ok, state has been changed | >"0" <=> state has NOT been changed
      <op_msg><![CDATA[....]]</op_msg>        // Message: In case of success empty or "OK" | In case of failure specified message

    </order>
    
    <order>                                   // Next single order
      ....
    </order>

  </order_data>
</xml>
*/
?>

