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


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


$autoMode = true;
$hasAccess = false;
// if (!isset($argv[1]) || $argv[1] == "") :
if (true) :
   include_once ("../include/auth.inc.php");
/*
   $usrAccessArray["cr"] = "1";
   authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
   authCheckEmployeeRights($emp_id, "8", "1");
   $autoMode = false;
*/
   $hasAccess = true;
else :
   if ($argv[1] == "acapella7890") :
       $hasAccess = true;
   endif;
endif;


getSecHttpVars("1",array("f_act", "dbhistory", "day_from", "month_from", "year_from", "day_to", "month_to", "year_to", "hour_from", "minute_from", "hour_to", "minute_to",
                         "stmNumber", "noStatisticMenu", "specialAligns", "f_showDateAndTime"));


include_once ("../include/inc_category_dbfields.inc.php");
include_once ("../include/inc_dbfields2array.inc.php");
include_once ("../include/inc_group.inc.php");
include_once ("../statistic/statistic_sql.inc.php");
include_once ("../include/email/htmlMimeMail.php");
$pageTitel = "STATISTIK";
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");


// Display data from courier logged in only (!!!!)
$crEid = "";
if ($usr_id != "" && is_numeric($usr_id) && $usr_id > "0") :
   $crEid = getFieldValueFromId("courier","usr_id",$usr_id,"cr_eid");  // $crEid = "STB283531";
endif;

$constListBgCol1 = "#AAAAFF";
$constListBgCol2 = "#AAAAFF";
$constListBgCol3 = "#CCCCFF";
$constListBgCol4 = "#CCCCFF";

if ($f_act == "") : $f_act = ""; endif;
if ($stmNumber == "") : $stmNumber = "0"; endif;
if ($f_showDateAndTime == "") : $f_showDateAndTime = "0"; endif; // Show the clock time fields [default "NO"]


// Check ranges of time. All fields have to be set
if ($f_showDateAndTime == "0" || $hour_from == "" || $minute_from == "" || $hour_to == "" || $minute_to == "") :
    $hour_from = "00";
    $minute_from = "00";
    $hour_to = "23";
    $minute_to = "59";
    $f_showDateAndTime == "0";
endif;
$hour_from = pad($hour_from,2);
$minute_from = pad($minute_from,2);
$hour_to = pad($hour_to,2);
$minute_to = pad($minute_to,2);

// Time range
$fromTimeRange = " " . $hour_from . ":" . $minute_from . ":00";
$toTimeRange = " " . $hour_to . ":" . $minute_to . ":59";

// Check ranges of date. All fields have to be set
if ($day_from == "" || $month_from == "" || $year_from == "" || 
    $day_to == "" || $month_to == "" || $year_to == "") :

    // Initialize date-ranges to the current date
    $fromDateRange = getDateTime("3") . $fromTimeRange;
    $toDateRange = getDateTime("3") . $toTimeRange;
    
    $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) . $fromTimeRange;
    $toDateRange = $year_to . "-" . pad($month_to,2) . "-" . pad($day_to,2) . $toTimeRange;
endif;

/*
echo "year_from: " . $year_from . "<br>";
// Get the year of the begin of history data
$dbhistory = getDBNames($dbhistory, $year_from);
echo "dbhistory: " . $dbhistory . "<br>";
$remDbHistory = $dbhistory;
$constYearOfBeginHistory = getParameterValue("0", "STATISTIC_YEAR_OF_BEGIN_HISTORY", "0");
if ($dbhistory == "1" || !is_numeric($constYearOfBeginHistory) || $constYearOfBeginHistory >= getDateTime("year")) :
   $constYearOfBeginHistory = "";
endif;
echo "constYearOfBeginHistory: " . $constYearOfBeginHistory . "<br>";
echo "dbh_jb: " . $dbh_jb . "<br>";
*/

// Get the year of the begin of history data
$dbhistory = "0";
// echo "dbhistory: " . $dbhistory . "<br>";
$dbhistory = getDBNames($dbhistory, $year_from);
// echo "dbhistory: " . $dbhistory . "<br>";
$constYearOfBeginHistory = getParameterValue("0", "STATISTIC_YEAR_OF_BEGIN_HISTORY", "0");
if ($dbhistory == "0" && is_numeric($constYearOfBeginHistory) && $year_from <= $constYearOfBeginHistory) :
   $dbhistory = "1";
   $dbhistory = getDBNames($dbhistory, $year_from);
