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

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

$autoMode = false;
if (!isset($argv[1]) || $argv[1] == "") :
   $isCron = false;
   include_once ("../include/auth.inc.php");

   getSecHttpVars("1",array("f_act", "customerId", "cscIdRoot", "cscIdActual", "requestMode",
                            "day_from", "month_from", "year_from", "day_to", "month_to", "year_to", 
                            "g_cs_eid", "g_csc_id", "g_cr_id", "g_cr_eid",
                            "f_hq_id", "f_text", "f_sort", "f_stat_export", "f_ftp_upload", "deactivateMenu"));

   $autoMode = true;
   $usrAccessArray["hq"] = "1";
   // $usrAccessArray["cs"] = "1";
   // $usrAccessArray["cr"] = "1";
   authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
else :
   // Error reporting
   // error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
   error_reporting(0);

   // Init parameters
   $f_act = ""; $hq_id = ""; $requestMode = ""; $date_from = ""; $date_to = ""; $f_sort = ""; $f_stat_export = ""; $f_ftp_upload = "";
   
   // Call e.g.
   // php export_illt.php acapella7890 execute 1 101 20190901000000 20190930235959 0 1 HHA SFTP
   
   $isCron = true;
   if ($argv[1] == "acapella7890") : $autoMode = true; endif;
   if ($autoMode) :
      if (isset($argv[2]) && $argv[2] != "")   : $f_act         = $argv[2]; endif;
      if (isset($argv[3]) && $argv[3] != "")   : $hq_id         = $argv[3]; endif;
      if (isset($argv[4]) && $argv[4] != "")   : $requestMode   = $argv[4]; endif;
      if (isset($argv[5]) && $argv[5] != "")   : $date_from     = $argv[5]; endif;
      if (isset($argv[6]) && $argv[6] != "")   : $date_to       = $argv[6]; endif;
      if (isset($argv[7]) && $argv[7] != "")   : $f_sort        = $argv[7]; endif;
      if (isset($argv[8]) && $argv[8] != "")   : $f_stat_export = $argv[8]; endif;
      if (isset($argv[9]) && $argv[9] != "")   : $f_ftp_upload  = $argv[9]; endif;
      if (isset($argv[9]) && $argv[10] != "")  : $sendMode      = $argv[10]; endif;
   endif;

   $year_from  = substr($date_from, 0, 4);
   $month_from = substr($date_from, 4, 2);
   $day_from   = substr($date_from, 6, 2);
   $year_to    = substr($date_to, 0, 4);
   $month_to   = substr($date_to, 4, 2);
   $day_to     = substr($date_to, 6, 2);
endif;

include_once ("../statistic/statistic_sql.inc.php");
include_once ("../include/inc_calendar.inc.php");
include_once ("../include/ftp.inc.php");

// Execution-Time for script
set_time_limit(300);

$deactivateMenuStatic = "1";

getLanguage(__FILE__);

// HASH folder
$hashFolder = "8384739274093038263748";
$secondsForUnlink = 60;
if ($isCron) :
   $hashFolder = "7384739274093038263748";
   $secondsForUnlink = 864000;
endif;

// Log file
$logFile = getParameterValue("0", "ILLT_EXPORT_LOGFILE", "0");
if ($logFile == "") :
   $logFile = getParameterValue("0", "AUTO_EXPORT_LOGFILE", "0");
   if ($logFile == "") : $logFile = "../log/auto_export.log"; endif;
endif;

// Send mode
if ($sendMode == "") : $sendMode = "SFTP"; endif;

$debug = false;
$debugLog = false;
if ($isCron) :
   $debug = false;
   $debugLog = true;
endif;
if ($debug) :
   echo "isCron = " . $isCron . "<br>";
   echo "hashFolder = " . $hashFolder . "<br>";
   echo "f_act = " . $f_act . "<br>";
   echo "requestMode = " . $requestMode . "<br>";
   echo "f_sort = " . $f_sort . "<br>";
   echo "f_stat_export = " . $f_stat_export . "<br>";
   echo "day_from = " . $day_from . "<br>";
   echo "month_from = " . $month_from . "<br>";
   echo "year_from = " . $year_from . "<br>";
   echo "day_to = " . $day_to . "<br>";
   echo "month_to = " . $month_to . "<br>";
   echo "year_to = " . $year_to . "<br>";
endif;
if ($debugLog) :
   writeToFile($logFile, $currentTime . " ----------------------------------------------------------------------------------- ");
   writeToFile($logFile, $currentTime . " - " . "isCron = " . $isCron);
   writeToFile($logFile, $currentTime . " - " . "hashFolder = " . $hashFolder);
   writeToFile($logFile, $currentTime . " - " . "f_act = " . $f_act);
   writeToFile($logFile, $currentTime . " - " . "requestMode = " . $requestMode);
   writeToFile($logFile, $currentTime . " - " . "f_sort = " . $f_sort);
   writeToFile($logFile, $currentTime . " - " . "f_stat_export = " . $f_stat_export);
   writeToFile($logFile, $currentTime . " - " . "day_from = " . $day_from);
   writeToFile($logFile, $currentTime . " - " . "month_from = " . $month_from);
   writeToFile($logFile, $currentTime . " - " . "year_from = " . $year_from);
   writeToFile($logFile, $currentTime . " - " . "day_to = " . $day_to);
   writeToFile($logFile, $currentTime . " - " . "month_to = " . $month_to);
   writeToFile($logFile, $currentTime . " - " . "year_to = " . $year_to);
endif;

$pageTitel = getLngt("AUFSTELLUNGEN");
$authCheck = FALSE;
$maxLimitOfRowsDisplayed = 1000;

$currentTime = getDateTime("0");
$currentDate = getDateTime("3");
$currentMonth = getDateTime("month");

