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


include_once ("../include/mcglobal.inc.php");
include_once ("../include/auth.inc.php");


getSecHttpVars("1",array("f_act", "statusMessage", "deactivateMenu", "numOfRows", "f_search", "f_su_chkbx", "f_suLoadStates", 
                         "f_su_orderByCol", "f_su_sort_sequence", "f_jb_orderByCol", "f_jb_sort_sequence", "f_log_orderByCol", "f_log_sort_sequence", 
                         "f_tv_01", "f_tv_02", "f_tv_03", "f_tv_04", "f_tv_05", "f_tv_06", "f_tv_07", "f_tv_08", "f_tv_09", "f_tv_10", 
                         "f_tv_11", "f_tv_12", "f_tv_13", "f_tv_14", "f_tv_15", "f_tv_16", "f_tv_17", "f_tv_18", "f_tv_19", "f_tv_20", 
                         "f_tv_21", "f_tv_22", "f_tv_23", "f_tv_24", "f_tv_25",
                         "f_pt_filter_1", "f_jb_filter_1", "f_jb_filter_2", "f_jb_filter_3", "f_log_filter_1", "f_su_admin_filter_1",
                         "f_su_admin_at_id", "f_su_admin_ati_serialno", "f_su_admin_stk_id", "f_su_admin_stk_name", "f_su_admin_stk_barcode",
                         "f_su_admin_ati_data_01", "f_su_admin_ati_data_02", "f_su_admin_ati_data_03", 
                         "f_su_admin_ad_id", "f_su_admin_ad_street", "f_su_admin_stk_hsno", 
                         "f_su_admin_ad_zipcode", "f_su_admin_ad_city", "f_su_tour_no",
                         "f_su_admin_ati_data_21_1", "f_su_admin_ati_data_21_2", "f_su_admin_ati_data_21_3", "f_su_admin_ati_data_21_4", 
                         "f_su_admin_ati_data_21_5", "f_su_admin_ati_data_21_6", "f_su_admin_ati_data_21_7", 
                         "maskDisplay00Switch", "maskDisplay01Switch", "maskDisplay02Switch", "maskDisplay03Switch", "maskDisplay04Switch",
                         "maskDisplay05Switch", "maskDisplay06Switch", "maskDisplay07Switch",
                         "day_from_jb", "month_from_jb", "year_from_jb", "day_to_jb", "month_to_jb", "year_to_jb", 
                         "hour_from_jb", "minute_from_jb", "hour_to_jb", "minute_to_jb", "f_showDateAndTime_jb", 
                         "f_actionObjType", "f_actionObjId", "f_actionID"));

// Select user-type for mode of security check 
$userType = getFieldValueFromId("user","usr_id",$usr_id,"usr_type");
$userTypeName = getUserTypeName($userType);

// Check authentication verifying emmployee an his/her costcenter- and customer-association
if ( !( authCheckHQ($hq_id,$usr_id,$emp_id) || authCheck($hq_id,$usr_id,$emp_id,$cscIdRoot,$customerId,$cscIdActual) ) || $userTypeName == "" ) :
   die ("$PHP_SELF: Access denied!");
endif;

$deactivateMenuStatic = "1";

getLanguage(__FILE__);

$pageTitel = getLngt("WARTUNGSAUFTRAGSPLANUNG");
if ($generatePDF != "1") :
   include_once ("../geo/geocode.inc.php");
endif;
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
include_once ("../include/inc_stock.inc.php");
include_once ("../locating/xServer.inc.php");

getCurrentScript(__FILE__);

// Check kind of user agent
$isFirefox = true;
if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") === false) {
   $isFirefox = false;
}

// SERVICE UNIT data fields
$dataSU = array();

// Message array
$outReportArray = array();
$generateOutput = true;

// Global state array
$outGlobalStateArray = array();

// Get root stock where all service units belong to
$rootStockSU = getParameterValue("0", "SU_STK_ROOT", $hq_id);
if ($rootStockSU != "" && is_numeric($rootStockSU)) :

   // Get db-parameter for the number of lists (frames) to be displayed of the current employee
   // This is important for the call of job lists only !!!
   $empMaskMultiJoblist = getParameterValue($emp_id, "MASK_MULTI_JOBLIST");
   if ($empMaskMultiJoblist == "") :
      $empMaskMultiJoblist = "3";
   endif;
   
   // Get vector of all message codes being critical
   $criticalMessageArray = getColVectorFromDB2ArrayByClause("phoenix.articlemessage", "atm_code", "atm_critical = '1'", "", "atm_code", "1");

   $maxNumOfTours = getParameterValue("0", "MAX_NUM_OF_SU_TOURS", $hq_id);
   if ($maxNumOfTours == "" || !is_numeric($maxNumOfTours)) :
      $maxNumOfTours = "4";
   endif;
   
   // Number of data fields in "articleitem" (ati_data_01, ati_data_02, ...)
   $maxNumOfAtiDataFields = getParameterValue("0", "MAX_NUM_OF_ATI_DATA_FIELDS", $hq_id);
   if ($maxNumOfAtiDataFields == "" || !is_numeric($maxNumOfAtiDataFields)) :
      $maxNumOfAtiDataFields = "25";
   endif;

   $jsExecBodyOnLoadArray = array("0","0","0","0","0");   // If one component is set to "1" then execute a special JS function according to "body onLoad"
   $suRoutePlanningArray = array();
   for ($j = 0; $j <= $maxNumOfTours; $j++) :
       $suRoutePlanningArray[$j] = array();
   endfor;
   $suRouteOptimizedArray = array();
   $outEventStatesArray = array();
   $outJobArray = array();
   $outLogArray = array();
   $outMessageArray = array();
   
   $constLngOutputTourChars = getLngt("T");  // Constant because there will be a search in the database

   $colArray = array();
   $colArray["bg"] = $constBackground;
   $colArray["blue"]   = "#0000FF";
   $colArray["green"]  = "#00FF00";
   $colArray["red"]    = "#FF0000";
   $colArray["white"]  = "#FFFFFF";
   $colArray["yellow"] = "#FFFF00";
   $colArray["black"]  = "#000000";
   $colArray["light_blue"]   = "#8888FF";

   $atiColsTypesArray = array();   // Represents the fields ati_data_01, ati_data_02, ..., ati_data_xx only!
   $atiColsTypes = getParameterValue("0", "STK_ATI_COLUMN_TYPES", $hq_id);
   if ($atiColsTypes != "") :
      $atiColsTypesArray = spliti(",", $atiColsTypes);
   else :
      // Default
      $atiColsTypesArray = array("varchar","number","number","date","integer","float2","integer","float2","float2","","","","","","","","","","integer","integer");
   endif;

   // SERVICEJOBS: Check ranges of time. All fields have to be set
   if ($f_showDateAndTime_jb == "") : $f_showDateAndTime_jb = "0"; endif;  // Show the clock time fields [default "NO"]
   if ($f_showDateAndTime_jb == "0" || $hour_from_jb == "" || $minute_from_jb == "" || $hour_to_jb == "" || $minute_to_jb == "") :
       $hour_from_jb = "00";
       $minute_from_jb = "00";
       $hour_to_jb = "23";
       $minute_to_jb = "59";
       $f_showDateAndTime_jb == "0";
   endif;
   $hour_from_jb = pad($hour_from_jb,2);
   $minute_from_jb = pad($minute_from_jb,2);
   $hour_to_jb = pad($hour_to_jb,2);
   $minute_to_jb = pad($minute_to_jb,2);
   // Time range
   $fromTimeRange = " " . $hour_from_jb . ":" . $minute_from_jb . ":00";
   $toTimeRange = " " . $hour_to_jb . ":" . $minute_to_jb . ":59";
   // Check ranges of date. All fields have to be set
   if ($day_from_jb == "" || $month_from_jb == "" || $year_from_jb == "" || 
       $day_to_jb == "" || $month_to_jb == "" || $year_to_jb == "") :
       // Initialize date-ranges to the current date
       $fromDateRange_jb = getDateTime("3") . $fromTimeRange;
       $toDateRange_jb = getDateTime("3") . $toTimeRange;
       $day_from_jb = getDateTime("day");
       $month_from_jb = getDateTime("month");
       $year_from_jb = getDateTime("year");
       $day_to_jb = getDateTime("day");
       $month_to_jb = getDateTime("month");
       $year_to_jb = getDateTime("year");
   else :
       $fromDateRange_jb = $year_from_jb . "-" . pad($month_from_jb,2) . "-" . pad($day_from_jb,2) . $fromTimeRange;
       $toDateRange_jb = $year_to_jb . "-" . pad($month_to_jb,2) . "-" . pad($day_to_jb,2) . $toTimeRange;
   endif;

   $f_search = trim($f_search);

   $numOfRowsSU = 0;
   $numOfRowsJB = 0;
   $numOfRowsLOG = 0;
   // Selected service units (checkboxes)
   if ($f_su_chkbx == "") : $f_su_chkbx = array(); endif;
   $f_su_chkbx_len = count($f_su_chkbx);
   // Selected tour
   if ($f_su_tour_no == "") : $f_su_tour_no = array(); endif;
   $f_su_tour_no_len = count($f_su_tour_no);


   $tresholdValuesArray = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
   $tresholdValues = getParameterValue("0", "SU_TRESHOLD_VALUES", $hq_id);
   if ($tresholdValues != "") :
      $tmpArray = spliti(",", $tresholdValues);
      $tmpArrayLen = count($tmpArray);
      for ($j = 0; $j < $tmpArrayLen; $j++) :
          if (is_numeric($tmpArray[$j])) :
             $tresholdValuesArray[$j] = $tmpArray[$j];
          endif;
      endfor;
   endif;

   if ($f_tv_01 == "") : $f_tv_01 = $tresholdValuesArray[0]; endif;   if ($f_tv_11 == "") : $f_tv_11 = $tresholdValuesArray[10]; endif;   if ($f_tv_21 == "") : $f_tv_21 = $tresholdValuesArray[20]; endif;   
   if ($f_tv_02 == "") : $f_tv_02 = $tresholdValuesArray[1]; endif;   if ($f_tv_12 == "") : $f_tv_12 = $tresholdValuesArray[11]; endif;   if ($f_tv_22 == "") : $f_tv_22 = $tresholdValuesArray[21]; endif;   
   if ($f_tv_03 == "") : $f_tv_03 = $tresholdValuesArray[2]; endif;   if ($f_tv_13 == "") : $f_tv_13 = $tresholdValuesArray[12]; endif;   if ($f_tv_23 == "") : $f_tv_23 = $tresholdValuesArray[22]; endif;   
   if ($f_tv_04 == "") : $f_tv_04 = $tresholdValuesArray[3]; endif;   if ($f_tv_14 == "") : $f_tv_14 = $tresholdValuesArray[13]; endif;   if ($f_tv_24 == "") : $f_tv_24 = $tresholdValuesArray[23]; endif;   
   if ($f_tv_05 == "") : $f_tv_05 = $tresholdValuesArray[4]; endif;   if ($f_tv_15 == "") : $f_tv_15 = $tresholdValuesArray[14]; endif;   if ($f_tv_25 == "") : $f_tv_25 = $tresholdValuesArray[24]; endif;   
   if ($f_tv_06 == "") : $f_tv_06 = $tresholdValuesArray[5]; endif;   if ($f_tv_16 == "") : $f_tv_16 = $tresholdValuesArray[15]; endif;   
   if ($f_tv_07 == "") : $f_tv_07 = $tresholdValuesArray[6]; endif;   if ($f_tv_17 == "") : $f_tv_17 = $tresholdValuesArray[16]; endif;
   if ($f_tv_08 == "") : $f_tv_08 = $tresholdValuesArray[7]; endif;   if ($f_tv_18 == "") : $f_tv_18 = $tresholdValuesArray[17]; endif;
   if ($f_tv_09 == "") : $f_tv_09 = $tresholdValuesArray[8]; endif;   if ($f_tv_19 == "") : $f_tv_19 = $tresholdValuesArray[18]; endif;
   if ($f_tv_10 == "") : $f_tv_10 = $tresholdValuesArray[9]; endif;   if ($f_tv_20 == "") : $f_tv_20 = $tresholdValuesArray[19]; endif;
   

   if ($f_tv_01 != $tresholdValuesArray[0] || $f_tv_02 != $tresholdValuesArray[1] || $f_tv_03 != $tresholdValuesArray[2] || $f_tv_04 != $tresholdValuesArray[3] || $f_tv_05 !=  $tresholdValuesArray[4] || 
       $f_tv_06 != $tresholdValuesArray[5] || $f_tv_07 != $tresholdValuesArray[6] || $f_tv_08 != $tresholdValuesArray[7] || $f_tv_09 != $tresholdValuesArray[8] || $f_tv_10 != $tresholdValuesArray[9] || 
       $f_tv_11 != $tresholdValuesArray[10] || $f_tv_12 != $tresholdValuesArray[11] || $f_tv_13 != $tresholdValuesArray[12] || $f_tv_14 != $tresholdValuesArray[13] || $f_tv_15 != $tresholdValuesArray[14] ||
       $f_tv_16 != $tresholdValuesArray[15] || $f_tv_17 != $tresholdValuesArray[16] || $f_tv_18 != $tresholdValuesArray[17] || $f_tv_19 != $tresholdValuesArray[18] || $f_tv_20 != $tresholdValuesArray[19] ||
       $f_tv_21 != $tresholdValuesArray[20] || $f_tv_22 != $tresholdValuesArray[21] || $f_tv_23 != $tresholdValuesArray[22] || $f_tv_24 != $tresholdValuesArray[23] || $f_tv_25 != $tresholdValuesArray[24]) :
       // At least one treshold value differs from the default value
       $outReportArray[] = getLngt("Mindestens ein Schwellwert differiert vom Standardwert!");
   endif;

   // Displayed DIV container by default
   $maskDisplay00Switch = "0";  // Only generate output if there is at least one system message
   if ($maskDisplay01Switch == "") : $maskDisplay01Switch = "0"; endif;
   if ($maskDisplay02Switch == "") : $maskDisplay02Switch = "1"; endif;
   if ($maskDisplay03Switch == "") : $maskDisplay03Switch = "0"; endif;
   if ($maskDisplay04Switch == "") : $maskDisplay04Switch = "0"; endif;
   if ($maskDisplay05Switch == "") : $maskDisplay05Switch = "0"; endif;
   if ($maskDisplay06Switch == "") : $maskDisplay06Switch = "0"; endif;
   if ($maskDisplay07Switch == "") : $maskDisplay07Switch = "1"; endif;
   
   if ($f_suLoadStates == "") : $f_suLoadStates = "0"; endif;
   if ($f_pt_filter_1 == "") : $f_pt_filter_1 = "0"; endif;
   if ($f_jb_filter_1 == "") : $f_jb_filter_1 = "0"; endif;
   if ($f_jb_filter_2 == "") : $f_jb_filter_2 = ""; endif;
   if ($f_jb_filter_3 == "") : $f_jb_filter_3 = ""; endif;
   if ($f_log_filter_1 == "") : $f_log_filter_1 = "0"; endif;
   if ($f_su_admin_filter_1 == "") : $f_su_admin_filter_1 = ""; endif;
   if ($f_su_admin_stk_id == "") : $f_su_admin_stk_id = ""; endif;

