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

include_once ("../include/mcglobal.inc.php");
include_once ("../include/auth.inc.php");
include_once ("../include/inc_wording_wrapper.inc.php");
include_once ("../geo/geocode.inc.php");
include_once ("../include/inc_file.inc.php");
include_once ("../include/inc_courier.inc.php");
include_once ("../include/inc_filters.inc.php");
include_once ("../locating/xServer.inc.php");


$httpVars = array("f_act", "companyId", "orderClause", "statusMessage");

$httpVisualVars = array("f_cmp_authenticated", "f_cmp_type", "f_cmp_comp", "f_cmp_comp2", "f_usr_id", "f_usr_name", "f_usr_firstname", "f_usr_country", 
                        "f_usr_phone", "f_usr_phone2", "f_usr_fax", "f_usr_email", "f_usr_inv_email", "f_cr_sid", "f_cr_eid", "f_vht_id_inv", "f_cr_maxweight", 
                        "f_cr_outlay", "f_cr_available", "f_cmp_iln", "f_cmp_tax_idno", "f_cmp_stax_idno", "f_cmp_bank", "f_cmp_bankno", "f_cmp_bankacc", 
                        "f_cmp_bankmode", "f_cmp_iban", "f_cmp_swift", "f_usr_account", "f_usr_password", "f_usr_password2", 
                        "f_ad_street", "f_cmp_hsno", "f_ad_zipcode", "f_ad_city", "f_ad_country", "f_cr_homezipcode",
                        "f_cr_id_parent", "f_cr_sid_parent", "f_cr_eid_parent", "f_cr_vh_sign",
                        "f_usr_birthdate_day", "f_usr_birthdate_month", "f_usr_birthdate_year", "f_cr_disposition", "f_cr_price_show", "f_cr_app_blocked",
                        "f_cmp_contract_date_day", "f_cmp_contract_date_month", "f_cmp_contract_date_year", 
                        "f_cr_imei", "f_cr_serialno", "f_cr_mobile_pda", "f_cmp_remark", "f_cmp_remark2", "f_cmp_freetext1", "f_cmp_visible", "f_cmp_no_longhaul",
                        "f_noaddressvalidation", "deactivateMenu", "objecttypemode");

$httpVarsArray = array_merge ($httpVars, $httpVisualVars);

getSecHttpVars("1", $httpVarsArray);

getLanguage(__FILE__);

$deactivateMenuStatic = "1";
if ($objecttypemode == "") : $objecttypemode = "cr"; endif;
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);

// Check for authentication access and granted rights
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
authCheckEmployeeRights($emp_id, "1", "1");

// Check handling of the type of the customer
$f_cmp_current_type = getFieldValueFromId("company", "cmp_id", $companyId, "cmp_type");
if ($f_cmp_type == "") : $f_cmp_type = $f_cmp_current_type; endif;
if ($f_cmp_type == "") : $f_cmp_type = "0"; endif;

$addressValidationErr = "";

// Check for validation of the address assigned to the customer
$noValidationOfAddress = FALSE;
if ($f_noaddressvalidation != "") :
   if ($f_noaddressvalidation[0] == '1') : $noValidationOfAddress = TRUE; endif;
endif;

// Init parameters
if ($f_vht_id_inv == "0") : $f_vht_id_inv = ""; endif;
$f_usr_birthdate = "0000-00-00";
if ($f_usr_birthdate_year != "" && $f_usr_birthdate_month != "" && $f_usr_birthdate_day != "") :
  $f_usr_birthdate = $f_usr_birthdate_year . "-" . pad($f_usr_birthdate_month, 2, "0") . "-" . pad($f_usr_birthdate_day, 2, "0");
endif;
$f_cmp_contract_date = "0000-00-00";
if ($f_cmp_contract_date_year != "" && $f_cmp_contract_date_month != "" && $f_cmp_contract_date_day != "") :
  $f_cmp_contract_date = $f_cmp_contract_date_year . "-" . pad($f_cmp_contract_date_month, 2, "0") . "-" . pad($f_cmp_contract_date_day, 2, "0");
endif;
$f_cr_id = "";
$f_cmp_authenticated2 = 0;
$f_cmp_visible2 = 0;
$importPath = "";
$execEmbargoCheck = "0";  // Parameter for executing the personal embargo request
mcIsSet($cs_id_new); mcIsSet($cmpId); mcIsSet($eid); mcIsSet($usrName); mcIsSet($usrFirstname); mcIsSet($adStreet); mcIsSet($cmpHsno);
mcIsSet($adZipcode); mcIsSet($adCity); mcIsSet($oldDpfChecksum); mcIsSet($phpCurrentNavigationInputHidden); mcIsSet($adCity);
if ($f_cr_id_parent == "") : $f_cr_id_parent = "0"; endif;
if ($f_cr_maxweight == "") : $f_cr_maxweight = "0"; endif;
if ($f_cr_outlay == "") : $f_cr_outlay = "0"; endif;
if ($f_cr_available == "") : $f_cr_available = "0"; endif;

// Only for output
// $htmlClass01 = "class=\"smaller\"";                // input,select
$htmlClass01 = "";
$html_td_01  = "valign=\"top\" align=\"left\"";    // input
$html_td_02  = "valign=\"top\" align=\"right\"";   // input

// Get current global number of THIS database instance
$constProductionMode = getParameterValue("0", "GLOBAL_PRODUCTION_STATE", "0", "0");
if ($constProductionMode == "TEST") :
   $constGlobalDbInstNo = "100";
else :
   // $constGlobalDbInstNo = getParameterValue("0", "GLOBAL_UNIQUE_DB_INSTANCE_NO", "0", "0");
   $constGlobalDbInstNo = getGlobalUniqueDbInstanceNo();
endif;

// Get external databases (e.g. APP properties, mobile data, etc.)
$dbhostArray = getGlobalDbEnvironments("meta_object", "metaobject", false);
$dbhostArrayLen = count($dbhostArray);
$dbConnectionArray = array();
if ($dbhostArrayLen > 0) :
   $dbConnectionArray["app_property"] = getDbConnectionSpecial($dbhostArray["as_intern"], "sysadmin", $dblogin, $dbpassword);   // Change if migrated to another place
endif;

// Flag for "own disposition"
if ($f_cr_disposition == "" || count($f_cr_disposition) == 0) :
   $f_cr_disposition = "0";
else: 
   $f_cr_disposition = "1";
endif;

// Flag for "own disposition"
if ($f_cr_app_blocked == "" || count($f_cr_app_blocked) == 0) :
   $f_cr_app_blocked = "0";
else: 
   $f_cr_app_blocked = "1";
endif;

// Flag for displaying cartage in the app
if ($f_cr_price_show == "" || count($f_cr_price_show) == 0) :
   $f_cr_price_show = "0";
else: 
   $f_cr_price_show = "1";
endif;

// Flag for no longhaul
if ($f_cmp_no_longhaul == "" || count($f_cmp_no_longhaul) == 0) :
   $f_cmp_no_longhaul = "0";
else: 
   $f_cmp_no_longhaul = "1";
endif;

// Check displaying mode for field "cr_mobile_pda"
$parMaskCrMobilePdaEdit = getParameterValue("0", "MASK_CR_MOBILE_PDA_EDIT", $hq_id);
if ($parMaskCrMobilePdaEdit == "") :
   $parMaskCrMobilePdaEdit = getParameterValue("0", "MASK_CR_MOBILE_PDA_EDIT", "0");
endif;

// Check for displaying report button for drivers associated to a parent carrier
$parMaskCrReportsHideForDriver = getParameterValue("0", "MASK_CR_REPORT_DRIVER_HIDE", $hq_id);
if ($parMaskCrReportsHideForDriver == "") :
   $parMaskCrReportsHideForDriver = getParameterValue("0", "MASK_CR_REPORT_DRIVER_HIDE", "0");
endif;

// Get min length of the EID
$parMaskCrEidMinLength = getParameterValue("0", "MASK_COURIER_EID_LENGTH", $hq_id);
if ($parMaskCrEidMinLength == "") :
   $parMaskCrEidMinLength = getParameterValue("0", "MASK_COURIER_EID_LENGTH", "0");
endif;

// Get max length of the EID
$parMaskCrEidMaxLength = getParameterValue("0", "MASK_COURIER_EID_MAX_LENGTH", $hq_id);
if ($parMaskCrEidMaxLength == "") :
   $parMaskCrEidMaxLength = getParameterValue("0", "MASK_COURIER_EID_MAX_LENGTH", "0");
endif;

// Get mask parameter
$maskHideCrVhtInv = getParameterValue("0", "MASK_HIDE_CR_VHT_INV", $hq_id);
if ($maskHideCrVhtInv == "") : 
   $maskHideCrVhtInv = getParameterValue("0", "MASK_HIDE_CR_VHT_INV", "0");
endif;

// Check displaying mode for cartage matrix
$parMaskCrCartageLinksDisabled = getParameterValue("0", "MASK_CR_CARTAGE_LINKS_DISABLED", $hq_id);
if ($parMaskCrCartageLinksDisabled == "") :
   $parMaskCrCartageLinksDisabled = getParameterValue("0", "MASK_CR_CARTAGE_LINKS_DISABLED", "0");
endif;


// Check mandatory fields to be filled
$checkMandatoryFieldsCr = "";

