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

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


// Check HTTP-Parameters
getSecHttpVars("1",array("history_mode", "f_act", "customerId", "cscIdRoot", "cscIdActual", "empIdMaster", "cs_id", "cr_id", "job_id", "at_id", "empIdHist", "op",
                         "day_from", "month_from", "year_from", "day_to", "month_to", "year_to", "dbhistory", "deactivateMenu", "logoselection", "displayselection"));

getLanguage(__FILE__);

if (!isset($op) || $op == "") : $op = "0"; endif;
if (!isset($logoselection) || $logoselection == "") : $logoselection = "0"; endif;

// Potential employee restrictions regarding rights
$historyEmpRightArr = array_fill(0, 100, true);
if (!authCheckEmployeeRights($emp_id, "40")) : $historyEmpRightArr[40] = false; endif;
if (!authCheckEmployeeRights($emp_id, "41")) : $historyEmpRightArr[41] = false; endif;

// $history_mode:
// "0" : Customer
// "1" : Courier
// "2" : Job
// "3" : Article
// "4" : Employee
$typeArray = array();
if ($history_mode == "0") :
   $typeArray["mode"] = "cs";
   $typeArray["id"] = $cs_id;
   $typeArray["auth"] = "0";
   $typeArray["pagetitle"] = getLngt("KUNDENHISTORIE");
   $typeArray["dateselection"] = "1";
   $typeArray["logomapping"] = array("1" => "36", "2" => "48");
   $typeArray["logoselection"] = "
     <select class=\"f8np1\" id=\"logoselection\" name=\"logoselection\" onChange=\"setDisplaySelection();\">
       <option value=\"0\">" . getLngt("FILTER") . "</option>
       <option value=\"1\" " . ($logoselection == "1" ? "selected" : "") . ">" . getLngt("Kundenänderungen") . "</option>
       <option value=\"2\" " . ($logoselection == "2" ? "selected" : "") . ">" . getLngt("Kostenstellenanschriften") . "</option>
     </select>&nbsp;&nbsp;&nbsp;&nbsp;
     <select class=\"f8np1\" id=\"displayselection\" name=\"displayselection\" onChange=\"checkLogoSelection();\">
       <option value=\"0\" " . ($displayselection == "0" ? "selected" : "") . ">" . getLngt("Alle Felder") . "</option>
       <option value=\"1\" " . ($displayselection == "1" ? "selected" : "") . ">" . getLngt("Nur geänderte") . "</option>
     </select>
   ";
elseif ($history_mode == "1") :
   $typeArray["mode"] = "cr";
   $typeArray["id"] = $cr_id;
   $typeArray["auth"] = "1";
   $typeArray["pagetitle"] = getLngt("TRANSPORTEURSHISTORIE");
   if ($logoselection == "2") :
      $typeArray["pagetitle"] = getLngt("FAHRZEUGHISTORIE DES TRANSPORTEURS");
   endif;
   $typeArray["dateselection"] = "1";
   $typeArray["logomapping"] = array("1" => "37", "2" => "86");
   $typeArray["logoselection"] = "
     <select class=\"f8np1\" id=\"logoselection\" name=\"logoselection\" onChange=\"setDisplaySelection();\">
       <option value=\"0\">" . getLngt("FILTER") . "</option>
       <option value=\"1\" " . ($logoselection == "1" ? "selected" : "") . ">" . getLngt("Transporteursänderungen") . "</option>
       <option value=\"2\" " . ($logoselection == "2" ? "selected" : "") . ">" . getLngt("Fahrzeugänderungen") . "</option>
     </select>&nbsp;&nbsp;&nbsp;&nbsp;
     <select class=\"f8np1\" id=\"displayselection\" name=\"displayselection\" onChange=\"checkLogoSelection();\">
       <option value=\"0\" " . ($displayselection == "0" ? "selected" : "") . ">" . getLngt("Alle Felder") . "</option>
       <option value=\"1\" " . ($displayselection == "1" ? "selected" : "") . ">" . getLngt("Nur geänderte") . "</option>
     </select>
   ";
