<?php
/*=======================================================================
 *
 * hq_admin.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 ("../include/html.inc.php");


// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "f_hq_id", "statusMessage", "deactivateMenu", "configDisplayMode",
                         "par_locatingByPDA", "par_locatingFromHrs", "par_locatingFromMin", "par_locatingToHrs", "par_locatingToMin"));

getLanguage(__FILE__);

$pageTitel = getLngt("NIEDERLASSUNGEN");
$pageHeadline = getLngt("Globale Einstellungen");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
include_once ("../include/inc_stock.inc.php");
getCurrentScript(__FILE__);

mcIsSet($customerId, "0");
mcIsSet($cscIdRoot, "0");
mcIsSet($cscIdActual, "0");

if ($configDisplayMode == "" || $configDisplayMode == "0") : $configDisplayMode = "1"; endif;

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


// Names of the headquarters e.g. for the global parameters
$hqNameArr = getColVectorFromDB2ArrayByClause("headquarters", "hq_name", "", "hq_id", "hq_id");

// All headquarters of the mandator and additional extended array with "0" (<=> all headquarters)
$f_hq_id_ext_len = 0;
if ($userTypeName == "hq") :
   // Extended field needed for global parameters
   $f_hq_id_ext = getColVectorFromDB2Array("mandatorheadquarters","md_id",$md_id,"hq_id");
   array_unshift($f_hq_id_ext, 0);
   $f_hq_id_ext_len = count($f_hq_id_ext);
endif;

// Special rights
$empHasGeneralAccessToHeadquartersAdministration = authCheckEmployeeRights($emp_id, "47");  // General access to headquarters administration
$empHasAccessregardingHeadquartersManager = authCheckEmployeeRights($emp_id, "32");         // Headquarters manager
$empHasAccessToModifyPDALocatingState = authCheckEmployeeRights($emp_id, "9");              // VPA locating
$empHasAccessToHeadquarters = authCheckEmployeeRights($emp_id, "10");                       // Access to all headquarters
$empHasAccessToEditBwvHotlineNumbers = authCheckEmployeeRights($emp_id, "45");              // BWV hotline

// Current timestamp
$currentTime = getDateTime("0");

// Get the emp_id of the root admin, e.g. setting new passwords of employees
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);

// For output only
$styleDivWidth01 = "190px";  // Container for parameterizing lists


if ($f_act != "") :            
            
   // Change GLOBAL parameters (for headquarter)
   if ($f_act == "setGlobPar") :
         
      if ($empHasGeneralAccessToHeadquartersAdministration) :
         $tmpLogStr = "";
         for ($f = 1; $f < $f_hq_id_ext_len; $f++) :

            getSecHttpVars("1",array("hq_data_cmp_comp_" . $f_hq_id_ext[$f], "hq_data_cmp_comp2_" . $f_hq_id_ext[$f], "hq_data_cmp_comp3_" . $f_hq_id_ext[$f], "hq_data_cmp_comp4_" . $f_hq_id_ext[$f], 
                                     "hq_data_ad_street_" . $f_hq_id_ext[$f], "hq_data_cmp_hsno_" . $f_hq_id_ext[$f], "hq_data_ad_zipcode_" . $f_hq_id_ext[$f], "hq_data_ad_city_" . $f_hq_id_ext[$f]));

            $cmpComp   = trim(${("hq_data_cmp_comp_"    . $f_hq_id_ext[$f])}); $cmpComp2  = trim(${("hq_data_cmp_comp2_"   . $f_hq_id_ext[$f])}); 
            $cmpComp3  = trim(${("hq_data_cmp_comp3_"   . $f_hq_id_ext[$f])}); $cmpComp4  = trim(${("hq_data_cmp_comp4_"   . $f_hq_id_ext[$f])});
            $adStreet  = trim(${("hq_data_ad_street_"   . $f_hq_id_ext[$f])}); $cmpHsno   = trim(${("hq_data_cmp_hsno_"    . $f_hq_id_ext[$f])});
            $adZipcode = trim(${("hq_data_ad_zipcode_"  . $f_hq_id_ext[$f])}); $adCity    = trim(${("hq_data_ad_city_"     . $f_hq_id_ext[$f])});

            $hqCmpId = getFieldValueFromId("headquarters","hq_id", $f_hq_id_ext[$f],"cmp_id");
            if ($hqCmpId != "" && is_numeric($hqCmpId) && $hqCmpId > 0) :
               updateStmt("company", "cmp_id", $hqCmpId, array("cmp_comp", $cmpComp, "cmp_comp2", $cmpComp2, "cmp_comp3", $cmpComp3, "cmp_comp4", $cmpComp4, "cmp_hsno", $cmpHsno));
               $hqAdId = getFieldValueFromId("company","cmp_id", $hqCmpId,"ad_id");
               if ($hqAdId != "" && is_numeric($hqAdId) && $hqAdId > 0) :
                  updateStmt("address", "ad_id", $hqAdId, array("ad_street", $adStreet, "ad_zipcode", $adZipcode, "ad_city", $adCity));
               else :
                  insertStmt("address", array("ad_street", $adStreet, "ad_zipcode", $adZipcode, "ad_city", $adCity));
                  $adIdNew = getLastInsertID();
                  updateStmt("company", "cmp_id", $hqCmpId, array("ad_id", $adIdNew));
               endif;
            endif;

            if ($tmpLogStr != "") : $tmpLogStr .= "|"; endif;
            $tmpLogStr .= $f . "=" . $hqCmpId . ";" . $hqAdId . ";" . $cmpComp . ";" . $cmpComp2 . ";" . $cmpComp3 . ";" . $cmpComp4 . ";" . $adStreet . ";" . $cmpHsno . ";" . $adZipcode . ";" . $adCity;
         endfor;

         // Write logdata into log database
         writeToLogDB("199",$hq_id,"",$usr_id,"","","","" . $tmpLogStr,"","","");
      endif;

      if ($empHasGeneralAccessToHeadquartersAdministration && $empHasAccessToModifyPDALocatingState) :
/*
         // Store value to enable/disable the PDA locating
         if (is_numeric($par_locatingByPDA)) :
            if (existsEntry("parameter",array("par_key","LOCATING_PDA_ENABLED","emp_id","0","hq_id",$hq_id))) :
                updateStmt("parameter", "emp_id", "0", array("par_value", $par_locatingByPDA), " par_key = 'LOCATING_PDA_ENABLED' AND hq_id = '" . $hq_id . "'");
            else:
                insertStmt("parameter", array("par_key", "LOCATING_PDA_ENABLED", "emp_id", "0", "par_value", $par_locatingByPDA, "hq_id", $hq_id, "md_id", $md_id));
            endif;
         else : 
            $statusMessage = getLngt("Der Status konnte nicht geändert werden.");
         endif;

         // Store interval for the PDA locating
         if ($par_locatingFromHrs == "" || !is_numeric($par_locatingFromHrs)) : $par_locatingFromHrs = "0"; endif;
         if ($par_locatingFromMin == "" || !is_numeric($par_locatingFromMin)) : $par_locatingFromMin = "0"; endif;
         if ($par_locatingToHrs == "" || !is_numeric($par_locatingToHrs)) : $par_locatingToHrs = "23"; endif;
         if ($par_locatingToMin == "" || !is_numeric($par_locatingToMin)) : $par_locatingToMin = "59"; endif;
         // Check for from-time <= to-time
         if ($par_locatingToHrs < $par_locatingFromHrs || ($par_locatingToHrs == $par_locatingFromHrs && $par_locatingToMin < $par_locatingFromMin)) :
            $statusMessage = getLngt("Die obere Intervallgrenze für die VPA-Ortung ist kleiner als die untere. Bitte neu eingeben!");
         else :
            if (existsEntry("parameter",array("par_key","LOCATING_PDA_INTERVAL","emp_id","0","hq_id",$hq_id))) :
               updateStmt("parameter", "emp_id", "0", array("par_value", $par_locatingFromHrs . "," . $par_locatingFromMin . "," . $par_locatingToHrs . "," . $par_locatingToMin), " par_key = 'LOCATING_PDA_INTERVAL' AND hq_id = '" . $hq_id . "'");
            else:
               insertStmt("parameter", array("par_key", "LOCATING_PDA_INTERVAL", "emp_id", "0", "par_value", $par_locatingFromHrs . "," . $par_locatingFromMin . "," . $par_locatingToHrs . "," . $par_locatingToMin, "hq_id", $hq_id, "md_id", $md_id));
            endif;
         endif;

         // Write logdata into log database
         writeToLogDB("194",$hq_id,"",$usr_id,"","","","LOC_GLOB_PAR_STATE=" . $par_locatingByPDA . "|LOC_GLOB_PAR_INTERVAL=" . $par_locatingFromHrs . "," . $par_locatingFromMin . "," . $par_locatingToHrs . "," . $par_locatingToMin,"","","");
*/
      endif;

      if ($empHasGeneralAccessToHeadquartersAdministration && $empHasAccessToEditBwvHotlineNumbers) :
         $tmpLogStr = "";
         for ($f = 0; $f < $f_hq_id_ext_len; $f++) :

            // BWV-Hotline
            getSecHttpVars("1",array("par_BWV_phone_" . $f_hq_id_ext[$f]));
            $par_BWV_phone = ${("par_BWV_phone_" . $f_hq_id_ext[$f])};
            if (existsEntry("parameter",array("par_key","BWV_PHONE_NO","emp_id","0","hq_id",$f_hq_id_ext[$f]))) :
                updateStmt("parameter", "emp_id", "0", array("par_value", $par_BWV_phone), " par_key = 'BWV_PHONE_NO' AND hq_id = '" . $f_hq_id_ext[$f] . "'");
            else:
                insertStmt("parameter", array("par_key", "BWV_PHONE_NO", "emp_id", "0", "par_value", $par_BWV_phone, "hq_id", $f_hq_id_ext[$f], "md_id", $md_id));
            endif;
            if ($tmpLogStr != "") : $tmpLogStr .= "|"; endif;
            $tmpLogStr .= $f . "=" . $par_BWV_phone;

            // GLN
            getSecHttpVars("1",array("par_GLN_" . $f_hq_id_ext[$f]));
            $par_GLN = ${("par_GLN_" . $f_hq_id_ext[$f])};
            if ($f == 0) :
               if (existsEntry("parameter",array("par_key","GLN_HQ_ALL","emp_id","0","hq_id",$f_hq_id_ext[$f]))) :
                   updateStmt("parameter", "emp_id", "0", array("par_value", $par_GLN), " par_key = 'GLN_HQ_ALL' AND hq_id = '" . $f_hq_id_ext[$f] . "'");
               else:
                   insertStmt("parameter", array("par_key", "GLN_HQ_ALL", "emp_id", "0", "par_value", $par_GLN, "hq_id", $f_hq_id_ext[$f], "md_id", $md_id));
               endif;
            else :
               updateStmt("headquarters", "hq_id", $f_hq_id_ext[$f], array("hq_gln", $par_GLN), "");
            endif;
            if ($tmpLogStr != "") : $tmpLogStr .= "|"; endif;
            $tmpLogStr .= "," . $par_GLN;

            // DUNS
            getSecHttpVars("1",array("par_DUNS_" . $f_hq_id_ext[$f]));
            $par_DUNS = ${("par_DUNS_" . $f_hq_id_ext[$f])};
            if ($f == 0) :
               if (existsEntry("parameter",array("par_key","DUNS_HQ_ALL","emp_id","0","hq_id",$f_hq_id_ext[$f]))) :
                   updateStmt("parameter", "emp_id", "0", array("par_value", $par_DUNS), " par_key = 'DUNS_HQ_ALL' AND hq_id = '" . $f_hq_id_ext[$f] . "'");
               else:
                   insertStmt("parameter", array("par_key", "DUNS_HQ_ALL", "emp_id", "0", "par_value", $par_DUNS, "hq_id", $f_hq_id_ext[$f], "md_id", $md_id));
               endif;
            else :
               updateStmt("headquarters", "hq_id", $f_hq_id_ext[$f], array("hq_duns", $par_DUNS), "");
            endif;
            if ($tmpLogStr != "") : $tmpLogStr .= "|"; endif;
            $tmpLogStr .= "," . $par_DUNS;
         endfor;

         // Write logdata into log database
         writeToLogDB("196",$hq_id,"",$usr_id,"","","","" . $tmpLogStr,"","","");
      endif;
   endif;
