<?php
/*=======================================================================
 *
 * pt_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", "generic", "genNum", "f_mode", "companyId", "orderClause", "statusMessage", "f_cmp_authenticated", "f_searchmode", "f_cmp_match",
                         "f_cmp_comp", "f_cmp_comp2", "f_cs_eid", "f_usr_name", "f_usr_phone", "f_usr_email", "f_csc_name",
                         "f_street", "f_hsno", "f_zipcode", "f_city", "f_country", "f_remark", "f_person", "tourno", "f_show_invisible",
                         "cscIdRoot", "customerId", "cscIdActual", "f_hq_id", "deactivateMenu"));

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

getLanguage(__FILE__);

$deactivateMenuStatic = "1";
$pageTitel = getLngt("INTERESSENTENLISTE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);

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

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

// 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;

// Current number of headquarters
$numOfHq = getCountOfTable("headquarters");

if ($f_searchmode == "") : $f_searchmode = "1"; endif;

if ($genNum == "") : $genNum = ""; endif;   // "Generic number" to use more javascript parameters ("g_", "g2_" <=> genNum = "2", "g3_" <=> genNum = "3")

$f_cmp_comp = trim($f_cmp_comp);
$f_cmp_comp2 = trim($f_cmp_comp2);


// Parameter for displayed column SEQUENCE
/*
$displayedListCols = getParameterValue($emp_id, "MASK_CSCSC_LIST_COLS");
if ($displayedListCols == "") :
   $displayedListCols = getParameterValue("0", "MASK_CSCSC_LIST_COLS", $hqId);
   if ($displayedListCols == "") :
      // Default settings
      $displayedListCols = "cmp_comp,cmp_comp2,cs_eid,csc_name,cmp_match,cmp_authenticated_img,ad_street,cscad_hsno,ad_zipcode,ad_city,cscad_remark,cscad_person,cscad_phone,statistic";
   endif;
endif;
*/
$displayedListCols = "cmp_comp,cmp_comp2,cs_eid,cmp_match,cmp_authenticated_img,ad_street,cmp_hsno,ad_zipcode,ad_city,cmp_remark,usr_phone";
$displayedListColsArray = spliti(",",$displayedListCols);
$displayedListColsArrayLen = count($displayedListColsArray);

// Parameter for displayed column LENGTH
/*
$displayedListLenCols = getParameterValue($emp_id, "MASK_CSCSC_LIST_LEN_COLS");
if ($displayedListLenCols == "") :
   $displayedListLenCols = getParameterValue("0", "MASK_CSCSC_LIST_LEN_COLS", $hqId);
   if ($displayedListLenCols == "") :
      // Default settings
      $displayedListLenCols = "30,15,11,20,30,5,20,5,5,20,20";
   endif;
endif;
*/
$displayedListLenCols = "30,15,11,30,5,20,5,5,20,20,20,15";
$displayedListLenColsArray = spliti(",",$displayedListLenCols);


// Get constants for fields to be searched in
$constSearchPtlistCmpcompCmpmatch = SEARCH_CSCSCLIST_CMPCOMP_CMPMATCH;      // Use constant like definition for customer
$constSearchPtlistCmpcompCseid = SEARCH_CSCSCLIST_CMPCOMP_CSEID;            // Use constant like definition for customer
$constSearchPtlistCmpcompCscadphone = SEARCH_CSCSCLIST_CMPCOMP_CSCADPHONE;  // Use constant like definition for customer

// 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 ($constSearchPtlistCmpcompCmpmatch == "1" && $f_cmp_match == "") : $f_cmp_match = trim($f_cmp_comp); endif;
$f_cs_eid = trim($f_cs_eid);
if ($constSearchPtlistCmpcompCseid == "1" && $f_cs_eid == "") : $f_cs_eid = trim($f_cmp_comp); endif;
$f_usr_phone = trim($f_usr_phone);
if ($constSearchPtlistCmpcompCscadphone == "1" && $f_usr_phone == "") : $f_usr_phone = trim($f_cmp_comp); endif;

$f_usr_name = trim($f_usr_name);
$f_usr_phone = trim($f_usr_phone);
$f_usr_email = trim($f_usr_email);
$f_street = trim($f_street);
$f_hsno = trim($f_hsno);
$f_zipcode = trim($f_zipcode);
$f_city = trim($f_city);
$f_country = trim($f_country);
$f_remark = trim($f_remark);

// Flag for "show invisible prospects"
if ($f_show_invisible == "" || count($f_show_invisible) == 0) :
   $f_show_invisible = "0";
else: 
   $f_show_invisible = "1";
endif;