elseif ($history_mode == "2") :
   $typeArray["mode"] = "jb";
   $typeArray["id"] = $job_id;
   $typeArray["auth"] = "4";
   $typeArray["pagetitle"] = getLngt("AUFTRAGSHISTORIE");
   $typeArray["dateselection"] = "0";
   $typeArray["logomapping"] = array();
   $typeArray["logoselection"] = "";
elseif ($history_mode == "3") :
   $typeArray["mode"] = "at";
   $typeArray["id"] = $at_id;
   $typeArray["auth"] = "14";
   $typeArray["pagetitle"] = getLngt("ARTIKELHISTORIE");
   $typeArray["dateselection"] = "1";
   $typeArray["logomapping"] = array();
   $typeArray["logoselection"] = "";
elseif ($history_mode == "4") :
   $typeArray["mode"] = "emp";
   $typeArray["id"] = $empIdHist;
   $typeArray["auth"] = "32";
   $typeArray["pagetitle"] = getLngt("MITARBEITERHISTORIE");
   $typeArray["dateselection"] = "1";
   $typeArray["logomapping"] = array();
   $typeArray["logoselection"] = "";
endif;

$deactivateMenuStatic = "1";
$pageTitel = $typeArray["pagetitle"];
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);

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

// Get the emp_id of the root admin because he/she is allowed to change a password of an employee
$empIdRootAdmin = getEmpIdOfRootAdmin($userTypeName);

// For limitation of the rows displayed
$limitOfRowsDisplayed = "2500";

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

if ($op != "0")  :
   $day_from = "01"; $month_from = "01"; $year_from = "2020";
   $day_to = getDateTime("day"); $month_to = getDateTime("month"); $year_to = getDateTime("year");
endif;

// Check range 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") . " 00:00:00";
    $toDateRange = getDateTime("3") . " 23:59:59";
 
    $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) . " 00:00:00";
    $toDateRange = $year_to . "-" . pad($month_to,2) . "-" . pad($day_to,2) . " 23:59:59";
endif;

// Get the year of the begin of history data
$dbhistory = getDBNames($dbhistory, $year_from);

/*
echo "op = " . $op . "<br>";
echo "logoselection = " . $logoselection . "<br>";
echo "displayselection = " . $displayselection . "<br>";
echo "fromDateRange = " . $fromDateRange . "<br>";
echo "toDateRange = " . $toDateRange . "<br>";
*/

// --- CUSTOMER HISTORY ------------------
if ($typeArray["mode"] == "cs") :

   // From table "log"
   $fieldClause = getDBFields("logoperation") . "," . getDBFields("log") . "," . getDBFields("user") . " ";
   
   $fromClause = "phoenix_log.logoperation AS logo, phoenix_log." . $dbh_log . " AS log " .
                 "LEFT JOIN phoenix.user AS usr ON log.usr_id = usr.usr_id ";

   // Pre-Statement to get the last modification entry to compare with the first of selectet date range
   $fromDateRangeSql = $fromDateRange;
   $toDateRangeSql = $toDateRange;
   $tmpMaxLogCreatetime = "";
   if ($logoselection > "0" && count($typeArray["logomapping"]) > 0) :
      $whereClausePre = "log.cs_id = '" . $cs_id . "' AND " 
                      . " log.logo_id = '" . $typeArray["logomapping"][$logoselection] . "' AND "
                      . " log.logo_id = logo.logo_id AND "
                      . " log.log_createtime < '" . $fromDateRange . "'";

      $tmpMaxLogCreatetime = getMaxOfField("phoenix_log.logoperation AS logo, phoenix_log.log AS log", "log.log_createtime", $whereClausePre);
      if ($tmpMaxLogCreatetime != "") :
         $fromDateRangeSql = $tmpMaxLogCreatetime;
      endif;
   endif;

   $whereClause = "log.cs_id = '" . $cs_id . "' AND " 
                . ($logoselection > "0" && count($typeArray["logomapping"]) > 0 ? "log.logo_id = '" . $typeArray["logomapping"][$logoselection] . "' AND " : "")
                . " log.logo_id = logo.logo_id AND"
                . " log.log_createtime >= '" . $fromDateRangeSql . "' AND"
                . " log.log_createtime <= '" . $toDateRangeSql . "'";

   // $orderByClause = "log.log_createtime LIMIT 0," . $limitOfRowsDisplayed;
   $orderByClause = ($logoselection > "0" && count($typeArray["logomapping"]) > 0 ? "log.logo_id, " : "")
                  . ($logoselection == "2" && count($typeArray["logomapping"]) > 0 ? "CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(logo_description, '|ADT_ID=', -1),'|', 1) AS UNSIGNED), " : "")
                  . "log.log_id LIMIT 0," . $limitOfRowsDisplayed;

   $sqlquery = generateStatement($fieldClause,$fromClause,$whereClause,$orderByClause);