endif;
$remDbHistory = $dbhistory;
// echo "year_from: " . $year_from . "<br>";
// echo "dbhistory: " . $dbhistory . "<br>";
// echo "constYearOfBeginHistory: " . $constYearOfBeginHistory . "<br>";
// echo "dbh_jb: " . $dbh_jb . "<br>";


// Converts matrix (2-dim-array) to vector (1-dim-array) e.g. like "csv-lines"
function specialConvertAssociativeMatrixToTable ($matrix, $typeArr = array(), $alignArr =array(), $noDisplayTableTag = "", $cssTable = "", $cssTr = "", $cssTd = "") {
  global $constListBgCol1,$constListBgCol2,$constListBgCol3,$constListBgCol4;
	$retValue = "";
	if (is_array($matrix)) :
	   if ($noDisplayTableTag != "1") :
	      $retValue .= "<table " . $cssTable . ">\n";
	   endif;
	   $matrixKeys = array_keys($matrix);
	   $matrixKeysLen = count($matrixKeys);
	   for ($i = 0; $i < $matrixKeysLen; $i++) :
	       $retValue .= "<tr" . ($cssTr != "" ? " " . $cssTr : "") . ">\n";
	       $colArray = $matrix[$matrixKeys[$i]];
	       $colArrayKeys = array_keys($colArray);
	       $colArrayKeysLen = count($colArrayKeys);
	       for ($j = 0; $j < $colArrayKeysLen; $j++) :
	           $val = $colArray[$colArrayKeys[$j]];
             switch($typeArr[$j]) {
               // case "integer" : $val = round($val,0);
               case "float" : $val = number_format(round($val,2), 2, ",", ".");
               case "varchar" : $val = trim($val);
               default : $val = trim($val);
             };
	           if ($cssTd != "") :
                // $cellColor = getListColor($i, $j);
                $cellColor = getListColorGeneric($i, $j, $constListBgCol1, $constListBgCol2, $constListBgCol3, $constListBgCol4);
                if ($cellColor != "") : $cssTd .= "background-color:" . $cellColor . ";"; endif;
                $cssTd .= "text-align:" . setAlign($alignArr[$j]) . ";";
                $retValue .= "<td style=\"" . $cssTd . "\">\n";
                $retValue .= $val;
                $retValue .= "</td>\n";
             else :
                $retValue .= $val;  // Content in $colArray[$j] is like "<td....> .... </td>"
             endif;
	       endfor;
	       $retValue .= "</tr>\n";
	   endfor;
	   if ($noDisplayTableTag != "1") :
	      $retValue .= "</table>\n";
	   endif;
	endif;
	return $retValue;
}

function statisticSetGlobalParameterArray () {
   global $aligns, $f_statusMode, $f_dateMode, $f_showDateAndTime, $f_crvh_sid, $f_direction_sort;
   global $f_filter, $f_filter2, $f_filter3, $f_filter4, $f_filter5, $f_filter6, $f_filter7, $f_filter8, $f_filter9, $f_filter10;
   global $f_price_formular, $f_filter_a, $f_filter_interval, $g_crvh_filter, $f_mode_statistic, $f_filter_calc, $f_service, $f_servicetype, $f_jb_service, $f_split_jb_services, $f_jb_specifics;
   global $f_cs_meta, $f_cr_meta, $f_cr_parent, $f_cr_pda_actions, $f_show_invoice_address, $f_show_delivery_address, $summationField, $summationField2, $uniqueSearchFields;
   global $hour_from, $minute_from, $hour_to, $minute_to, $fromTimeRange, $toTimeRange, $f_cmp_new_date, $f_cs_become_cs_date, $f_net_gross;
   global $f_group, $f_groupLen, $f_staticGroup, $f_staticGroupLen, $f_priceMode;

   $globalParArray = array($aligns, $f_statusMode, $f_dateMode, $f_showDateAndTime, $f_crvh_sid, $f_direction_sort, 
                           $f_filter, $f_filter2, $f_filter3, $f_filter4, $f_filter5, $f_filter6, $f_filter7, $f_filter8, $f_filter9, $f_filter10,
                           $f_price_formular, $f_filter_a, $f_filter_interval, $g_crvh_filter, $f_mode_statistic, $f_filter_calc, $f_service, $f_servicetype, $f_jb_service, $f_split_jb_services, $f_jb_specifics,
                           $f_cs_meta, $f_cr_meta, $f_cr_parent, $f_cr_pda_actions, $f_show_invoice_address, $f_show_delivery_address, $summationField, $summationField2, $uniqueSearchFields,
                           $hour_from, $minute_from, $hour_to, $minute_to, $fromTimeRange, $toTimeRange, $f_cmp_new_date, $f_cs_become_cs_date, $f_net_gross,
                           $f_group, $f_groupLen, $f_staticGroup, $f_staticGroupLen, $f_priceMode);
  return $globalParArray;
}


