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

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

// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "f_mode", "companyId", "orderClause", "statusMessage", "f_cmp_authenticated",
                         "f_cmp_comp", "f_cmp_comp2", "f_cmp_comp3", "f_cmp_comp4", "f_cmp_match", "f_cs_eid", 
                         "f_cs_discount", "f_usr_phone", "f_usr_email", "f_usr_inv_email", "f_usr_reminder_email", "f_usr_name", "f_usr_firstname", 
                         "f_ad_street", "f_cmp_hsno", "f_ad_zipcode", "f_ad_city", "f_searchmode", "f_show_invisible", 
                         "f_hide_notauthenticated", "f_show_only_invisible", "f_show_only_jbedit", "f_show_only_old_eid", "f_show_allcustomers", 
                         "f_no_metacustomer", "f_with_metacustomer", "f_with_discount", "f_cmp_type", "f_hq_id", "deactivateMenu", 
                         "csExtendedFlag", "csExportIt", "csExportDelimiter", "f_cmp_new_date_month", "f_cmp_new_date_year", 
                         "f_exp_cmp_comp", "f_exp_cmp_comp2", "f_exp_cmp_comp3", "f_exp_cmp_comp4", "f_br_key", "f_br_name", 
                         "f_exp_ad_street", "f_exp_cmp_hsno", "f_exp_ad_zipcode", "f_cs_eid_old", "f_cs_become_cs_date",
                         "f_exp_ad_city", "f_exp_cmp_match", "f_exp_cs_eid", "f_exp_usr_phone", "f_exp_usr_email", 
                         "f_exp_usr_name", "f_exp_usr_firstname", "f_exp_br_key", "f_exp_br_name", "f_branch", "f_cmp_sales_ranking_man",
                         "f_cmp_sustainability_email", "f_cmp_stax_idno", "f_tx_sign", "f_tx_value", "f_cmp_inv2hq", "f_mt_value_payment_term",
                         "f_cscad_service_street", "f_cscad_service_zipcode", "f_cscad_service_city", "f_cscad_invoice_street", "f_cscad_invoice_zipcode", "f_cscad_invoice_city", 
                         "f_cscad_pickup_street", "f_cscad_pickup_zipcode", "f_cscad_pickup_city"));

getLanguage(__FILE__);

$pageTitel = getLngt("KUNDEN");
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);
authCheckEmployeeRights($emp_id, "0", "1");

$htmlClass01 = "class=\"smaller\"";   // input,select
$htmlClass02 = "class=\"f7np1\"";     // write
$numOfRows = 0;

$pageHeadline = "";
$f_secretFileName = "";
$onLoadCall = "";
$tableOfRows = "";

// Flag for "show invisible customers"
if ($f_show_invisible == "" || count($f_show_invisible) == 0) :
   $f_show_invisible = "0";
else: 
   $f_show_invisible = "1";
endif;
// Flag for "show invisible customers ONLY" (sets $f_show_invisible automatically)
if ($f_show_only_invisible == "" || count($f_show_only_invisible) == 0) :
   $f_show_only_invisible = "0";
else: 
   $f_show_only_invisible = "1";
   $f_show_invisible = "1";  // Overrules (sets) $f_show_invisible
endif;
// Flag for "show customers WITH activated job edit option ONLY"
if ($f_show_only_jbedit == "" || count($f_show_only_jbedit) == 0) :
   $f_show_only_jbedit = "0";
else: 
   $f_show_only_jbedit = "1";
endif;
// Flag for "show customers WITH existing old EID ONLY"
if ($f_show_only_old_eid == "" || count($f_show_only_old_eid) == 0) :
   $f_show_only_old_eid = "0";
else: 
   $f_show_only_old_eid = "1";
endif;
// Flag for "hide not authenticated customers"
if ($f_hide_notauthenticated == "" || count($f_hide_notauthenticated) == 0) :
   $f_hide_notauthenticated = "0";
else: 
   $f_hide_notauthenticated = "1";
endif;
// Flag for "show all customers"
if ($f_show_allcustomers == "" || count($f_show_allcustomers) == 0) :
   $f_show_allcustomers = "0";
else: 
   $f_show_allcustomers = "1";
endif;
// Flag for "no relation to metacustomer"
if ($f_no_metacustomer == "" || count($f_no_metacustomer) == 0) :
   $f_no_metacustomer = "0";
else: 
   $f_no_metacustomer = "1";
endif;
// Flag for "with relation to metacustomer"
if ($f_with_metacustomer == "" || count($f_with_metacustomer) == 0) :
   $f_with_metacustomer = "0";
else: 
   $f_with_metacustomer = "1";
endif;
// Flag for "with discount"
if ($f_with_discount == "" || count($f_with_discount) == 0) :
   $f_with_discount = "0";
else: 
   $f_with_discount = "1";
endif;


$f_cmp_new_date = "";                                            // Filter (Only new customers since date)
if ($f_cmp_new_date_month != "" && $f_cmp_new_date_year != "") :
   $f_cmp_new_date = $f_cmp_new_date_year . "-" . pad($f_cmp_new_date_month,2) . "-01 00:00:00";
endif;

// Delimiter for export
if ($csExportDelimiter == "") : $csExportDelimiter = "|"; endif;

// Mandator filter
if ($f_hq_id == "") : $f_hq_id = array(); endif;
if (count($f_hq_id) == 0) : array_push($f_hq_id, $hq_id); endif;

// Get the parameter to set the order of the columns to be displayed
$displayedListCols = getParameterValue($emp_id, "MASK_CS_LIST_COLS");
if ($displayedListCols == "") :
   $displayedListCols = getParameterValue("0", "MASK_CS_LIST_COLS", $hqId);
   if ($displayedListCols == "") :
      // Default settings
      $displayedListCols = "cmp_comp,cmp_comp2,ad_street,ad_zipcode,cmp_match,cs_eid,usr_phone,usr_email,csc_id_jb_edit,cs_id_history,cs_id_report,cmp_authenticated_img,cs_id_jb_permanent,cmp_id_edit";
   endif;
endif;
$displayedListColsArray = spliti(",",$displayedListCols);
$displayedListColsArrayLen = count($displayedListColsArray);

// Because of performance the display (accentuation) of the meta customers has to be enabled explicitly
// $metaCsMarkerEnabled = getParameterValue("0", "MASK_CS_LIST_META_CS_MARKER", "0");
// if ($metaCsMarkerEnabled == "1") :
   $metaCsArray = getColVectorFromDB2ArrayByClause("customer", "cs_id", "NOT isnull(cs_id_parent) AND cs_id_parent != '0'", "cs_id_parent", "cs_id_parent", "1");
// endif;


// *** Fill up special search fields according to the value of the company field ***
// * START *
// Get constants for fields to be searched in
$constSearchCscsclistCmpcompCmpmatch = (SEARCH_CSCSCLIST_CMPCOMP_CMPMATCH != "" ? SEARCH_CSCSCLIST_CMPCOMP_CMPMATCH : "0");
// $constSearchCscsclistCmpcompCseid = (SEARCH_CSCSCLIST_CMPCOMP_CSEID != "" ? SEARCH_CSCSCLIST_CMPCOMP_CSEID : "0");
$constSearchCscsclistCmpcompCseid = "";
// $constSearchCscsclistCmpcompCscadphone = (SEARCH_CSCSCLIST_CMPCOMP_CSCADPHONE != "" ? SEARCH_CSCSCLIST_CMPCOMP_CSCADPHONE : "0");
$constSearchCscsclistCmpcompCscadphone = "";

// Check consistence of used fields per JavaScript
$tableHeaderSearchFieldsExtra = "";    // Defines the extra hidden fields to be integrated for search
$j = array_search("cmp_match",$displayedListColsArray);
if ($j === FALSE) : $tableHeaderSearchFieldsExtra .= "<input type=\"hidden\" name=\"f_cmp_match\" value=\"\">"; endif;
// $j = array_search("cs_eid",$displayedListColsArray);
// if ($j === FALSE) : $tableHeaderSearchFieldsExtra .= "<input type=\"hidden\" name=\"f_cs_eid\" value=\"\">"; endif;
// $j = array_search("cscad_phone",$displayedListColsArray);
// if ($j === FALSE) : $tableHeaderSearchFieldsExtra .= "<input type=\"hidden\" name=\"f_usr_phone\" value=\"\">"; endif;

$f_cmp_match = trim($f_cmp_match);
if ($constSearchCscsclistCmpcompCmpmatch == "1" && $f_cmp_match == "") : $f_cmp_match = trim($f_cmp_comp); endif;
// $f_cs_eid = trim($f_cs_eid);
// if ($constSearchCscsclistCmpcompCseid == "1" && $f_cs_eid == "") : $f_cs_eid = trim($f_cmp_comp); endif;
// $f_phone = trim($f_phone);
// if ($constSearchCscsclistCmpcompCscadphone == "1" && $f_usr_phone == "") : $f_usr_phone = trim($f_cmp_comp); endif;
// * END *


// EXPORT: Table header export select fields
$tableHeaderExportFields = "";
if (TRUE) :
   $rangeTo = $displayedListColsArrayLen;   // upper range for export fields almost is less or equal than number of elements for output on screen
   $dspColHeaderExportFieldArray = array();
   $dspColHeaderExportFieldArray["cmp_comp"] = "<select name=\"f_exp_cmp_comp\">" . addOptionsFromRange(1, $rangeTo, $f_exp_cmp_comp, $emptyItem = "1", "", "") . "</select>";
   $dspColHeaderExportFieldArray["cmp_comp2"] = "<select name=\"f_exp_cmp_comp2\">" . addOptionsFromRange(1, $rangeTo, $f_exp_cmp_comp2, $emptyItem = "1", "", "") . "</select>";
   $dspColHeaderExportFieldArray["cmp_comp3"] = "<select name=\"f_exp_cmp_comp3\">" . addOptionsFromRange(1, $rangeTo, $f_exp_cmp_comp3, $emptyItem = "1", "", "") . "</select>";
   $dspColHeaderExportFieldArray["cmp_comp4"] = "<select name=\"f_exp_cmp_comp4\">" . addOptionsFromRange(1, $rangeTo, $f_exp_cmp_comp4, $emptyItem = "1", "", "") . "</select>";
   $dspColHeaderExportFieldArray["ad_street"] = "<select name=\"f_exp_ad_street\">" . addOptionsFromRange(1, $rangeTo, $f_exp_ad_street, $emptyItem = "1", "", "") . "</select>";
   $dspColHeaderExportFieldArray["cmp_hsno"] = "<select name=\"f_exp_cmp_hsno\">" . addOptionsFromRange(1, $rangeTo, $f_exp_cmp_hsno, $emptyItem = "1", "", "") . "</select>";
   $dspColHeaderExportFieldArray["ad_zipcode"] = "<select name=\"f_exp_ad_zipcode\">" . addOptionsFromRange(1, $rangeTo, $f_exp_ad_zipcode, $emptyItem = "1", "", "") . "</select>";
   $dspColHeaderExportFieldArray["ad_city"] = "<select name=\"f_exp_ad_city\">" . addOptionsFromRange(1, $rangeTo, $f_exp_ad_city, $emptyItem = "1", "", "") . "</select>";
   $dspColHeaderExportFieldArray["cmp_match"] = "<select name=\"f_exp_cmp_match\">" . addOptionsFromRange(1, $rangeTo, $f_exp_cmp_match, $emptyItem = "1", "", "") . "</select>";
   $dspColHeaderExportFieldArray["cs_eid"] = "<select name=\"f_exp_cs_eid\">" . addOptionsFromRange(1, $rangeTo, $f_exp_cs_eid, $emptyItem = "1", "", "") . "</select>";
   $dspColHeaderExportFieldArray["usr_phone"] = "<select name=\"f_exp_usr_phone\">" . addOptionsFromRange(1, $rangeTo, $f_exp_usr_phone, $emptyItem = "1", "", "") . "</select>";
   $dspColHeaderExportFieldArray["usr_email"] = "<select name=\"f_exp_usr_email\">" . addOptionsFromRange(1, $rangeTo, $f_exp_usr_email, $emptyItem = "1", "", "") . "</select>";
   $dspColHeaderExportFieldArray["usr_name"] = "<select name=\"f_exp_usr_name\">" . addOptionsFromRange(1, $rangeTo, $f_exp_usr_name, $emptyItem = "1", "", "") . "</select>";
   $dspColHeaderExportFieldArray["usr_firstname"] = "<select name=\"f_exp_usr_firstname\">" . addOptionsFromRange(1, $rangeTo, $f_exp_usr_firstname, $emptyItem = "1", "", "") . "</select>";
   $dspColHeaderExportFieldArray["br_key"] = "<select name=\"f_exp_br_key\">" . addOptionsFromRange(1, $rangeTo, $f_exp_br_key, $emptyItem = "1", "", "") . "</select>";
   $dspColHeaderExportFieldArray["br_name"] = "<select name=\"f_exp_br_name\">" . addOptionsFromRange(1, $rangeTo, $f_exp_br_name, $emptyItem = "1", "", "") . "</select>";