// echo $sqlquery . "<br><br>";
   // Send request to database
   $result = $db->query($sqlquery);

   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());

   // Generate list with header
   $titleArray = array(getLngt("Vorgang") . "&nbsp;&nbsp;",getLngt("Zeitpunkt") . "&nbsp;&nbsp;",getLngt("Name") . "&nbsp;&nbsp;",getLngt("Vorname") . "&nbsp;&nbsp;",getLngt("Telefon") . "&nbsp;&nbsp;",getLngt("Details"));
   $fieldArray = array("logo_op_shortname","log_createtime","usr_name","usr_firstname","usr_phone","logo_description");
   $aligns = "l,c,l,l,l,l";
   $alignArray = spliti(",",$aligns);
   $alignTitles = "center";
   $widths = "180,130,150,150,80,350";
   $widthArray = spliti(",",$widths);
   $summationField = "";
   $postParserField = "logo_description";
   $mode = "1";             // Output from DB-RESULT
   $sortDBField = "";       // Used in following include-file for sorting per column;
   if ($logoselection > "0" && count($typeArray["logomapping"]) > 0) :
      $noDisplayBoolCondition = array("log_createtime", ">=", $fromDateRange);
   endif;
   include ("../include/inc_list_defineoutput.inc.php");

   $result->free();
   
   
   // *** ONLY OUTPUT ***
   
   // Customer
   $cmpId = getFieldValueFromId("customer", "cs_id", $cs_id, "cmp_id");
   $tmpFields = getFieldsValueFromId("company","cmp_id",$cmpId,array("cmp_comp","cmp_comp2"));
   $csCmpComp = $tmpFields[0];
   $csCmpComp2 = $tmpFields[1];
   
   // Post parsing if necessary
   if ($postParserField != "") :
      $tableBody = postParseCsHistory($tableBody, ($logoselection > "0" ? true : false));
   endif;

   // Invert all occurrences of "<tr>"
   $tableBody = reverseOuterTableRows($tableBody);
endif;


// --- COURIER HISTORY ------------------
if ($typeArray["mode"] == "cr") :

   // From table "log"
   $fieldClause = getDBFields("logoperation") . "," . getDBFields("log") . "," . getDBFields("user") . " ";
   
   $fromClause = "phoenix_log.logoperation AS logo, phoenix_log." . $dbh_log . " AS log " .
                 "LEFT JOIN phoenix.user AS usr ON log.usr_id = usr.usr_id ";

   // Pre-Statement to get the last modification entry to compare with the first of selectet date range
   $fromDateRangeSql = $fromDateRange;
   $toDateRangeSql = $toDateRange;
   $tmpMaxLogCreatetime = "";
   if ($logoselection > "0" && count($typeArray["logomapping"]) > 0) :
      $whereClausePre = "log.cr_id = '" . $cr_id . "' AND " 
                      . " log.logo_id = '" . $typeArray["logomapping"][$logoselection] . "' AND "
                      . " log.logo_id = logo.logo_id AND "
                      . " log.log_createtime < '" . $fromDateRange . "'";

      $tmpMaxLogCreatetime = getMaxOfField("phoenix_log.logoperation AS logo, phoenix_log.log AS log", "log.log_createtime", $whereClausePre);
      if ($tmpMaxLogCreatetime != "") :
         $fromDateRangeSql = $tmpMaxLogCreatetime;
      endif;
   endif;

   $whereClause = "log.cr_id = '" . $cr_id . "' AND "
                . ($logoselection > "0" && count($typeArray["logomapping"]) > 0 ? "log.logo_id = '" . $typeArray["logomapping"][$logoselection] . "' AND " : "")
                . " log.logo_id = logo.logo_id AND "
                . " log.log_createtime >= '" . $fromDateRangeSql . "' AND"
                . " log.log_createtime <= '" . $toDateRangeSql . "'";

   // $orderByClause = "log.log_createtime LIMIT 0," . $limitOfRowsDisplayed;
   $orderByClause = "log.log_id LIMIT 0," . $limitOfRowsDisplayed;

   $sqlquery = generateStatement($fieldClause,$fromClause,$whereClause,$orderByClause);