if ($requestMode == "101") :
   $pageTitel = getLngt("GELDBETRAGSHISTORIE");
   if ($isCron) :
      $authCheck = TRUE;
   else :
      $authCheck = authCheckEmployeeRights($emp_id, "0");
   endif;

   // Parameters
   $limitOfRowsDisplayed = getParameterValue("0", "MASK_STAT_ILLT_ROWS_DISPLAYED_101", "0");    // For limitation of the rows displayed
   if ($limitOfRowsDisplayed == "" || !is_numeric($limitOfRowsDisplayed)) : $limitOfRowsDisplayed = getParameterValue("0", "MASK_STAT_ILLT_ROWS_DISPLAYED", "0"); endif;
   if ($limitOfRowsDisplayed == "" || !is_numeric($limitOfRowsDisplayed)) : $limitOfRowsDisplayed = 10000; endif;

   // Get the cs_id if "g_cs_eid" does exist
   if ($g_cs_eid != "") : 
      $cs_id = getFieldValueFromId("customer", "cs_eid", $g_cs_eid, "cs_id");
   elseif ($g_csc_id != "") :
      $cs_id = getFieldValueFromId("costcenter", "csc_id", $g_csc_id, "cs_id");
      $g_cs_eid = getFieldValueFromId("customer", "cs_id", $cs_id, "cs_eid");
   endif;

   // Statistic values of the customer
   /*
   if ($cs_id != "") :
      // Statistic business volume from 01.01. of the current year to the current day
      $tmpFromDate = getDateTime("year") . "-01-01";
      $tmpToDate = getDateTime("3");
      $statisticValueCurrentYear = getCsStatistic ($rpObjId, $tmpFromDate, $tmpToDate);

      // Year before in the same interval
      $tmpFromDate = getDateTime("lastyear") . "-01-01";
      $tmpToDate = getDateTime("date_lastyear");
      $statisticValueLastYear = getCsStatistic ($rpObjId, $tmpFromDate, $tmpToDate);
      
      // Year before complete
      $tmpFromDate = getDateTime("lastyear") . "-01-01";
      $tmpToDate = getDateTime("lastyear") . "-12-31";
      $statisticValueLastYearComplete = getCsStatistic ($rpObjId, $tmpFromDate, $tmpToDate);
   endif;
   */

   if ($month_from == "" || $year_from == "") :
      $month_from = getDateTime("month");
      $year_from = getDateTime("year");
   endif;
      
   if ($year_from == "" || $month_from == "" || $day_from == "" || $year_to == "" || $month_to == "" || $day_to == "") : 
      // Default monthly like frontend
      $fromDateRange = $year_from . "-" . pad($month_from,2) . "-" . "01";
      $toDateRange = $year_from . "-" . pad($month_from,2) . "-" . $calMonthDays[($month_from - 1)];
   else :
      $fromDateRange = $year_from . "-" . pad($month_from,2) . "-" . pad($day_from,2);
      $toDateRange = $year_to . "-" . pad($month_to,2) . "-" . pad($day_to,2);
   endif;
   
   
elseif ($requestMode == "102") :

   $pageTitel = getLngt("KASSETTENBEWEGUNGEN");
   if ($isCron) :
      $authCheck = TRUE;
   else :
      $authCheck = authCheckEmployeeRights($emp_id, "0");
   endif;

   // Parameters
   $limitOfRowsDisplayed = getParameterValue("0", "MASK_STAT_ILLT_ROWS_DISPLAYED_102", "0");    // For limitation of the rows displayed
   if ($limitOfRowsDisplayed == "" || !is_numeric($limitOfRowsDisplayed)) : $limitOfRowsDisplayed = 10000; endif;
   
   if ($month_from == "" || $year_from == "") :
      $month_from = getDateTime("month");
      $year_from = getDateTime("year");
   endif;
   
   if ($year_from == "" || $month_from == "" || $day_from == "" || $year_to == "" || $month_to == "" || $day_to == "") : 
      // Default monthly like frontend
      $fromDateRange = $year_from . "-" . pad($month_from,2) . "-" . "01";
      $toDateRange = $year_from . "-" . pad($month_from,2) . "-" . $calMonthDays[($month_from - 1)];
   else :
      $fromDateRange = $year_from . "-" . pad($month_from,2) . "-" . pad($day_from,2);
      $toDateRange = $year_to . "-" . pad($month_to,2) . "-" . pad($day_to,2);
   endif;

elseif ($requestMode == "103") :

   $pageTitel = getLngt("ALARMSTATUS");
   if ($isCron) :
      $authCheck = TRUE;
   else :
      $authCheck = authCheckEmployeeRights($emp_id, "0");
   endif;

   // Parameters
   $limitOfRowsDisplayed = getParameterValue("0", "MASK_STAT_ILLT_ROWS_DISPLAYED_103", "0");    // For limitation of the rows displayed
   if ($limitOfRowsDisplayed == "" || !is_numeric($limitOfRowsDisplayed)) : $limitOfRowsDisplayed = 10000; endif;
   
   if ($month_from == "" || $year_from == "") :
      $month_from = getDateTime("month");
      $year_from = getDateTime("year");
   endif;

   if ($year_from == "" || $month_from == "" || $day_from == "" || $year_to == "" || $month_to == "" || $day_to == "") : 
      // Default monthly like frontend
      $fromDateRange = $year_from . "-" . pad($month_from,2) . "-" . "01";
      $toDateRange = $year_from . "-" . pad($month_from,2) . "-" . $calMonthDays[($month_from - 1)];
   else :
      $fromDateRange = $year_from . "-" . pad($month_from,2) . "-" . pad($day_from,2);
      $toDateRange = $year_to . "-" . pad($month_to,2) . "-" . pad($day_to,2);
   endif;

