<?php
/*=======================================================================
 *
 * inc_history.inc.php
 *
 * Autor: Marc Vollmann
 *
 =======================================================================*/



function postParseCsHistory ($textToParse, $checkDifferences = false) {
	global $historyEmpRightArr;
  $textToParse = trim($textToParse);

  if ($textToParse != "") :

     // Init
     if ($checkDifferences) :
        $colorHead = "f8np1_blue";
        $colorDiff = "f8np1_darkgreen";
     endif;
     // Customer
     $preCsLogoDescriptionArr = array();
     // Costcenter addresses
     $preCscLogoDescriptionArr = array();
     $preCscLogoDescriptionArr[1] = array();  // "Leistungsanschrift"
     $preCscLogoDescriptionArr[2] = array();  // "Rechnungsanschrift"
     $preCscLogoDescriptionArr[3] = array();  // Empty
     $preCscLogoDescriptionArr[4] = array();  // "Abhol-/Lieferadresse"

     // Iterate ALL occurrences of "<postparser>...</postparser>"          
     while (!(strpos($textToParse, "<postparser>") === FALSE)) {
     
        $beginTagPosBegin = strpos($textToParse, "<postparser>");
        $beginTagPosEnd = $beginTagPosBegin + 12;
        $endTagPosBegin = strpos($textToParse, "</postparser>");
        $endTagPosEnd = $endTagPosBegin + 13;
     
        if ($beginTagPosEnd < $endTagPosBegin) :
           $tagContent = substr($textToParse, $beginTagPosEnd, $endTagPosBegin - $beginTagPosEnd);

           if ($tagContent != "") :
              $logoDescriptionArray = getKeyValueArrayFromString($tagContent);
              $tagContent = "";

              $keyArr = array("STATUS_VISIBILITY","STATUS_VISIBILITY","STATUS_AUTHENTICATION","STATUS_AUTHENTICATION",
                              "CSC_ID","CSC_NAME","CSC_NAME_NEW","ADT_ID","INTERVAL","ADDRESS","STATUS_MODIFIED","STATUS_NEW");
              $keyArrLen = count($keyArr);
              for ($i = 0; $i < $keyArrLen; $i++) :
                  mcArrIsSet($logoDescriptionArray, $keyArr[$i]);
              endfor;

              // Special treatment
              if (isset($logoDescriptionArray["STATUS_VISIBILITY"]) && $logoDescriptionArray["STATUS_VISIBILITY"] == "1") : 
                 $tagContent .= "&nbsp;" . getLngt("sichtbar") . "<br>";
              endif;
              if (isset($logoDescriptionArray["STATUS_VISIBILITY"]) && $logoDescriptionArray["STATUS_VISIBILITY"] == "0") : 
                 $tagContent .= "&nbsp;" . getLngt("ausgeblendet") . "<br>";
              endif;              
              if (isset($logoDescriptionArray["STATUS_AUTHENTICATION"]) && $logoDescriptionArray["STATUS_AUTHENTICATION"] == "1") : 
                 $tagContent .= "&nbsp;" . getLngt("freigegeben") . "<br>";
              endif;
              if (isset($logoDescriptionArray["STATUS_AUTHENTICATION"]) && $logoDescriptionArray["STATUS_AUTHENTICATION"] == "0") : 
                 $tagContent .= "&nbsp;" . getLngt("gesperrt") . "<br>";
              endif;
              if (isset($logoDescriptionArray["CSC_NAME"]) && $logoDescriptionArray["CSC_NAME"] != "") : 
                 $tagContent .= "&nbsp;" . getLngt("Kostenstelle:") . " " . "<span class=\"" . $colorHead . "\"><b>" . $logoDescriptionArray["CSC_NAME"] . "</span><br>";
              endif;
              if (isset($logoDescriptionArray["CSC_ID"]) && $logoDescriptionArray["CSC_ID"] != "" && $logoDescriptionArray["CSC_NAME"] == "") : 
                 $cscName = getFieldValueFromId("costcenter", "csc_id", $logoDescriptionArray["CSC_ID"], "csc_name");
                 $tagContent .= "&nbsp;" . getLngt("Kostenstelle:") . " " . "<span class=\"" . $colorHead . "\"><b>" . $cscName . "</b></span><br>";
              endif;
              if (isset($logoDescriptionArray["CSC_NAME_NEW"]) && $logoDescriptionArray["CSC_NAME_NEW"] != "") : 
                 $tagContent .= "&nbsp;" . getLngt("Neuer Kst.-Name:") . $logoDescriptionArray["CSC_NAME_NEW"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["ADT_ID"]) && $logoDescriptionArray["ADT_ID"] != "") : 
                 if ($logoDescriptionArray["ADT_ID"] == "1") : 
                    $adtId = getLngt("Postanschrift");
                 elseif ($logoDescriptionArray["ADT_ID"] == "2") :
                    $adtId = getLngt("Rechnungsanschrift");
                 elseif ($logoDescriptionArray["ADT_ID"] == "3") :
                    $adtId = getLngt("Rechnungsversandanschrift");
                 elseif ($logoDescriptionArray["ADT_ID"] == "4") :
                    $adtId = getLngt("Abhol-/Lieferadresse");
                 endif;
                 $tagContent .= "&nbsp;" . getLngt("Adresstyp:") . " " . "<span class=\"" . $colorHead . "\"><b>" . $adtId . "</b></span><br>";
              endif;
              if (isset($logoDescriptionArray["INTERVAL"]) && $logoDescriptionArray["INTERVAL"] != "") : 
                 if ($logoDescriptionArray["INTERVAL"] == "0") : 
                    $interval = getLngt("Tägliche Fakturierung");
                 elseif ($logoDescriptionArray["INTERVAL"] == "1") :
                    $interval = getLngt("Wöchentliche Fakturierung");
                 elseif ($logoDescriptionArray["INTERVAL"] == "2") :
                    $interval = getLngt("Dekadische Fakturierung");
                 elseif ($logoDescriptionArray["INTERVAL"] == "3") :
                    $interval = getLngt("Vierzehntägige Fakturierung");
                 elseif ($logoDescriptionArray["INTERVAL"] == "4") :
                    $interval = getLngt("Monatliche Fakturierung");
                 endif;
                 $tagContent .= "&nbsp;" . getLngt("Adresstyp:") . " " . $interval . "<br>";
              endif;
              /*
              if (isset($logoDescriptionArray["ADDRESS"]) && $logoDescriptionArray["ADDRESS"] != "") :
                 $tagContent .= "- " . getLngt("Adresse:") . " " . $logoDescriptionArray["ADDRESS"] . "<br>";
              endif;
              */
              if (isset($logoDescriptionArray["ADDRESS"]) && $logoDescriptionArray["ADDRESS"] != "") :
                 mcArrIsSet($preCscLogoDescriptionArr[$logoDescriptionArray["ADT_ID"]], $logoDescriptionArray["CSC_ID"], array());                 
                 $valCscAddressArr = array();
                 $valCscAddressArr[1] = array();  // "Leistungsanschrift"
                 $valCscAddressArr[2] = array();  // "Rechnungsanschrift"
                 $valCscAddressArr[3] = array();  // Empty
                 $valCscAddressArr[4] = array();  // "Abhol-/Lieferadresse"
                 mcArrIsSet($valCscAddressArr[$logoDescriptionArray["ADT_ID"]], $logoDescriptionArray["CSC_ID"], array());
                 $valCscAddressArr[$logoDescriptionArray["ADT_ID"]][$logoDescriptionArray["CSC_ID"]] = explode(";", $logoDescriptionArray["ADDRESS"]);
                 $valCscAddressArrLen = count($valCscAddressArr[$logoDescriptionArray["ADT_ID"]][$logoDescriptionArray["CSC_ID"]]);
                 // Key arrays (text and display state)
                 $historyKeyTextArray_STATUS_MODIFIED = array();
                 $historyKeyActiveArray_STATUS_MODIFIED = array();
                 $tmpKeyText = getParameterValue("0", "HISTORY_CSC_ADDRESS_MODIFIED_KEYTEXT", "0");
                 if ($tmpKeyText != "") :
                    $historyKeyTextArray_STATUS_MODIFIED = explode(";", $tmpKeyText);
                    $historyKeyActiveArray_STATUS_MODIFIED = explode(";", getParameterValue("0", "HISTORY_CSC_ADDRESS_MODIFIED_KEYACTIVE", "0"));
                 endif;
                 if (count($historyKeyTextArray_STATUS_MODIFIED) == 0) :
                    $tagContent .= "" . $logoDescriptionArray["ADDRESS"] . "<br>";
                 else :
                    // Check differences
                    $diffCscArr = array();
                    if ($checkDifferences && count($preCscLogoDescriptionArr[$logoDescriptionArray["ADT_ID"]][$logoDescriptionArray["CSC_ID"]]) > 0) :
                       $diffCscArr = array_diff_assoc($valCscAddressArr[$logoDescriptionArray["ADT_ID"]][$logoDescriptionArray["CSC_ID"]], $preCscLogoDescriptionArr[$logoDescriptionArray["ADT_ID"]][$logoDescriptionArray["CSC_ID"]]);
                    endif;
                    $tmpOut = "<table>";
                    for ($i = 0; $i < $valCscAddressArrLen; $i++) :
                        $tmpKey = $historyKeyTextArray_STATUS_MODIFIED[$i]; 
                        $tmpVal = $valCscAddressArr[$logoDescriptionArray["ADT_ID"]][$logoDescriptionArray["CSC_ID"]][$i];
                        if ($historyKeyActiveArray_STATUS_MODIFIED[$i] == "1") :
                           $tmpKey = getLngt($tmpKey);
                           $valChanged = false;
                           if (array_key_exists($i, $diffCscArr)) :
                              $tmpKey = "<span class=\"" . $colorDiff . "\"><b>" . $tmpKey . "</b></span>";
                              $tmpVal = "<span class=\"" . $colorDiff . "\"><b>" . $tmpVal . "</b></span>";
                              $valChanged = true;
                           endif;
                           $tmpOut .= "<tr class=\"" . ($valChanged ? "state_changed" : "state_not_changed") . "\" style=\"vertical-align: top;\"><td>" . $tmpKey . ":</td><td>" . $tmpVal . "</td></tr>";
                        endif;
                    endfor;
                    // Add filter
                    if ($logoDescriptionArray["FILTER"] != "") :
                       $tmpFilter = substr($logoDescriptionArray["FILTER"], 1, -1);
                       $tmpFilter = my_str_replace ($tmpFilter, ",", "<br>", "5");
                       $tmpOut .= "<tr style=\"vertical-align: top;\"><td>" . getLngt("Filter") . ":</td><td>" . $tmpFilter . "</td></tr>";
                    endif;
                    $tmpOut .= "</table><br>";
                    $tagContent .= $tmpOut;

                    if ($checkDifferences) :
                       $preCscLogoDescriptionArr[$logoDescriptionArray["ADT_ID"]][$logoDescriptionArray["CSC_ID"]] = $valCscAddressArr[$logoDescriptionArray["ADT_ID"]][$logoDescriptionArray["CSC_ID"]];
                    endif;
                 endif;
              endif;
              /*
              if (isset($logoDescriptionArray["STATUS_MODIFIED"]) && $logoDescriptionArray["STATUS_MODIFIED"] != "") : 
                 $tagContent .= "" . $logoDescriptionArray["STATUS_MODIFIED"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["STATUS_NEW"]) && $logoDescriptionArray["STATUS_NEW"] != "") : 
                 $tagContent .= "" . $logoDescriptionArray["STATUS_NEW"] . "<br>";
              endif;
              */
              if (isset($logoDescriptionArray["STATUS_NEW"]) && $logoDescriptionArray["STATUS_NEW"] != "" || $logoDescriptionArray["STATUS_MODIFIED"] != "") :
                 $valCsArr = explode(";", $logoDescriptionArray["STATUS_MODIFIED"]);
                 $valCsArrLen = count($valCsArr);

                 // Key arrays (text and display state)
                 $historyKeyTextArray_STATUS_MODIFIED = array();
                 $historyKeyActiveArray_STATUS_MODIFIED = array();
                 $tmpKeyText = getParameterValue("0", "HISTORY_CS_STATUS_MODIFIED_KEYTEXT", "0");
                 if ($tmpKeyText != "") :
                    $historyKeyTextArray_STATUS_MODIFIED = explode(";", $tmpKeyText);
                    $historyKeyActiveArray_STATUS_MODIFIED = explode(";", getParameterValue("0", "HISTORY_CS_STATUS_MODIFIED_KEYACTIVE", "0"));
                 endif;

                 if (count($historyKeyTextArray_STATUS_MODIFIED) == 0) :
                    $tagContent .= "" . $logoDescriptionArray["STATUS_MODIFIED"] . "<br>";
                 else :
                    // Check differences
                    $diffCsArr = array();
                    if ($checkDifferences && count($preCsLogoDescriptionArr) > 0) :
                       $diffCsArr = array_diff_assoc($valCsArr, $preCsLogoDescriptionArr);
                    endif;
                    $tmpOut = "<table>";
                    for ($i = 0; $i < $valCsArrLen; $i++) :
                        $tmpKey = mcArrIsSet($historyKeyTextArray_STATUS_MODIFIED, $i);
                        $tmpVal = mcArrIsSet($valCsArr, $i);
                        if ($historyKeyActiveArray_STATUS_MODIFIED[$i] == "1") :
                           if ($i == "12") :
                              if ($tmpVal == "0") :
                                 $tmpVal = getLngt("Kilometer");
                              elseif ($tmpVal == "1") :
                                 $tmpVal = getLngt("PLZ");
                              elseif ($tmpVal == "2") :
                                 $tmpVal = getLngt("Bereich");
                              elseif ($tmpVal == "3") :
                                 $tmpVal = getLngt("Radius");
                              endif;
                           elseif ($i == "16") :
                              $tmpVal = ($tmpVal == "0" ? getLngt("Rechnung") : getLngt("Einzug"));
                           elseif ($i == "38" || $i == "42") :
                              // Drittzahler / Metakunde
                              $tmpVal = getFieldValueFromId("customer", "cs_id", $tmpVal, "cs_eid");
                           elseif ($i == "40") :
                              // Steuer-ID
                              $tmpVal = getFieldValueFromId("tax", "tx_id", $tmpVal, "tx_value");
                           elseif ($i == "41") :
                              // Branchen-ID
                              $tmpVal = getFieldValueFromId("branch", "br_id", $tmpVal, "br_name");
                           elseif ($i == "81") :
                              // Report-Intervall
                              if ($tmpVal == "0") :
                                 $tmpVal = getLngt("monatlich");
                              elseif ($tmpVal == "1") :
                                 $tmpVal = getLngt("quartalsweise");
                              elseif ($tmpVal == "2") :
                                 $tmpVal = getLngt("jährlich");
                              endif;                              
                           elseif ($i == 19 || $i == 21 || $i == 22 || $i == 23 || $i == 24 || $i == 43 || $i == 44 || 
                                   $i == 45 || $i == 46 || $i == 50 || $i == 53 || $i == 54 || $i == 55 || $i == 63 || 
                                   $i == 70 || $i == 71 || $i == 72 || $i == 73 || $i == 77) :
                              // ["1" <=> "Yes", "0" <=> "No"]
                              $tmpVal = ($tmpVal == "1" ? getLngt("Ja") : getLngt("Nein"));
                           elseif ($i == 0 || $i == 26) :
                              // ["0" <=> "Yes", "1" <=> "No"]
                              $tmpVal = ($tmpVal == "1" ? getLngt("Nein") : getLngt("Ja"));
                           endif;
                           $tmpKey = getLngt($tmpKey);
                           $valChanged = false;
                           if (array_key_exists($i, $diffCsArr)) :
                              $tmpKey = "<span class=\"" . $colorDiff . "\"><b>" . $tmpKey . "</b></span>";
                              $tmpVal = "<span class=\"" . $colorDiff . "\"><b>" . $tmpVal . "</b></span>";
                              $valChanged = true;
                           endif;
                           $tmpOut .= "<tr class=\"" . ($valChanged ? "state_changed" : "state_not_changed") . "\" style=\"vertical-align: top;\"><td>" . $tmpKey . ":</td><td>" . $tmpVal . "</td></tr>";
                        endif;
                    endfor;
                    // Add filter
                    if (isset($logoDescriptionArray["FILTER"]) && $logoDescriptionArray["FILTER"] != "") :
                       $tmpFilter = substr($logoDescriptionArray["FILTER"], 1, -1);
                       $tmpFilter = my_str_replace ($tmpFilter, ",", "<br>", "5");
                       $tmpOut .= "<tr style=\"vertical-align: top;\"><td>" . getLngt("Filter") . ":</td><td>" . $tmpFilter . "</td></tr>";
                    endif;
                    $tmpOut .= "</table><br>";
                    $tagContent .= $tmpOut;
                    
                    if ($checkDifferences) :
                       $preCsLogoDescriptionArr = $valCsArr;
                    endif;
                 endif;
              endif;

              // Remove last "<br>"
              $tagContent = substr($tagContent, 0, -4);
           endif;

           // Substitute text fragment
           $textToParse = substr_replace($textToParse, $tagContent, $beginTagPosBegin, $endTagPosEnd - $beginTagPosBegin);
        endif;
      }
  endif;
  return $textToParse;  
}