else :
   $outReportArray[] = getLngt("Es wurden keine Serviceeinheiten aufgefunden!");
   $generateOutput = false;
endif;  // Check for $rootStockSU is defined



// *************
// * Functions *
// *************
// Initialisations
if ($selYear == "") : $selYear = date("Y"); endif;
if ($selMonth == "") : $selMonth = date("m"); endif;
if ($selDay == "") : $selDay = date("d"); endif;
include_once ("../include/inc_calendar.inc.php");
include_once ("../include/inc_serviceunit.inc.php");


// Check for $rootStockSU is defined
if ($generateOutput) :

   // *******************************************
   // * Store form data for a service unit item *
   // *******************************************
   if ($f_act == "storeDataServiceunit") :

      $f_su_admin_ati_serialno = trim($f_su_admin_ati_serialno);
      $f_su_admin_ati_data_01  = trim($f_su_admin_ati_data_01);
      $f_su_admin_ati_data_02  = trim($f_su_admin_ati_data_02);
      $f_su_admin_ati_data_03  = trim($f_su_admin_ati_data_03);

      $currAtId = getFieldValueFromClause("phoenix.articleitem", "at_id", "ati_serialno = '" . $f_su_admin_ati_serialno . "'");
      $currStkId = getFieldValueFromClause("phoenix.articleitem", "stk_id", "ati_serialno = '" . $f_su_admin_ati_serialno . "'");

      $currentTime = getDateTime("0");
      if ($f_su_admin_at_id != "" && is_numeric($f_su_admin_at_id)) :
         if ($f_su_admin_stk_id != "" && is_numeric($f_su_admin_stk_id)) :
            $doModifyStockarticle = false;

           // Vector of predefined vehicles of days of the week
           $f_su_admin_ati_data_21 = $f_su_admin_ati_data_21_1 . "," . $f_su_admin_ati_data_21_2 . "," . $f_su_admin_ati_data_21_3 . "," . $f_su_admin_ati_data_21_4 . ","
                                   . $f_su_admin_ati_data_21_5 . "," . $f_su_admin_ati_data_21_6 . "," . $f_su_admin_ati_data_21_7;

            // Check for selection of a service unit item
            if ($f_su_admin_filter_1 == "") :
               // * INSERT *
               if (!existsEntry("phoenix.articleitem",array("ati_serialno",$f_su_admin_ati_serialno))) :
                  insertStmt("phoenix.articleitem", array("at_id", $f_su_admin_at_id, "stk_id", $f_su_admin_stk_id, "ati_serialno", $f_su_admin_ati_serialno, "ati_data_01", $f_su_admin_ati_data_01, "ati_data_02", $f_su_admin_ati_data_02, "ati_data_03", $f_su_admin_ati_data_03, "ati_data_04", $currentTime, "ati_data_21", $f_su_admin_ati_data_21));
                  $doModifyStockarticle = true;
                  $outReportArray[] = getLngt("Die neuen Automatendaten wurden angelegt!");
               else :
                  $outReportArray[] = getLngt("Dieser Automat existiert schon! Schauen Sie bitte in der Auswahl!");
               endif;
            else :
               // * UPDATE *
               updateStmt("phoenix.articleitem", "ati_serialno", $f_su_admin_ati_serialno, array("at_id", $f_su_admin_at_id, "stk_id", $f_su_admin_stk_id, "ati_data_01", $f_su_admin_ati_data_01, "ati_data_02", $f_su_admin_ati_data_02, "ati_data_03", $f_su_admin_ati_data_03, "ati_data_04", $currentTime, "ati_data_21", $f_su_admin_ati_data_21), "");
               $doModifyStockarticle = true;
               // Check for updating stockarticle. Do NOT update the quantities if article item will NEITHER be changed by the article id NOR the stock id!
               if ($currStkId == $f_su_admin_stk_id && $currAtId == $f_su_admin_at_id) :
                  $doModifyStockarticle = false;
               endif;
               $outReportArray[] = getLngt("Die Automatendaten wurden aktualisiert!");
            endif;

            if ($doModifyStockarticle) :
               // *** Update stock quantity from source stock ***
               if ($currStkId > "0") :
                  // Get current item quantity of the specified article and source stock
                  $stkatItemQuantity = getFieldValueFromClause("stockarticle", "stkat_itemquantity", "stk_id = '" . $currStkId . "' AND at_id = '" . $currAtId . "'");
                  if ($stkatItemQuantity > 0) :
                     $stkatItemQuantity = $stkatItemQuantity - 1;
                     if ($stkatItemQuantity > 0) :
                        updateStmt("phoenix.stockarticle","stk_id",$currStkId,array("stkat_quantity",$stkatItemQuantity,"stkat_itemquantity",$stkatItemQuantity),"at_id = '".$currAtId."'");
                     else :
                        deleteStmt("phoenix.stockarticle"," stk_id = '".$currStkId."' AND at_id = '".$currAtId."' ");
                     endif;
                  endif;
               endif;

               // *** Update stock quantity from target stock ***
               if ($f_su_admin_stk_id > "0") :
                  // Get current item quantity of the specified article and target stock
                  $stkatItemQuantity = getFieldValueFromClause("stockarticle", "stkat_itemquantity", "stk_id = '" . $f_su_admin_stk_id . "' AND at_id = '" . $f_su_admin_at_id . "'");
                  if ($stkatItemQuantity != "") : 
                     $stkatItemQuantity = $stkatItemQuantity + 1;
                  endif;
                  if (existsEntry("phoenix.stockarticle",array("stk_id",$f_su_admin_stk_id,"at_id",$f_su_admin_at_id))) :
                     updateStmt("phoenix.stockarticle","stk_id",$f_su_admin_stk_id,array("stkat_quantity",$stkatItemQuantity,"stkat_itemquantity",$stkatItemQuantity),"at_id = '".$f_su_admin_at_id."'");
                  else :
                     insertStmt("phoenix.stockarticle",array("stk_id",$f_su_admin_stk_id,"at_id",$f_su_admin_at_id,"stkat_quantity","1","stkat_itemquantity","1"));
                  endif;
               endif;
            endif;
         else :
            $outReportArray[] = getLngt("Es wurde bei der Erfassung kein Standort zugewiesen!");
         endif;
      else :
         $outReportArray[] = getLngt("Es wurde bei der Erfassung kein Automatentypen selektiert!");
      endif;
   endif;


   // ***********************************************
   // * Store form data for stock (service station) *
   // ***********************************************
   if ($f_act == "storeDataStock") :

      $f_su_admin_stk_name = trim($f_su_admin_stk_name);
      $f_su_admin_stk_barcode = trim($f_su_admin_stk_barcode);
      $f_su_admin_ad_street = trim($f_su_admin_ad_street);
      $f_su_admin_ad_zipcode = trim($f_su_admin_ad_zipcode);
      $f_su_admin_ad_city = trim($f_su_admin_ad_city);
      $f_su_admin_stk_hsno = trim($f_su_admin_stk_hsno);
      if ($f_su_admin_stk_hsno == "") : $f_su_admin_stk_hsno = "."; endif;
      if ($f_su_admin_ad_country == "") : $f_su_admin_ad_country = "DE"; endif;

      // Check for empty entries in address-fields
      if ($f_su_admin_ad_street != "" && $f_su_admin_ad_zipcode != "" && $f_su_admin_ad_city != "" && $f_su_admin_ad_country != "") :
         // Check zipcode and city
         // $addressValidityArray = checkCityZipcode($f_su_admin_ad_zipcode, $f_su_admin_ad_city, $f_su_admin_ad_street);
         // if ($noValidationOfAddress || $addressValidityArray[0] >= 1) :
         if (true) :
            TA("B");
            if ($f_su_admin_stk_name != "") :
               // Check for existing entry in address (because of redundance)
               $tmpArray = insertAddress($f_su_admin_ad_street, $f_su_admin_ad_zipcode, $f_su_admin_ad_city, "", $f_su_admin_ad_country, true);
               $ad_id_new = $tmpArray[0];
               if ($ad_id_new != "" && is_numeric($ad_id_new) ) :
                  // Get current timestamp
                  $currentTime = getDateTime("0");      
                  // Check for selection of a service unit item
                  if ($f_su_admin_stk_id != "" && is_numeric($f_su_admin_stk_id)) :
                     // Check for existence of the stock name
                     $stkIdToCheck = getFieldValueFromId("stock","stk_name",$f_su_admin_stk_name,"stk_id");
                     if ($stkIdToCheck == "" || $f_su_admin_stk_id == $stkIdToCheck) :
                         // Check barcode information still existing
                         $stkBarcodeToCheck = getFieldValueFromClause("phoenix.stock", "stk_barcode", "stk_barcode = '" . $f_su_admin_stk_barcode . "' AND stk_id != '" . $f_su_admin_stk_id . "'");
                         if ($f_su_admin_stk_barcode != "" && $f_su_admin_stk_barcode == $stkBarcodeToCheck) :
                            // Generate info only
                            $outReportArray[] = getLngt("Nur zur Information: Die Standortinfo existiert schon!");
                         endif;
                         // * UPDATE *
                         updateStmt("phoenix.stock", "stk_id", $f_su_admin_stk_id, array("ad_id", $ad_id_new, "stk_name", $f_su_admin_stk_name, "stk_hsno", $f_su_admin_stk_hsno, "stk_barcode", $f_su_admin_stk_barcode), "");
                         $outReportArray[] = getLngt("Die Standortdaten wurden aktualisiert!");
                     else :
                         $outReportArray[] = getLngt("Die neue Standortbezeichnung existiert schon! vergeben Sie bitte einen anderen Namen!");
                     endif;
                  else :
                     // * INSERT *
                     if (!existsEntry("phoenix.stock",array("stk_name",$f_su_admin_stk_name))) :
                        insertStmt("phoenix.stock", array("hq_id", $hq_id, "stk_name",$f_su_admin_stk_name, "stk_pre_id", $rootStockSU,"stk_path", "//" . $rootStockSU . "//", "ad_id", $ad_id_new,"stk_barcode",$f_su_admin_stk_barcode,"stk_modifytime", $currentTime, "stk_visible", "1"));
                        $outReportArray[] = getLngt("Der neue Standort wurde angelegt!");
                     else :
                        $outReportArray[] = getLngt("Dieser Standort existiert schon! Schauen Sie bitte in der Auswahl!");
                     endif;
                  endif;
               else :
                  $outReportArray[] = getLngt("Die Generierung der Adresse hat nicht funktioniert!");
               endif;
            else :
               $outReportArray[] = getLngt("Die Standortangabe ist leer!");
            endif;
            TA("C");    
            TA("E");
         else :
           $outReportArray[] = getLngt("Die Postleitzahl passt nicht zu dem angegebenen Ort!");
         endif;
      else :
         $outReportArray[] = getLngt("Bitte geben Sie die Addressdaten vollständig an!");
      endif;
   endif;


   // Set the global master array and get special array for geo-coordinates of the current selected service units (selected by checkboxes)
   // This has to be called after storing the form data (!!!)
   getPersistentStates("2");


   // ***************************************************
   // * Process specified action for a specified object *
   // ***************************************************
   // if ($f_act == "processAction") :
      if ($f_actionObjType != "" && $f_actionObjId != "" && $f_actionID != "") :
         
         if ($f_actionObjType = "ati_serialno") :
            if ($f_actionID == "101") :
               // Get position on map
               // ...
            elseif ($f_actionID == "102") :
               // Get log events
               // getLogData("log.logo_id = '1000' AND log.id_01 = '" . $f_actionObjId . "'");
               getSuHistoryData("0", "AND stk.stk_pre_id = '" . $rootStockSU . "' AND atih.atih_serialno = '" . $f_actionObjId . "'");
               if ($f_act == "processAction") :
                  $maskDisplay01Switch = "0";
                  $maskDisplay02Switch = "0";
                  $maskDisplay03Switch = "0";
                  $maskDisplay04Switch = "1";
                  $maskDisplay05Switch = "0";
                  $maskDisplay06Switch = "0";
                  $maskDisplay07Switch = "0";
               endif;
            elseif ($f_actionID == "103") :
               // Get service jobs
               $f_jb_filter_2 = $f_actionObjId;  // Set filter for service jobs regarding the serialnumber of the service unit
               // getServiceJoblist();           // Will be called later including this filter !!!
               if ($f_act == "processAction") :
                  $maskDisplay01Switch = "0";
                  $maskDisplay02Switch = "0";
                  $maskDisplay03Switch = "1";
                  $maskDisplay04Switch = "0";
                  $maskDisplay05Switch = "0";
                  $maskDisplay06Switch = "0";
                  $maskDisplay07Switch = "0";
               endif;
               resetActionParameters();
            elseif ($f_actionID == "104") :
               getSuMessageData($f_actionObjId);
               if ($f_act == "processAction") :
                  $maskDisplay01Switch = "0";
                  $maskDisplay02Switch = "0";
                  $maskDisplay03Switch = "0";
                  $maskDisplay04Switch = "0";
                  $maskDisplay05Switch = "1";
                  $maskDisplay06Switch = "0";
                  $maskDisplay07Switch = "0";
               endif;
            elseif ($f_actionID == "105") :
               // Set form fields for the administration
               $f_su_admin_filter_1 = $f_actionObjId;  // Set filter for administration of the service unit
               $jsExecBodyOnLoadArray[2] = "1";        // Set service unit form data according to $f_actionObjId
               if ($f_act == "processAction") :
                  $jsExecBodyOnLoadArray[0] = "1";   // Set form by "body onLoad"
                  $maskDisplay01Switch = "0";
                  $maskDisplay02Switch = "0";
                  $maskDisplay03Switch = "0";
                  $maskDisplay04Switch = "0";
                  $maskDisplay05Switch = "0";
                  $maskDisplay06Switch = "1";
                  $maskDisplay07Switch = "0";
               endif;
               resetActionParameters();
            endif;
         endif;
   // else :
   //   $outReportArray[] = getLngt("Die gewählte Aktion konnte nicht ausgeführt werden, da nicht alle Angaben gesetzt wurden!");
      endif;

   // $f_act = "";  // Init
   // endif;


   // *****************************************
   // * Save state of the selected checkboxes *
   // *****************************************
   if ($f_act == "savePT" || $f_act == "optimizePT") :
   
      // Remove existing persistent states
      // ONLY do this if ALL service units are displayed (!!!)
      // OTHERWISE it is NOT necessary because the delta
      if ($f_pt_filter_1 == "0") :
         $sqlStmt = "UPDATE phoenix.articleitem SET ati_data_20 = '0' WHERE stk_id IN (SELECT stk_id FROM stock WHERE stk_pre_id = '" . $rootStockSU . "')";
         $res = $db->query($sqlStmt);
         if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif;
      endif;
      
      // Update checked checkboxes
      if ($f_su_chkbx_len > 0) :
         for ($i = 0; $i < $f_su_chkbx_len; $i++) :
             updateStmt("phoenix.articleitem", "ati_serialno", $f_su_chkbx[$i], array("ati_data_20", "1"));
         endfor;
      endif;
   endif;


   // **********************
   // * Optimize tour data *
   // **********************
   if ($f_act == "optimizePT") :

      $optimizationDisabled = getParameterValue("0", "OPTIMIZATION_DISABLED", $hq_id);
      if (true || $optimizationDisabled != "1") :         // Presently no restrictions regarding to the optimization !!!!!!!!!!!!

         // * Optimization process by server *

         $usedVehicleNumberArray = array();
         for ($j = 1; $j <= $maxNumOfTours; $j++) :
             if (count($suRoutePlanningArray[$j]) > 0) :
                $usedVehicleNumberArray[] = $j;   // E.g. ONE vehicle only, but it is the vehicle "3"
             endif;
         endfor;

         // Get potential coordinates of the start and/or end of all tours
         // Start coordinates
         $coordinatesStart = getParameterValue("0", "OPTIMIZATION_COORDINATES_START", $hq_id);
         $coordinatesStartArray = array();      
         if ($coordinatesStart != "") :
            $coordinatesStartArray = spliti(",", $coordinatesStart);
         endif;
         $coordinatesStartArrayLen = count($coordinatesStartArray);
         // End coordinates
         $coordinatesEnd = getParameterValue("0", "OPTIMIZATION_COORDINATES_END", $hq_id);
         $coordinatesEndArray = array();      
         if ($coordinatesEnd != "") :
            $coordinatesEndArray = spliti(",", $coordinatesEnd);
         endif;
         $coordinatesEndArrayLen = count($coordinatesEndArray);

         // Iterate tours to be created for each vehicle (vehicle #1, vehicle #2, ...)
         $usedVehicleNumberArrayLen = count($usedVehicleNumberArray);

         // Remove old persistent optimization states in "ati.ati_data_19"
         if ($usedVehicleNumberArrayLen > 0) :
            $sqlStmt = "UPDATE phoenix.articleitem SET ati_data_19 = '' WHERE stk_id IN (SELECT stk_id FROM stock WHERE stk_pre_id = '" . $rootStockSU . "')";
            $res = $db->query($sqlStmt);
            if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif;
         endif;

         // Iterate all selected vehicles
         for ($j = 0; $j < $usedVehicleNumberArrayLen; $j++) :

             $tmpVehicleNum = $usedVehicleNumberArray[$j];
             $suRoutePlanningArrayLen = count($suRoutePlanningArray[$tmpVehicleNum]);
             if ($suRoutePlanningArrayLen > 0) :

                // Add start and/or end coordinates if exist
                $tmpLen = 0;
                if ($coordinatesStartArrayLen > 0) :
                   $suRoutePlanningArray[$tmpVehicleNum] = array_merge(array($coordinatesStartArray), $suRoutePlanningArray[$tmpVehicleNum]);
                endif;
                if ($coordinatesEndArrayLen > 0) :
                   $suRoutePlanningArray[$tmpVehicleNum] = array_merge($suRoutePlanningArray[$tmpVehicleNum], array($coordinatesEndArray));
                   $tmpLen = 1;
                endif;

                // Trigger optimization process
                // Data structure in "$suRoutePlanningArray[$tmpVehicleNum]": array(array("92845", "10.241763", "53.661418"), array("92730", "10.064445", "53.586847"), ...)

                // Set last element of the list to be optimized as target address
                // $tmpLen = count($suRoutePlanningArray[$tmpVehicleNum]);

                $suRouteOptimizedArray[$tmpVehicleNum] = XSplanTourId($suRoutePlanningArray[$tmpVehicleNum], $tmpLen);
                $suRouteOptimizedArrayLen = count($suRouteOptimizedArray[$tmpVehicleNum]);
                if ($suRouteOptimizedArrayLen > 0) :

                   // Store optimization sort in table "articleitem"
                   if ($suRouteOptimizedArrayLen > 0) :
                      for ($i = 0; $i < $suRouteOptimizedArrayLen; $i++) :

                          if (!( ($i == 0 && $coordinatesStartArrayLen > 0) || ($i == $suRouteOptimizedArrayLen && $coordinatesEndArrayLen > 0) )) :
                             updateStmt("phoenix.articleitem", "ati_serialno", $suRouteOptimizedArray[$tmpVehicleNum][$i][0], array("ati_data_19", $constLngOutputTourChars . pad($tmpVehicleNum, 2, "0") . "-" . pad($i, 2, "0")));
                          endif;
                      endfor;
                   endif;
                else :
                   $outReportArray[] = getLngt("Tour") . " " . $tmpVehicleNum . ": " . getLngt("Die Optimierung schlug fehl! Der Rückgabevektor ist leer!");
                endif;
             else :
                $outReportArray[] = getLngt("Tour") . " " . $tmpVehicleNum . ": " . getLngt("Die Optimierung wurde mangels Geo-Koordinaten nicht durchgeführt!");
             endif;
         endfor;
      endif;
   endif;


   // Get current persistent states of the service units
   getPersistentStates();


   // ************************************************
   // * Make job from persistent optimization vector *
   // ************************************************
   if ($f_act == "makeJobPT") :

      // Get current timestamp
      $currentTime = getDateTime("0");

      // Init fix values for all jobs
      $cscIdPayer = getParameterValue("0", "CSC_ID_PAYER_DEFAULT", $hq_id);
      if ($cscIdPayer != "" && is_numeric($cscIdPayer)) :
         $cscId = "0"; $jbOrdertime = $currentTime; 
         $jbCrFilter = ""; $jbStatus = "0"; $jbType = ""; $jbTourname = ""; $fixprice = "0"; $cmpPostage = "0"; $csInvmode = "";
         $jbCrvhWeight = ""; $jbCrvhLength = ""; $jbCrvhWidth = ""; $jbCrvhHeight = ""; $jbCrvhPosition = "";  
         $jbTourdata = "";
         $cscIdExternal = getParameterValue("0", "CSC_ID_PAYER_EXTERN", $hq_id);
         $txValue = getFieldValueFromId("tax","tx_id","4","tx_value"); $txSign = getFieldValueFromId("tax","tx_id","4","tx_sign");
   
         // Get vehicles to map... (e.g. 1 <=> HHA101, 2 <=> HHA102, 3 <=> HHA103)