function checkMandatoryFieldsCr () {
  global $f_cmp_comp, $f_cmp_contract_date_day, $f_cmp_contract_date_month, $f_cmp_contract_date_year;
  global $f_usr_name, $f_usr_firstname, $f_usr_phone, $f_usr_account, $parMaskCrMobilePdaEdit, $f_cr_mobile_pda;
  global $f_ad_street, $f_ad_zipcode, $f_ad_city, $f_cmp_hsno, $maskHideCrVhtInv, $f_vht_id_inv, $f_cmp_tax_idno, $f_cr_sid, $f_cr_eid, $f_cr_serialno;
  $retStr = "";
  $bgcol = "'red'";
/*
  if ($f_cmp_comp == "") {$retStr .= "$('#f_cmp_comp').css('background-color', " . $bgcol . ");";};
  if ($f_usr_name == "") {$retStr .= "$('#f_usr_name').css('background-color', " . $bgcol . ");";};
  if ($f_usr_firstname == "") {$retStr .= "$('#f_usr_firstname').css('background-color', " . $bgcol . ");";};
  if ($f_usr_phone == "") {$retStr .= "$('#f_usr_phone').css('background-color', " . $bgcol . ");";};
  if ($f_usr_account == "") {$retStr .= "$('#f_usr_account').css('background-color', " . $bgcol . ");";};
  if ($f_ad_street == "") {$retStr .= "$('#f_ad_street').css('background-color', " . $bgcol . ");";};
  if ($f_cmp_hsno == "") {$retStr .= "$('#f_cmp_hsno').css('background-color', " . $bgcol . ");";};
  if ($f_ad_zipcode == "") {$retStr .= "$('#f_ad_zipcode').css('background-color', " . $bgcol . ");";};
  if ($f_ad_city == "") {$retStr .= "$('#f_ad_city').css('background-color', " . $bgcol . ");";};
  if ($f_cmp_tax_idno == "") {$retStr .= "$('#f_cmp_tax_idno').css('background-color', " . $bgcol . ");";};
  if (!(CR_SID_STATUS == "0" || $f_cr_sid != "")) {$retStr .= "$('#f_cr_sid').css('background-color', " . $bgcol . ");";};
  if ($f_cr_eid == "") {$retStr .= "$('#f_cr_eid').css('background-color', " . $bgcol . ");";};
  if ($f_cr_serialno == "") {$retStr .= "$('#f_cr_serialno').css('background-color', " . $bgcol . ");";};
  // if ($xxxxxxxx == "") {$retStr .= "$('#xxxxxxxx').css('background-color', " . $bgcol . ");";};  
  if (!($parMaskCrMobilePdaEdit != "1" || $f_cr_mobile_pda != "")) {$retStr .= "$('#f_cr_mobile_pda').css('background-color', " . $bgcol . ");";};
  if (!($maskHideCrVhtInv == "1" || $f_vht_id_inv != "")) {$retStr .= "$('#f_vht_id_inv').css('background-color', " . $bgcol . ");";};
*/

  return $retStr;
}



   // *******************************
   // * Operations for the couriers *   
   // *******************************

   // Generate log string
   if ($f_act != "") :
      $f_usr_name = trim($f_usr_name);
      $f_usr_firstname = trim($f_usr_firstname);
      $f_usr_email = trim($f_usr_email);

      // Set coordinates for home zipcode or fallback address zipcode
      if ($f_act == "newCourier") :
         list($f_cr_gps_lat_home, $f_cr_gps_long_home) = setCrHomeCoordinatesByZipcode($f_cr_homezipcode, $f_ad_zipcode);
      elseif ($f_act == "modifyCourier" && $companyId != "") :
         list($f_cr_gps_lat_home, $f_cr_gps_long_home) =  setCrHomeCoordinatesByZipcode($f_cr_homezipcode, $f_ad_zipcode, $companyId, "cmp");
      endif;

      $logString = makeLogString(array($f_cmp_authenticated,$f_cmp_comp,$f_cmp_comp2,$f_usr_name,$f_usr_firstname,$f_usr_phone,
                                       $f_usr_phone2,$f_usr_fax,$f_usr_email,$f_cr_sid,$f_cr_eid,$f_vht_id_inv,$f_cr_maxweight,
                                       $f_cr_outlay,$f_cmp_iln,$f_cmp_tax_idno,$f_cmp_bank,$f_cmp_bankno,$f_cmp_bankacc,
                                       $f_cmp_bankmode,$f_usr_account,$f_ad_street,$f_cmp_hsno,$f_ad_zipcode,$f_ad_city,
                                       $f_ad_country,$f_cr_eid_parent,$f_cr_vh_sign,$f_cr_imei,$f_cr_mobile_pda,
                                       $f_cmp_remark,$f_cmp_remark2,$f_usr_birthdate,$f_cmp_stax_idno,$f_cmp_iban,$f_cmp_swift,
                                       $f_usr_inv_email,$f_cr_disposition,$f_usr_country,$f_cmp_freetext1,$f_cr_price_show,
                                       $f_cr_serialno, $f_cmp_contract_date, $f_cr_homezipcode, $f_cr_app_blocked,
                                       $f_cr_gps_long_home, $f_cr_gps_lat_home, $f_cmp_no_longhaul), ";", "0");
   endif;

   // Insert new courier
   if ($f_act == "newCourier") :

      // Check mandatory fields to be filled
      $checkMandatoryFieldsCr = checkMandatoryFieldsCr();
      if ($checkMandatoryFieldsCr == "") :

          // Parameter für checking company name
          $parChkCmpDisabled = getParameterValue("0", "MASK_CR_CHK_CMP_EXIST_DISABLED", "0");
         
         // Check unique account for all couriers (all data) except the current one to be updated
         if ($db->getOne("SELECT usr.usr_id FROM user AS usr WHERE usr.usr_account = '" . $f_usr_account . "' ")) :
            $statusMessage = "Der Benutzername existiert schon! Bitte wählen Sie einen anderen!";

         elseif ($parChkCmpDisabled != "1" && $db->getOne("SELECT cmp.cmp_comp FROM company AS cmp, courier AS cr WHERE cmp.cmp_comp = '" . $f_cmp_comp . "' AND cmp.cmp_id = cr.cmp_id AND cr.hq_id = '" . $hq_id . "'")) :
                $statusMessage = getLngt("Der Firmenname ist bereits vorhanden! Bitte wählen Sie einen anderen!");            
                                                
         // elseif ($db->getOne("SELECT cr_sid FROM courier WHERE cr_sid = '" . $f_cr_sid . "'")) :
         //        $statusMessage = "Die systemweit eindeutige Kuriernummer ist bereits vergeben! Bitte wählen Sie eine andere";
         elseif (CR_SID_STATUS == "1" && $db->getOne("SELECT cr_sid FROM courier WHERE cr_sid = '" . $f_cr_sid . "' AND hq_id = '" . $hq_id . "'")) :
                $statusMessage = getLngt("Die eindeutige Kuriernummer (SID) ist bereits vergeben! Bitte wählen Sie eine andere");
                
         elseif ($db->getOne("SELECT cr_eid FROM courier WHERE cr_eid = '" . $f_cr_eid . "' AND hq_id = '" . $hq_id . "'")) :
                $statusMessage = getLngt("Die eindeutige Kuriernummer (ExtID) ist bereits vergeben! Bitte wählen Sie eine andere");
               
         elseif (checkPasswordValidation($f_usr_password,$f_usr_password2)) : 
                        
            $addressValid = getGeoCoordinates($f_ad_street, $f_ad_zipcode, $f_ad_city, $f_cmp_hsno, $f_ad_country, "");            
            if ($addressValid != "") :                        
                        
                // Check zipcode and city
                $addressValidityArray = checkCityZipcode($f_ad_zipcode, $f_ad_city, $f_ad_street);
                if ($noValidationOfAddress || $addressValidityArray[0] >= 1) :                        
                        
                   TA("B");
                   
                   $currentTime = getDateTime("0");

                   // Insert user
                   $sqlStmtPwd = "INSERT INTO user (hq_id,usr_type,usr_name,usr_firstname,usr_email,usr_inv_email,usr_phone,usr_phone2,usr_fax,usr_account,usr_password,usr_password_modify,usr_birthdate,usr_country)" .
                                     " VALUES ($hq_id,'3','$f_usr_name','$f_usr_firstname','$f_usr_email','$f_usr_inv_email','$f_usr_phone','$f_usr_phone2','$f_usr_fax','$f_usr_account',PASSWORD('$f_usr_password'),'$currentTime','$f_usr_birthdate','$f_usr_country')";
                   // writeDbLog($sqlStmtPwd);
                   $res = $db->query($sqlStmtPwd);
                   if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif;                                     
                   $usr_id_new = getLastInsertID(); 

                   // Insert company
                   insertStmt("company", array("cmp_type", $f_cmp_type, "cmp_comp", $f_cmp_comp, "cmp_comp2", $f_cmp_comp2, "cmp_comp3", "", "cmp_comp4", "",
                              "cmp_hsno", $f_cmp_hsno, "cmp_iln", $f_cmp_iln, "cmp_tax_idno", $f_cmp_tax_idno, "cmp_stax_idno", $f_cmp_stax_idno, 
                              "cmp_bank", $f_cmp_bank, "cmp_bankno", $f_cmp_bankno, "cmp_bankacc", $f_cmp_bankacc, "cmp_iban", $f_cmp_iban, "cmp_swift", $f_cmp_swift,
                              "cmp_authenticated", "1", "cmp_visible", "1", "cmp_no_longhaul", $f_cmp_no_longhaul, "cmp_remark", $f_cmp_remark, "cmp_remark2", $f_cmp_remark2, "cmp_freetext1", $f_cmp_freetext1,
                              "cmp_new_date", $currentTime, "cmp_contract_date", $f_cmp_contract_date, "cmp_modify_status", "1"));
                   $cmp_id_new = getLastInsertId();

                   // Check for mobile number
                   $writeLogCrMobilePda = false;
                   if ($parMaskCrMobilePdaEdit != "1" && $dbhostArrayLen > 0 && $dbConnectionArray["app_property"] != "") :
                      // Remove potential old association of the new number if it is NOT empty
                      $crEidWithSameMobileNo = "";
                      if ($f_cr_mobile_pda != "") :
                         $crIdWithMobileSameNo = getFieldValueFromId("courier", "cr_mobile_pda", $f_cr_mobile_pda, "cr_id");
                         if ($crIdWithMobileSameNo != "") :
                            updateStmt("courier","cr_id",$crIdWithMobileSameNo,array("cr_mobile_pda", ""));
                            $crEidWithSameMobileNo = getFieldValueFromId("courier", "cr_id", $crIdWithMobileSameNo, "cr_eid");
                            $statusMessage = getLngt("Die Mobilnummer wurde beim folgendem " . wrapPhrase("Transporteur", $objecttypemode) . " entfernt:") . " " . $crEidWithSameMobileNo;
                         endif;
                      endif;
                      $remDb = $db;
                      $db = $dbConnectionArray["app_property"];
                      // Make new association
                      updateStmt("sysadmin.conf_prop", "cp_secval", $f_cr_mobile_pda, array("usr_id", $usr_id_new), "cust_id = '" . $constGlobalDbInstNo . "' AND prop_id = '1' AND cp_secval != ''");
                      $db = $remDb;
                      // Write logdata into log database
                      $writeLogCrMobilePda = true;
                   endif;

                   // Insert courier
                   // [MC 20250908] :: Following phrase removed from following statement: "cr_sid", $f_cr_sid, 
                   insertStmt("courier", array("cmp_id", $cmp_id_new, "hq_id", $hq_id, "usr_id", $usr_id_new, "cr_eid", $f_cr_eid, 
                                               "cr_id_parent", $f_cr_id_parent, "vht_id", "0", "vht_id_inv", $f_vht_id_inv, "cr_filter", "", "cr_vh_sign", $f_cr_vh_sign, 
                                               "cr_imei", $f_cr_imei, "cr_serialno", $f_cr_serialno, "cr_mobile_pda", $f_cr_mobile_pda, "cr_device_info", "", "cr_maxweight", $f_cr_maxweight,
                                               "cr_outlay", $f_cr_outlay, "cr_locationzipcode", "", "cr_homezipcode", $f_cr_homezipcode, "cr_gps_long_home", $f_cr_gps_long_home, "cr_gps_lat_home", $f_cr_gps_lat_home, "cr_ar_jb_id", "0", "cr_available", $f_cr_available, "cr_mobile_cell", "",
                                               "cr_disposition", $f_cr_disposition, "cr_price_show", $f_cr_price_show, "cr_app_blocked", $f_cr_app_blocked));
                   $cr_id_new = getLastInsertId();
                   
                   // SET filter "VA" if $f_cr_app_blocked == "0"
                   if ($f_cr_app_blocked == "0") :
                      updateStmt("courier","cr_id",$cr_id_new,array("cr_filter", ",VA,"));
                   endif;
                   
                   // Write log for changed mobile PDA with new cr_id
                   if ($writeLogCrMobilePda) :
                       writeToLogDB("117",$hq_id,"",$usr_id,$cr_id_new,"","","MSISDN_OLD=|MSISDN_NEW=" . $f_cr_mobile_pda . "|CR_EID_OLD=" . $crEidWithSameMobileNo);
                   endif;

                   // Insert address                
                   $tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
                   $ad_id_new = $tmpArray[0];

                   // Update (the new) company-entry with address-id
                   updateStmt("company", "cmp_id", $cmp_id_new, array("ad_id", $ad_id_new));

                   // Automatischer E-Mail-Versand eines systemgenerierten Passwortes ???
                
                   // Write logdata into log database
                   writeToLogDB("35",$hq_id,"",$usr_id,$cr_id_new,"","","OBJ_TYPE=CR|STATUS_NEW=" . $logString);
                
                   TA("C");
                   TA("E");


                   // ********** DPF **********

                   // Check according to personal embargo
                   // (NOT included in transaction)
                   $constDPFCourierEnabled = getParameterValue("0", "DPF_CR_ENABLED", "0");  // "Meta-Global" <=> hq_id = 0
                   if ($constDPFCourierEnabled == '1') :
                      $execEmbargoCheck = "1";
                      $cmpId = $cmp_id_new;
                      $eid = $f_cr_eid;
                      $usrName = $f_usr_name;
                      $usrFirstname = $f_usr_firstname;
                      $adStreet = $f_ad_street;
                      $cmpHsno = $f_cmp_hsno;
                      $adZipcode = $f_ad_zipcode;
                      $adCity = $f_ad_city;
                      // = $f_ad_country;
                      
                      // Check for DPF checksum
                      $oldDpfChecksum = "";
                      $newDpfChecksum = md5($usrFirstname . $usrName . $adStreet . $cmpHsno . $adZipcode . $adCity);
                      updateStmt("company", "cmp_id", $cmp_id_new, array("cmp_dpf_checksum", $newDpfChecksum));
                   endif;


                   // ********** HASH **********
                   // Check for execute functionality
                   if ($GLOBAL_USAGE_HASH) :
                      // Get current global number of THIS database instance
                      
                      $constProductionMode = getParameterValue("0", "GLOBAL_PRODUCTION_STATE", "0", "0");
                      if ($constProductionMode == "TEST") :
                         $constGlobalDbInstNo = "100";
                      else :
                         // $constGlobalDbInstNo = getParameterValue("0", "GLOBAL_UNIQUE_DB_INSTANCE_NO", "0", "0");
                         $constGlobalDbInstNo = getGlobalUniqueDbInstanceNo();
                      endif;
                      if ($constGlobalDbInstNo != "" && is_numeric($constGlobalDbInstNo)) :
                         // Generate unique hash value e.g. for newsletter of the courier
                         $tmpHashCR = makeMD5Hash($hq_id, $cr_id_new, $currentTime);
                         // Generate unique hash value e.g. for timetracking of the user
                         $tmpHashUSR = makeMD5Hash($hq_id, $usr_id_new, $currentTime);
                      
                         // Get database instance connection data of metaobject
                         $constExtDbInst = getExternalMetaDbInst();
                         $db_conn = getDbConnectionSpecial($constExtDbInst, $dbname, $dblogin, $dbpassword);
                         $tmpSqlQuery = "INSERT meta_object.metaobject (mo_id_ref_db,mo_mnemonic,mo_name,mo_obj_type,mo_obj_id,mo_hash) VALUES ('" . $constGlobalDbInstNo . "','','','cr','" . $cr_id_new . "','" . $tmpHashCR . "') ";                                                  
                         $result = $db_conn->query($tmpSqlQuery);
                         $err = "";
                         if (DB::isError($result)) {$err = "ERR";};
                         if ($err == "ERR") :
                            // Message to system administrator...
                            // $statusMessage = getLngt("Message to system administrator...!");
                         endif;

                         $tmpSqlQuery = "INSERT meta_object.metaobject (mo_id_ref_db,mo_mnemonic,mo_name,mo_obj_type,mo_obj_id,mo_hash) VALUES ('" . $constGlobalDbInstNo . "','','','usr','" . $usr_id_new . "','" . $tmpHashUSR . "') ";
                         $result = $db_conn->query($tmpSqlQuery);
                         $err = "";
                         if (DB::isError($result)) {$err = "ERR";};
                         if ($err == "ERR") :
                            // Message to system administrator...
                            // $statusMessage = getLngt("Message to system administrator...!");
                         endif;
                      endif;
                   endif;

                   // Reset fields of form-parameters
                   clearParameters($httpVisualVars);
                   $f_usr_birthdate = "";
                   $f_cmp_contract_date = "";

                   $statusMessage = getLngt("Der Datensatz wurde gespeichert!");
                else :
                  $statusMessage = getLngt("Die Postleitzahl passt nicht zu dem angegebenen Ort!");
                  $addressValidationErr = "1";
                endif;
                                 
            else :
              $statusMessage = getLngt("Der Adress-Server kennt die eingebene Adresse nicht oder besitzt keine Geocodierung!");
            endif;                 
                 
         endif;
      else :
         $statusMessage = getLngt("Bitte geben Sie alle mit * gekennzeichneten Felder ein!");
      endif;
   endif;            

   // Modify courier
   if ($f_act == "modifyCourier" && $companyId != "") :

      // Check mandatory fields to be filled
      $checkMandatoryFieldsCr = checkMandatoryFieldsCr();
      if ($checkMandatoryFieldsCr == "") :

         if ($db->getOne("SELECT usr.usr_id FROM user AS usr WHERE usr.usr_account = '" . $f_usr_account . "' AND usr.usr_id != $f_usr_id")) :
            $statusMessage = getLngt("Der Benutzername existiert schon! Bitte wählen Sie einen anderen!");
                       
         else : 
            $sqlquery = "SELECT cmp.cmp_comp, cr.cr_id, usr.usr_id, cr.cr_mobile_pda " 
                      . " FROM user AS usr, courier AS cr, company AS cmp"
                      . " WHERE cmp.cmp_id = " . $companyId
                      . "   AND cr.cmp_id = cmp.cmp_id"
                      . "   AND usr.usr_id = cr.usr_id";                      
            $result = $db->query($sqlquery);
            if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
            while ($row = $result->fetch_assoc()):
                  $v_cmp_comp = $row["cmp_comp"];
                  $v_cr_id = $row["cr_id"];
                  $v_usr_id = $row["usr_id"];
                  $v_cr_mobile_pda = $row["cr_mobile_pda"];
            endwhile;
            $result->free();                      
         
            if ($v_cr_id != "" && $v_usr_id != "") :
            
               if (CR_SID_STATUS == "1" && $db->getOne("SELECT cr_sid FROM courier WHERE cr_sid = '" . $f_cr_sid . "' AND " 
                                                             . " NOT (cr_id = '" . $v_cr_id . "') AND "
                                                             . " hq_id = '" . $hq_id . "'")) :
                  $statusMessage = getLngt("Die eindeutige Kuriernummer (SID) ist bereits vergeben! Bitte wählen Sie eine andere");
                  
               elseif ($db->getOne("SELECT cr_eid FROM courier WHERE cr_eid = '" . $f_cr_eid . "' AND " 
                                                             . " NOT (cr_id = '" . $v_cr_id . "') AND "
                                                             . " hq_id = '" . $hq_id . "'")) :
                  $statusMessage = getLngt("Die eindeutige Kuriernummer (ExtID) ist bereits vergeben! Bitte wählen Sie eine andere");
                  
               else :
                        
                  $addressValid = getGeoCoordinates($f_ad_street, $f_ad_zipcode, $f_ad_city, $f_cmp_hsno, $f_ad_country, "");            
                  if ($addressValid != "") :     
               
                     // Check zipcode and city
                     $addressValidityArray = checkCityZipcode($f_ad_zipcode, $f_ad_city, $f_ad_street);
                     if ($noValidationOfAddress || $addressValidityArray[0] >= 1) :               
               
                        TA("B");

                        // Get current state in cmp_modify_status because it is equal to "1" then do NOT change                        
                        $modifyStatus = getFieldValueFromId("company", "cmp_id", $companyId, "cmp_modify_status");
                        if ($modifyStatus != "1") : $modifyStatus = "2"; endif;
            
                        // Update company                                                                                                                                  
                        $defaultFields = array("cmp_type", $f_cmp_type,"cmp_comp",$f_cmp_comp,"cmp_comp2",$f_cmp_comp2,"cmp_hsno",$f_cmp_hsno,"cmp_iln",$f_cmp_iln,"cmp_tax_idno",$f_cmp_tax_idno,"cmp_stax_idno",$f_cmp_stax_idno,
                                               "cmp_bank",$f_cmp_bank,"cmp_bankno",$f_cmp_bankno,"cmp_bankacc",$f_cmp_bankacc,"cmp_iban",$f_cmp_iban,"cmp_swift",$f_cmp_swift, "cmp_no_longhaul", $f_cmp_no_longhaul,
                                               "cmp_remark",$f_cmp_remark,"cmp_remark2",$f_cmp_remark2,"cmp_freetext1",$f_cmp_freetext1,"cmp_contract_date",$f_cmp_contract_date,"cmp_modify_status",$modifyStatus);
                        updateStmt("company","cmp_id",$companyId,$defaultFields);

                        // Update courier mobile number and remove old association if does exist and update usr_id in meta table "conf_prop" for mobile client association
                        if ($parMaskCrMobilePdaEdit != "1" && $dbhostArrayLen > 0 && $dbConnectionArray["app_property"] != "") :
                           if ($v_cr_mobile_pda != $f_cr_mobile_pda) :
                              // Remove potential old association of the new number if it is NOT empty
                              $crEidWithSameMobileNo = "";
                              if ($f_cr_mobile_pda != "") :
                                 $crIdWithMobileSameNo = getFieldValueFromId("courier", "cr_mobile_pda", $f_cr_mobile_pda, "cr_id");
                                 if ($crIdWithMobileSameNo != "" && $crIdWithMobileSameNo != $v_cr_id) :
                                    updateStmt("courier","cr_id",$crIdWithMobileSameNo,array("cr_mobile_pda", ""));
                                    $crEidWithSameMobileNo = getFieldValueFromId("courier", "cr_id", $crIdWithMobileSameNo, "cr_eid");
                                    $statusMessage = getLngt("Die Mobilnummer wurde beim folgendem " . wrapPhrase("Transporteur", $objecttypemode) . " entfernt:") . " " . $crEidWithSameMobileNo;
                                 endif;
                              endif;
                              $remDb = $db;
                              $db = $dbConnectionArray["app_property"];
                              // Remove current association
                              updateStmt("sysadmin.conf_prop", "cp_secval", $v_cr_mobile_pda, array("usr_id", ''), "cust_id = '" . $constGlobalDbInstNo . "' AND prop_id = '1' AND cp_secval != ''");
                              // Make new association
                              updateStmt("sysadmin.conf_prop", "cp_secval", $f_cr_mobile_pda, array("usr_id", $v_usr_id), "cust_id = '" . $constGlobalDbInstNo . "' AND prop_id = '1' AND cp_secval != ''");
                              $db = $remDb;
                              // Write logdata into log database
                              writeToLogDB("117",$hq_id,"",$usr_id,$v_cr_id,"","","MSISDN_OLD=" . $v_cr_mobile_pda . "|MSISDN_NEW=" . $f_cr_mobile_pda . "|CR_EID_OLD=" . $crEidWithSameMobileNo);
                           else : 
                              $remDb = $db;
                              $db = $dbConnectionArray["app_property"];
                              // Make new association
                              updateStmt("sysadmin.conf_prop", "cp_secval", $f_cr_mobile_pda, array("usr_id", $v_usr_id), "cust_id = '" . $constGlobalDbInstNo . "' AND prop_id = '1' AND cp_secval != ''");
                              $db = $remDb;
                              // Write logdata into log database
                              writeToLogDB("117",$hq_id,"",$usr_id,$v_cr_id,"","","MSISDN_OLD=" . $v_cr_mobile_pda . "|MSISDN_NEW=" . $f_cr_mobile_pda . "|CR_EID_OLD=IDENT");
                           endif;
                        endif;

                        // Update courier (with new mobile number)
                        // [MC 20250908] :: Following phrase removed from following statement: "cr_sid", $f_cr_sid,
                        $defaultFields = array("cr_eid", $f_cr_eid, "vht_id_inv", $f_vht_id_inv,
                                               "cr_maxweight", $f_cr_maxweight, "cr_outlay", $f_cr_outlay, "cr_homezipcode", $f_cr_homezipcode, "cr_gps_long_home", $f_cr_gps_long_home, "cr_gps_lat_home", $f_cr_gps_lat_home,
                                               "cr_id_parent", $f_cr_id_parent, "cr_vh_sign", $f_cr_vh_sign,
                                               "cr_imei", $f_cr_imei, "cr_serialno", $f_cr_serialno, "cr_mobile_pda", $f_cr_mobile_pda, "cr_disposition", $f_cr_disposition, "cr_price_show", $f_cr_price_show,
                                               "cr_app_blocked", $f_cr_app_blocked);
                        updateStmt("courier","cr_id",$v_cr_id,$defaultFields);

                        // REMOVE filter "VA" if $f_cr_app_blocked == "1" otherwise SET filter
                        $crFilter = getFieldValueFromId("courier", "cr_id", $v_cr_id, "cr_filter");
                        if ($f_cr_app_blocked == "1") :
                           $crFilter = removeItemFromFilterstringWithCommata($crFilter, "VA");
                           updateStmt("courier","cr_id",$v_cr_id,array("cr_filter", $crFilter));
                        else :
                           if ($crFilter != "") :
                              if (strpos($crFilter, ",VA,") === false) :
                                 updateStmt("courier","cr_id",$v_cr_id,array("cr_filter", $crFilter . "VA,"));
                              endif;
                           else :
                              updateStmt("courier","cr_id",$v_cr_id,array("cr_filter", ",VA,"));
                           endif;
                        endif;

                        // Update user
                        $defaultFields = array("usr_name",$f_usr_name,"usr_firstname",$f_usr_firstname,"usr_email",$f_usr_email,"usr_inv_email",$f_usr_inv_email,"usr_phone",$f_usr_phone,"usr_phone2",$f_usr_phone2,"usr_fax",$f_usr_fax,"usr_account",$f_usr_account,"usr_birthdate",$f_usr_birthdate,"usr_country",$f_usr_country);
                        updateStmt("user","usr_id",$v_usr_id,$defaultFields);

                        // Get current address associated to the customer
                        $currAdress = getAddress($companyId, "company");

                        if ($currAdress["street"] != $f_ad_street || $currAdress["hsno"] != $f_cmp_hsno || $currAdress["zipcode"] != $f_ad_zipcode || $currAdress["city"] != $f_ad_city) :
                           $statusMessage .= getLngt("Die Adresse hat sich geändert. Haben sie eine neue Steuernummer und Gewerbeummeldung angefordert?");
                        endif;

                        // Insert address                
                        $tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
                        $ad_id_new = $tmpArray[0];
                
                        // Update (the new) company-entry with address-id
                        updateStmt("company", "cmp_id", $companyId, array("ad_id", $ad_id_new));
                  
                        // Write logdata into log database
                        writeToLogDB("37",$hq_id,"",$usr_id,$v_cr_id,"","","OBJ_TYPE=CR|STATUS_MODIFIED=" . $logString);

                        // Senbd logout-command to app server in case the courier is blocked for using the app
                        if ($f_cr_app_blocked == "1") :
                           $f_act = "logoutCourier";
                        endif;
                  
                        TA("C");
                        TA("E");


                        // ********** DPF **********

                        // Check according to personal embargo
                        // (NOT included in transaction)
                        $constDPFCourierEnabled = getParameterValue("0", "DPF_CR_ENABLED", "0");  // "Meta-Global" <=> hq_id = 0
                        if ($constDPFCourierEnabled == '1') :
                           $execEmbargoCheck = "1";
                           $cmpId = $companyId;
                           $eid = $f_cr_eid;
                           $usrName = $f_usr_name;
                           $usrFirstname = $f_usr_firstname;
                           $adStreet = $f_ad_street;
                           $cmpHsno = $f_cmp_hsno;
                           $adZipcode = $f_ad_zipcode;
                           $adCity = $f_ad_city;
                           // = $f_ad_country;

                           // Check for DPF checksum
                           $oldDpfChecksum = getFieldValueFromId("company", "cmp_id", $companyId, "cmp_dpf_checksum");
                           $newDpfChecksum = md5($usrFirstname . $usrName . $adStreet . $cmpHsno . $adZipcode . $adCity);
                           if ($oldDpfChecksum == $newDpfChecksum) :
                              $execEmbargoCheck = "0";
                           else :
                              updateStmt("company", "cmp_id", $companyId, array("cmp_dpf_checksum", $newDpfChecksum));
                           endif;
                        endif;
                   
                     else :
                       $statusMessage = getLngt("Die Postleitzahl passt nicht zu dem angegebenen Ort!");
                       $addressValidationErr = "1";
                     endif;               
               
                  else :
                    $statusMessage = getLngt("Der Adress-Server kennt die eingebene Adresse nicht oder besitzt keine Geocodierung!");
                  endif;                           
                  
               endif;
               
            else : 
               $statusMessage = getLngt("Datenfehler! Merken Sie sich bitte den Datensatz und kontaktieren uns!!!");
            endif;
         endif;        
      else :
         $statusMessage = getLngt("Bitte geben Sie alle mit * gekennzeichneten Felder ein!");
      endif;                                                            
   endif;
   
   // Delete courier
   if ($f_act == "removeCourier" && $companyId != "") :
  
      // Get courier ID and user ID from the company ID
      $sqlquery = "SELECT cr.cr_id, usr.usr_id " 
                . " FROM user AS usr, courier AS cr, company AS cmp"
                . " WHERE cmp.cmp_id = " . $companyId
                . "   AND cr.cmp_id = cmp.cmp_id"
                . "   AND usr.usr_id = cr.usr_id";                      
      $result = $db->query($sqlquery);
      if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
      while ($row = $result->fetch_assoc()):
            $v_cr_id = $row["cr_id"];
            $v_usr_id = $row["usr_id"];
      endwhile;
      $result->free();

      if ($v_cr_id != "" && $v_usr_id != "") :

         // Check existence of reference(s) in job
         $numOfJobs = getCountOfTable("job", $whereClause = "cr_id = '" . $v_cr_id . "'");
         if ($numOfJobs <= 0) :

            // Check existence of vehicles
            $numOfVehicles = getCountOfTable("couriervehicle", $whereClause = "cr_id = '" . $v_cr_id . "'");
            if ($numOfVehicles <= 0) : 

               if (!existsEntry("courier",array("cr_id_parent",$v_cr_id))) :

                  TA("B");

                  deleteStmt("courierdatatransfer","cr_id = ".$v_cr_id);
                  deleteStmt("customercourier","cr_id = ".$v_cr_id);
                  deleteStmt("user","usr_id = ".$v_usr_id . " AND hq_id = '" . $hq_id . "'");
                  deleteStmt("company","cmp_id = ".$companyId);
                  updateStmt("courier","cr_id_parent",$v_cr_id,array("cr_id_parent",""));
                  deleteStmt("courier","cr_id = ".$v_cr_id . " AND hq_id = '" . $hq_id . "'");

                  // Write logdata into log database
                  writeToLogDB("43",$hq_id,"",$usr_id,$v_cr_id,"","","STATUS_DELETED");   

                  TA("C");
                  TA("E");

                  // Important: Initilization of the identificator
                  $companyId = "";
               else :
                  $statusMessage = getLngt("Dem " . wrapPhrase("Transporteur", $objecttypemode) . " ist mind. noch ein anderen " . wrapPhrase("Transporteur", $objecttypemode) . " zugeordnet! Bitte entfernen Sie diese Beziehung(en) erst!");
               endif;
            else :
               $statusMessage = getLngt("Dem " . wrapPhrase("Transporteur", $objecttypemode) . " sind noch Fahrzeuge zugeordnet! Bitte löschen Sie diese erst!");
            endif;
         else :
            $statusMessage = getLngt("Der " . wrapPhrase("Transporteur", $objecttypemode) . " darf nicht gelöscht werden, da mindestens ein Auftrag bearbeitet wurde!");
         endif;
      endif;
   endif;  
   
   // Set status of authentication of the courier
   if ($f_act == "setAuthentication") :

      // Check for company
      if ($companyId != "") :

         if (existsEntry("company",array("cmp_id",$companyId))) :

            // Check in case the courier shall be set free but he/she is noticeable according to embargo check
            $currentDPFState = getFieldValueFromId("company", "cmp_id", $companyId, "cmp_dpf_state");
            if ($f_cmp_authenticated == "1" && $currentDPFState >= "1" && $currentDPFState <= "9") :
               // Update DPF state 
               // Attention: Description of the states look for "dpf.php"
               $newDPFState = $currentDPFState + 10;
               updateStmt("company","cmp_id",$companyId,array("cmp_dpf_state",$newDPFState));
            endif;

            // Update authentication-status
            updateStmt("company","cmp_id",$companyId,array("cmp_authenticated",$f_cmp_authenticated));
            
            // Write logdata into log database
            $v_cr_id = getFieldValueFromId("courier", "cmp_id", $companyId, "cr_id");
            writeToLogDB("39",$hq_id,"",$usr_id,$v_cr_id,"","","STATUS_AUTHENTICATION=".$f_cmp_authenticated);
         else :               
            $statusMessage = getLngt("Der spezifizierte " . wrapPhrase("Transporteur", $objecttypemode) . " ist nicht im Datenbestand erhalten!");
         endif;      
      else :
         $statusMessage = getLngt("Sie haben keinen " . wrapPhrase("Transporteur", $objecttypemode) . " spezifiziert!");
      endif;
   endif;

   // Set status of visibility of the courier
   if ($f_act == "setVisibility") :

      // Check for company
      if ($companyId != "") :

         if (existsEntry("company",array("cmp_id",$companyId))) :

            // Update visibility status
            updateStmt("company","cmp_id",$companyId,array("cmp_visible",$f_cmp_visible));

            // Write logdata into log database
            $v_cr_id = getFieldValueFromId("courier", "cmp_id", $companyId, "cr_id");
            writeToLogDB("41",$hq_id,"",$usr_id,$v_cr_id,"","","STATUS_VISIBILITY=".$f_cmp_visible);
         else :               
            $statusMessage = getLngt("Der spezifizierte " . wrapPhrase("Transporteur", $objecttypemode) . " ist nicht im Datenbestand erhalten!");
         endif;      
      else :
         $statusMessage = getLngt("Sie haben keinen " . wrapPhrase("Transporteur", $objecttypemode) . " spezifiziert!");
      endif;
   endif;
   
   // Logout the PDA of the courier ("time-thief")
   if ($f_act == "logoutCourier") :

      // Check for company
      if ($companyId != "") :

         if (existsEntry("company",array("cmp_id",$companyId))) :

            $v_cr_id = getFieldValueFromId("courier", "cmp_id", $companyId, "cr_id");
            $currentTime = getDateTime("0");

            // Update availability status
            // updateStmt("courier","cr_id",$v_cr_id,array("cr_available","0","cr_sid",""));
            updateStmt("courier","cr_id",$v_cr_id,array("cr_availabletime",$currentTime,"cr_locationzipcode","LOGOUT"));

            // Insert PDA command to quit application
            $currentTime = getDateTime("0");
            $execTimelimit = getDateTime("datetime_plus_offset", array(0,16,0,0,0,0), $formatStr = "Y-m-d H:i:s");
            insertPDACommand($hq_id, $v_cr_id, "2", "1", "", $currentTime, $execTimelimit);

            // Write logdata into log database            
            writeToLogDB("50",$hq_id,"",$usr_id,$v_cr_id,"","","STATUS_LOGOUT=PDA-LOGOUT DURCH WEB");
         else :               
            $statusMessage = getLngt("Der spezifizierte " . wrapPhrase("Transporteur", $objecttypemode) . " ist nicht im Datenbestand erhalten!");
         endif;      
      else :
         $statusMessage = getLngt("Sie haben keinen " . wrapPhrase("Transporteur", $objecttypemode) . " spezifiziert!");
      endif;
   endif;
   
   // Reset password
   if ($f_act == "resetPasswdCourier") :

      // Check for company
      if ($companyId != "") :

         if (existsEntry("company",array("cmp_id",$companyId))) :

            $v_cr_id = getFieldValueFromId("courier", "cmp_id", $companyId, "cr_id");
            $v_usr_id = getFieldValueFromId("courier", "cr_id", $v_cr_id, "usr_id");
            $currentTime = getDateTime("0");

            // Generate password
            $v_usr_password = "test" . rand(1000,9999);

            // Update password of the courier
            $sqlStmt = "UPDATE user SET usr_password = PASSWORD('" . $v_usr_password . "'), usr_password_modify = '" . $currentTime . "' WHERE usr_id = '" . $v_usr_id . "'"; 
            $res = $db->query($sqlStmt);
            if (DB::isError($res)) die ("$PHP_SELF: <br>$sqlStmt<br>" . $res->getMessage());            

            // Write logdata into log database
            writeToLogDB("84",$hq_id,"",$usr_id,$v_cr_id,"","","PASSWORD=RESET DURCH WEB");

            $statusMessage = getLngt("Der neue Passwort lautet:") . " " . $v_usr_password;
         else :               
            $statusMessage = getLngt("Der spezifizierte " . wrapPhrase("Transporteur", $objecttypemode) . " ist nicht im Datenbestand erhalten!");
         endif;      
      else :
         $statusMessage = getLngt("Sie haben keinen " . wrapPhrase("Transporteur", $objecttypemode) . " spezifiziert!");
      endif;
   endif;

   // Reset 2-FA
   if ($f_act == "reset2FACourier") :

      // Check for company
      if ($companyId != "") :

         if (existsEntry("company",array("cmp_id",$companyId))) :

            $v_cr_id = getFieldValueFromId("courier", "cmp_id", $companyId, "cr_id");
            $retVal = user2FARemove($v_cr_id, "cr");
            
            $statusMessage = $retVal[1];
         else :               
            $statusMessage = getLngt("Der spezifizierte " . wrapPhrase("Transporteur", $objecttypemode) . " ist nicht im Datenbestand erhalten!");
         endif;      
      else :
         $statusMessage = getLngt("Sie haben keinen " . wrapPhrase("Transporteur", $objecttypemode) . " spezifiziert!");
      endif;
   endif;   


   // ******************************************************************
   // * Selection of the courier-data only for the current headquarter *
   // ******************************************************************
   if ($companyId != "") :
      $sqlquery = "SELECT cmp.cmp_id, cmp.cmp_comp, cmp.cmp_comp2, cmp.cmp_hsno, cmp.cmp_iln, cmp.cmp_tax_idno, cmp.cmp_stax_idno,"
                   . "    cmp.cmp_bank, cmp.cmp_bankno, cmp.cmp_bankacc, cmp.cmp_iban, cmp.cmp_swift,"
                   . "    cmp.cmp_authenticated, cmp.cmp_remark, cmp.cmp_remark2, cmp.cmp_visible, cmp.cmp_no_longhaul, cmp.cmp_freetext1, cmp.cmp_contract_date,"
                   . "    cr.cr_id, cr.cr_sid, cr.cr_eid, cr.vht_id, cr.vht_id_inv, cr.cr_maxweight, cr.cr_outlay, cr.cr_homezipcode,"
                   . "    cr.cr_available, cr.cr_id_parent, cr.cr_vh_sign, cr.cr_imei, cr.cr_serialno, cr.cr_mobile_pda, cr.cr_disposition,"
                   . "    cr.cr_price_show, cr.cr_app_blocked,"
                   . "    usr.usr_id, usr.usr_name, usr.usr_firstname, usr.usr_email, usr.usr_inv_email,"
                   . "    usr.usr_phone, usr.usr_phone2, usr.usr_fax, usr.usr_account,usr.usr_birthdate,usr.usr_country,"
                   . "    ad.ad_street, ad.ad_zipcode, ad.ad_city, ad.ad_country"
                   . " FROM company AS cmp, courier AS cr, user AS usr, address AS ad"
                   . " WHERE cmp.cmp_id = '" . $companyId . "' AND"
                   . "       cmp.cmp_id = cr.cmp_id AND"
                   . "       cr.usr_id = usr.usr_id AND"
                   . getSQLMandatorPhrase($emp_id, "usr.hq_id = '" . $hq_id . "' AND")
                   . "       cmp.ad_id = ad.ad_id";
      $result = $db->query($sqlquery);
      if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());

      while ($row = $result->fetch_assoc()):
            $f_companyId         = $row["cmp_id"];         
            $f_cmp_comp          = $row["cmp_comp"];
            $f_cmp_comp2         = $row["cmp_comp2"];
            $f_cmp_hsno          = $row["cmp_hsno"];
            $f_cmp_iln           = $row["cmp_iln"];
            $f_cmp_tax_idno      = $row["cmp_tax_idno"];
            $f_cmp_stax_idno     = $row["cmp_stax_idno"];
            $f_cmp_bank          = $row["cmp_bank"];
            $f_cmp_bankno        = $row["cmp_bankno"];
            $f_cmp_bankacc       = $row["cmp_bankacc"];
            $f_cmp_iban          = $row["cmp_iban"];
            $f_cmp_swift         = $row["cmp_swift"];
            $f_cmp_no_longhaul   = $row["cmp_no_longhaul"];
            $f_cmp_remark        = $row["cmp_remark"];
            $f_cmp_remark2       = $row["cmp_remark2"];
            $f_cmp_freetext1     = $row["cmp_freetext1"];
            $f_cmp_contract_date = $row["cmp_contract_date"];
            $f_cmp_authenticated = $row["cmp_authenticated"];
            $f_cmp_authenticated2 = 0;
            if ($f_cmp_authenticated != "1") :
               $f_cmp_authenticated = 0; 
               $f_cmp_authenticated2 = 1;
            endif;
            $f_cmp_visible = $row["cmp_visible"];
            $f_cmp_visible2 = 0;
            if ($f_cmp_visible != "1") :
               $f_cmp_visible = 0; 
               $f_cmp_visible2 = 1;
            endif;
            $f_cr_id             = $row["cr_id"];
            $f_cr_sid            = $row["cr_sid"];
            $f_cr_eid            = $row["cr_eid"];
            $f_cr_id_parent      = $row["cr_id_parent"];
            $f_cr_vh_sign        = $row["cr_vh_sign"];
            $f_cr_imei           = $row["cr_imei"];
            $f_cr_serialno       = $row["cr_serialno"];
            $f_cr_mobile_pda     = $row["cr_mobile_pda"];
            $f_cr_disposition    = $row["cr_disposition"];
            $f_cr_price_show     = $row["cr_price_show"];
            $f_cr_app_blocked    = $row["cr_app_blocked"];
            $f_vht_id            = $row["vht_id"];
            $f_vht_id_inv        = $row["vht_id_inv"];
            $f_cr_maxweight      = $row["cr_maxweight"];
            $f_cr_outlay         = $row["cr_outlay"];
            $f_cr_homezipcode    = $row["cr_homezipcode"];
            $f_cr_available      = $row["cr_available"];
            $f_usr_id            = $row["usr_id"];
            $f_usr_name          = $row["usr_name"];
            $f_usr_firstname     = $row["usr_firstname"];
            $f_usr_email         = $row["usr_email"];
            $f_usr_inv_email     = $row["usr_inv_email"];
            $f_usr_phone         = $row["usr_phone"];
            $f_usr_phone2        = $row["usr_phone2"];
            $f_usr_fax           = $row["usr_fax"];
            $f_usr_account       = $row["usr_account"];
            $f_usr_birthdate     = $row["usr_birthdate"];
            $f_usr_country       = $row["usr_country"];
            $f_ad_street         = $row["ad_street"];
            $f_ad_zipcode        = $row["ad_zipcode"];
            $f_ad_city           = $row["ad_city"];            
            $f_ad_country        = $row["ad_country"];
      endwhile;
      $result->free();
   endif;

   // Get courier-sid|eid of the parent-id
   if (CR_SID_STATUS == "1") :
      $f_cr_sid_parent = getFieldValueFromId("courier", "cr_id", "$f_cr_id_parent", "cr_sid");
   else :
      $f_cr_eid_parent = getFieldValueFromId("courier", "cr_id", "$f_cr_id_parent", "cr_eid");
   endif;

   // Get max-value of the EID of the current courier for inserting a new row 
   // The constant value "CR_EID_GENERATION" contains the prefix of the SID [SPECIAL TREATMENT]
   $f_eid_maxval = "";
   if (CR_EID_GENERATION != "") :
      $f_eid_maxval = getMaxOfField("courier", "cr_eid", "cr_eid < '" . CR_EID_GENERATION . "'");
      if (is_numeric($f_eid_maxval)) :
         ++$f_eid_maxval;   // Increment because of the next free EID (Attention: Not TA-safe!)
      else :
        // Remove alphanumeric chars (e.g "HTHB123456" => "123456")
        $prefixChars = ereg_replace("[^[:alpha:]+]","",$f_eid_maxval);
        $f_eid_maxval = ereg_replace("[^[:digit:]+]","",$f_eid_maxval);
        ++$f_eid_maxval;
        $f_eid_maxval = $prefixChars . $f_eid_maxval;
      endif;
   endif;

   // Birthdate
   $f_usr_birthdate_day = "";
   $f_usr_birthdate_month = "";
   $f_usr_birthdate_year = "";
   if ($f_usr_birthdate != "" && $f_usr_birthdate != "0000-00-00") :
     $f_usr_birthdate_year = substr($f_usr_birthdate,0,4);
     $f_usr_birthdate_month = substr($f_usr_birthdate,5,2);
     $f_usr_birthdate_day = substr($f_usr_birthdate,8,2);
   endif;

   // Contract date
   $f_cmp_contract_date_day = "";
   $f_cmp_contract_date_month = "";
   $f_cmp_contract_date_year = "";
   if ($f_cmp_contract_date != "" && $f_cmp_contract_date != "0000-00-00") :
     $f_cmp_contract_date_year = substr($f_cmp_contract_date,0,4);
     $f_cmp_contract_date_month = substr($f_cmp_contract_date,5,2);
     $f_cmp_contract_date_day = substr($f_cmp_contract_date,8,2);
   endif;   

   // Own disposition
   $f_cr_disposition_0 = "";
   if ($f_cr_disposition == "1") : $f_cr_disposition_0 = "checked"; endif;

   // App blocked
   $f_cr_app_blocked_0 = "";
   if ($f_cr_app_blocked == "1") : $f_cr_app_blocked_0 = "checked"; endif;

   // Display cartage in app
   $f_cr_price_show_0 = "";
   if ($f_cr_price_show == "1") : $f_cr_price_show_0 = "checked"; endif;

    // Flag for no longhaul
    $f_cmp_no_longhaul_0 = "";
    if ($f_cmp_no_longhaul == "1") : $f_cmp_no_longhaul_0 = "checked"; endif;

   // Only for output
   $pageHeadline = getLngt("NEUER " . strtoupper(wrapPhrase("Transporteur", $objecttypemode)));
   $title = $pageHeadline;
   $buttonAuthentication = "";
   $buttonVisibility = "";
   $buttonVehicles = "";
   $buttonCustomer = "";
   $buttonRemove = "";
   $buttonLogout = "";
   $buttonResetPasswd = "";
   $buttonReset2FA = "";
   $buttonCrHistory = "";
   $buttonMessagegroup = "";
   $buttonGroup = "";
   $buttonPage2 = "";
   $buttonFilter = "";
   $buttonDocument = "";
   $buttonReport = "";
   $buttonLogout = "";
   $displayTextAuthentication = "";
   $displayTextVisibility = "";
   $confirmTextAuthentication = "";
   $confirmTextVisibility = "";

   if ($companyId != "") :
      $title = $f_cmp_comp;
      $pageHeadline = "<span class=\"f12bp1_blue\">" . strtoupper(getLngt(wrapPhrase("TRANSPORTEUR", $objecttypemode))) . "</span>" . " &nbsp;&nbsp;&nbsp;&nbsp;" . $f_cmp_comp . ($f_cmp_comp2 != "" ? " :: " . $f_cmp_comp2 : "");
      
      // Get path for courier documents (type "CR")
      if ($importPath == "") : $importPath = getFieldValueFromId("mandator","md_id",$md_id,"md_doc_path"); endif;
      $importPath = getPathForObjectData($importPath, "CR");
      // Get number of documents for the current customer
      $crNumOfFiles = getNumOfFilesByFilterInFolder($importPath, $f_cr_eid . "_", "1");
      
      $buttonAuthentication = defineButtonType10(getLngt("Sperren"), "action_lock", "authenticationFinishPage();", "100", "left", "0");
      $confirmTextAuthentication = "Soll der Kurier wirklich gesperrt werden?";
      if ($f_cmp_authenticated != "1") :
         $buttonAuthentication = defineButtonType10(getLngt("Freischalten"), "action_unlock", "authenticationFinishPage();", "100", "left", "0");
         $displayTextAuthentication = getLngt("(gesperrt)");
         $confirmTextAuthentication = getLngt("Soll der Kurier wirklich freigeschaltet werden?");
      endif;
      $buttonVisibility = defineButtonType10(getLngt("Ausblenden"), "action_visible", "visibilityFinishPage();", "100", "left", "0");
      $confirmTextVisibility = getLngt("Soll der " . wrapPhrase("Transporteur", $objecttypemode) . " wirklich ausgeblendet werden?");
      if ($f_cmp_visible != "1") :
         $buttonVisibility = defineButtonType10(getLngt("Einblenden"), "action_visible", "visibilityFinishPage();", "100", "left", "0");
         $displayTextVisibility = getLngt("(ausgeblendet)");
         $confirmTextVisibility = getLngt("Soll der " . wrapPhrase("Transporteur", $objecttypemode) . " wirklich eingeblendet werden?");
      endif;      
     
      $buttonVehicles = defineButtonType10(getLngt("Fahrzeuge"), "action_crvh", "openCourierVehicles('" . ec($f_cr_id) . "');", "120", "left", "0");
      $buttonCustomer = defineButtonType10(getLngt("Kunden"), "action_cs", "openCourierCustomers('" . ec($f_cr_id) . "');", "120", "left", "0");
      $buttonRemove = defineButtonType10(getLngt("Löschen"), "action_remove", "removeCourierFinishPage();", "120", "left", "0");
      $buttonLogout = defineButtonType10(getLngt("Logout&nbsp;VPA&nbsp;/&nbsp;PDA"), "action_logout", "logoutCourierFinishPage();", "158", "left", "0", "", "", "150px");
      $buttonResetPasswd = defineButtonType10(getLngt("Neues&nbsp;Passwort"), "action_passwd", "resetPasswdCourierFinishPage();", "140", "left", "0", "", "", "150px");
      $buttonCrHistory = defineButtonType10(getLngt("Änderungshistorie"), "action_cr_history", "openCrHistory('" . ec($f_cr_id) . "');", "190", "left", "0");
      $buttonReset2FA = defineButtonType10(getLngt("2FA&nbsp;zurücksetzen"), "action_2fa", "reset2FACourierFinishPage();", "140", "left", "0", "", "", "150px");
      $buttonMessagegroup = defineButtonType10(getLngt("Nachrichtengruppen"), "action_msggrps", "openMessageGroups('" . ec($f_cr_id) . "');", "158", "left", "0", "", "", "170px");
      $buttonGroup = defineButtonType10(getLngt("Gruppen"), "action_grp", "openGroups('" . ec($f_cr_id) . "');", "120", "left", "0", "", "", "170px");
      $buttonPage2 = defineButtonType10(getLngt("2. Seite"), "action_2ndpage", "openMetaFieldSpecial('3','" . ec($f_cr_id) . "');", "120", "left", "0");
      $buttonFilter = defineButtonType10(getLngt("Filter"), "action_crf", "openCourierFilters();", "120", "left", "0");
      if ($f_cr_id_parent == "" || $f_cr_id_parent == "0" || $parMaskCrReportsHideForDriver != "1") :
         $buttonReport = defineButtonType10(getLngt("Berichte"), "action_rp", "openCourierReports('" . $f_cr_id . "');", "120", "left", "0");
      endif;
      $buttonDocument = defineLinkButtonType10(getLngt("Dokumente") . ($crNumOfFiles != "-1" ? ": " . $crNumOfFiles : ""), "action_dt_cr", "../import/data_transfer.php?objType=cr&objId=" . ec($f_cr_id), "160", "left", "1", "", "", "", "", "0");

      if ($parMaskCrCartageLinksDisabled != "1") :
         if (MASK_CUSTOMERDETAILS_TARGET == "1") :
            if (authCheckEmployeeRights($emp_id, "2")) :
               $serviceLink1 = "Service (Grundpreise, Kilometer, Radien, Zuschläge, Preis-/Leistungstypen): <a href=\"../admin/services.php?opener=1&mode=price&crId=" . ec($f_cr_id) . "\" target=\"_blank\">" . getLngt("Frachtvergütungen") . "</a>/" .
                                        "<a href=\"../admin/services.php?opener=1&mode=discount&crId=" . ec($f_cr_id) . "\" target=\"_blank\">" . getLngt("Frachtvergütungsrabatte") . "</a>\n";
               $serviceLink2 = "PLZ: <a href=\"../admin/services_plz.php?opener=1&mode=price&crId=" . ec($f_cr_id) . "\" target=\"_blank\">" . getLngt("Frachtvergütungen") . "</a>/" . 
                                    "<a href=\"../admin/services_plz.php?opener=1&mode=discount&crId=" . ec($f_cr_id) . "\" target=\"_blank\">" . getLngt("Frachtvergütungsrabatte") . "</a>\n";
               $serviceLink3 = "Bereiche: <a href=\"../admin/services_plz_area.php?opener=1&mode=price&crId=" . ec($f_cr_id) . "\" target=\"_blank\">" . getLngt("Frachtvergütungen") . "</a>/" . 
                                             "<a href=\"../admin/services_plz_area.php?opener=1&mode=discount&crId=" . ec($f_cr_id) . "\" target=\"_blank\">" . getLngt("Frachtvergütungsrabatte") . "</a>\n";
               $serviceLink4 = "\n";
            else :
               $serviceLink1 = getLngt("Service: Preise/Rabatte") . "</td>\n";
               $serviceLink2 = getLngt("PLZ: Preise/Rabatte") . "</td>\n";
               $serviceLink3 = getLngt("PLZ-Bereiche: Preise/Rabatte") . "</td>\n";
               $serviceLink4 = "\n";      
            endif;
         else :
            if (authCheckEmployeeRights($emp_id, "2")) :
               $serviceLink1 = "<td>Service: <a href=\"../admin/services.php?opener=1&mode=price&crId=" . ec($f_cr_id) . "\" target=\"_blank\">" . getLngt("Frachtvergütungen") . "</a>/" .
                                                                "<a href=\"../admin/services.php?opener=1&mode=discount&crId=" . ec($f_cr_id) . "\" target=\"_blank\">" . getLngt("Frachtvergütungsrabatte") . "</a></td>\n";
               $serviceLink2 = "<td>PLZ: <a href=\"../admin/services_plz.php?opener=1&mode=price&crId=" . ec($f_cr_id) . "\" target=\"_blank\">" . getLngt("Frachtvergütungen") . "</a>/" . 
                                                            "<a href=\"../admin/services_plz.php?opener=1&mode=discount&crId=" . ec($f_cr_id) . "\" target=\"_blank\">" . getLngt("Frachtvergütungsrabatte") . "</a></td>\n";
               $serviceLink3 = "<td>PLZ-Bereiche: <a href=\"../admin/services_plz_area.php?opener=1&mode=price&crId=" . ec($f_cr_id) . "\" target=\"_blank\">" . getLngt("Frachtvergütungen") . "</a>/" . 
                                                                 "<a href=\"../admin/services_plz_area.php?opener=1&mode=discount&crId=" . ec($f_cr_id) . "\" target=\"_blank\">" . getLngt("Frachtvergütungsrabatte") . "</a></td>\n";
               $serviceLink4 = "<td></td>\n";
            else :
               $serviceLink1 = "<td>" . getLngt("Service: Frachtvergütungen/Frachtvergütungsrabatte") . "</td>\n";
               $serviceLink2 = "<td>" . getLngt("PLZ: Frachtvergütungen/Frachtvergütungsrabatte") . "</td>\n";
               $serviceLink3 = "<td>" . getLngt("PLZ-Bereiche: Frachtvergütungen/Frachtvergütungsrabatte") . "</td>\n";
               $serviceLink4 = "<td></td>\n";      
            endif;      
         endif;
      endif;
   else :
      if ($f_cr_eid == "") :
         $f_cr_eid = getParameterValue("0", "CR_EID_PREFIX", $hq_id);
      endif;
   endif;
   
   
   // Password-fields for entering a new courier (admin-user)
   $setPasswordForNewUserOutput = "";
   $setPassword2ForNewUserOutput = "";
   if ($companyId == "") :
      $setPasswordForNewUserOutput = getLngt("Passwort*:") . "&nbsp;<input type=\"text\" " . $htmlClass01 . " id=\"f_usr_password\" name=\"f_usr_password\" value=\"\" maxlength=\"20\" size=\"20\" tabindex=\"191\">\n";
      $setPassword2ForNewUserOutput = getLngt("Wiederholung*:") . "&nbsp;<input type=\"text\" " . $htmlClass01 . " id=\"f_usr_password2\" name=\"f_usr_password2\" value=\"\" maxlength=\"20\" size=\"20\" tabindex=\"192\">\n";
   endif;    


   // Only for output:  
   // Check for updading the list
   $javaScriptOut = "";
   if ($statusMessage == "" && $f_act != "") :
      // Update list
      $javaScriptOut .= "if (opener) {opener.finishPage();};";
      // If courier is removed initialize form
      if ($f_act == "removeCourier") :      
         $javaScriptOut .= "clearAllFields();";
      endif;
      $f_act = "";
   endif;
   // Call embargo check
   if ($execEmbargoCheck == "1") :
      $javaScriptOut .= "openEmbargoCheck();";
   endif;
   // Check status of the courier being online
   $onlineOut = "";
   if ($companyId != "") :
      $onlineOut = "<span class=\"f8np1_red\">" . getLngt("Nein") . "</span>";
      if ($f_cr_available == "1") : 
         $onlineOut = "<span class=\"f8np1_green\" " . $html_td_01 . ">" . getLngt("Ja") . " (" 
                      . getFieldValueFromClause("metatype","mt_value","mt_type = 'vehicletype' AND mt_sort = '" . $f_vht_id . "'") 
                      . ")</span>";
      endif;
   endif;