// echo $sqlquery . "<br><br>";
   // Send request to database
   $result = $db->query($sqlquery);

   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());

   // Generate list with header
   $titleArray = array(getLngt("Vorgang") . "&nbsp;&nbsp;",getLngt("Zeitpunkt") . "&nbsp;&nbsp;",getLngt("Auftrag") . "&nbsp;&nbsp;",getLngt("Fahrzeug") . "&nbsp;&nbsp;",getLngt("Name") . "&nbsp;&nbsp;",getLngt("Vorname") . "&nbsp;&nbsp;",getLngt("Telefon") . "&nbsp;&nbsp;",getLngt("Details"));
   $fieldArray = array("logo_op_shortname","log_createtime","jb_id","cr_sid","usr_name","usr_firstname","usr_phone","logo_description");
   $aligns = "l,c,c,c,l,l,l,l";
   $alignArray = spliti(",",$aligns);
   $alignTitles = "center";
   $widths = "330,130,50,50,150,150,80,200";
   $widthArray = spliti(",",$widths);
   $summationField = "";
   $postParserField = "logo_description";
   $mode = "1";             // Output from DB-RESULT
   $sortDBField = "";       // Used in following include-file for sorting per column;
   if ($logoselection > "0" && count($typeArray["logomapping"]) > 0) :
      $noDisplayBoolCondition = array("log_createtime", ">=", $fromDateRange);
   endif;
   // $checkDifferences = true;
   include ("../include/inc_list_defineoutput.inc.php");

   $result->free();
   
   
   // *** ONLY OUTPUT ***
   
   // Courier
   $crSid = getFieldValueFromId("courier", "cr_id", $cr_id, "cr_sid");
   $crUsrId = getFieldValueFromId("courier", "cr_id", $cr_id, "usr_id");
   $tmpFields = getFieldsValueFromId("user","usr_id",$crUsrId,array("usr_firstname","usr_name"));
   $crUsrFirstname = $tmpFields[0];
   $crUsrName = $tmpFields[1];
   
   // Post parsing if necessary
   if ($postParserField != "") :
      $tableBody = postParseCrHistory($tableBody, $crSid, ($logoselection > "0" ? true : false));
   endif;

   // Invert all occurrences of "<tr>"
   $tableBody = reverseOuterTableRows($tableBody);
endif;