// Has to be parameterized !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
         $mappedCourierArray = array("", "9322", "9323", "9324");
// HARDCODED !!!!!!!!!!!
   
         // Get required vehicles from the persistent state of the optimized tours
         $usedVehicleNumberArray = array();
         $tmpOptimizedTourArray = getColVectorFromDB2ArrayByClause("phoenix.articleitem", "ati_data_19", "ati_data_19 != ''", "", "", "");
         $tmpOptimizedTourArrayLen = count($tmpOptimizedTourArray);
         for ($j = 0; $j < $tmpOptimizedTourArrayLen; $j++) :
             $tmpArray = spliti("-", $tmpOptimizedTourArray[$j]);
             $tmpTourNo = $tmpArray[0];
             $tmpTourNo = substr($tmpTourNo, strlen($constLngOutputTourChars));
             $x = array_search($tmpTourNo, $usedVehicleNumberArray);
             if ($x === FALSE) :
                $usedVehicleNumberArray[] = $tmpTourNo;
             endif;
         endfor;
         sort($usedVehicleNumberArray);   // The array e.g. contains ("1", "2", "3")
         $usedVehicleNumberArrayLen = count($usedVehicleNumberArray);
   
         // Iterate all vehicles to get a job for their tour
         if ($usedVehicleNumberArrayLen > 0) :         
            for ($j = 0; $j < $usedVehicleNumberArrayLen; $j++) :
                $tmpVehicleNum = $usedVehicleNumberArray[$j];    // It is a pad value like "01", "02", "03", ... !!!
   
                // Get persistent optimized vector of service unit data
                $tmpStrLen = strlen($constLngOutputTourChars) + strlen($tmpVehicleNum);
                $sqlStmt = getStmtGenericStockArticleItems("0", $rootStockSU, "", "1", "ati.ati_data_19 != '' AND LEFT(ati.ati_data_19, " . $tmpStrLen . ") = '" . $constLngOutputTourChars . $tmpVehicleNum . "'", "", "ati.ati_data_19", "");
                if ($sqlStmt != "") :
                   $result = $db->query($sqlStmt);     
                   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
                   if ($result->numRows() > 0) :
   
                      TA("B");
   
                      $crId = $mappedCourierArray[intval($tmpVehicleNum)];
                      $crIdOrder = $crId;
                      $crvhId = getFieldValueFromId("couriervehicle","cr_id",$crId,"crvh_id");
                      $vhtId = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"vht_id");
                      $crSid = getFieldValueFromId("couriervehicle","crvh_id",$crvhId,"crvh_sid");
                      $jbRemark = "";
   
                      // Create general job data
                      insertStmt("job", array("hq_id", $hq_id, "csc_id", $cscId, "vht_id", $vhtId, "csc_id_payer", $cscIdPayer, "jb_payment", "0",
                                              "jb_ordertime", $jbOrdertime, "cr_id", $crId, "cr_sid", $crSid, "cr_id_order", $crIdOrder,
                                              "jb_cr_filter", $jbCrFilter, "jb_cr_filter_opt", "", "jb_waitstorno", "0", 
                                              "jb_taketime", "", "jb_status", $jbStatus, "jb_autoranking", "0", "jb_type", $jbType, 
                                              "jb_incomplete", "0", "jb_globaljob", "0", "jb_tourname", $jbTourname,
                                              "jb_finishtime", "", "emp_id", $usr_id, "jb_fixprice", $fixprice, "jb_totalprice", $fixprice,
                                              "jb_postage", $cmpPostage, "jb_invmode", $csInvmode, "jb_freetext_1", "",
                                              "jb_weight", $jbCrvhWeight, "jb_crvh_length", $jbCrvhLength, "jb_crvh_width", $jbCrvhWidth, 
                                              "jb_crvh_height", $jbCrvhHeight, "jb_crvh_position", $jbCrvhPosition, "jb_invtext", $jbRemark,
                                              "jb_tourdata", $jbTourdata, "jb_lockuser", "0", "jb_id_parent", "0", "jb_dispoinfo", "",
                                              "jb_sales_tax_rate", $txValue, "jb_sales_tax_rate_sign", $txSign, "jb_booktime", ""));
                      $jbIdNew = getLastInsertId();
   
                      // Create tour data
                      $i = 0;
                      while ($row = $result->fetch_assoc()):
                            $trSort = $i + 1;
   
                            // Get state of the service unit
                            $trRemark = "";
                            $tmpAtiArray = getFieldsValueFromId("articleitem","ati_serialno",$row["ati_serialno"],array("at_id","ati_data_17"));
                            $tmpAtId = $tmpAtiArray[0];
                            $tmpAtimCodes = $tmpAtiArray[1];
                            if ($tmpAtId != "" && $tmpAtimCodes != "") :
                               $tmpAtimCodesArray = spliti(",", $tmpAtimCodes);
                               $tmpAtimCodesArrayLen = count($tmpAtimCodesArray);
                               for ($k = 0; $k < $tmpAtimCodesArrayLen; $k++) :
                                   $tmpAtimCode = $tmpAtimCodesArray[$k];
                                   $tmpAtimDesc = getFieldValueFromClause("articlemessage","atm_desc","at_id = '" . $tmpAtId . "' AND atm_code = '" . $tmpAtimCode . "'");
                                   $tmpAtimText = getFieldValueFromClause("articlemessage","atm_text","at_id = '" . $tmpAtId . "' AND atm_code = '" . $tmpAtimCode . "'");
                                   if ($trRemark != "") : $trRemark .= " | "; endif;
                                   $trRemark .= "[" . ($k + 1) . ".] " . $tmpAtimCode . ": " . $tmpAtimDesc . " | => " . $tmpAtimText;
                               endfor;
                            endif;
   
                            // Insert tour data for station
                            insertStmt("tour", array("jb_id", $jbIdNew, "ad_id", $row["ad_id"], "tr_sort", $trSort, "tr_comp", $row["ati_serialno"], "tr_comp2", "",
                                                     "tr_hsno", $row["stk_hsno"], "csc_id", $cscIdExternal, "tr_status", "0", 
                                                     "tr_commission_no", $row["ati_serialno"], "tr_ware_from_to", "", 
                                                     "tr_person", "", "tr_phone", "", "tr_remark", $trRemark));
   
                            // Insert tourservice data
                            $tmpSuSingleChargingLevels =  getLngt("BEK:") . number_format($row["ati_data_05"], 0, ",", ".") . ",";
                            $tmpSuSingleChargingLevels .= getLngt("MEK:") . number_format($row["ati_data_06"], 2, ",", ".") . ",";
                            $tmpSuSingleChargingLevels .= getLngt("H1:") .  number_format($row["ati_data_07"], 0, ",", ".") . ",";
                            $tmpSuSingleChargingLevels .= getLngt("H2:") .  number_format($row["ati_data_08"], 2, ",", ".") . ",";
                            $tmpSuSingleChargingLevels .= getLngt("H3:") .  number_format($row["ati_data_09"], 2, ",", ".");
                            $tmpSuChargingLevelSum = 0;
                            if ($row["ati_data_05"] != "" && is_numeric($row["ati_data_05"])) : $tmpSuChargingLevelSum += $row["ati_data_05"]; endif;
                            if ($row["ati_data_06"] != "" && is_numeric($row["ati_data_06"])) : $tmpSuChargingLevelSum += $row["ati_data_06"]; endif;
                            if ($row["ati_data_07"] != "" && is_numeric($row["ati_data_07"])) : $tmpSuChargingLevelSum += $row["ati_data_07"]; endif;
                            if ($row["ati_data_08"] != "" && is_numeric($row["ati_data_08"])) : $tmpSuChargingLevelSum += $row["ati_data_08"]; endif;
                            if ($row["ati_data_09"] != "" && is_numeric($row["ati_data_09"])) : $tmpSuChargingLevelSum += $row["ati_data_09"]; endif;
                            insertStmt("tourservice", array("jb_id", $jbIdNew, "csc_id", $cscIdPayer, "tr_sort", $trSort, 
                                                            "srv_id", "0", "trs_srv_name", $tmpSuSingleChargingLevels, "srvt_id", "0", "trs_srvt_name", "",
                                                            "trs_price", $tmpSuChargingLevelSum));
   
                            // Insert tourarticle
                            insertStmt("tourarticle", array("jb_id", $jbIdNew, "tr_sort", $trSort, "trat_serialno", $row["ati_serialno"], "trat_createtime", $currentTime));
                            $tratIdNew = getLastInsertId();
   
                            // Insert tourarticleprocess
                            // Store snapshot of the current data in articleitem of the current service unit
                            if ($tratIdNew != "" && is_numeric($tratIdNew)) :
                               // [tratp_type == "5" <=> ati_data_05 <=> e.g. BEK, tratp_type == "6" <=> ati_data_06 <=> e.g. MEK, etc.]
                               // for ($k = 1; $k <= $maxNumOfAtiDataFields; $k++) :
                               for ($k = 5; $k <= 9; $k++) :
                                   insertStmt("tourarticleprocess", array("trat_id", $tratIdNew, "tratp_type", $k, "tratp_state", "0", 
                                                                          "tratp_remark", $row["ati_data_" . pad($k, 2, "0")], "tratp_createtime", $currentTime));
                               endfor;
                            endif;
   
                            $i++;
                      endwhile;
   
                      TA("C");
                      TA("E");
   
                      if (existsEntry("job", array("jb_id", $jbIdNew))) :
                         $outReportArray[] = getLngt("Der Auftrag mit der Nummer") . " " . $jbIdNew . " " . getLngt("wurde erzeugt!");
                      else :
                         $outReportArray[] = getLngt("Es wurde leider kein Auftrag erzeugt!");
                      endif;
                   endif;
                   $result->free();
                endif;
            endfor;
         endif;
      else :
         $outReportArray[] = getLngt("Es existiert kein Default-Bezahler für die Tour. Der Auftrag wurde NICHT angelegt! Bitte der Systemadministration melden!");
      endif;
   endif;


   // Get service jobs
   getServiceJoblist();