endif;


// Button for setting GLOBAL PARAMETERS
$buttonGlobalSettings = defineButtonType10(getLngt("Speichern"), "action_save_globs", "finishPage('" . ec("setGlobPar") . "');", "140", "left");

$outHqAddress = "";
$outHotlineBWV = "";
$outGLN = "";
$outDUNS = "";
$outVHT = "";
$outLocatingVPA = "";

if ($userTypeName == "hq") : 

   // Headquarters master data (address, etc.)
   if ($empHasGeneralAccessToHeadquartersAdministration || $empHasAccessToHeadquarters) :
      
      $outHqAddress .= "";
      
      for ($f = 1; $f < $f_hq_id_ext_len; $f++) :

          $hqCmpId = getFieldValueFromId("headquarters","hq_id", $f_hq_id_ext[$f],"cmp_id");
          $hqCmpFields = getFieldsValueFromId("company", "cmp_id", $hqCmpId, array("cmp_comp","cmp_comp2","cmp_comp3","cmp_comp4","ad_id","cmp_hsno"));          
          $cmpAdId = $hqCmpFields[4];
          $hqAdFields = getFieldsValueFromId("address", "ad_id", $cmpAdId, array("ad_street","ad_zipcode","ad_city","ad_country"));

          $outHqAddress .= "<div style=\"width:700px\"><b>" . getLngt("Niederlassung") . "&nbsp;" . $hqNameArr[$f_hq_id_ext[$f]] . "</b></br>";

          if (($empHasGeneralAccessToHeadquartersAdministration || ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin))) :
             $outHqAddress .= "<div>";
             $outHqAddress .= "<input type=\"text\" name=\"hq_data_cmp_comp_"   . $f_hq_id_ext[$f] . "\" value=\"" . $hqCmpFields[0] . "\" placeholder=\"" . getLngt("[1]") . "\"   size=\"50\">" . "&nbsp;";
             $outHqAddress .= "<input type=\"text\" name=\"hq_data_cmp_comp2_"  . $f_hq_id_ext[$f] . "\" value=\"" . $hqCmpFields[1] . "\" placeholder=\"" . getLngt("[2]") . "\"  size=\"50\">" . "";
             $outHqAddress .= "</div><div>";
             $outHqAddress .= "<input type=\"text\" name=\"hq_data_cmp_comp3_"  . $f_hq_id_ext[$f] . "\" value=\"" . $hqCmpFields[2] . "\" placeholder=\"" . getLngt("[3]") . "\"  size=\"50\">" . "&nbsp;";
             $outHqAddress .= "<input type=\"text\" name=\"hq_data_cmp_comp4_"  . $f_hq_id_ext[$f] . "\" value=\"" . $hqCmpFields[3] . "\" placeholder=\"" . getLngt("[4]") . "\"  size=\"50\">" . "";
             $outHqAddress .= "</div><div>";
             $outHqAddress .= "<input type=\"text\" name=\"hq_data_ad_street_"  . $f_hq_id_ext[$f] . "\" value=\"" . $hqAdFields[0]  . "\" placeholder=\"" . getLngt("Strasse") . "\" size=\"50\">" . "&nbsp;";
             $outHqAddress .= "<input type=\"text\" name=\"hq_data_cmp_hsno_"   . $f_hq_id_ext[$f] . "\" value=\"" . $hqCmpFields[5] . "\" placeholder=\"" . getLngt("Hausnr.") . "\" size=\"10\">" . "";
             $outHqAddress .= "</div><div>";
             $outHqAddress .= "<input type=\"text\" name=\"hq_data_ad_zipcode_" . $f_hq_id_ext[$f] . "\" value=\"" . $hqAdFields[1]  . "\" placeholder=\"" . getLngt("PLZ") . "\"     size=\"10\">" . "&nbsp;";
             $outHqAddress .= "<input type=\"text\" name=\"hq_data_ad_city_"    . $f_hq_id_ext[$f] . "\" value=\"" . $hqAdFields[2]  . "\" placeholder=\"" . getLngt("Ort") . "\"     size=\"50\">" . "&nbsp;";
             $outHqAddress .= "</div>";
          else :
             $outHqAddress .= "<div>";
             $outHqAddress .= $hqCmpFields[0] . "&nbsp;" . $hqCmpFields[1];
             $outHqAddress .= "</div><div>";
             $outHqAddress .= $hqCmpFields[2] . "&nbsp;" . $hqCmpFields[3];
             $outHqAddress .= "</div><div>";
             $outHqAddress .= $hqAdFields[0]  . "&nbsp;" . $hqCmpFields[5];
             $outHqAddress .= "</div><div>";
             $outHqAddress .= $hqAdFields[1]  . "&nbsp;" . $hqAdFields[2];
             $outHqAddress .= "</div>";
          endif;          
          $outHqAddress .= "<br><br></div>\n";
      endfor;
   endif;

   // VPA locating
   if ($empHasAccessToModifyPDALocatingState) :