endif;


// OUTPUT: Table header search fields
$tableHeaderSearchFields = "";
if (TRUE) :
   $dspColHeaderSearchFieldArray = array();
   $dspColHeaderSearchFieldArray["cmp_comp"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_cmp_comp\" value=\"" . $f_cmp_comp . "\" onBlur=\"javascript:checkSearchParameters('cmp_comp');\">";
   $dspColHeaderSearchFieldArray["cmp_comp2"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_cmp_comp2\" value=\"" . $f_cmp_comp2 . "\">";
   $dspColHeaderSearchFieldArray["cmp_comp3"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_cmp_comp3\" value=\"" . $f_cmp_comp3 . "\">";
   $dspColHeaderSearchFieldArray["cmp_comp4"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_cmp_comp4\" value=\"" . $f_cmp_comp4 . "\">";
   $dspColHeaderSearchFieldArray["ad_street"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_ad_street\" value=\"" . $f_ad_street . "\">";
   $dspColHeaderSearchFieldArray["cmp_hsno"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_cmp_hsno\" value=\"" . $f_cmp_hsno . "\">";
   $dspColHeaderSearchFieldArray["ad_zipcode"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_ad_zipcode\" value=\"" . $f_ad_zipcode . "\" size=\"5\">";
   $dspColHeaderSearchFieldArray["ad_city"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_ad_city\" value=\"" . $f_ad_city . "\" >";
   $dspColHeaderSearchFieldArray["cmp_match"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_cmp_match\" value=\"" . $f_cmp_match . "\" >";
   $dspColHeaderSearchFieldArray["cs_eid"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_cs_eid\" value=\"" . $f_cs_eid . "\" size=\"10\">";
   $dspColHeaderSearchFieldArray["cs_discount"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_cs_discount\" value=\"" . $f_cs_discount . "\" size=\"5\">";
   $dspColHeaderSearchFieldArray["usr_phone"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_usr_phone\" value=\"" . $f_usr_phone . "\"size=\"15\">";
   $dspColHeaderSearchFieldArray["usr_email"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_usr_email\" value=\"" . $f_usr_email . "\">";
   $dspColHeaderSearchFieldArray["usr_inv_email"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_usr_inv_email\" value=\"" . $f_usr_inv_email . "\">";
   $dspColHeaderSearchFieldArray["usr_reminder_email"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_usr_reminder_email\" value=\"" . $f_usr_reminder_email . "\">";
   $dspColHeaderSearchFieldArray["cmp_sustainability_email"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_cmp_sustainability_email\" value=\"" . $f_cmp_sustainability_email . "\">";
   $dspColHeaderSearchFieldArray["cmp_stax_idno"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_cmp_stax_idno\" value=\"" . $f_cmp_stax_idno . "\">";
   $dspColHeaderSearchFieldArray["tx_sign"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_tx_sign\" value=\"" . $f_tx_sign . "\">";
   $dspColHeaderSearchFieldArray["tx_value"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_tx_value\" value=\"" . $f_tx_value . "\">";
   $dspColHeaderSearchFieldArray["cmp_inv2hq"] = "<select " . $htmlClass02 . " name=\"f_cmp_inv2hq\"><option value=\"\">----</option><option value=\"0\" " . ($f_cmp_inv2hq == "0" ? "selected" : "") . ">" . getLngt("Keine Einzelrechnung") . "</option><option value=\"2\" " . ($f_cmp_inv2hq == "2" ? "selected" : "") . ">" . getLngt("Nur Einzelrechnung") . "</option></select>";
   $dspColHeaderSearchFieldArray["mt_value_payment_term"] = "<select " . $htmlClass02 . " name=\"f_mt_value_payment_term\"><option value=\"\">----</option>" . addOptionsFromTable("metatype","mt_sort","CONCAT(mt_value,' :: ',mt_mapped_value) AS mt_value_payment_term","mt_sort","mt_type = 'payment_term'",$f_mt_value_payment_term) . "</select>";
   $dspColHeaderSearchFieldArray["usr_name"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_usr_name\" value=\"" . $f_usr_name . "\">";
   $dspColHeaderSearchFieldArray["usr_firstname"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_usr_firstname\" value=\"" . $f_usr_firstname . "\">";
   $dspColHeaderSearchFieldArray["csc_id_jb_edit"] = "&nbsp;";
   $dspColHeaderSearchFieldArray["cs_id_history"] = "&nbsp;";
   $dspColHeaderSearchFieldArray["cs_id_report"] = "&nbsp;";
   $dspColHeaderSearchFieldArray["cmp_authenticated_img"] = "<a href=\"javascript:document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Suchen") . "&nbsp;</a>";
   $dspColHeaderSearchFieldArray["cs_id_jb_permanent"] = "&nbsp;</td>";
   // $dspColHeaderSearchFieldArray["cmp_cashmode"] = "&nbsp;";
   $dspColHeaderSearchFieldArray["cmp_id_edit"] = "&nbsp;";
   $dspColHeaderSearchFieldArray["cs_num_of_documents"] = "&nbsp;";
   $dspColHeaderSearchFieldArray["br_key"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_br_key\" value=\"" . $f_br_key . "\" size=\"10\">";
   $dspColHeaderSearchFieldArray["br_name"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_br_name\" value=\"" . $f_br_name . "\" size=\"10\">";
   $dspColHeaderSearchFieldArray["cs_eid_old"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_cs_eid_old\" value=\"" . $f_cs_eid_old . "\">";
   $dspColHeaderSearchFieldArray["cs_become_cs_date"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_cs_become_cs_date\" value=\"" . $f_cs_become_cs_date . "\">";

   // Use "check-array" to avoid search fields by multiple columns of the same (DB) field
   $chkArr = array();

   $tmpKeys = array_keys($dspColHeaderSearchFieldArray);
   for ($i = 0; $i < $displayedListColsArrayLen; $i++) {
       // Search for the value "$displayedListColsArray" in "$dspColArray" and get the key (index)
       $j = array_search($displayedListColsArray[$i], $tmpKeys);
       if (!($j === FALSE)) :
          $cellColor = getListColor(1, 1);
          if (!in_array($tmpKeys[$j], $chkArr)) :
             $tableHeaderSearchFields .= "<td bgcolor=\"" . $cellColor . "\">" . $dspColHeaderSearchFieldArray[$tmpKeys[$j]] . "</td>";
             array_push($chkArr, $tmpKeys[$j]);
          else :
             $tableHeaderSearchFields .= "<td bgcolor=\"" . $cellColor . "\">" . "&nbsp;" . "</td>";
          endif;
       endif;
   }
endif;


// OUTPUT: Table header column links
$tableHeaderLinks = "";
if (TRUE) :
   $dspColHeaderLinksArray = array();
   $dspColHeaderLinksArray["cmp_comp"] = "<a href=\"javascript:document.forms[0].orderClause.value='cmp.cmp_comp';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Firma") . "&nbsp;</a>";
   $dspColHeaderLinksArray["cmp_comp2"] = "<a href=\"javascript:document.forms[0].orderClause.value='cmp.cmp_comp2';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Firma2") . "&nbsp;</a>";
   $dspColHeaderLinksArray["cmp_comp3"] = "<a href=\"javascript:document.forms[0].orderClause.value='cmp.cmp_comp3';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Firma3") . "&nbsp;</a>";
   $dspColHeaderLinksArray["cmp_comp4"] = "<a href=\"javascript:document.forms[0].orderClause.value='cmp.cmp_comp4';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Firma4") . "&nbsp;</a>";
   $dspColHeaderLinksArray["ad_street"] = "<a href=\"javascript:document.forms[0].orderClause.value='ad.ad_street';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Strasse") . "&nbsp;</a>";
   $dspColHeaderLinksArray["cmp_hsno"] = "<a href=\"javascript:document.forms[0].orderClause.value='cmp.cmp_hsno';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Hausnr.") . "&nbsp;</a>";
   $dspColHeaderLinksArray["ad_zipcode"] = "<a href=\"javascript:document.forms[0].orderClause.value='ad.ad_zipcode';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("PLZ") . "&nbsp;</a>";
   $dspColHeaderLinksArray["ad_city"] = "<a href=\"javascript:document.forms[0].orderClause.value='ad.ad_city';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Ort") . "&nbsp;</a>";
   $dspColHeaderLinksArray["cmp_match"] = "<a href=\"javascript:document.forms[0].orderClause.value='cmp.cmp_match';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Freitext") . "&nbsp;</a>";
   $dspColHeaderLinksArray["cs_eid"] = "<a href=\"javascript:document.forms[0].orderClause.value='cs.cs_eid';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("EID") . "&nbsp;</a>";
   $dspColHeaderLinksArray["cs_discount"] = "<a href=\"javascript:document.forms[0].orderClause.value='cs.cs_discount';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Rabatt") . "&nbsp;</a>";
   $dspColHeaderLinksArray["usr_phone"] = "<a href=\"javascript:document.forms[0].orderClause.value='usr.usr_phone';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Telefon") . "&nbsp;</a>";
   $dspColHeaderLinksArray["usr_email"] = "<a href=\"javascript:document.forms[0].orderClause.value='usr.usr_email';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Email") . "&nbsp;</a>";
   $dspColHeaderLinksArray["usr_inv_email"] = "<a href=\"javascript:document.forms[0].orderClause.value='usr.usr_inv_email';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Rechnungs-Email") . "&nbsp;</a>";
   $dspColHeaderLinksArray["usr_reminder_email"] = "<a href=\"javascript:document.forms[0].orderClause.value='usr.usr_reminder_email';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Mahn-Email") . "&nbsp;</a>";
   $dspColHeaderLinksArray["cmp_sustainability_email"] = "<a href=\"javascript:document.forms[0].orderClause.value='cmp.cmp_sustainability_email';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Nachhaltigkeits-Email") . "&nbsp;</a>";
   $dspColHeaderLinksArray["cmp_stax_idno"] = "<a href=\"javascript:document.forms[0].orderClause.value='cmp.cmp_stax_idno';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("USt-IdNr.") . "&nbsp;</a>";
   $dspColHeaderLinksArray["tx_sign"] = "<a href=\"javascript:document.forms[0].orderClause.value='tx.tx_sign';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("USt-Kennz.") . "&nbsp;</a>";
   $dspColHeaderLinksArray["tx_value"] = "<a href=\"javascript:document.forms[0].orderClause.value='tx.tx_value';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("USt-Satz") . "&nbsp;</a>";
   $dspColHeaderLinksArray["cmp_inv2hq"] = "<a href=\"javascript:document.forms[0].orderClause.value='cmp.cmp_inv2hq';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Einzelrechnung") . "&nbsp;</a>";
   $dspColHeaderLinksArray["mt_value_payment_term"] = "<a href=\"javascript:document.forms[0].orderClause.value='cs.cs_payment_term';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Zahlungsbedingung") . "&nbsp;</a>";
   $dspColHeaderLinksArray["usr_name"] = "<a href=\"javascript:document.forms[0].orderClause.value='usr.usr_name';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Name") . "&nbsp;</a>";
   $dspColHeaderLinksArray["usr_firstname"] = "<a href=\"javascript:document.forms[0].orderClause.value='usr.usr_firstname';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Vorname") . "&nbsp;</a>";
   $dspColHeaderLinksArray["csc_id_jb_edit"] = "&nbsp;" . getLngt("Auftrag") . "&nbsp;";
   $dspColHeaderLinksArray["cs_id_history"] = "&nbsp;" . getLngt("Historie");
   $dspColHeaderLinksArray["cs_id_report"] = "&nbsp;" . getLngt("Berichte");
   $dspColHeaderLinksArray["cmp_authenticated_img"] = "&nbsp;" . getLngt("Kundenstatus") . "<br>&nbsp;" . getLngt("Hat&nbsp;Metakunden") . "<br>&nbsp;" . getLngt("Freigabe") . "<br>&nbsp;" . getLngt("Eigenerfassung") . "&nbsp;";
   $dspColHeaderLinksArray["cs_id_jb_permanent"] = "&nbsp;" . getLngt("Konserven") . ",<br>&nbsp;" . getLngt("Dauerauftr.");
   // $dspColHeaderLinksArray["cmp_cashmode"] = "&nbsp;" . getLngt("Rechnung") . "&nbsp;";
   $dspColHeaderLinksArray["cmp_id_edit"] = "&nbsp;" . getLngt("Bearbeiten") . "&nbsp;";
   $dspColHeaderLinksArray["cs_num_of_documents"] = "&nbsp;" . getLngt("Dokumente") . "&nbsp;";
   $dspColHeaderLinksArray["br_key"] = "<a href=\"javascript:document.forms[0].orderClause.value='br.br_key';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Br.Schl.") . "&nbsp;</a>";
   $dspColHeaderLinksArray["br_name"] = "<a href=\"javascript:document.forms[0].orderClause.value='br.br_name';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Branche") . "&nbsp;</a>";
   $dspColHeaderLinksArray["cs_eid_old"] = "<a href=\"javascript:document.forms[0].orderClause.value='cs_eid_old';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Alt-EID") . "&nbsp;</a>";
   $dspColHeaderLinksArray["cs_become_cs_date"] = "<a href=\"javascript:document.forms[0].orderClause.value='cs_become_cs_date';document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Kunde&nbsp;seit") . "&nbsp;</a>";

   $tmpKeys = array_keys($dspColHeaderLinksArray);
   for ($i = 0; $i < $displayedListColsArrayLen; $i++) {
       // Search for the value "$displayedListColsArray" in "$dspColArray" and get the key (index)
       $j = array_search($displayedListColsArray[$i], $tmpKeys);
       if (!($j === FALSE)) :
          $cellColor = getListColor(0, 0);
          $tableHeaderLinks .= "<td bgcolor=\"" . $cellColor . "\">" . $dspColHeaderLinksArray[$tmpKeys[$j]] . "</td>";
          
          // Handling of the export fields
          if (isset($dspColHeaderExportFieldArray[$tmpKeys[$j]]) && $dspColHeaderExportFieldArray[$tmpKeys[$j]] != "") :
             // $tableHeaderExportFields .= "<tr>";
             $tableHeaderExportFields .= "<td bgcolor=\"" . $cellColor . "\">" . $dspColHeaderLinksArray[$tmpKeys[$j]] . ":</td>";
             $tableHeaderExportFields .= "<td bgcolor=\"" . $cellColor . "\">" . $dspColHeaderExportFieldArray[$tmpKeys[$j]] . "</td>";
             $tableHeaderExportFields .= "<td>&nbsp;&nbsp;&nbsp;</td>";
             // $tableHeaderExportFields .= "</tr>";
          endif;
       endif;
   }
endif;


if ($f_searchmode == "") : $f_searchmode = "1"; endif;   
   
// Generate search-resultset
if ($f_act == "search") :

  mcTrim($f_cmp_comp); mcTrim($f_cmp_comp2); mcTrim($f_cmp_comp3); mcTrim($f_cmp_comp4); mcTrim($f_ad_street); mcTrim($f_cmp_hsno);
  mcTrim($f_ad_zipcode); mcTrim($f_ad_city); mcTrim($f_cmp_match); mcTrim($f_cs_eid); mcTrim($f_cs_discount); mcTrim($f_usr_phone);
  mcTrim($f_usr_email); mcTrim($f_usr_inv_email); mcTrim($f_usr_reminder_email); mcTrim($f_usr_name); mcTrim($f_usr_firstname); 
  mcTrim($f_cmp_iln); mcTrim($f_cmp_tax_idno); mcTrim($f_cmp_bank); mcTrim($f_cmp_bankno); mcTrim($f_cmp_bankacc); 
  mcTrim($f_br_key); mcTrim($f_br_name); mcTrim($f_cs_eid_old); mcTrim($f_cs_become_cs_date);
  mcTrim($f_cmp_sustainability_email); mcTrim($f_cmp_stax_idno); mcTrim($f_tx_sign); mcTrim($f_tx_value); mcTrim($f_cmp_inv2hq); mcTrim($f_mt_value_payment_term);

  $doSearch = FALSE;
  if (strlen($f_cmp_comp . $f_cmp_comp2 . $f_cmp_comp3 . $f_cmp_comp4 . $f_cmp_match . $f_ad_street . $f_cmp_hsno . $f_ad_zipcode . $f_ad_city . $f_cs_eid . $f_cs_discount . 
             $f_usr_phone . $f_usr_email . $f_usr_inv_email . $f_usr_reminder_email . $f_usr_name . $f_usr_firstname . $f_cmp_iln . $f_cmp_tax_idno . 
             $f_cmp_bank . $f_cmp_bankno . $f_cmp_bankacc . $f_br_key . $f_br_name . $f_cs_eid_old . $f_cs_become_cs_date . 
             $f_cmp_sustainability_email . $f_cmp_stax_idno . $f_tx_sign . $f_tx_value . $f_cmp_inv2hq . $f_mt_value_payment_term) == 0) :

     if ($f_show_allcustomers == "1" || getCountOfTable("customer") <= MAX_CARDINALITY) :
        
        $doSearch = TRUE;
     endif;
  endif;             


  if ($doSearch || strlen($f_cmp_comp) > 2 || strlen($f_cmp_comp2) > 2 || strlen($f_cmp_comp3) > 2 || strlen($f_cmp_comp4) > 2 || strlen($f_ad_street) > 2 || strlen($f_cmp_hsno) > 0 || strlen($f_ad_zipcode) > 2 || strlen($f_ad_city) > 2 || 
                   strlen($f_cmp_match) > 2 || strlen($f_cs_eid) > 2 || strlen($f_cs_discount) > 0 || strlen($f_usr_phone) > 2 || strlen($f_usr_email) > 2 || strlen($f_usr_inv_email) > 2 || strlen($f_usr_reminder_email) > 2 ||
                   strlen($f_usr_name) > 2 || strlen($f_usr_firstname) > 2 || strlen($f_cmp_iln) > 2 || strlen($f_cmp_tax_idno) > 2 || strlen($f_cmp_bank) > 2 || strlen($f_cmp_bankno) > 2 || strlen($f_cmp_bankacc) > 2 || 
                   strlen($f_br_key) > 2 || strlen($f_br_name) > 3  || strlen($f_cs_eid_old) > 2  || strlen($f_cs_become_cs_date) > 3 || strlen($f_cmp_sustainability_email) > 2 || strlen($f_cmp_stax_idno) > 3  || 
                   $f_tx_sign != ""  || $f_tx_value != "" || $f_cmp_inv2hq != "" || strlen($f_mt_value_payment_term) >= 1) :

                              
   // *******************************************
   // * Selection of the customers for the list *
   // *******************************************
   if ($f_searchmode == "1") : $prefix = "%"; else : $prefix = ""; endif;
   $whereClause = "";
   
   // Check for search value in cmp.cmp_comp OR cmp.cmp_match
   if ($f_cmp_comp != "") :
      $whereClause .= "cmp.cmp_comp LIKE '" . $prefix . $f_cmp_comp . "%'";
      if (($constSearchCscsclistCmpcompCmpmatch == "1" && $f_cmp_match != "") || 
          ($constSearchCscsclistCmpcompCseid == "1" && $f_cs_eid != "") || 
          ($constSearchCscsclistCmpcompCscadphone == "1" && $f_usr_phone != "")) :
         $whereClause = " (" . $whereClause;
         if ($constSearchCscsclistCmpcompCmpmatch == "1" && $f_cmp_match != "") :
            $whereClause .= " OR cmp.cmp_match LIKE '" . $prefix . $f_cmp_match . "%'"; 
         endif;
         if ($constSearchCscsclistCmpcompCseid == "1" && $f_cs_eid != "") :
            $whereClause .= " OR cs.cs_eid LIKE '" . $prefix . $f_cs_eid . "%'";
         endif;
         if ($constSearchCscsclistCmpcompCscadphone == "1" && $f_usr_phone != "") :
            $whereClause .= " OR usr.usr_phone LIKE '" . $prefix . $f_usr_phone . "%'";
         endif;            
         $whereClause .= ") ";
      endif;
   endif;

   // if ($f_cmp_comp != "") : $whereClause .= "cmp.cmp_comp LIKE '" . $prefix . $f_cmp_comp . "%'"; endif;
   if ($whereClause != "" && $f_cmp_comp2 != "") : $whereClause .= " AND "; endif;
   if ($f_cmp_comp2 != "") : $whereClause .= "cmp.cmp_comp2 LIKE '" . $prefix . $f_cmp_comp2 . "%'"; endif;
   if ($whereClause != "" && $f_cmp_comp3 != "") : $whereClause .= " AND "; endif;
   if ($f_cmp_comp3 != "") : $whereClause .= "cmp.cmp_comp3 LIKE '" . $prefix . $f_cmp_comp3 . "%'"; endif;
   if ($whereClause != "" && $f_cmp_comp4 != "") : $whereClause .= " AND "; endif;
   if ($f_cmp_comp4 != "") : $whereClause .= "cmp.cmp_comp4 LIKE '" . $prefix . $f_cmp_comp4 . "%'"; endif;
   // if ($whereClause != "" && $f_cmp_match != "") : $whereClause .= " AND "; endif;
   // if ($f_cmp_match != "") : $whereClause .= "cmp.cmp_match LIKE '" . $prefix . $f_cmp_match . "%'"; endif;
   if ($whereClause != "" && $f_cs_eid != "") : $whereClause .= " AND "; endif;
   if ($f_cs_eid != "") : $whereClause .= "cs.cs_eid LIKE '" . $prefix . $f_cs_eid . "%'"; endif;
   if ($whereClause != "" && $f_cs_discount != "") : $whereClause .= " AND "; endif;
   if ($f_cs_discount != "") : $whereClause .= "cs.cs_discount LIKE '" . $prefix . $f_cs_discount . "%'"; endif;
   if ($whereClause != "" && $f_usr_name != "") : $whereClause .= " AND "; endif;
   if ($f_usr_name != "") : $whereClause .= "usr.usr_name LIKE '" . $prefix . $f_usr_name . "%'"; endif;
   if ($whereClause != "" && $f_usr_phone != "") : $whereClause .= " AND "; endif;
   if ($f_usr_phone != "") : $whereClause .= "usr.usr_phone LIKE '" . $prefix . $f_usr_phone . "%'"; endif;
   if ($whereClause != "" && $f_usr_email != "") : $whereClause .= " AND "; endif;
   if ($f_usr_email != "") : $whereClause .= "usr.usr_email LIKE '" . $prefix . $f_usr_email . "%'"; endif;
   if ($whereClause != "" && $f_usr_inv_email != "") : $whereClause .= " AND "; endif;
   if ($f_usr_inv_email != "") : $whereClause .= "usr.usr_inv_email LIKE '" . $prefix . $f_usr_inv_email . "%'"; endif;
   if ($whereClause != "" && $f_usr_reminder_email != "") : $whereClause .= " AND "; endif;
   if ($f_usr_reminder_email != "") : $whereClause .= "usr.usr_reminder_email LIKE '" . $prefix . $f_usr_reminder_email . "%'"; endif;
   if ($whereClause != "" && $f_cmp_sustainability_email != "") : $whereClause .= " AND "; endif;
   if ($f_cmp_sustainability_email != "") : $whereClause .= "cmp.cmp_sustainability_email LIKE '" . $prefix . $f_cmp_sustainability_email . "%'"; endif;
   if ($whereClause != "" && $f_cmp_stax_idno != "") : $whereClause .= " AND "; endif;
   if ($f_cmp_stax_idno != "") : $whereClause .= "cmp.cmp_stax_idno LIKE '" . $prefix . $f_cmp_stax_idno . "%'"; endif;
   if ($whereClause != "" && $f_tx_sign != "") : $whereClause .= " AND "; endif;
   if ($f_tx_sign != "") : $whereClause .= "tx.tx_sign = '" . $f_tx_sign . "'"; endif;
   if ($whereClause != "" && $f_tx_value != "") : $whereClause .= " AND "; endif;
   if ($f_tx_value != "") : $whereClause .= "tx.tx_value = '" . $f_tx_value . "'"; endif;
   if ($whereClause != "" && $f_cmp_inv2hq != "") : $whereClause .= " AND "; endif;
   if ($f_cmp_inv2hq != "") : $whereClause .= "cmp.cmp_inv2hq = '" . $f_cmp_inv2hq . "'"; endif;
   if ($whereClause != "" && $f_mt_value_payment_term != "") : $whereClause .= " AND "; endif;
   if ($f_mt_value_payment_term != "") : $whereClause .= "mt_payment_term.mt_sort = '" . $f_mt_value_payment_term . "'"; endif;
   if ($whereClause != "" && $f_usr_name != "") : $whereClause .= " AND "; endif;
   if ($f_usr_name != "") : $whereClause .= "usr.usr_name LIKE '" . $prefix . $f_usr_name . "%'"; endif;
   if ($whereClause != "" && $f_usr_firstname != "") : $whereClause .= " AND "; endif;
   if ($f_usr_firstname != "") : $whereClause .= "usr.usr_firstname LIKE '" . $prefix . $f_usr_firstname . "%'"; endif;
   if ($whereClause != "" && $f_cmp_iln != "") : $whereClause .= " AND "; endif;      
   if ($f_cmp_iln != "") : $whereClause .= "cmp.cmp_iln LIKE '" . $prefix . $f_cmp_iln . "%'"; endif;
   if ($whereClause != "" && $f_cmp_tax_idno != "") : $whereClause .= " AND "; endif;
   if ($f_cmp_tax_idno != "") : $whereClause .= "cmp.cmp_tax_idno LIKE '" . $prefix . $f_cmp_tax_idno . "%'"; endif;
   if ($whereClause != "" && $f_cmp_bank != "") : $whereClause .= " AND "; endif;
   if ($f_cmp_bank != "") : $whereClause .= "cmp.cmp_bank LIKE '" . $prefix . $f_cmp_bank . "%'"; endif;
   if ($whereClause != "" && $f_cmp_bankno != "") : $whereClause .= " AND "; endif;
   if ($f_cmp_bankno != "") : $whereClause .= "cmp.cmp_bankno LIKE '" . $prefix . $f_cmp_bankno . "%'"; endif;
   if ($whereClause != "" && $f_cmp_bankacc != "") : $whereClause .= " AND "; endif;
   if ($f_cmp_bankacc != "") : $whereClause .= "cmp.cmp_bankacc LIKE '" . $prefix . $f_cmp_bankacc . "%'"; endif;   
   if ($whereClause != "" && $f_ad_street != "") : $whereClause .= " AND "; endif;
   if ($f_ad_street != "") : $whereClause .= "ad.ad_street LIKE '" . $prefix . $f_ad_street . "%'"; endif;   
   if ($whereClause != "" && $f_cmp_hsno != "") : $whereClause .= " AND "; endif;
   if ($f_cmp_hsno != "") : $whereClause .= "cmp.cmp_hsno LIKE '" . $prefix . $f_cmp_hsno . "%'"; endif;   
   if ($whereClause != "" && $f_ad_zipcode != "") : $whereClause .= " AND "; endif;
   if ($f_ad_zipcode != "") : $whereClause .= "ad.ad_zipcode LIKE '" . $prefix . $f_ad_zipcode . "%'"; endif;
   if ($whereClause != "" && $f_ad_city != "") : $whereClause .= " AND "; endif;
   if ($f_ad_city != "") : $whereClause .= "ad.ad_city LIKE '" . $prefix . $f_ad_city . "%'"; endif;
   if ($whereClause != "" && $f_br_key != "") : $whereClause .= " AND "; endif;
   if ($f_br_key != "") : $whereClause .= "br.br_key LIKE '" . $prefix . $f_br_key . "%'"; endif;
   if ($whereClause != "" && $f_br_name != "") : $whereClause .= " AND "; endif;
   if ($f_br_name != "") : $whereClause .= "br.br_name LIKE '" . $prefix . $f_br_name . "%'"; endif;
   if ($whereClause != "" && $f_cs_eid_old != "") : $whereClause .= " AND "; endif;
   if ($f_cs_eid_old != "") : $whereClause .= "gdc_2.gdc_content LIKE '" . $prefix . $f_cs_eid_old . "%'"; endif;
   if ($whereClause != "" && $f_cs_become_cs_date != "") : $whereClause .= " AND "; endif;
   if ($f_cs_become_cs_date != "") : $whereClause .= "cs.cs_become_cs_date LIKE '" . $prefix . $f_cs_become_cs_date . "%'"; endif;
   
   // Check authentication
   if ($whereClause != "" && $f_cmp_authenticated == "1") : $whereClause .= " AND "; endif;
   if ($f_cmp_authenticated == "1") : $whereClause .= "cmp.cmp_authenticated LIKE '" . $f_cmp_authenticated . "%'"; endif;
   
   // Check visibles
   if ($f_show_only_invisible == "1") :
      $whereClauseVisibility = " cmp.cmp_visible = '0' ";
   else :
      $whereClauseVisibility = " cmp.cmp_visible = '1' ";
      if ($f_show_invisible == "1") : $whereClauseVisibility = ""; endif;
   endif;
   
   if ($whereClause != "" && $whereClauseVisibility != "") : $whereClauseVisibility = " AND " . $whereClauseVisibility; endif;
   $whereClause .= $whereClauseVisibility;

   // Check job edit activated
   $whereClauseJobEdit = "";
   if ($f_show_only_jbedit == "1") : $whereClauseJobEdit = " cs.cs_jbedit = '1' "; endif;
   if ($whereClause != "" && $whereClauseJobEdit != "") : $whereClauseJobEdit = " AND " . $whereClauseJobEdit; endif;
   $whereClause .= $whereClauseJobEdit;

   // Check existing old EID
   $whereClauseOldEid = "";
   if ($f_show_only_old_eid == "1") : $whereClauseOldEid = " gdc_2.gdc_content != '' "; endif;
   if ($whereClause != "" && $whereClauseOldEid != "") : $whereClauseOldEid = " AND " . $whereClauseOldEid; endif;
   $whereClause .= $whereClauseOldEid;

   // Check authenticated
   $whereClauseAuthenticated = "";
   if ($f_hide_notauthenticated == "1") : $whereClauseAuthenticated = " cmp.cmp_authenticated = '1' "; endif;
   if ($whereClause != "" && $whereClauseAuthenticated != "") : $whereClauseAuthenticated = " AND " . $whereClauseAuthenticated; endif;
   $whereClause .= $whereClauseAuthenticated;

   // Check no metacustomer reference
   $whereClauseNoMetacustomer = "";
   if ($f_no_metacustomer == "1") : $whereClauseNoMetacustomer = " (cs.cs_id_parent = '' OR isnull(cs.cs_id_parent)) "; endif;
   if ($whereClause != "" && $whereClauseNoMetacustomer != "") : $whereClauseNoMetacustomer = " AND " . $whereClauseNoMetacustomer; endif;
   $whereClause .= $whereClauseNoMetacustomer;

   // Check with metacustomer reference
   $whereClauseWithMetacustomer = "";
   if ($f_with_metacustomer == "1") : $whereClauseWithMetacustomer = " (cs.cs_id_parent != '' AND (NOT isnull(cs.cs_id_parent)) AND cs.cs_id_parent > '0') "; endif;
   if ($whereClause != "" && $whereClauseWithMetacustomer != "") : $whereClauseWithMetacustomer = " AND " . $whereClauseWithMetacustomer; endif;
   $whereClause .= $whereClauseWithMetacustomer;

   // Filter by discount
   $whereClauseCsDiscount = "";
   if ($f_with_discount == "1") :
      $whereClauseCsDiscount = " cs.cs_discount != '0' AND";
   endif;

   // Filter by type (customer, prospect, ...)
   $whereClauseCmpType = "";
   if ($f_cmp_type != "") :
      $whereClauseCmpType = " cmp.cmp_type = '" . $f_cmp_type . "' AND";
   endif;

   // Only new customers according to entered date
   $whereClauseCmpNewDate = "";
   if ($f_cmp_new_date != "") :
      $whereClauseCmpNewDate = " cmp.cmp_new_date >= '" . $f_cmp_new_date . "' AND";
   endif;

   // Filter by branch
   $whereClauseBranch = "";
   if ($f_branch != "") :
      $whereClauseBranch = " cmp.br_id = '" . $f_branch . "' AND";
   endif;

   // Filter by sales ranking
   $whereClauseSalesRankingMan = "";
   if ($f_cmp_sales_ranking_man != "") :
      $whereClauseSalesRankingMan = " cmp.cmp_sales_ranking_man = '" . $f_cmp_sales_ranking_man . "' AND";
   endif;


   // **** Costcenter addresses (service, invoice, pickup) => Search with harder plausible checks ****
   $f_cscad_service_street = trim($f_cscad_service_street); $f_cscad_service_zipcode = trim($f_cscad_service_zipcode); $f_cscad_service_city = trim($f_cscad_service_city);
   $f_cscad_invoice_street = trim($f_cscad_invoice_street); $f_cscad_invoice_zipcode = trim($f_cscad_invoice_zipcode); $f_cscad_invoice_city = trim($f_cscad_invoice_city);
   $f_cscad_pickup_street =  trim($f_cscad_pickup_street);  $f_cscad_pickup_zipcode  = trim($f_cscad_pickup_zipcode);  $f_cscad_pickup_city  = trim($f_cscad_pickup_city);

   $f_cscad_addresses = $f_cscad_service_street . $f_cscad_service_zipcode . $f_cscad_service_city
                      . $f_cscad_invoice_street . $f_cscad_invoice_zipcode . $f_cscad_invoice_city
                      . $f_cscad_pickup_street . $f_cscad_pickup_zipcode . $f_cscad_pickup_city;

   // Check at least one char has been entered in address fields
   $cscadRequested = false;
   if ($f_cscad_addresses != "") :
      $cscadRequested = true;
   endif;

   $cscadAtLeastLen = 4;
   if (strlen($f_cscad_service_street) >= $cscadAtLeastLen || strlen($f_cscad_service_zipcode) >= $cscadAtLeastLen || strlen($f_cscad_service_city) >= $cscadAtLeastLen ||
       strlen($f_cscad_invoice_street) >= $cscadAtLeastLen || strlen($f_cscad_invoice_zipcode) >= $cscadAtLeastLen || strlen($f_cscad_invoice_city) >= $cscadAtLeastLen ||
       strlen($f_cscad_pickup_street)  >= $cscadAtLeastLen || strlen($f_cscad_pickup_zipcode)  >= $cscadAtLeastLen || strlen($f_cscad_pickup_city)  >= $cscadAtLeastLen) :

// f_cscad_service_street, f_cscad_service_zipcode, f_cscad_service_city, f_cscad_invoice_street, f_cscad_invoice_zipcode, f_cscad_invoice_city, f_cscad_pickup_street, f_cscad_pickup_zipcode, f_cscad_pickup_city
// $f_cscad_service_street, $f_cscad_service_zipcode, $f_cscad_service_city, $f_cscad_invoice_street, $f_cscad_invoice_zipcode, $f_cscad_invoice_city, $f_cscad_pickup_street, $f_cscad_pickup_zipcode, $f_cscad_pickup_city

      $whereClauseAddresses = "";
      // Service address
      if ($f_cscad_service_street != "") : $whereClauseAddresses = " ad_srv.ad_street LIKE '%" . $f_cscad_service_street . "%'"; endif;
      if ($whereClauseAddresses != "" && $f_cscad_service_zipcode != "") : $whereClauseAddresses .= " AND "; endif;
      if ($f_cscad_service_zipcode != "") : $whereClauseAddresses = " ad_srv.ad_zipcode = '" . $f_cscad_service_zipcode . "'"; endif;
      if ($whereClauseAddresses != "" && $f_cscad_service_city != "") : $whereClauseAddresses .= " AND "; endif;
      if ($f_cscad_service_city != "") : $whereClauseAddresses = " ad_srv.ad_city = '" . $f_cscad_service_city . "'"; endif;
      // Invoice address
      if ($whereClauseAddresses != "" && $f_cscad_invoice_street != "") : $whereClauseAddresses .= " AND "; endif;
      if ($f_cscad_invoice_street != "") : $whereClauseAddresses = " ad_inv.ad_street LIKE '%" . $f_cscad_invoice_street . "%'"; endif;
      if ($whereClauseAddresses != "" && $f_cscad_invoice_zipcode != "") : $whereClauseAddresses .= " AND "; endif;
      if ($f_cscad_invoice_zipcode != "") : $whereClauseAddresses = " ad_inv.ad_zipcode = '" . $f_cscad_invoice_zipcode . "'"; endif;
      if ($whereClauseAddresses != "" && $f_cscad_invoice_city != "") : $whereClauseAddresses .= " AND "; endif;
      if ($f_cscad_invoice_city != "") : $whereClauseAddresses = " ad_inv.ad_city = '" . $f_cscad_invoice_city . "'"; endif;
      // Pickup address
      if ($whereClauseAddresses != "" && $f_cscad_pickup_street != "") : $whereClauseAddresses .= " AND "; endif;
      if ($f_cscad_pickup_street != "") : $whereClauseAddresses = " ad_pck.ad_street LIKE '%" . $f_cscad_pickup_street . "%'"; endif;
      if ($whereClauseAddresses != "" && $f_cscad_pickup_zipcode != "") : $whereClauseAddresses .= " AND "; endif;
      if ($f_cscad_pickup_zipcode != "") : $whereClauseAddresses = " ad_pck.ad_zipcode = '" . $f_cscad_pickup_zipcode . "'"; endif;
      if ($whereClauseAddresses != "" && $f_cscad_pickup_city != "") : $whereClauseAddresses .= " AND "; endif;
      if ($f_cscad_pickup_city != "") : $whereClauseAddresses = " ad_pck.ad_city = '" . $f_cscad_pickup_city . "'"; endif;

      if ($whereClauseAddresses != "") : $whereClauseAddresses .= " AND "; endif;

      if ($whereClause != "") : $whereClause .= " AND "; endif;
   
      if ($orderClause == "") : $orderClause = "cmp.cmp_comp"; endif;

      // $sqlquery = "SELECT " . getDBFields("all_customer") . "," . getDBFields("all_company") . "," . getDBFields("costcenter") . "," 
      //                    . getDBFields("costcenteraddress_service") . "," . getDBFields("costcenteraddress_invoice") . "," . getDBFields("costcenteraddress_pickup") . ","
      //                    . getDBFields("address_service") . "," . getDBFields("address_invoice") . "," . getDBFields("address_pickup")
      $sqlquery = "SELECT cmp.cmp_id, cmp.cmp_type, cmp.cmp_comp, cmp.cmp_comp2, cmp.cmp_comp3, cmp.cmp_comp4, cmp.cmp_iln, cmp.cmp_tax_idno,"
                   . "    cmp.cmp_bank, cmp.cmp_bankno, cmp.cmp_bankacc, cmp.cmp_authenticated, cmp.cmp_match, cmp.cmp_cashmode, cmp.cmp_hsno,"
                   . "    cmp.cmp_inv2hq, cmp.cmp_sustainability_email, cmp.cmp_stax_idno, tx.tx_sign, tx.tx_value, br.br_key, br.br_name,"
                   . "    cs.cs_id, cs.cs_eid, cs.cs_discount, cs.csc_id, cs.cs_jbedit, cs.cs_id_parent, cs.cs_become_cs_date,"                
                   . "    mt_payment_term.mt_value AS mt_value_payment_term, mt_payment_term.mt_mapped_value AS mt_mapped_value_payment_term,"
                   . "    gdc_1.gdc_content AS cs_num_of_documents, gdc_2.gdc_content AS cs_eid_old,"
                   . "    usr.usr_name, usr.usr_firstname, usr.usr_email, usr.usr_inv_email, usr.usr_reminder_email, usr.usr_phone,"
                   . "    usr.usr_phone2, usr.usr_fax, ad.ad_street, ad.ad_zipcode, ad.ad_city"
                   . "  FROM"
                   . "    customer AS cs LEFT JOIN genericdatacontainer AS gdc_1 ON cs.cs_id = gdc_1.gdc_obj_id AND gdc_1.gdc_obj_type = 'cs' AND gdc_1.gdc_gen_fieldname = 'num_of_documents'"
                   . "                   LEFT JOIN genericdatacontainer AS gdc_2 ON cs.cs_id = gdc_2.gdc_obj_id AND gdc_2.gdc_obj_type = 'cs' AND gdc_2.gdc_gen_fieldname = 'eid_old'"
                   . "                   LEFT JOIN metatype AS mt_payment_term ON cs.cs_payment_term = mt_payment_term.mt_sort AND mt_payment_term.mt_type = 'payment_term',"
                   . "    company AS cmp LEFT JOIN branch AS br ON cmp.br_id = br.br_id"
                   . "                   LEFT JOIN tax AS tx ON cmp.tx_id = tx.tx_id,"
                   . "    address AS ad,"
                   . "    employee AS emp,"
                   . "    user AS usr,"
                   . "    costcenter AS csc,"
                   . "    costcenteraddress AS cscad_inv,"
                   . "    address AS ad_inv,"
                   . "    costcenteraddress AS cscad_pck,"
                   . "    address AS ad_pck,"
                   . "    costcenteraddress AS cscad_srv,"
                   . "    address AS ad_srv"
                   . "  WHERE " . $whereClause . $whereClauseCsDiscount . $whereClauseCmpType . $whereClauseCmpNewDate . $whereClauseBranch . $whereClauseSalesRankingMan . $whereClauseAddresses
                   . "    csc.csc_id = cs.csc_id AND"
                   . "    cs.hq_id IN " . getSQLMandatorArray($f_hq_id) . " AND"
                   . "    cscad_inv.csc_id = csc.csc_id AND"
                   . "    cscad_inv.adt_id = '2' AND"
                   . "    ad_inv.ad_id = cscad_inv.ad_id AND"
                   . "    cscad_pck.csc_id = csc.csc_id AND"
                   . "    cscad_pck.adt_id = '4' AND"
                   . "    ad_pck.ad_id = cscad_pck.ad_id AND"
                   . "    cscad_srv.csc_id = csc.csc_id AND"
                   . "    cscad_srv.adt_id = '1' AND"
                   . "    ad_srv.ad_id = cscad_srv.ad_id AND"
                   . "    cmp.cmp_id = cs.cmp_id AND"
                   . "    cmp.cmp_archived = '0' AND"
                   . "    cmp.cmp_authenticated = '1' AND"
                   . "    cmp.cmp_visible = '1' AND"
                   . "    cmp.cmp_type = '0'   AND"
                   . "    cmp.ad_id = ad.ad_id    AND"
                   . "    emp.emp_id = cs.cs_admin AND"
                   . "    usr.usr_id = emp.usr_id" . " AND"
                   . "    usr.hq_id IN " . getSQLMandatorArray($f_hq_id)
                   . "  ORDER BY " . $orderClause;

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

   else :

      // At least one char has been entered in address fields, but no search condition does match. Init all address values (!!!!)
      if ($cscadRequested) :
         $f_cscad_service_street = ""; $f_cscad_service_zipcode = ""; $f_cscad_service_city = "";
         $f_cscad_invoice_street = ""; $f_cscad_invoice_zipcode = ""; $f_cscad_invoice_city = "";
         $f_cscad_pickup_street = "";  $f_cscad_pickup_zipcode = "";  $f_cscad_pickup_city = "";
         $statusMessage = getLngt("Geben Sie bitte in mindestens einem aller Felder für die Leistungs-/Rechnungs-/Abhol-/Liefer-Adresse mindestens " . $cscadAtLeastLen . " Zeichen ein!");
      endif;

      if ($whereClause != "") : $whereClause .= " AND "; endif;

      if ($orderClause == "") : $orderClause = "cmp.cmp_comp"; endif;

      $sqlquery = "SELECT cmp.cmp_id, cmp.cmp_type, cmp.cmp_comp, cmp.cmp_comp2, cmp.cmp_comp3, cmp.cmp_comp4, cmp.cmp_iln, cmp.cmp_tax_idno,"
                   . "    cmp.cmp_bank, cmp.cmp_bankno, cmp.cmp_bankacc, cmp.cmp_authenticated, cmp.cmp_match, cmp.cmp_cashmode, cmp.cmp_hsno,"
                   . "    cmp.cmp_inv2hq, cmp.cmp_sustainability_email, cmp.cmp_stax_idno, tx.tx_sign, tx.tx_value, br.br_key, br.br_name,"
                   . "    cs.cs_id, cs.cs_eid, cs.cs_discount, cs.csc_id, cs.cs_jbedit, cs.cs_id_parent, cs.cs_become_cs_date,"                
                   . "    mt_payment_term.mt_value AS mt_value_payment_term, mt_payment_term.mt_mapped_value AS mt_mapped_value_payment_term,"
                   . "    gdc_1.gdc_content AS cs_num_of_documents, gdc_2.gdc_content AS cs_eid_old,"
                   . "    usr.usr_name, usr.usr_firstname, usr.usr_email, usr.usr_inv_email, usr.usr_reminder_email, usr.usr_phone,"
                   . "    usr.usr_phone2, usr.usr_fax, ad.ad_street, ad.ad_zipcode, ad.ad_city"
                   . " FROM company AS cmp LEFT JOIN branch AS br ON cmp.br_id = br.br_id"
                   . "                     LEFT JOIN tax AS tx ON cmp.tx_id = tx.tx_id,"
                   . "      customer AS cs LEFT JOIN genericdatacontainer AS gdc_1 ON cs.cs_id = gdc_1.gdc_obj_id AND gdc_1.gdc_obj_type = 'cs' AND gdc_1.gdc_gen_fieldname = 'num_of_documents'"
                   . "                     LEFT JOIN genericdatacontainer AS gdc_2 ON cs.cs_id = gdc_2.gdc_obj_id AND gdc_2.gdc_obj_type = 'cs' AND gdc_2.gdc_gen_fieldname = 'eid_old'"
                   . "                     LEFT JOIN metatype AS mt_payment_term ON cs.cs_payment_term = mt_payment_term.mt_sort AND mt_payment_term.mt_type = 'payment_term',"                
                   . "      employee AS emp, user AS usr, address AS ad"
                   . " WHERE " . $whereClause . $whereClauseCsDiscount . $whereClauseCmpType . $whereClauseCmpNewDate . $whereClauseBranch . $whereClauseSalesRankingMan
                   . "       cmp.cmp_id = cs.cmp_id   AND"
                   . "       cmp.cmp_archived = '0'   AND "
                   . "       cs.hq_id IN " . getSQLMandatorArray($f_hq_id) . " AND"
                   . "       cmp.ad_id = ad.ad_id     AND"
                   . "       cs.cs_admin = emp.emp_id AND"
                   . "       emp.usr_id = usr.usr_id  AND"
                   . "       usr.hq_id IN " . getSQLMandatorArray($f_hq_id)
                   . " ORDER BY " . $orderClause;

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

   endif;

   // Table with header
   $rowCounter = 0;
   $lineToggler = 0;
   while ($row = $result->fetch_assoc()):
         $numOfRows++;
         $dspColArray = array();
         
         // Only for focussing the first element (link) of the list
         // Look in tag <body ... onLoad=...>
         $elementName = "";
         if ($numOfRows == "1") : $elementName = " name=\"cs2focus\" "; endif;

         $tableOfRows .= "<tr>";

         // Link refers to job
         // $tableOfRows .= "<td ".$htmlClass02."__BGCOL__>&nbsp;<a href=\"../jobs/job_edit.php?csc_id_start=" . ec($row["csc_id"]) . "\" " . $elementName . "target=\"_blank\">"
         //                         . substr($row["cmp_comp"], 0, 15) . "</a>" . "</td>";            
         // Link refers to customer details

         // $dspColArray["cmp_comp"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;<a href=\"javascript:openCustomerSpecial('" . ec($row["cmp_id"]) . "');\" " . $elementName . ">"
         //                            . $row["cmp_comp"] . "</a>" . "</td>";
         $dspColArray["cmp_comp"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;<a href=\"../admin/customer_special.php?companyId=" . ec($row["cmp_id"]) . "\" " . $elementName . "target=\"_blank\">"
                                    . $row["cmp_comp"] . "</a>" . "</td>";

         $dspColArray["cmp_comp2"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["cmp_comp2"] . "</td>";
         $dspColArray["cmp_comp3"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["cmp_comp3"] . "</td>";
         $dspColArray["cmp_comp4"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["cmp_comp4"] . "</td>";
         $dspColArray["ad_street"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["ad_street"] . "</td>";
         $dspColArray["cmp_hsno"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["cmp_hsno"] . "</td>";
         $dspColArray["ad_zipcode"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . substr($row["ad_zipcode"], 0, 5) . "</td>";
         $dspColArray["ad_city"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["ad_city"] . "</td>";         
         $dspColArray["cmp_match"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["cmp_match"] . "</td>";
         $dspColArray["cmp_iln"] = "<td__BGCOL__>&nbsp;" . $row["cmp_iln"] . "</td>";
         $dspColArray["cmp_tax_idno"] = "<td__BGCOL__>&nbsp;" . $row["cmp_tax_idno"] . "</td>";
         $dspColArray["cs_eid"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . substr($row["cs_eid"], 0, 10) . "</td>";
         $dspColArray["cs_discount"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . ($row["cs_discount"] != 0 ? pad(number_format($row["cs_discount"], 2, ",", "."),5," ") : "") . "</td>";
         $dspColArray["usr_phone"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . substr($row["usr_phone"], 0, 15) . "</td>";
         $dspColArray["usr_email"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["usr_email"] . "</td>";
         $dspColArray["usr_inv_email"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["usr_inv_email"] . "</td>";
         $dspColArray["usr_reminder_email"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["usr_reminder_email"] . "</td>";
         $dspColArray["usr_name"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["usr_name"] . "</td>";
         $dspColArray["usr_firstname"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["usr_firstname"] . "</td>";
         $dspColArray["br_key"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["br_key"] . "</td>";
         $dspColArray["br_name"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["br_name"] . "</td>";
         $dspColArray["cmp_sustainability_email"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["cmp_sustainability_email"] . "</td>";
         $dspColArray["cmp_stax_idno"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["cmp_stax_idno"] . "</td>";
         $dspColArray["tx_sign"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["tx_sign"] . "</td>";
         $dspColArray["tx_value"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["tx_value"] . "</td>";
         $dspColArray["cmp_inv2hq"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . ($row["cmp_inv2hq"] == "0" ? getLngt("Nein") : getLngt("Ja")) . "</td>";
         $dspColArray["mt_value_payment_term"] = "<td ".$htmlClass02."__BGCOL__>&nbsp;" . $row["mt_value_payment_term"] . "&nbsp;::&nbsp;" . str_replace(" ", "&nbsp;", $row["mt_mapped_value_payment_term"]) . "</td>";
         
         // $tableOfRows .= "<td align=\"center\"__BGCOL__><a href=\"../admin/csc_list.php?f_act=search&customerId=" . ec($row["cs_id"]) . "\" target=\"_blank\">"
         //                        . "<img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\">" 
         //                        . "</a>" . "</td>";             
         $dspColArray["csc_id_jb_edit"] = "<td ".$htmlClass02." align=\"center\"__BGCOL__><a href=\"../jobs/job_edit.php?csc_id_start=" . ec($row["csc_id"]) . "\" target=\"_blank\">"
                                          . "<img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\">" 
                                          . "</a>" . "</td>";                                                

         $dspColArray["cs_id_history"] =  "<td ".$htmlClass02." align=\"center\"__BGCOL__><a href=\"../admin/history.php?history_mode=" . ec(0) . "&cs_id=" . ec($row["cs_id"]) . "&op=0\" target=\"_blank\">"
                                          . "<img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\">"
                                          . "</a></td>";

         // $dspColArray["cs_id_report"] =  "<td ".$htmlClass02." align=\"center\"__BGCOL__><a href=\"../groupware/cs_report.php?g_cs_eid=" . ec($row["cs_eid"]) . "\" target=\"_blank\">"
         //                                 . "<img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\">"
         //                                 . "</a></td>";
         $dspColArray["cs_id_report"] =  "<td ".$htmlClass02." align=\"center\"__BGCOL__><a href=\"../groupware/report.php?rpObjType=cs&g_cs_eid=" . ec($row["cs_eid"]) . "\" target=\"_blank\">"
                                          . "<img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\">"
                                          . "</a></td>";

         $dspColArray["cmp_bank"] = "<td__BGCOL__>&nbsp;" . $row["cmp_bank"] . "</td>";
         $dspColArray["cmp_bankno"] = "<td__BGCOL__>&nbsp;" . $row["cmp_bankno"] . "</td>";
         $dspColArray["cmp_bankacc"] = "<td__BGCOL__>&nbsp;" . $row["cmp_bankacc"] . "</td>";
         // $dspColArray["cmp_id_remove"] = "<td__BGCOL__>&nbsp;" . "<a href=\"javascript:removeCustomer(" . ec($row["cmp_id"]) . ");\">"
         //                                 . "<img src=\"../images/trash.jpg\" border=\"0\" height=\"13\" width=\"8\">" 
         //                                 . "</a>" . "</td>";            
         
         // Status images of the customer
         $csStatusArray = array();
         $imgStyle = "style=\"width: 7px; height: 7px; \"";

         // Customer state (customer or meta customer)
         $tmpImgName = "spacer_green.jpg";
         if ($row["cmp_type"] == "1") : $tmpImgName = "spacer_lightblue.jpg"; endif;
         if ($row["cmp_type"] == "2") : $tmpImgName = "spacer_lightblue.jpg"; endif;
         if ($row["cmp_type"] == "3") : $tmpImgName = "spacer_lightblue.jpg"; endif;
         // if ($metaCsMarkerEnabled == "1") :
            if (isset($metaCsArray[$row["cs_id"]]) && $metaCsArray[$row["cs_id"]] != "" && $metaCsArray[$row["cs_id"]] != "0") :
               $tmpImgName = "spacer_magenta.jpg";
            endif;
         // endif;
         $csStatusArray[0] = "<img src=\"../images/" . $tmpImgName . "\" " . $imgStyle . " title=\"" . getLngt("Kundenstatus [grün=Kunde,magenta=Metakunde,blau=Interessent]") . "\">";

         // Has meta customer
         $csStatusArray[1] = "<img src=\"../images/" . ($row["cs_id_parent"] != "" && $row["cs_id_parent"] != "0" ? "spacer_purple.jpg" : "spacer_white.jpg") . "\" " . $imgStyle . " title=\"" . getLngt("Hat&nbsp;Metakunden [lila=hat&nbsp;Metakunden]") . "\">";

         // Authenticated
         $csStatusArray[2] = "<img src=\"../images/" . ($row["cmp_authenticated"] == "1" ? "spacer_green.jpg" : "spacer_red.jpg") . "\" " . $imgStyle . " title=\"" . getLngt("Freigabe [grün=freigegeben,rot=gesperrt]") . "\">";

         // Customer is able to insert jobs
         /*
         $csStatusArray[2] = "";
         if ($row["cs_jbedit"] == "1") :
            $csStatusArray[2] = "<img src=\"../images/spacer_yellow.jpg\" " . $imgStyle . ">";
         endif;
         */
         $csStatusArray[3] = "<img src=\"../images/" . ($row["cs_jbedit"] == "1" ? "spacer_yellow.jpg" : "spacer_white.jpg") . "\" " . $imgStyle . " title=\"" . getLngt("Eigenerfassung [gelb=aktiviert]") . "\">";

         $dspColArray["cmp_authenticated_img"] = "<td align=\"center\"__BGCOL__><table><tr>";
         $csStatusArrayLen = count($csStatusArray);
         for ($i = 0; $i < $csStatusArrayLen; $i++) :
             $dspColArray["cmp_authenticated_img"] .= "<td " . $imgStyle . " __BGCOL__>" . $csStatusArray[$i] . "</td>";
         endfor;
         $dspColArray["cmp_authenticated_img"] .= "</tr></table></td>";
         
         $dspColArray["cs_id_jb_permanent"] = "<td align=\"center\"__BGCOL__><a href=\"../jobs/jb_special.php?cs_id=" . ec($row["cs_id"]) . "\" target=\"_blank\">"
                                              . "<img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\">"
                                              . "</a></td>";

         // Only cash payer mode or invoice customer
         $cashmodeImgName = "circle_red.png";
         if ($row["cmp_cashmode"] == "0") : $cashmodeImgName = "circle_green.png"; endif;
         // $dspColArray["cmp_cashmode"] = "<td ".$htmlClass02." align=\"center\"__BGCOL__><img src=\"../images/" . $cashmodeImgName . "\" border=\"0\" height=\"10\" width=\"25\"></td>";            

         // $dspColArray["cmp_id_edit"] = "<td ".$htmlClass02." align=\"center\"__BGCOL__><a href=\"javascript:openCustomerSpecial('" . ec($row["cmp_id"]) . "');\">"
         //                               . "<img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\">" 
         //                               . "</a>" . "</td>";
         $dspColArray["cmp_id_edit"] = "<td ".$htmlClass02." align=\"center\"__BGCOL__><a href=\"../admin/customer_special.php?companyId=" . ec($row["cmp_id"]) . "\" target=\"_blank\">"
                                     . "<img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\">" 
                                     . "</a>" . "</td>";
         // Number of documents associated to the customer
         $dspColArray["cs_num_of_documents"] = "<td ".$htmlClass02." align=\"center\"__BGCOL__>"
                                             . "<a href=\"../import/data_transfer.php?objType=cs&objId=" . ec($row["cs_id"]) . "\" target=\"_blank\">" . ($row["cs_num_of_documents"] != "" && $row["cs_num_of_documents"] != "0" ? "[" . $row["cs_num_of_documents"] . "]" : "&nbsp;") . "</a>"
                                             . "</td>";
         $dspColArray["cs_eid_old"] = "<td__BGCOL__>&nbsp;" . $row["cs_eid_old"] . "</td>";
         $dspColArray["cs_become_cs_date"] = "<td__BGCOL__>&nbsp;" . ($row["cs_become_cs_date"] != "0000-00-00" ? $row["cs_become_cs_date"] : "") . "</td>";

         // Generate list
         $rowCounter++;
         $tmpKeys = array_keys($dspColArray);
         for ($i = 0; $i < $displayedListColsArrayLen; $i++) :
             // Search for the value "$displayedListColsArray" in "$dspColArray" and get the key (index)
             $j = array_search($displayedListColsArray[$i], $tmpKeys);
             if (!($j === FALSE)) :
   	            if ($lineToggler == 0) : $lineToggler = 1; else : $lineToggler = 0; endif;                
                $cellColor = getListColor($rowCounter, $lineToggler);
                $dspColArray[$tmpKeys[$j]] = str_replace("__BGCOL__", " bgcolor=\"" . $cellColor ."\"", $dspColArray[$tmpKeys[$j]]);
                $tableOfRows .= $dspColArray[$tmpKeys[$j]];
             endif;
         endfor;

         $tableOfRows .= "</tr>";
   endwhile;
   $result->free();


   // ***  (CSV-)EXPORT of the customer data
   if ($csExportIt == "1") :
   
      // Compose $fieldArray
      $fieldArray = array();
      for ($i = 1; $i <= $displayedListColsArrayLen; $i++) :
          if ($f_exp_cmp_comp == $i) : array_push($fieldArray, "cmp_comp"); endif;
          if ($f_exp_cmp_comp2 == $i) : array_push($fieldArray, "cmp_comp2"); endif;
          if ($f_exp_cmp_comp3 == $i) : array_push($fieldArray, "cmp_comp3"); endif;
          if ($f_exp_cmp_comp4 == $i) : array_push($fieldArray, "cmp_comp4"); endif;
          if ($f_exp_ad_street == $i) : array_push($fieldArray, "ad_street"); endif;
          if ($f_exp_cmp_hsno == $i) : array_push($fieldArray, "cmp_hsno"); endif;
          if ($f_exp_ad_zipcode == $i) : array_push($fieldArray, "ad_zipcode"); endif;
          if ($f_exp_ad_city == $i) : array_push($fieldArray, "ad_city"); endif;
          if ($f_exp_cmp_match == $i) : array_push($fieldArray, "cmp_match"); endif;
          if ($f_exp_cs_eid == $i) : array_push($fieldArray, "cs_eid"); endif;
          if ($f_exp_usr_phone == $i) : array_push($fieldArray, "usr_phone"); endif;
          if ($f_exp_usr_email == $i) : array_push($fieldArray, "usr_email"); endif;
          // if ($f_exp_usr_inv_email == $i) : array_push($fieldArray, "usr_inv_email"); endif;
          // if ($f_exp_usr_reminder_email == $i) : array_push($fieldArray, "usr_reminder_email"); endif;
          if ($f_exp_usr_name == $i) : array_push($fieldArray, "usr_name"); endif;
          if ($f_exp_usr_firstname == $i) : array_push($fieldArray, "usr_firstname"); endif;
          if ($f_exp_br_key == $i) : array_push($fieldArray, "br_key"); endif;
          if ($f_exp_br_name == $i) : array_push($fieldArray, "br_name"); endif;
      endfor;
   
      // Remove old files
      foreach (glob(TEMP_PATH . "*.cs") as $fileNameToBoRemoved) {
          if ((time() - filemtime($fileNameToBoRemoved)) > 60) :
             if (file_exists($fileNameToBoRemoved)) :
                unlink($fileNameToBoRemoved);
             endif;
          endif;
      }

      // Reset row pointer
      // $row = $result->fetch_assoc(DB_FETCHMODE_OBJECT, 0);
      
      $result = $db->dbQ($sqlquery);

      // Define output parameters
      $delimiter = $csExportDelimiter;
      $writeHeader = "NO";
      $mode = "1";

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

      $outputLinesArrayLen = count($outputLinesArray);
      if ($outputLinesArrayLen > 0) :

         $f_fileName = getLngt("KUNDEN") . "_" . date("YmdHis");
         $f_secretFileName = md5($f_fileName) . ".cs";
         if ($outputHeader != "") :
            writeToFile(TEMP_PATH . $f_secretFileName, $outputHeader);   // write header if requested
         endif;
         for ($i = 0; $i < $outputLinesArrayLen; $i++) :                   
             writeToFile(TEMP_PATH . $f_secretFileName, $outputLinesArray[$i]);   // write statistic data
         endfor;
      else :
         $statusMessage = getLngt("Es wurden keine Daten gefunden! Eine Datei wurde deshalb nicht generiert!");
         $fileOutput = false;
      endif;
      
      $result->free();
      $onLoadCall .= "downloadFile();";
   endif;      
   // **************************************

  else :
   $statusMessage = getLngt("Bei Eingabe weniger als 3 Zeichen in mindestens einem Feld erfolgt keine Suche!");
  endif;      
endif;   

// Link to enter a new customer or to switch "visibility output"
$headerOps = "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;";
// $headerOps .= "<a href=\"javascript:openCustomerSpecial('');\">" . getLngt("Neuer Kunde") . "</a>";
$headerOps .= "<a href=\"../admin/customer_special.php\" target=\"_blank\">" . getLngt("Neuer Kunde") . "</a>";
$headerOps .= "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;";
$headerOps .= getLngt("Ausgeblendete&nbsp;anzeigen") . "&nbsp;<input type=\"checkbox\" name=\"f_show_invisible[]\" value=\"1\" " . ($f_show_invisible == "1" ? "checked" : "") . " tabindex=\"\">";

?>

<html>

<head>
<title><?php echo $pageTitel ?></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/checkFormTags.js" type="text/javascript"></script>

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

function setFocus() {
 var numOfRows = <?php echo $numOfRows ?>;
 if (numOfRows > 0) {
    numOfLinks = document.links.length;
    for (i=0; i<numOfLinks; ++i) {
    	if (document.links[i].name == 'cs2focus') {
           document.links[i].focus();
        };
    }; 
 } else {
   document.forms[0].f_cmp_comp.focus();
 };
};

function removeCustomer(cmp_id) {
  if (confirm('<?php echo getLngt("Kunde wirklich entfernen?") ?>')) {
     document.forms[0].f_act.value = '<?php echo ec("removeCustomer") ?>';
     document.forms[0].companyId.value = cmp_id;
     document.forms[0].submit();
  };
};

function checkSearchParameters(field_from) {
  if (field_from == 'cmp_comp') {
     // Check for search value in cmp_name to be also searched in cmp_match
     if (<?php echo $constSearchCscsclistCmpcompCmpmatch ?> == 1) {
     	document.forms[0].f_cmp_match.value = document.forms[0].f_cmp_comp.value;
     }
     /*
     if (<?php echo $constSearchCscsclistCmpcompCseid ?> == 1) {
     	document.forms[0].f_cs_eid.value = document.forms[0].f_cmp_comp.value;
     }
     if (<?php echo $constSearchCscsclistCmpcompCscadphone ?> == 1) {
     	document.forms[0].f_usr_phone.value = document.forms[0].f_cmp_comp.value;
     }     
     */
  }
};

function finishPage(comp,comp2,street,zipcode,cmp_match,eid,phone,email,hsno,usr_name,usr_firstname,comp3,comp4) {
  document.forms[0].f_cmp_comp.value=comp;
  document.forms[0].f_cmp_comp2.value=comp2;
  document.forms[0].f_cmp_comp3.value=comp3;
  document.forms[0].f_cmp_comp4.value=comp4;
  document.forms[0].f_ad_street.value=street;
  document.forms[0].f_cmp_hsno.value=hsno;
  document.forms[0].f_ad_zipcode.value=zipcode;
  document.forms[0].f_cmp_match.value=cmp_match;
  document.forms[0].f_cs_eid.value=eid;
  document.forms[0].f_usr_phone.value=phone;
  document.forms[0].f_usr_email.value=email;
  document.forms[0].f_usr_name.value=usr_name;
  document.forms[0].f_usr_firstname.value=usr_firstname;
  
  document.forms[0].f_act.value='<?php echo ec("search") ?>';
  document.forms[0].submit();  
};

function clearFields() {
  if (document.forms[0].f_cmp_comp) {document.forms[0].f_cmp_comp.value = ''};
  if (document.forms[0].f_cmp_comp2) {document.forms[0].f_cmp_comp2.value = ''};
  if (document.forms[0].f_cmp_comp3) {document.forms[0].f_cmp_comp3.value = ''};
  if (document.forms[0].f_cmp_comp4) {document.forms[0].f_cmp_comp4.value = ''};
  if (document.forms[0].f_ad_street) {document.forms[0].f_ad_street.value = ''};
  if (document.forms[0].f_cmp_hsno) {document.forms[0].f_cmp_hsno.value = ''};
  if (document.forms[0].f_ad_zipcode) {document.forms[0].f_ad_zipcode.value = ''};
  if (document.forms[0].f_ad_city) {document.forms[0].f_ad_city.value = ''};
  if (document.forms[0].f_cmp_match) {document.forms[0].f_cmp_match.value = ''};
  if (document.forms[0].f_cs_eid) {document.forms[0].f_cs_eid.value = ''};
  if (document.forms[0].f_cs_discount) {document.forms[0].f_cs_discount.value = ''};
  if (document.forms[0].f_usr_phone) {document.forms[0].f_usr_phone.value = ''};
  if (document.forms[0].f_usr_email) {document.forms[0].f_usr_email.value = ''};
  if (document.forms[0].f_usr_inv_email) {document.forms[0].f_usr_inv_email.value = ''};
  if (document.forms[0].f_usr_reminder_email) {document.forms[0].f_usr_reminder_email.value = ''};
  if (document.forms[0].f_usr_name) {document.forms[0].f_usr_name.value = ''};
  if (document.forms[0].f_usr_firstname) {document.forms[0].f_usr_firstname.value = ''};
  if (document.forms[0].f_cs_eid_old) {document.forms[0].f_cs_eid_old.value = ''};
  if (document.forms[0].f_cs_become_cs_date) {document.forms[0].f_cs_become_cs_date.value = ''};
  if (document.forms[0].f_cmp_sustainability_email) {document.forms[0].f_cmp_sustainability_email.value = ''};
  if (document.forms[0].f_cmp_stax_idno) {document.forms[0].f_cmp_stax_idno.value = ''};
  if (document.forms[0].f_tx_sign) {document.forms[0].f_tx_sign.value = ''};
  if (document.forms[0].f_tx_value) {document.forms[0].f_tx_value.value = ''};
  if (document.forms[0].f_cmp_inv2hq) {setSelectedValue('f_cmp_inv2hq', '')};
  if (document.forms[0].f_mt_value_payment_term) {setSelectedValue('f_mt_value_payment_term', '')};
};

function openCustomerSpecial(cmpId) {
  var widthPopupWin = 900;
  var heightPopupWin = 750;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/customer_special.php?companyId=" + cmpId ,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

// Hides the (csv-)export fields of a customer entity initially
function initCsExportHead() {
	var displayState = document.forms[0].csExtendedFlag.value;
  if (displayState == '' || displayState == '0') {
     myhide('csExportHead');
  };
}

// Shows/Hides the (csv-)export fields of a customer entity
function toggleCsExtendedHead() {
	var displayState = document.forms[0].csExtendedFlag.value;
  if (displayState == '0' || displayState == '') {
     myshow('csExportHead');
     document.forms[0].csExtendedFlag.value = '1';
  };
  if (displayState == '1') {
     myhide('csExportHead');
     document.forms[0].csExtendedFlag.value = '0';
  };
}

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("../include/data_download.php?f_path=<?php echo TEMP_PATH ?>&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 ?>initCsExportHead();displayStatusMessage();setFocus();<?php echo $onLoadCall ?>">

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

<?php if ($pageHeadline != "") : ?>
  <div class="mc_page-header" id="mc_page-header">
    <?php echo $pageHeadline ?>
  </div>
<?php endif ?>

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

  <form action="../admin/customer_list.php" method="post" target="">
  <input type="hidden" name="f_act" value="">  
  <input type="hidden" name="orderClause" value="<?php echo $orderClause ?>">
  <?php echo $tableHeaderSearchFieldsExtra ?>
  <?php echo $phpCurrentNavigationInputHidden ?>
  <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">
  <input type="hidden" name="csExtendedFlag" value="<?php echo $csExtendedFlag ?>">
  <input type="hidden" name="csExportIt" value="">

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

  <!-- Headquarters checkboxes -->
  <?php if (authCheckEmployeeRights($emp_id, "10")) : ?>
    <?php echo getHeadquartersCheckboxes($f_hq_id); ?>
    <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
  <?php endif; ?>
 
  <div>
    <a href="javascript:document.forms[0].f_act.value='search';document.forms[0].submit();">&nbsp;<?php echo getLngt("Suchen") ?>&nbsp;</a>
    &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
    <a href="javascript:clearFields();"><?php echo getLngt("Felder zurücksetzen") ?></a>
    &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
    Option:&nbsp;&nbsp;
    <input type="radio" name="f_searchmode" value="0" <?php if ($f_searchmode == "0") : echo "checked"; endif; ?>> <?php echo getLngt("Präfix") ?>
    <input type="radio" name="f_searchmode" value="1" <?php if ($f_searchmode == "1") : echo "checked"; endif; ?>> <?php echo getLngt("Teilwort") ?>
    <?php echo $headerOps ?>
    &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
    <a href="javascript:toggleCsExtendedHead();">&nbsp;<?php echo getLngt("Erweiterung") ?>&nbsp;</a>
  </div>

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

  <div id="csExportHead" name="csExportHead">
    <?php echo htmlDivLineSpacer("20px"); ?>    
    <div>
      <table class="f8np1" border="0" cellpadding="0">
        <tr>
          <td class="f10np1" colspan="2"><?php echo getLngt("Weitere&nbsp;Suchoptionen:") ?></td>
        </tr>
        <tr>
          <td>
            <?php echo getLngt("Alle&nbsp;Kunden&nbsp;im&nbsp;Suchergebnis") . "&nbsp;<input type=\"checkbox\" name=\"f_show_allcustomers[]\" value=\"1\" " . ($f_show_allcustomers == "1" ? "checked" : "") . ">"; ?>
          </td>
        </tr>
        <tr>
          <td>
            <?php echo getLngt("Keine&nbsp;gesperrten") . "&nbsp;<input type=\"checkbox\" name=\"f_hide_notauthenticated[]\" value=\"1\" " . ($f_hide_notauthenticated == "1" ? "checked" : "") . ">"; ?>
          </td>
        </tr>
        <tr>
          <td>
            <?php echo getLngt("Nur&nbsp;ausgeblendete") . "&nbsp;<input type=\"checkbox\" name=\"f_show_only_invisible[]\" value=\"1\" " . ($f_show_only_invisible == "1" ? "checked" : "") . ">"; ?>
          </td>
        </tr>
        <tr>
          <td>
            <?php echo getLngt("Nur&nbsp;mit&nbsp;Eigenerfassung") . "&nbsp;<input type=\"checkbox\" name=\"f_show_only_jbedit[]\" value=\"1\" " . ($f_show_only_jbedit == "1" ? "checked" : "") . ">"; ?>
          </td>
        </tr>
        <tr>
          <td>
            <?php echo getLngt("Nur&nbsp;mit&nbsp;alter&nbsp;EID") . "&nbsp;<input type=\"checkbox\" name=\"f_show_only_old_eid[]\" value=\"1\" " . ($f_show_only_old_eid == "1" ? "checked" : "") . ">"; ?>
          </td>
        </tr>
        <tr>
          <td>
            <?php echo getLngt("Keine&nbsp;Metakundenreferenz") . "&nbsp;<input type=\"checkbox\" name=\"f_no_metacustomer[]\" value=\"1\" " . ($f_no_metacustomer == "1" ? "checked" : "") . ">"; ?>
          </td>
        </tr>
        <tr>
          <td>
            <?php echo getLngt("Mit&nbsp;Metakundenreferenz") . "&nbsp;<input type=\"checkbox\" name=\"f_with_metacustomer[]\" value=\"1\" " . ($f_with_metacustomer == "1" ? "checked" : "") . ">"; ?>
          </td>
        </tr>
        <tr>
          <td>
            <?php echo getLngt("Mit&nbsp;Rabatt") . "&nbsp;<input type=\"checkbox\" name=\"f_with_discount[]\" value=\"1\" " . ($f_with_discount == "1" ? "checked" : "") . ">"; ?>
          </td>
        </tr>
        <tr>
          <td>
            <?php echo getLngt("Typ") ?>:
            <select name="f_cmp_type" class="f8np1">
            	<option value="">---</option>
              <?php echo addOptionsFromTable("metatype","mt_sort","mt_value","mt_sort","mt_type = 'customer_type'",$f_cmp_type) ?>
            </select>
          </td>
        </tr>
        <tr>
          <td>
            <?php echo getLngt("Nur Neukunden seit") ?>:
            <select name="f_cmp_new_date_month" class="f8np1">
              <?php echo addOptionsFromRange("1","12",$f_cmp_new_date_month,"1") ?>
            </select> (Monat)
            <select name="f_cmp_new_date_year" class="f8np1">
              <?php echo addOptionsFromRange("2000",getDateTime("year"),$f_cmp_new_date_year,"1") ?>
            </select> (Jahr)
          </td>
        </tr>
        <tr>
          <td>
            <?php echo getLngt("Branche") ?>:
            <select name="f_branch" class="f8np1">
            	<option value="">---</option>
              <?php // echo addOptionsFromTable("branch","br_id","CONCAT(br_key,' ',br_name)","br_key","br_visible = '1'",$f_branch) ?>
              <?php echo addOptionsFromTable("branch","br_id","CONCAT(br_key,' ',br_name) AS br_keyname","br_key","br_visible = '1'",$f_branch) ?>
            </select>
          </td>
        </tr>
        <tr>
          <td>
            <?php echo getLngt("Vertriebsranking") ?>:
            <select name="f_cmp_sales_ranking_man" class="f8np1">
              <option value="" <?php if ($f_cmp_sales_ranking_man == "" || $f_cmp_sales_ranking_man == "0") : echo "selected"; endif; ?>></option>
              <option value="1" <?php if ($f_cmp_sales_ranking_man == "1") : echo "selected"; endif; ?>>A</option>
              <option value="2" <?php if ($f_cmp_sales_ranking_man == "2") : echo "selected"; endif; ?>>B</option>
              <option value="3" <?php if ($f_cmp_sales_ranking_man == "3") : echo "selected"; endif; ?>>C</option>
            </select>
          </td>
        </tr>
        <tr>
        	<table>
        		<tr>
        			<td><?php echo "Leistungsadresse" ?>:&nbsp;&nbsp;</td>
              <td><input type="text" class="smaller" name="f_cscad_service_street" value="<?php echo $f_cscad_service_street ?>" size="50" maxlength="50" placeholder="<?php echo "Strasse" ?>"></td>
              <td><input type="text" class="smaller" name="f_cscad_service_zipcode" value="<?php echo $f_cscad_service_zipcode ?>" size="5" maxlength="5" placeholder="<?php echo "PLZ" ?>"></td>
              <td><input type="text" class="smaller" name="f_cscad_service_city" value="<?php echo $f_cscad_service_city ?>" size="50" maxlength="50" placeholder="<?php echo "Ort" ?>"></td>            
            </tr>
        		<tr>
        			<td><?php echo "Rechnungssadresse" ?>:&nbsp;&nbsp;</td>
              <td><input type="text" class="smaller" name="f_cscad_invoice_street" value="<?php echo $f_cscad_invoice_street ?>" size="50" maxlength="50" placeholder="<?php echo "Strasse" ?>"></td>
              <td><input type="text" class="smaller" name="f_cscad_invoice_zipcode" value="<?php echo $f_cscad_invoice_zipcode ?>" size="5" maxlength="5" placeholder="<?php echo "PLZ" ?>"></td>
              <td><input type="text" class="smaller" name="f_cscad_invoice_city" value="<?php echo $f_cscad_invoice_city ?>" size="50" maxlength="50" placeholder="<?php echo "Ort" ?>"></td>            
            </tr>
        		<tr>
        			<td><?php echo "Abhol-/Lieferadresse" ?>:&nbsp;&nbsp;</td>
              <td><input type="text" class="smaller" name="f_cscad_pickup_street" value="<?php echo $f_cscad_pickup_street ?>" size="50" maxlength="50" placeholder="<?php echo "Strasse" ?>"></td>
              <td><input type="text" class="smaller" name="f_cscad_pickup_zipcode" value="<?php echo $f_cscad_pickup_zipcode ?>" size="5" maxlength="5" placeholder="<?php echo "PLZ" ?>"></td>
              <td><input type="text" class="smaller" name="f_cscad_pickup_city" value="<?php echo $f_cscad_pickup_city ?>" size="50" maxlength="50" placeholder="<?php echo "Ort" ?>"></td>            
            </tr>
        	<table>
        </tr>
      </table>
    </div>
    <div>
      <table class="f8np1" border="0" cellpadding="0">
        <tr>
          <td class="f10np1" colspan="2"><br><?php echo getLngt("Exportfelder:") ?></td>
        </tr>
        <tr>
          <?php echo $tableHeaderExportFields ?>
        </tr>
        <tr>
        </tr>
      </table>
    </div>    
    <?php echo defineButtonType08("Export", "action_fileexport", "document.forms[0].csExportIt.value='1';document.forms[0].f_act.value='search';document.forms[0].submit();", "95", "left", "5"); ?>
    <div>
      <?php echo "Feldbegrenzer" ?>:&nbsp;&nbsp;<input type="text" class="smaller" name="csExportDelimiter" value="<?php echo $csExportDelimiter ?>" size="3" maxlength="5">
    </div>
    <?php echo htmlDivLineSpacer("20px"); ?>
  </div>
  
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <table class="f8np1" border="0" cellpadding="0">
      <tr>
        <?php echo $tableHeaderSearchFields ?>
      </tr>
      <tr>
        <?php echo $tableHeaderLinks ?>
      </tr>
      <?php echo $tableOfRows ?>
    </table>
  </div>

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

  <div>
    <?php echo getLngt("Anzahl Einträge:") ?> <?php echo $numOfRows ?><?php if ($numOfRows == "0" && $f_act == "search" && $statusMessage == "") : echo " " . getLngt("(Keine Einträge gefunden.)"); endif; ?>
  </div>

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

</body>

</html>