// --- JOB HISTORY ------------------
if ($typeArray["mode"] == "jb") :

   // From table "log"
   $fieldClause = getDBFields("logoperation") . "," . getDBFields("log") . "," . getDBFields("user") . " ";
   
   $fromClause = "phoenix_log.logoperation AS logo, phoenix_log." . $dbh_log . " AS log " .
                 "LEFT JOIN phoenix.user AS usr ON log.usr_id = usr.usr_id ";

   // $whereClause = "log.jb_id = '" . $job_id . "' AND log.hq_id = '" . $hq_id . "' AND log.logo_id = logo.logo_id";
   $whereClause = "log.jb_id = '" . $job_id . "' AND log.logo_id = logo.logo_id";
   
   // $orderByClause = "log.log_createtime";
   $orderByClause = "log.log_id DESC";

   $sqlquery = generateStatement($fieldClause,$fromClause,$whereClause,$orderByClause);

   // Send request to database
   $result = $db->query($sqlquery);

   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());

   // Generate list with header
   $titleArray = array(getLngt("Vorgang") . "&nbsp;&nbsp;",getLngt("Zeitpunkt") . "&nbsp;&nbsp;",getLngt("Fahrzeug") . "&nbsp;&nbsp;",getLngt("Name") . "&nbsp;&nbsp;",getLngt("Vorname") . "&nbsp;&nbsp;",getLngt("Telefon") . "&nbsp;&nbsp;",getLngt("Details"));
   $fieldArray = array("logo_op_shortname","log_createtime","cr_sid","usr_name","usr_firstname","usr_phone","logo_description");
   $aligns = "l,c,c,l,l,l,l";
   $alignArray = spliti(",",$aligns);
   $alignTitles = "center";
   $widths = "330,130,50,150,150,80,200";
   $widthArray = spliti(",",$widths);
   $summationField = "";
   $postParserField = "logo_description";
   $mode = "1";             // Output from DB-RESULT
   $sortDBField = "";       // Used in following include-file for sorting per column;
   include ("../include/inc_list_defineoutput.inc.php");
   $historyentry = $tableHeader . $tableBody;

   $result->free();


   // *** ONLY OUTPUT ***
   
   // Job
   // $jbXXXX = getFieldValueFromId("job", "jb_id", $job_id, "jb_XXXX");
   
   // Post parsing if necessary
   if ($postParserField != "") :
      $tableBody = postParseJbHistory($tableBody);
   endif;

   // Invert all occurrences of "<tr>"
   $tableBody = reverseOuterTableRows($tableBody);
endif;


// --- ARTICLE HISTORY ------------------
if ($typeArray["mode"] == "at") :

   // From table "log"
   $fieldClause = getDBFields("logoperation") . "," . getDBFields("log") . "," . getDBFields("user") . " ";
   
   $fromClause = "phoenix_log.logoperation AS logo, phoenix_log." . $dbh_log . " AS log " .
                 "LEFT JOIN phoenix.user AS usr ON log.usr_id = usr.usr_id ";

   // $whereClause = "log.at_id = '" . $at_id . "' AND log.hq_id = '" . $hq_id . "' AND log.logo_id = logo.logo_id AND ";
   $whereClause = "log.at_id = '" . $at_id . "' AND log.logo_id = logo.logo_id AND ";
   $whereClause .= "log.log_createtime >= '$fromDateRange' AND log.log_createtime <= '$toDateRange'";

   // $orderByClause = "log.log_createtime LIMIT 0," . $limitOfRowsDisplayed;
   $orderByClause = "log.log_id LIMIT 0," . $limitOfRowsDisplayed;

   $sqlquery = generateStatement($fieldClause,$fromClause,$whereClause,$orderByClause);

   // Send request to database
   $result = $db->query($sqlquery);

   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());

   // Generate list with header
   $titleArray = array(getLngt("Vorgang") . "&nbsp;&nbsp;",getLngt("Zeitpunkt") . "&nbsp;&nbsp;",getLngt("Name") . "&nbsp;&nbsp;",getLngt("Vorname") . "&nbsp;&nbsp;",getLngt("Telefon") . "&nbsp;&nbsp;",getLngt("Details"));
   $fieldArray = array("logo_op_shortname","log_createtime","usr_name","usr_firstname","usr_phone","logo_description");
   $aligns = "l,c,l,l,l,l";
   $alignArray = spliti(",",$aligns);
   $alignTitles = "center";
   $widths = "180,130,150,150,80,350";
   $widthArray = spliti(",",$widths);
   $summationField = "";
   $postParserField = "logo_description";
   $mode = "1";             // Output from DB-RESULT
   $sortDBField = "";       // Used in following include-file for sorting per column;
   include ("../include/inc_list_defineoutput.inc.php");

   $result->free();
   
   // *** ONLY OUTPUT ***
   
   // Article
   $tmpFields = getFieldsValueFromId("article","at_id",$at_id,array("at_name","at_eid"));
   $atName  = $tmpFields[0];
   $atEid = $tmpFields[1];
   
   // Post parsing if necessary
   if ($postParserField != "") :
      $tableBody = postParseAtHistory($tableBody);
   endif;

   // Invert all occurrences of "<tr>"
   $tableBody = reverseOuterTableRows($tableBody);