/*
      // Get current state of locating mode
      $locatingByPDA = getParameterValue("0", "LOCATING_PDA_ENABLED");   // Get hq value from table "parameter"
      if ($locatingByPDA == "" || !is_numeric($locatingByPDA) || !($locatingByPDA == "0" || $locatingByPDA == "1")) :
         $locatingByPDA = LOCATING_PDA_ENABLED;
         if (!is_numeric($locatingByPDA) || !($locatingByPDA == "0" || $locatingByPDA == "1")) :
            $locatingByPDA = "1";     // Enable per default
         endif;
      endif;
      // Get interval of locating mode if mode is activated
      $intervalStatus = array();
      $locatingInterval = getParameterValue("0", "LOCATING_PDA_INTERVAL");   // Get corresponding interval
      if ($locatingInterval == "") :
         $locatingInterval = LOCATING_PDA_INTERVAL;
      endif;
      if ($locatingInterval != "") :
         $intervalStatus = explode(",",$locatingInterval);
      endif;
// for ($f = 0; $f < $f_hq_id_ext_len; $f++) :
      $outLocatingVPA .= "<div style=\"float:left;width:80px\"><b>" . getLngt("VPA-Ortung:") . "</b></div>\n" .
                         "<div><select name=\"par_locatingByPDA\">" . addOptionsGenericText(array(getLngt("Aus"),getLngt("An")),$locatingByPDA,"") . "</select><br><br></div>\n";
      $outLocatingVPA .= "<div style=\"float:left;width:80px\"><b>" . getLngt("Intervall bei<br>Aktivierung:") . "</b></div>\n" .
                         "<div>" .
                           "<select name=\"par_locatingFromHrs\">" . addOptionsFromRange("0","23",$intervalStatus[0],"1") . "</select> : " . 
                           "<select name=\"par_locatingFromMin\">" . addOptionsFromRange("0","59",$intervalStatus[1],"1") . "</select>" .
                           "&nbsp;&nbsp;(" . getLngt("von") . ")" .
                         "</div>\n" .
                         "<div style=\"float:left;width:80px\">&nbsp;</div>\n" .
                         "<div>" .
                           "<select name=\"par_locatingToHrs\">" . addOptionsFromRange("0","23",$intervalStatus[2],"1") . "</select> : " . 
                           "<select name=\"par_locatingToMin\">" . addOptionsFromRange("0","59",$intervalStatus[3],"1") . "</select>" .
                           "&nbsp;&nbsp;(" . getLngt("bis") . ")" . "<br><br>" .
                         "</div>\n";
*/
   endif;

   // BWV-Hotline, GLN, DUNS
   if ($empHasAccessToEditBwvHotlineNumbers) :

      $par_GLN_HQ_ALL = getParameterValue("0", "GLN_HQ_ALL", "0");
      $par_DUNS_HQ_ALL = getParameterValue("0", "DUNS_HQ_ALL", "0");

      for ($f = 0; $f < $f_hq_id_ext_len; $f++) :

          // BWV-Hotline
          $par_BWV_phone = getParameterValue("0", "BWV_PHONE_NO", (string) $f_hq_id_ext[$f]);
          $outHotlineBWV .= "<div style=\"width:300px\"><b>" . ($f_hq_id_ext[$f] == "0" ? getLngt("BWV-Hotline bundesweit:") : getLngt("BWV-Hotline") . "&nbsp;" . $hqNameArr[$f_hq_id_ext[$f]]) . "</b><br>";
          if (($empHasGeneralAccessToHeadquartersAdministration || ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin)) && authCheckEmployeeRights($emp_id, "45")) :
             $outHotlineBWV .= "<input type=\"text\" name=\"par_BWV_phone_" . $f_hq_id_ext[$f] . "\" value=\"" . $par_BWV_phone . "\">";
          else :
             $outHotlineBWV .= $par_BWV_phone;
          endif;          
          $outHotlineBWV .= "<br><br></div>\n";

          // GLN
          $hq_gln = "";
          if ($f > 0) :
             $hq_gln = getFieldValueFromId("headquarters","hq_id", $f_hq_id_ext[$f],"hq_gln");
          endif;
          $outGLN .= "<div style=\"width:300px\"><b>" . ($f_hq_id_ext[$f] == "0" ? getLngt("GLN bundesweit:") : getLngt("GLN") . "&nbsp;" . $hqNameArr[$f_hq_id_ext[$f]]) . "</b><br>";
          if (($empHasGeneralAccessToHeadquartersAdministration || ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin)) && authCheckEmployeeRights($emp_id, "45")) :
             if ($f == 0) :
                $outGLN .= "<input type=\"text\" name=\"par_GLN_0\" value=\"" . $par_GLN_HQ_ALL . "\">";
             else :
                $outGLN .= "<input type=\"text\" name=\"par_GLN_" . $f_hq_id_ext[$f] . "\" value=\"" . $hq_gln . "\">";
             endif;
          else :
             if ($f == 0) :
                $outGLN .= $par_GLN_HQ_ALL;
             else :
                $outGLN .= $hq_gln;
             endif;
          endif;
          $outGLN .= "<br><br></div>\n";

          // DUNS
          $hq_duns = "";
          if ($f > 0) :
             $hq_duns = getFieldValueFromId("headquarters","hq_id", $f_hq_id_ext[$f],"hq_duns");
          endif;
          $outDUNS .= "<div style=\"width:300px\"><b>" . ($f_hq_id_ext[$f] == "0" ? getLngt("DUNS bundesweit:") : getLngt("DUNS") . "&nbsp;" . $hqNameArr[$f_hq_id_ext[$f]]) . "</b><br>";
          if (($empHasGeneralAccessToHeadquartersAdministration || ($empIdRootAdmin != "" && $emp_id == $empIdRootAdmin)) && authCheckEmployeeRights($emp_id, "45")) :
             if ($f == 0) :
                $outDUNS .= "<input type=\"text\" name=\"par_DUNS_0\" value=\"" . $par_DUNS_HQ_ALL . "\">";
             else :
                $outDUNS .= "<input type=\"text\" name=\"par_DUNS_" . $f_hq_id_ext[$f] . "\" value=\"" . $hq_duns . "\">";
             endif;
          else :
             if ($f == 0) :
                $outDUNS .= $par_DUNS_HQ_ALL;
             else :
                $outDUNS .= $hq_duns;
             endif;
          endif;
          $outDUNS .= "<br><br></div>\n";
      endfor;
   endif;
   
   // Vehicle classes (output only)
   if (true) :   
   
      $sqlquery = "SELECT hq.hq_mnemonic, cr.hq_id, crvh.vht_id, mt.mt_value, COUNT(*) AS num"
                . " FROM couriervehicle AS crvh, courier AS cr, metatype AS mt, headquarters AS hq, mandatorheadquarters AS md"
                . " WHERE crvh.cr_id = cr.cr_id AND cr.hq_id = hq.hq_id AND md.hq_id = hq.hq_id AND"
                . "        crvh.vht_id = mt.mt_sort AND mt.mt_type = 'vehicletype'"
                . " GROUP BY cr.hq_id, crvh.vht_id"
                . " ORDER BY hq.hq_mnemonic, crvh.vht_id";
