<?php
/*=======================================================================
 *
 * csc_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", "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", "f_phone", "tourno",
                         "cscIdRoot","customerId","cscIdActual","csc_id"));

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

getLanguage(__FILE__);

getCurrentScript(__FILE__);

// Check for authentication access and granted rights
$usrAccessArray["cs"] = "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

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

$f_csc_name = trim($f_csc_name);
$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);
$f_person = trim($f_person);
$f_phone = trim($f_phone);

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

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

         $whereClause = "";
         if ($whereClause != "" && $f_csc_name != "") : $whereClause .= " AND "; endif;
         if ($f_csc_name != "") : $whereClause .= "csc.csc_name LIKE '" . $prefix . $f_csc_name . "%'"; endif;
         if ($whereClause != "" && $f_street != "") : $whereClause .= " AND "; endif;
         if ($f_street != "") : $whereClause .= "ad.ad_street LIKE '" . $prefix . $f_street . "%'"; endif;
         if ($whereClause != "" && $f_hsno != "") : $whereClause .= " AND "; endif;
         if ($f_hsno != "") : $whereClause .= "cscad.cscad_hsno LIKE '" . $prefix . $f_hsno . "%'"; endif;
         if ($whereClause != "" && $f_zipcode != "") : $whereClause .= " AND "; endif;
         if ($f_zipcode != "") : $whereClause .= "ad.ad_zipcode LIKE '" . $prefix . $f_zipcode . "%'"; endif;
         if ($whereClause != "" && $f_city != "") : $whereClause .= " AND "; endif;
         if ($f_city != "") : $whereClause .= "ad.ad_city LIKE '" . $prefix . $f_city . "%'"; endif;
         if ($whereClause != "" && $f_country != "") : $whereClause .= " AND "; endif;
         if ($f_country != "") : $whereClause .= "ad.ad_country LIKE '" . $prefix . $f_country . "%'"; endif;
         // if ($whereClause != "" && $f_remark != "") : $whereClause .= " AND "; endif;
         // if ($f_remark != "") : $whereClause .= "cscad.cscad_remark LIKE '" . $prefix . $f_remark . "%'"; endif;
         if ($whereClause != "" && $f_person != "") : $whereClause .= " AND "; endif;
         if ($f_person != "") : $whereClause .= "cscad.cscad_person LIKE '" . $prefix . $f_person . "%'"; endif;

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

         if ($orderClause == "") : $orderClause = "csc.csc_name"; endif;


         $cscNameRoot = getFieldValueFromId("costcenter","csc_id",$cscIdRoot,"csc_name");

         $cscIdsRoot = $cscIdRoot;
         $customerIds = $customerId;
         $cscNamesRoot = $cscNameRoot;
         // check for existens of children
         $sqlquery = "SELECT cs_id, csc_id FROM customer WHERE cs_id_parent = " . $customerId;
         $result = $db->query($sqlquery);
	     if (DB::isError($result)) die ("$PHP_SELF: '$sqlquery': " . $result->getMessage());
  	     while ($row = ($phpVersion >= "8.0" ? $result->fetch_assoc() : $result->fetchRow())):
  	       $cscIdsRoot .= "," . $row["csc_id"];
  	       $customerIds .= "," . $row["cs_id"];
           $cscNamesRoot .= "//%' OR csc.csc_path LIKE '%//" . getFieldValueFromId("costcenter","csc_id",$row["csc_id"],"csc_name");
   	     endwhile;
  	     $result->free();

         $whereClause2 .= "AND ((csc.csc_id IN (" . $cscIdsRoot . ")) OR " .
                     "(csc.csc_path LIKE '%//" . $cscNamesRoot . "//%')) AND " .
                     "csc.cs_id IN (" . $customerIds . ")";

  	     $sqlquery = "SELECT csc.csc_id, csc.csc_name, cs.cs_id, cs.cs_eid, cs.csc_id_payer, cs.cs_commission_no, cs.cs_jobbatch, cs.cs_discount, cs.cs_fixprice_discount, cs.cs_filter, cs.cs_invmode,"
  	                  . "    cmp.cmp_id, cmp.cmp_comp, cmp.cmp_comp2, cmp.cmp_authenticated, cmp.cmp_remark, cmp.cmp_match, cmp.cmp_cashmode,"
  	                  . "    cmp.tx_id, cscad.ad_id, cscad.cscad_comp, cscad.cscad_comp2, cscad.cscad_hsno,"
  	                  . "    cscad.cscad_remark, cscad.cscad_person, cscad.cscad_phone,"
  	                  . "    ad.ad_street, ad.ad_zipcode, ad.ad_city, ad.ad_country, gdc_content AS tr_mediationarea_id"
  	                  . " FROM company AS cmp, customer AS cs, costcenter AS csc,"
  	                  . "      costcenteraddress AS cscad, address AS ad"
                      . "      LEFT JOIN genericdatacontainer ON gdc_obj_type = 'ad' AND gdc_obj_id = ad.ad_id AND gdc_gen_fieldname = 'tr_mediationarea_id'"
  	                  . " WHERE " .$whereClause
  	                  . "       cs.hq_id = '$hq_id'              AND"
  	                  . "       cs.cs_id IN (" . $customerIds . ") AND"
  	                  . "       cmp.cmp_id = cs.cmp_id           AND"
  	                  . "       cs.cs_id = csc.cs_id                "
  	                  . "       " . $whereClause2 . "            AND"
  	                  . "       csc.csc_is_extern = '0'          AND"
  	                  . "       csc.csc_visible = '1'            AND"
  	                  . "       csc.csc_id = cscad.csc_id        AND"
  	                  . "       cscad.adt_id = '4'               AND"
  	                  . "       cscad.ad_id = ad.ad_id"
  	                  . " ORDER BY " . $orderClause;
//echo $sqlquery;
	       $result = $db->query($sqlquery);
	       if (DB::isError($result)) die ("$PHP_SELF: '$sqlquery': " . $result->getMessage());

  	     // Table with header
  	     while ($row = ($phpVersion >= "8.0" ? $result->fetch_assoc() : $result->fetchRow())):
               $numOfRows++;

               $tableOfRows .= "<tr>";
               if ($tourno == -1) {
                 $tableOfRows .= "<td>&nbsp;" . substr($row["cmp_comp"], 0, 30) . "</td>";

                 $tableOfRows .= "<td>&nbsp;" . substr($row["cmp_comp2"], 0, 15) . "</td>";
                 $tableOfRows .= "<td>&nbsp;" . substr($row["cs_eid"], 0, 11) . "</td>";
               }
                     $csc_id_payer_comp = "";
                     if ($row["csc_id_payer"] != "" && $row["csc_id_payer"] != 0)
                       $csc_id_payer_comp = $db->getOne("SELECT cmp_comp FROM company, customer, costcenter WHERE company.cmp_id = customer.cmp_id AND customer.cs_id = costcenter.cs_id AND costcenter.csc_id = " . $row["csc_id_payer"]);

                 if (trim($row["cscad_comp"] == ""))
                   $row["cscad_comp"] = $row["cmp_comp"];
               if (!isset($row["tr_mediationarea_id"]) || $row["tr_mediationarea_id"] == "")
                 $row["tr_mediationarea_id"] = 0;
               $tableOfRows .= "<td>&nbsp;<a href=\"javascript:finishPage('" . $row["cs_id"] . "','" . $row["csc_id"] . "','" . my_str_check_js($row["csc_name"]) . "','" . my_str_check_js($row["cscad_comp"]) . "','" . my_str_check_js($row["cscad_comp2"]) . "','" . my_str_check_js($row["ad_street"]) . "','" . $row["cscad_hsno"] . "','" . $row["ad_zipcode"] . "','" . my_str_check_js($row["ad_city"]) . "','" . my_str_check_js($row["ad_country"]) . "','" . my_str_check_js($row["cscad_remark"]) . "','" . my_str_check_js($row["cscad_person"]) . "','" . $tourno . "','" . my_str_check_js($row["csc_id_payer"]) . "','" . my_str_check_js($csc_id_payer_comp) . "','" . $row["tx_id"] . "','" . $row["cs_eid"]  . "','" . $row["cs_commission_no"] . "','" . $row["cmp_authenticated"]  . "','" . my_str_check_js($row["cmp_remark"]) . "','" . $row["cs_jobbatch"] . "','" . $row["cs_discount"] . "','" . $row["cs_fixprice_discount"] . "','" . $row["cs_filter"] . "','" . my_str_check_js($row["cmp_comp"]) . "','" . my_str_check_js($row["cmp_comp2"]) . "'," . $row["tr_mediationarea_id"] . "," . $row["cs_invmode"] . ");\">" . my_str_check_html(substr($row["csc_name"], 0, 40)) . "</a></td>";
               // $tableOfRows .= "<td>&nbsp;" . substr($row["cmp_match"], 0, 30) . "</td>";

               // $authImgName = "circle_red.jpg";
               // if ($row["cmp_authenticated"] == "1") : $authImgName = "circle_green.jpg"; endif;
               // $tableOfRows .= "<td align=\"center\"><img src=\"../images/" . $authImgName . "\" border=\"1\" height=\"10\" width=\"25\"></td>";

               $tableOfRows .= "<td>&nbsp;" . substr($row["ad_street"], 0, 20) . "</td>";
               $tableOfRows .= "<td>&nbsp;" . substr($row["cscad_hsno"], 0, 5) . "</td>";
               $tableOfRows .= "<td>&nbsp;" . substr($row["ad_zipcode"], 0, 5) . "</td>";
               $tableOfRows .= "<td>&nbsp;" . substr($row["ad_city"], 0, 20) . "</td>";
               // $tableOfRows .= "<td>&nbsp;" . substr($row["cscad_remark"], 0, 20) . "</td>";
               $tableOfRows .= "<td>&nbsp;" . substr($row["cscad_person"], 0, 20) . "</td>";
               $tableOfRows .= "<td>&nbsp;" . substr($row["cscad_phone"], 0, 15) . "</td>";

               $tableOfRows .= "</tr>";
  	     endwhile;
  	     $result->free();
//      else :
//        $statusMessage = getLngt("Bei Eingabe weniger als 3 Zeichen in mindestens einem Feld erfolgt keine Suche! Mind. ein Zeichen bei Kostenstelle reicht aus!");
//      endif;
   endif;
?>

<html>

<head>
<title><?php echo getLngt("KOSTENSTELLENLISTE") ?></title>
<link rel="stylesheet" type="text/css" href="../css/phoenix.css">

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

function displayStatusMessage() {
 if (statusMessage != "") {
    alert(statusMessage);
 }
};


function finishPage(cs_id,csc_id,name,comp,comp2,street,hsno,zipcode,city,country,remark,person,tourno,csc_id_payer,csc_id_payer_comp,tx_id,cs_eid,cs_commission_no,cmp_authenticated,cmp_remark,cs_jobbatch,cs_discount,cs_fixprice_discount,cs_filter,cmp_comp,cmp_comp2,tr_mediationarea_id,cs_invmode) {
  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");
    opener.setJobList(tourno, opener.jl_tr_mediationarea_id, tr_mediationarea_id);
    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";
    }
/*
    if (tx_id != "" && tx_id != 0)
    {
      opener.setSelectedOption("job_options", "tourOptions", "jb_sales_tax_rate_sign", tx_id);
      opener.checkJb_sales_tax_rate_sign();
    }
*/
<?php if (getParameterValue("0", "MASK_DONT_CHANGE_PAYER_" . $customerId, "0") != "1") : ?>
  if (csc_id_payer_comp != "address_only")
    opener.setCsc_id_payer(csc_id, comp);