?>

<html>

<head>
<title><?php echo $title ?></title>

<style type="text/css">
  <?php include_once ("../css/phoenix.css.php"); ?>
  <?php include_once ("../css/navigation.css.php"); ?>
  <?php include_once ("../css/mc.css.php"); ?>
</style>

<?php include_once ("../include/js_framework.inc.php"); ?>

<script src="../include/checkFormTags.js" type="text/javascript"></script>
<script src="../include/searchLists.js" type="text/javascript"></script>

<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>

var f_cr_id = '<?php echo $f_cr_id ?>';

function clearAllFields() {
  document.location.href = "courier_special.php";
};

function clearCourierParent() {	
  document.forms[0].f_cr_id_parent.value='';
  document.forms[0].f_cr_sid_parent.value='';
  document.forms[0].f_cr_eid_parent.value='';
};

function authenticationFinishPage() {
  if (confirm('<?php echo $confirmTextAuthentication ?>')) {	
     document.forms[0].f_cmp_authenticated.value='<?php echo ec($f_cmp_authenticated2) ?>';
     document.forms[0].f_act.value='<?php echo ec("setAuthentication") ?>';
     document.forms[0].submit();
  }
};

function visibilityFinishPage() {
  if (confirm('<?php echo $confirmTextVisibility ?>')) {
     document.forms[0].f_cmp_visible.value='<?php echo ec($f_cmp_visible2) ?>';
     document.forms[0].f_act.value='setVisibility';
     document.forms[0].submit();
  }
};