// echo $sqlquery . "<br>";

      $result = $db->dbQ($sqlquery);
      $remHqId = 0;
      while ($row = $result->fetch_assoc()):
            $hqId = $row["hq_id"];
            $hqMnemonic = $row["hq_mnemonic"];
            $vhtName = $row["mt_value"];
            $numOfVehiclesPerClass = $row["num"];

            if ($remHqId == 0) : 
               $remHqId = $hqId;
               $outVHT .= "<div style=\"width:700px\"><b>" . getLngt("Niederlassung") . "&nbsp;" . $hqMnemonic . "</b>";
            endif;

            if ($remHqId != $hqId) :
               $remHqId = $hqId;
               $outVHT .= "<br><br></div>\n";
               $outVHT .= "<div style=\"width:700px\"><b>" . getLngt("Niederlassung") . "&nbsp;" . $hqMnemonic . "</b>";
            endif;
            $outVHT .= "<div><span style=\"display: inline-block; width: 70px\">" . getLngt($vhtName) . "</span>" . "&nbsp;" . "<span style=\"display: inline-block; width: 30px; text-align: right;\">" . $numOfVehiclesPerClass . "</span></div>";
      endwhile;
      $outVHT .= "<br><br></div>\n";
      $result->free();

   endif;
   
endif;
?>