elseif ($requestMode == "104") :

   $pageTitel = getLngt("Abgeholte Kassetten");
   if ($isCron) :
      $authCheck = TRUE;
   else :
      $authCheck = authCheckEmployeeRights($emp_id, "0");
   endif;

   // Parameters
   $limitOfRowsDisplayed = getParameterValue("0", "MASK_STAT_ILLT_ROWS_DISPLAYED_104", "0");    // For limitation of the rows displayed
   if ($limitOfRowsDisplayed == "" || !is_numeric($limitOfRowsDisplayed)) : $limitOfRowsDisplayed = 10000; endif;

   if ($year_from == "" || $month_from == "" || $day_from == "") :
      $day_from = getDateTime("day");
      $month_from = getDateTime("month");
      $year_from = getDateTime("year");
   endif;

   if ($year_from == "" || $month_from == "" || $day_from == "" || $year_to == "" || $month_to == "" || $day_to == "") : 
      // Default monthly like frontend
      $fromDateRange = $year_from . "-" . pad($month_from,2) . "-" . "01";
      $toDateRange = $year_from . "-" . pad($month_from,2) . "-" . $calMonthDays[($month_from - 1)];
   else :
      $fromDateRange = $year_from . "-" . pad($month_from,2) . "-" . pad($day_from,2);
      $toDateRange = $year_to . "-" . pad($month_to,2) . "-" . pad($day_to,2);
   endif;

elseif ($requestMode == "105") :

   // .............
   
elseif ($requestMode == "199") :

   // .............

else :

   if ($day_from == "" || $month_from == "" || $year_from == "" || 
       $day_to == "" || $month_to == "" || $year_to == "") :

       if ($currentMonth >= 7) :
          $fromDateRange = getDateTime("year") . "-07-01";
       else :
          $fromDateRange = getDateTime("year") . "-01-01";
       endif;
       $toDateRange = $currentDate;

       $day_from = getDateTime("day");
       $month_from = getDateTime("month");       
       $year_from = getDateTime("year");
       $day_to = getDateTime("day");
       $month_to = getDateTime("month");
       $year_to = getDateTime("year");
   else :
       $fromDateRange = $year_from . "-" . pad($month_from,2) . "-" . pad($day_from,2);
       $toDateRange = $year_to . "-" . pad($month_to,2) . "-" . pad($day_to,2);
   endif;
endif;
// $fromDateRange .= " 00:00:00";
// $toDateRange .= " 23:59:59";

if (!$isCron) :
   include ("../admin/menu.php");
endif;
include_once ("../include/html.inc.php");
include_once ("../include/inc_stock.inc.php");

getCurrentScript(__FILE__);

// if (!$isCron && (!$authCheck || !authCheckEmployeeRights($emp_id, "16"))) : gotoReferer("1"); endif;


// Mandator filter (related here to the USER !!!)
if ($f_hq_id == "") : $f_hq_id = array(); endif;
if (count($f_hq_id) == 0) : array_push($f_hq_id, $hq_id); endif;
if ($f_sort == "") : $f_sort = "0"; endif;                                   // ORDER BY column "$fieldArray[$f_sort]"
if ($limitOfRowsDisplayed == "") : $limitOfRowsDisplayed = $maxLimitOfRowsDisplayed; endif;
$f_text = trim($f_text);                                                     // Text of an entry
$output = "";

// Export report statistic data as CSV file
if ($f_stat_export == "" || count($f_stat_export) == 0) : $f_stat_export = false; else: $f_stat_export = true; endif;

// Get the array for formatting the database-values for the output according to the defined type
$outputFormatField = defineOutputFormats();

if ($debug) :
   echo "fromDateRange = " . $fromDateRange . "<br>";
   echo "toDateRange = " . $toDateRange . "<br>";
endif;
if ($debugLog) :
   writeToFile($logFile, $currentTime . " - " . "fromDateRange = " . $fromDateRange);
   writeToFile($logFile, $currentTime . " - " . "toDateRange = " . $toDateRange);
endif;