if ($hasAccess && $crEid != "" && $f_act = "calculate" && $stmNumber != "" && is_numeric($stmNumber) && $stmNumber > 0) :

   // Mode in $argv[2]
   // $mode = trim ($argv[2]);
   $mode = "Nutzungsverhalten";
   $currencySymbol = "€";

   // Init system parameter
   $path = "../temp/download/";
   
   
   // Init global parameter for script
   $aligns = "";
   $f_statusMode = "1";  // Finished jobs
   $f_dateMode = "2";  // "creating date", "booking date", "finish date" [default], "export date", "order_date"
   // $f_showDateAndTime = "0";  // Clock time restriction (0 = none)
   $f_crvh_sid = "";  // Filter for special vehicle SID
   $f_direction_sort = "0";  // ORDER BY ASC or DESC"
   $f_filter = "0";  // Filter (Split for vehicletype, start zipcode, etc.)
   $f_filter2 = "0";  // Filter (Split for "Aufträge und Gutschriften") (0 = none)
   $f_filter3 = "0";  // Filter (Split for "Fahrzeugkategorie" ["jb_type"]) (0 = none)
   $f_filter4 = "0";  // Filter (Split for headquarters) (0 = none)
   $f_filter5 = "0";  // Filter (Split for branches) (0 = none)
   $f_filter6 = "0";  // Filter (Split for carriers [ONLY customer statistics]) (0 = none)
   $f_filter7 = "0";  // Filter (Split for vehicles) (0 = none)
   $f_filter8 = "0";  // Filter (Split for employees) (0 = none)
   $f_filter9 = "0";  // Filter (Split for job types ["jb_type"]) (0 = none)
   $f_filter10 = "0";  // Filter (Split for costcenter ["csc_id_payer" / "csc_id_related"]) (0 = none)
   $f_price_formular = "0";  // Computation of the price (0 = jb_totalprice)
   $f_filter_a = "0";  // Subfilter to $f_filter (Kind of vehicletype [Requested or real]) (0 = none)
   $f_filter_interval = "0";  // Filter (Split for time intervals) (0 = none)
   $g_crvh_filter = "";  // Vehicle filter  ("" = default)
   $f_mode_statistic = "0";  // Normal statistic (0 = default, 1 = calculator)
   $f_filter_calc = "0";  // (0 = none)
   $f_service = "0";  // Service for "service statistic" (0 = none)
   $f_servicetype = "0";  // Servicetype for "service statistic" (0 = none)
   $f_jb_service = array();  // Job service array as filter (empty array = default)
   $f_split_jb_services = "0";  // Filter (Split for job services) (0 = none)
   $f_jb_specifics = array();  // Job specifics used as filter (empty array = default)
   $f_cs_meta = "0";  // Filter (Split for sub customers ["meta-customer"]) (0 = none)
   $f_cr_meta = "1";  // Filter (Split for driver) (0 = none)
   $f_cr_parent = "2";  // Every courier or driver OR cumulation by parent ("" = default)
   $f_cr_pda_actions = "0";  // Filter for courier action statistics (absolute/relative per job) (0 = none)
   $f_show_invoice_address = "0";
   $f_show_delivery_address = "0";
   $summationField = "";
   $summationField2 = "";
   $uniqueSearchFields = array();
   $f_cmp_new_date = "";  // Filter (Only new data set since date)
   $f_cs_become_cs_date = "";  // Filter (Only new customers since date)
   $f_net_gross = "0";
   $f_group = array();
   $f_groupLen = 0;
   $f_staticGroup = array();
   $f_staticGroupLen = 0;
   $f_priceMode = 0;
   $f_editCsMode = 0;
   $station_based_group_field = "";

   $csEid = "";
   $orderByClause = "cr.cr_eid";

   $f_category = "2";
   $f_hq_id = array($hq_id);