function postParseCrHistory ($textToParse, $crSid, $checkDifferences = false) {
	global $historyEmpRightArr;
  $textToParse = trim($textToParse);

  if ($textToParse != "") :

     // Init
     if ($checkDifferences) :
        $colorHead = "f8np1_blue";
        $colorDiff = "f8np1_darkgreen";
     endif;
     if ($checkDifferences) :
        $preLogoDescriptionArr = array();
     endif;

     $tmpValuePre = array();
     $notChangedTextOut = "Keine Änderung!";

     // Iterate ALL occurrences of "<postparser>...</postparser>"          
     while (!(strpos($textToParse, "<postparser>") === FALSE)) {
     
        $beginTagPosBegin = strpos($textToParse, "<postparser>");
        $beginTagPosEnd = $beginTagPosBegin + 12;
        $endTagPosBegin = strpos($textToParse, "</postparser>");
        $endTagPosEnd = $endTagPosBegin + 13;

        if ($beginTagPosEnd < $endTagPosBegin) :
           $tagContent = substr($textToParse, $beginTagPosEnd, $endTagPosBegin - $beginTagPosEnd);

           if ($tagContent != "") :
              $logoDescriptionArray = getKeyValueArrayFromString($tagContent);
              $tagContent = "";

              $keyArr = array("ASSIGN_STATUS","ZIP_FREE_OLD","ZIP_FREE","ZIP_JOB","ZIP_REAL","LRANK","CASH_STATION","REASON","ZIPCODE",
                              "SID","STATUS_VISIBILITY","STATUS_AUTHENTICATION","MSISDN_OLD","MSISDN_NEW","STATUS_NEW",
                              "STATUS_MODIFIED","OBJ_TYPE","FILTER","STATUS_LOGOUT","PASSWORD","LOCATING","base","line",
                              "type","ver","BATTLEVEL","PWRSRC","DISPLAY_TO","LDA_ERR","comm");
              $keyArrLen = count($keyArr);
              for ($i = 0; $i < $keyArrLen; $i++) :
                  mcArrIsSet($logoDescriptionArray, $keyArr[$i]);
              endfor;

              // Special treatment
              if (isset($logoDescriptionArray["ASSIGN_STATUS"]) && $logoDescriptionArray["ASSIGN_STATUS"] == "RESERVED") : 
                 $tagContent .= "- Direkte Anforderung<br>";
              endif;
              if (isset($logoDescriptionArray["ASSIGN_STATUS"]) && $logoDescriptionArray["ASSIGN_STATUS"] == "FAVOURED") :
                 $tagContent .= "- Bevorzugt<br>";
              endif;
              if (isset($logoDescriptionArray["ASSIGN_STATUS"]) && $logoDescriptionArray["ASSIGN_STATUS"] != "") : 
                 if ($logoDescriptionArray["ASSIGN_STATUS"] == "AREA") : 
                    $tagContent .= "- " . getLngt("Hauptbereich") . "<br>";
                 elseif ($logoDescriptionArray["ASSIGN_STATUS"] == "NEIGHBOUR_AREA") :
                    $tagContent .= "- " . getLngt("Nachbarbereich") . "<br>";
                 elseif ($logoDescriptionArray["ASSIGN_STATUS"] == "NEIGHBOUR_AREA_2") :
                    $tagContent .= "- " . getLngt("2. Nachbarbereich") . "<br>";
                 elseif ($logoDescriptionArray["ASSIGN_STATUS"] == "NEIGHBOUR_AREA_3") :
                    $tagContent .= "- " . getLngt("3. Nachbarbereich") . "<br>";
                 elseif ($logoDescriptionArray["ASSIGN_STATUS"] == "NEIGHBOUR_AREA_4") :
                    $tagContent .= "- " . getLngt("4. Nachbarbereich") . "<br>";
                 elseif ($logoDescriptionArray["ASSIGN_STATUS"] == "NEIGHBOUR_AREA_5") :
                    $tagContent .= "- " . getLngt("5. Nachbarbereich") . "<br>";
                 elseif ($logoDescriptionArray["ASSIGN_STATUS"] == "NEIGHBOUR_AREA_6") :
                    $tagContent .= "- " . getLngt("6. Nachbarbereich") . "<br>";
                 elseif ($logoDescriptionArray["ASSIGN_STATUS"] == "NEIGHBOUR_AREA_7") :
                    $tagContent .= "- " . getLngt("7. Nachbarbereich") . "<br>";
                 endif;
              endif;
              if (isset($logoDescriptionArray["ZIP_FREE_OLD"]) && $logoDescriptionArray["ZIP_FREE_OLD"] != "") : 
                 $tagContent .= "- " . getLngt("Alte Freimeldung:") . " " . $logoDescriptionArray["ZIP_FREE_OLD"] . "<br>";
              endif;              
              if (isset($logoDescriptionArray["ZIP_FREE"]) && $logoDescriptionArray["ZIP_FREE"] != "") : 
                 $tagContent .= "- " . getLngt("Freimeldung:") . " " . $logoDescriptionArray["ZIP_FREE"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["ZIP_JOB"]) && $logoDescriptionArray["ZIP_JOB"] != "") : 
                 $tagContent .= "- " . getLngt("Auftrag:") . " " . $logoDescriptionArray["ZIP_JOB"] . "<br>";
              endif;
//              if (isset($logoDescriptionArray["ASSIGN_GPS"]) && $logoDescriptionArray["ASSIGN_GPS"] == "NO") :
              if (isset($logoDescriptionArray["LOCOLD"]) && $logoDescriptionArray["LOCOLD"] == "YES") :
                 $tagContent .= "- erfolgloser Ortungsversuch<br>";
              elseif (isset($logoDescriptionArray["ZIP_REAL"]) && $logoDescriptionArray["ZIP_REAL"] != "") : 
                 $tagContent .= "- " . getLngt("Ortung:") . " " . $logoDescriptionArray["ZIP_REAL"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["LRANK"]) && $logoDescriptionArray["LRANK"] == "YES") : 
                 $tagContent .= "- " . getLngt("Ranking verloren") . "<br>";
              elseif (isset($logoDescriptionArray["LRANK"]) && $logoDescriptionArray["LRANK"] == "NO") :
                 $tagContent .= "- " . getLngt("Ranking erhalten") . "<br>";
              endif;
              if (isset($logoDescriptionArray["STATE"]) && $logoDescriptionArray["STATE"] == "CR_SAME_COURIER") : 
                 $tagContent .= "- " . getLngt("Der Auftrag war bereits auf dem Gerät") . "<br>";
              endif;
              // if (isset($logoDescriptionArray["LOST_RANKING"]) && $logoDescriptionArray["LOST_RANKING"] == "YES") : 
              //    $tagContent .= "- Ranking verloren<br>";
              // elseif (isset($logoDescriptionArray["LOST_RANKING"]) && $logoDescriptionArray["LOST_RANKING"] == "NO") :
              //    $tagContent .= "- Ranking erhalten<br>";
              // endif;
              if (isset($logoDescriptionArray["CASH_STATION"]) && $logoDescriptionArray["CASH_STATION"] == "1") : 
                 $tagContent .= "- " . getLngt("Auf Barzahlung gesetzt") . "<br>";
              endif;
              if (isset($logoDescriptionArray["REASON"]) && $logoDescriptionArray["REASON"] == "LOGOUT") : 
                 $tagContent .= "- " . getLngt("Ordentlich beendet") . "<br>";
              endif;
              if (isset($logoDescriptionArray["REASON"]) && $logoDescriptionArray["REASON"] == "QUIT") : 
                 $tagContent .= "- " . getLngt("Client beendet ohne Ausloggen") . "<br>";
              endif;
              if (isset($logoDescriptionArray["REASON"]) && $logoDescriptionArray["REASON"] == "CONNLOST") : 
                 $tagContent .= "- " . getLngt("Verbindungsabbruch") . "<br>";
              endif;
              if (isset($logoDescriptionArray["REASON"]) && $logoDescriptionArray["REASON"] == "Driver_Occupied") : 
                 $tagContent .= "- " . getLngt("Fahrer besetzt") . "<br>";
              endif;
              if (isset($logoDescriptionArray["REASON"]) && $logoDescriptionArray["REASON"] == "Num_Of_Challenges_Reached") : 
                 $tagContent .= "- " . getLngt("Max. Anzahl Vermittlungsversuche erreicht") . "<br>";
              endif;
              if (isset($logoDescriptionArray["REASON"]) && $logoDescriptionArray["REASON"] == "No_Match_Vehicle_Type") : 
                 $tagContent .= "- " . getLngt("Fahrzeugtyp passt nicht") . "<br>";
              endif;
              if (isset($logoDescriptionArray["REASON"]) && $logoDescriptionArray["REASON"] == "Third_Country_Check") : 
                 $tagContent .= "- " . getLngt("Drittlandprüfung") . "<br>";
              endif;
              if (isset($logoDescriptionArray["REASON"]) && $logoDescriptionArray["REASON"] == "Quarantine_Check") : 
                 $tagContent .= "- " . getLngt("Quarantäneprüfung") . "<br>";
              endif;
              if (isset($logoDescriptionArray["REASON"]) && $logoDescriptionArray["REASON"] == "Nationality_Check") : 
                 $tagContent .= "- " . getLngt("Nationalitätenprüfung") . "<br>";
              endif;
              if (isset($logoDescriptionArray["ZIPCODE"]) && $logoDescriptionArray["ZIPCODE"] != "") : 
                 $tagContent .= "- " . getLngt("Rankingabfrage:") . " " . $logoDescriptionArray["ZIPCODE"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["SID"]) && $logoDescriptionArray["SID"] != "") : 
                 if ($crSid != "") :
                    $tmp = str_replace($crSid, "<span class=\"f8np1_red\">" . $crSid . "</span>", $logoDescriptionArray["SID"]);
                 else :
                    $tmp = $logoDescriptionArray["SID"];
                 endif;
                 $tagContent .= "- " . getLngt("Fahrzeuge:") . " " . $tmp . "<br>";
              endif;

              // Modifications by employees
              if (isset($logoDescriptionArray["STATUS_VISIBILITY"]) && $logoDescriptionArray["STATUS_VISIBILITY"] == "1") : 
                 $tagContent .= "- " . getLngt("sichtbar") . "<br>";
              endif;
              if (isset($logoDescriptionArray["STATUS_VISIBILITY"]) && $logoDescriptionArray["STATUS_VISIBILITY"] == "0") : 
                 $tagContent .= "- " . getLngt("ausgeblendet") . "<br>";
              endif;              
              if (isset($logoDescriptionArray["STATUS_AUTHENTICATION"]) && $logoDescriptionArray["STATUS_AUTHENTICATION"] == "1") : 
                 $tagContent .= "- " . getLngt("freigegeben") . "<br>";
              endif;
              if (isset($logoDescriptionArray["STATUS_AUTHENTICATION"]) && $logoDescriptionArray["STATUS_AUTHENTICATION"] == "0") : 
                 $tagContent .= "- " . getLngt("gesperrt") . "<br>";
              endif;
              if (isset($logoDescriptionArray["MSISDN_OLD"]) && $logoDescriptionArray["MSISDN_OLD"] != "") : 
                 $tagContent .= "- " . getLngt("Alte MSISDN:") . " " . $logoDescriptionArray["MSISDN_OLD"] . "<br>";
              endif;              
              if (isset($logoDescriptionArray["MSISDN_NEW"]) && $logoDescriptionArray["MSISDN_NEW"] != "") : 
                 $tagContent .= "- " . getLngt("MSISDN:") . " " . $logoDescriptionArray["MSISDN_NEW"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["STATUS_NEW"]) && $logoDescriptionArray["STATUS_NEW"] != "" || $logoDescriptionArray["STATUS_MODIFIED"] != "") :
                 $valArr = explode(";", $logoDescriptionArray["STATUS_MODIFIED"]);
                 $valArrLen = count($valArr);

                 // Key arrays (text and display state)
                 $historyKeyTextArray_STATUS_MODIFIED = array();
                 $historyKeyActiveArray_STATUS_MODIFIED = array();
                 if ((isset($logoDescriptionArray["OBJ_TYPE"]) && $logoDescriptionArray["OBJ_TYPE"] == "CRVH") || $valArrLen <= 31) :  // Length <= 31 <=> Compatible for old log entries of crvh changes
                    $tmpKeyText = getParameterValue("0", "HISTORY_CRVH_STATUS_MODIFIED_KEYTEXT", "0");
                    if ($tmpKeyText != "") :
                       $historyKeyTextArray_STATUS_MODIFIED = explode(";", $tmpKeyText);
                       $historyKeyActiveArray_STATUS_MODIFIED = explode(";", getParameterValue("0", "HISTORY_CRVH_STATUS_MODIFIED_KEYACTIVE", "0"));
                    endif;
                 else :
                    $tmpKeyText = getParameterValue("0", "HISTORY_CR_STATUS_MODIFIED_KEYTEXT", "0");
                    if ($tmpKeyText != "") :
                       $historyKeyTextArray_STATUS_MODIFIED = explode(";", $tmpKeyText);
                       $historyKeyActiveArray_STATUS_MODIFIED = explode(";", getParameterValue("0", "HISTORY_CR_STATUS_MODIFIED_KEYACTIVE", "0"));
                    endif;
                 endif;
                 if (count($historyKeyTextArray_STATUS_MODIFIED) == 0) :
                    $tagContent .= "" . $logoDescriptionArray["STATUS_MODIFIED"] . "<br>";
                 else :
                    // Check differences
                    if ($checkDifferences && count($preLogoDescriptionArr) > 0) :
                       $diffArr = array_diff_assoc($valArr, $preLogoDescriptionArr);
                    endif;
                    $tmpOut = "<table>";
                    if (isset($logoDescriptionArray["OBJ_TYPE"]) && $logoDescriptionArray["OBJ_TYPE"] == "CRVH") :
                       // CRVH
                       for ($i = 0; $i < $valArrLen; $i++) :
                           $tmpKey = isset($historyKeyTextArray_STATUS_MODIFIED[$i]) ? $historyKeyTextArray_STATUS_MODIFIED[$i] : "";
                           $tmpVal = $valArr[$i];