// OUTPUT: Page header option fields
$pageHeaderOptionFields = "";
if (TRUE) :
   $pageHeaderOptionFields .= "<a href=\"javascript:document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Suchen") . "&nbsp;</a>\n";
   $pageHeaderOptionFields .= "&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;\n";
   $pageHeaderOptionFields .= "<a href=\"javascript:clearFields();\">" . getLngt("Felder&nbsp;zurücksetzen") . "</a>\n";
   $pageHeaderOptionFields .= "&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;\n";
   $pageHeaderOptionFields .= getLngt("Option:") . "&nbsp;&nbsp;\n";
   $pageHeaderOptionFields .= "<input type=\"radio\" name=\"f_searchmode\" value=\"0\" " . ($f_searchmode == "0" ? "checked" : "") . ">&nbsp;" . getLngt("Präfix") . "\n";
   $pageHeaderOptionFields .= "<input type=\"radio\" name=\"f_searchmode\" value=\"1\" " . ($f_searchmode == "1" ? "checked" : "") . ">&nbsp;" . getLngt("Teilwort") . "\n";
   $pageHeaderOptionFields .= "<br><br>\n";
   $pageHeaderOptionFields .= getLngt("Ausgeblendete&nbsp;anzeigen") . "&nbsp;\n";
   $pageHeaderOptionFields .= "<input type=\"checkbox\" name=\"f_show_invisible[]\" value=\"1\" " . ($f_show_invisible == "1" ? "checked" : "") . ">\n";
   // $pageHeaderOptionFields .= "&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;\n";   
   $pageHeaderOptionFields .= "<br><br><br>\n";
endif;