<?php endif; ?>
  } else {
    opener.setCsc_id_payer(csc_id, cs_eid + " " + comp);
<?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);
    var i=opener.cs_eid_list.length;
    opener.cs_eid_list[i-1][12] = cs_id;
    opener.cs_eid_list[i-1][24] = cs_invmode;
    opener.cs_eid_list[i-1][13] = cs_fixprice_discount;
  }
  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();
};

function clearFields() {
  // document.forms[0].f_cmp_comp.value = '';
  // document.forms[0].f_cmp_comp2.value = '';
  // document.forms[0].f_cmp_match.value = '';
  // document.forms[0].f_cs_eid.value = '';
  document.forms[0].f_csc_name.value = '';
  document.forms[0].f_street.value = '';
  document.forms[0].f_hsno.value = '';
  document.forms[0].f_zipcode.value = '';
  document.forms[0].f_city.value = '';
  // document.forms[0].f_remark.value = '';
  document.forms[0].f_person.value = '';
  document.forms[0].f_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 SEARCH_CSCSCLIST_CMPCOMP_CMPMATCH ?> == 1) {
     	document.forms[0].f_cmp_match.value = document.forms[0].f_cmp_comp.value;
     }
     if (<?php echo SEARCH_CSCSCLIST_CMPCOMP_CSEID ?> == 1) {
     	document.forms[0].f_cs_eid.value = document.forms[0].f_cmp_comp.value;
     }
     if (<?php echo SEARCH_CSCSCLIST_CMPCOMP_CSCADPHONE ?> == 1) {
     	document.forms[0].f_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();
};
-->
</script>
</head>