if ($f_act == "execute" && $requestMode != "") :

   $f_act = "";  // Init
   $orderByClause = "";
   
   if ($requestMode == "101") :

      // Generate list with header
      $titleArray = array(getLngt("Serienr."),getLngt("Datum"),getLngt("BEK"),getLngt("MEK"),getLngt("H1"),getLngt("H2"),getLngt("H3"));
      $fieldArray = array("atih_serialno","atih_data_04","atih_data_05","atih_data_06","atih_data_07","atih_data_08","atih_data_09");
      $aligns = "l,l,r,r,r,r,r";
      $widths = "120,100,80,80,80,80,80";

      if ($f_sort != "" && is_numeric($f_sort)) :
         $orderByClause = "atih." . $fieldArray[$f_sort];
         if ($orderByClause == "atih.atih_serialno") :
            $orderByClause .= ", LEFT(atih.atih_data_04,10) ";
         endif;
      endif;
      if ($orderByClause == "") :
         $orderByClause = " atih.atih_serialno, LEFT(atih.atih_data_04,10) ";
      endif;
      
      // Automatendaten
      // $sqlquery = "SELECT CONCAT(atih.atih_serialno,';',LEFT(atih.atih_data_04,10),';',atih.atih_data_05,';',atih.atih_data_06,';',atih.atih_data_07,';',atih.atih_data_08,';',atih.atih_data_09)"
      $sqlquery = "SELECT atih.atih_serialno, LEFT(atih.atih_data_04,10) AS atih_data_04, atih.atih_data_05, atih.atih_data_06, atih.atih_data_07, atih.atih_data_08, atih.atih_data_09"
                . "  FROM"
                . "    phoenix_log.articleitemhistory AS atih,"
                . "    phoenix.article AS at"
                . "  WHERE "
                . "    LEFT(atih.atih_data_04,10) >= '" . $fromDateRange . "' AND"
                . "    LEFT(atih.atih_data_04,10) <= '" . $toDateRange . "' AND"
                . "    atih.at_id = at.at_id AND"
                . "    at.at_group LIKE '%,1,%'"
                . " ORDER BY " . $orderByClause
                . (!$f_stat_export ? " LIMIT 0," . $limitOfRowsDisplayed : "");

   elseif ($requestMode == "102") :

      // Generate list with header
      $titleArray = array(getLngt("Lfd."),getLngt("Datum"),getLngt("Serienr."),getLngt("Typ"),getLngt("Quelle"),getLngt("Ziel"),getLngt("Zusatz"));
      $fieldArray = array("stkmv_id","stkmv_datetime","stkmv_serialno","at_match","stk_name_from","stk_name_to","stkmv_tan");
      $aligns = "r,c,l,l,l,l,l";
      $widths = "40,100,80,40,150,150,150";

      $whereClause = " LEFT(stkmv.stkmv_datetime,10) >= '" . $fromDateRange . "' AND"
                   . " LEFT(stkmv.stkmv_datetime,10) <= '" . $toDateRange . "'";

      if ($f_sort != "" && is_numeric($f_sort)) :
         $orderByClause = $fieldArray[$f_sort];
      endif;
      if ($orderByClause == "") :
         $orderByClause = " stkmv.stkmv_id ";
      endif;

      $sqlquery = getStmtStockJournal($whereClause, $orderByClause, $limitOfRowsDisplayed);

   elseif ($requestMode == "103") :

      $postParserField  = "usr_id_kill";
      $postParserField2 = "utc_kill";
      $postParserField3 = "calling_usr_id";

      // Generate list with header
      $titleArray = array(getLngt("Zeitpunkt"),getLngt("Auslöst durch"),getLngt("Fahrzeug"),getLngt("Beendendet durch"),getLngt("Beendigungszeit"));
      $fieldArray = array("bo_createtime", $postParserField3, "usr_name", $postParserField, $postParserField2);
      $aligns = "l,l,l,l,l";
      $widths = "100,120,120,120,100";

      if ($f_sort != "" && is_numeric($f_sort)) :
         $orderByClause = "b2b." . $fieldArray[$f_sort];
         if ($orderByClause == "usr.usr_firstname" || $orderByClause == "usr.usr_name" || $orderByClause == "crvh.crvh_vh_sign") :
            $orderByClause .= ", LEFT(b2b.bo_createtime,10) ";
         endif;
      endif;
      if ($orderByClause == "") :
         $orderByClause = " b2b.bo_createtime ";
      endif;

      // Alarmdaten
      $sqlquery = "SELECT b2b.bo_createtime, usr.usr_firstname, usr.usr_name, crvh.crvh_vh_sign, b2b.bo_obj_data AS " . $postParserField 
                . ", b2b.bo_obj_data AS " . $postParserField2 . ", b2b.bo_obj_data AS " . $postParserField3
                . "  FROM"
                . "    phoenix_log.b2b_objects AS b2b,"
                . "    phoenix.courier AS cr,"
                . "    phoenix.couriervehicle AS crvh,"
                . "    phoenix.user AS usr"
                . "  WHERE "
                . "    bo_ext_id1 = cr.usr_id AND"
                . "    cr.cr_id = crvh.cr_id AND"
                . "    cr.usr_id = usr.usr_id AND"
                . "    bo_type = 333 AND"
                . "    LEFT(b2b.bo_createtime,10) >= '" . $fromDateRange . "' AND"
                . "    LEFT(b2b.bo_createtime,10) <= '" . $toDateRange . "'"
                . " ORDER BY " . $orderByClause
                . (!$f_stat_export ? " LIMIT 0," . $limitOfRowsDisplayed : "");

   elseif ($requestMode == "104") :

      // Generate list with header
      $titleArray = array(getLngt("Fahrzeug"),getLngt("Automatennummer"),getLngt("Standort"),getLngt("Kassettencode"),getLngt("Betrag"),getLngt("Belegdatum"),getLngt("Belegzeit"),getLngt("Annahmezeit"));

      // Abgeholte Kassetten
      $sqlquery = "SELECT  b2b.bo_id, b2b.bo_createtime, b2b.bo_obj_data, usr.usr_firstname, usr.usr_name"
                . "  FROM"
                . "    phoenix_log.b2b_objects AS b2b,"
                . "    phoenix.courier AS cr,"        
                . "    phoenix.user AS usr"
                . "  WHERE "
                . "    bo_ext_id1 = cr.cr_id  AND"
                . "    cr.usr_id = usr.usr_id AND"
                . "    bo_type IN (221,222)   AND"
                . "    LEFT(b2b.bo_createtime,10) >= '" . $fromDateRange . "' AND"
                . "    LEFT(b2b.bo_createtime,10) <= '" . $toDateRange . "'"
                . " ORDER BY bo_id"
                . (!$f_stat_export ? " LIMIT 0," . $limitOfRowsDisplayed : "");

   endif;