<html>

<head>
<title><?php echo $pageTitel ?> <?php echo $usr_account ?></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"); ?>

  .flex-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
    flex-wrap: nowrap;
  }

  .divNav {
    flex: 0 0 200px;
    padding: 20px;      
    display: flex;
    flex-direction: column;
  }
  
  .divContent1, .divContent2, .divContent3, .divContent4, .divContent5, .divContent6 {
    flex: 1;
    padding: 20px;      
    display: flex;
    flex-direction: column;
  }  
</style>

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

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

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

function finishPage(f_act) {
  document.forms[0].f_act.value = f_act;
  document.forms[0].submit();  
};

var configDisplayMode = '<?php echo $configDisplayMode; ?>';
function changeDisplay (configDisplayModeNew) {
	if (configDisplayMode != configDisplayModeNew) {
	   myhide('divContent' + configDisplayMode);
	   myshow('divContent' + configDisplayModeNew);
	   configDisplayMode = configDisplayModeNew;
	   $('#configDisplayMode').val(configDisplayModeNew);
  }
}

function initDisplay () {
	myhide('divContent1');
	myhide('divContent2');
	myhide('divContent3');
	myhide('divContent4');
	myhide('divContent5');
	myhide('divContent6');
	myshow('divContent' + configDisplayMode);
}