<body onLoad="displayStatusMessage();">
  <form action="../customer/csc_list.php" method="post">
  <input type="hidden" name="f_act" value="">
  <input type="hidden" name="customerId" value="<?php echo $customerId ?>">
  <input type="hidden" name="cscIdRoot" value="<?php echo $cscIdRoot ?>">
  <input type="hidden" name="cscIdActual" value="<?php echo $cscIdActual ?>">    
  <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="f_cmp_authenticated" value="<?php echo $f_cmp_authenticated ?>">
  <table border="0">
    <tr>
      <td>
        <table border="0">
          <tr>
            <td class="f12bp1_red">
              <?php echo getLngt("Kostenstellen") ?><br><br>
            </td>
          </tr>
          <tr>
            <td>
              <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;&nbsp;&nbsp;
              <a href="javascript:clearFields();"><?php echo getLngt("Felder zurücksetzen") ?></a>
              &nbsp;&nbsp;&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") ?>

              <br><br>
              <table class="f8np1" border="1" cellpadding="0">
                <tr>
<?php if ($tourno != -1) echo "<!--"; ?>
                  <td><input type="text" <?php echo $htmlClass01 ?> name="f_cmp_comp" value="<?php echo $f_cmp_comp ?>" size="30" onBlur="javascript:checkSearchParameters('cmp_comp');"></td>
                  <td><input type="text" <?php echo $htmlClass01 ?> name="f_cmp_comp2" value="<?php echo $f_cmp_comp2 ?>" size="15"></td>
                  <td><input type="text" <?php echo $htmlClass01 ?> name="f_cs_eid" value="<?php echo $f_cs_eid ?>" size="11"></td>