/*
   // Init system parameter
   $path = "../temp/download/";
   $f_secretFileName = "stat_cr_" . str_replace("-","",getDateTime("date_yesterday_currentmonth_currentyear")) . ".csv";
   $matrix = array();  // array("","Monat Vorjahr","Vormonat","Aktueller Monat IST","Aktueller Monat SOLL")
   $output = "";

   // Remove potential existing file
   if (file_exists($path . $f_secretFileName)) :
      unlink($path . $f_secretFileName);
   endif;
*/
       
   $globalParArray = statisticSetGlobalParameterArray();
   
   $tmpStmNumber = $stmNumber;
   if ($stmNumber >= "1000" && $stmNumber <= "1999") :
      $tmpStmNumber = "1000";
   endif;
   $idArrayLen = getCategoryDBFields($tmpStmNumber);

   $retArray = getStatistic($globalParArray, $stmNumber, $fromDateRange, $toDateRange, $csEid, $crEid, $orderByClause);
   $rowArray = $retArray[0];        // Statistic data

   $tdStyle = "border:1px solid #7777FF; border-collapse:collapse; background-color:#CCCCFF; padding: 5px;";

   $outTable = "<table style=\"border:1px solid #7777FF; border-collapse:collapse; background-color:#CCCCFF;\">";
   $outTable .= "<tr>";
   $outTable .= "  <td style=\"" . $tdStyle . "font-weight: bold;\">" . getLngt("Transporteur") . "</td>";
   $outTable .= "  <td style=\"" . $tdStyle . "font-weight: bold;\">" . getLngt("Vorname") . "</td>";
   $outTable .= "  <td style=\"" . $tdStyle . "font-weight: bold;\">" . getLngt("Nachname") . "</td>";
   $outTable .= "  <td style=\"" . $tdStyle . "font-weight: bold;\">" . getLngt("Auftragsanzahl") . "</td>";
   $outTable .= "  <td style=\"" . $tdStyle . "font-weight: bold;\">" . getLngt("Umsatz") . "</td>";
   $outTable .= "</tr>";
   $outTable .= specialConvertAssociativeMatrixToTable($rowArray, array("varchar","varchar","varchar","integer","float"), array("l","l","l","r","r"), "1", "", "", $tdStyle);
   $outTable .= "</table>";