endif;


// --- EMPLOYEE HISTORY ------------------
if ($typeArray["mode"] == "emp") :

   // From table "log"
   $fieldClause = getDBFields("logoperation") . "," . getDBFields("log") . "," . getDBFields("user") . " ";

   $fromClause = "phoenix_log.logoperation AS logo, phoenix_log." . $dbh_log . " AS log " 
               . "LEFT JOIN phoenix.user AS usr ON log.usr_id = usr.usr_id ";

   $whereClause = "";
   if ($empIdHist != "0") :
      $whereClause .= "log.emp_id = '" . $empIdHist . "' AND ";
   endif;
   $whereClause .= "log.logo_id = logo.logo_id AND log.log_createtime >= '$fromDateRange' AND log.log_createtime <= '$toDateRange' AND logo_op_category = 'emp' ";
   // $orderByClause = "log.log_createtime LIMIT 0," . $limitOfRowsDisplayed;
   $orderByClause = "log.log_id LIMIT 0," . $limitOfRowsDisplayed;

   $sqlquery = generateStatement($fieldClause,$fromClause,$whereClause,$orderByClause);

   // Send request to database
   $result = $db->query($sqlquery);

   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());

   // Generate list with header
   $titleArray = array(getLngt("Vorgang") . "&nbsp;&nbsp;",getLngt("Zeitpunkt") . "&nbsp;&nbsp;",getLngt("Name") . "&nbsp;&nbsp;",getLngt("Vorname") . "&nbsp;&nbsp;",getLngt("Telefon") . "&nbsp;&nbsp;",getLngt("Details"));
   $fieldArray = array("logo_op_shortname","log_createtime","usr_name","usr_firstname","usr_phone","logo_description");
   $aligns = "l,c,l,l,l,l";
   $alignArray = spliti(",",$aligns);
   $alignTitles = "center";
   $widths = "330,130,150,150,80,300";
   $widthArray = spliti(",",$widths);
   $summationField = "";
   $postParserField = "logo_description";
   $mode = "1";             // Output from DB-RESULT
   $sortDBField = "";       // Used in following include-file for sorting per column;
   include ("../include/inc_list_defineoutput.inc.php");

   $result->free();
   
   
   // *** ONLY OUTPUT ***
   
   // Employee
   $usrIdHist = getFieldValueFromId("employee", "emp_id", $empIdHist, "usr_id");
   $tmpFields = getFieldsValueFromId("user","usr_id",$usrIdHist,array("usr_firstname","usr_name"));
   $empUsrFirstname = $tmpFields[0];
   $empUsrName = $tmpFields[1];
   
   // Post parsing if necessary
   if ($postParserField != "") :
      $tableBody = postParseEmpHistory($tableBody, $crSid);
   endif;

   // Invert all occurrences of "<tr>"
   $tableBody = reverseOuterTableRows($tableBody);
endif;


// Define output table
$historyentry = $tableHeader . $tableBody;   

$currentFrameName = "";  // Empty string for "main frame"


$filter_dateranges = "";
$js_date = "";
if ($op == "0" && $typeArray["dateselection"] == "1") :
   // Date-ranges 
   $filter_dateranges .= "<td>" . getLngt("Von:") . "\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><td>&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";
endif;

// Output headline
$pageHeadline = $pageTitel . ":&nbsp;&nbsp;&nbsp;";
if ($typeArray["mode"] == "cs") : 
   $pageHeadline .= $csCmpComp . " " . $csCmpComp2; 
elseif ($typeArray["mode"] == "cr") : 
   $pageHeadline .= $crUsrFirstname . " " . $crUsrName; 
elseif ($typeArray["mode"] == "jb") : 
   $pageHeadline .= $job_id;