<?php if ($tourno != -1) echo "-->"; ?>
                  <td><input type="text" <?php echo $htmlClass01 ?> name="f_csc_name" value="<?php echo $f_csc_name ?>" size="25"></td>
            <!--  <td><input type="text" <?php echo $htmlClass01 ?> name="f_cmp_match" value="<?php echo $f_cmp_match ?>" size="30"></td>  -->

            <!--  <td><a href="javascript:document.forms[0].f_act.value='search';document.forms[0].submit();">&nbsp;Suchen&nbsp;</a></td>  -->

            <!--  <td><input type="text" <?php echo $htmlClass01 ?> name="f_usr_name" value="<?php echo $f_usr_name ?>" size="15"></td>  -->
            <!--  <td><input type="text" <?php echo $htmlClass01 ?> name="f_usr_phone" value="<?php echo $f_usr_phone ?>" size="20"></td>  -->
            <!--  <td><input type="text" <?php echo $htmlClass01 ?> name="f_usr_email" value="<?php echo $f_usr_email ?>" size="30"></td>  -->

                  <td><input type="text" <?php echo $htmlClass01 ?> name="f_street" value="<?php echo $f_street ?>" size="25"></td>
                  <td><input type="text" <?php echo $htmlClass01 ?> name="f_hsno" value="<?php echo $f_hsno ?>" size="5"></td>
                  <td><input type="text" <?php echo $htmlClass01 ?> name="f_zipcode" value="<?php echo $f_zipcode ?>" size="5"></td>
                  <td><input type="text" <?php echo $htmlClass01 ?> name="f_city" value="<?php echo $f_city ?>" size="20"></td>
            <!--  <td><input type="text" <?php echo $htmlClass01 ?> name="f_remark" value="<?php echo $f_remark ?>" size="20"></td> -->
                  <td><input type="text" <?php echo $htmlClass01 ?> name="f_person" value="<?php echo $f_person ?>" size="20"></td>
                  <td><input type="text" <?php echo $htmlClass01 ?> name="f_phone" value="<?php echo $f_phone ?>" size="15"></td>
                </tr>
                <tr>