/*
   // **** Send CSV file per mail ****
   $mailObj = new htmlMimeMail();
   $mailCssFontType = "Calibri, Arial, Verdana, Helvetica, sans-serif";

   $mailtext  = "<html><head><meta text/html>";
   $mailtext .= "<style type=\"text/css\">";
   $mailtext .= ".f8np1 { font-family: " . $mailCssFontType . "; font-size: 8pt; font-weight: normal; padding: 1px}";
   $mailtext .= ".f8bp1 { font-family: " . $mailCssFontType . "; font-size: 8pt; font-weight: bold; padding: 1px}";
   $mailtext .= ".f10np1 { font-family: " . $mailCssFontType . "; font-size: 10pt; font-weight: normal; padding: 1px}";
   $mailtext .= ".f10bp1 { font-family: " . $mailCssFontType . "; font-size: 10pt; font-weight: bold; padding: 1px}";
   $mailtext .= ".f8np1_red { font-family: " . $mailCssFontType . "; font-size: 8pt; font-weight: normal; padding: 1px; color: #FF0000;}";

   $mailtext .= " table { border-width: 2px; border-style: solid; border-color: white; }";
   $mailtext .= " .td_border { border-width: 2px; border-style: solid; border-color: white; }";
   $mailtext .= " .td_cell { padding: 5px; }";

   $mailtext .= "</style>";
   $mailtext .= "</head><body><h4>";
   $mailtext .= $output;
   $mailtext .= "</h4></body></html>";

   $mailSubject = strtoupper($mode) . "- UND AUFTRAGSDATENÜBERSICHT GFL für den Monat " . substr(getDateTime("date_yesterday_currentmonth_currentyear"),0,7);
   $mailObj->setSubject($mailSubject);

   $mailObj->setHtml($mailtext, null, "./");

   // $mailSenderAddress = getParameterValue("0", "MAIL_SENDER_ADDRESS", "0");
   // if ($mailSenderAddress != "" && checkEmailFormat($mailSenderAddress)) :
      $mailSenderAddress = "hb.transport@hansetrans.de";
   // endif;            
   $mailObj->setFrom($mailSenderAddress);

   $mailCcAddress = getParameterValue("0", "MAIL_CC_ADDRESS", "0");
   if ($mailCcAddress != "" && checkEmailFormat($mailCcAddress)) :
      $mailObj->setCc($mailCcAddress);
   endif;
   
   $mailBccAddress = getParameterValue("0", "MAIL_BCC_ADDRESS", "0");
   if ($mailBccAddress != "" && checkEmailFormat($mailBccAddress)) :
      $mailObj->setBcc($mailBccAddress);
   endif;            
   
   if (file_exists($path . $f_secretFileName)) :
      $attachment = $mailObj->getFile($path . $f_secretFileName);
      $mailObj->addAttachment($attachment, $f_secretFileName, 'text/csv');
   endif;

   $mailResult = $mailObj->send(array("mail-cron@assecutor.de","ca@hansetrans.de","sascha.engel@hansetrans.de"), 'smtp');
// $mailResult = $mailObj->send(array("mv@assecutor.de"), 'smtp');

   if ($mailResult) :
      // $mailsendStatus = getLngt("Die Nachricht wurde versandt!");
      // Write logdata into log database
      // writeToLogDB("22",$currentHqId,$job_id,$currentSessionUsrId,"","","",$f_email . "|STATION");
   else :
      // $mailsendStatus = getLngt("Die Nachricht konnte nicht gesendet werden!");
      // Write logdata into log database
      // writeToLogDB("23",$currentHqId,$job_id,$currentSessionUsrId,"","","",$f_email . "|STATION");
   endif;

   $mailObj = NULL;
   if (file_exists($path . $f_secretFileName)) :
      unlink($path . $f_secretFileName);
   endif;


   // OUTPUT
   if (!$autoMode) :
      echo $mailtext;
   endif;
*/
endif;

// Javascript-function as template only for categorie depending on date-filter (not status-filter)
// $onLoadCall = "displayStatusMessage();";
$onLoadCall = "";

$js_date = "";
$js_date .= "<script src=\"../include/lib_global.js\" type=\"text/javascript\">\n";
$js_date .= "</script>\n";
$js_date .= "\n";
$js_date .= "<script type=\"text/javascript\">\n";
$js_date .= "<!--\n";
$js_date .= "function initForm() {\n";
$js_date .= "  fillDateFields(1,\"maincontent\",\"statistic\",\"\",\"day_from\",\"month_from\",\"year_from\",\"\",\"\",\"\");\n";
$js_date .= "  setDateTimeFields(\"maincontent\",\"statistic\",".$day_from.",".$month_from.",".$year_from.", \"\", \"\", \"day_from\", \"month_from\", \"year_from\", \"\", \"\", \"\");\n";
$js_date .= "  fillDateFields(1,\"maincontent\",\"statistic\", \"\", \"day_to\", \"month_to\", \"year_to\", \"\", \"\", \"\");\n";
$js_date .= "  setDateTimeFields(\"maincontent\",\"statistic\",".$day_to.",".$month_to.",".$year_to.", \"\", \"\", \"day_to\", \"month_to\", \"year_to\", \"\", \"\", \"\");\n";
$js_date .= "}\n";
$js_date .= "-->\n";
$js_date .= "</script>\n";

if ($noStatisticMenu == "") :
   $onLoadCall .= "initForm();";
endif;

if ($fileOutput) :
   $onLoadCall .= "downloadFile();";
endif;



?>

<html>

<head>
<title><?php echo getLngt("STATISTIK"); ?></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; ?>


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

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