// echo $tmpKey . " : " . $tmpVal . "<br>";
                           if (!isset($tmpValuePre[$tmpKey])) :  // Structure for avoiding $notChangedTextOut
                              $tmpValuePre[$tmpKey] = "";
                           endif;
                           if (isset($historyKeyTextArray_STATUS_MODIFIED[$i]) && $historyKeyActiveArray_STATUS_MODIFIED[$i] == "1") :
                              if ($i == 0 || $i == 20 || $i == 30) :
                                 if ($i == 0) :
                                    $tmpMtValue = "vehicletype";
                                 elseif ($i == 20) :
                                    $tmpMtValue = "vehicle_ci";
                                 elseif ($i == 30) :
                                    $tmpMtValue = "drivetype";
                                 endif;
                                 $tmpVal = getFieldValueFromClause("metatype", "mt_value", "mt_type = '" . $tmpMtValue . "' AND mt_sort = '" . $tmpVal . "'");
                              elseif ($i == 17 || $i == 21 || $i == 28 || $i == 29) :
                                 // ["1" <=> "Yes", "0" <=> "No"]
                                 $tmpVal = ($tmpVal == "1" ? getLngt("Ja") : getLngt("Nein"));
                              elseif (false) :
                                 // ["0" <=> "Yes", "1" <=> "No"]
                                 $tmpVal = ($tmpVal == "1" ? getLngt("Nein") : getLngt("Ja"));
                              endif;
                              $tmpKey = getLngt($tmpKey);
                              $tmpKeyOut = $tmpKey;
                              $tmpValOut = $tmpVal;
                              $valChanged = false;
                              // if (isset($diffArr) && array_key_exists($i, $diffArr)) :
                              if (isset($diffArr) && array_key_exists($i, $diffArr) && $tmpVal != $tmpValuePre[$tmpKey] && $tmpVal != $notChangedTextOut && $tmpValuePre[$tmpKey] != $notChangedTextOut) :
                                 $tmpKeyOut = "<span class=\"" . $colorDiff . "\"><b>" . $tmpKey . "</b></span>";
                                 $tmpValOut = "<span class=\"" . $colorDiff . "\"><b>" . $tmpVal . "</b></span>";
                                 $valChanged = true;
                              endif;
                              $tmpOut .= "<tr class=\"" . ($valChanged ? "state_changed" : "state_not_changed") . "\" style=\"vertical-align: top;\"><td>" . $tmpKeyOut . ":</td><td>" . $tmpValOut . "</td></tr>";
                              if ($tmpVal != $notChangedTextOut) :  // Structure for avoiding $notChangedTextOut
                                 $tmpValuePre[$tmpKey] = $tmpVal;
                              endif;
                           endif;
                       endfor;
                       // Add filter
                       if (isset($logoDescriptionArray["FILTER"]) && $logoDescriptionArray["FILTER"] != "") :
                          $tmpFilterKey = getLngt("Filter");
                          $tmpFilterKeyOut = $tmpFilterKey;
                          $tmpFilterVal = substr($logoDescriptionArray["FILTER"], 1, -1);
                          $tmpFilterValOut = $tmpFilterVal;
                          $tmpFilterValOut = my_str_replace ($tmpFilterValOut, ",", "<br>", "5");
                          if (!isset($tmpFilterValPre)) : $tmpFilterValPre = $tmpFilterVal; endif;
                          $valFilterChanged = false;
                          if ($tmpFilterValPre != $tmpFilterVal) :
                             $tmpFilterKeyOut = "<span class=\"" . $colorDiff . "\"><b>" . $tmpFilterKey . "</b></span>";
                             $tmpFilterValOut = "<span class=\"" . $colorDiff . "\"><b>" . $tmpFilterValOut . "</b></span>";
                             $valChanged = true;
                          endif;
                          $tmpOut .= "<tr class=\"" . ($valChanged ? "state_changed" : "state_not_changed") . "\" style=\"vertical-align: top;\"><td>" . $tmpFilterKeyOut . ":</td><td>" . $tmpFilterValOut . "</td></tr>";
                          $tmpFilterValPre = $tmpFilterVal;
                       endif;
                    else :
                       // CR
                       for ($i = 0; $i < $valArrLen; $i++) :
                           mcArrIsSet($historyKeyTextArray_STATUS_MODIFIED, $i);
                           mcArrIsSet($valArr, $i);
                           mcArrIsSet($historyKeyActiveArray_STATUS_MODIFIED, $i);
                           $tmpKey = $historyKeyTextArray_STATUS_MODIFIED[$i]; 
                           $tmpVal = $valArr[$i];
                           if ($historyKeyActiveArray_STATUS_MODIFIED[$i] == "1") :
                              if ($i == "11") :
                                 if ($i == "11") :
                                    $tmpMtValue = "vehicletype";
                                 elseif ($i == "2222") :
                                    $tmpMtValue = "mt.mt_value";
                                 endif;
                                 $tmpVal = getFieldValueFromClause("metatype", "mt_value", "mt_type = '" . $tmpMtValue . "' AND mt_sort = '" . $tmpVal . "'");
                              elseif ($i == 37 || $i == 40 || $i == 44 || $i == 47) :
                                 // ["1" <=> "Yes", "0" <=> "No"]
                                 $tmpVal = ($tmpVal == "1" ? getLngt("Ja") : getLngt("Nein"));
                              elseif ($i == 0) :
                                 // ["0" <=> "Yes", "1" <=> "No"]
                                 $tmpVal = ($tmpVal == "1" ? getLngt("Nein") : getLngt("Ja"));
                              endif;
                              $tmpKey = getLngt($tmpKey);
                              $tmpKeyOut = $tmpKey;
                              $tmpValOut = $tmpVal;
                              $valChanged = false;
                              if (isset($diffArr) && array_key_exists($i, $diffArr)) :
                                 $tmpKeyOut = "<span class=\"" . $colorDiff . "\"><b>" . $tmpKey . "</b></span>";
                                 $tmpValOut = "<span class=\"" . $colorDiff . "\"><b>" . $tmpVal . "</b></span>";
                                 $valChanged = true;
                              endif;
                              $tmpOut .= "<tr class=\"" . ($valChanged ? "state_changed" : "state_not_changed") . "\" style=\"vertical-align: top;\"><td>" . $tmpKeyOut . ":</td><td>" . $tmpValOut . "</td></tr>";
                           endif;
                       endfor;
                       // Add filter
                       if (isset($logoDescriptionArray["FILTER"]) && $logoDescriptionArray["FILTER"] != "") :
                          $tmpFilterKey = getLngt("Filter");
                          $tmpFilterKeyOut = $tmpFilterKey;
                          $tmpFilterVal = substr($logoDescriptionArray["FILTER"], 1, -1);
                          $tmpFilterValOut = $tmpFilterVal;
                          $tmpFilterValOut = my_str_replace ($tmpFilterValOut, ",", "<br>", "5");
                          if (!isset($tmpFilterValPre)) : $tmpFilterValPre = $tmpFilterVal; endif;
                          $valFilterChanged = false;
                          if ($tmpFilterValPre != $tmpFilterVal) :
                             $tmpFilterKeyOut = "<span class=\"" . $colorDiff . "\"><b>" . $tmpFilterKey . "</b></span>";
                             $tmpFilterValOut = "<span class=\"" . $colorDiff . "\"><b>" . $tmpFilterValOut . "</b></span>";
                             $valChanged = true;
                          endif;
                          $tmpOut .= "<tr class=\"" . ($valChanged ? "state_changed" : "state_not_changed") . "\" style=\"vertical-align: top;\"><td>" . $tmpFilterKeyOut . ":</td><td>" . $tmpFilterValOut . "</td></tr>";
                          $tmpFilterValPre = $tmpFilterVal;
                       endif;
                    endif;
                    $tmpOut .= "</table><br>";
                    $tagContent .= $tmpOut;

                    if ($checkDifferences) :
                       $preLogoDescriptionArr = $valArr;
                    endif;
                 endif;
              endif;
              if (isset($logoDescriptionArray["STATUS_LOGOUT"]) && $logoDescriptionArray["STATUS_LOGOUT"] != "") : 
                 $tagContent .= "- <span class=\"f8np1_red\">" . $logoDescriptionArray["STATUS_LOGOUT"] . "</span><br>";
              endif;
              if (isset($logoDescriptionArray["PASSWORD"]) && $logoDescriptionArray["PASSWORD"] != "") : 
                 $tagContent .= "- <span class=\"f8np1_red\">" . $logoDescriptionArray["PASSWORD"] . "</span><br>";
              endif;
              if (isset($logoDescriptionArray["LOCATING"]) && $logoDescriptionArray["LOCATING"] != "") : 
                 if ($logoDescriptionArray["LOCATING"] == "0") : 
                    $tagContent .= "- " . getLngt("GPS off & Network off ") . "<br>";
                 elseif ($logoDescriptionArray["LOCATING"] == "1") : 
                    $tagContent .= "- " . getLngt("GPS on & Network off ") . "<br>";
                 elseif ($logoDescriptionArray["LOCATING"] == "2") : 
                    $tagContent .= "- " . getLngt("GPS off & Network on ") . "<br>";
                 elseif ($logoDescriptionArray["LOCATING"] == "3") : 
                    $tagContent .= "- " . getLngt("GPS on & Network on ") . "<br>";
                 else :
                    $tagContent .= "- <span class=\"f8np1_red\">" . getLngt("Deaktivierung") . "</span><br>";
                 endif;
              endif;
              if (isset($logoDescriptionArray["base"]) && $logoDescriptionArray["base"] == "app") : 
                 $tagContent .= "- " . getLngt("Basis: APP") . "<br>";
              endif;
              if (isset($logoDescriptionArray["line"]) && $logoDescriptionArray["line"] == "live") : 
                 $tagContent .= "- " . getLngt("Linie: Live") . "<br>";
              endif;
              if (isset($logoDescriptionArray["type"]) && $logoDescriptionArray["type"] == "sb") : 
                 $tagContent .= "- " . getLngt("Benutzeroberfläche: Standard") . "<br>";
              endif;
              if (isset($logoDescriptionArray["ver"]) && $logoDescriptionArray["ver"] != "") :
                 $tagContent .= "- " . getLngt("Version:") . " " . $logoDescriptionArray["ver"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["app_ver"]) && $logoDescriptionArray["app_ver"] != "") :
                 $tagContent .= "- " . getLngt("Version:") . " " . $logoDescriptionArray["app_ver"] . "<br>";
              endif;
              if ((isset($logoDescriptionArray["BATTLEVEL"]) && $logoDescriptionArray["BATTLEVEL"] != "") && is_numeric($logoDescriptionArray["BATTLEVEL"])) :
                 $tmpBattLevel = $logoDescriptionArray["BATTLEVEL"];
                 if ($tmpBattLevel <= 15) : $tmpBattLevel = "<span class=\"f8np1_red\">" . $tmpBattLevel . "</span>"; endif;
                 $tagContent .= "- " . getLngt("Akku: ") . " " . $tmpBattLevel . "%<br>";
              endif;
              if (isset($logoDescriptionArray["PWRSRC"]) && $logoDescriptionArray["PWRSRC"] != "") : 
                 if ($logoDescriptionArray["PWRSRC"] == "BATT") :
                    $tagContent .= "- " . getLngt("Stromquelle: Akku") . "<br>";
                 elseif ($logoDescriptionArray["PWRSRC"] == "USB") :
                    $tagContent .= "- " . getLngt("Stromquelle: USB") . "<br>";
                 elseif ($logoDescriptionArray["PWRSRC"] == "EXT") :
                    $tagContent .= "- " . getLngt("Stromquelle: Ladegerät") . "<br>";
                 endif;
              endif;
              if (isset($logoDescriptionArray["DISPLAY_TO"]) && $logoDescriptionArray["DISPLAY_TO"] != "" && is_numeric($logoDescriptionArray["DISPLAY_TO"])) : 
                 $tagContent .= "- " . getLngt("Displaytimeout: ") . " " . number_format(round(($logoDescriptionArray["DISPLAY_TO"] / 1000),2), 2, ",", ".") . " Sek.<br>";
              endif;
              if (isset($logoDescriptionArray["LDA_ERR"]) && $logoDescriptionArray["LDA_ERR"] != "") : 
                 $tmpArr = array("OK", "Fahrer-Zuordnung nicht gefunden", "Station zur Kommissionsnummer nicht gefunden", "Station schon erledigt", "Abweichendes Fahrzeug im Auftrag (Achtung: damit ist der Kurier gemeint, nicht die sid!)", "Interner Fehler - Station wurde nicht verändert");
                 $tagContent .= "- " . getLngt("LDA-Status") . ":<br>&nbsp;&nbsp;" . getLngt($tmpArr[$logoDescriptionArray["LDA_ERR"]]) . "<br>";
                 $tagContent .= "- " . getLngt("Komm.-Nr.") . ":&nbsp;&nbsp;" . $logoDescriptionArray["comm"] . "<br>";
              endif;

              // Remove last "<br>"
              $tagContent = substr($tagContent, 0, -4);
           endif;

           // Substitute text fragment
           $textToParse = substr_replace($textToParse, $tagContent, $beginTagPosBegin, $endTagPosEnd - $beginTagPosBegin);
        endif;
     }
  endif;
  return $textToParse;  
}