<?php if ($tourno != -1) echo "<!--"; ?>
                  <td><a href="javascript:document.forms[0].orderClause.value='cmp.cmp_comp';document.forms[0].f_act.value='search';document.forms[0].submit();">&nbsp;Firma&nbsp;</a></td>
                  <td><a href="javascript:document.forms[0].orderClause.value='cmp.cmp_comp2';document.forms[0].f_act.value='search';document.forms[0].submit();">&nbsp;Firma2&nbsp;</a></td>
                  <td><a href="javascript:document.forms[0].orderClause.value='cs.cs_eid';document.forms[0].f_act.value='search';document.forms[0].submit();">&nbsp;ExtID&nbsp;</a></td>
<?php if ($tourno != -1) echo "-->"; ?>
<!--
                  <td><a href="javascript:document.forms[0].orderClause.value='csc.csc_name';document.forms[0].f_act.value='search';document.forms[0].submit();">&nbsp;Kostenstelle&nbsp;</a></td>
                  <td><a href="javascript:document.forms[0].orderClause.value='cmp.cmp_match';document.forms[0].f_act.value='search';document.forms[0].submit();">&nbsp;Freitext&nbsp;</a></td>
                  <td><a href="javascript:document.forms[0].orderClause.value='ad.ad_street';document.forms[0].f_act.value='search';document.forms[0].submit();">&nbsp;Straße</a></td>
                  <td><a href="javascript:document.forms[0].orderClause.value='cscad.cscad_hsno';document.forms[0].f_act.value='search';document.forms[0].submit();">&nbsp;Hausnr.</a></td>
                  <td><a href="javascript:document.forms[0].orderClause.value='ad.ad_zipcode';document.forms[0].f_act.value='search';document.forms[0].submit();">&nbsp;PLZ</a></td>
                  <td><a href="javascript:document.forms[0].orderClause.value='ad.ad_city';document.forms[0].f_act.value='search';document.forms[0].submit();">&nbsp;Ort</a></td>
                  <td><a href="javascript:document.forms[0].orderClause.value='cscad.cscad_remark';document.forms[0].f_act.value='search';document.forms[0].submit();">&nbsp;Bemerkung</a></td>
                  <td><a href="javascript:document.forms[0].orderClause.value='cscad.cscad_person';document.forms[0].f_act.value='search';document.forms[0].submit();">&nbsp;Person</a></td>
                  <td><a href="javascript:document.forms[0].orderClause.value='cscad.cscad_phone';document.forms[0].f_act.value='search';document.forms[0].submit();">&nbsp;Telefon</a></td>
