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

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


$httpVars = array("f_act", "actionMode", "filterType", "customerId", "courierId", "crfIdAction", "f_crvh_filter", "f_crvh_filter_str",
                  "f_crf_edit_enabled", "f_crf_modify_enabled", "f_crf_type", "f_crf_status", "f_crf_short", "f_crf_text", "f_crf_sort",
                  "f_crf_order_by", "orderClause", "statusMessage", "deactivateMenu", "openerParameter", "readonly", "crf_admin");

getSecHttpVars("1", $httpVars);

getLanguage(__FILE__);

if ($crf_admin == "" || $crf_admin != "100") :
   $deactivateMenuStatic = "1";
endif;
$pageTitel = getLngt("AUFTRAGSFILTER");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
include_once ("../include/inc_filters.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);
authCheckEmployeeRights($emp_id, "0", "1");

$outputJS = "";
$crfTextRightToEdit = "0";
if ($crf_admin == "100" &&  authCheckEmployeeRights($emp_id, "32")) :
   $crfTextRightToEdit = "1";
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// if (true || $usr_id != "300001") : $crfTextRightToEdit = "0"; $f_crf_edit_enabled = "0"; $f_crf_modify_enabled = "0"; endif;  // !!!!!!!!!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
endif;

// Flag for displaying filter texts
if (mcIsSet($f_crf_edit_enabled) == "" || (is_array($f_crf_edit_enabled) && count($f_crf_edit_enabled) == 0)) :
   $f_crf_edit_enabled = "0";
else: 
   $f_crf_edit_enabled = "1";
   if ($crfTextRightToEdit != "1") :
      $f_crf_edit_enabled = "0";
   endif;
endif;
$f_crf_edit_enabled_0 = "";
if ($f_crf_edit_enabled == "1") : $f_crf_edit_enabled_0 = "checked"; endif;

// Flag for modifying filters
if ($f_crf_modify_enabled == "" || count($f_crf_modify_enabled) == 0) :
   $f_crf_modify_enabled = "0";
else: 
   $f_crf_modify_enabled = "1";
   if ($crfTextRightToEdit != "1") :
      $f_crf_modify_enabled = "0";
   endif;
endif;
$f_crf_modify_enabled_0 = "";
if ($f_crf_modify_enabled == "1") : $f_crf_modify_enabled_0 = "checked"; endif;

if ($actionMode == "") : $actionMode = "0"; endif;     // ["0" = Returns filter string per JS (default) / "1" = Returns customer filters]
if ($openerParameter == "") : $openerParameter = "g_crvh_filter"; endif;    // Name of the parameter of the opener 
if ($filterType != "" && !is_numeric($filterType)) : $filterType = ""; endif;    // Filter type [0 = crvh (default), 1 = cr, ....]
if ($f_crf_order_by == "" || !is_numeric($f_crf_order_by)) : $f_crf_order_by = "0"; endif; 

if ($f_crvh_filter_str != "") :
   if (substr($f_crvh_filter_str, 0, 1) != ",") : $f_crvh_filter_str = "," . $f_crvh_filter_str; endif;
   if (substr($f_crvh_filter_str, -1) != ",") : $f_crvh_filter_str = $f_crvh_filter_str . ","; endif;
else :
   // Implode checked courier filter fields to store in DB
   $f_crvh_filter_str = getImplodedFilterstring($f_crvh_filter);
endif;


// Modify filter
$retFilters = 0;
if ($f_act == "modifyFilter") :

   if ($actionMode == "0") :
      // Return filter string
      $f_crvh_filter_str = substr($f_crvh_filter_str, 1);      // Remove first comma
      $f_crvh_filter_str = substr($f_crvh_filter_str, 0, -1);  // Remove last comma
      $retFilters = 1;
   endif;

   if ($customerId != "") :
      if ($actionMode == "1") :
         // TA("B");         
         // Update customer filter
         updateStmt("customer","cs_id",$customerId,array("cs_filter ", $f_crvh_filter_str));
         // TA("C");
         // TA("E");
      endif;
   endif;

   if ($courierId != "") :
      if ($actionMode == "1") :
         // TA("B");         
         // Update courier filter
         updateStmt("courier","cr_id",$courierId,array("cr_filter ", $f_crvh_filter_str));
         // TA("C");
         // TA("E");
      endif;
   endif;
endif;

// Insert filter
if ($f_act == "insertFilter") :
   $f_crf_short = trim($f_crf_short);
   $f_crf_text = trim($f_crf_text);
   if ($f_crf_sort == "" || !is_numeric($f_crf_sort)) : 
      $f_crf_sort = "0";
   endif;
   if ($f_crf_short != "" && $f_crf_text != "") :
      // Check lock regarding queue of filters to be removed
      $doRemove = true;
      $parCrfToBeRemoved = getParameterValue("0", "FILTER_TO_BE_DELETED", "0", "0");
      if ($parCrfToBeRemoved != "") :
         if (strpos($parCrfToBeRemoved, "," . $f_crf_short . ",") !== false) :
            $doRemove = false;
         endif;
      endif;
      if ($doRemove) :
         insertStmt("courierfilter", array("crf_type", $f_crf_type, "crf_short", $f_crf_short, "crf_text", $f_crf_text, "crf_status", $f_crf_status, "vht_id", "0", "crf_sort", $f_crf_sort));
         $crfIdNew = getLastInsertId();
         // Write logdata into log database
         writeToLogDB("168",$hq_id,"",$usr_id,"","","","crf_id=" . $crfIdNew . "|crf_type=" . $f_crf_type . "|crf_short=" . $f_crf_short . "|crf_text=" . $f_crf_text . "|crf_status=" . $f_crf_status . "|vht_id=" . "0" . "|crf_sort=" . $f_crf_sort);
         $statusMessage = getLngt("Der Filter wurde hinzugefügt!");
      else :
         $statusMessage = getLngt("ACHTUNG! Der Filter wurde NICHT hinzugefügt. Das gewünschte Kürzel") . " " . $f_crf_short . " " . getLngt("wurde erst kürzlich gelöscht und transaktionell noch nicht vollständig verarbeitet, so z.B. die Entfernung aus allen relevanten Aufträgen, etc.") . " " . getLngt("Vermutlich können Sie den neuen Filter am morgigen Tag anlegen!");
      endif;
   endif;
endif;

// Remove filter
if ($f_act == "removeFilter") :
   if ($crfIdAction != "" && is_numeric($crfIdAction)) :   
      // Get current values before removing
      $crfFields = getFieldsValueFromId("courierfilter", "crf_id", $crfIdAction, array("crf_type","crf_short","crf_text","crf_status","vht_id","crf_sort","crf_longtext"));
      $crfShort = $crfFields[1];
      if ($crfShort != "") :
         TA("B");
         // * Table "courierfilter" *
         deleteStmt("courierfilter","crf_id = ".$crfIdAction);

         // * Table "job" *
         $parCrfToBeRemoved = getParameterValue("0", "FILTER_TO_BE_DELETED", "0", "0");
         if ($parCrfToBeRemoved == "") :
            setParameterValue("FILTER_TO_BE_DELETED", "," . $crfShort . ",");
         else :
            setParameterValue("FILTER_TO_BE_DELETED", $parCrfToBeRemoved . $crfShort . ",");
         endif;

         // * Table "customer" *
         $sqlquery = "UPDATE customer,
                             (SELECT cs.cs_id FROM customer AS cs, company AS cmp WHERE cs.cs_filter != '' AND cs.cmp_id = cmp.cmp_id AND cmp.cmp_archived = '0') AS cs_relevant
                        SET cs_filter = REPLACE(cs_filter, '," . $crfShort . ",', ','), cs_modify = cs_modify
                        WHERE customer.cs_id = cs_relevant.cs_id";
         $result = $db->query($sqlquery);
         if (DB::isError($result)) die ("$PHP_SELF: <br>$sqlquery<br>" . $result->getMessage());
         // Clean up
         $sqlquery = "UPDATE customer,
                             (SELECT cs.cs_id FROM customer AS cs, company AS cmp WHERE cs.cs_filter = ',' AND cs.cmp_id = cmp.cmp_id AND cmp.cmp_archived = '0') AS cs_relevant
                        SET cs_filter = '', cs_modify = cs_modify
                        WHERE customer.cs_id = cs_relevant.cs_id";
         $result = $db->query($sqlquery);
         if (DB::isError($result)) die ("$PHP_SELF: <br>$sqlquery<br>" . $result->getMessage());
         
         // * Table "courier" *
         $sqlquery = "UPDATE courier,
                             (SELECT cr.cr_id FROM courier AS cr, company AS cmp WHERE cr.cr_filter != '' AND cr.cmp_id = cmp.cmp_id AND cmp.cmp_archived = '0') AS cr_relevant
                        SET cr_filter = REPLACE(cr_filter, '," . $crfShort . ",', ','), cr_modify = cr_modify
                        WHERE courier.cr_id = cr_relevant.cr_id";
         $result = $db->query($sqlquery);
         if (DB::isError($result)) die ("$PHP_SELF: <br>$sqlquery<br>" . $result->getMessage());
         // Clean up
         $sqlquery = "UPDATE courier,
                             (SELECT cr.cr_id FROM courier AS cr, company AS cmp WHERE cr.cr_filter = ',' AND cr.cmp_id = cmp.cmp_id AND cmp.cmp_archived = '0') AS cr_relevant
                        SET cr_filter = '', cr_modify = cr_modify
                        WHERE courier.cr_id = cr_relevant.cr_id";
         $result = $db->query($sqlquery);
         if (DB::isError($result)) die ("$PHP_SELF: <br>$sqlquery<br>" . $result->getMessage());
         
         // * Table "couriervehicle" *
         $sqlquery = "UPDATE couriervehicle
                        SET crvh_filter = REPLACE(crvh_filter, '," . $crfShort . ",', ','), crvh_modify = crvh_modify";
         $result = $db->query($sqlquery);
         if (DB::isError($result)) die ("$PHP_SELF: <br>$sqlquery<br>" . $result->getMessage());
         // Clean up
         $sqlquery = "UPDATE couriervehicle
                        SET crvh_filter = '', crvh_modify = crvh_modify
                        WHERE crvh_filter = ','";
         $result = $db->query($sqlquery);
         if (DB::isError($result)) die ("$PHP_SELF: <br>$sqlquery<br>" . $result->getMessage());

         // Write logdata into log database
         writeToLogDB("169",$hq_id,"",$usr_id,"","","","crf_id=" . $crfIdAction . "|crf_type=" . $crfFields[0] . "|crf_short=" . $crfFields[1] . "|crf_text=" . $crfFields[2] . "|crf_status=" . $crfFields[3] . "|vht_id=" . $crfFields[4] . "|crf_sort=" . $crfFields[5] . "|crf_longtext=" . $crfFields[6]);
         $statusMessage = getLngt("Der Filter wurde entfernt!");
         TA("C");
         TA("E");
      endif;
   endif;
endif;


// Only for output
$pageHeadline = getLngt("Filterauswahl");
if ($customerId != "") :
   // Get filters from customer
   $f_crvh_filter_str = getFieldValueFromId("customer","cs_id",$customerId,"cs_filter");

   $cmpId = getFieldValueFromId("customer", "cs_id", $customerId, "cmp_id");
   $tmpFields = getFieldsValueFromId("company","cmp_id",$cmpId,array("cmp_comp","cmp_comp2"));
   $cmpComp = $tmpFields[0];
   $cmpComp2 = $tmpFields[1];
   $pageHeadline = $cmpComp . " " . $cmpComp2;
endif;

if ($courierId != "") :
   // Get filters from customer
   $f_crvh_filter_str = getFieldValueFromId("courier","cr_id",$courierId,"cr_filter");

   $cmpId = getFieldValueFromId("courier", "cr_id", $courierId, "cmp_id");
   $tmpFields = getFieldsValueFromId("company","cmp_id",$cmpId,array("cmp_comp","cmp_comp2"));
   $cmpComp = $tmpFields[0];
   $cmpComp2 = $tmpFields[1];
   $pageHeadline = $cmpComp . " " . $cmpComp2;
endif;

// Selected filters
$output = getFilters($f_crvh_filter_str, $filterType, "", "100", "4", "1", "", $f_crf_edit_enabled, $f_crf_modify_enabled, $f_crf_order_by);

getCurrentScript(__FILE__);
?>

<html>

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

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

  .class_crf_lt_edit { width:180px; height:50px; background-color:#AAAACC; border:grey 3px solid; box-shadow: 10px 20px 30px grey; display: none;}
  .class_crf_lt_textarea { position: relative; width: 200px; height: 50px; }
</style>
<style type="text/css">
  <?php include_once ("../css/mc.css.php"); ?>
</style>

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

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

<script type="text/javascript">
<!--
var retFilters = <?php echo $retFilters ?>;
if (retFilters == 1) {
	 opener.document.forms[0].<?php echo $openerParameter ?>.value = '<?php echo $f_crvh_filter_str ?>';
	 window.close();
}

// NAVIGATION
<?php echo $jsMenuOut; ?>

function openCourierfilterSort() {	
  var widthPopupWin = 800;
  var heightPopupWin = 1024;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/sort.php?deactivateMenu=1&objType=crf&objId=0&noMap=1","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");  
};

function finishPage(mode) {
  var doSubmit = true;
  var msg = '';

  if (mode == 'save') {
     document.forms[0].f_act.value='modifyFilter';
     document.forms[0].submit();
  }
  if (mode == 'insert') {
     document.forms[0].f_act.value='insertFilter';
     if ($('#f_crf_type').val() != 0 && $('#f_crf_type').val() != 1) {
        doSubmit = false;
        msg = '<?php echo getLngt("Bitte die Art des Filters bestimmen (Transporteursfilter oder Fahrzeugfilter)!") ?>';
     }
     if ($('#f_crf_status').val() != 1 && $('#f_crf_status').val() != 2) {
        doSubmit = false;
        msg = '<?php echo getLngt("Bitte den Typ des Filters bestimmen (Pflichtfilter oder optionaler Filter)!") ?>';
     }
     if ($('#f_crf_sort').val() == '' || isNaN($('#f_crf_sort').val()) ) {
        // doSubmit = false;
        msg = '<?php echo getLngt("Es wurde keine Sortierungsnummer erfasst. Diese wird vorerst auf 0 gesetzt!") ?>';
     }
     if (trim($('#f_crf_short').val()) == '') {
        doSubmit = false;
        msg = '<?php echo getLngt("Bitte das Kürzel festlegen!") ?>';
     } else {
     	  // Check existence of the new value in "crf.crf_short"
     	  ajaxRequestGet('../include/ajaxReqLib.php', 'mode=0&db_table=courierfilter&db_id_field=crf_short&search_value=' + encodeURI(escape(trim($('#f_crf_short').val()))) + '&db_return_field=crf_id');
     	  if (retValue != '' || isNaN(retValue)) {
           doSubmit = false;
           msg = '<?php echo getLngt("Das Kürzel existiert schon, bitte wählen Sie ein anderes!") ?>';
     	  }
     }
     if (trim($('#f_crf_text').val()) == '') {
        doSubmit = false;
        msg = '<?php echo getLngt("Bitte die Bezeichnung festlegen!") ?>';
     } else {
     	  // Check existence of the new value in "crf.crf_text"
     	  ajaxRequestGet('../include/ajaxReqLib.php', 'mode=0&db_table=courierfilter&db_id_field=crf_text&search_value=' + encodeURI(escape(trim($('#f_crf_text').val()))) + '&db_return_field=crf_id');
     	  if (retValue != '' || isNaN(retValue)) {
           doSubmit = false;
           msg = '<?php echo getLngt("Die Bezeichnung existiert schon!") ?>';
     	  }
     }
     if (doSubmit) {
     	  if (!confirm('<?php echo getLngt("Soll der neue Filter angelegt werden?") ?>')) {
           doSubmit = false;
           msg = '<?php echo getLngt("Der Filter wurde nicht eingefügt!") ?>';
     	  }
     }
  }
  if (mode == 'remove') {
     document.forms[0].f_act.value='removeFilter';
  }
  if (mode == 'sort') {
     // document.forms[0].f_act.value='sortFilter';
     openCourierfilterSort();
  }

  if (msg != '') {
  	 alert(msg);
  }

  if (doSubmit) {
     document.forms[0].submit();
  } else {
  	 document.forms[0].f_act.value='';
  }
};

function containerAction (elemId, elemVisual = '', elemVal = '_noAction_') {
	<?php if ($f_crf_edit_enabled == "1") : ?>
	if (elemVal != '_noAction_') {
	   $('#' + elemId).val(elemVal);
  }
  if (elemVisual == 'hide') {
     myhide(elemId);
  } else if (elemVisual == 'show') {
  	 myshow(elemId);
  }
  <?php endif; ?>
}

function saveCrfLongtext (crfId, elemId, partTextLen = 100) {	
	<?php if ($f_crf_edit_enabled == "1") : ?>
  if (elemId) {
// alert('crfId = ' + crfId + ' :: elemId = ' + elemId.value);
  	if (confirm('<?php echo getLngt("Soll der neue Text gespeichert werden?") ?>')) {
  		 elemVal = elemId.value;
  		 elemVal = elemVal.replace(/'/g, '');
  		 if (true) {
          // Update new longtext value in courierfilter
          ajaxRequestGet('../include/ajaxReqLib.php', 'mode=100&db_table=courierfilter&db_id_field=crf_id&db_op_field=crf_longtext&new_content=' + encodeURI(escape(elemVal)) + '&search_value=' + crfId);
          // Insert into log
          ajaxRequestGet('../include/ajaxReqLib.php', 'mode=300&db_id_field=170&db_op_field=crf&search_value=' + crfId + '&id_01=crf_id&value_01=' + crfId + '&id_02=crf_longtext&value_02=' + encodeURI(escape(elemVal)));
          // Refresh main output field with the new value
          var buttonStr = '&nbsp;&nbsp;<input type="button" style="width: 10px; height: 10px; vertical-align: middle;" id="crf_' + crfId + '" value="" onClick="containerAction(\'crf_lt_edit_' + crfId + '\', \'show\');">';
          var dotStr = '';
          if (elemVal.length > partTextLen) {
          	 dotStr = '....';
          }
          $('#crf_lt_part_' + crfId).html(elemVal.substr(0, partTextLen) + dotStr + buttonStr);
          containerAction('crf_lt_part_' + crfId, 'show');
          // Rewrite ....
          // ajaxRequestGet('../include/ajaxReqGeneric.php', 'incPath=include&incFile=caglobal.inc.php&fun=mk_jb_invtext_full&par_01=' + crfId + '&retIdx=0');
          // Reload ....
          // ajaxRequestGet('../include/ajaxReqLib.php', 'mode=0&db_table=job&db_id_field=jb_id&search_value=' + crfId + '&db_return_field=jb_invtext');
          // if (retValue != '') {
          // 	  $('#f_jb_invtext_new').html(retValue);
          // }
       // } else {
       // 	  alert('<?php echo getLngt("....") ?>');
       }
    }
  } else {
  	alert('<?php echo getLngt("Das hat leider nicht geklappt!") ?>');
  }
	<?php endif; ?>
}

function crfSortUpdate (crfId, crfSort) {
  <?php if ($f_crf_modify_enabled == "1") : ?>
// alert('crfId = ' + crfId + ' :: crfSort = ' + crfSort);
  if (true) {
     // Update
     ajaxRequestGet('../include/ajaxReqLib.php', 'mode=100&db_table=courierfilter&db_id_field=crf_id&db_op_field=crf_sort&new_content=' + crfSort + '&search_value=' + crfId);
     // Insert into log
     ajaxRequestGet('../include/ajaxReqLib.php', 'mode=300&db_id_field=171&db_op_field=crf&search_value=' + crfId + '&id_01=crf_id&value_01=' + crfId + '&id_02=crf_sort&value_02=' + crfSort);
  }
  <?php endif; ?>
}

function removeCrf (crfId, crfShort, crfText) {
  <?php if ($f_crf_modify_enabled == "1") : ?>
  if (confirm('<?php echo getLngt("Soll der Filter ' + crfShort + ' [' + crfText + '] wirklich gelöscht werden?") ?>')) {
     document.forms[0].crfIdAction.value = crfId;
     finishPage('remove');
  }
  <?php endif; ?>
}
-->
</script>

</head>

<body class="menu_bgcol" onLoad="<?php echo $phpCurrentNavigationOnLoad ?><?php echo $outputJS ?>displayStatusMessage();">

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

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

<?php if ($f_crf_modify_enabled != "1") : ?>
<div class="f10bp1_blue">
  <?php
    if ($readonly != "1") :
       echo defineButtonType10(getLngt("Speichern"), "action_save", "finishPage('save');", "120", "left", "0");
    endif;
  ?>
  <?php 
    if ($deactivateMenuStatic == "1") :
       echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "120", "left", "0"); 
    endif;
  ?>
</div>
<?php endif; ?>

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

<form action="../admin/filter.php" method="post">
  <input type="hidden" name="f_act" value="">
  <input type="hidden" name="filterType" value="<?php echo ec($filterType) ?>">
  <input type="hidden" name="actionMode" value="<?php echo ec($actionMode) ?>">
  <input type="hidden" name="openerParameter" value="<?php echo ec($openerParameter) ?>">
  <input type="hidden" name="customerId" value="<?php echo ec($customerId) ?>">
  <input type="hidden" name="courierId" value="<?php echo ec($courierId) ?>">
  <input type="hidden" name="crfIdAction" value="">
  <?php echo $phpCurrentNavigationInputHidden ?>
  <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
  <input type="hidden" name="crf_admin" value="<?php echo ec($crf_admin) ?>">

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

  <?php
    if ($crfTextRightToEdit == "1") :
       echo '
       <div style="float:left;">
       ' . getLngt("Sortierung nach") . '&nbsp;&nbsp;
       <select class="f8np1" name="f_crf_order_by" onChange="document.forms[0].submit();">
         <option value="0" ' . ($f_crf_order_by == "0" ? "selected" : "") . '>' . getLngt("Kürzel") . '</option>
         <option value="1" ' . ($f_crf_order_by == "1" ? "selected" : "") . '>' . getLngt("Bezeichnung") . '</option>
         <option value="2" ' . ($f_crf_order_by == "2" ? "selected" : "") . '>' . getLngt("Sortiernr.") . '</option>
       </select>&nbsp;&nbsp;&nbsp;&nbsp;
       ' . getLngt("Weitere Filterelemente anzeigen") . '&nbsp;&nbsp;
       <input type="checkbox" name="f_crf_edit_enabled[]" value="' . $row["crf_short"] . '" ' . $f_crf_edit_enabled_0 . ' onChange="document.forms[0].submit();">
       &nbsp;&nbsp;&nbsp;&nbsp;
       ' . getLngt("Filter verwalten") . '&nbsp;&nbsp;
       <input type="checkbox" name="f_crf_modify_enabled[]" value="' . $row["crf_short"] . '" ' . $f_crf_modify_enabled_0 . ' onChange="document.forms[0].submit();">
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
       </div>
       ';
       echo defineButtonType08(getLngt("Sortieren"), "action_sort", "finishPage('sort');", "80");
       echo htmlDivLineSpacer("20px");

       if ($f_crf_modify_enabled == "1") :
          echo '
          <div style="float:left;">
            <select class="f8np1" id="f_crf_type" name="f_crf_type">
              <option value="0" selected>' . getLngt("Fahrzeugfilter") . '</option>
              <option value="1">' . getLngt("Transporteursfilter") . '</option>
            </select>
            <select class="f8np1" id="f_crf_status" name="f_crf_status">
              <option value="1" selected>' . getLngt("Pflichtfilter") . '</option>
              <option value="2">' . getLngt("Optionaler Filter") . '</option>
            </select>
            <input type="text" class="f8np1" id="f_crf_short" name="f_crf_short" value="" size="4" maxlength="4" placeholder="' . getLngt("Kürzel") . '">
            <input type="text" class="f8np1" id="f_crf_text" name="f_crf_text" value="" size="30" maxlength="50" placeholder="' . getLngt("Bezeichnung") . '">
            <input type="text" class="f8np1" id="f_crf_sort" name="f_crf_sort" value="" size="5" maxlength="7" placeholder="' . getLngt("Sort.") . '">
            &nbsp;&nbsp;
          </div>          
          ';
          echo defineButtonType08(getLngt("Anlegen"), "action_insert", "finishPage('insert');", "80", "left", "3");
          echo htmlDivLineSpacer("30px");
       endif;
    else :
       echo "<input type=\"hidden\" name=\"f_crf_edit_enabled\" value=\"0\">";
    endif;
  ?>  

  <!-- Filter -->
  <div>
    <table>
      <tr>
        <td>          
          <?php echo $output ?>
        </td>      
      </tr>
    </table>
  </div>
  
  <?php // echo htmlDivLineSpacer("15px"); ?>
  
</form>
</div>
</body>

</html>