-->
</script>

</head>

<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>initDisplay();changeDisplay('<?php echo $configDisplayMode; ?>');displayStatusMessage();">

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

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

<?php // echo htmlDivLineSpacer("5px", "", "left"); ?>
<div>
  <?php echo $buttonGlobalSettings ?>
</div> 
<?php echo htmlDivLineSpacer("20px", "", "left"); ?>

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

<form action="../admin/hq_admin.php" method="post">
  <input type="hidden" name="f_act" value="">
  <?php echo $phpCurrentNavigationInputHidden ?>
  <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
  <input type="hidden" id="configDisplayMode" name="configDisplayMode" value="<?php echo $configDisplayMode ?>">

<div class="flex-container">
  <!-- 0. column -->
  <div class="divNav" id="divNav">
    <div>
    	<?php
        echo defineButtonType10(getLngt("Standortadresse"), "action_change_1", "changeDisplay('1');", "160");
        echo htmlDivLineSpacer("5px");
        echo defineButtonType10(getLngt("BWV-Hotline"), "action_change_2", "changeDisplay('2');", "160");
        echo htmlDivLineSpacer("5px");
        echo defineButtonType10(getLngt("GLN"), "action_change_3", "changeDisplay('3');", "160");
        echo htmlDivLineSpacer("5px");
        echo defineButtonType10(getLngt("DUNS"), "action_change_4", "changeDisplay('4');", "160");
        echo htmlDivLineSpacer("5px");
        echo defineButtonType10(getLngt("Fahrzeugklassen"), "action_change_5", "changeDisplay('5');", "160");
        echo htmlDivLineSpacer("5px");
        // echo defineButtonType10(getLngt("VPA-Ortung"), "action_change_6", "changeDisplay('6');", "160");
        // echo htmlDivLineSpacer("5px");
      ?>
    </div>    
  </div>

  <!-- 1. column -->
  <div class="divContent1" id="divContent1">
    <?php echo $outHqAddress ?>
  </div>

  <!-- 2. column -->
  <div class="divContent2" id="divContent2">
  	<?php echo $outHotlineBWV ?>
  </div>

  <!-- 3. column -->
  <div class="divContent3" id="divContent3">
  	<?php echo $outGLN ?>
  </div>

  <!-- 4. column -->
  <div class="divContent4" id="divContent4">
  	<?php echo $outDUNS ?>
  </div>

  <!-- 5. column -->
  <div class="divContent5" id="divContent5">
  	<?php echo $outVHT ?>
  </div>

  <!-- 6. column -->
  <div class="divContent6" id="divContent6">
  	<?php // echo $outLocatingVPA ?>
  </div>

</form>

</div>

</body>

</html>