-->
            <!--  <td><a href="javascript:submitPage('cmp.cmp_comp');">&nbsp;Firma&nbsp;</a></td>  -->
            <!--  <td><a href="javascript:submitPage('cmp.cmp_comp2');">&nbsp;Firma2&nbsp;</a></td>  -->
            <!--  <td><a href="javascript:submitPage('cs.cs_eid');">&nbsp;ExtID&nbsp;</a></td>  -->

                  <td><a href="javascript:submitPage('csc.csc_name');">&nbsp;<?php echo getLngt("Kostenstelle") ?>&nbsp;</a></td>
            <!--  <td><a href="javascript:submitPage('cmp.cmp_match');">&nbsp;Freitext&nbsp;</a></td>  -->
            <!--  <td>&nbsp;Freigabe&nbsp;</td>   -->
                  <td><a href="javascript:submitPage('ad.ad_street');">&nbsp;<?php echo getLngt("Straße") ?></a></td>
                  <td><a href="javascript:submitPage('cscad.cscad_hsno');">&nbsp;<?php echo getLngt("Hausnr.") ?></a></td>
                  <td><a href="javascript:submitPage('ad.ad_zipcode');">&nbsp;<?php echo getLngt("PLZ") ?></a></td>
                  <td><a href="javascript:submitPage('ad.ad_city');">&nbsp;<?php echo getLngt("Ort") ?></a></td>
            <!--  <td><a href="javascript:submitPage('cscad.cscad_remark');">&nbsp;Bemerkung</a></td>  -->
                  <td><a href="javascript:submitPage('cscad.cscad_person');">&nbsp;<?php echo getLngt("Person") ?></a></td>
                  <td><a href="javascript:submitPage('cscad.cscad_phone');">&nbsp;<?php echo getLngt("Telefon") ?></a></td>
                </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 " (Keine Einträge gefunden.)"; endif; ?>
            </td>
          </tr>
        </table>
      </td>
  </table>
    <?php
      // Nur wenn eine csc_id übergeben und wenn ansonsten keine Einträge gefunden
      if ($csc_id != "" && $f_act == "search" && $statusMessage == "" && $tourno > -1) {
        $sqlquery = "SELECT jb_tourname, tr_sort, tr_comp, tr_person, tour.csc_id, ad_street, tr_hsno, ad_country, ad_zipcode, ad_city, tr_remark, tr_mediationarea_id" .
          " FROM job, tour, address WHERE (csc_id_payer = " . $csc_id . " AND csc_id_payer_cash = '0') AND LENGTH(jb_tourname) > 0" .
          " AND job.jb_id = tour.jb_id AND tour.ad_id = address.ad_id ORDER BY jb_tourname, tr_sort" ;
        $res = $db->query($sqlquery);
        if ($res->numRows() > 0) {
          echo "<br><table border=\"0\"><tr><td><table border=\"0\"><tr><td class=\"f12bp1_red\">";
          echo "Adressen aus gespeicherten Touren<br><br>";
          echo "<table border=\"1\"><tr><td>&nbsp;Name&nbsp;</td><td>&nbsp;Station&nbsp;</td><td" .
            ">&nbsp;</td><td" .
            ">&nbsp;Firma&nbsp;</td><td>&nbsp;Person&nbsp;</td><td>&nbsp;Straße&nbsp;</td><td" .
            ">&nbsp;Nr.&nbsp;</td><td>&nbsp;PLZ&nbsp;</td><td>&nbsp;Ort&nbsp;</td><td" .
            ">&nbsp;Bemerkung&nbsp;</td></tr>";
        }
        if (DB::isError($res)) die ("$PHP_SELF: '$sqlquery': " . $res->getMessage());
        $lineToggler = 0;
   	    while ($row = ($phpVersion >= "8.0" ? $res->fetch_assoc() : $res->fetchRow())):
          if ($lineToggler == 0) : $lineToggler = 1; else : $lineToggler = 0; endif;
          echo "<tr><td>&nbsp;" . $row["jb_tourname"] . "</td><td>&nbsp;" . $row["tr_sort"] . "</td><td>" .            
            "<a href=\"javascript:finishPage('','" . $row["csc_id"] . "','','" . my_str_check_js($row["tr_comp"]) . "','','" . my_str_check_js($row["ad_street"]) . "','" . $row["tr_hsno"] . "','" .
            $row["ad_zipcode"] . "','" . my_str_check_js($row["ad_city"]) . "','" . my_str_check_js($row["ad_country"]) . "','" . my_str_check_js($row["tr_remark"]) . "','" .
            my_str_check_js($row["tr_person"]) . "','" . $tourno . "','','address_only','','','','','','','','','',''," . $row["tr_mediationarea_id"] . ");\">" .
            "<img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\">" . "</a>" . "</td><td" .
            ">&nbsp;" . $row["tr_comp"] . "</td><td>&nbsp;" . $row["tr_person"] . "</td><td" .
            ">&nbsp;" . $row["ad_street"] . "</td><td>&nbsp;" . $row["tr_hsno"] . "</td><td" .
            ">&nbsp;" . $row["ad_zipcode"] . "</td><td>&nbsp;" . $row["ad_city"] . "</td><td" .
            ">&nbsp;" . $row["tr_remark"] . "</td></tr>";
   	    endwhile;
        if ($res->numRows() > 0)
          echo "</td></td></tr>";
          echo "</tr></td></table></tr></td></table>";
   	    $res->free();
   	  }
    ?>

</body>

</html>