elseif ($typeArray["mode"] == "at") : 
   $pageHeadline .= $atName . " (" . $atEid . ")";
elseif ($typeArray["mode"] == "emp") : 
   $pageHeadline .= $empUsrFirstname . " " . $empUsrName;
endif; 
?>

<html>

<head>
<title><?php echo $pageTitel ?> <?php if ($typeArray["mode"] == "cs") : echo $csCmpComp; elseif ($typeArray["mode"] == "cr") : echo $crUsrFirstname . " " . $crUsrName; elseif ($typeArray["mode"] == "jb") : echo $job_id; elseif ($typeArray["mode"] == "at") : echo $atEid; endif; ?></title>

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

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

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

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

function setDisplaySelection() {
	var logoSelectionVal = $('#logoselection').val();
	if (logoSelectionVal > 0) {
		 $('#displayselection').val('1');
	} else {
		 $('#displayselection').val('0');
	}	
}

function checkLogoSelection() {
	var logoSelectionVal = $('#logoselection').val();
	var displaySelectionVal = $('#displayselection').val();
	if (displaySelectionVal > 0) {
		 if (logoSelectionVal == 0) {
		    $('#displayselection').val('0');
		    alert('<?php echo getLngt("Sie müssen einen Filter selektieren, um nur die geänderten Werte anzuzeigen") ?>');
		 } else {
		 	  $(".state_not_changed").hide();
		 }
	} else {
		$(".state_not_changed").show();
	}	
}

</script>

<?php echo $js_date ?>

</head>

<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?><?php echo ($op == "0" ? "initForm();" : "") ?>setDisplaySelection();checkLogoSelection();">

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

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

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

<form name="history" action="../admin/history.php" method="post">

  <input type="hidden" name="history_mode" value="<?php echo ec($history_mode) ?>">
  <input type="hidden" name="cs_id" value="<?php echo ec($cs_id) ?>">
  <input type="hidden" name="cr_id" value="<?php echo ec($cr_id) ?>">
  <input type="hidden" name="job_id" value="<?php echo ec($job_id) ?>">
  <input type="hidden" name="at_id" value="<?php echo ec($at_id) ?>">
  <input type="hidden" name="empIdHist" value="<?php echo ec($empIdHist) ?>">
  <input type="hidden" name="op" value="<?php echo ec($op) ?>">
  <?php echo $phpCurrentNavigationInputHidden ?>
  <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">

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

  <div>
    <!- Date-ranges and filter -->
    <div 
    	<?php echo setStyleHtmlDiv("700px","left"); ?>><?php echo $filter_dateranges ?>
    	<?php 
    	  if ($op == "0" && $typeArray["logoselection"] != "") :
    	     echo "&nbsp;&nbsp;&nbsp;&nbsp;" . $typeArray["logoselection"] . "&nbsp;&nbsp;";
    	  else :
    	     echo "<input type=\"hidden\" id=\"logoselection\" name=\"logoselection\" value=\"" . $logoselection . "\">";
           echo "<input type=\"hidden\" id=\"displayselection\" name=\"displayselection\" value=\"" . $displayselection . "\">";
    	  endif; 
    	?>
    </div>

    <!- Actions -->
    <div>
      <?php if ($op == "0") : echo defineButton(getLngt("Aktualisieren"), "action_refresh", "submitPage();", "left", "5", "", "", "115px"); endif; ?>
      <?php // echo defineButton(getLngt("Schließen"), "action_close", "window.close();", "left", "", "", "", "115px"); ?>
    </div>
  </div>

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

  <div>   
   <?php if ($rowCounter >= $limitOfRowsDisplayed) : echo getLngt("Mehr als") . " " . $limitOfRowsDisplayed . " " . getLngt("Datensätze werden nicht dargestellt"); endif; ?>
   <?php echo htmlDivLineSpacer("15px"); ?>
  </div>

  <!- History -->
  <div>
   <table cellspacing="0" cellpadding="0" vspace="0" hspace="0">
     <?php echo $historyentry ?>     
   </table>
  </div>

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

</html>