endif;  // Check for $rootStockSU is defined



// **********
// * Output *
// **********

// Output threshold values
$outThresholdValues = "";
if ($generateOutput) :
   $outThresholdValues .= "<table border=\"1\">";
   $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\"><b>" . getLngt("KASSETTENTYP") . "</b></td>"
                          . "  <td class=\"f8np1\" style=\"width:150;text-align:left;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\"><b>" . getLngt("ART") . "</td>"
                          . "  <td class=\"f8np1\" style=\"width:45;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\"><b>" . getLngt("BETRAG") . "</td>"
                          . "</tr>";
   $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Münzkassette (MEK)") . "</b></td>"
                          . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("gelbe MEK") . "</td>"
                          . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_01\" value=\"" . $f_tv_01 . "\" size=\"10\">" . "</td>"
                          . "</tr>";
   $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Münzkassette (MEK)") . "</b></td>"
                          . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("rote MEK") . "</td>"
                          . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_02\" value=\"" . $f_tv_02 . "\" size=\"10\">" . "</td>"
                          . "</tr>";
   $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Banknotenkassetten (BEK)") . "</b></td>"
                          . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("gelbe BEK") . "</td>"
                          . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_03\" value=\"" . $f_tv_03 . "\" size=\"10\">" . "</td>"
                          . "</tr>";
   $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Banknotenkassetten (BEK)") . "</b></td>"
                          . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("rote BEK") . "</td>"
                          . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_04\" value=\"" . $f_tv_04 . "\" size=\"10\">" . "</td>"
                          . "</tr>";
   $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Wechselgeldspeicher (Kassetten)") . "</b></td>"
                          . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("Hopper 1 (2 EUR)") . "</td>"
                          . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_05\" value=\"" . $f_tv_05 . "\" size=\"10\">" . "</td>"
                          . "</tr>";
   $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Wechselgeldspeicher (Kassetten)") . "</b></td>"
                          . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("Hopper 2 (10 ct)") . "</td>"
                          . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_06\" value=\"" . $f_tv_06 . "\" size=\"10\">" . "</td>"
                          . "</tr>";
   $outThresholdValues .= "<tr><td class=\"f8np1\" style=\"width:300;text-align:left;\"><b>" . getLngt("Wechselgeldspeicher (Kassetten)") . "</b></td>"
                          . "  <td class=\"f8np1\" style=\"width:150;text-align:left;\"><b>" . getLngt("Hopper 3 (5 ct)") . "</td>"
                          . "  <td class=\"f8np1\" style=\"width:45;text-align:right;\"><b>" . "<input type=\"text\" name=\"f_tv_07\" value=\"" . $f_tv_07 . "\" size=\"10\">" . "</td>"
                          . "</tr>";
   $outThresholdValues .= "</table>";
   
   // Prepare for remaining threshold values. Use hidden parameters
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_08\" value=\"" . $f_tv_08 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_09\" value=\"" . $f_tv_09 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_10\" value=\"" . $f_tv_10 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_11\" value=\"" . $f_tv_11 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_12\" value=\"" . $f_tv_12 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_13\" value=\"" . $f_tv_13 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_14\" value=\"" . $f_tv_14 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_15\" value=\"" . $f_tv_15 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_16\" value=\"" . $f_tv_16 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_17\" value=\"" . $f_tv_17 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_18\" value=\"" . $f_tv_18 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_19\" value=\"" . $f_tv_19 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_20\" value=\"" . $f_tv_20 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_21\" value=\"" . $f_tv_21 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_22\" value=\"" . $f_tv_22 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_23\" value=\"" . $f_tv_23 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_24\" value=\"" . $f_tv_24 . "\">";
   $outThresholdValues .= "<input type=\"hidden\" name=\"f_tv_25\" value=\"" . $f_tv_25 . "\">";
endif;


// Output current states of service units
$outEventStates = "";
if ($generateOutput) :
   $outEventStatesArrayLen = count($outEventStatesArray);
   if ($outEventStatesArrayLen > 0) :
      $outEventStates .= "<table width=\"100%\" border=\"1\">";
      $outEventStates .= "<tr><td class=\"f8np1\" style=\"width:45;text-align:left;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('0');\"><b>" . getLngt("FA") . "</b></td>";
      $outEventStates .= "  <td class=\"f8np1\" style=\"width:20;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('18');\"><b>" . getLngt("N") . "</td>";
      $outEventStates .= "  <td class=\"f8np1\" style=\"width:240;text-align:left;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('1');\"><b>" . getLngt("Standort") . "</td>";
      $outEventStates .= "  <td class=\"f8np1\" style=\"width:30;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('2');\"><b>" . getLngt("Opt.") . "</td>";
      $outEventStates .= "  <td class=\"f8np1\" style=\"width:30;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('3');\"><b>" . getLngt("Fzg.") . "</td>";
      $outEventStates .= "  <td class=\"f8np1\" style=\"width:50;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('4');\"><b>" . getLngt("Sort.") . "</td>";
      // $outEventStates .= "  <td class=\"f8np1\" style=\"width:50;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('5');\"><b>" . getLngt("XXX") . "</td>";
      $outEventStates .= "  <td class=\"f8np1\" style=\"width:50;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('6');\"><b>" . getLngt("PLZ") . "</td>";
      // $outEventStates .= "  <td class=\"f8np1\" style=\"width:120;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('7');\"><b>" . getLngt("Geog. Breite") . "</td>";
      // $outEventStates .= "  <td class=\"f8np1\" style=\"width:120;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('8');\"><b>" . getLngt("Geog. Länge") . "</td>";
      $outEventStates .= "  <td class=\"f8np1\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('9');\"><b>" . getLngt("BEK") . "</td>";
      $outEventStates .= "  <td class=\"f8np1\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('10');\"><b>" . getLngt("MEK") . "</td>";
      $outEventStates .= "  <td class=\"f8np1\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('11');\"><b>" . getLngt("H1") . "</td>";
      $outEventStates .= "  <td class=\"f8np1\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('12');\"><b>" . getLngt("H2") . "</td>";
      $outEventStates .= "  <td class=\"f8np1\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('13');\"><b>" . getLngt("H3") . "</td>";
      $outEventStates .= "  <td class=\"f8np1\" style=\"width:80;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('14');\"><b>" . getLngt("Messzeitpunkt") . "</td>";
      $outEventStates .= "  <td class=\"f8np1\" style=\"width:80;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('15');\"><b>" . getLngt("Meldungen") . "</td>";
      $outEventStates .= "  <td class=\"f8np1\" style=\"width:40;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('16');\"><b>" . getLngt("SW") . "</td>";
      $outEventStates .= "  <td class=\"f8np1\" style=\"width:40;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["blue"] . ";\" onClick=\"suChangeOrderBy('17');\"><b>" . getLngt("Status") . "</td>";
      $outEventStates .= "</tr>";
      for ($j = 0; $j < $outEventStatesArrayLen; $j++) :
          $outEventStates .= $outEventStatesArray[$j];
      endfor;
      $outEventStates .= "</table>";
   endif;
endif;


// Output service jobs
$outServiceJobs = "";
$outServiceJobJsDate = "";
$jbDateFilter = "";
if ($generateOutput) :
   $outJobArrayLen = count($outJobArray);
   if ($outJobArrayLen > 0) :
      $outServiceJobs .= "<table width=\"100%\" border=\"1\">";
      $outServiceJobs .= "<tr>";
      $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:40;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('0');\"><b>" . getLngt("Auftrag") . "</b></td>";
      $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:40;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('1');\"><b>" . getLngt("Fahrzeug") . "</td>";
      $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:20;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('2');\"><b>" . getLngt("Station") . "</td>";
      $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:120;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('3');\"><b>" . getLngt("Erledigungszeit") . "</td>";
      $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:50;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('4');\"><b>" . getLngt("Automat") . "</td>";
      $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:240;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('5');\"><b>" . getLngt("Standort") . "</td>";
      $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:50;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('6');\"><b>" . getLngt("PLZ") . "</td>";
      // $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:120;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('7');\"><b>" . getLngt("Auftragsbeginn") . "</td>";
      // $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:120;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('8');\"><b>" . getLngt("Annahmezeit") . "</td>";
      // $outServiceJobs .= "  <td class=\"f8np1\" style=\"width:120;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('9');\"><b>" . getLngt("Auftragsende") . "</td>";
      $outServiceJobs .= "  <td class=\"f8np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["green"] . ";\" onClick=\"jbChangeOrderBy('10');\"><b>" . getLngt("Wartungsarbeiten") . "</td>";
      $outServiceJobs .= "</tr>";
      for ($j = 0; $j < $outJobArrayLen; $j++) :
          $outServiceJobs .= $outJobArray[$j];
      endfor;
      $outServiceJobs .= "</table>";
   endif;

   $outServiceJobJsDate .= "<script src=\"../include/lib_global.js\" type=\"text/javascript\">\n";
   $outServiceJobJsDate .= "</script>\n";
   $outServiceJobJsDate .= "\n";
   $outServiceJobJsDate .= "<script type=\"text/javascript\">\n";
   $outServiceJobJsDate .= "<!--\n";
   $outServiceJobJsDate .= "function initForm() {\n";
   $outServiceJobJsDate .= "  fillDateFields(1,\"maincontent\",\"servicejobs\",\"\",\"day_from_jb\",\"month_from_jb\",\"year_from_jb\",\"\",\"\",\"\");\n";
   $outServiceJobJsDate .= "  setDateTimeFields(\"maincontent\",\"servicejobs\",".$day_from_jb.",".$month_from_jb.",".$year_from_jb.", \"\", \"\", \"day_from_jb\", \"month_from_jb\", \"year_from_jb\", \"\", \"\", \"\");\n";
   $outServiceJobJsDate .= "  fillDateFields(1,\"maincontent\",\"servicejobs\", \"\", \"day_to_jb\", \"month_to_jb\", \"year_to_jb\", \"\", \"\", \"\");\n";
   $outServiceJobJsDate .= "  setDateTimeFields(\"maincontent\",\"servicejobs\",".$day_to_jb.",".$month_to_jb.",".$year_to_jb.", \"\", \"\", \"day_to_jb\", \"month_to_jb\", \"year_to_jb\", \"\", \"\", \"\");\n";
   $outServiceJobJsDate .= "}\n";
   $outServiceJobJsDate .= "-->\n";
   $outServiceJobJsDate .= "</script>\n";
   
   // Date ranges
   $jbDateFilter  = "von:\n";      
   $jbDateFilter .= "<select name=\"day_from_jb\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'servicejobs', 'day_from_jb', 'day_from_jb', 'month_from_jb', 'year_from_jb', '', '', '', 'day_to_jb', 'month_to_jb', 'year_to_jb', '', '', '')\"></select>\n";
   $jbDateFilter .= "<select name=\"month_from_jb\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'servicejobs', 'month_from_jb', 'day_from_jb', 'month_from_jb', 'year_from_jb', '', '', '', 'day_to_jb', 'month_to_jb', 'year_to_jb', '', '', '')\"></select>\n";
   $jbDateFilter .= "<select name=\"year_from_jb\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'servicejobs', 'year_from_jb', 'day_from_jb', 'month_from_jb', 'year_from_jb', '', '', '', 'day_to_jb', 'month_to_jb', 'year_to_jb', '', '', '')\"></select>\n";      
   $jbDateFilter .= "&nbsp;&nbsp;bis:\n";     
   $jbDateFilter .= "<select name=\"day_to_jb\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'servicejobs', 'day_to_jb', 'day_from_jb', 'month_from_jb', 'year_from_jb', '', '', '', 'day_to_jb', 'month_to_jb', 'year_to_jb', '', '', '')\"></select>\n";
   $jbDateFilter .= "<select name=\"month_to_jb\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'servicejobs', 'month_to_jb', 'day_from_jb', 'month_from_jb', 'year_from_jb', '', '', '', 'day_to_jb', 'month_to_jb', 'year_to_jb', '', '', '')\"></select>\n";
   $jbDateFilter .= "<select name=\"year_to_jb\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'servicejobs', 'year_to_jb', 'day_from_jb', 'month_from_jb', 'year_from_jb', '', '', '', 'day_to_jb', 'month_to_jb', 'year_to_jb', '', '', '')\"></select>\n";
   $jbDateFilter .= "&nbsp;";

   // Time ranges
   /*
   $jbTimeFilter = "[";
   $jbTimeFilter .= "Ohne<input class=\"smaller\" type=\"radio\" name=\"f_showDateAndTime_jb\" value=\"0\" " . ($f_showDateAndTime_jb == "0" ? "checked" : "") . ">|";
   $jbTimeFilter .= "Mit<input class=\"smaller\" type=\"radio\" name=\"f_showDateAndTime_jb\" value=\"1\" " . ($f_showDateAndTime_jb == "1" ? "checked" : "") . ">";
   $jbTimeFilter .= "Einschränkung auf Zeitintervall von:\n";
   $jbTimeFilter .= "<select name=\"hour_from_jb\" class=\"f8np1\">" . addOptionsFromRange("0","23",$hour_from_jb,"1") . "</select>\n";
   $jbTimeFilter .= "<select name=\"minute_from_jb\" class=\"f8np1\">" . addOptionsFromRange("0","59",$minute_from_jb,"1") . "</select>\n";
   $jbTimeFilter .= "Uhr&nbsp;&nbsp;bis:\n";      
   $jbTimeFilter .= "<select name=\"hour_to_jb\" class=\"f8np1\">" . addOptionsFromRange("0","23",$hour_to_jb,"1") . "</select>\n";
   $jbTimeFilter .= "<select name=\"minute_to_jb\" class=\"f8np1\">" . addOptionsFromRange("0","59",$minute_to_jb,"1") . "</select>\n";
   $jbTimeFilter .= "Uhr]\n";
   */
endif;