// echo $sqlquery . "<br>";
   $result = $db->query($sqlquery);
   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());

   // Special output for some categories or generic output per standard list by default
   if ($requestMode == "104") :

      $csvHeader = implode(",", $titleArray);
      $csvHeaderLen = strlen($csvHeader);
      $csvData = "";
      $outputLinesArray = array();
      $outputLinesArray[] = $csvHeader;
      while ($row = $result->fetch_assoc()):   
            $boId          = $row["bo_id"];
            $boCreatetime  = $row["bo_createtime"];
            $usrFirstname  = $row["usr_firstname"];
            $usrName       = $row["usr_name"];
            $boObjData     = $row["bo_obj_data"];
            // Remove headline from DB content in "bo_obj_data"
            $boObjData = substr($boObjData, $csvHeaderLen + 1);
            $outputLinesArray[] = $boObjData;
            // Aggregate contents in "bo_obj_data"
            $csvData .= $boObjData . "\n";
      endwhile;
      $csvData = $csvHeader . "\n" . $csvData;
      $csvDataOutHTML = str_replace("\n", "<br>", $csvData);
      $output = $csvDataOutHTML;

   else :
      // DEFAULT OUTPUT STANDARD LIST
      $alignArray = explode(",",$aligns);
      $alignTitles = "center";   
      $widthArray = explode(",",$widths);
      $summationField = "";
      $mode = "1";             // Output from DB-RESULT
      $fieldSortArray = $fieldArray;
      $sortDBField = "YES";    // Used in following include-file for sorting per column;
      // $javaScriptFunctionNameForSort = "finishPageStatisticIlltSort";
      $javaScriptFunctionNameForSort = "";
      if (!$f_stat_export) :
         include ("../include/inc_list_defineoutput.inc.php");
         // Post parsing if necessary
         if ($postParserField != "") :
            $tableBody = postParseExport($tableBody, $postParserField);
         endif;
         if ($postParserField2 != "") :
            $tableBody = postParseExport($tableBody, $postParserField2, "postparser2");
         endif;
         if ($postParserField3 != "") :
            $tableBody = postParseExport($tableBody, $postParserField3, "postparser3");
         endif;
         $output = $tableHeader . $tableBody;
      else :
         $output = "<tr><td>" . getLngt("Keine Bildschirmausgabe bei Download!") . "</td></tr>";
      endif;
      $result->free();
      $sortDBField = "YES";                  // Reset
      $javaScriptFunctionNameForSort = "";   // Reset
      // Define output table   
      $tableHeader = "";
      $tableBody = "";
   endif;

   // *** File output ***
   if ($f_stat_export) :
      // Remove old files
      foreach (glob("../export/download/" . $hashFolder . "/*.illt_exp_" . $requestMode . ".csv") as $fileNameToBoRemoved) {
      	  // Check for older than 10 days
          if ((time() - filemtime($fileNameToBoRemoved)) > $secondsForUnlink) :
             if (file_exists($fileNameToBoRemoved)) :
                unlink($fileNameToBoRemoved);
             endif;
          endif;
      }
      $f_secretFileName = "";
      // 2nd request for file output
      $result = $db->query($sqlquery);
      if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
      
      // Special FILE output for some categories or generic output per standard list by default
      if ($requestMode == "104") :

          
      else:      
         // Define output parameters
         $delimiter = ';';
         $writeHeader = "YES";
         $mode = "1";
         include_once ("../include/inc_list_defineoutput2file.inc.php");                    
      endif;

      $outputLinesArrayLen = count($outputLinesArray);
      if ($outputLinesArrayLen > 0) :
         if ($filename == "") : $filename = $pageTitel; endif;
         // $f_fileName = $filename . "_" . date("YmdHis");
         $f_fileName = $filename . "_" . date("Ymd");
         $f_secretFileName = $f_fileName . ".illt_exp_" . $requestMode . ".csv";
         // Current file to be written
         $currFilename = "../export/download/" . $hashFolder . "/" . $f_secretFileName;
         // If file does exist then remove it for the following rewrite process
         if (file_exists($currFilename)) :
            unlink($currFilename);
         endif;
         // Write (new) file
         if ($outputHeader != "") :
            writeToFile($currFilename, $outputHeader);   // write header if requested
         endif;
         for ($i = 0; $i < $outputLinesArrayLen; $i++) :
             // Post parsing if necessary
             if ($postParserField != "") :
                $outputLinesArray[$i] = postParseExport($outputLinesArray[$i], $postParserField);
             endif;
             if ($postParserField2 != "") :
                $outputLinesArray[$i] = postParseExport($outputLinesArray[$i], $postParserField2, "postparser2");
             endif;
             if ($postParserField3 != "") :
                $outputLinesArray[$i] = postParseExport($outputLinesArray[$i], $postParserField3, "postparser3");
             endif;
             writeToFile($currFilename, $outputLinesArray[$i]);   // write statistic data
         endfor;

         if ($f_ftp_upload != "" && $hq_id != "" && is_numeric($hq_id)) :

            if ($sendMode == "SFTP" || $sendMode == "FTP") :

               $ftp_server    = getParameterValue("0", "FTP_SERVER_HHA", $hq_id);
               $localPath     = getParameterValue("0", "FTP_LOCALPATH_HHA", $hq_id);
               $remotePath    = getParameterValue("0", "FTP_REMOTEPATH_HHA", $hq_id);
               $ftp_user_name = getParameterValue("0", "FTP_USER_HHA", $hq_id);
               $ftp_user_pass = getParameterValue("0", "FTP_PASSWORD_HHA", $hq_id);
            
               if ($ftp_server != "" && $localPath != "" && $remotePath != "" && $ftp_user_name != "" && $ftp_user_pass != "")  :
                  // Check remote existence of current file to be uploaded. If does exist then do NOT execute upload !!!!
                  $continue = true;
                  $f_ftp_ssl = "0";
                  if ($sendMode == "SFTP") : $f_ftp_ssl = "2"; endif;
                  $tmpArray = ftpDir($ftp_server, $ftp_user_name, $ftp_user_pass, $remotePath, "", $f_ftp_ssl);
                  $fileNamesRemote = $tmpArray[0];
                  $tmpErrNo = $tmpArray[1];
                  $tmpErrDesc = $tmpArray[2];
                  $fileNamesRemoteLen = count($fileNamesRemote);
                  for ($j = 0; $j < $fileNamesRemoteLen; $j++) :
                      if ($fileNamesRemote[$j] == $f_secretFileName) :
                         $continue = false;
                         writeToFile($logFile, $currentTime . " - ERR: EXPORT ABORTED! REMOTE DATA STILL EXIST!" . " " . $f_secretFileName);
                         writeToFile($logFile, "-------------------------------------------------------------------------------------------------------------------");
                         if ($debug) : echo "EXPORT ABORTED! REMOTE DATA STILL EXIST! \n\r"; endif;
                         break 1;
                      endif;
                  endfor;
                  
                  if ($continue)  :
                     $opArray = ftpUpload($f_secretFileName, $f_secretFileName, $ftp_server, $ftp_user_name, $ftp_user_pass, $localPath, $remotePath, $f_ftp_ssl);

                     if ($opArray[0] != "0") :
                        $statusMessage = getLngt("Die Datei konnte nicht hochgeladen werden. Ein Upload-Fehler ist aufgetreten!") . " [" . $f_secretFileName . "] [" . $opArray[0] . " : " . $opArray[1] . "]";
                        sendInternalMail($statusMessage);
                        if ($debug) : echo "ERROR! " . $opArray[0] . " : " . $opArray[1] . $br . " \n\r"; endif;
                     endif;
                  endif;
               else :
                  $statusMessage = getLngt("Die Datei konnte nicht hochgeladen werden. Der FTP-Modus wurde nicht festgelgt!") . " [" . $f_secretFileName . "]";
               endif;
            else :
               $statusMessage = getLngt("Die Datei konnte nicht hochgeladen werden. Die Verbindungsparameter unvollständig sind!") . " [" . $f_secretFileName . "]";
            endif;
         endif;
      else :
         $statusMessage = getLngt("Es wurden keine Daten gefunden! Eine Datei wurde deshalb nicht generiert!");
         $f_stat_export = false;
      endif;
   endif;