// OUTPUT: Table header search fields
$tableHeaderSearchFields = "";
if (TRUE) :
   $dspColHeaderSearchFieldArray["cmp_comp"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_cmp_comp\" value=\"" . $f_cmp_comp . "\" onBlur=\"javascript:checkSearchParameters('cmp_comp');\" _SIZE_MACRO_>";
   $dspColHeaderSearchFieldArray["cmp_comp2"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_cmp_comp2\" value=\"" . $f_cmp_comp2 . "\" _SIZE_MACRO_>";
   $dspColHeaderSearchFieldArray["cs_eid"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_cs_eid\" value=\"" . $f_cs_eid . "\" _SIZE_MACRO_>";
   $dspColHeaderSearchFieldArray["cmp_match"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_cmp_match\" value=\"" . $f_cmp_match . "\" _SIZE_MACRO_>";
   $dspColHeaderSearchFieldArray["cmp_authenticated_img"] = "<a href=\"javascript:document.forms[0].f_act.value='search';document.forms[0].submit();\">&nbsp;" . getLngt("Suchen") . "&nbsp;</a>";
   $dspColHeaderSearchFieldArray["usr_name"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_usr_name\" value=\"" . $f_usr_name . "\" _SIZE_MACRO_>";
   $dspColHeaderSearchFieldArray["usr_phone"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_usr_phone\" value=\"" . $f_usr_phone . "\" _SIZE_MACRO_>";
   $dspColHeaderSearchFieldArray["usr_email"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_usr_email\" value=\"" . $f_usr_email . "\" _SIZE_MACRO_>";
   $dspColHeaderSearchFieldArray["ad_street"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_street\" value=\"" . $f_street . "\" _SIZE_MACRO_>";
   $dspColHeaderSearchFieldArray["cmp_hsno"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_hsno\" value=\"" . $f_hsno . "\" _SIZE_MACRO_>";
   $dspColHeaderSearchFieldArray["ad_zipcode"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_zipcode\" value=\"" . $f_zipcode . "\" _SIZE_MACRO_>";
   $dspColHeaderSearchFieldArray["ad_city"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_city\" value=\"" . $f_city . "\" _SIZE_MACRO_>";
   $dspColHeaderSearchFieldArray["cmp_remark"] = "<input type=\"text\" " . $htmlClass01 . " name=\"f_remark\" value=\"" . $f_remark . "\" _SIZE_MACRO_>";

   $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)) :
   	      // Define length (html attribute "size") of the field and substitute macro
   	      if ($displayedListLenColsArray[$i] == "" || $displayedListLenColsArray[$i] == "0") :
             $dspColHeaderSearchFieldArray[$tmpKeys[$j]] = str_replace("_SIZE_MACRO_", "", $dspColHeaderSearchFieldArray[$tmpKeys[$j]]);
   	      else :
   	         $dspColHeaderSearchFieldArray[$tmpKeys[$j]] = str_replace("_SIZE_MACRO_", " size=\"" . $displayedListLenColsArray[$i] . "\" ", $dspColHeaderSearchFieldArray[$tmpKeys[$j]]);
   	      endif;
          $cellColor = getListColor(1, 1);
          $tableHeaderSearchFields .= "<td bgcolor=\"" . $cellColor . "\">" . $dspColHeaderSearchFieldArray[$tmpKeys[$j]] . "</td>";
       endif;
   }
endif;

// OUTPUT: Table header column links
$tableHeaderLinks = "";
if (TRUE) :
   $dspColHeaderLinksArray = array();
   $dspColHeaderLinksArray["cmp_comp"] = "<a href=\"javascript:submitPage('pt.pt_cmp_comp');\">&nbsp;" . getLngt("Firma") . "&nbsp;</a></td>";
   $dspColHeaderLinksArray["cmp_comp2"] = "<a href=\"javascript:submitPage('pt.pt_cmp_comp2');\">&nbsp;" . getLngt("Firma2") . "&nbsp;</a></td>";
   $dspColHeaderLinksArray["cs_eid"] = "<a href=\"javascript:submitPage('pt.pt_cs_eid');\">&nbsp;" . getLngt("ExtID") . "&nbsp;</a></td>";
   $dspColHeaderLinksArray["cmp_match"] = "<a href=\"javascript:submitPage('pt.pt_cmp_match');\">&nbsp;" . getLngt("Freitext") . "&nbsp;</a></td>";
   $dspColHeaderLinksArray["cmp_authenticated_img"] = "&nbsp;" . getLngt("Freigabe") . "&nbsp;</td>";
   $dspColHeaderLinksArray["usr_name"] = "<a href=\"javascript:submitPage('pt.pt_usr_name');\">&nbsp;" . getLngt("Admin-Name") . "</a></td>";
   $dspColHeaderLinksArray["usr_phone"] = "<a href=\"javascript:submitPage('pt.pt_usr_phone');\">&nbsp;" . getLngt("Admin-Telefon") . "</a></td>";
   $dspColHeaderLinksArray["usr_email"] = "<a href=\"javascript:submitPage('pt.pt_usr_email');\">&nbsp;" . getLngt("Admin-Email") . "</a></td>";
   $dspColHeaderLinksArray["ad_street"] = "<a href=\"javascript:submitPage('ad.ad_street');\">&nbsp;" . getLngt("Straße") . "</a></td>";
   $dspColHeaderLinksArray["cmp_hsno"] = "<a href=\"javascript:submitPage('pt.pt_cmp_hsno');\">&nbsp;" . getLngt("Hausnr.") . "</a></td>";
   $dspColHeaderLinksArray["ad_zipcode"] = "<a href=\"javascript:submitPage('ad.ad_zipcode');\">&nbsp;" . getLngt("PLZ") . "</a></td>";
   $dspColHeaderLinksArray["ad_city"] = "<a href=\"javascript:submitPage('ad.ad_city');\">&nbsp;" . getLngt("Ort") . "</a></td>";
   $dspColHeaderLinksArray["cmp_remark"] = "<a href=\"javascript:submitPage('pt.pt_cmp_remark');\">&nbsp;" . getLngt("Bemerkung") . "</a></td>";
   
   $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>";
       endif;
   }
endif;


// if called e.g. by the first time with empty search-fields
$searchValues = $f_cmp_comp . $f_cmp_comp2 . $f_cmp_match . $f_cs_eid . $f_street . $f_hsno . $f_zipcode . $f_city . $f_country . $f_remark . $f_usr_phone;

   // Generate search-resultset
   if ($f_act == "search" && $searchValues != "") :

      if (strlen($f_cmp_comp) > 2 || strlen($f_cmp_comp2) > 2 || strlen($f_cmp_match) > 2 || strlen($f_cs_eid) > 2 || 
          strlen($f_street) > 2 || strlen($f_hsno) > 0 || strlen($f_zipcode) > 2 || strlen($f_city) > 2 ||
          strlen($f_remark) > 2 || strlen($f_usr_phone) > 2) :

         // *******************************************
         // * Selection of the customers for the list *
         // *******************************************
         if ($f_searchmode == "1") : $prefix = "%"; else : $prefix = ""; endif;
         $whereClause = "";

         // Check for search value in pt.pt_cmp_comp OR pt.pt_cmp_match
         if ($f_cmp_comp != "") :
            $whereClause .= "pt.pt_cmp_comp LIKE '" . $prefix . $f_cmp_comp . "%'";
            if (($constSearchPtlistCmpcompCmpmatch == "1" && $f_cmp_match != "") || 
                ($constSearchPtlistCmpcompCseid == "1" && $f_cs_eid != "") || 
                ($constSearchPtlistCmpcompCscadphone == "1" && $f_usr_phone != "")) :
               $whereClause = " (" . $whereClause;
               if ($constSearchPtlistCmpcompCmpmatch == "1" && $f_cmp_match != "") :
                  $whereClause .= " OR pt.pt_cmp_match LIKE '" . $prefix . $f_cmp_match . "%'"; 
               endif;
               if ($constSearchPtlistCmpcompCseid == "1" && $f_cs_eid != "") :
                  $whereClause .= " OR pt.pt_cs_eid LIKE '" . $prefix . $f_cs_eid . "%'";
               endif;
               if ($constSearchPtlistCmpcompCscadphone == "1" && $f_usr_phone != "") :
                  $whereClause .= " OR pt.pt_usr_phone LIKE '" . $prefix . $f_usr_phone . "%'";
               endif;            
               $whereClause .= ") ";
            endif;
         endif;
   
         if ($whereClause != "" && $f_cmp_comp2 != "") : $whereClause .= " AND "; endif;
         if ($f_cmp_comp2 != "") : $whereClause .= "pt.pt_cmp_comp2 LIKE '" . $prefix . $f_cmp_comp2 . "%'"; endif;
         
         // Check for search value in pt.pt_cmp_comp OR pt.pt_cmp_match
         if ($constSearchPtlistCmpcompCmpmatch != "1") :
            if ($whereClause != "" && $f_cmp_match != "") : $whereClause .= " AND "; endif;
            if ($f_cmp_match != "") : $whereClause .= "pt.pt_cmp_match LIKE '" . $prefix . $f_cmp_match . "%'"; endif;
         endif;
   
         // Check for search value in pt.pt_cmp_comp OR pt.pt_cs_eid
         if ($constSearchPtlistCmpcompCseid != "1") :
            if ($whereClause != "" && $f_cs_eid != "") : $whereClause .= " AND "; endif;
            if ($f_cs_eid != "") : $whereClause .= "pt.pt_cs_eid LIKE '" . $prefix . $f_cs_eid . "%'"; endif;
         endif;
         
         // Check for search value in pt.pt_cmp_comp OR pt.pt_usr_phone
         if ($constSearchPtlistCmpcompCscadphone != "1") :
            if ($whereClause != "" && $f_usr_phone != "") : $whereClause .= " AND "; endif;
            if ($f_usr_phone != "") : $whereClause .= "pt.pt_usr_phone LIKE '" . $prefix . $f_usr_phone . "%'"; endif;
         endif;
               
         if ($whereClause != "" && $f_usr_name != "") : $whereClause .= " AND "; endif;
         if ($f_usr_name != "") : $whereClause .= "pt.pt_usr_name LIKE '" . $prefix . $f_usr_name . "%'"; endif;
         if ($whereClause != "" && $f_usr_email != "") : $whereClause .= " AND "; endif;
         if ($f_usr_email != "") : $whereClause .= "pt.pt_usr_email LIKE '" . $prefix . $f_usr_email . "%'"; endif;
         // if ($whereClause != "" && $f_cmp_iln != "") : $whereClause .= " AND "; endif;
         // if ($f_cmp_iln != "") : $whereClause .= "pt.pt_cmp_iln LIKE '" . $prefix . $f_cmp_iln . "%'"; endif;
         // if ($whereClause != "" && $f_cmp_tax_idno != "") : $whereClause .= " AND "; endif;
         // if ($f_cmp_tax_idno != "") : $whereClause .= "pt.pt_cmp_tax_idno LIKE '" . $prefix . $f_cmp_tax_idno . "%'"; endif;
         // if ($whereClause != "" && $f_cmp_bank != "") : $whereClause .= " AND "; endif;
         // if ($f_cmp_bank != "") : $whereClause .= "pt.pt_cmp_bank LIKE '" . $prefix . $f_cmp_bank . "%'"; endif;
         // if ($whereClause != "" && $f_cmp_bankno != "") : $whereClause .= " AND "; endif;
         // if ($f_cmp_bankno != "") : $whereClause .= "pt.pt_cmp_bankno LIKE '" . $prefix . $f_cmp_bankno . "%'"; endif;
         // if ($whereClause != "" && $f_cmp_bankacc != "") : $whereClause .= " AND "; endif;
         // if ($f_cmp_bankacc != "") : $whereClause .= "pt.pt_cmp_bankacc LIKE '" . $prefix . $f_cmp_bankacc . "%'"; endif;
         if ($whereClause != "" && $f_street != "") : $whereClause .= " AND "; endif;
         if ($f_street != "") : $whereClause .= "ad.ad_street LIKE '" . $f_street . "%'"; endif;
         if ($whereClause != "" && $f_hsno != "") : $whereClause .= " AND "; endif;
         if ($f_hsno != "") : $whereClause .= "pt.pt_cmp_hsno LIKE '" . $f_hsno . "%'"; endif;
         if ($whereClause != "" && $f_zipcode != "") : $whereClause .= " AND "; endif;
         if ($f_zipcode != "") : $whereClause .= "ad.ad_zipcode LIKE '" . $f_zipcode . "%'"; endif;
         if ($whereClause != "" && $f_city != "") : $whereClause .= " AND "; endif;
         if ($f_city != "") : $whereClause .= "ad.ad_city LIKE '" . $f_city . "%'"; endif;
         if ($whereClause != "" && $f_country != "") : $whereClause .= " AND "; endif;
         if ($f_country != "") : $whereClause .= "ad.ad_country LIKE '" . $f_country . "%'"; endif;
         if ($whereClause != "" && $f_remark != "") : $whereClause .= " AND "; endif;
         if ($f_remark != "") : $whereClause .= "pt.pt_cmp_remark LIKE '" . $f_remark . "%'"; endif;  
   
         // Check authentication
   // Enable again 4 cashMode (... damit die "eigentliche" Funktion des Sperrens wieder aufgenommen werden kann !!!!!!!!!!!!!!!!!!)
   //      if ($whereClause != "" && $f_cmp_authenticated == "1") : $whereClause .= " AND "; endif;
   //      if ($f_cmp_authenticated == "1") : $whereClause .= "cmp.cmp_authenticated LIKE '" . $f_cmp_authenticated . "%'"; endif;
   
         // Show "invisible" prospects
         if ($f_show_invisible != "1") :
            if ($whereClause != "") : $whereClause .= " AND "; endif;
            $whereClause .= " pt.pt_cmp_visible = '1'";
         endif;
   
         if ($whereClause != "") : $whereClause .= " AND "; endif;
   
         if ($orderClause == "") : $orderClause = "pt.pt_cmp_comp"; endif;

         $sqlquery = "SELECT pt.pt_id, pt.pt_cs_eid, pt.pt_cs_commission_no, pt.pt_cs_discount, pt.pt_cs_fixprice_discount, "
                      . "    pt.pt_cmp_comp, pt.pt_cmp_comp2, pt.pt_cmp_authenticated, pt.pt_cmp_remark, pt.pt_cmp_match, pt.pt_cmp_cashmode,"
                      . "    pt.tx_id, pt.ad_id, pt.pt_cmp_hsno,pt.pt_usr_phone,"
                      . "    ad.ad_street, ad.ad_zipcode, ad.ad_city, ad.ad_country"
                      . " FROM prospect AS pt, address AS ad"
                      . " WHERE " .$whereClause
                      . "       pt.hq_id IN " . getSQLMandatorArray($f_hq_id) . " AND"
                      . "       pt.ad_id = ad.ad_id"
                      . " ORDER BY " . $orderClause;                  
// echo $sqlquery . "<br>";
         getDb2Connection();     // Try to connect request server because of performance
         $result = $db2->query($sqlquery);
         if (DB::isError($result)) die ("$PHP_SELF: '$sqlquery': " . $result->getMessage());

   	     // Table with header
   	     $rowCounter = 0;
   	     $lineToggler = 0;
   	     while ($row = $result->fetch_assoc()):
   	           $numOfRows++;
   	           $dspColArray = array();
         
   	           $tableOfRows .= "<tr>";
         
               // $dspColArray["cmp_comp"] = "<td__BGCOL__>&nbsp;__START__" . $row["pt_cmp_comp"] . "__END__</td>";
               $dspColArray["cmp_comp"] = "<td__BGCOL__>&nbsp;<a href=\"javascript:finishPage('" . $row["pt_id"] . "','" . my_str_check_js($row["ad_street"]) . "','" . $row["pt_cmp_hsno"] . "','" . $row["ad_zipcode"] . "','" . my_str_check_js($row["ad_city"]) . "','" . my_str_check_js($row["ad_country"]) . "','" . my_str_check_js($row["pt_cmp_remark"]) . "','" . $row["tx_id"] . "','" . $row["pt_cs_eid"]  . "','" . $row["pt_cs_commission_no"] . "','" . $row["pt_cmp_authenticated"]  . "','" . $row["pt_cs_discount"] . "','" . my_str_check_js($row["pt_cmp_comp"]) . "','" . my_str_check_js($row["pt_cmp_comp2"]) . "'," . $row["pt_cs_fixprice_discount"] . ");\">__START__" . my_str_check_html($row["pt_cmp_comp"]) . "__END__</a></td>";
               $dspColArray["cmp_comp2"] = "<td__BGCOL__>&nbsp;__START__" . $row["pt_cmp_comp2"] . "__END__</td>";
               $dspColArray["cs_eid"] = "<td__BGCOL__>&nbsp;__START__" . $row["pt_cs_eid"] . "__END__</td>";

               $dspColArray["cmp_match"] = "<td__BGCOL__>&nbsp;__START__" . $row["cmp_match"] . "__END__</td>";

               $authImgName = "circle_red.png";
   	           if ($row["pt_cmp_authenticated"] == "1") : $authImgName = "circle_green.png"; endif;
   	           $dspColArray["cmp_authenticated_img"] = "<td align=\"center\"__BGCOL__><img src=\"../images/" . $authImgName . "\" border=\"0\" height=\"10\" width=\"25\"></td>";
         
   	           $cashmodeImgName = "circle_green.png";
   	           if ($row["pt_cmp_cashmode"] == "1") : $cashmodeImgName = "circle_red.png"; endif;
               // Enable 4 cashMode
               // $dspColArray["usr_name"] = "<td align=\"center\"><img src=\"../images/" . $cashmodeImgName . "\" border=\"0\" height=\"10\" width=\"25\"></td>";
         
               $dspColArray["usr_name"] = "<td__BGCOL__>&nbsp;__START__" . $row["pt_usr_name"] . "__END__</td>";
               $dspColArray["usr_phone"] = "<td__BGCOL__>&nbsp;__START__" . $row["pt_usr_phone"] . "__END__</td>";
               $dspColArray["usr_email"] = "<td__BGCOL__>&nbsp;__START__" . $row["pt_usr_email"] . "__END__</td>";
               $dspColArray["ad_street"] = "<td__BGCOL__>&nbsp;__START__" . $row["ad_street"] . "__END__</td>";
               $dspColArray["cmp_hsno"] = "<td__BGCOL__>&nbsp;__START__" . $row["pt_cmp_hsno"] . "__END__</td>";
               $dspColArray["ad_zipcode"] = "<td__BGCOL__>&nbsp;__START__" . $row["ad_zipcode"] . "__END__</td>";
               $dspColArray["ad_city"] = "<td__BGCOL__>&nbsp;__START__" . $row["ad_city"] . "__END__</td>";
               $dspColArray["cmp_remark"] = "<td__BGCOL__>&nbsp;__START__" . $row["pt_cmp_remark"] . "__END__</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)) :
         
   	                  // Define length (html attribute "size") of the field and substitute macro
   	                  if ($displayedListLenColsArray[$i] == "" || $displayedListLenColsArray[$i] == "0") :
                         $dspColArray[$tmpKeys[$j]] = str_replace("__START__", "", $dspColArray[$tmpKeys[$j]]);
                         $dspColArray[$tmpKeys[$j]] = str_replace("__END__", "", $dspColArray[$tmpKeys[$j]]);
   	                  else :
                         // content of db-fields
                         $tagBegin = "__START__";
                         $tagEnd = "__END__";
                         if (!(strpos($dspColArray[$tmpKeys[$j]], $tagBegin) === FALSE) && !(strpos($dspColArray[$tmpKeys[$j]], $tagEnd) === FALSE)) :
                         
                            $pos0 = strpos($dspColArray[$tmpKeys[$j]], $tagBegin);                         // begin of tagBegin (first occurrence)
                            $pos1 = strpos($dspColArray[$tmpKeys[$j]], $tagBegin) + strlen($tagBegin);     // end of tagBegin   (first occurrence)
                            $pos2 = strpos($dspColArray[$tmpKeys[$j]], $tagEnd);                           // begin of tagEnd   (first occurrence)
                            $pos3 = strpos($dspColArray[$tmpKeys[$j]], $tagEnd) + strlen($tagEnd);         // end of tagEnd     (first occurrence)
                            
                            if ($pos2 - $pos1 > 0) :
                               // first get the content of the tag
                               $fieldContent = substr($dspColArray[$tmpKeys[$j]], $pos1, $pos2 - $pos1);
                         
                               $fieldContent = substr($fieldContent, 0, $displayedListLenColsArray[$i]);
         
                               // replace original content with string-content
                               $dspColArray[$tmpKeys[$j]] = substr_replace($dspColArray[$tmpKeys[$j]], $fieldContent, $pos0, $pos3 - $pos0);
   	                        endif;
   	                     endif;
   	                  endif;
   	                  
   	                  if ($lineToggler == 0) : $lineToggler = 1; else : $lineToggler = 0; endif;
                      $cellColor = getListColor($rowCounter, $lineToggler);
   	                  
                      $dspColArray[$tmpKeys[$j]] = str_replace("__START__", "", $dspColArray[$tmpKeys[$j]]);
                      $dspColArray[$tmpKeys[$j]] = str_replace("__END__", "", $dspColArray[$tmpKeys[$j]]);
                      $dspColArray[$tmpKeys[$j]] = str_replace("__BGCOL__", " bgcolor=\"" . $cellColor ."\"", $dspColArray[$tmpKeys[$j]]);

                      $tableOfRows .= $dspColArray[$tmpKeys[$j]] . "\n";
                   endif;
               }
               
               if ($lineToggler == 0) : $lineToggler = 1; else : $lineToggler = 0; endif;
   	           $tableOfRows .= "</tr>\n";
   	     endwhile;
   	     $result->free();

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

<html>

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

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

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

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

<?php if ($generic == "") : ?>
function finishPage(pt_id,street,hsno,zipcode,city,country,cmp_remark,tx_id,cs_eid,cs_commission_no,cmp_authenticated,cs_discount,cmp_comp,cmp_comp2,cs_fixprice_discount) {
  if (tourno > -1)
  {
    opener.setJobList(tourno, opener.jl_csc_id, csc_id);
    opener.setJobList(tourno, opener.jl_tr_comp, comp);
    opener.setJobList(tourno, opener.jl_tr_person, person);
    opener.setJobList(tourno, opener.jl_ad_street, street);
    opener.setJobList(tourno, opener.jl_tr_hsno, hsno);
    opener.setJobList(tourno, opener.jl_ad_zipcode, zipcode);
    opener.setJobList(tourno, opener.jl_ad_city, city);
    opener.setJobList(tourno, opener.jl_tr_remark, remark);
    opener.setJobList(tourno, opener.jl_csc_id_payer, "false");
    opener.setJobList(tourno, opener.jl_hide_tr_remark, "true");
    if (csc_id_payer != "" && csc_id_payer != 0)
    {
      opener.setCsc_id_payer(csc_id_payer, csc_id_payer_comp);
      opener.parent.job_options.document.tourOptions.payer_is_default.value = "true";
    }
  } else {
    opener.setCsc_id_payer(csc_id, comp);
    if (tx_id != "" && tx_id != 0)
    {
      opener.checkJb_sales_tax_rate_sign(tx_id);
      opener.checkCs_filter(cs_filter);
    }
<?php if (MASK_CASH_PAYER_SELECT == "1") : ?>
    opener.parent.job_tour.document.tourForm.jb_costsplit.checked = true;
    opener.checkCostsplit(true);    
<?php endif; ?>
  }
  if (cs_eid != "" && cs_eid != 0)
  {
    opener.add_cs_eid(csc_id, cs_eid, cs_commission_no, comp, cmp_authenticated, cmp_remark, cs_jobbatch, cs_discount, cs_filter, tx_id, name, is_extern, cs_id, cs_fixprice_discount, cs_prov);
  }
  self.setTimeout("opener.refreshFormFields()", 100);
  self.setTimeout("opener.resetSignificantPriceValues()", 150);
//  opener.refreshFormFields();
  self.setTimeout("opener.checkSendTour()", 200);
//  opener.checkSendTour();
  self.setTimeout("self.close()", 300);
//  self.close();
};
<?php else : ?>
// GENERIC function
function finishPage(pt_id,street,hsno,zipcode,city,country,cmp_remark,tx_id,cs_eid,cs_commission_no,cmp_authenticated,cs_discount,cmp_comp,cmp_comp2,cs_fixprice_discount) {

  <?php if (substr($generic, 0,1) == "1") : ?> opener.document.forms[0].g<?php echo $genNum; ?>_pt_id.value = pt_id;         <?php endif; ?>
  <?php if (substr($generic, 1,1) == "1") : ?> opener.document.forms[0].g<?php echo $genNum; ?>_pt_cmp_comp.value = cmp_comp;   <?php endif; ?>
  <?php if (substr($generic, 2,1) == "1") : ?> opener.document.forms[0].g<?php echo $genNum; ?>_pt_cmp_comp2.value = cmp_comp2; <?php endif; ?>
  <?php if (substr($generic, 3,1) == "1") : ?> opener.document.forms[0].g<?php echo $genNum; ?>_ad_street.value = street;    <?php endif; ?>
  <?php if (substr($generic, 4,1) == "1") : ?> opener.document.forms[0].g<?php echo $genNum; ?>_pt_cmp_hsno.value = hsno;       <?php endif; ?>
  <?php if (substr($generic, 5,1) == "1") : ?> opener.document.forms[0].g<?php echo $genNum; ?>_ad_zipcode.value = zipcode;  <?php endif; ?>
  <?php if (substr($generic, 6,1) == "1") : ?> opener.document.forms[0].g<?php echo $genNum; ?>_ad_city.value = city;        <?php endif; ?>
  <?php if (substr($generic, 7,1) == "1") : ?> opener.document.forms[0].g<?php echo $genNum; ?>_ad_country.value = country;  <?php endif; ?>
  <?php if (substr($generic, 8,1) == "1") : ?> opener.document.forms[0].g<?php echo $genNum; ?>_pt_cs_eid.value = cs_eid;       <?php endif; ?>
  <?php if (substr($generic, 9,1) == "1") : ?> opener.document.forms[0].g<?php echo $genNum; ?>_pt_cmp_remark.value = remark;   <?php endif; ?>  
  self.close();
};
<?php endif; ?>

function clearFields() {
  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_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_csc_name) {document.forms[0].f_csc_name.value = ''};
  if (document.forms[0].f_street) {document.forms[0].f_street.value = ''};
  if (document.forms[0].f_hsno) {document.forms[0].f_hsno.value = ''};
  if (document.forms[0].f_zipcode) {document.forms[0].f_zipcode.value = ''};
  if (document.forms[0].f_city) {document.forms[0].f_city.value = ''};
  if (document.forms[0].f_country) {document.forms[0].f_country.value = 'DE'};
  if (document.forms[0].f_remark) {document.forms[0].f_remark.value = ''};
  if (document.forms[0].f_person) {document.forms[0].f_person.value = ''};
  if (document.forms[0].f_usr_phone) {document.forms[0].f_usr_phone.value = ''};
};

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 $constSearchPtlistCmpcompCmpmatch ?> == 1) {
     	document.forms[0].f_cmp_match.value = document.forms[0].f_cmp_comp.value;
     }
     if (<?php echo $constSearchPtlistCmpcompCseid ?> == 1) {
     	document.forms[0].f_cs_eid.value = document.forms[0].f_cmp_comp.value;
     }
     if (<?php echo $constSearchPtlistCmpcompCscadphone ?> == 1) {
     	document.forms[0].f_usr_phone.value = document.forms[0].f_cmp_comp.value;
     }     
  }
};

function submitPage(orderClause) {
  document.forms[0].orderClause.value = orderClause;
  document.forms[0].f_act.value='search';
  document.forms[0].submit();
};

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

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

function openCustomerStatistics(csEid) {
  var widthPopupWin = 900;
  var heightPopupWin = 700;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../statistic/statistic.php?f_act=calculate&f_category=3&f_statistic=51&g_cs_eid="+csEid+"&noStatisticMenu=1&outputColumnMode=0&outputTitle=Monatsübersicht&specialAligns=l,l,l,l,r&day_from=01&month_from=01&year_from=<?php echo getDateTime('lastyear'); ?>&day_to=<?php echo getDateTime('day'); ?>&month_to=<?php echo getDateTime('month'); ?>&year_to=<?php echo getDateTime('year'); ?>","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};
-->
</script>
</head>

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

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

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

  <form action="../admin/pt_list.php" method="post">
  <input type="hidden" name="f_act" value="">
  <input type="hidden" name="orderClause" value="<?php echo $orderClause ?>">
  <input type="hidden" name="tourno" value="<?php echo $tourno ?>">
  <input type="hidden" name="generic" value="<?php echo $generic ?>">
  <input type="hidden" name="genNum" value="<?php echo $genNum ?>">
  <input type="hidden" name="f_cmp_authenticated" value="<?php echo $f_cmp_authenticated ?>">
  <?php echo $tableHeaderSearchFieldsExtra ?>
  <?php echo $phpCurrentNavigationInputHidden ?>
  <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">

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

  <div class="f10bp1_blue">
    <?php echo $pageTitel ?>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <!-- Headquarters checkboxes -->
  <?php if (authCheckEmployeeRights($emp_id, "10")) : ?>
    <?php echo getHeadquartersCheckboxes($f_hq_id, $numOfHq); ?>
    <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
  <?php endif; ?>
  
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <?php echo $pageHeaderOptionFields ?>
  </div>
  <?php echo htmlDivLineSpacer("15px"); ?>

  <div>
    <table border="0">
      <tr>
        <td>
          <table border="0">
            <tr>
              <td>
                <table class="f8np1" border="0" cellpadding="0">
                  <tr>
                    <?php echo $tableHeaderSearchFields ?>
                  </tr>
                  <tr>
                    <?php echo $tableHeaderLinks ?>
                  </tr>
                  <?php echo $tableOfRows ?>
                </table>
                <br><br>
                <?php echo getLngt("Anzahl Einträge:") ?> <?php echo $numOfRows ?><?php if ($numOfRows == "0" && $f_act == "search" && $statusMessage == "") : echo " " . getLngt("(Keine Einträge gefunden.)"); endif; ?>
              </td>
            </tr>
          </table>
        </td>
    </table>
  </div>

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

</html>