function downloadFile() {
  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("../statistic/statistic_data_download.php?f_fileName=<?php echo $f_secretFileName ?>", "","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};
-->
</script>

<?php echo $js_date ?>


</head>

<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?><?php echo $onLoadCall ?>" >

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

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

  <form name="statistic" action="../tools/statistic_special_CR.php" method="post">
    <input type="hidden" name="f_act" value="">
    <input type="hidden" name="dbhistory" value="<?php echo $dbhistory ?>">
    <input type="hidden" name="outputTitle" value="<?php echo $outputTitle ?>">
    <input type="hidden" name="noStatisticMenu" value="<?php echo $noStatisticMenu ?>">
    <?php echo $phpCurrentNavigationInputHidden ?>
    <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
  
    <?php
      if ($noStatisticMenu != "") :
    ?>     
         <input type="hidden" name="f_category" value="<?php echo $f_category ?>">
         <input type="hidden" name="f_statistic" value="<?php echo $f_statistic ?>">
         <input type="hidden" name="f_sort" value="<?php echo $f_sort ?>">
         <input type="hidden" name="outputColumnMode" value="<?php echo $outputColumnMode ?>">
         <input type="hidden" name="specialAligns" value="<?php echo $specialAligns ?>">
         
         <input type="hidden" name="day_from" value="<?php echo $day_from ?>">
         <input type="hidden" name="month_from" value="<?php echo $month_from ?>">
         <input type="hidden" name="year_from" value="<?php echo $year_from ?>">
         <input type="hidden" name="day_to" value="<?php echo $day_to ?>">
         <input type="hidden" name="month_to" value="<?php echo $month_to ?>">
         <input type="hidden" name="year_to" value="<?php echo $year_to ?>">
    <?php
      else :
    ?>
  
    <input type="hidden" name="f_sort" value="">
    <?php echo htmlDivLineSpacer("20px"); ?>
  
    <!-- Output of the calculated values -->  
    <div>
      <div class="f12bp1_blue"><?php echo getLngt("STATISTIK"); ?></div>
    </div>
  
    <?php echo htmlDivLineSpacer("15px"); ?>
  
    <div>
      <div <?php echo $htmlDivFixedWidth; ?>><?php echo getLngt("Optionen"); ?>:</div>
      <div>
        <select name="stmNumber">
          <option value="0" <?php if ($stmNumber == "0") : echo "selected"; endif; ?>>---</option>
          <option value="1006" <?php if ($stmNumber == "1006") : echo "selected"; endif; ?>><?php echo getLngt("Anzahl automatischer Auftragsvermittlungsveruche pro Transporteur"); ?></option>
          <option value="1007" <?php if ($stmNumber == "1007") : echo "selected"; endif; ?>><?php echo getLngt("Anzahl manueller Auftragsvermittlungsveruche pro Transporteur"); ?></option>
          <option value="1003" <?php if ($stmNumber == "1003") : echo "selected"; endif; ?>><?php echo getLngt("Anzahl angenommener Aufträge pro Transporteur"); ?></option>
          <option value="1011" <?php if ($stmNumber == "1011") : echo "selected"; endif; ?>><?php echo getLngt("Anzahl abgelehnter Aufträge pro Transporteur"); ?></option>
          <option value="1008" <?php if ($stmNumber == "1008") : echo "selected"; endif; ?>><?php echo getLngt("Anzahl automatisch entzogener Aufträge pro Transporteur"); ?></option>
        </select>
      </div>
    </div>
    <?php echo htmlDivLineSpacer("10px"); ?>

    <div>
      <div <?php echo $htmlDivFixedWidth; ?>><?php echo getLngt("Datums-Filter"); ?>:</div>
      <div>
        <?php 
        // Date ranges
        $categoryFilter  = "von:\n";      
        $categoryFilter .= "<select name=\"day_from\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'statistic', 'day_from', 'day_from', 'month_from', 'year_from', '', '', '', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
        $categoryFilter .= "<select name=\"month_from\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'statistic', 'month_from', 'day_from', 'month_from', 'year_from', '', '', '', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
        $categoryFilter .= "<select name=\"year_from\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'statistic', 'year_from', 'day_from', 'month_from', 'year_from', '', '', '', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";      
        $categoryFilter .= "&nbsp;&nbsp;bis:\n";     
        $categoryFilter .= "<select name=\"day_to\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'statistic', 'day_to', 'day_from', 'month_from', 'year_from', '', '', '', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
        $categoryFilter .= "<select name=\"month_to\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'statistic', 'month_to', 'day_from', 'month_from', 'year_from', '', '', '', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
        $categoryFilter .= "<select name=\"year_to\" class=\"f8np1\" onchange=\"fillDateFieldsCheck(0, 'maincontent', 'statistic', 'year_to', 'day_from', 'month_from', 'year_from', '', '', '', 'day_to', 'month_to', 'year_to', '', '', '')\"></select>\n";
        $categoryFilter .= "&nbsp;<br>";
        echo $categoryFilter;
        ?>
        <?php echo htmlDivLineSpacer("5px"); ?>
      <div <?php echo $htmlDivFixedWidth; ?>>&nbsp;</div>
      <div>
        <?php 
        if (true) :
        // Time ranges
        $categoryFilter  = "[";
        $categoryFilter .= "Ohne<input class=\"smaller\" type=\"radio\" name=\"f_showDateAndTime\" value=\"0\" " . ($f_showDateAndTime == "0" ? "checked" : "") . ">|";
        $categoryFilter .= "Mit<input class=\"smaller\" type=\"radio\" name=\"f_showDateAndTime\" value=\"1\" " . ($f_showDateAndTime == "1" ? "checked" : "") . ">";
        $categoryFilter .= "Einschränkung auf Zeitintervall von:\n";
        $categoryFilter .= "<select name=\"hour_from\" class=\"f8np1\">" . addOptionsFromRange("0","23",$hour_from,"1") . "</select>\n";
        $categoryFilter .= "<select name=\"minute_from\" class=\"f8np1\">" . addOptionsFromRange("0","59",$minute_from,"1") . "</select>\n";
        $categoryFilter .= "Uhr&nbsp;&nbsp;bis:\n";      
        $categoryFilter .= "<select name=\"hour_to\" class=\"f8np1\">" . addOptionsFromRange("0","23",$hour_to,"1") . "</select>\n";
        $categoryFilter .= "<select name=\"minute_to\" class=\"f8np1\">" . addOptionsFromRange("0","59",$minute_to,"1") . "</select>\n";
        $categoryFilter .= "Uhr]\n";
        echo $categoryFilter;
        endif;
        ?>
      </div>
    </div>
  
    <?php echo htmlDivLineSpacer("10px"); ?>
    
    <div>
      <div <?php echo $htmlDivFixedWidth; ?>><?php /* echo getLngt("Statistik berechnen"); */ ?></div>
      <div>
        <?php echo defineButton("Berechnen", "action_statistic", "finishPage('calculate');", "left", "", "", "", "100px"); ?>
        <?php if (false) : ?>
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
           <input type="checkbox" name="fileOutput" value="1" <?php /* if ($fileOutput) : echo "checked"; endif; */ ?>>&nbsp;<?php echo getLngt("Zusätzlicher&nbsp;Download&nbsp;der&nbsp;Daten"); ?>

           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
           <select class="f8np1" name="f_type_chart" onChange="checkSelectedIntervalByChart();">
             <option value="0" <?php if ($f_type_chart == "0") : echo "selected"; endif; ?>><?php echo getLngt("Keine Diagrammausgabe") ?></option>
             <option value="1" <?php if ($f_type_chart == "1") : echo "selected"; endif; ?>><?php echo getLngt("Tortendiagramm") ?></option>
             <option value="2" <?php if ($f_type_chart == "2") : echo "selected"; endif; ?>><?php echo getLngt("Balkendiagramm") ?></option>
             <option value="10" <?php if ($f_type_chart == "10") : echo "selected"; endif; ?>><?php echo getLngt("Normierter Stapel auf 100%") ?></option>
             <option value="11" <?php if ($f_type_chart == "11") : echo "selected"; endif; ?>><?php echo getLngt("Multi-Balkendiagramm") ?></option>
             <option value="12" <?php if ($f_type_chart == "12") : echo "selected"; endif; ?>><?php echo getLngt("Flächenstapeldiagramm") ?></option>
             <option value="13" <?php if ($f_type_chart == "13") : echo "selected"; endif; ?>><?php echo getLngt("Flächendiagramm") ?></option>
           </select>
        <?php endif; ?>
      </div>
    </div>
    
    <?php echo htmlDivLineSpacer("10px"); ?>
    
    <?php
      endif;
    ?>
  </form>

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


  <!-- Display calculated values -->
  <div>
    <div class="f12bp1_blue"><?php if ($outputTitle != "") : echo $outputTitle; else : echo getLngt("Aufstellung"); endif; ?></div>
  </div>

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

  <div>
    <?php echo $outTable; ?>  	
  </div>

</div>

</body>
</html>     