endif;


function postParseExport ($textToParse, $postParserField, $parseTag = "") {
	global $emp_id, $usr_id, $rpObjId, $reportTypeArray;
  $textToParse = trim($textToParse);
  if ($parseTag == "") : $parseTag = "postparser"; endif;
  $parseTagLen = strlen($parseTag) + 2;  // Add 2 signs "<" and ">"

  if ($textToParse != "") :
     $count = 1;

     // Iterate ALL occurrences of "<postparser>...</postparser>"          
     while (!(strpos($textToParse, "<" . $parseTag . ">") === FALSE)) {

        $beginTagPosBegin = strpos($textToParse, "<" . $parseTag . ">");
        $beginTagPosEnd = $beginTagPosBegin + $parseTagLen;
        $endTagPosBegin = strpos($textToParse, "</" . $parseTag . ">");
        $endTagPosEnd = $endTagPosBegin + $parseTagLen + 1;

        if ($beginTagPosEnd < $endTagPosBegin) :

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

           if ($postParserField == "usr_id_kill") :
              $tagContentArray = getKeyValueArrayFromString($tagContent, "|", "=");
              $usrName = getFieldValueFromId("user", "usr_id", $tagContentArray["usr_id_kill"], "usr_name");
              $usrFirstname = getFieldValueFromId("user", "usr_id", $tagContentArray["usr_id_kill"], "usr_firstname");
              $tagContent = $usrName . ($usrFirstname != "" ? ", " : " ") . $usrFirstname;
           endif;
           if ($postParserField == "utc_kill") :
              $tagContentArray = getKeyValueArrayFromString($tagContent, "|", "=");
              // $utcKillDatetime = gmdate($tagContentArray["utc_kill"] . ' UTC');
              $killdatetime = gmdate("Y-m-d H:i:s", $tagContentArray["utc_kill"]);
              $tagContent = $killdatetime;
           endif;
           if ($postParserField == "imei") :
              $tagContentArray = getKeyValueArrayFromString($tagContent, "|", "=");
              $tagContent = $tagContentArray["imei"];
           endif;
           if ($postParserField == "calling_usr_id") :
              $tagContentArray = getKeyValueArrayFromString($tagContent, "|", "=");
              $usrName = getFieldValueFromId("user", "usr_id", $tagContentArray["calling_usr_id"], "usr_name");
              $usrFirstname = getFieldValueFromId("user", "usr_id", $tagContentArray["calling_usr_id"], "usr_firstname");
              $tagContent = $usrName . ($usrFirstname != "" ? ", " : " ") . $usrFirstname;
           endif;

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

$contentFrame = "";
$filter_dateranges = "";
$js_date = "";

// Date-ranges 
if ($requestMode == "101" || $requestMode == "102" || $requestMode == "103") :

   $filter_dateranges .= "<td>" . getLngt("Monat / Jahr:") . "\n";
   $filter_dateranges .= "<select name=\"month_from\" class=\"f8np1\">" . addOptionsFromRange("1", "12", pad($month_from,2), "", "2", "0") . "</select>\n";
   $filter_dateranges .= "<select name=\"year_from\" class=\"f8np1\">" . addOptionsFromRange((getDateTime("year") - 3), getDateTime("year"), $year_from) . "</select>\n";

   // Javascript-function as template only for
   $js_date .= "<script type=\"text/javascript\">\n";
   $js_date .= "<!--\n";
   $js_date .= "function initForm() { }\n";
   $js_date .= "-->\n";
   $js_date .= "</script>\n";


elseif ($requestMode == "199") :

   // $filter_dateranges .= "<td>" . getLngt("von:") . "\n";
   $filter_dateranges .= "<select name=\"day_from\" class=\"f8np1\" onchange=\"javascript:serviceFinishPage('');\"></select>\n";
   $filter_dateranges .= "<select name=\"month_from\" class=\"f8np1\" onchange=\"javascript:serviceFinishPage('');\"></select>\n";
   $filter_dateranges .= "<select name=\"year_from\" class=\"f8np1\" onchange=\"javascript:serviceFinishPage('');\"></select>\n";
   /*
   $filter_dateranges .= "<select name=\"day_from\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $currentFrameName . "', 'history', 'day_from', 'day_from', 'month_from', 'year_from', '', '', '')\"></select>\n";
   $filter_dateranges .= "<select name=\"month_from\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $currentFrameName . "', 'history', 'month_from', 'day_from', 'month_from', 'year_from', '', '', '')\"></select>\n";
   $filter_dateranges .= "<select name=\"year_from\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $currentFrameName . "', 'history', 'year_from', 'day_from', 'month_from', 'year_from', '', '', '')\"></select>\n";
   $filter_dateranges .= "</td>";
   $filter_dateranges .= "<td>";
   $filter_dateranges .= "&nbsp;&nbsp;" . getLngt("bis:") . "\n";
   $filter_dateranges .= "<select name=\"day_to\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $currentFrameName . "', 'history', 'day_to', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
   $filter_dateranges .= "<select name=\"month_to\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $currentFrameName . "', 'history', 'month_to', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
   $filter_dateranges .= "<select name=\"year_to\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $currentFrameName . "', 'history', 'year_to', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
   $filter_dateranges .= "</td>";
   */
   
   // Javascript-function as template only for
   $js_date .= "<script type=\"text/javascript\">\n";
   $js_date .= "<!--\n";
   $js_date .= "function initForm() {\n";
   $js_date .= "  fillDateFields(1,\"" . $currentFrameName . "\",\"history\",\"\",\"day_from\",\"month_from\",\"year_from\",\"\",\"\",\"\");\n";
   $js_date .= "  setDateTimeFields(\"" . $currentFrameName . "\",\"history\",".$day_from.",".$month_from.",".$year_from.", \"\", \"\", \"day_from\", \"month_from\", \"year_from\", \"\", \"\", \"\");\n";
   // $js_date .= "  fillDateFields(1,\"" . $currentFrameName . "\",\"history\", \"\", \"day_to\", \"month_to\", \"year_to\", \"\", \"\", \"\");\n";
   // $js_date .= "  setDateTimeFields(\"" . $currentFrameName . "\",\"history\",".$day_to.",".$month_to.",".$year_to.", \"\", \"\", \"day_to\", \"month_to\", \"year_to\", \"\", \"\", \"\");\n";
   $js_date .= "}\n";
   $js_date .= "-->\n";
   $js_date .= "</script>\n";

else :

   $filter_dateranges = "Von:\n";
   $filter_dateranges .= "<select name=\"day_from\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $contentFrame . "', 'cs_report', 'day_from', 'day_from', 'month_from', 'year_from', '', '', '')\"></select>\n";
   $filter_dateranges .= "<select name=\"month_from\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $contentFrame . "', 'cs_report', 'month_from', 'day_from', 'month_from', 'year_from', '', '', '')\"></select>\n";
   $filter_dateranges .= "<select name=\"year_from\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $contentFrame . "', 'cs_report', 'year_from', 'day_from', 'month_from', 'year_from', '', '', '')\"></select>\n";
   $filter_dateranges .= "&nbsp;&nbsp;bis:\n";
   $filter_dateranges .= "<select name=\"day_to\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $contentFrame . "', 'cs_report', 'day_to', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
   $filter_dateranges .= "<select name=\"month_to\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $contentFrame . "', 'cs_report', 'month_to', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
   $filter_dateranges .= "<select name=\"year_to\" class=\"f8np1\" onchange=\"fillDateFields(0, '" . $contentFrame . "', 'cs_report', 'year_to', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
   
   // Javascript-function as template only for
   $js_date = "<script type=\"text/javascript\">\n";
   $js_date .= "<!--\n";
   $js_date .= "function initForm() {\n";
   $js_date .= "  fillDateFields(1,\"" . $contentFrame . "\",\"cs_report\",\"\",\"day_from\",\"month_from\",\"year_from\",\"\",\"\",\"\");\n";
   $js_date .= "  setDateTimeFields(\"" . $contentFrame . "\",\"cs_report\",".$day_from.",".$month_from.",".$year_from.", \"\", \"\", \"day_from\", \"month_from\", \"year_from\", \"\", \"\", \"\");\n";
   $js_date .= "  fillDateFields(1,\"" . $contentFrame . "\",\"cs_report\", \"\", \"day_to\", \"month_to\", \"year_to\", \"\", \"\", \"\");\n";
   $js_date .= "  setDateTimeFields(\"" . $contentFrame . "\",\"cs_report\",".$day_to.",".$month_to.",".$year_to.", \"\", \"\", \"day_to\", \"month_to\", \"year_to\", \"\", \"\", \"\");\n";
   $js_date .= "}\n";
   $js_date .= "-->\n";
   $js_date .= "</script>\n";
endif;
?>

<?php if (!$isCron) : ?>

<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"); ?>

<style type="text/css">
.divpadding10 { padding-top:10px; padding-bottom:10px; padding-left:10px; padding-right:10px;}
input.minwidth { min-width:90px; }
</style>

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

<?php echo $js_date ?>

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

var popupWinMetaFieldSpecial = '';

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

function hqCheckAll(numOfHq) {
  for (i = 0; i < numOfHq; i++) {
	  document.getElementsByName('f_hq_id[]')[i].checked = true;
	}
}

function hqUncheckAll(numOfHq) {
  for (i = 0; i < numOfHq; i++) {
	  document.getElementsByName('f_hq_id[]')[i].checked = false;
  }
}

<?php if ($requestMode == ".......") : ?>
function searchCsCsc() {
  var f_act = 'search';
  
  var widthPopupWin = 950;
  var heightPopupWin = 600;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/cs_csc_list.php?f_act=" + f_act + "&allowAllCustomerTypes=1&generic=0000000000001&callOpenerFunction=finishPage('')",
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes");
};

function clearSpecialCustomer() {	
  document.forms[0].g_cs_eid.value='';
  document.forms[0].rpObjId.value='';
};

<?php elseif ($requestMode == ".......") : ?>

function searchCr() {
  var f_act = 'search';
  
  var widthPopupWin = 950;
  var heightPopupWin = 600;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/courier_list.php?deactivateMenu=1&f_act=search&f_mode=3",
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes");
};

function clearSpecialCourier() {	
	document.forms[0].g_cr_id.value='';
  document.forms[0].g_cr_eid.value='';
  document.forms[0].rpObjId.value='';
};

<?php endif; ?>

function finishPageSort(col) {
	document.forms[0].f_sort.value=col;
  finishPage('');
};

function downloadExportFile() {
  var widthPopupWin = 850;
  var heightPopupWin = 600;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../include/data_download.php?f_path=EMC2/export/download/<?php echo $hashFolder ?>/&f_fileName=<?php echo $f_secretFileName ?>", "","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};
-->
</script>

</head>

<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>initForm();<?php if ($f_stat_export) : echo "downloadExportFile();"; endif;?><?php if ($f_rpIdToCopy != "") : echo "changeReportForm();"; endif; ?><?php if ($confirmForNewAppointment) : echo "confirmForNewAppointment();"; endif; ?>">

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

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

<form name="cs_report" action="../export/export_illt.php" method="post" target="">

   <input type="hidden" name="f_act" value="<?php echo $f_act ?>">
   <input type="hidden" name="contentFrame" value="<?php echo ec($contentFrame) ?>">
   <input type="hidden" name="f_sort" value="<?php echo $f_sort ?>">
   <?php echo $phpCurrentNavigationInputHidden ?>
   <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">

  <?php echo htmlDivLineSpacer("20px"); ?>

  <!- Title -->
  <div class="f10bp1_blue">
    <div style="float:left">
      <?php echo $pageTitel; ?>

      <?php echo htmlDivLineSpacer("20px"); ?>
      
      <div>
        <select name="requestMode" onChange="finishPage('')">
          <option value=""><?php echo getLngt("AUSWAHL:") ?></option>
          <option value="101" <?php if ($requestMode == "101") : echo "selected"; endif; ?>><?php echo getLngt("Geldbetragshistorie") ?></option>
          <option value="102" <?php if ($requestMode == "102") : echo "selected"; endif; ?>><?php echo getLngt("Kassettenbewegungen") ?></option>
          <option value="103" <?php if ($requestMode == "103") : echo "selected"; endif; ?>><?php echo getLngt("Alarmstatus") ?></option>
          <option value="104" <?php if ($requestMode == "104") : echo "selected"; endif; ?>><?php echo getLngt("Abgeholte Kassetten") ?></option>
        </select>&nbsp;&nbsp;&nbsp;&nbsp;
        <?php 
          if ($requestMode != "") :
             echo getLngt("CSV-Export") . "&nbsp;<input class=\"f8np1\" type=\"checkbox\" name=\"f_stat_export[]\" value=\"1\">";
          endif;
        ?>
      <div>

      <?php if ($requestMode == ".......") : ?>
        <input type="text" name="g_cs_eid" value="<?php echo $g_cs_eid ?>" size="10" readonly>&nbsp;&nbsp;
      <?php elseif ($requestMode == ".........") : ?>
        <input type="hidden" name="g_cr_id" value="<?php echo $g_cr_id ?>">
        <input type="text" name="g_cr_eid" value="<?php echo $g_cr_eid ?>" size="10" readonly>&nbsp;&nbsp;
      <?php endif; ?>
    </div>

    <?php 
      if ($requestMode == "......") :
         echo defineButtonType10("...", "action_search", "searchCsCsc();", "20", "left", "2");
      elseif ($requestMode == "......") :
         echo defineButtonType10("...", "action_search", "searchCr();", "20", "left", "2");
      elseif ($requestMode == "......") :
         echo defineButtonType10("...", "action_pt_search", "searchPt();", "20", "left", "2");
      endif;
    ?>
    <div>
      <?php if ($requestMode == "......") : ?>
        <a href="javascript:clearSpecialCustomer();" tabindex="340"><img src="../images/waste.png" border="0" height="15" width="12"></a>
      <?php elseif ($requestMode == "......") : ?>
        <a href="javascript:clearSpecialCourier();" tabindex="340"><img src="../images/waste.png" border="0" height="15" width="12"></a>
      <?php elseif ($requestMode == "......") : ?>
        <a href="javascript:clearSpecialProspect();" tabindex="340"><img src="../images/waste.png" border="0" height="15" width="12"></a>
      <?php endif; ?>
    </div>
  </div>

  <?php echo htmlDivLineSpacer("20px", "", "left"); ?>

  <?php /* if ($statisticValueCurrentYear != "") : ?>
    <div class="f8np1">
    	  [<?php echo getLngt("Umsatz im laufenden Jahr bis heute:"); ?> &nbsp;<?php echo $statisticValueCurrentYear; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
    	   <?php echo getLngt("Umsatz im letzen Jahr in demselben Zeitraum:") ?> &nbsp;<?php echo $statisticValueLastYear; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
    	   <?php echo getLngt("Gesamtumsatz im letzen Jahr:") ?> &nbsp;<?php echo $statisticValueLastYearComplete; ?>]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    	  [<?php echo $invoiceOverview; ?>]
    </div>
    <?php echo htmlDivLineSpacer("20px"); ?>
  <?php endif; */ ?>

   <!- Date-ranges -->
  <div class="f10bp1_blue">
    <?php echo $filter_dateranges ?>
  </div>

  <?php echo htmlDivLineSpacer("20px"); ?>

   <!- Actions -->
  <div>
    <?php echo defineButtonType10(getLngt("Ausführen"), "action_stat_execute", "finishPage('execute');", "100", "left", "5") ?>
    <?php echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "100", "left", "20") ?>
  </div>
  
  <?php echo htmlDivLineSpacer("30px", "", "left"); ?>
   
  <!-- Headquarters checkboxes -->
  <?php /*
    if (!$isCron && authCheckEmployeeRights($emp_id, "10")) :
       echo getHeadquartersCheckboxes($f_hq_id);
       echo htmlDivLineSpacer("30px", "", "left");
    endif; */ 
  ?>

  <?php
    if ($f_act != "") :
    // if ($rowCounter > $limitOfRowsDisplayed) :
       echo "<div>" . getLngt("Mehr als") . " " . $limitOfRowsDisplayed . " " . getLngt("Datensätze werden nicht dargestellt! Der Export umfasst sämtliche Daten!") . "</div>";
       echo htmlDivLineSpacer("20px", "", "left");
    // endif;
    endif;
  ?>
    
  <?php echo "<table>" . $output . "</table>" ?>

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

</html>

<?php endif; ?>