function removeCourierFinishPage() {
  if (confirm('<?php echo getLngt("Möchten Sie den Datensatz des " . wrapPhrase("Transporteurs", $objecttypemode) . " wirklich löschen?") ?>')) {
     document.forms[0].f_act.value='removeCourier';
     document.forms[0].submit();
  }
};

function logoutCourierFinishPage() {
  if (confirm('<?php echo getLngt("Möchten Sie den PDA des " . wrapPhrase("Transporteurs", $objecttypemode) . " wirklich ausloggen? ACHTUNG: Der Vorgang wird protokolliert!") ?>')) {
     document.forms[0].f_act.value='logoutCourier';
     document.forms[0].submit();
  }
};

function resetPasswdCourierFinishPage() {
  if (confirm('<?php echo getLngt("Möchten Sie dass Passwort des " . wrapPhrase("Transporteurs", $objecttypemode) . " wirklich zurücksetzen?") ?>')) {
     document.forms[0].f_act.value='resetPasswdCourier';
     document.forms[0].submit();
  }
};

function reset2FACourierFinishPage() {
  if (confirm('<?php echo getLngt("Möchten Sie 2-Faktor-Authentifikation des " . wrapPhrase("Transporteurs", $objecttypemode) . " wirklich zurücksetzen?") ?>')) {
     document.forms[0].f_act.value='reset2FACourier';
     document.forms[0].submit();
  }
};