function postParseAtHistory ($textToParse) {
	global $historyEmpRightArr;
  $textToParse = trim($textToParse);

  if ($textToParse != "") :
  
     // Iterate ALL occurrences of "<postparser>...</postparser>"          
     while (!(strpos($textToParse, "<postparser>") === FALSE)) {
     
        $beginTagPosBegin = strpos($textToParse, "<postparser>");
        $beginTagPosEnd = $beginTagPosBegin + 12;
        $endTagPosBegin = strpos($textToParse, "</postparser>");
        $endTagPosEnd = $endTagPosBegin + 13;
     
        if ($beginTagPosEnd < $endTagPosBegin) :
           $tagContent = substr($textToParse, $beginTagPosEnd, $endTagPosBegin - $beginTagPosEnd);

           if ($tagContent != "") :
              $logoDescriptionArray = getKeyValueArrayFromString($tagContent);
              $tagContent = "";

              $keyArr = array("STATUS_VISIBILITY","STATUS_AUTHENTICATION","STATUS_NEW","STATUS_MODIFIED");
              $keyArrLen = count($keyArr);
              for ($i = 0; $i < $keyArrLen; $i++) :
                  mcArrIsSet($logoDescriptionArray, $keyArr[$i]);
              endfor;

              // Special treatment
              if (isset($logoDescriptionArray["STATUS_VISIBILITY"]) && $logoDescriptionArray["STATUS_VISIBILITY"] == "1") : 
                 $tagContent .= "- " . getLngt("sichtbar") . "<br>";
              endif;
              if (isset($logoDescriptionArray["STATUS_VISIBILITY"]) && $logoDescriptionArray["STATUS_VISIBILITY"] == "0") : 
                 $tagContent .= "- " . getLngt("ausgeblendet") . "<br>";
              endif;              
              if (isset($logoDescriptionArray["STATUS_AUTHENTICATION"]) && $logoDescriptionArray["STATUS_AUTHENTICATION"] == "1") : 
                 $tagContent .= "- " . getLngt("freigegeben") . "<br>";
              endif;
              if (isset($logoDescriptionArray["STATUS_AUTHENTICATION"]) && $logoDescriptionArray["STATUS_AUTHENTICATION"] == "0") : 
                 $tagContent .= "- " . getLngt("gesperrt") . "<br>";
              endif;
              if (isset($logoDescriptionArray["STATUS_MODIFIED"]) && $logoDescriptionArray["STATUS_MODIFIED"] != "") : 
                 $tagContent .= "" . $logoDescriptionArray["STATUS_MODIFIED"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["STATUS_NEW"]) && $logoDescriptionArray["STATUS_NEW"] != "") : 
                 $tagContent .= "" . $logoDescriptionArray["STATUS_NEW"] . "<br>";
              endif;

              // Remove last "<br>"
              $tagContent = substr($tagContent, 0, -4);
           endif;

           // Substitute text fragment
           $textToParse = substr_replace($textToParse, $tagContent, $beginTagPosBegin, $endTagPosEnd - $beginTagPosBegin);
        endif;
      }
  endif;
  return $textToParse;  
}