// Output log data
$outLogData = "";
if ($generateOutput) :
   $outLogArrayLen = count($outLogArray);
   if ($outLogArrayLen > 0) :
      $outLogData .= "<table width=\"100%\" border=\"1\">";
      $outLogData .= "<tr><td colspan=\"6\" class=\"f10np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . $f_actionObjId . "<b></td></tr>";
      $outLogData .= "<tr><td class=\"f8np1\" style=\"width:120;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('0');\"><b>" . getLngt("Zeitpunkt") . "</b></td>"
                         . "  <td class=\"f8np1\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('1');\"><b>" . getLngt("BEK") . "</td>"
                         . "  <td class=\"f8np1\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('2');\"><b>" . getLngt("MEK") . "</td>"
                         . "  <td class=\"f8np1\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('3');\"><b>" . getLngt("H1") . "</td>"
                         . "  <td class=\"f8np1\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('4');\"><b>" . getLngt("H2") . "</td>"
                         . "  <td class=\"f8np1\" style=\"width:60;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\" onClick=\"logChangeOrderBy('5');\"><b>" . getLngt("H3") . "</td>"
                   . "</tr>";
      for ($j = 0; $j < $outLogArrayLen; $j++) :
          $outLogData .= $outLogArray[$j];
      endfor;
      $outLogData .= "</table>";
   endif;
endif;


// Output message data
$outMessageData = "";
if ($generateOutput) :
   $outMessageArrayLen = count($outMessageArray);
   if ($outMessageArrayLen > 0) :
      $outMessageData .= "<table width=\"100%\" border=\"1\">";
      $outMessageData .= "<tr><td colspan=\"6\" class=\"f10np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . $f_actionObjId . "<b></td></tr>";
      $outMessageData .= "<tr><td class=\"f8np1\" style=\"width:100;text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . getLngt("Code") . "</b></td>"
                         . "  <td class=\"f8np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . getLngt("Beschreibung") . "</td>"
                         . "  <td class=\"f8np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . getLngt("Text") . "</td>"
                   . "</tr>";
      for ($j = 0; $j < $outMessageArrayLen; $j++) :
          $outMessageData .= $outMessageArray[$j];
      endfor;
      $outMessageData .= "</table>";
   endif;
endif;


$outSuFormData = "";
if ($generateOutput) :
   $tmpCol_bg_01 = $colArray["bg"];       $tmpCol_bg_02 = $colArray["green"];      $tmpCol_bg_03 = $colArray["blue"];
   $tmpCol_fg_01 = $colArray["black"];    $tmpCol_fg_02 = $colArray["black"];      $tmpCol_fg_03 = $colArray["black"];
   
   $outSuFormData .= "<table width=\"100%\" border=\"1\">";
   // Service unit data
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td colspan=\"2\" class=\"f8np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . getLngt("Administration Automaten mit Standort") . "</b></td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Automatennummer") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_ati_serialno\" value=\"" . $f_su_admin_ati_serialno . "\" size=\"50\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Automatentyp") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   $outSuFormData .= "    <select name=\"f_su_admin_at_id\">";
   $outSuFormData .= "      <option value=\"\" " . ($f_su_admin_at_id == "" ? "selected" : "") . "></option>";
   $outSuFormData .=        addOptionsFromTable("article AS at, articleitem AS ati, stock AS stk","at.at_id","at.at_match","at.at_match","at.at_id = ati.at_id AND ati.stk_id = stk.stk_id AND stk.stk_pre_id = '" . $rootStockSU . "' ",$f_su_admin_at_id,"DISTINCT");
   $outSuFormData .= "    </select>";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Bemerkung") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_ati_data_01\" value=\"" . $f_su_admin_ati_data_01 . "\" size=\"50\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Geographische Breite") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_ati_data_02\" value=\"" . $f_su_admin_ati_data_02 . "\" size=\"50\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Geographische Länge") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_ati_data_03\" value=\"" . $f_su_admin_ati_data_03 . "\" size=\"50\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Präselektion für Tourenoptimierung [Tourennummer]") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   for ($j = 1; $j <= 7; $j++) :   
       $tmpAtiFieldValue = ${("f_su_admin_ati_data_21_" . $j)};
       $outSuFormData .= substr($calWeekDays[($j - 1)], 0, 2) . "&nbsp;";
       $outSuFormData .= "    <select name=\"f_su_admin_ati_data_21_" . $j . "\">";
       $outSuFormData .= "      <option value=\"\" " . ($tmpAtiFieldValue == "" ? "selected" : "") . "></option>";
       for ($k = 1; $k <= $maxNumOfTours; $k++) :
           $outSuFormData .= "      <option value=\"" . $k . "\" " . ($tmpAtiFieldValue == $k ? "selected" : "") . ">" . $k . "</option>";
       endfor;
       $outSuFormData .= "    </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
   endfor;
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Aktionen") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_02 . ";\">&nbsp;";
   $outSuFormData .= "    " . defineButtonType08("Automatendaten speichern", "action_store_form_serviceunit", "finishFormServiceUnit();", "200", "left", "2");
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";

   // Stock data (service stations)
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td colspan=\"2\" class=\"f8np1\" style=\"text-align:center;color:" . $colArray["white"] . ";background-color:" . $colArray["red"] . ";\"><b>" . getLngt("Administration Standorte") . "</b></td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Standort") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_03 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_stk_name\" value=\"" . $f_su_admin_stk_name . "\" size=\"50\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Info") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_03 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_stk_barcode\" value=\"" . $f_su_admin_stk_barcode . "\" size=\"5\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Strasse, Hausnr.") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_03 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"hidden\" name=\"f_su_admin_ad_id\" value=\"" . $f_su_admin_ad_id . "\">";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_ad_street\" value=\"" . $f_su_admin_ad_street . "\" size=\"40\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_stk_hsno\" value=\"" . $f_su_admin_stk_hsno . "\" size=\"10\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("PLZ, Ort") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:left;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_03 . ";\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_ad_zipcode\" value=\"" . $f_su_admin_ad_zipcode . "\" size=\"10\">&nbsp;";
   $outSuFormData .= "    <input type=\"text\" name=\"f_su_admin_ad_city\" value=\"" . $f_su_admin_ad_city . "\" size=\"40\">";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "<tr>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"width:50%;text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_01 . ";\">";
   $outSuFormData .= "    <b>" . getLngt("Aktionen") . "</b>&nbsp;:&nbsp;";
   $outSuFormData .= "  </td>";
   $outSuFormData .= "  <td class=\"f8np1\" style=\"text-align:right;color:" . $tmpCol_fg_01 . ";background-color:" . $tmpCol_bg_03 . ";\">&nbsp;";
   $outSuFormData .= "    " . defineButtonType08("Standortdaten speichern", "action_store_form_stock", "finishFormStock();", "200", "left", "2");
   $outSuFormData .= "  </td>";
   $outSuFormData .= "</tr>";
   $outSuFormData .= "</table>";
endif;


// Output report entries and system messages
$outReport = "";
$outReportArrayLen = count($outReportArray);
if ($outReportArrayLen > 0) :
   $maskDisplay00Switch = "1";   // Activate output if there is at least one message to be displayed
   $outReport .= "<table width=\"100%\" border=\"0\">";
   for ($j = 0; $j < $outReportArrayLen; $j++) :
       $outReport .= "<tr><td><span class=\"f8np1_red\">" . $outReportArray[$j] . "</span></td></tr>";
   endfor;
   $outReport .= "</table>";
endif;

?>


<?php if (!$isFirefox) : ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "../include/strict.dtd">
<?php endif; ?>

<html>

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

<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
  <?php include_once ("../css/navigation.css.php"); ?>
</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; ?>

var checkboxStateVectorWasChanged = false;

function setCheckboxStateVectorWasChanged() {
	checkboxStateVectorWasChanged = true;
}

// Shows/Hides display areas
function changeHideShow(areaSwitched,displayState) {
	var areaShow = areaSwitched;
	var areaShowAction = areaSwitched + 'Action';
  var areaReducedAction = areaSwitched + 'ReducedAction';

  if (displayState == 'on') {
  	 myshow(areaShow);
  	 myshow(areaShowAction);
  	 myhide(areaReducedAction);
     elem = eval('document.forms[0].' + areaShow + 'Switch');
     elem.value = '1';
  };
  if (displayState == 'off') {
     myhide(areaShow);
     myhide(areaShowAction);
     myshow(areaReducedAction);
     elem = eval('document.forms[0].' + areaShow + 'Switch');
     elem.value = '0';
  };
}

function removeSystemMessage() {
  changeHideShow('maskDisplay00','off');
  vSetElementContent('maskDisplay00Content', '');
}

function suCheckAll(numOfRows) {
  for (i = 0; i < numOfRows; i++) {
  	if (document.getElementsByName('f_su_chkbx[]')[i]) {
	     document.getElementsByName('f_su_chkbx[]')[i].checked = true;
	  }
	}
	setCheckboxStateVectorWasChanged();
}

function suUncheckAll(numOfRows) {
  for (i = 0; i < numOfRows; i++) {
  	if (document.getElementsByName('f_su_chkbx[]')[i]) {
	     document.getElementsByName('f_su_chkbx[]')[i].checked = false;
	  }
  }
  setCheckboxStateVectorWasChanged();
}

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

function preFinishPage(f_act) {
	var doFinishPage = true;
	if (checkboxStateVectorWasChanged) {
		 doFinishPage = false;
		 if (confirm('<?php echo getLngt("Die Auswahl (Checkboxen) wurde verändert! Möchten Sie trotzdem fortfahren? Ansonsten bitte den Auswahlzustand sichern!") ?>')) {
		 	  doFinishPage = true;
		 }
  }
	if (doFinishPage) {
     finishPage(f_act);
  }
}

function suCheckboxes() {
  var frm = document.forms[0]; 
  if (frm.f_pt_action_1.options[1].selected == true) {
     frm.f_suLoadStates.value = '1';
     if (confirm('<?php echo getLngt("Möchten Sie den aktuellen Auswahlzustand verwerfen?") ?>')) {
        finishPage('');
     }
  }
  if (frm.f_pt_action_1.options[2].selected == true) {
     frm.f_suLoadStates.value = '3';
     if (confirm('<?php echo getLngt("Möchten Sie die kritischen der aktuellen Auswahl zufügen?") ?>')) {
        finishPage('');
     }
  }
  if (frm.f_pt_action_1.options[3].selected == true) {
  	 if (confirm('<?php echo getLngt("Möchten Sie den aktuellen Auswahlzustand verwerfen?") ?>')) {
        suCheckAll(<?php echo $numOfRowsSU ?>);
     }
  }
  if (frm.f_pt_action_1.options[4].selected == true) {
  	 if (confirm('<?php echo getLngt("Möchten Sie den aktuellen Auswahlzustand verwerfen?") ?>')) {
        suUncheckAll(<?php echo $numOfRowsSU ?>);
     }
  }
  if (frm.f_pt_action_1.options[5].selected == true) {
  	 if (confirm('<?php echo getLngt("Möchten Sie den gespeicherten Auswahlzustand überschreiben?") ?>')) {
        finishPage('savePT');
     }
  }
  if (frm.f_pt_action_1.options[6].selected == true) {
     frm.f_suLoadStates.value = '2';
     if (confirm('<?php echo getLngt("Möchten Sie den gespeicherten Auswahlzustand laden?") ?>')) {
        finishPage('');
     }
  }
  setSelectedValue('f_pt_action_1', '0');
  setCheckboxStateVectorWasChanged();
};

function suOptimize() {
  if (confirm('<?php echo getLngt("Möchten Sie für den angezeigten Auswahlzustand eine Optimierung vornehmen? Der aktuelle Auswahlzustand wird automatisch gespeichert!") ?>')) {
     finishPage('optimizePT');
  }	
}

function suMakeJob() {
  if (confirm('<?php echo getLngt("Möchten Sie auf Basis der angezeigten Sortierung Fuhraufträge erzeugen?") ?>')) {
     finishPage('makeJobPT');
  }	
}

function tvSetDefaults() {
	var frm = document.forms[0];
	frm.f_tv_01.value = '<?php echo $f_tv_01_org ?>';
	frm.f_tv_02.value = '<?php echo $f_tv_02_org ?>';
	frm.f_tv_03.value = '<?php echo $f_tv_03_org ?>';
	frm.f_tv_04.value = '<?php echo $f_tv_04_org ?>';
	frm.f_tv_05.value = '<?php echo $f_tv_05_org ?>';
	frm.f_tv_06.value = '<?php echo $f_tv_06_org ?>';
	frm.f_tv_07.value = '<?php echo $f_tv_07_org ?>';
	frm.f_tv_08.value = '<?php echo $f_tv_08_org ?>';
	frm.f_tv_09.value = '<?php echo $f_tv_09_org ?>';
	frm.f_tv_10.value = '<?php echo $f_tv_10_org ?>';
	frm.f_tv_11.value = '<?php echo $f_tv_11_org ?>';
	frm.f_tv_12.value = '<?php echo $f_tv_12_org ?>';
	frm.f_tv_13.value = '<?php echo $f_tv_13_org ?>';
	frm.f_tv_14.value = '<?php echo $f_tv_14_org ?>';
	frm.f_tv_15.value = '<?php echo $f_tv_15_org ?>';
	frm.f_tv_16.value = '<?php echo $f_tv_16_org ?>';
	frm.f_tv_17.value = '<?php echo $f_tv_17_org ?>';
	frm.f_tv_18.value = '<?php echo $f_tv_18_org ?>';
	frm.f_tv_19.value = '<?php echo $f_tv_19_org ?>';
	frm.f_tv_20.value = '<?php echo $f_tv_20_org ?>';
	frm.f_tv_21.value = '<?php echo $f_tv_21_org ?>';
	frm.f_tv_22.value = '<?php echo $f_tv_22_org ?>';
	frm.f_tv_23.value = '<?php echo $f_tv_23_org ?>';
	frm.f_tv_24.value = '<?php echo $f_tv_24_org ?>';
	frm.f_tv_25.value = '<?php echo $f_tv_25_org ?>';
	// preFinishPage('');
	finishPage('');
}

function suChangeOrderBy(col) {
	if (col != '') {
		 document.forms[0].f_su_orderByCol.value = col;
		 finishPage('');
  }
}

function jbChangeOrderBy(col) {
	if (col != '') {
		 document.forms[0].f_jb_orderByCol.value = col;
		 finishPage('');
  }
}

function logChangeOrderBy(col) {
	if (col != '') {
		 document.forms[0].f_log_orderByCol.value = col;
		 finishPage('');
  }
}