function openCourierVehicles(courierId) {
  var widthPopupWin = 1000;
  var heightPopupWin = 900;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/courier_vehicle.php?courierId=" + courierId,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openCourierCustomers(courierId) {
  var widthPopupWin = 800;
  var heightPopupWin = 550;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/courier_customer.php?courierId=" + courierId,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openCourierFilters() {
  var widthPopupWin = 900;
  var heightPopupWin = 700;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/filter.php?courierId=" + f_cr_id + "&filterType=1&actionMode=1","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openCrHistory(f_cr_id) {
  var widthPopupWin = 1200;
  var heightPopupWin = 1024;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/history.php?history_mode=<?php echo ec(1) ?>&cr_id=" + f_cr_id + "&op=<?php echo ec(2) ?>&logoselection=<?php echo ec(1) ?>&displayselection=<?php echo ec(1) ?>","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function checkDate(checkObj,mode) {
  var resetValue = checkDateFields(checkObj,mode);
  if (resetValue) {
     checkObj.value = '';
     checkObj.focus();
  };
};

function finishPage() {
  var ok = true;

  if (document.forms[0].f_usr_email.value.length != 0) {
     // if e-mail has content then check syntax
     if (!checkMailAddress(document.forms[0].f_usr_email, '<?php echo getLngt("Bitte tragen Sie eine gültige EMail-Adresse ein!") ?>')) {ok = false;};
  }
  if (document.forms[0].f_usr_inv_email.value.length != 0) {
     if (!checkMailAddress(document.forms[0].f_usr_inv_email, '<?php echo getLngt("Bitte tragen Sie eine gültige EMail-Adresse für den Rechnungsversand ein!") ?>')) {ok = false;};
  }
  if (!checkIsNaNIgnoreSpace(document.forms[0].f_usr_phone.value, '<?php echo getLngt("Bitte tragen Sie eine Nummer bei Telefon ein!") ?>')) {ok = false;};
  if (!checkIsNaNIgnoreSpace(document.forms[0].f_usr_phone2.value, '<?php echo getLngt("Bitte tragen Sie eine Nummer bei Mobil ein!") ?>')) {ok = false;};
  <?php if ($parMaskCrMobilePdaEdit == "1") :  ?>
    if (!checkIsNaNIgnoreSpace(document.forms[0].f_cr_mobile_pda.value, '<?php echo getLngt("Bitte tragen Sie eine Nummer bei Mobil-PDA für die Ortung ein!") ?>')) {ok = false;};
  <?php endif; ?>

  // Check length of the courier EID
  if (('<?php echo $parMaskCrEidMinLength ?>' != '') && (document.forms[0].f_cr_eid.value.length < <?php echo $parMaskCrEidMinLength ?>)) {
     alert('<?php echo getLngt("Die erforderliche Mindestlänge der EID ist nicht erfüllt!") ?>' + ' [<?php echo $parMaskCrEidMinLength ?>]');
     ok = false;
  }
  if (('<?php echo $parMaskCrEidMaxLength ?>' != '') && (document.forms[0].f_cr_eid.value.length > <?php echo $parMaskCrEidMaxLength ?>)) {
     alert('<?php echo getLngt("Die Maximallänge der EID ist überschritten!") ?>' + ' [<?php echo $parMaskCrEidMaxLength ?>]');
     ok = false;
  }

  if (ok) {
     document.forms[0].submit();
  }
};

function searchMaxEID() {
  var maxvalue = document.forms[0].f_eid_maxval.value;
  if (confirm('<?php echo getLngt("Soll der Wert") ?>' + ' ' + maxvalue + ' ' + '<?php echo getLngt("übernommen werden") ?>')) {
     document.forms[0].f_cr_eid.value = maxvalue;
  };
};

function openMessageGroups(courierId) {
  var widthPopupWin = 800;
  var heightPopupWin = 700;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/courier_msggrp.php?courierId=" + courierId,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openGroups(courierId) {
  var widthPopupWin = 800;
  var heightPopupWin = 700;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/groupmembers.php?itemType=cr&itemId=" + courierId,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openMetaFieldSpecial(category, objId, specialPageTitle) {
  var widthPopupWin = 900;
  var heightPopupWin = 870;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/metafield_special.php?deactivateMenu=1&category=" + category + "&objId=" + objId + "&specialPageTitle=" + specialPageTitle ,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openEmbargoCheck() {
  var widthPopupWin = 900;
  var heightPopupWin = 870;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../include/dpf.php?cmpId=<?php echo ec($cmpId); ?>&hqId=<?php echo $hq_id; ?>&eid=<?php echo $eid; ?>&usrName=<?php echo $usrName; ?>&usrFirstname=<?php echo $usrFirstname; ?>&adStreet=<?php echo $adStreet; ?>&cmpHsno=<?php echo $cmpHsno; ?>&adZipcode=<?php echo $adZipcode; ?>&adCity=<?php echo $adCity; ?>&cmpDpfChecksum=<?php echo $oldDpfChecksum; ?>" ,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openCourierReports(f_cr_id) {
  var widthPopupWin = 1200;
  var heightPopupWin = 1024;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../groupware/report.php?rpObjType=cr&g_cr_id=" + f_cr_id,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function checkMandatoryFieldsCr () {
	var bgcol = 'red';
  $('#f_cmp_comp').css('background-color', bgcol);
  $('#f_usr_name').css('background-color', bgcol);
  $('#f_usr_firstname').css('background-color', bgcol);
  $('#f_usr_phone').css('background-color', bgcol);
  $('#f_usr_account').css('background-color', bgcol);
  <?php if ($companyId == "") : ?>
      $('#f_usr_password').css('background-color', bgcol);
      $('#f_usr_password2').css('background-color', bgcol);
  <?php endif; ?>
  $('#f_ad_street').css('background-color', bgcol);
  $('#f_cmp_hsno').css('background-color', bgcol);
  $('#f_ad_zipcode').css('background-color', bgcol);
  $('#f_ad_city').css('background-color', bgcol);
  $('#f_cmp_tax_idno').css('background-color', bgcol);
  $('#f_cr_eid').css('background-color', bgcol);
  $('#f_cr_serialno').css('background-color', bgcol);
  // $('#f_cr_mobile_pda').css('background-color', bgcol);
  $('#f_vht_id_inv').css('background-color', bgcol);
  <?php if ($companyId == "") : ?>
  $('#f_cmp_contract_date_day').css('background-color', bgcol);
  $('#f_cmp_contract_date_month').css('background-color', bgcol);
  $('#f_cmp_contract_date_year').css('background-color', bgcol);
  <?php endif ?>
}

function finishPageBycheckingMandatoryFields () {
	var doFinishPage = true;
	if ($('#f_cmp_comp').val() == '') {doFinishPage = false;};
	if ($('#f_usr_name').val() == '') {doFinishPage = false;};
	if ($('#f_usr_firstname').val() == '') {doFinishPage = false;};
	if ($('#f_usr_phone').val() == '') {doFinishPage = false;};
	if ($('#f_usr_account').val() == '') {doFinishPage = false;};
  <?php if ($companyId == "") : ?>
      if ($('#f_usr_password').val() == '') {doFinishPage = false;};
      if ($('#f_usr_password2').val() == '') {doFinishPage = false;};
  <?php endif; ?>
	if ($('#f_ad_street').val() == '') {doFinishPage = false;};
	if ($('#f_cmp_hsno').val() == '') {doFinishPage = false;};
	if ($('#f_ad_zipcode').val() == '') {doFinishPage = false;};
	if ($('#f_ad_city').val() == '') {doFinishPage = false;};
	if ($('#f_cmp_tax_idno').val() == '') {doFinishPage = false;};
	if ($('#f_cr_eid').val() == '') {doFinishPage = false;};
	if ($('#f_cr_serialno').val() == '') {doFinishPage = false;};
	<?php if ($companyId == "") : ?>
	if ($('#f_cmp_contract_date_day').val() == '') {doFinishPage = false;};
	if ($('#f_cmp_contract_date_month').val() == '') {doFinishPage = false;};
	if ($('#f_cmp_contract_date_year').val() == '') {doFinishPage = false;};
	<?php endif; ?>
	// if ($('#f_cr_mobile_pda').val() == '') {doFinishPage = false;};
	var f_vht_id_inv = getSelectedValue('f_vht_id_inv');
	if (f_vht_id_inv == '' || f_vht_id_inv == '0') {doFinishPage = false;};  
  if (doFinishPage) {
  	 finishPage();
  } else {
     checkMandatoryFieldsCr();
     alert('<?php echo getLngt("Bitte geben Sie alle mit * gekennzeichneten Felder ein!"); ?>');
  };
}
-->
</script>

</head>

<body class="menu_bgcol" onLoad="<?php echo $phpCurrentNavigationOnLoad ?><?php echo $javaScriptOut ?>displayStatusMessage();">

<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>

<div class="mc_page-header">
  <?php echo $pageHeadline ?>
</div>

<?php // echo htmlDivLineSpacer("5px", "", "left"); ?>
<div>
  
  <?php 
    if ($companyId != "") : 
       $valueText = getLngt("Änderungen&nbsp;speichern"); $f_actText = "modifyCourier";
    else :
       $valueText = getLngt("Speichern"); $f_actText = "newCourier";
    endif;
  ?>
  
  <?php echo $buttonVehicles ?>    
  <?php echo $buttonAuthentication ?>
  <?php echo $buttonVisibility ?>  
  <?php echo $buttonResetPasswd ?>  
  <?php echo $buttonPage2 ?>
  <?php echo $buttonFilter ?>
  <?php echo $buttonCustomer ?>
  <?php echo $buttonReport ?>  
  <?php echo $buttonGroup ?>
  <?php echo $buttonMessagegroup ?>
  <?php echo $buttonLogout ?>
  <?php echo $buttonCrHistory ?>
  <?php echo $buttonReset2FA ?>
  <?php echo $buttonDocument ?>
  <?php echo htmlDivLineSpacer("1px", "", "left"); ?>
  <?php echo defineButtonType10(getLngt("Speichern"), "action_submit", "document.forms[0].f_act.value='". ec($f_actText) . "';finishPageBycheckingMandatoryFields();", "120", "left", "20"); ?>
  <?php echo defineButtonType10(getLngt("Zurücksetzen"), "action_reset", "clearAllFields();", "120", "left", "0"); ?>
  <?php echo $buttonRemove ?>
</div>
<?php echo htmlDivLineSpacer("20px", "", "left"); ?>

<div class="maincontent mc_elem" name="maincontent" id="maincontent">

<form action="../admin/courier_special.php" method="post">
  <input type="hidden" name="f_act" value="">
  <input type="hidden" name="companyId" value="<?php echo ec($companyId) ?>">
  <input type="hidden" name="f_usr_id" value="<?php echo ec($f_usr_id) ?>">
  <input type="hidden" name="f_cmp_authenticated" value="<?php echo ec($f_cmp_authenticated) ?>">
  <input type="hidden" name="f_cmp_visible" value="<?php echo ec($f_cmp_visible) ?>">
  <input type="hidden" name="f_cr_id_parent" value="<?php echo $f_cr_id_parent ?>">
  <input type="hidden" name="f_eid_maxval" value="<?php echo $f_eid_maxval ?>">
  <input type="hidden" name="objecttypemode" value="<?php echo ec($objecttypemode) ?>">
   
  <?php if ($displayTextAuthentication != "") : ?>
    <div class="f10bp1_blue">  	
      <span class="f10bp1_red"><?php echo strtoupper($displayTextAuthentication) ?></span>
      <?php echo htmlDivLineSpacer("20px"); ?>    
    </div>  
  <?php endif; ?>

  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Firma*") ?>, <?php echo getLngt("Zusatz") ?>:</div>
    <div>
      <input type="text" <?php echo $htmlClass01 ?> id="f_cmp_comp" name="f_cmp_comp" value="<?php echo strWrapHtml($f_cmp_comp) ?>" maxlength="35" size="50" tabindex="10">
      <input type="text" <?php echo $htmlClass01 ?> name="f_cmp_comp2" value="<?php echo strWrapHtml($f_cmp_comp2) ?>" maxlength="35" size="50" tabindex="20">&nbsp;&nbsp;&nbsp;&nbsp;
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <?php if (false) : ?>
  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Typ*") ?>:</div>
    <div>
      <?php 
        echo "<select class=\"f8np1\" name=\"f_cmp_type\">" . addOptionsFromTable("metatype","mt_sort","mt_value","mt_sort","mt_type = 'courier_type'",$f_cmp_type) . "</select>"; 
      ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>
  <?php else : ?>
    <input type="hidden" name="f_cmp_type" value="<?php echo $f_cmp_type ?>">
  <?php endif; ?>
  
  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("ExtID*") ?>:</div>
    <div>
      <div style="float:left">
        <?php if ($companyId != "" || !defined('CR_EID_GENERATION') || CR_EID_GENERATION == "") : ?>
          <input type="text" <?php echo $htmlClass01 ?> id="f_cr_eid" name="f_cr_eid" value="<?php echo $f_cr_eid ?>" tabindex="40" <?php if (!defined('CR_EID_EDITABLE') || CR_EID_EDITABLE != "1") : echo "readonly"; endif; ?>>
        <?php else : ?>
          <div style="float:left">
            <input type="text" <?php echo $htmlClass01 ?> id="f_cr_eid" name="f_cr_eid" value="<?php echo $f_cr_eid ?>" size="10" maxlength="40" tabindex="30">&nbsp;
          </div>
          <?php echo defineButtonType08("...", "action_search", "searchMaxEID();", "20", "left", "2") ?>
        <?php endif; ?>
        
        <?php if (defined('CR_SID_STATUS') && CR_SID_STATUS == "1") : ?>
          &nbsp;&nbsp;&nbsp;<?php echo getLngt("SID*") ?>:&nbsp;<input type="text" <?php echo $htmlClass01 ?> id="f_cr_sid" name="f_cr_sid" value="<?php echo $f_cr_sid ?>" size="10" tabindex="30">
        <?php else : ?>
          <input type="hidden" name="f_cr_sid" value="<?php echo $f_cr_sid ?>">
        <?php endif; ?>
              
        <?php if (!defined('MASK_CR_PARENT_HIDE') || MASK_CR_PARENT_HIDE != "1") : ?>
          &nbsp;&nbsp;&nbsp;<?php echo getLngt("(fährt für) Unternehmer") ?>: 
          <!-- Look for real parent id above in input-hidden for storing in DB!!! -->
          <?php if (defined('CR_SID_STATUS') && CR_SID_STATUS == "1") : ?>
             <input type="text" <?php echo $htmlClass01 ?> name="f_cr_sid_parent" value="<?php echo $f_cr_sid_parent ?>" size="10" readonly>
             <input type="hidden" name="f_cr_eid_parent" value="<?php echo $f_cr_eid_parent ?>">
          <?php else : ?>
             <input type="text" <?php echo $htmlClass01 ?> name="f_cr_eid_parent" value="<?php echo $f_cr_eid_parent ?>" size="10" readonly>
             <input type="hidden" name="f_cr_sid_parent" value="<?php echo $f_cr_sid_parent ?>">
          <?php endif; ?>
          &nbsp;
        <?php endif; ?>
      </div>
      <?php if (!defined('MASK_CR_PARENT_HIDE') || MASK_CR_PARENT_HIDE != "1") : ?>
        <?php echo defineButtonType08("...", "action_cr_search", "searchCourier('1');", "20", "left", "2") ?>
        <div style="float:left">
          <a href="javascript:clearCourierParent();"><img src="../images/waste.png" border="0" height="15" width="10" tabindex="60"></a>
        </div>
      <?php endif; ?>

      <div style="float:left">
        &nbsp;&nbsp;&nbsp;&nbsp;<?php echo getLngt("Vertragsbeginn") . ($companyId == "" ? "*" : "") ?>:        
        <input type="text" <?php echo $htmlClass01 ?> id="f_cmp_contract_date_day" name="f_cmp_contract_date_day" value="<?php echo $f_cmp_contract_date_day ?>" size="2" maxlength="2" tabindex="35" onBlur="checkDate(this,'day')">&nbsp;
        <input type="text" <?php echo $htmlClass01 ?> id="f_cmp_contract_date_month" name="f_cmp_contract_date_month" value="<?php echo $f_cmp_contract_date_month ?>" size="2" maxlength="2" tabindex="36" onBlur="checkDate(this,'month')">&nbsp;
        <input type="text" <?php echo $htmlClass01 ?> id="f_cmp_contract_date_year" name="f_cmp_contract_date_year" value="<?php echo $f_cmp_contract_date_year ?>" size="4" maxlength="4" tabindex="37">&nbsp;&nbsp;
        <?php echo getLngt("(TT-MM-JJJJ)") ?>
      </div>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("20px", "", "left"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Name*") ?>, <?php echo getLngt("Vorname*") ?>:</div>
    <div>
      <input type="text" <?php echo $htmlClass01 ?> id="f_usr_name" name="f_usr_name" value="<?php echo strWrapHtml($f_usr_name) ?>" maxlength="50" size="50" tabindex="70">
      <input type="text" <?php echo $htmlClass01 ?> id="f_usr_firstname" name="f_usr_firstname" value="<?php echo strWrapHtml($f_usr_firstname) ?>" maxlength="50" size="50" tabindex="75">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Land der Nationalität") ?>:</div>
    <div>
      <select class="f8np1" name="f_usr_country" tabindex="77">
        <?php echo getCountryCodesAsOptions($f_usr_country, "cou_iso_2", "cou_name", "cou_name", "cou_nation"); ?>
      </select>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Tel.*") ?>, <?php echo getLngt("Mobil") ?>, <?php echo getLngt("Fax") ?>:</div>
    <div>
      <input type="text" <?php echo $htmlClass01 ?> id="f_usr_phone" name="f_usr_phone" value="<?php echo $f_usr_phone ?>" maxlength="20" size="20" tabindex="80">
      <input type="text" <?php echo $htmlClass01 ?> name="f_usr_phone2" value="<?php echo $f_usr_phone2 ?>" maxlength="20" size="20" tabindex="84">
      <input type="text" <?php echo $htmlClass01 ?> name="f_usr_fax" value="<?php echo $f_usr_fax ?>" maxlength="20" size="20" tabindex="87">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Email") ?>, <?php echo getLngt("IMEI-Nr.") ?>, <?php echo getLngt("Seriennr.*") ?>:</div>
    <div>
      <input type="text" <?php echo $htmlClass01 ?> name="f_usr_email" value="<?php echo $f_usr_email ?>" maxlength="250" size="50" tabindex="90">
      <input type="text" <?php echo $htmlClass01 ?> name="f_cr_imei" value="<?php echo $f_cr_imei ?>" maxlength="20" size="20" tabindex="95">
      <input type="text" <?php echo $htmlClass01 ?> id="f_cr_serialno" name="f_cr_serialno" value="<?php echo $f_cr_serialno ?>" maxlength="20" size="20" tabindex="96">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>
  
  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Email-Adr. Rechnungen") ?>:</div>
    <div>
      <input type="text" <?php echo $htmlClass01 ?> name="f_usr_inv_email" value="<?php echo $f_usr_inv_email ?>" maxlength="250" size="50" tabindex="97">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Mobil-Nr. VPA/PDA*") ?>:</div>
    <div>
    	<?php         
        if ($parMaskCrMobilePdaEdit == "1") :
          echo "<input type=\"text\" " . $htmlClass01 . " id=\"f_cr_mobile_pda\" name=\"f_cr_mobile_pda\" value=\"" . $f_cr_mobile_pda . "\" maxlength=\"20\" size=\"20\" tabindex=\"100\">";
    	  else :
    	    if ($dbhostArrayLen > 0 && $dbConnectionArray["app_property"] != "") :
    	       $whereClauseUsrId = "";
    	       if ($f_usr_id != "" && is_numeric($f_usr_id)) : $whereClauseUsrId = " OR usr_id = '" . $f_usr_id . "'"; endif;
    	       $remDb = $db;
             $db = $dbConnectionArray["app_property"];
             echo "<select class=\"f8np1\" id=\"f_cr_mobile_pda\" name=\"f_cr_mobile_pda\" tabindex=\"100\">\n";
             echo "<option value=\"\">" . getLngt("Kein Eintrag") . "</option>\n";
             echo addOptionsFromTable("sysadmin.conf_prop","cp_secval","cp_secval","cp_secval","cust_id = '" . $constGlobalDbInstNo . "' AND hq_id = '" . $hq_id . "' AND prop_id = '1' AND cp_secval != '' AND (usr_id = '' OR usr_id = '0' OR ISNULL(usr_id)" . $whereClauseUsrId . ")",$f_cr_mobile_pda);
             echo "</select>\n";
             $db = $remDb;
          else :
             echo getLngt("**** Zugriffsproblem ****");
             // echo "<input type=\"hidden\" name=\"f_cr_mobile_pda\" value=\"" . $f_cr_mobile_pda . "\">";
          endif;
    	  endif;
      ?>
      &nbsp;&nbsp;&nbsp;<?php echo getLngt("Geburtstag") ?>:
      <input type="text" <?php echo $htmlClass01 ?> name="f_usr_birthdate_day" value="<?php echo $f_usr_birthdate_day ?>" size="2" maxlength="2" tabindex="110" onBlur="checkDate(this,'day')">&nbsp;
      <input type="text" <?php echo $htmlClass01 ?> name="f_usr_birthdate_month" value="<?php echo $f_usr_birthdate_month ?>" size="2" maxlength="2" tabindex="114" onBlur="checkDate(this,'month')">&nbsp;
      <input type="text" <?php echo $htmlClass01 ?> name="f_usr_birthdate_year" value="<?php echo $f_usr_birthdate_year ?>" size="4" maxlength="4" tabindex="117">&nbsp;&nbsp;
      <?php echo getLngt("(TT-MM-JJJJ)") ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("20px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Str.*") ?> & <?php echo getLngt("Hausnr.*") ?>:</div>
    <div>
      <div style="float:left">
        <input type="text" <?php echo $htmlClass01 ?> id="f_ad_street" name="f_ad_street" value="<?php echo strWrapHtml($f_ad_street) ?>" maxlength="50" size="50" tabindex="120">
        <input type="text" <?php echo $htmlClass01 ?> id="f_cmp_hsno" name="f_cmp_hsno" value="<?php echo $f_cmp_hsno ?>" maxlength="10" size="5" tabindex="125">
        &nbsp;
      </div>
      <?php echo defineButtonType08("...", "action_ad_search", "searchAddress();", "20", "left", "2") ?>
      <div>
        &nbsp;&nbsp;<input type="checkbox" name="f_noaddressvalidation[]" value="1" tabindex="150">&nbsp;<?php echo getLngt("(Keine Prüfung)") ?>
      </div>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
  
  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("PLZ*") ?> & <?php echo getLngt("Ort*") ?>:</div>
    <div>
      <input type="text" <?php echo $htmlClass01 ?> id="f_ad_zipcode" name="f_ad_zipcode" value="<?php echo $f_ad_zipcode ?>"  maxlength="10" size="5" tabindex="140">
      <input type="text" <?php echo $htmlClass01 ?> id="f_ad_city" name="f_ad_city" value="<?php echo strWrapHtml($f_ad_city) ?>" maxlength="50" size="50" tabindex="144">
      <select class="f8np1" name="f_ad_country" tabindex="147">
        <?php echo getCountryCodesAsOptions($f_ad_country); ?>
      </select>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("20px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt(wrapPhrase("Freitext", $objecttypemode)) ?>:</div>
    <div>
      <textarea name="f_cmp_freetext1" cols="75" rows="1" tabindex="220"><?php echo $f_cmp_freetext1 ?></textarea>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("20px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Bank") ?>,&nbsp;<?php echo getLngt("BLZ") ?> & <?php echo getLngt("Konto") ?>:</div>
    <div>
      <input type="text" <?php echo $htmlClass01 ?> name="f_cmp_bank" value="<?php echo strWrapHtml($f_cmp_bank) ?>" maxlength="30" size="30" tabindex="160">
      <input type="text" <?php echo $htmlClass01 ?> name="f_cmp_bankno" value="<?php echo $f_cmp_bankno ?>" maxlength="20" size="20" tabindex="164">
      <input type="text" <?php echo $htmlClass01 ?> name="f_cmp_bankacc" value="<?php echo $f_cmp_bankacc ?>" maxlength="20" size="20" tabindex="167">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>
  
  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("IBAN") ?>,&nbsp;<?php echo getLngt("BIC/Swift") ?>:</div>
    <div>
      <input type="text" <?php echo $htmlClass01 ?> name="f_cmp_iban" value="<?php echo $f_cmp_iban ?>" maxlength="40" size="40" tabindex="170">
      <input type="text" <?php echo $htmlClass01 ?> name="f_cmp_swift" value="<?php echo $f_cmp_swift ?>" maxlength="20" size="20" tabindex="175">
    </div>
  </div>  
  <?php echo htmlDivLineSpacer("10px"); ?>
  
  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Steuernr.*") ?>,&nbsp;<?php echo getLngt("USt-ID") ?>:</div>
    <div>
      <input type="text" <?php echo $htmlClass01 ?> id="f_cmp_tax_idno" name="f_cmp_tax_idno" value="<?php echo $f_cmp_tax_idno ?>" maxlength="30" size="30" tabindex="180">
      <input type="text" <?php echo $htmlClass01 ?> name="f_cmp_stax_idno" value="<?php echo $f_cmp_stax_idno ?>" maxlength="30" size="30" tabindex="185">
    </div>
  </div>  
  <?php echo htmlDivLineSpacer("20px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Anmeldename*") ?>:</div>
    <div>
      <input type="text" <?php echo $htmlClass01 ?> id="f_usr_account" name="f_usr_account" value="<?php echo $f_usr_account ?>" maxlength="20" size="20" tabindex="190">
      <?php echo $setPasswordForNewUserOutput ?>
      <?php echo $setPassword2ForNewUserOutput ?>
    </div>
  </div>  
  <?php echo htmlDivLineSpacer("10px"); ?>

  <?php if ($maskHideCrVhtInv != "1") : ?>
    <div>
      <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Rechnungsfahrzeugtyp*") ?>:</div>
      <div>
        <select class="f8np1" id="f_vht_id_inv" name="f_vht_id_inv" tabindex="200">
          <?php
            // Check excludes vehicle type IDs
            $mask_exclude_vht_ids = getParameterValue("0", "MASK_EXCLUDE_VHT_IDS", $hq_id);
            if ($mask_exclude_vht_ids != "") $mask_exclude_vht_ids = " AND NOT mt_sort IN (" . $mask_exclude_vht_ids . ")";
            echo addOptionsFromTable("metatype","mt_sort","mt_value","mt_sort","mt_type = 'vehicletype'" . $mask_exclude_vht_ids, $f_vht_id_inv);
          ?>
        </select>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <?php echo getLngt("Wahl-/Wunsch-PLZ") ?>:
        <input type="text" <?php echo $htmlClass01 ?> name="f_cr_homezipcode" value="<?php echo $f_cr_homezipcode ?>" maxlength="10" size="10" tabindex="149">
        <!-- 
        KFZ-Kennzeichen: 
        <input type="text" <?php echo $htmlClass01 ?> name="f_cr_vh_sign" value="<?php echo $f_cr_vh_sign ?>" maxlength="10" size="10" tabindex="19"> 
        -->
      </div>
    </div>  
    <?php echo htmlDivLineSpacer("10px"); ?>
  <?php else : ?>
    <input type="hidden" name="f_vht_id_inv" value="<?php echo $f_vht_id_inv ?>">
  <?php endif; ?>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <?php 
    $maskHideCrOutlay = getParameterValue("0", "MASK_HIDE_CR_OUTLAY", $hq_id);
    if ($maskHideCrOutlay == "") : $maskHideCrOutlay = getParameterValue("0", "MASK_HIDE_CR_OUTLAY", "0"); endif;
    $maskHideCrDisposition = getParameterValue("0", "MASK_HIDE_CR_DISPOSITION", $hq_id);
    if ($maskHideCrDisposition == "") : $maskHideCrDisposition = getParameterValue("0", "MASK_HIDE_CR_DISPOSITION", "0"); endif;
  ?>
  <?php if ($maskHideCrOutlay != "1" || $maskHideCrDisposition != "1") : ?>
    <div>
      <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php if ($maskHideCrOutlay != "1") : echo getLngt("Einstellungen") . ":"; endif; ?>&nbsp;</div>
      <div>
      	<?php if ($maskHideCrOutlay != "1") : ?>
          <?php echo getLngt("Maximale Auslage:") ?> <input type="text" <?php echo $htmlClass01 ?> name="f_cr_outlay" value="<?php echo $f_cr_outlay ?>" size="5" maxlength="5" tabindex="205">
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <?php else : ?>
          <input type="hidden" name="f_cr_outlay" value="<?php echo $f_cr_outlay ?>">
        <?php endif; ?>
        <?php if ($maskHideCrDisposition != "1") : ?>
          <?php echo getLngt("Disposition der eigenen Fahrzeuge:") ?> <input class="f8np1" type="checkbox" name="f_cr_disposition[]" value="1" <?php echo $f_cr_disposition_0 ?> tabindex="207">
        <?php else : ?>
          <input type="hidden" name="f_cr_disposition" value="">
        <?php endif; ?>
        <?php if (false) : ?>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <?php echo getLngt("Frachtvergütungsanzeige in App") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_cr_price_show[]" value="1" <?php echo $f_cr_price_show_0 ?> tabindex="207">
        <?php endif; ?>
        <?php if (true) : ?>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <?php echo getLngt("Keine bundesweite Vermittlung:") ?> <input class="f8np1" type="checkbox" name="f_cmp_no_longhaul[]" value="1" <?php echo $f_cmp_no_longhaul_0 ?> tabindex="207">
        <?php endif; ?>
      </div>
    </div>  
    <?php echo htmlDivLineSpacer("10px"); ?>
  <?php endif; ?>

  <?php if ($parMaskCrCartageLinksDisabled != "1") : ?>
    <div>
      <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Fuhrlöhne") ?>, <?php echo getLngt("Frachtvergütungsrabatte") ?>:</div>
      <div>
        <?php echo $serviceLink1 ?>&nbsp;&nbsp;
        <?php echo $serviceLink2 ?>&nbsp;&nbsp;
        <?php echo $serviceLink3 ?>&nbsp;&nbsp;
        <?php echo $serviceLink4 ?>&nbsp;&nbsp;
      </div>
    </div>
    <?php echo htmlDivLineSpacer("15px"); ?>
  <?php endif; ?>

  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Derzeit online") ?>:</div>
    <div>
      <?php echo $onlineOut ?>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("APP-Zugang gesperrt") ?>: <input class="f8np1" type="checkbox" name="f_cr_app_blocked[]" value="1" <?php echo $f_cr_app_blocked_0 ?>>
    </div>
  </div>  
  <?php echo htmlDivLineSpacer("20px"); ?>
  
  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Bemerkung") ?>:</div>
    <div>
      <input type="text" <?php echo $htmlClass01 ?> name="f_cmp_remark" value="<?php echo strWrapHtml($f_cmp_remark) ?>" size="100" tabindex="210">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>
  
  <div>
    <div <?php echo setStyleHtmlDiv("170px","left"); ?>><?php echo getLngt("Intern") ?>:</div>
    <div>
      <textarea name="f_cmp_remark2" cols="75" rows="1" tabindex="220"><?php echo $f_cmp_remark2 ?></textarea>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("20px"); ?>
  
  <?php 
    $parMaskFormsCR = getParameterValue("0", "MASK_FORMS_CR", "0");
    $outFormLinks = "";
    if ($parMaskFormsCR != "") :
       $parMaskFormsCRArray = spliti(",", $parMaskFormsCR);
       $parMaskFormsCRArrayLen = count($parMaskFormsCRArray);
       $outFormLinks .= htmlDivLineSpacer("30px", "", "left");
       for ($i = 0; $i < $parMaskFormsCRArrayLen; $i++) :
           $mtfcId = $parMaskFormsCRArray[$i];
           $mtfcDescription = getFieldValueFromId("metafieldcategory", "mtfc_id", $mtfcId, "mtfc_description");
           $outFormLinks .= "<div>\n";
           $outFormLinks .= "<a href=\"javascript:openMetaFieldSpecial('" . ec($mtfcId) . "', '" . ec($f_cr_id) . "','" . $mtfcDescription . "')\">" . $mtfcDescription . "</a>\n";
           $outFormLinks .= "</div>\n";
           $outFormLinks .= htmlDivLineSpacer("10px");
       endfor;
    endif;
    echo $outFormLinks;
  ?>

</form>
</div>
</body>

</html>