function postParseJbHistory ($textToParse) {
	global $db, $job_id, $historyEmpRightArr;
  $textToParse = trim($textToParse);

  if ($textToParse != "") :

     $globalParSalesTaxRate = 0;
     $globalParUseRelatedCustomer = getParameterValue("0", "GLOBAL_USE_RELATED_CUSTOMER", "0");
     if ($globalParUseRelatedCustomer == 1) :
        // Get tax value
        $globalParSalesTaxRate = getParameterValue("0", "GLOBAL_SALES_TAX", "0");
        if ($globalParSalesTaxRate == "" || !is_numeric($globalParSalesTaxRate)) : $globalParSalesTaxRate = 19; endif;
     endif;

     // Iterate ALL occurrences of "<postparser>...</postparser>"          
     while (!(strpos($textToParse, "<postparser>") === FALSE)) {
     
        $beginTagPosBegin = strpos($textToParse, "<postparser>");
        $beginTagPosEnd = $beginTagPosBegin + 12;
        $endTagPosBegin = strpos($textToParse, "</postparser>");
        $endTagPosEnd = $endTagPosBegin + 13;
     
        if ($beginTagPosEnd < $endTagPosBegin) :
           $tagContent = substr($textToParse, $beginTagPosEnd, $endTagPosBegin - $beginTagPosEnd);

           if ($tagContent != "") :
              $logoDescriptionArray = getKeyValueArrayFromMultiDelimiterString($tagContent);
//echo $tagContent . "<br>\n<br>\m";
//print_r($logoDescriptionArray);
              $setCheckboxes = "";
              $pos1 = strpos($tagContent, "`");
              while (!($pos1 === FALSE)) {
                $pos2 = strpos($tagContent, "´", $pos1);
                $setCheckboxes .= substr($tagContent, $pos1 + 1, $pos2 - $pos1 - 1) . ", ";
                $pos1 = strpos($tagContent, "`", $pos2);
              }
              if ($setCheckboxes != "")
                $setCheckboxes = "-&nbsp;<b>" . getLngt("Gesetzte&nbsp;Optionen") . ":</b>&nbsp;&nbsp;" . str_replace(" ", "&nbsp;", substr($setCheckboxes, 0, strlen($setCheckboxes) - 2)) . "<br>";
              $tagContent = "";
              // Special treatment
              if (isset($logoDescriptionArray["\$csc_id_payer_old"]) && $logoDescriptionArray["\$csc_id_payer_old"] != $logoDescriptionArray["\$csc_id_payer"]) :
                 $tmpCsEid = getLngt("Keiner");
                 if ($logoDescriptionArray["\$csc_id_payer_old"] != "" && $logoDescriptionArray["\$csc_id_payer_old"] != "0") :
                    $tmpCsId = getFieldValueFromId("costcenter", "csc_id", $logoDescriptionArray["\$csc_id_payer_old"], "cs_id");
                    if ($tmpCsId != "") :
                       $tmpCsEid = getFieldValueFromId("customer", "cs_id", $tmpCsId, "cs_eid");
                    endif;
                 endif;
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisheriger&nbsp;Bezahler") . ":</b>&nbsp;&nbsp;" . getLngt($tmpCsEid) . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$csc_id_payer_cash_old"]) && $logoDescriptionArray["\$csc_id_payer_cash_old"] != $logoDescriptionArray["\$csc_id_payer_cash"]) : 
                 $tmpCsEid = getLngt("Keiner");
                 if ($logoDescriptionArray["\$csc_id_payer_cash_old"] != "" && $logoDescriptionArray["\$csc_id_payer_cash_old"] != "0") : 
                    $tmpCsId = getFieldValueFromId("costcenter", "csc_id", $logoDescriptionArray["\$csc_id_payer_cash_old"], "cs_id");
                    if ($tmpCsId != "") :
                       $tmpCsEid = getFieldValueFromId("customer", "cs_id", $tmpCsId, "cs_eid");
                    endif;
                 endif;
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisheriger&nbsp;Barzahler") . ":</b>&nbsp;&nbsp;" . getLngt($tmpCsEid) . "<br>";
              endif;
              if (isset($logoDescriptionArray["JB_ID_ORG"]) && $logoDescriptionArray["JB_ID_ORG"] != "") : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Vorlageauftrag") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["JB_ID_ORG"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["HQ_ID_EXEC"]) && $logoDescriptionArray["HQ_ID_EXEC"] != "") : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Einstellende&nbsp;NL") . ":</b>&nbsp;&nbsp;" . $db->getOne("SELECT hq_mnemonic FROM headquarters, job WHERE headquarters.hq_id = job.hq_id AND jb_id = " . $job_id) . "<br>";
                 $tagContent .= "-&nbsp;<b>" . getLngt("Ausf&uuml;hrende&nbsp;NL") . ":</b>&nbsp;&nbsp;" . $db->getOne("SELECT hq_mnemonic FROM headquarters WHERE hq_id = " . $logoDescriptionArray["HQ_ID_EXEC"]) . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$hq_id_exec_old"]) && $logoDescriptionArray["\$hq_id_exec_old"] != $logoDescriptionArray["\$hq_id_exec"]) : 
                 if ($logoDescriptionArray["\$hq_id_exec_old"] != "") : 
                    $logoDescriptionArray["\$hq_id_exec"] = $db->getOne("SELECT hq_mnemonic FROM headquarters WHERE hq_id = " . $logoDescriptionArray["\$hq_id_exec"]);
                    $logoDescriptionArray["\$hq_id_exec_old"] = $db->getOne("SELECT hq_mnemonic FROM headquarters WHERE hq_id = " . $logoDescriptionArray["\$hq_id_exec_old"]);
                 endif;
                 $tagContent .= "-&nbsp;<b>" . getLngt("Ausf&uuml;hrende&nbsp;NL") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$hq_id_exec"] . "&nbsp;(bisher:&nbsp;" . $logoDescriptionArray["\$hq_id_exec_old"] . ")" . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_longhaul_old"]) && $logoDescriptionArray["\$jb_longhaul_old"] != $logoDescriptionArray["\$jb_longhaul"]) : 
                 if ($logoDescriptionArray["\$jb_longhaul_old"] != "") : 
                    $logoDescriptionArray["\$jb_longhaul"] = $logoDescriptionArray["\$jb_longhaul"] == "1" ? "Ja" : "Nein";
                    $logoDescriptionArray["\$jb_longhaul_old"] = $logoDescriptionArray["\$jb_longhaul"] == "1" ? "Ja" : "Nein";
                 endif;
                 $tagContent .= "-&nbsp;<b>" . getLngt("BWV-Auftrag") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_longhaul"] . "&nbsp;(bisher:&nbsp;" . $logoDescriptionArray["\$jb_longhaul_old"] . ")" . "<br>";
              endif;
              if (isset($logoDescriptionArray["JB_LONGHAUL"]) && $logoDescriptionArray["JB_LONGHAUL"] == "1") : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("BWV-Auftrag") . "<br>";
              endif;
              if (isset($logoDescriptionArray["ORDERTIME_OLD"]) && $logoDescriptionArray["ORDERTIME_OLD"] != "") : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisherige&nbsp;Auftragszeit") . ":</b><br>&nbsp;&nbsp;" . formatOutput($logoDescriptionArray["ORDERTIME_OLD"],"datetime","1","") . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_ordertime_old"]) && $logoDescriptionArray["\$jb_ordertime_old"] != $logoDescriptionArray["\$jb_ordertime"]) : 
                 if ($logoDescriptionArray["\$jb_ordertime_old"] != "") : 
                    $logoDescriptionArray["\$jb_ordertime_old"] = formatOutput($logoDescriptionArray["\$jb_ordertime_old"],"datetime","1","");
                 endif;
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisherige&nbsp;Auftragszeit") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_ordertime_old"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_reserv_old"]) && $logoDescriptionArray["\$jb_reserv_old"] != $logoDescriptionArray["\$jb_reserv"] && $logoDescriptionArray["\$jb_reserv_old"] != "0") : 
                 if ($logoDescriptionArray["\$jb_reserv_old"] != "1") : 
                     $jb_reserv_txt  = "Nein";
                   else:
                     $jb_reserv_txt  = "Ja";
                 endif;
                 $tagContent .= "-&nbsp;<b>" . getLngt("Auftragszeit&nbsp;war&nbsp;eingegeben") . ":</b>&nbsp;&nbsp;" . $jb_reserv_txt . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_totalprice_old"]) && $logoDescriptionArray["\$jb_totalprice_old"] != $logoDescriptionArray["\$jb_totalprice"]) : 
                 if ($logoDescriptionArray["jb_totalprice_old"] != "" && $logoDescriptionArray["\$jb_totalprice_old"] != $logoDescriptionArray["\$jb_totalprice"]) : 
                    $logoDescriptionArray["jb_totalprice_old"] = number_format(round($logoDescriptionArray["jb_totalprice_old"] * (1 + ($globalParSalesTaxRate / 100)) ,2), 2, ",", ".");
                 endif;
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisheriger&nbsp;Preis") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["jb_totalprice_old"] . "&nbsp;€<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_fixprice_old"]) && $logoDescriptionArray["\$jb_fixprice_old"] != "" && $logoDescriptionArray["\$jb_fixprice_old"] != $logoDescriptionArray["\$jb_fixprice"]) : 
                 if ($logoDescriptionArray["\$jb_fixprice_old"] != "" && $logoDescriptionArray["\$jb_fixprice_old"] != $logoDescriptionArray["\$jb_fixprice"]) : 
                    $logoDescriptionArray["\$jb_fixprice_old"] = number_format(round($logoDescriptionArray["\$jb_fixprice_old"] * (1 + ($globalParSalesTaxRate / 100)) ,2), 2, ",", ".");
                 endif;
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisheriger&nbsp;Fixpreis") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_fixprice_old"] . "&nbsp;€<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_serviceprice_old"]) && $logoDescriptionArray["\$jb_serviceprice_old"] != "" && $logoDescriptionArray["\$jb_serviceprice_old"] != $logoDescriptionArray["\$jb_serviceprice"]) : 
                 if ($logoDescriptionArray["\$jb_serviceprice_old"] != "" && $logoDescriptionArray["\$jb_serviceprice_old"] != $logoDescriptionArray["\$jb_serviceprice"]) : 
                    $logoDescriptionArray["\$jb_serviceprice_old"] = number_format(round($logoDescriptionArray["\$jb_serviceprice_old"] * (1 + ($globalParSalesTaxRate / 100)) ,2), 2, ",", ".");
                 endif;
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisheriger&nbsp;Servicepreis") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_serviceprice_old"] . "&nbsp;€<br>";
              endif;
              if (isset($logoDescriptionArray["LDA_ERR"]) && $logoDescriptionArray["LDA_ERR"] != "") : 
                 $tmpArr = array("OK", "Fahrer-Zuordnung nicht gefunden", "Station zur Kommissionsnummer nicht gefunden", "Station schon erledigt", "Abweichendes Fahrzeug im Auftrag (Achtung: damit ist der Kurier gemeint, nicht die sid!)", "Interner Fehler - Station wurde nicht verändert");
                 $tagContent .= "-&nbsp;<b>" . getLngt("LDA-Status") . ":</b><br>&nbsp;&nbsp;" . getLngt($tmpArr[$logoDescriptionArray["LDA_ERR"]]) . "<br>";
                 $tagContent .= "-&nbsp;<b>" . getLngt("Komm.-Nr.") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["comm"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_cr_filter_old"]) && $logoDescriptionArray["\$jb_cr_filter_old"] != $logoDescriptionArray["\$jb_cr_filter"]) : 
                 $tmpCrFilter = getLngt("Keine");
                 if ($logoDescriptionArray["\$jb_cr_filter_old"] != "") : 
                    $tmpCrFilter = $logoDescriptionArray["\$jb_cr_filter_old"];
                 endif;
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisherige&nbsp;Filter") . ":</b>&nbsp;&nbsp;" . $tmpCrFilter . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$vht_id_old"]) && trim($logoDescriptionArray["\$vht_id_old"]) != trim($logoDescriptionArray["\$vht_id"])) :
                 $mtValue = getLngt("Keiner");
                 if (trim($logoDescriptionArray["\$vht_id"]) != "") : 
                    $mtValue = getFieldValueFromClause("metatype", "mt_value", "mt_type = 'vehicletype' AND mt_sort = '" . trim($logoDescriptionArray["\$vht_id"]) . "'");
                 endif;
                 $mtValue_old = getLngt("Keiner");
                 if (trim($logoDescriptionArray["\$vht_id_old"]) != "") : 
                    $mtValue_old = getFieldValueFromClause("metatype", "mt_value", "mt_type = 'vehicletype' AND mt_sort = '" . trim($logoDescriptionArray["\$vht_id_old"]) . "'");
                 endif;
                 $tagContent .= "-&nbsp;<b>" . getLngt("Fahrzeugtyp")  . ":&nbsp;&nbsp;" . str_replace(" ", "&nbsp;", getLngt($mtValue)) . "</b>&nbsp;(" . getLngt("bisher") . ":&nbsp;&nbsp;" . str_replace(" ", "&nbsp;", getLngt($mtValue_old)) . ")<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_dispoinfo_old"]) && $logoDescriptionArray["\$jb_dispoinfo_old"] != $logoDescriptionArray["\$jb_dispoinfo"]) : 
                 $tmpJbDispoinfo = getLngt("Keine");
                 if ($logoDescriptionArray["\$jb_dispoinfo_old"] != "") : 
                   $tmpJbDispoinfo = $logoDescriptionArray["\$jb_dispoinfo_old"];
                 endif;
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisherige&nbsp;Dispo-Info") . ":</b>&nbsp;&nbsp;" . $tmpJbDispoinfo . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_warningtime_old"]) && $logoDescriptionArray["\$jb_warningtime_old"] != $logoDescriptionArray["\$jb_warningtime"]) : 
                 $tmpJbWarningtime = getLngt("Keines");
                 if ($logoDescriptionArray["\$jb_warningtime_old"] != "0000-00-00 00:00:00") : 
                   $tmpJbWarningtime = formatOutput($logoDescriptionArray["\$jb_warningtime_old"],"datetime","1","");
                 endif;
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisheriges&nbsp;Datum&nbsp;der&nbsp;Dispo-Info") . ":</b>&nbsp;&nbsp;" . $tmpJbWarningtime . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_cashpayer_mail_old"]) && $logoDescriptionArray["\$jb_cashpayer_mail_old"] != $logoDescriptionArray["\$jb_cashpayer_mail"]) : 
                 $tmpJbCashpayer = getLngt("Keine");
                 if ($logoDescriptionArray["\$jb_cashpayer_mail_old"] != "") : 
                    $tmpJbCashpayer = $logoDescriptionArray["\$jb_cashpayer_mail_old"];
                 endif;
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisherige&nbsp;Barzahler-Mail") . ":</b>&nbsp;&nbsp;" . $tmpJbCashpayer . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_weight_old"]) && $logoDescriptionArray["\$jb_weight_old"] != "" && $logoDescriptionArray["\$jb_weight_old"] != $logoDescriptionArray["\$jb_weight"]) : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisheriges&nbsp;Gewicht") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_weight_old"] . "&nbsp;kg<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_crvh_length_old"]) && $logoDescriptionArray["\$jb_crvh_length_old"] != "" && $logoDescriptionArray["\$jb_crvh_length_old"] != $logoDescriptionArray["\$jb_crvh_length"]) : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisherige&nbsp;L&auml;nge") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_crvh_length_old"] . "&nbsp;cm<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_weight_old"]) && $logoDescriptionArray["\$jb_weight_old"] != "" && $logoDescriptionArray["\$jb_crvh_width_old"] != $logoDescriptionArray["\$jb_crvh_width"]) : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisherige&nbsp;Breite") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_crvh_width_old"] . "&nbsp;cm<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_crvh_height_old"]) && $logoDescriptionArray["\$jb_crvh_height_old"] != "" && $logoDescriptionArray["\$jb_crvh_height_old"] != $logoDescriptionArray["\$jb_crvh_height"]) : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisherige&nbsp;H&ouml;he") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_crvh_height_old"] . "&nbsp;cm<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_crvh_position_old"]) && $logoDescriptionArray["\$jb_crvh_position_old"] != "" && $logoDescriptionArray["\$jb_crvh_position_old"] != $logoDescriptionArray["\$jb_crvh_position"]) : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisherige&nbsp;Anzahl&nbsp;Stellpl&auml;tze") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_crvh_position_old"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_sales_tax_rate_sign_old"]) && $logoDescriptionArray["\$jb_sales_tax_rate_sign_old"] != "" && $logoDescriptionArray["\$jb_sales_tax_rate_sign_old"] != $logoDescriptionArray["\$jb_sales_tax_rate_sign"]) : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisheriges&nbsp;MwSt-Kennzeichen") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_sales_tax_rate_sign_old"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_sales_tax_rate_old"]) && $logoDescriptionArray["\$jb_sales_tax_rate_old"] != "" && $logoDescriptionArray["\$jb_sales_tax_rate_old"] != $logoDescriptionArray["\$jb_sales_tax_rate"]) : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisheriger&nbsp;MwSt-Satz") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_sales_tax_rate_old"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_markup_old"]) && $logoDescriptionArray["\$jb_markup_old"] != "" && $logoDescriptionArray["\$jb_markup_old"] != $logoDescriptionArray["\$jb_markup"]) : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisheriger&nbsp;Treibstoffzuschlag") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_markup_old"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_km_old"]) && $logoDescriptionArray["\$jb_km_old"] != $logoDescriptionArray["\$jb_km"]) : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisherige&nbsp;Kilometer") . ":</b>&nbsp;&nbsp;" . str_replace(".", ",", $logoDescriptionArray["\$jb_km_old"]) . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$cs_invmail_old"]) && $logoDescriptionArray["\$cs_invmail_old"] != $logoDescriptionArray["\$cs_invmail"]) : 
                 $tmpCs_invmail = getLngt("Keine");
                 if ($logoDescriptionArray["\$cs_invmail_old"] != "") : 
                    $tmpCs_invmail = $logoDescriptionArray["\$cs_invmail_old"];
                 endif;
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisherige&nbsp;Rechnungs-Email") . ":</b>&nbsp;&nbsp;" . $tmpCs_invmail . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$cmp_postage_old"]) && $logoDescriptionArray["\$cmp_postage_old"] != $logoDescriptionArray["\$cmp_postage"]) :
                 $tagContent .= "-&nbsp;<b>" . getLngt("Bisheriges&nbsp;Porto") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$cmp_postage_old"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_id_permanent_pre"]) && $logoDescriptionArray["\$jb_id_permanent_pre"] != "") : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Einmalige&nbsp;&Auml;nderung,&nbsp;fortgesetzt&nbsp;wird") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_id_permanent_pre"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_id_ori"]) && $logoDescriptionArray["\$jb_id_ori"] != "") : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Dauerauftragskopie&nbsp;von") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_id_ori"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_id_permanent_pre1"]) && $logoDescriptionArray["\$jb_id_permanent_pre1"] != "") : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Aufgrund&nbsp;einmaliger&nbsp;&Auml;nderung&nbsp;wurde&nbsp;fortgesetzt") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_id_permanent_pre1"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_id_ori_copy"]) && $logoDescriptionArray["\$jb_id_ori_copy"] != "") : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Multiauftragskopie&nbsp;von") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_id_ori_copy"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_multi_factor"]) && $logoDescriptionArray["\$jb_multi_factor"] != "") : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Multiauftrag,&nbsp;Anzahl&nbsp;Auftr&auml;ge") . ":</b>&nbsp;&nbsp;" . $logoDescriptionArray["\$jb_multi_factor"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$i_multi"]) && $logoDescriptionArray["\$i_multi"] != "") : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Kopie&nbsp;Nr.") . ":</b>&nbsp;&nbsp;" . ($logoDescriptionArray["\$i_multi"] - 1) . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$tr_add"]) && $logoDescriptionArray["\$tr_add"] != "") : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Station(en)&nbsp;hinzugef&uuml;gt&nbsp;an&nbsp;Position") . ":</b>&nbsp;&nbsp;" . (str_replace(" ", "&nbsp;", $logoDescriptionArray["\$tr_add"])) . "<br>";
              endif;
              if (isset($logoDescriptionArray["JB_RHYTHM_DEL"]) && $logoDescriptionArray["JB_RHYTHM_DEL"] == "1") : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Dauerauftragsregel bleibt erhalten") . "<br>";
              endif;
              if (isset($logoDescriptionArray["JB_RHYTHM_DEL"]) && $logoDescriptionArray["JB_RHYTHM_DEL"] == "2") : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Dauerauftragsregel wurde gelöscht") . "<br>";
              endif;
              if (isset($logoDescriptionArray["STATION_ID"]) && $logoDescriptionArray["STATION_ID"] != "" && is_numeric($logoDescriptionArray["STATION_ID"])) :
                 $trSort = getFieldValueFromId("tour", "tr_id", $logoDescriptionArray["STATION_ID"], "tr_sort");
                 $tagContent .= "<br><b>[" . getLngt("Station") . "&nbsp;" . $trSort .  "]</b><br>";
                 // $tagContent .= getJobInternalRemarkItems($job_id, "2", $logoDescriptionArray["STATION_ID"]) . "<br>";
                 $mtIntRemItem = getColVectorFromDB2ArrayByClause("metatype", "mt_value", "mt_type = 'internal_remark' AND mt_objtype = '' AND mt_objid = '0'", "mt_sort", "mt_sort", "");
                 $remark_items = array_filter(explode(",", $logoDescriptionArray["REMARK_ITEMS"]));
                 for ($i = 0; $i < count($remark_items); $i++) :
                   $tagContent .= "<br>&bull;&nbsp;" . $mtIntRemItem[$remark_items[$i]];
                 endfor;
                 $tagContent .= "<br>";
                 if (trim($logoDescriptionArray["REMARK_TEXT"]) != "") $tagContent .= $logoDescriptionArray["REMARK_TEXT"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["MAIL_STATE"]) && $logoDescriptionArray["MAIL_STATE"] != "") :
                 $tagContent .= "<br>- " . getLngt("Versandstatus") . ":&nbsp;";
                 if ($logoDescriptionArray["MAIL_STATE"] == "SENT") :
                    $tagContent .= "<b>" . getLngt("OK") . "</b><br>";
                 else :
                    $tagContent .= "<b>" . getLngt("FEHLER") . "</b><br>";
                 endif;
                 $tagContent .= "<br>- " . getLngt("An") . ":&nbsp;" . $logoDescriptionArray["MAIL_TO"] . "<br>";
              endif;
              if (isset($logoDescriptionArray["THRESHOLD"]) && $logoDescriptionArray["THRESHOLD"] != "") : 
                 $tagContent .= $logoDescriptionArray["OVERRIDE"] . "&nbsp;&euro;" . "&nbsp;(<b>Schwellwert:</b>&nbsp;" . $logoDescriptionArray["THRESHOLD"] . "&nbsp;&euro;)" . "<br>";
              endif;
              if (isset($logoDescriptionArray["BLOCK"]) && $logoDescriptionArray["BLOCK"] != "") : 
                 $tagContent .= $logoDescriptionArray["OVERRIDE"] . "&nbsp;&euro;" . "&nbsp;(<b>Sperrwert:</b>&nbsp;" . $logoDescriptionArray["BLOCK"] . "&nbsp;&euro;)" . "<br>";
              endif;
              if (isset($logoDescriptionArray["REASON"]) && $logoDescriptionArray["REASON"] == "Driver_Occupied") : 
                 $tagContent .= "- " . getLngt("Fahrer besetzt") . "<br>";
              endif;
              if (isset($logoDescriptionArray["REASON"]) && $logoDescriptionArray["REASON"] == "Num_Of_Challenges_Reached") : 
                 $tagContent .= "- " . getLngt("Max. Anzahl Vermittlungsversuche erreicht") . "<br>";
              endif;
              if (isset($logoDescriptionArray["REASON"]) && $logoDescriptionArray["REASON"] == "No_Match_Vehicle_Type") : 
                 $tagContent .= "- " . getLngt("Fahrzeugtyp passt nicht") . "<br>";
              endif;
              if (isset($logoDescriptionArray["REASON"]) && $logoDescriptionArray["REASON"] == "Third_Country_Check") : 
                 $tagContent .= "- " . getLngt("Drittlandprüfung") . "<br>";
              endif;
              if (isset($logoDescriptionArray["REASON"]) && $logoDescriptionArray["REASON"] == "Quarantine_Check") : 
                 $tagContent .= "- " . getLngt("Quarantäneprüfung") . "<br>";
              endif;
              if (isset($logoDescriptionArray["REASON"]) && $logoDescriptionArray["REASON"] == "Nationality_Check") : 
                 $tagContent .= "- " . getLngt("Nationalitätenprüfung") . "<br>";
              endif;
              if (isset($logoDescriptionArray["\$jb_cr_price_one_way"])) : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Preis&nbsp;nur&nbsp;Hinfahrt") . ":</b>&nbsp;&nbsp;" . str_replace(".", ",", $logoDescriptionArray["\$jb_cr_price_one_way"]) . "&nbsp;&euro;" . "<br>";
                if (isset($logoDescriptionArray["\$jb_cr_price"])) : 
                   $tagContent .= "-&nbsp;<b>" . getLngt("Hin&nbsp;und&nbsp;Zur&uuml;ck") . ":</b>&nbsp;&nbsp;" . str_replace(".", ",", $logoDescriptionArray["\$jb_cr_price"]) . "&nbsp;&euro;" . "<br>";
                endif;
              endif;
              $numOfStations = getCountOfTable("phoenix.tour", "jb_id = '" . $job_id . "'");
              if (isset($logoDescriptionArray["\$tr_del"]) && $logoDescriptionArray["\$tr_del"] != "") : 
                 $tagContent .= "-&nbsp;<b>" . getLngt("Station(en)&nbsp;gel&ouml;scht&nbsp;an&nbsp;Position") . ":</b>&nbsp;&nbsp;" . (str_replace(" ", "&nbsp;", $logoDescriptionArray["\$tr_del"])) . "<br>";
                 $tr_sorts = explode (", ", $logoDescriptionArray["\$tr_del"]);
                 $numOfStations = $tr_sorts[count($tr_sorts) - 1];
              endif;
              if (isset($logoDescriptionArray["INTERNAL_REMARK"])) : 
                 $tagContent .= $logoDescriptionArray["INTERNAL_REMARK"] . "<br>";
              endif;
              // Station addresses
              for ($i = 0; $i < $numOfStations; $i++) :
                  $trSort = $i + 1;
                  $stationTagContent = "";
                  if (isset($logoDescriptionArray["\$tr_comp_old_" . $trSort]) && $logoDescriptionArray["\$tr_comp_old_" . $trSort] != $logoDescriptionArray["\$tr_comp_" . $trSort]) : 
                     $tmpTrComp = getLngt("Keine");
                     if ($logoDescriptionArray["\$tr_comp_old_" . $trSort] != "") : 
                        $tmpTrComp = getLngt($logoDescriptionArray["\$tr_comp_old_" . $trSort]);
                     endif;
                     $stationTagContent .= "&nbsp;&nbsp;-&nbsp;<b>" . getLngt("Bisherige&nbsp;Firma") . ":</b><br>&nbsp;&nbsp;&nbsp;&nbsp;" . $tmpTrComp . "<br>";
                  endif;
                  if ((isset($logoDescriptionArray["\$ad_street_old_" . $trSort]) && $logoDescriptionArray["\$ad_street_old_" . $trSort] != "" && $logoDescriptionArray["\$ad_street_old_" . $trSort] != $logoDescriptionArray["\$ad_street_" . $trSort]) || 
                      (isset($logoDescriptionArray["\$tr_hsno_old_" . $trSort]) && $logoDescriptionArray["\$tr_hsno_old_" . $trSort] != ""  && $logoDescriptionArray["\$tr_hsno_old_" . $trSort] != $logoDescriptionArray["\$tr_hsno_" . $trSort]) ||
                      (isset($logoDescriptionArray["\$ad_zipcode_old_" . $trSort]) && $logoDescriptionArray["\$ad_zipcode_old_" . $trSort] != ""  && $logoDescriptionArray["\$ad_zipcode_old_" . $trSort] != $logoDescriptionArray["\$ad_zipcode_" . $trSort]) || 
                      (isset($logoDescriptionArray["\$ad_city_old_" . $trSort]) && $logoDescriptionArray["\$ad_city_old_" . $trSort] != ""  && $logoDescriptionArray["\$ad_city_old_" . $trSort] != $logoDescriptionArray["\$ad_city_" . $trSort])) : 
                      $stationTagContent .= "&nbsp;&nbsp;-&nbsp;<b>" . getLngt("Bisherige&nbsp;Adresse") . ":</b><br>&nbsp;&nbsp;&nbsp;&nbsp;"
                                                    . getLngt($logoDescriptionArray["\$ad_street_old_" . $trSort]) . "&nbsp;" . getLngt($logoDescriptionArray["\$tr_hsno_old_" . $trSort]) . "<br>&nbsp;&nbsp;&nbsp;&nbsp;"
                                                    . getLngt($logoDescriptionArray["\$ad_zipcode_old_" . $trSort]) . "&nbsp;" . getLngt($logoDescriptionArray["\$ad_city_old_" . $trSort]) . "<br>";
                  endif;
                  if (isset($logoDescriptionArray["\$tr_person_old_" . $trSort]) && $logoDescriptionArray["\$tr_person_old_" . $trSort] != $logoDescriptionArray["\$tr_person_" . $trSort]) : 
                     $tmpTrPerson = getLngt("Keine");
                     if ($logoDescriptionArray["\$tr_person_old_" . $trSort] != "") : 
                        $tmpTrPerson = getLngt($logoDescriptionArray["\$tr_person_old_" . $trSort]);
                     endif;
                     $stationTagContent .= "&nbsp;&nbsp;-&nbsp;<b>" . getLngt("Bisheriger&nbsp;Ansprechpartner") . ":</b><br>&nbsp;&nbsp;&nbsp;&nbsp;" . $tmpTrPerson . "<br>";
                  endif;
                  if (isset($logoDescriptionArray["\$tr_remark_old_" . $trSort]) && $logoDescriptionArray["\$tr_remark_old_" . $trSort] != $logoDescriptionArray["\$tr_remark_" . $trSort]) : 
                     $tmpTrRemark = getLngt("Keine");
                     if ($logoDescriptionArray["\$tr_remark_old_" . $trSort] != "") : 
                        $tmpTrRemark = getLngt($logoDescriptionArray["\$tr_remark_old_" . $trSort]);
                     endif;
                     $stationTagContent .= "&nbsp;&nbsp;-&nbsp;<b>" . getLngt("Bisherige&nbsp;Bemerkungen") . ":</b><br>&nbsp;&nbsp;" . $tmpTrRemark . "<br>";
                  endif;
                  if (isset($logoDescriptionArray["\$tr_commission_no_old_" . $trSort]) && $logoDescriptionArray["\$tr_commission_no_old_" . $trSort] != $logoDescriptionArray["\$tr_commission_no_" . $trSort]) : 
                     $tmpTrCommissionNo = getLngt("Keine");
                     if ($logoDescriptionArray["\$tr_commission_no_old_" . $trSort] != "") : 
                        $tmpTrCommissionNo = getLngt($logoDescriptionArray["\$tr_commission_no_old_" . $trSort]);
                     endif;
                     $stationTagContent .= "&nbsp;&nbsp;-&nbsp;<b>" . getLngt("Bisherige&nbsp;Kommissionsnr.") . ":</b><br>&nbsp;&nbsp;" . $tmpTrCommissionNo . "<br>";
                  endif;
                  if (isset($logoDescriptionArray["\$tr_photo_old_" . $trSort]) && $logoDescriptionArray["\$tr_photo_old_" . $trSort] != $logoDescriptionArray["\$tr_photo_" . $trSort]) : 
                     $tmpTrPhoto = getLngt("Keine");
                     if ($logoDescriptionArray["\$tr_photo_old_" . $trSort] != "") : 
                        $tmpTrPhoto = getLngt($logoDescriptionArray["\$tr_photo_old_" . $trSort]);
                     endif;
                     $stationTagContent .= "&nbsp;&nbsp;-&nbsp;<b>" . getLngt("Bisherige&nbsp;Fotos") . ":</b><br>&nbsp;&nbsp;" . $tmpTrPhoto . "<br>";
                  endif;
                  // Write station data if at least one changement does exist
                  if ($stationTagContent != "") :
                     $tagContent .= "-&nbsp;<b>" . getLngt("STATION") . "&nbsp;" . $trSort . "</b><br>";
                     $tagContent .= $stationTagContent;
                  endif;
              endfor;
              $tagContent .= $setCheckboxes;
              // Remove last "<br>"
              $tagContent = substr($tagContent, 0, -4);
           endif;

           // Substitute text fragment
           $textToParse = substr_replace($textToParse, $tagContent, $beginTagPosBegin, $endTagPosEnd - $beginTagPosBegin);
        endif;
      }
  endif;
  return $textToParse;  
}