function openMap(stkId) {
  var widthPopupWin = 1200;
  var heightPopupWin = 800;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  var presetFields = '<?php echo urlencode(getParameterValue("0", "MASK_CS2CO_PRESET", "0")) ?>';
  popupWin = window.open("../locating/map_stock.php?stk_id=" + stkId,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

// Every element (service unit serialno, job ID, zipcode, ...) has some possibilities to be selected for
function selAction(actionObjType, actionObjId, actionObjIdInfo) {
	var frm = document.forms[0];
	// IMPORTANT: Init parameters to be submitted because no DB operation will be executed for the next page submit for a specified service unit !!!
	frm.f_actionObjType.value = '';
	frm.f_actionObjId.value = '';
	frm.f_actionID.value = '';
	// Define selected form parameters
	frm.actionObjType.value = actionObjType;
	frm.actionObjId.value = actionObjId;
  if (actionObjType == 'ati_serialno') {
  	 vSetElementContent('ac_title', '<b>Automat&nbsp;' + actionObjId + '</b>&nbsp;&nbsp;' + actionObjIdInfo);
  	 vSetElementContent('ac_01', '<a href="javascript:execAjaxAction(\'' + actionObjType + '\',\'' + actionObjId + '\',' + '\'101\'' + ')"><?php echo getLngt("Standort auf der Karte") ?></a>');
  	 vSetElementContent('ac_02', '<a href="javascript:execAction(\'' + actionObjType + '\',\'' + actionObjId + '\',' + '\'102\'' + ')"><?php echo getLngt("Zustandsverlauf anzeigen") ?></a>');
  	 vSetElementContent('ac_03', '<a href="javascript:execAction(\'' + actionObjType + '\',\'' + actionObjId + '\',' + '\'103\'' + ')"><?php echo getLngt("Aufträge anzeigen") ?></a>');
  	 vSetElementContent('ac_04', '<a href="javascript:execAction(\'' + actionObjType + '\',\'' + actionObjId + '\',' + '\'104\'' + ')"><?php echo getLngt("Betriebsmeldungen anzeigen") ?></a>');
  	 vSetElementContent('ac_05', '<a href="javascript:execAction(\'' + actionObjType + '\',\'' + actionObjId + '\',' + '\'105\'' + ')"><?php echo getLngt("Verwaltung") ?></a>');
  	 vSetElementContent('ac_06', '');
  	 vSetElementContent('ac_07', '');
  	 vSetElementContent('ac_08', '');

  	 // Notice associated to a service unit
  	 ajaxRequestGet('../include/ajaxReqLib.php', 'mode=0&db_table=articleitem&db_id_field=ati_serialno&search_value=' + actionObjId + '&db_return_field=ati_data_25');
     vSetElementContent('ac_09', '<input type="text" name="f_su_content_109" value="' + retValue + '" size="50"><br><a href="javascript:execAjaxAction(\'' + actionObjType + '\',\'' + actionObjId + '\',' + '\'109\'' + ')"><?php echo getLngt("Notiz speichern") ?></a>');
  }
  if (actionObjType == 'jb_id') {
  	 vSetElementContent('ac_title', '<b>Auftrag&nbsp;' + actionObjId + '</b>&nbsp;&nbsp;' + actionObjIdInfo);
  	 vSetElementContent('ac_01', '<a href="../tools/jb_detail_MC.php?jbId=' + actionObjId + '" target="_blank"><?php echo getLngt("Auftragsdetails") ?></a>');
  	 vSetElementContent('ac_02', '');
  	 vSetElementContent('ac_03', '');
  	 vSetElementContent('ac_04', '');
  	 vSetElementContent('ac_05', '');
  	 vSetElementContent('ac_06', '');
  	 vSetElementContent('ac_07', '');
  	 vSetElementContent('ac_08', '');
  	 vSetElementContent('ac_09', '');
  }
  myshow('actioncontainer');
}

// Execute a selected action for a specified object
function execAction(actionObjType, actionObjId, actionID) {
	myhide('actioncontainer');
	var frm = document.forms[0];
  if (actionObjType != '' && actionObjId != '' && actionID != '') {
  	 frm.f_actionObjType.value = actionObjType;
	   frm.f_actionObjId.value = actionObjId;
	   frm.f_actionID.value = actionID;
	   finishPage('processAction');
  }
}

// Execute a selected action for a specified object
function execAjaxAction(actionObjType, actionObjId, actionID) {
	// myhide('actioncontainer');
	var frm = document.forms[0];
  if (actionObjType != '' && actionObjId != '' && actionID != '') {
     if (actionObjType == 'ati_serialno') {
        if (actionID == '101') {
           ajaxRequestGet('../include/ajaxReqLib.php', 'mode=0&db_table=articleitem&db_id_field=ati_serialno&search_value=' + actionObjId + '&db_return_field=stk_id');
           if (retValue != '') {
              openMap(retValue);    // Open map tith stock ID
           }
        }
        if (actionID == '109') {
           if (frm.f_su_content_109) {
           	  var content = frm.f_su_content_109.value;
              ajaxRequestGet('../include/ajaxReqLib.php', 'mode=100&db_table=articleitem&db_id_field=ati_serialno&search_value=' + actionObjId + '&db_op_field=ati_data_25&new_content=' + content);
              if (content != '') {
                 vSetElementContent(actionObjId + '_notice', '*');        // Set asterisk into the table cell
              } else {
                 vSetElementContent(actionObjId + '_notice', '&nbsp;');   // Remove asterisk out of the table cell
              }
           }
        }
     }
  }
}

function setSuFormData() {
  var frm = document.forms[0];
  setSelectedValue('f_su_admin_at_id', '<?php echo $f_su_admin_at_id; ?>');
  setSelectedValue('f_su_admin_stk_id', '<?php echo $f_su_admin_stk_id; ?>');
  frm.f_su_admin_ati_serialno.value = '<?php echo $f_su_admin_ati_serialno; ?>';
  frm.f_su_admin_stk_name.value = '<?php echo $f_su_admin_stk_name; ?>';
  frm.f_su_admin_stk_barcode.value = '<?php echo $f_su_admin_stk_barcode; ?>';
  frm.f_su_admin_ati_data_01.value = '<?php echo $f_su_admin_ati_data_01; ?>';
  frm.f_su_admin_ati_data_02.value = '<?php echo $f_su_admin_ati_data_02; ?>';
  frm.f_su_admin_ati_data_03.value = '<?php echo $f_su_admin_ati_data_03; ?>';
  frm.f_su_admin_ad_id.value = '<?php echo $f_su_admin_ad_id; ?>';
  frm.f_su_admin_ad_street.value = '<?php echo $f_su_admin_ad_street; ?>';
  frm.f_su_admin_stk_hsno.value = '<?php echo $f_su_admin_stk_hsno; ?>';
  frm.f_su_admin_ad_zipcode.value = '<?php echo $f_su_admin_ad_zipcode; ?>';
  frm.f_su_admin_ad_city.value = '<?php echo $f_su_admin_ad_city; ?>';
  <?php
    for ($i = 1; $i <= $maxNumOfTours; $i++) :
        echo "frm.f_su_admin_ati_data_21_" . $i . ".value = '" . ${("f_su_admin_ati_data_21_" . $i)} . "';";
    endfor;
  ?>
}

function resetSuFormData() {
  var frm = document.forms[0];
  setSelectedValue('f_su_admin_filter_1', '');
  setSelectedValue('f_su_admin_at_id', '');
  setSelectedValue('f_su_admin_stk_id', '');
  frm.f_su_admin_ati_serialno.value = '';
  frm.f_su_admin_stk_name.value = '';
  frm.f_su_admin_stk_barcode.value = '';
  frm.f_su_admin_ati_data_01.value = '';
  frm.f_su_admin_ati_data_02.value = '';
  frm.f_su_admin_ati_data_03.value = '';
  frm.f_su_admin_ad_id.value = '';
  frm.f_su_admin_ad_street.value = '';
  frm.f_su_admin_stk_hsno.value = '';
  frm.f_su_admin_ad_zipcode.value = '';
  frm.f_su_admin_ad_city.value = '';
  <?php
    for ($i = 1; $i <= $maxNumOfTours; $i++) :
        echo "frm.f_su_admin_ati_data_21_" . $i . ".value = '';";
    endfor;
  ?>
  removeSystemMessage();
}

function finishFormServiceUnit() {
	var frm = document.forms[0];
	var msg = '';
	var doStore = true;
	
  // Get current selected value for article id
  var atId = '';
  for(i=0;i<frm.f_su_admin_at_id.length;++i) {
    if (frm.f_su_admin_at_id.options[i].selected == true) {
       atId = frm.f_su_admin_at_id.options[i].value;
    }
  }
  // Get current selected value for stock id
  var stkId = '';
  for(i=0;i<frm.f_su_admin_stk_id.length;++i) {
    if (frm.f_su_admin_stk_id.options[i].selected == true) {
       stkId = frm.f_su_admin_stk_id.options[i].value;
    }
  }

	// If a service unit was selected (option value is NOT "") then there have to be an article id and a stock id
	if (frm.f_su_admin_filter_1.options[0].selected == false) {
     for(i=0;i<frm.f_su_admin_filter_1.length;++i) {
       if (frm.f_su_admin_filter_1.options[i].selected == true) {
          if (frm.f_su_admin_filter_1.options[i].value != frm.f_su_admin_ati_serialno.value) {
		 	       doStore = false;
		 	       msg += '<?php echo getLngt("Die Automatennummer stimmt nicht mir der Filterauswahl überein!") ?> ';
          }
       }
     }
  }
  // Check article (service unit type)
	if (atId == '') {
		  doStore = false;
		  msg += '<?php echo getLngt("Bitte einen Automatentypen wählen!") ?> ';
	}
	// Check stock (service station)
	if (stkId == '') {
		  doStore = false;
		  msg += '<?php echo getLngt("Bitte einen Standort selektieren!") ?> ';
	}
  // Check coordinates
  if (frm.f_su_admin_ati_data_02.value == '' || isNaN(frm.f_su_admin_ati_data_02.value) ||
      frm.f_su_admin_ati_data_03.value == '' || isNaN(frm.f_su_admin_ati_data_03.value)) {
		 doStore = false;
		 msg += '<?php echo getLngt("Bitte geben Sie die Geo-Koordinaten korrekt ein!") ?> ';
  }
  // Check preselection for optimization process
  var doStoreTours = true;
  <?php
    for ($i = 1; $i <= $maxNumOfTours; $i++) :
        echo "if (frm.f_su_admin_ati_data_21_" . $i . ".options[0].selected == true) {";
        echo "   doStoreTours = false;";
        echo "};";
    endfor;
  ?>
  if (!doStoreTours) {
		 doStore = false;
		 msg += '<?php echo getLngt("Bitte ordnen Sie eine Tour zu!") ?> ';
  }
  if (doStore) {
     finishPage('storeDataServiceunit');
	} else {
     alert(msg + ' ' + '<?php echo getLngt("Die Daten wurden nicht gespeichert!") ?>');
	}
}

function finishFormStock() {
	var frm = document.forms[0];
	var msg = '';
	var doStore = true;

  // Get current selected value for stock id
  var stkId = '';
  for(i=0;i<frm.f_su_admin_stk_id.length;++i) {
    if (frm.f_su_admin_stk_id.options[i].selected == true) {
       stkId = frm.f_su_admin_stk_id.options[i].value;
    }
  }

	// Check the name of the stock has been set
  if (trim(frm.f_su_admin_stk_name.value) == '') {
		 doStore = false;
		 msg += '<?php echo getLngt("Die Bezeichnung des Standorts darf nicht leer sein!") ?> ';
  }
  // Check preselection for optimization process
  if (trim(frm.f_su_admin_ad_street.value) == '' || trim(frm.f_su_admin_stk_hsno.value) == '' || trim(frm.f_su_admin_ad_zipcode.value) == '' || trim(frm.f_su_admin_ad_city.value) == '') {
		 doStore = false;
		 msg += '<?php echo getLngt("Bitte geben Sie die Adressdaten vollständig ein! Als Straße verwenden Sie bspw. die Standortbezeichnung oder bei der Hausnummer lediglich einen Punkt. Die PLZ und die Ortsangabe sollten richtig angegeben werden.") ?> ';
  }
  if (doStore) {
     finishPage('storeDataStock');
	} else {
     alert(msg + ' ' + '<?php echo getLngt("Die Daten wurden nicht gespeichert!") ?>');
	}
}

function getServiceunitData(atiSerialNoSpecial) {
	var frm = document.forms[0];
	var atiSerialno = '';
	
	if (atiSerialNoSpecial != '') {
		 atiSerialno = atiSerialNoSpecial;
  } else {
     // Get current selected value for service unit item
     for(i=0;i<frm.f_su_admin_filter_1.length;++i) {
       if (frm.f_su_admin_filter_1.options[i].selected == true) {
          atiSerialno = frm.f_su_admin_filter_1.options[i].value;
       }
     }
  }

  if (atiSerialno != '') {
     ajaxRequestGet('../include/ajaxReqLib.php', 'mode=1&db_table=articleitem&db_id_field=ati_serialno&search_value=' + atiSerialno + '&db_return_field=at_id---stk_id---ati_data_01---ati_data_02---ati_data_03---ati_data_21');
     frm.f_su_admin_ati_serialno.value = atiSerialno;
     frm.f_su_admin_at_id.value = retValue['at_id'];
     frm.f_su_admin_stk_id.value = retValue['stk_id'];
     frm.f_su_admin_ati_data_01.value = retValue['ati_data_01'];
     frm.f_su_admin_ati_data_02.value = retValue['ati_data_02'];
     frm.f_su_admin_ati_data_03.value = retValue['ati_data_03'];
     
     var atiData21 = retValue['ati_data_21'];
     var atiData21Array = atiData21.split(",");
     var atiData21ArrayLen = atiData21Array.length;
     var tmpFrmData21 = '';
     var elemNo;
     for(i=0;i<atiData21ArrayLen;++i) {    	  
     	  tmpFrmData21 = 'f_su_admin_ati_data_21_' + (i + 1).toString();
     	  setSelectedValue(tmpFrmData21, atiData21Array[i]);
     }

     if (retValue['at_id'] != '') {
     	  setSelectedValue('f_su_admin_at_id', retValue['at_id']);
     }
     if (retValue['stk_id'] != '') {
        ajaxRequestGet('../include/ajaxReqLib.php', 'mode=1&db_table=stock&db_id_field=stk_id&search_value=' + retValue['stk_id'] + '&db_return_field=ad_id---stk_hsno---stk_name---stk_barcode');
        frm.f_su_admin_stk_name.value = retValue['stk_name'];
        frm.f_su_admin_ad_id.value = retValue['ad_id'];
        frm.f_su_admin_stk_hsno.value = retValue['stk_hsno'];
        frm.f_su_admin_stk_barcode.value = retValue['stk_barcode'];
        if (retValue['ad_id'] != '') {
           ajaxRequestGet('../include/ajaxReqLib.php', 'mode=1&db_table=address&db_id_field=ad_id&search_value=' + retValue['ad_id'] + '&db_return_field=ad_street---ad_zipcode---ad_city');
           frm.f_su_admin_ad_street.value = retValue['ad_street'];        
           frm.f_su_admin_ad_zipcode.value = retValue['ad_zipcode'];
           frm.f_su_admin_ad_city.value = retValue['ad_city'];
        }
     }
  }

  removeSystemMessage();
}

function getStockData() {
	var frm = document.forms[0];

  // Get current selected value for stock id
  var stkId = '';
  for(i=0;i<frm.f_su_admin_stk_id.length;++i) {
    if (frm.f_su_admin_stk_id.options[i].selected == true) {
       stkId = frm.f_su_admin_stk_id.options[i].value;
    }
  }
  
  if (stkId != '') {
     ajaxRequestGet('../include/ajaxReqLib.php', 'mode=1&db_table=stock&db_id_field=stk_id&search_value=' + stkId + '&db_return_field=ad_id---stk_hsno---stk_name---stk_barcode');
     frm.f_su_admin_stk_name.value = retValue['stk_name'];
     frm.f_su_admin_ad_id.value = retValue['ad_id'];
     frm.f_su_admin_stk_hsno.value = retValue['stk_hsno'];
     frm.f_su_admin_stk_barcode.value = retValue['stk_barcode'];
     if (retValue['ad_id'] != '') {
        ajaxRequestGet('../include/ajaxReqLib.php', 'mode=1&db_table=address&db_id_field=ad_id&search_value=' + retValue['ad_id'] + '&db_return_field=ad_street---ad_zipcode---ad_city');
        frm.f_su_admin_ad_street.value = retValue['ad_street'];        
        frm.f_su_admin_ad_zipcode.value = retValue['ad_zipcode'];
        frm.f_su_admin_ad_city.value = retValue['ad_city'];
     }
  }
  
  removeSystemMessage();
}

function execBodyOnLoad() {
	myhide('actioncontainer');
	initForm();
  <?php
    if ($maskDisplay00Switch == "1") : echo "changeHideShow('maskDisplay00','on');"; else : echo "changeHideShow('maskDisplay00','off');"; endif;
    if ($maskDisplay01Switch == "1") : echo "changeHideShow('maskDisplay01','on');"; else : echo "changeHideShow('maskDisplay01','off');"; endif;
    if ($maskDisplay02Switch == "1") : echo "changeHideShow('maskDisplay02','on');"; else : echo "changeHideShow('maskDisplay02','off');"; endif;
    if ($maskDisplay03Switch == "1") : echo "changeHideShow('maskDisplay03','on');"; else : echo "changeHideShow('maskDisplay03','off');"; endif;
    if ($maskDisplay04Switch == "1") : echo "changeHideShow('maskDisplay04','on');"; else : echo "changeHideShow('maskDisplay04','off');"; endif;
    if ($maskDisplay05Switch == "1") : echo "changeHideShow('maskDisplay05','on');"; else : echo "changeHideShow('maskDisplay05','off');"; endif;
    if ($maskDisplay06Switch == "1") : echo "changeHideShow('maskDisplay06','on');"; else : echo "changeHideShow('maskDisplay06','off');"; endif;
    if ($maskDisplay07Switch == "1") : echo "changeHideShow('maskDisplay07','on');"; else : echo "changeHideShow('maskDisplay07','off');"; endif;
    
    if ($jsExecBodyOnLoadArray[0] == "1") : echo "setSuFormData();"; endif;
    if ($jsExecBodyOnLoadArray[1] == "1") : echo "resetSuFormData();"; endif;
    if ($jsExecBodyOnLoadArray[2] == "1") : echo "getServiceunitData('" . $f_su_admin_filter_1 . "');"; endif;
  ?>
  myshow('maincontent');
  displayStatusMessage();
}

-->
</script>

<?php echo $outServiceJobJsDate ?>

<?php
  if ($isFirefox) :
     $tmpDivPos = "style=\"position:fixed; top:100px; left:450; width:500px; height:500px; background-color:#8888FF;\"";
  else :
     $tmpDivPos = "";
?>
   <style type="text/css">
     #actioncontainer { position:absolute; top:100px; left:450px; width:500px; height:500px; background-color:#8888FF; }     
     html>body #actioncontainer { position: fixed; }
   </style>
   <!--[if lt IE 7]>
   <style type="text/css">
     @media screen {
       html, body {
         height: 100%; overflow-y: hidden;
       }
       #scrollcontainer {
         height: 100%; width: 100%; overflow: auto;
       }
     }
   </style>
   <![endif]-->
<?php   
  endif;
?>


</head>

<body onLoad="execBodyOnLoad();">

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

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

<script type="text/javascript">myhide('maincontent');</script>

  <form name="servicejobs" action="../tools/servicejob.php" method="post">
  	
  <div id="scrollcontainer">

    <input type="hidden" name="f_act" value="">
    <?php echo $phpCurrentNavigationInputHidden ?>
    <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
    <input type="hidden" name="statusMessage" value="">
    
    <input type="hidden" name="f_suLoadStates" value="0">
    <input type="hidden" name="f_su_orderByCol" value="<?php echo ec($f_su_orderByCol) ?>">
    <input type="hidden" name="f_jb_orderByCol" value="<?php echo ec($f_jb_orderByCol) ?>">
    <input type="hidden" name="f_log_orderByCol" value="<?php echo ec($f_log_orderByCol) ?>">

    <input type="hidden" name="maskDisplay00Switch" value="<?php echo $maskDisplay00Switch ?>">
    <input type="hidden" name="maskDisplay01Switch" value="<?php echo $maskDisplay01Switch ?>">
    <input type="hidden" name="maskDisplay02Switch" value="<?php echo $maskDisplay02Switch ?>">
    <input type="hidden" name="maskDisplay03Switch" value="<?php echo $maskDisplay03Switch ?>">
    <input type="hidden" name="maskDisplay04Switch" value="<?php echo $maskDisplay04Switch ?>">
    <input type="hidden" name="maskDisplay05Switch" value="<?php echo $maskDisplay05Switch ?>">
    <input type="hidden" name="maskDisplay06Switch" value="<?php echo $maskDisplay06Switch ?>">
    <input type="hidden" name="maskDisplay07Switch" value="<?php echo $maskDisplay07Switch ?>">

    <input type="hidden" name="f_actionObjType" value="<?php echo $f_actionObjType ?>">
    <input type="hidden" name="f_actionObjId" value="<?php echo $f_actionObjId ?>">
    <input type="hidden" name="f_actionID" value="<?php echo $f_actionID ?>">

    <table width="100%" border="0">
    	<tr>
    		<td width="20">
    	  </td>

        <td>
        	<!-- LOGO -->
          <div style="float:left;width:240px;height:50px;">
        	  <div style="float:left;">
        	    <div><img src="../images/external/hochbahn_hh.jpg" border="0" height="42" width="205"></div>
        	    <?php echo htmlDivLineSpacer("5px"); ?>
        	    <?php // echo defineButtonType08("Automatendaten importieren", "action_import", "finishPage('');", "205", "", "") ?>
        	    <?php // echo htmlDivLineSpacer("5px"); ?>
        	    <!--
        	    <div class="f10bp1_blue" style="float:left;"><input type="text" name="f_search" value="<?php echo $f_search ?>" size="17">&nbsp;</div>
        	    <?php echo defineButtonType08("Suche", "import", "finishPage('');", "70", "", "") ?>
        	    -->
        	  </div>
          </div>

          <!-- NAVIGATION START -->
          <div>
            <!-- Output report entries -->
            <div style="float:left;">
              <div id="maskDisplay00Action" name="maskDisplay00Action">
                <?php echo defineButtonType08("-", "action_00", "changeHideShow('maskDisplay00','off');", "10", "left", "2") ?>
                <div class="<?php echo ($outReportArrayLen > 0 ? "f10bp1_red" : "f10bp1_blue") ?>" style="float:left;width:180px;">
                  <?php echo getLngt("SYSTEMMELDUNGEN") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>      
              </div>
              <div id="maskDisplay00ReducedAction" name="maskDisplay00ReducedAction">
                <?php echo defineButtonType08("+", "action_00", "changeHideShow('maskDisplay00','on');", "10", "left", "2") ?>
                <div class="<?php echo ($outReportArrayLen > 0 ? "f10bp1_red" : "f10bp1_blue") ?>" style="float:left;width:180px;">
                  <?php echo getLngt("SYSTEMMELDUNGEN") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
              </div>
            </div>
            
            <!-- Output threshold values -->
            <div style="float:left;">
              <div id="maskDisplay01Action" name="maskDisplay01Action">
                <?php echo defineButtonType08("-", "action_01", "changeHideShow('maskDisplay01','off');", "10", "left", "2") ?>
                <div class="f10bp1_blue" style="float:left;width:180px;">
                  <?php echo getLngt("SCHWELLWERTE") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>      
              </div>
              <div id="maskDisplay01ReducedAction" name="maskDisplay01ReducedAction">
                <?php echo defineButtonType08("+", "action_01", "changeHideShow('maskDisplay01','on');", "10", "left", "2") ?>
                <div class="f10bp1_blue" style="float:left;width:180px;">
                  <?php echo getLngt("SCHWELLWERTE") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
              </div>
            </div>

            <!-- Output current states of service units -->
            <div style="float:left;">
              <div id="maskDisplay02Action" name="maskDisplay02Action">
                <?php echo defineButtonType08("-", "action_02", "changeHideShow('maskDisplay02','off');", "10", "left", "2") ?>
                <div class="f10bp1_blue" style="float:left;width:180px;">
                  <?php echo getLngt("AUTOMATENZUSTÄNDE") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>      
              </div>
              <div id="maskDisplay02ReducedAction" name="maskDisplay02ReducedAction">
                <?php echo defineButtonType08("+", "action_02", "changeHideShow('maskDisplay02','on');", "10", "left", "2") ?>
                <div class="f10bp1_blue" style="float:left;width:180px;">
                  <?php echo getLngt("AUTOMATENZUSTÄNDE") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
              </div>
            </div>
            
            <!-- Output jobs -->
            <div style="float:left;">
              <div id="maskDisplay03Action" name="maskDisplay03Action">
                <?php echo defineButtonType08("-", "action_03", "changeHideShow('maskDisplay03','off');", "10", "left", "2") ?>
                <div class="f10bp1_blue" style="float:left;width:180px;">
                  <?php echo getLngt("AUFTRÄGE") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>      
              </div>
              <div id="maskDisplay03ReducedAction" name="maskDisplay03ReducedAction">
                <?php echo defineButtonType08("+", "action_03", "changeHideShow('maskDisplay03','on');", "10", "left", "2") ?>
                <div class="f10bp1_blue" style="float:left;width:180px;">
                  <?php echo getLngt("AUFTRÄGE") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
              </div>
            </div>

            <!-- Output log events of a specified service unit -->
            <div style="float:left;">
              <div id="maskDisplay04Action" name="maskDisplay04Action">
                <?php echo defineButtonType08("-", "action_04", "changeHideShow('maskDisplay04','off');", "10", "left", "2") ?>
                <div class="f10bp1_blue" style="float:left;width:180px;">
                  <?php echo getLngt("ZUSTANDSVERLAUF") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>      
              </div>
              <div id="maskDisplay04ReducedAction" name="maskDisplay04ReducedAction">
                <?php echo defineButtonType08("+", "action_04", "changeHideShow('maskDisplay04','on');", "10", "left", "2") ?>
                <div class="f10bp1_blue" style="float:left;width:180px;">
                  <?php echo getLngt("ZUSTANDSVERLAUF") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
              </div>
            </div>

            <!-- Output messages of a specified service unit -->
            <div style="float:left;">
              <div id="maskDisplay05Action" name="maskDisplay05Action">
                <?php echo defineButtonType08("-", "action_05", "changeHideShow('maskDisplay05','off');", "10", "left", "2") ?>
                <div class="f10bp1_blue" style="float:left;width:180px;">
                  <?php echo getLngt("BETRIEBSMELDUNGEN") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>      
              </div>
              <div id="maskDisplay05ReducedAction" name="maskDisplay05ReducedAction">
                <?php echo defineButtonType08("+", "action_05", "changeHideShow('maskDisplay05','on');", "10", "left", "2") ?>
                <div class="f10bp1_blue" style="float:left;width:180px;">
                  <?php echo getLngt("BETRIEBSMELDUNGEN") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
              </div>
            </div>
            
            <!-- Output form to insert/edit a service unit -->
            <div style="float:left;">
              <div id="maskDisplay06Action" name="maskDisplay06Action">
                <?php echo defineButtonType08("-", "action_06", "changeHideShow('maskDisplay06','off');", "10", "left", "2") ?>
                <div class="f10bp1_blue" style="float:left;width:180px;">
                  <?php echo getLngt("VERWALTUNG") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
              </div>
              <div id="maskDisplay06ReducedAction" name="maskDisplay06ReducedAction">
                <?php echo defineButtonType08("+", "action_06", "changeHideShow('maskDisplay06','on');", "10", "left", "2") ?>
                <div class="f10bp1_blue" style="float:left;width:180px;">
                  <?php echo getLngt("VERWALTUNG") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
              </div>
            </div>
            
            <!-- Global state values of all serviceunits -->
            <div style="float:left;">
              <div id="maskDisplay07Action" name="maskDisplay07Action">
                <?php echo defineButtonType08("-", "action_07", "changeHideShow('maskDisplay07','off');", "10", "left", "2") ?>
                <div class="f10bp1_blue" style="float:left;width:180px;">
                  <?php echo getLngt("GLOBALE WERTE") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
              </div>
              <div id="maskDisplay07ReducedAction" name="maskDisplay07ReducedAction">
                <?php echo defineButtonType08("+", "action_07", "changeHideShow('maskDisplay07','on');", "10", "left", "2") ?>
                <div class="f10bp1_blue" style="float:left;width:180px;">
                  <?php echo getLngt("GLOBALE WERTE") ?>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
              </div>
            </div>

          </div>
          <?php echo htmlDivLineSpacer("20px", "", "left"); ?>
          <!-- NAVIGATION END -->

          <!-- ******************************************************************************************** -->

          <!-- GLOBAL STATE VALUES OF ALL SERVICEUNITS -->
          <div id="maskDisplay07" name="maskDisplay07">
            <?php echo defineButtonType08("-", "action_global_state_values", "changeHideShow('maskDisplay07','off');", "10", "left", "2") ?>
            <div class="f10bp1_blue" style="float:left">
              <?php echo getLngt("GLOBALE WERTE:") ?>&nbsp;&nbsp;&nbsp;&nbsp;
            </div>
            <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
            <div id="maskDisplay07Content" name="maskDisplay07Content">
              <?php 
                getGlobalStateData ();
                echo getLngt("AUTOMATENANZAHL:") . "&nbsp;" . $outGlobalStateArray["numOfRowsSU"] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                echo getLngt("KRITISCHE AUTOMATEN:") . "&nbsp;" . $outGlobalStateArray["numOfCriticalRowsSU"] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                echo getLngt("SEMIKRITISCHE AUTOMATEN:") . "&nbsp;" . $outGlobalStateArray["numOfSemiCriticalRowsSU"] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                /*
                echo "<br><br>";
                echo getLngt("BEK:") . "&nbsp;" . number_format($outGlobalStateArray["ati_data_05"], 0, ",", ".") . "&nbsp;€&nbsp;&nbsp;&nbsp;&nbsp;";
                echo getLngt("MEK:") . "&nbsp;" . number_format($outGlobalStateArray["ati_data_06"], 2, ",", ".") . "&nbsp;€&nbsp;&nbsp;&nbsp;&nbsp;";
                echo getLngt("H1:")  . "&nbsp;" . number_format($outGlobalStateArray["ati_data_07"], 0, ",", ".") . "&nbsp;€&nbsp;&nbsp;&nbsp;&nbsp;";
                echo getLngt("H2:")  . "&nbsp;" . number_format($outGlobalStateArray["ati_data_08"], 2, ",", ".") . "&nbsp;€&nbsp;&nbsp;&nbsp;&nbsp;";
                echo getLngt("H3:")  . "&nbsp;" . number_format($outGlobalStateArray["ati_data_09"], 2, ",", ".") . "&nbsp;€&nbsp;&nbsp;&nbsp;&nbsp;";
                $outGlobalSum = $outGlobalStateArray["ati_data_05"] + $outGlobalStateArray["ati_data_06"] + $outGlobalStateArray["ati_data_07"] + $outGlobalStateArray["ati_data_08"] + $outGlobalStateArray["ati_data_09"];
                echo getLngt("Summe:")  . "&nbsp;" . number_format( $outGlobalSum, 2, ",", ".") . "&nbsp;€";
                */
              ?>
            </div>
            <?php echo htmlDivLineSpacer("20px"); ?>
          </div>

          <!-- ******************************************************************************************** -->

          <!-- REPORT ENTRIES, SYSTEM MESSAGES -->
          <div id="maskDisplay00" name="maskDisplay00">
            <?php echo defineButtonType08("-", "action_reports", "changeHideShow('maskDisplay00','off');", "10", "left", "2") ?>
            <div class="f10bp1_red" style="float:left">
              <?php echo getLngt("SYSTEMMELDUNGEN:") ?>&nbsp;&nbsp;&nbsp;&nbsp;
            </div>
            <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
            <div id="maskDisplay00Content" name="maskDisplay00Content">
              <?php echo $outReport ?>
            </div>
            <?php echo htmlDivLineSpacer("20px"); ?>
          </div>

          <!-- THRESHOLD VALUES -->
          <div id="maskDisplay01" name="maskDisplay01">
            <?php echo defineButtonType08("-", "action_states", "changeHideShow('maskDisplay01','off');", "10", "left", "2") ?>
            <div class="f10bp1_blue" style="float:left">
              <?php echo getLngt("SCHWELLWERTE:") ?>&nbsp;&nbsp;&nbsp;&nbsp;
            </div>
            <?php echo defineButtonType08("Standardwerte setzen", "action_tv_default", "tvSetDefaults();", "150", "left", "2") ?>
            <?php echo defineButtonType08("Automatenzustände aktualisieren", "action_tv_reload", "finishPage('');", "200", "left", "2") ?>
            <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
            <div>
              <?php echo $outThresholdValues ?>
            </div>
            <?php echo htmlDivLineSpacer("20px"); ?>
          </div>

          <!-- CURRENT STATES OF SERVICE UNITS -->
          <div id="maskDisplay02" name="maskDisplay02">
            <?php echo defineButtonType08("-", "action_treshold", "changeHideShow('maskDisplay02','off');", "10", "left", "2") ?>
            <div class="f10bp1_blue" style="float:left">
              <?php echo getLngt("AUTOMATENZUSTÄNDE:") ?>&nbsp;&nbsp;&nbsp;&nbsp;
              <select name="f_su_sort_sequence" onChange="finishPage('');">
       	        <option value="0" <?php echo ($f_su_sort_sequence == "0" ? "selected" : ""); ?>><?php echo getLngt("Sortierung aufsteigend") ?></option>
       	        <option value="1" <?php echo ($f_su_sort_sequence == "1" ? "selected" : ""); ?>><?php echo getLngt("Sortierung absteigend") ?></option>
              </select>&nbsp;&nbsp;&nbsp;&nbsp;
              <!--
              <select name="f_pt_filter_1" onChange="preFinishPage('');">
       	        <option value="0" <?php echo ($f_pt_filter_1 == "0" ? "selected" : ""); ?>><?php echo getLngt("Alle Automaten") ?></option>
       	        <option value="1" <?php echo ($f_pt_filter_1 == "1" ? "selected" : ""); ?>><?php echo getLngt("Nur kritische Automaten") ?></option>
       	        <option value="2" <?php echo ($f_pt_filter_1 == "2" ? "selected" : ""); ?>><?php echo getLngt("Nur unkritische Automaten") ?></option>
              </select>&nbsp;&nbsp;&nbsp;&nbsp;
              -->
              <select name="f_pt_action_1" onChange="suCheckboxes();">
       	        <option value="0"><?php echo getLngt("AUSWAHLAKTIONEN:") ?></option>
       	        <option value="1"><?php echo getLngt("Ausschließlich alle kritischen auswählen") ?></option>
       	        <option value="2"><?php echo getLngt("Kritische der aktuellen Auswahl zufügen") ?></option>
       	        <option value="3"><?php echo getLngt("Alle auswählen") ?></option>
       	        <option value="4"><?php echo getLngt("Alle abwählen") ?></option>
       	        <option value="5"><?php echo getLngt("Auswahlzustand sichern") ?></option>
       	        <option value="6"><?php echo getLngt("Auswahlzustand laden") ?></option>
              </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            </div>
            <?php echo defineButtonType08("Optimierung starten", "action_opzimize", "suOptimize();", "150", "left", "2") ?>
            <?php echo defineButtonType08("Auftrag erzeugen", "action_makejob", "suMakeJob();", "150", "left", "2") ?>
            <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
            <div>
            	<?php echo $outEventStates ?>
            </div>
            <?php echo htmlDivLineSpacer("20px"); ?>
          </div>          

          <!-- SERVICE JOBS -->
          <div id="maskDisplay03" name="maskDisplay03">
            <?php echo defineButtonType08("-", "action_states", "changeHideShow('maskDisplay03','off');", "10", "left", "2") ?>
            <div class="f10bp1_blue" style="float:left">
              <?php echo getLngt("AUFTRÄGE:") ?>&nbsp;&nbsp;
              <?php 
                echo $jbDateFilter;
                // echo $jbTimeFilter;
              ?>
              <select name="f_jb_sort_sequence" onChange="finishPage('');">
       	          <option value="0" <?php echo ($f_jb_sort_sequence == "0" ? "selected" : ""); ?>><?php echo getLngt("Sortierung aufsteigend") ?></option>
       	          <option value="1" <?php echo ($f_jb_sort_sequence == "1" ? "selected" : ""); ?>><?php echo getLngt("Sortierung absteigend") ?></option>
              </select>&nbsp;&nbsp;
              <select name="f_jb_filter_1" onChange="preFinishPage('');">
       	        <option value="0" <?php echo ($f_jb_filter_1 == "0" ? "selected" : ""); ?>><?php echo getLngt("Alle Aufträge") ?></option>
       	        <option value="1" <?php echo ($f_jb_filter_1 == "1" ? "selected" : ""); ?>><?php echo getLngt("Laufende Aufträge") ?></option>
       	        <option value="2" <?php echo ($f_jb_filter_1 == "2" ? "selected" : ""); ?>><?php echo getLngt("Erledigte Aufträge") ?></option>
              </select>&nbsp;&nbsp;
              <select name="f_jb_filter_2" onChange="preFinishPage('');">
       	        <option value=""><?php echo getLngt("SERVICEEINHEITEN:") ?></option>
                <?php echo addOptionsFromTable("articleitem AS ati, stock AS stk","ati_serialno","ati_serialno","ati_serialno","ati.stk_id = stk.stk_id AND stk.stk_pre_id = '" . $rootStockSU . "' ",$f_jb_filter_2); ?>
              </select>&nbsp;&nbsp;
              <select name="f_jb_filter_3" onChange="preFinishPage('');">
       	        <option value=""><?php echo getLngt("STANDORTE:") ?></option>
                <?php echo addOptionsFromTable("stock","stk_name","stk_name","stk_name","stk_pre_id = '" . $rootStockSU . "' ",$f_jb_filter_3); ?>
              </select>&nbsp;&nbsp;
            </div>
            <?php echo htmlDivLineSpacer("15px", "", "left"); ?>
            <?php echo defineButtonType08("Aktualisieren", "action_jb_reload", "finishPage('');", "140", "left", "2") ?>
            <?php echo defineLinkButtonType08("Auftragslisten", "action_jb_list", "../admin/jb_list_fs.php?maskNumOfWins=" . $empMaskMultiJoblist, "140", "left", "2") ?>
            <?php echo htmlDivLineSpacer("15px", "", "left"); ?>
            <div>
              <?php echo $outServiceJobs ?>
            </div>
            <?php echo htmlDivLineSpacer("20px"); ?>
          </div>

          <!-- STATE LOG OF A SPECIFIED SERVICE UNIT -->
          <div id="maskDisplay04" name="maskDisplay04">
            <?php echo defineButtonType08("-", "action_log", "changeHideShow('maskDisplay04','off');", "10", "left", "2") ?>
            <div class="f10bp1_blue" style="float:left">
              <?php echo getLngt("ZUSTANDSVERLAUF:") ?>&nbsp;&nbsp;&nbsp;&nbsp;
              <select name="f_log_filter_1" onChange="finishPage('processAction');">
       	        <option value="0" <?php echo ($f_log_filter_1 == "0" ? "selected" : ""); ?>><?php echo getLngt("Alle Zustandsdatensätze") ?></option>
       	        <option value="1" <?php echo ($f_log_filter_1 == "1" ? "selected" : ""); ?>><?php echo getLngt("Kritische Zustandsdatensätze (mindestens ein Wert)") ?></option>
       	        <option value="2" <?php echo ($f_log_filter_1 == "2" ? "selected" : ""); ?>><?php echo getLngt("Unkritische Zustandsdatensätze (alle Werte)") ?></option>
              </select>&nbsp;&nbsp;&nbsp;&nbsp;
            </div>
            <?php echo defineButtonType08("Aktualisieren", "action_log_reload", "finishPage('processAction');", "140", "left", "2") ?>
            <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
            <div>
              <?php echo $outLogData ?>
            </div>
            <?php echo htmlDivLineSpacer("20px"); ?>
          </div>

          <!-- STATE LOG OF A SPECIFIED SERVICE UNIT -->
          <div id="maskDisplay05" name="maskDisplay05">
            <?php echo defineButtonType08("-", "action_log", "changeHideShow('maskDisplay05','off');", "10", "left", "2") ?>
            <div class="f10bp1_blue" style="float:left">
              <?php echo getLngt("BETRIEBSMELDUNGEN:") ?>&nbsp;&nbsp;&nbsp;&nbsp;
            </div>
            <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
            <div>
              <?php echo $outMessageData ?>
            </div>
            <?php echo htmlDivLineSpacer("20px"); ?>
          </div>

          <!-- FORM TO INSERT/EDIT A SERVICE UNIT -->
          <div id="maskDisplay06" name="maskDisplay06">
            <?php echo defineButtonType08("-", "action_log", "changeHideShow('maskDisplay06','off');", "10", "left", "2") ?>
            <div class="f10bp1_blue" style="float:left">
              <?php echo getLngt("VERWALTUNG:") ?>&nbsp;&nbsp;&nbsp;&nbsp;
              <select name="f_su_admin_filter_1" onChange="getServiceunitData('');">
       	        <option value=""><?php echo getLngt("SERVICEEINHEITEN:") ?></option>
                <?php echo addOptionsFromTable("articleitem AS ati, stock AS stk","ati_serialno","ati_serialno","ati_serialno","ati.stk_id = stk.stk_id AND stk.stk_pre_id = '" . $rootStockSU . "' ",$f_su_admin_filter_1); ?>
              </select>&nbsp;&nbsp;
              <select name="f_su_admin_stk_id" onChange="getStockData();">
       	        <option value=""><?php echo getLngt("STANDORTE:") ?></option>
                <?php echo addOptionsFromTable("stock","stk_id","stk_name","stk_name","stk_pre_id = '" . $rootStockSU . "' ",$f_su_admin_stk_id); ?>
              </select>&nbsp;&nbsp;
            </div>
            <?php // echo defineButtonType08("Automatendaten speichern", "action_store_form_serviceunit", "finishFormServiceUnit();", "200", "left", "2") ?>
            <?php // echo defineButtonType08("Standortdaten speichern", "action_store_form_stock", "finishFormStock();", "200", "left", "2") ?>
            <?php echo defineButtonType08("Zurücksetzen", "action_reset_form", "resetSuFormData();", "140", "left", "2") ?>
            <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
            <div>
              <?php echo $outSuFormData ?>
            </div>
            <?php echo htmlDivLineSpacer("20px"); ?>
          </div>

          <!-- ADMINISTRATION ... -->
          <!-- ... -->

        </td>       

    	  <td width="20">
    	  </td>
      </tr>
    </table>

  </div>   <!-- scrollcontainer -->
  

  <div id="actioncontainer" <?php echo $tmpDivPos ?>>
  	<input type="hidden" name="actionObjType" value="">
  	<input type="hidden" name="actionObjId" value="">
  	
  	<?php echo defineButtonType08("Schließen", "action_actioncontainer_close", "myhide('actioncontainer');", "100", "", "") ?>
  	<?php echo htmlDivLineSpacer("30px"); ?>
  	
  	<div style="float:left;width:40px;height:100%">
  		&nbsp;
    </div>
    <div>
  	  <div id="ac_title"></div>
  	  <?php echo htmlDivLineSpacer("20px"); ?>
  	  <div id="ac_01"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="ac_02"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="ac_03"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="ac_04"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="ac_05"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="ac_06"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="ac_07"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="ac_08"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	  <div id="ac_09"></div>
  	  <?php echo htmlDivLineSpacer("5px"); ?>
  	</div>
  </div>  
  
  </form>

</div>

</body>

</html>



<?php
/*

****************
* HOCHBAHN AG: *
****************

Special usage of the fields
Semantic of the data fields in table "articleitem"
ati_data_01 : Added informations to the stations
ati_data_02 : Latitude of the station
ati_data_03 : Longitude of the station
ati_data_04 : Timestamp of the persistent measured data
ati_data_05 : BEK
ati_data_06 : MEK
ati_data_07 : Hopper 1
ati_data_08 : Hopper 2
ati_data_09 : Hopper 3
ati_data_10 : RSG (10)
ati_data_11 : RSG (11)
ati_data_12 : RSG (12)
ati_data_13 : RSG (13)
ati_data_14 : RSG (14)
ati_data_15 : RSG (15)
ati_data_16 : Priorities (presently not needed)
ati_data_17 : Persistent state of the message code(s)
ati_data_18 : Persistent state of probabilities regarding to the service intervals
ati_data_19 : Persistent state of optimized locations
ati_data_20 : Persistent state of selected checkboxes
ati_data_21 : Preselection for the number of the tour for each day of the week ("1" = Tour #1, "2" = Tour #2, ...)
ati_data_22 : 
ati_data_23 : 
ati_data_24 : 
ati_data_25 : 

INSERT INTO parameter (par_key, hq_id, emp_id, par_value, par_text) VALUES ('MASK_SU_TV_01', 1, 0, '900', NULL);
INSERT INTO parameter (par_key, hq_id, emp_id, par_value, par_text) VALUES ('MASK_SU_TV_02', 1, 0, '1800', NULL);
INSERT INTO parameter (par_key, hq_id, emp_id, par_value, par_text) VALUES ('MASK_SU_TV_03', 1, 0, '2250', NULL);
INSERT INTO parameter (par_key, hq_id, emp_id, par_value, par_text) VALUES ('MASK_SU_TV_04', 1, 0, '4500', NULL);
INSERT INTO parameter (par_key, hq_id, emp_id, par_value, par_text) VALUES ('MASK_SU_TV_05', 1, 0, '50', NULL);
INSERT INTO parameter (par_key, hq_id, emp_id, par_value, par_text) VALUES ('MASK_SU_TV_06', 1, 0, '25', NULL);
INSERT INTO parameter (par_key, hq_id, emp_id, par_value, par_text) VALUES ('MASK_SU_TV_07', 1, 0, '25', NULL);

*/
?>