function postParseEmpHistory ($textToParse) {
	global $historyEmpRightArr;
  $textToParse = trim($textToParse);

  if ($textToParse != "") :
  
     // Get headquarters
     $empHistHqArr = getColVectorFromDB2ArrayByClause("headquarters", "hq_mnemonic", "", "hq_id", "hq_mnemonic", "");
     $empHistHqArrLen = count($empHistHqArr);
  
     // Iterate ALL occurrences of "<postparser>...</postparser>"          
     while (!(strpos($textToParse, "<postparser>") === FALSE)) {
     
        $beginTagPosBegin = strpos($textToParse, "<postparser>");
        $beginTagPosEnd = $beginTagPosBegin + 12;
        $endTagPosBegin = strpos($textToParse, "</postparser>");
        $endTagPosEnd = $endTagPosBegin + 13;
     
        if ($beginTagPosEnd < $endTagPosBegin) :
           $tagContent = substr($textToParse, $beginTagPosEnd, $endTagPosBegin - $beginTagPosEnd);

           if ($tagContent != "") :
              $logoDescriptionArray = getKeyValueArrayFromString($tagContent);
              $tagContent = "";

              // Special treatment
              if (isset($logoDescriptionArray["RIGHTS_OLD"]) && $logoDescriptionArray["RIGHTS_OLD"] != "" || $logoDescriptionArray["RIGHTS_NEW"] != "") : 
                 $tmpRgtsOld =  $logoDescriptionArray["RIGHTS_OLD"];
                 $tmpRgtsNew =  $logoDescriptionArray["RIGHTS_NEW"];
                 $tmpStrLen = max(strlen($tmpRgtsOld), strlen($tmpRgtsNew));
                 for ($i = 0; $i < $tmpStrLen; $i++) :
                     if (substr($tmpRgtsOld, $i, 1) != substr($tmpRgtsNew, $i, 1)) :
                        $rgtName = getFieldValueFromId("rights", "rgt_id", ($i + 1), "rgt_name");
                        if ($rgtName != "") :
                           $tagContent .= "-&nbsp;" . getLngt("Berechtigung") . "&nbsp;<b>" . $rgtName . "</b>&nbsp;" . (substr($tmpRgtsNew, $i, 1) == "1" ? getLngt("vergeben") : getLngt("entzogen")) . "<br>";
                        endif;
                     endif;
                 endfor;
              endif;
              if (isset($logoDescriptionArray["STATUS_NEW"]) && $logoDescriptionArray["STATUS_NEW"] != "") :
                 $tmpArr = explode($logoDescriptionArray["STATUS_NEW"]);
                 // array($userType,$usr_name,$usr_firstname,$usr_email,$usr_phone,$usr_phone2,$usr_account,$f_usr_birthdate)
                 $tmpArr = array($tmpArr[1], $tmpArr[2], $tmpArr[3], $tmpArr[4], $tmpArr[6]);
                 $tagContent .= "-&nbsp;" . implode(",", $tmpArr) . "<br>";
              endif;
              if (isset($logoDescriptionArray["STATUS_MODIFIED"]) && $logoDescriptionArray["STATUS_MODIFIED"] != "") :
                 $tmpArr = explode($logoDescriptionArray["STATUS_MODIFIED"]);
                 // array($tmpUsrName,$tmpUsrFirstName,$tmpUsrAccount,$tmpEmpActRigths,$tmpUsrPassword,$tmpEmpActRigths,$tmpUsrBirthdate)
                 $tmpArr = array($tmpArr[0], $tmpArr[1], $tmpArr[2]);
                 $tagContent .= "-&nbsp;" . implode(",", $tmpArr) . "<br>";
              endif;
              /*
              if (isset($logoDescriptionArray["USER_INFO"]) && $logoDescriptionArray["USER_INFO"] != "") :
                 $tmpArr = explode($logoDescriptionArray["USER_INFO"]);
                 // array($tmpUsrName,$tmpUsrFirstName,$tmpUsrAccount)
                 $tmpArr = array($tmpArr[0], $tmpArr[1], $tmpArr[2]);
                 $tagContent .= "-&nbsp;" . implode(",", $tmpArr) . "<br>";
              endif;
              */
              if (isset($logoDescriptionArray["HQ_ACCESS_OLD"]) && $logoDescriptionArray["HQ_ACCESS_OLD"] != "") : 
                 $tmpHqs = explode(",", $logoDescriptionArray["HQ_ACCESS_OLD"]);
                 $tmpHqsLen = count($tmpHqs);
                 $tmpHqNamesArr = array();
                 for ($i = 0; $i < $tmpHqsLen; $i++) :
                     $tmpHqNamesArr[] = $empHistHqArr[$tmpHqs[$i]];
                 endfor;
                 $tagContent .= "-&nbsp;" . getLngt("Vorher") . ":&nbsp;<b>" . implode(",&nbsp;", $tmpHqNamesArr) . "</b>&nbsp;" . "<br>";
              endif;
              if (isset($logoDescriptionArray["HQ_ACCESS_NEW"]) && $logoDescriptionArray["HQ_ACCESS_NEW"] != "") : 
                 $tmpHqs = explode(",", $logoDescriptionArray["HQ_ACCESS_NEW"]);
                 $tmpHqsLen = count($tmpHqs);
                 $tmpHqNamesArr = array();
                 for ($i = 0; $i < $tmpHqsLen; $i++) :
                     $tmpHqNamesArr[] = $empHistHqArr[$tmpHqs[$i]];
                 endfor;
                 $tagContent .= "-&nbsp;" . getLngt("Nachher") . ":&nbsp;<b>" . implode(",&nbsp;", $tmpHqNamesArr) . "</b>&nbsp;" . "<br>";
              endif;

              // Remove last "<br>"
              $tagContent = substr($tagContent, 0, -4);
           endif;

           // Substitute text fragment
           $textToParse = substr_replace($textToParse, $tagContent, $beginTagPosBegin, $endTagPosEnd - $beginTagPosBegin);
        endif;
      }
  endif;
  return $textToParse;
}
?>
