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

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


$httpVars = array("f_act", "companyId", "orderClause", "statusMessage", "printVersion");

$httpVisualVars = array("f_cmp_authenticated", "f_cmp_comp", "f_cmp_comp2", "f_cs_eid", "f_usr_id", "f_usr_name", "f_usr_firstname",  
                        "f_usr_phone", "f_usr_phone2", "f_usr_fax", "f_usr_email", "f_cmp_iln", "f_cmp_tax_idno", "f_cs_invmode",
                        "f_cmp_bank", "f_cmp_bankno", "f_cmp_bankacc", "f_cmp_bankmode", "f_cs_discount", "f_cmp_postage", "f_cmp_inv2hq", 
                        "f_usr_account", "f_usr_password", "cpfs", "f_usr_password2", "f_cs_jbstatusmail", "f_cs_jbstatusmail2", "f_cs_jbstatusmail3", 
                        "f_cs_commission_no", "f_cs_cr_fav_only", "f_cs_jobbatch", "f_cmp_cashmode", "f_cmp_visible", "f_cs_fixprice_discount",
                        "f_ad_changemode", "f_adt_change", "f_cmp_changemode", "f_adt_change2", "f_cs_invtext_mode", "f_cs_prov",
                        "f_ad_street", "f_cmp_hsno", "f_ad_zipcode", "f_ad_city", "f_ad_country", "f_cmp_match", "f_cmp_match2", 
                        "f_cmp_remark", "f_cmp_remark2", "f_noaddressvalidation", "g_cs_id", "g_csc_id", "g_tx_id", "g_br_id", "g2_cs_id", 
                        "copyPt", "deactivateMenu");

$httpVarsArray = array_merge ($httpVars, $httpVisualVars);
                         
getSecHttpVars("1", $httpVarsArray);                         

getLanguage(__FILE__);

$deactivateMenuStatic = "1";
$pageTitel = getLngt("INTERESSENT");
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");

// No operation if print version requested
if ($printVersion == "1") : $f_act = ""; endif;


$addressValidationErr = "";
$dbOperationCompleted = "0";

// Check for validation of the address assigned to the customer
$noValidationOfAddress = FALSE;
if ($f_noaddressvalidation != "") :
   if ($f_noaddressvalidation[0] == '1') : $noValidationOfAddress = TRUE; endif;
endif;

// Init parameters:
// Invoice mode
if ($f_cmp_inv2hq == "" || count($f_cmp_inv2hq) == 0) :
   $f_cmp_inv2hq = "0";
else :
   $f_cmp_inv2hq = $f_cmp_inv2hq[0] + $f_cmp_inv2hq[1];
endif;
// Only favoured couriers
if ($f_cs_cr_fav_only == "" || count($f_cs_cr_fav_only) == 0) :
   $f_cs_cr_fav_only = "0";
else: 
   $f_cs_cr_fav_only = "1";
endif;
// Flag for "list customer" (jobbatch)
if ($f_cs_jobbatch == "" || count($f_cs_jobbatch) == 0) :
   $f_cs_jobbatch = "0";
else: 
   $f_cs_jobbatch = "1";
endif;
// Flag for fixprice discount
if ($f_cs_fixprice_discount == "" || count($f_cs_fixprice_discount) == 0) :
   $f_cs_fixprice_discount = "0";
else: 
   $f_cs_fixprice_discount = "1";
endif;
// Flag for invoice text mode
if ($f_cs_invtext_mode == "" || count($f_cs_invtext_mode) == 0) :
   $f_cs_invtext_mode = "0";
else: 
   $f_cs_invtext_mode = "1";
endif;
// Change costcenter addresses according to the main address
$changeInvoiceAddress = FALSE;
$changePickUpAddress = FALSE;
if ($f_adt_change != "") :
   if (!(array_search("2",$f_adt_change) === FALSE)) : $changeInvoiceAddress = TRUE; endif;
   if (!(array_search("4",$f_adt_change) === FALSE)) : $changePickUpAddress = TRUE; endif;
endif;
// Change costcenter company names according to the main name
$changeInvoiceCompany = FALSE;
$changePickUpCompany = FALSE;
if ($f_adt_change2 != "") :
   if (!(array_search("2",$f_adt_change2) === FALSE)) : $changeInvoiceCompany = TRUE; endif;
   if (!(array_search("4",$f_adt_change2) === FALSE)) : $changePickUpCompany = TRUE; endif;
endif;

// Get EID prefix and reset EID only if equals prefix
$constCsEidPrefix = getParameterValue("0", "CS_EID_PREFIX", $hq_id);
if ($f_cs_eid == $constCsEidPrefix) : $f_cs_eid = ""; endif;    

// Initialize service-mode for invoicing with global default setting
if ($f_cs_invmode == "") : 
   // Get the general invmode for the headquarter
   $hq_invmode = getFieldValueFromId("headquarters", "hq_id", "$hq_id", "hq_invmode");
   $f_cs_invmode = $hq_invmode;
endif;

   // ********************************
   // * Operations for the customers *   
   // ********************************

   // Generate log string
   if ($f_act != "") :
      $logString = makeLogString(array($f_cmp_authenticated,$f_cmp_comp,$f_cmp_comp2,$f_cs_eid,$f_usr_name,
                                       $f_usr_firstname,$f_usr_phone,$f_usr_phone2,$f_usr_fax,$f_usr_email,$f_cmp_iln,
                                       $f_cmp_tax_idno,$f_cs_invmode,$f_cmp_bank,$f_cmp_bankno,$f_cmp_bankacc,
                                       $f_cmp_bankmode,$f_cs_discount,$f_cmp_postage,$f_cmp_inv2hq,$f_usr_account,
                                       $f_cs_jbstatusmail,$f_cs_commission_no,$f_cs_cr_fav_only,$f_cs_jobbatch,
                                       $f_cmp_cashmode,$f_cmp_visible,$f_ad_changemode,$f_adt_change,$f_cmp_changemode,
                                       $f_adt_change2,$f_ad_street,$f_cmp_hsno,$f_ad_zipcode,$f_ad_city,$f_ad_country,
                                       $f_cmp_match,$f_cmp_match2,$g_cs_id,$g_csc_id,$g_tx_id,$g_br_id,$g2_cs_id,
                                       $f_cs_fixprice_discount,$f_cs_jbstatusmail2,$f_cs_jbstatusmail3, 
                                       $f_cs_invtext_mode, $f_cs_prov, $f_cmp_remark,$f_cmp_remark2), ";", "0");
   endif;

   // Insert new prospect
   if ($f_act == "newCustomer") :
      
      if ($f_cmp_comp != "" && $f_cs_eid != "" && $f_usr_phone != "" && 
          $f_ad_street != "" && $f_ad_zipcode != "" && $f_ad_city != "" && $f_cmp_hsno != "") :
          // $f_usr_name != "" && $f_usr_firstname != "" && 

         // Check unique account for all customers (all data) except the current one to be updated
         if ($f_usr_account != "" && $db->getOne("SELECT usr.usr_id FROM user AS usr WHERE usr.usr_account = '" . $f_usr_account . "' ")) :
            $statusMessage = getLngt("Der Benutzername existiert schon! Bitte wählen Sie einen anderen!");
            
         elseif (FALSE && $db->getOne("SELECT cmp_comp FROM company WHERE cmp_comp = '" . $f_cmp_comp . "'")) :
                $statusMessage = getLngt("Der Firmenname ist bereits vorhanden! Bitte wählen Sie einen anderen!");
         
         elseif ($db->getOne("SELECT pt_cs_eid FROM prospect WHERE pt_cs_eid = '" . $f_cs_eid . "'")) :
                $statusMessage = getLngt("Die eindeutige Interessentennummer (ExtID) ist bereits vergeben! Bitte wählen Sie eine andere");
         
         // The account and password can be empty (only for customer)
         elseif ($f_usr_password == "" || checkPasswordValidation($f_usr_password,$f_usr_password2)) : 

            // Check address for validation
            $addressValid = getGeoCoordinates($f_ad_street, $f_ad_zipcode, $f_ad_city, $f_cmp_hsno, $f_ad_country, "");
            if ($addressValid != "") :
                
                // Check zipcode and city
                $addressValidityArray = checkCityZipcode($f_ad_zipcode, $f_ad_city, $f_ad_street);
                
                if ($noValidationOfAddress || $addressValidityArray[0] >= 1) :
                
                   TA("B");
                        
                   $currentTime = getDateTime("0");

                   // Insert prospect
                   $f_cs_discount = str_replace (",", ".", $f_cs_discount);
                   $f_cs_prov = str_replace (",", ".", $f_cs_prov);
                   insertStmt("prospect", array("hq_id", $hq_id, "pt_cmp_comp", $f_cmp_comp, "pt_cmp_comp2", $f_cmp_comp2,
                                                "pt_cmp_authenticated", "1", "pt_cmp_visible", "1", "pt_cmp_hsno", $f_cmp_hsno,
                                                "pt_cs_eid", $f_cs_eid, "pt_cmp_cashmode", $f_cmp_cashmode,
                                                "pt_cs_discount", $f_cs_discount, "pt_cs_fixprice_discount", $f_cs_fixprice_discount,
                                                "pt_cs_invmode", $f_cs_invmode, "pt_cs_commission_no", $f_cs_commission_no,
                                                "pt_usr_name", $f_usr_name, "pt_usr_firstname", $f_usr_firstname, "pt_usr_email", $f_usr_email,
                                                "pt_usr_phone", $f_usr_phone, "pt_usr_phone2", $f_usr_phone2, "pt_usr_fax", $f_usr_fax,
                                                "pt_cmp_match", $f_cmp_match, "pt_cmp_match2", $f_cmp_match2,
                                                "pt_cmp_remark", $f_cmp_remark, "pt_cmp_remark2", $f_cmp_remark2));
                   $pt_id_new = getLastInsertId();
                                      
                   // Insert address
                   $tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
                   $ad_id_new = $tmpArray[0];

                   // Update (the new) company-entry with address-id
                   updateStmt("prospect", "pt_id", $pt_id_new, array("ad_id", $ad_id_new));
                   
                   // Write logdata into log database
                   writeToLogDB("67",$hq_id,"",$usr_id,"","","","STATUS_NEW=" . $logString,"",$pt_id_new);

                   TA("C");
                   TA("E");
                
                   // Reset fields of form-parameters
                   // clearParameters($httpVisualVars);   // <= Moved to the end of the php-part of this script...
                   $dbOperationCompleted = "1";
                
                else :
                  $statusMessage = getLngt("Die Postleitzahl bzw. Strasse passt nicht zu dem angegebenen Ort!");
                  $addressValidationErr = "1";
                endif;
 
            else :
              $statusMessage = getLngt("Der Adress-Server kennt die eingebene Adresse nicht oder besitzt keine Geocodierung!");
            endif;
 
         endif;
      else :
         $statusMessage = getLngt("Bitte geben Sie alle mit * gekennzeichneten Felder ein!");
      endif;
   endif;            

   // Modify prospect
   if ($f_act == "modifyCustomer" && $companyId != "") :
      
      if ($f_cmp_comp != "" && $f_usr_phone != "" && 
          $f_ad_street != "" && $f_ad_zipcode != "" && $f_ad_city != "" && $f_cmp_hsno != "") :
          // $f_cs_eid != "" &&  $f_usr_name != "" && $f_usr_firstname != "" && 
                                        
         if ($f_usr_account != "" && 
            $db->getOne("SELECT usr.usr_id FROM user AS usr " . 
                         " WHERE usr.usr_account = '" . $f_usr_account . "' AND " .
                         "       usr.usr_id != $f_usr_id")) :
            $statusMessage = getLngt("Der Benutzername existiert schon! Bitte wählen Sie einen anderen!");

         else : 

           if (trim($f_usr_account) == "" || $cpfs == "0" || ($cpfs == "1" && trim($f_usr_account) != "" && checkPasswordValidation($f_usr_password,$f_usr_password2))) :

               if ($db->getOne("SELECT pt_cs_eid FROM prospect WHERE pt_cs_eid = '" . $f_cs_eid . "' AND " 
                                                             . " NOT (pt_id = '" . $companyId . "')")) :
                  $statusMessage = getLngt("Die eindeutige Interessentennummer (ExtID) ist bereits vergeben! Bitte wählen Sie eine andere");

               else :         
                  $addressValid = getGeoCoordinates($f_ad_street, $f_ad_zipcode, $f_ad_city, $f_cmp_hsno, $f_ad_country, "");            
                  if ($addressValid != "") :

                     // Check zipcode and city
                     $addressValidityArray = checkCityZipcode($f_ad_zipcode, $f_ad_city, $f_ad_street);
                     if ($noValidationOfAddress || $addressValidityArray[0] >= 1) :
                        
                        TA("B");
                                                
                        // Update prospect
                        $f_cs_discount = str_replace (",", ".", $f_cs_discount);
                        $f_cs_prov = str_replace (",", ".", $f_cs_prov);
                        $defaultFields = array("pt_cmp_comp", $f_cmp_comp, "pt_cmp_comp2", $f_cmp_comp2,
                                               "pt_cs_eid", $f_cs_eid, "pt_cmp_cashmode", $f_cmp_cashmode, "pt_cmp_hsno", $f_cmp_hsno,
                                               "pt_cs_discount", $f_cs_discount, "pt_cs_fixprice_discount", $f_cs_fixprice_discount,
                                               "pt_cs_invmode", $f_cs_invmode, "pt_cs_commission_no", $f_cs_commission_no,
                                               "pt_usr_name", $f_usr_name, "pt_usr_firstname", $f_usr_firstname, "pt_usr_email", $f_usr_email,
                                               "pt_usr_phone", $f_usr_phone, "pt_usr_phone2", $f_usr_phone2, "pt_usr_fax", $f_usr_fax,
                                               "pt_cmp_match", $f_cmp_match, "pt_cmp_match2", $f_cmp_match2,
                                               "pt_cmp_remark", $f_cmp_remark, "pt_cmp_remark2", $f_cmp_remark2);
                        updateStmt("prospect","pt_id",$companyId,$defaultFields);

                        // Insert address
                        $tmpArray = insertAddress($f_ad_street, $f_ad_zipcode, $f_ad_city, "", $f_ad_country, $noValidationOfAddress);
                        $ad_id_new = $tmpArray[0];

                        // Update (the new) company-entry with address-id
                        updateStmt("prospect", "pt_id", $companyId, array("ad_id", $ad_id_new));


                        // Write logdata into log database
                        writeToLogDB("68",$hq_id,"",$usr_id,"","","","STATUS_MODIFIED=" . $logString,"",$companyId);

                        TA("C");
                        TA("E");

                        $dbOperationCompleted = "1";

                     else :
                       $statusMessage = getLngt("Die Postleitzahl passt nicht zu dem angegebenen Ort!");
                       $addressValidationErr = "1";
                     endif;
                  
                  else :
                    $statusMessage = getLngt("Der Adress-Server kennt die eingebene Adresse nicht oder besitzt keine Geocodierung!");
                  endif;               
                  
               endif;               
          endif;  // account empty or not empty and checked by passwordcheck
         endif;        
      else :
         $statusMessage = getLngt("Bitte geben Sie alle mit * gekennzeichneten Felder ein!");
      endif;                                                            
   endif;
   
   // Delete prospect
   if ($f_act == "removeCustomer" && $companyId != "") :
      if (!existsEntry("prospect",array("pt_id",$companyId))) :
         // if (getDbFieldValues("employee",array("usr_id"),array("emp_id",$emp_id_act))) :
         //   TA("B");
         //   deleteStmt("employee","emp_id = ".$emp_id_act);
         //   deleteStmt("user","usr_id = ".$usr_id_new);
         
         //   // Write logdata into log database
         //   $v_cs_id = getFieldValueFromId("customer", "cmp_id", $companyId, "cs_id");
         //   writeToLogDB("71",$hq_id,"",$usr_id,"","",$v_cs_id,"STATUS_DELETED");
         
         //   TA("C");
         //   TA("E");
         // else : 
         //   $statusMessage = getLngt("Datenfehler! Merken Sie sich bitte den Datensatz und kontaktieren uns!!!");
         // endif;
      endif;
   endif;  
      
   // Set status of authentication of the prospect
   if ($f_act == "setAuthentication") :

      // Check for prospect
      if ($companyId != "") :

         if (existsEntry("prospect",array("pt_id",$companyId))) :

            // Update authentication-status
            updateStmt("prospect","pt_id",$companyId,array("pt_cmp_authenticated",$f_cmp_authenticated));
            
            // Write logdata into log database
            writeToLogDB("69",$hq_id,"",$usr_id,"","","","STATUS_AUTHENTICATION=".$f_cmp_authenticated,"",$companyId);
         else :               
            $statusMessage = getLngt("Der spezifizierte Interessent ist nicht im Datenbestand erhalten!");
         endif;      
      else :
         $statusMessage = getLngt("Sie haben keinen Interessenten spezifiziert!");
      endif;
   endif;
   
   // Set status of visibility of the customer
   if ($f_act == "setVisibility") :

      // Check for company
      if ($companyId != "") :

         if (existsEntry("prospect",array("pt_id",$companyId))) :

            // Update authentication-status
            updateStmt("prospect","pt_id",$companyId,array("pt_cmp_visible",$f_cmp_visible));

            // Write logdata into log database
            writeToLogDB("70",$hq_id,"",$usr_id,"","","","STATUS_VISIBILITY=".$f_cmp_visible,"",$companyId);
         else :               
            $statusMessage = getLngt("Der spezifizierte Interessent ist nicht im Datenbestand erhalten!");
         endif;      
      else :
         $statusMessage = getLngt("Sie haben keinen Interessenten spezifiziert!");
      endif;
   endif;   
   
   // Set status of cash mode of the customer
   if ($f_act == "setCashmode") :

      // Check for company
      if ($companyId != "") :

         if (existsEntry("prospect",array("pt_id",$companyId))) :

            // Update authentication-status
            updateStmt("prospect","pt_id",$companyId,array("pt_cmp_cashmode",$f_cmp_cashmode));
            
            // Write logdata into log database
            writeToLogDB("72",$hq_id,"",$usr_id,"","","","STATUS_CASHMODE=".$f_cmp_cashmode,"",$companyId);
         else :               
            $statusMessage = getLngt("Der spezifizierte Interessent ist nicht im Datenbestand erhalten!");
         endif;      
      else :
         $statusMessage = getLngt("Sie haben keinen Interessenten spezifiziert!");
      endif;
   endif;   


   // *******************************************************************
   // * Selection of the customer-data only for the current headquarter *
   // *******************************************************************
   if ($companyId != "") :
      $sqlquery = "SELECT pt.pt_id, pt.hq_id, pt.pt_cmp_comp, pt.pt_cmp_comp2, pt.pt_cmp_hsno,"
                   . "    pt.pt_cmp_remark, pt.pt_cmp_remark2, pt.pt_cmp_match,"
                   . "    pt.pt_cmp_match2, pt.pt_cmp_cashmode, pt.pt_cs_discount, pt.pt_cs_eid,"
                   . "    pt.pt_cs_invmode, pt.pt_cmp_authenticated, pt.pt_cmp_visible, pt.tx_id, pt.br_id,"
                   . "    pt.pt_usr_name, pt.pt_usr_firstname, pt.pt_usr_email, pt.pt_usr_phone,"
                   . "    pt.pt_usr_phone2, pt.pt_usr_fax, ad.ad_id, ad.ad_street, ad.ad_zipcode, ad.ad_city, ad.ad_country"
                   . " FROM prospect AS pt, address AS ad"
                   . " WHERE pt.pt_id = $companyId AND"
                   . getSQLMandatorPhrase($emp_id, "pt.hq_id = '" . $hq_id . "' AND")
                   . "       pt.ad_id = ad.ad_id";

      $result = $db->query($sqlquery);

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

      while ($row = $result->fetch_assoc()):
            $f_cmp_comp          = $row["pt_cmp_comp"];
            $f_cmp_comp2         = $row["pt_cmp_comp2"];
            $f_cmp_hsno          = $row["pt_cmp_hsno"];
            $f_cmp_iln           = $row["pt_cmp_iln"];
            $f_cmp_tax_idno      = $row["pt_cmp_tax_idno"];
            $f_cmp_bank          = $row["pt_cmp_bank"];
            $f_cmp_bankno        = $row["pt_cmp_bankno"];
            $f_cmp_bankacc       = $row["pt_cmp_bankacc"];
            $f_cmp_bankmode      = $row["pt_cmp_bankmode"];
            $f_cmp_postage       = $row["pt_cmp_postage"];
            $f_cmp_inv2hq        = $row["pt_cmp_inv2hq"];
            $f_cmp_match         = $row["pt_cmp_match"];
            $f_cmp_match2        = $row["pt_cmp_match2"];
            $f_cmp_remark        = $row["pt_cmp_remark"];
            $f_cmp_remark2       = $row["pt_cmp_remark2"];
            $f_cmp_authenticated = $row["pt_cmp_authenticated"];
            $f_cmp_authenticated2 = 0;
            if ($f_cmp_authenticated != "1") :
               $f_cmp_authenticated = 0; 
               $f_cmp_authenticated2 = 1;
            endif;
            $f_cmp_visible = $row["pt_cmp_visible"];
            $f_cmp_visible2 = 0;
            if ($f_cmp_visible != "1") :
               $f_cmp_visible = 0; 
               $f_cmp_visible2 = 1;
            endif;
            $f_cmp_cashmode = $row["pt_cmp_cashmode"];
            $f_cmp_cashmode2 = 0;
            if ($f_cmp_cashmode != "1") :
               $f_cmp_cashmode = 0; 
               $f_cmp_cashmode2 = 1;
            endif;
            $f_pt_id             = $row["pt_id"];
            $f_cs_eid            = $row["pt_cs_eid"];
            $f_cs_hq_id          = $row["hq_id"];
            $f_cs_discount       = $row["pt_cs_discount"];
            $f_cs_invmode        = $row["pt_cs_invmode"];            
            $f_cs_commission_no  = $row["pt_cs_commission_no"];
            $f_cs_cr_fav_only    = $row["pt_cs_cr_fav_only"];
            $f_cs_jobbatch       = $row["pt_cs_jobbatch"];
            $f_cs_invtext_mode   = $row["pt_cs_invtext_mode"];            
            $f_cs_fixprice_discount = $row["pt_cs_fixprice_discount"];
            $f_cs_prov           = $row["pt_cs_prov"];
            $f_usr_name          = $row["pt_usr_name"];
            $f_usr_firstname     = $row["pt_usr_firstname"];
            $f_usr_email         = $row["pt_usr_email"];
            $f_usr_phone         = $row["pt_usr_phone"];
            $f_usr_phone2        = $row["pt_usr_phone2"];
            $f_usr_fax           = $row["pt_usr_fax"];
            $f_ad_id             = $row["ad_id"];
            $f_ad_street         = $row["ad_street"];
            $f_ad_zipcode        = $row["ad_zipcode"];
            $f_ad_city           = $row["ad_city"];
            $f_ad_country        = $row["ad_country"];
            
            $g_csc_id            = $row["csc_id_payer"];
            $g_tx_id             = $row["tx_id"];
            $g_br_id             = $row["br_id"];
            $g2_cs_id            = $row["cs_id_parent"];
      endwhile;
      $result->free();
   endif;

   // Get the data of the tax if exists
   if ($g_tx_id != "") :
       $g_tx_sign = getFieldValueFromId("tax", "tx_id", "$g_tx_id", "tx_sign");
       $g_tx_value = getFieldValueFromId("tax", "tx_id", "$g_tx_id", "tx_value");
   endif;
   // Get the data of the branch if exists
   if ($g_br_id != "") :
       $g_br_key = getFieldValueFromId("branch", "br_id", "$g_br_id", "br_key");
       $g_br_name = getFieldValueFromId("branch", "br_id", "$g_br_id", "br_name");
   endif;


   // Get max-value of the EID of the current courier for inserting a new row 
   // The constant value "CS_EID_GENERATION" contains the prefix of the SID [SPECIAL TREATMENT]
   $f_eid_maxval = "";
   // $csEidGeneration = getParameterValue("0", "CS_EID_GENERATION");
   if (CS_EID_GENERATION != "") :
      $f_eid_maxval = getMaxOfField("prospect", "pt_cs_eid", "pt_cs_eid < '" . CS_EID_GENERATION . "'");
      if (is_numeric($f_eid_maxval)) :
         ++$f_eid_maxval;   // Increment because of the next free EID (Attention: Not TA-safe!)
      else :
        // Remove alphanumeric chars (e.g "HTHB123456" => "123456")
        $prefixChars = ereg_replace("[^[:alpha:]+]","",$f_eid_maxval);
        $f_eid_maxval = ereg_replace("[^[:digit:]+]","",$f_eid_maxval);
        ++$f_eid_maxval;
        $f_eid_maxval = $prefixChars . $f_eid_maxval;
      endif;
   endif;

   // Check if a copy of the current prospect is requested. 
   // If it is then reset some values
   if ($copyPt == "1") :
      $companyId = "";
      $f_cs_eid = "";
      // $statusMessage = getLngt("ACHTUNG: Aus Sicherheitsgründen werden ausschließlich Daten des Stammblatts kopiert! Filter, Services, Kostenstellen, etc. sind entsprechend nachträglich zuzuweisen!");
   endif;

   // Only for output
   $title = getLngt("NEUER INTERESSENT");
   $buttonCourier = "";
   $buttonAuthentication = "";
   $buttonVisibility = "";
   $buttonCashmode = "";
   $buttonGroup = "";
   $displayTextAuthentication = "";
   $displayTextVisibility = "";
   $confirmTextAuthentication = "";
   $confirmTextVisibility = "";
   $confirmTextCashmode = "";   
   $serviceLink1 = "";
   $serviceLink2 = "";
   $serviceLink3 = "";
   $serviceLink4 = "";
   $buttonFilter = "";
   $buttonService = "";
   $buttonSetToCs = "";
   $buttonCopy = "";

   if ($companyId != "") :
      $title = getLngt("INTERESSENT:") . " &nbsp;" . substr($f_cmp_comp . " " . $f_cmp_comp2, 0, 100);

      // Show mandator
      if (authCheckEmployeeRights($emp_id, "10")) :
         
         // Name of the headquarter
         $hq_name = getFieldValueFromId("headquarters", "hq_id", $f_cs_hq_id, "hq_name");
         $title .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
         $title .= "[" . $hq_name . "]";
      endif;

      // $buttonCourier = defineButtonType08(getLngt("Transporteure"), "action_cr", "openCustomerCouriers();", "90", "left", "3");
      // $buttonFilter = defineButtonType08(getLngt("Filter"), "action_crf", "openCustomerFilters();", "90", "left", "3");
      // $buttonService = defineButtonType08(getLngt("Services"), "action_srv", "openCustomerServices();", "90", "left", "3");
      $buttonCopy = defineButtonType08(getLngt("Kopie"), "action_copy", "copyProspect();", "90", "left", "3");
      $buttonSetToCs = defineButtonType08(getLngt("Kunde"), "action_move", "setProspectToCustomer('" . ec($companyId) . "');", "90", "left", "3");
      // $buttonGroup = defineButtonType08(getLngt("Gruppen"), "action_grp", "openGroups('" . ec($companyId) . "');", "90", "left", "3");

      $buttonAuthentication = defineButtonType08(getLngt("Sperren"), "action_lock", "authenticationFinishPage();", "90", "left", "3");
      $confirmTextAuthentication = getLngt("Soll der Interessent wirklich gesperrt werden?");
      if ($f_cmp_authenticated != "1") : 
         $buttonAuthentication = defineButtonType08(getLngt("Freischalten"), "action_lock", "authenticationFinishPage();", "90", "left", "3");
         $displayTextAuthentication = getLngt("(gesperrt)");
         $confirmTextAuthentication = getLngt("Soll der Interessent wirklich freigeschaltet werden?");
      endif;

      $buttonVisibility = defineButtonType08(getLngt("Ausblenden"), "action_visible", "visibilityFinishPage();", "90", "left", "3");
      $confirmTextVisibility = getLngt("Soll der Interessent wirklich ausgeblendet werden?");
      if ($f_cmp_visible != "1") : 
         $buttonVisibility = defineButtonType08(getLngt("Einblenden"), "action_visible", "visibilityFinishPage();", "90", "left", "3");
         $displayTextVisibility = getLngt("(ausgeblendet)");
         $confirmTextVisibility = getLngt("Soll der Interessent wirklich eingeblendet werden?");
      endif;

      // $buttonCashmode = defineButtonType08(getLngt("Rechnung"), "action_cashmode", "cashModeFinishPage();", "90", "left", "3");
      $confirmTextCashmode = getLngt("Soll der Interessent zukünftig wieder Rechnungen erhalten?");
      if ($f_cmp_cashmode != "1") :
         // $buttonCashmode = defineButtonType08(getLngt("Nur&nbsp;bar"), "action_cashmode", "cashModeFinishPage();", "90", "left", "3");
         $confirmTextCashmode = getLngt("Soll der Interessent zukünftig wirklich nur barzahlen?");
      endif;

      $buttonCostcenter = "";
      // IMPORTANT: Check if customer-admin-user-account exists, because in this case only the customer has to administrate the costcenters !!!
      if ($f_usr_account == "") :
         // $buttonCostcenter = defineButtonType08(getLngt("Kostenstellen"), "action_csc", "openCostcenterAdmin();", "90", "left", "3");
      endif;
      
/*   
      if (authCheckEmployeeRights($emp_id, "2")) :
         $serviceLink1 = "Service: <a href=\"../admin/services.php?opener=1&mode=price&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Preise") . "</a>/" .
                                  "<a href=\"../admin/services.php?opener=1&mode=discount&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Rabatte") . "</a>\n";
         $serviceLink2 = "PLZ: <a href=\"../admin/services_plz.php?opener=1&mode=price&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Preise") . "</a>/" . 
                              "<a href=\"../admin/services_plz.php?opener=1&mode=discount&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Rabatte") . "</a>\n";
         $serviceLink3 = "PLZ-Bereiche: <a href=\"../admin/services_plz_area.php?opener=1&mode=price&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Preise") . "</a>/" . 
                                       "<a href=\"../admin/services_plz_area.php?opener=1&mode=discount&csId=" . ec($f_cs_id) . "\" target=\"_blank\">" . getLngt("Rabatte") . "</a>\n";
         $serviceLink4 = "\n";
      else :
         $serviceLink1 = getLngt("Service: Preise/Rabatte") . "</td>\n";
         $serviceLink2 = getLngt("PLZ: Preise/Rabatte") . "</td>\n";
         $serviceLink3 = getLngt("PLZ-Bereiche: Preise/Rabatte") . "</td>\n";
         $serviceLink4 = "\n";      
      endif;   
*/      
   endif;

   // Password-fields for entering a new customer (admin-user)
   $setPasswordForNewUserOutput = "<td>&nbsp;</td><td>&nbsp;</td>";
   $setPassword2ForNewUserOutput = "<td>&nbsp;</td><td>&nbsp;</td>";         
   if (MASK_CUSTOMERDETAILS_TARGET == "1") :
      $setPasswordForNewUserOutput = "";
      $setPassword2ForNewUserOutput = "";
   endif;
   $cpfs = "0";   // checkPasswordForStoring
   if ($companyId == "" || $f_usr_account == "") :

      $setPasswordForNewUserOutput = "<input class=\"smaller\" type=\"password\" name=\"f_usr_password\" value=\"\" size=\"15\" tabindex=\"250\" disabled>\n";
      $setPassword2ForNewUserOutput = "<input class=\"smaller\" type=\"password\" name=\"f_usr_password2\" value=\"\" size=\"15\" tabindex=\"260\" disabled>\n";
      $cpfs = "1";      
   endif;    

   // Only for output:
   // Check for updating the list
   $javaScriptOut = "";
   if ($statusMessage == "" && $f_act != "" && $dbOperationCompleted == "1" && MASK_CUSTOMER_SHOW_LIST == "1") :
      $javaScriptOut .= "parent.admin_cs_list.finishPage('".strWrapJs($f_cmp_comp)."','".strWrapJs($f_cmp_comp2)."','".strWrapJs($f_ad_street)."','".$f_ad_zipcode."','".strWrapJs($f_cmp_match)."','".$f_cs_eid."','".$f_usr_phone."','".$f_usr_email."');";
   endif;   
   if ($f_act == "newCustomer" && $dbOperationCompleted == "1") :
      // Reset fields of form-parameters
      clearParameters($httpVisualVars);
   endif;
  
  
   // ******************************************************************************************************************


   $f_cmp_comp = strWrapHtml($f_cmp_comp);
   $f_cmp_comp2 = strWrapHtml($f_cmp_comp2);
   $f_usr_firstname = strWrapHtml($f_usr_firstname);
   $f_usr_name = strWrapHtml($f_usr_name);
   $f_ad_street = strWrapHtml($f_ad_street);
   $f_ad_city = strWrapHtml($f_ad_city);
   $f_cmp_bank = strWrapHtml($f_cmp_bank);
   $f_cmp_remark = strWrapHtml($f_cmp_remark);
   $f_cmp_remark2 = strWrapHtml($f_cmp_remark2);
   $f_cmp_match = strWrapHtml($f_cmp_match);
   $f_cmp_match2 = strWrapHtml($f_cmp_match2);

   if ($companyId != "" || CS_EID_GENERATION == "") :
        $f_cs_eid_out = "<input class=\"smaller\" type=\"text\" name=\"f_cs_eid\" value=\"" . $f_cs_eid . "\" tabindex=\"30\" size=\"10\" maxlength=\"10\" " . (CS_EID_EDITABLE != "1" ? "readonly" : "") . ">";
   else :
        if ($f_cs_eid == "") :
           $f_cs_eid = $constCsEidPrefix;
        endif;

        $f_cs_eid_out = "<div style=\"float:left\"><input class=\"f8np1\" type=\"text\" name=\"f_cs_eid\" value=\"" . $f_cs_eid . "\" tabindex=\"30\" size=\"11\" maxlength=\"10\">&nbsp;</div>";
        $f_cs_eid_out .= defineButtonType08("...", "action_eid", "searchMaxEID();", "20", "left", "2");
   endif;
   
   // Generate Output
   if ($companyId != "") : 
       $valueText = getLngt("Änd. speichern");
       $f_actText = "modifyCustomer";
   else :
       $valueText = getLngt("Speichern");
       $f_actText = "newCustomer";
   endif;

   $f_cmp_id = $companyId;
   
   // Mail if job is finished
   $f_cs_jbstatusmail_0 = "";
   $f_cs_jbstatusmail_1 = "";
   if ($f_cs_jbstatusmail == "0" || $f_cs_jbstatusmail == "") : $f_cs_jbstatusmail_0 = "checked"; endif;
   if ($f_cs_jbstatusmail == "1") : $f_cs_jbstatusmail_1 = "checked"; endif;
   
   // Mail if first hop is done
   $f_cs_jbstatusmail2_0 = "";
   $f_cs_jbstatusmail2_1 = "";
   if ($f_cs_jbstatusmail2 == "0" || $f_cs_jbstatusmail2 == "") : $f_cs_jbstatusmail2_0 = "checked"; endif;
   if ($f_cs_jbstatusmail2 == "1") : $f_cs_jbstatusmail2_1 = "checked"; endif;
   
   // Mail if new job is inserted
   $f_cs_jbstatusmail3_0 = "";
   $f_cs_jbstatusmail3_1 = "";
   if ($f_cs_jbstatusmail3 == "0" || $f_cs_jbstatusmail3 == "") : $f_cs_jbstatusmail3_0 = "checked"; endif;
   if ($f_cs_jbstatusmail3 == "1") : $f_cs_jbstatusmail3_1 = "checked"; endif;
   
   $f_cs_invmode_0 = "";
   $f_cs_invmode_1 = "";
   $f_cs_invmode_2 = "";
   if ($f_cs_invmode == "0" || $f_cs_invmode == "") : $f_cs_invmode_0 = "checked"; endif;
   if ($f_cs_invmode == "1") : $f_cs_invmode_1 = "checked"; endif;
   if ($f_cs_invmode == "2") : $f_cs_invmode_2 = "checked"; endif;

   $f_cmp_bankmode_0 = "";
   $f_cmp_bankmode_1 = "";
   if ($f_cmp_bankmode == "0" || $f_cmp_bankmode == "") : $f_cmp_bankmode_0 = "checked"; endif;
   if ($f_cmp_bankmode == "1") : $f_cmp_bankmode_1 = "checked"; endif;

   $f_cs_jobbatch_0 = "";
   if ($f_cs_jobbatch == "1") : $f_cs_jobbatch_0 = "checked"; endif;

   $f_cs_fixprice_discount_0 = "";
   if ($f_cs_fixprice_discount == "1") : $f_cs_fixprice_discount_0 = "checked"; endif;

   $f_cs_invtext_mode_0 = "";
   if ($f_cs_invtext_mode == "1") : $f_cs_invtext_mode_0 = "checked"; endif;

   $f_cmp_inv2hq_0 = "";
   $f_cmp_inv2hq_1 = "";
   if ($f_cmp_inv2hq == "1" || $f_cmp_inv2hq == "3") : $f_cmp_inv2hq_0 = "checked"; endif;
   if ($f_cmp_inv2hq == "2" || $f_cmp_inv2hq == "3") : $f_cmp_inv2hq_1 = "checked"; endif;

   $f_cs_commission_no_0 = "";
   $f_cs_commission_no_1 = "";
   if ($f_cs_commission_no == "0" || $f_cs_commission_no == "") : $f_cs_commission_no_0 = "checked"; endif;
   if ($f_cs_commission_no == "1") : $f_cs_commission_no_1 = "checked"; endif;

   $f_cs_cr_fav_only_0 = "";
   if ($f_cs_cr_fav_only == "1") : $f_cs_cr_fav_only_0 = "checked"; 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 src="../include/checkFormTags.js" type="text/javascript"></script>
<script src="../include/searchLists.js" type="text/javascript"></script>

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

var f_cs_id = '<?php echo $f_cs_id ?>';
var f_cmp_id = '<?php echo $f_cmp_id ?>';
var f_csc_id = '<?php echo $f_csc_id ?>';

function clearAllFields() {
  document.location.href = "prospect_special.php";
};

function authenticationFinishPage() {
  if (confirm('<?php echo $confirmTextAuthentication ?>')) {
     document.forms[0].f_cmp_authenticated.value='<?php echo $f_cmp_authenticated2 ?>';
     document.forms[0].f_act.value='setAuthentication';
     document.forms[0].submit();
  }
};

function visibilityFinishPage() {
  if (confirm('<?php echo $confirmTextVisibility ?>')) {	
     document.forms[0].f_cmp_visible.value='<?php echo $f_cmp_visible2 ?>';
     document.forms[0].f_act.value='setVisibility';
     document.forms[0].submit();
  }
};

function cashModeFinishPage() {
  if (confirm('<?php echo $confirmTextCashmode ?>')) {
     document.forms[0].f_cmp_cashmode.value='<?php echo $f_cmp_cashmode2 ?>';
     document.forms[0].f_act.value='setCashmode';
     document.forms[0].submit();  
  }
};

function finishPage() {
  var ok = true;

  if (document.forms[0].f_usr_email.value.length != 0) {
     // if e-mail has content then check syntax
     if (!checkMailAddress(document.forms[0].f_usr_email, '<?php echo getLngt("Bitte tragen Sie eine gültige Email-Adresse ein!") ?>')) {ok = false;};
  }
  if (ok && document.forms[0].f_cs_jbstatusmail[1].checked && document.forms[0].f_usr_email.value.length == 0) {
     alert('<?php echo getLngt("Um Auftragsbestätigungs-Emails zu verschicken, tragen Sie bitte eine gültige Email-Adresse ein!") ?>');
     ok = false;
  }
  if (!checkIsNaNIgnoreSpace(document.forms[0].f_usr_phone.value, '<?php echo getLngt("Bitte tragen Sie eine Nummer bei Telefon ein!") ?>')) {ok = false;};
  if (!checkIsNaNIgnoreSpace(document.forms[0].f_usr_phone2.value, '<?php echo getLngt("Bitte tragen Sie eine Nummer bei Mobil ein!") ?>')) {ok = false;};

  if (ok) {
     document.forms[0].submit();
  }
};

function searchCsCsc(genVal,genNum) {
  var f_act = 'search';
  
  var widthPopupWin = 950;
  var heightPopupWin = 600;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/cs_csc_list.php?f_act=" + f_act + "&generic=" + genVal + "&genNum=" + genNum,
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes");
};

function clearPayer() {	
  document.forms[0].g_cs_id.value='';
  document.forms[0].g_csc_id.value='';
  document.forms[0].g_cscad_comp.value='';
};

function clearParent() {	
  document.forms[0].g2_cs_id.value='';
  document.forms[0].g2_cmp_comp.value='';
};

function searchTx() {
  var f_act = 'search';
  
  var widthPopupWin = 250;
  var heightPopupWin = 400;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/tx_list.php?f_act=" + f_act + "&generic=1011",
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes");
};

function clearTx() {	
  document.forms[0].g_tx_id.value='';
  document.forms[0].g_tx_sign.value='';
  document.forms[0].g_tx_value.value='';
};

function searchBr() {
  var f_act = 'search';
  
  var widthPopupWin = 300;
  var heightPopupWin = 550;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/br_list.php?f_act=" + f_act + "&generic=111",
    "","dependent=yes,width=" + widthPopupWin + ",height=" +
    heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin +
    ",scrollbars=yes");
};

function clearBr() {	
  document.forms[0].g_br_id.value='';
  document.forms[0].g_br_key.value='';
  document.forms[0].g_br_name.value='';
};

function searchMaxEID() {
  var maxvalue = document.forms[0].f_eid_maxval.value;
  if (confirm('<?php echo getLngt("Soll der Wert") ?>' + ' ' + maxvalue + ' ' + '<?php echo getLngt("übernommen werden") ?>')) {
     document.forms[0].f_cs_eid.value = maxvalue;
  };
};

function openPrintLayout() {
  var widthPopupWin = 800;
  var heightPopupWin = 700;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/prospect_special.php?companyId=" + f_cmp_id + "&printVersion=1","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function copyProspect() {
  document.forms[0].copyPt.value = '1';
  document.forms[0].submit();
};

function checkCsProv() {
  var csProv = trim(document.forms[0].f_cs_prov.value);
  csProv = csProv.replace(/,/, ".");
  if (!checkIsNaN(csProv, '<?php echo getLngt("Die Eingabe im Provisionsfeld ist nicht numerisch") ?>')) {
     document.forms[0].f_cs_prov.value = '0.00';
  } else {
    if (csProv < 0) {
       document.forms[0].f_cs_prov.value = '0.00';
       alert('<?php echo getLngt("Der Prozentsatz darf nicht negativ sein!") ?>');
    } else {
  
       var pos = csProv.indexOf(".");
       if (pos != -1) {
          var decimal = csProv.substr(pos + 1);
          if (decimal == '00' || decimal == '50' || decimal == '0' || decimal == '5') {
             if (pos == 0) {csProv = '0' + csProv;};     // If value like ".0", ".5", ... then set to "0.0", "0.5", ...
             document.forms[0].f_cs_prov.value = csProv;
          } else {
             document.forms[0].f_cs_prov.value = '0.00';
             alert('<?php echo getLngt("Die Systemeinstellungen erfordern eine Dezimalstelle der Form ,0 bzw ,5 oder auch ,00 bzw. ,50 !") ?>');
          }
       } else {
          if (csProv >= 0 && csProv <= 99) {
             document.forms[0].f_cs_prov.value = csProv + '.00';
          } else {
             document.forms[0].f_cs_prov.value = '0.00';
             alert('<?php echo getLngt("Der Prozentsatz muss größer gleich 0 und kleiner 100 sein!") ?>');
          }
       }
    }
  }
};

function setProspectToCustomer(ptId) {
  if (confirm('<?php echo getLngt("Soll der Interessent in den Kundenstamm übernommen werden?") ?>')) {
     alert('<?php echo getLngt("Achtung: Sie befinden sich im Anschluss gleich in der Kundenliste!") ?>');
     document.forms[0].action = "../admin/customer_special.php";
     document.forms[0].f_act.value='newCustomer';
     document.forms[0].companyId.value='';
     document.forms[0].pt2cs.value=ptId;
     document.getElementsByName('f_noaddressvalidation[]')[0].checked = true;
     opener.location.href = "customer_list.php";
     document.forms[0].submit();
  };
};

function openGroups(prospectId) {
  var widthPopupWin = 800;
  var heightPopupWin = 700;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/groupmembers.php?itemType=pt&itemId=" + prospectId,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};
-->
</script>

</head>

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

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

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

<form action="../admin/prospect_special.php" method="post">
  <input type="hidden" name="f_act" value="">
  <input type="hidden" name="companyId" value="<?php echo $companyId ?>">
  <input type="hidden" name="f_usr_id" value="<?php echo $f_usr_id ?>">
  <input type="hidden" name="f_cmp_authenticated" value="<?php echo $f_cmp_authenticated ?>">
  <input type="hidden" name="f_cmp_visible" value="<?php echo $f_cmp_visible ?>">
  <input type="hidden" name="f_cmp_cashmode" value="<?php echo $f_cmp_cashmode ?>">
  <input type="hidden" name="cpfs" value="<?php echo $cpfs ?>">
  <input type="hidden" name="g_cs_id" value="<?php echo $g_cs_id ?>">
  <input type="hidden" name="g_csc_id" value="<?php echo $g_csc_id ?>">
  <input type="hidden" name="g_tx_id" value="<?php echo $g_tx_id ?>">
  <input type="hidden" name="g_br_id" value="<?php echo $g_br_id ?>">
  <input type="hidden" name="g2_cs_id" value="<?php echo $g2_cs_id ?>">
  <input type="hidden" name="g2_csc_id" value="<?php echo $g2_csc_id ?>">
  <input type="hidden" name="f_eid_maxval" value="<?php echo $f_eid_maxval ?>">
  <input type="hidden" name="copyPt" value="">
  <input type="hidden" name="pt2cs" value="">
  <?php echo $phpCurrentNavigationInputHidden ?>
  <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">

  <?php echo htmlDivLineSpacer("10px"); ?>
  
  <div class="f10bp1_blue">
    <?php echo $title ?>&nbsp;&nbsp;&nbsp;<span class="f10bp1_red"><?php echo $displayTextAuthentication ?></span>
  </div>
  <?php echo htmlDivLineSpacer("20px", "", "left"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("Firma*, Zusatz") ?>:</div>
    <div>
      <div style="float:left">
        <input class="f8np1" type="text" name="f_cmp_comp" value="<?php echo $f_cmp_comp ?>" maxlength="35" size="50" tabindex="10">
        <input class="f8np1" type="text" name="f_cmp_comp2" value="<?php echo $f_cmp_comp2 ?>" maxlength="35"  size="50" tabindex="20">
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <?php echo getLngt("ExtID*") ?>:&nbsp;
      </div>
      <?php echo $f_cs_eid_out ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("Übernahme") ?>:</div>
    <div>
        <input class="smaller" type="radio" name="f_cmp_changemode" value="0" checked tabindex="32" disabled> <?php echo getLngt("Keine") ?>
        <input class="smaller" type="radio" name="f_cmp_changemode" value="1" tabindex="33" disabled> <?php echo getLngt("Nur Hauptkostenstelle") ?>
        <input class="smaller" type="radio" name="f_cmp_changemode" value="2" tabindex="34" disabled> <?php echo getLngt("Alle Kostenstellen") ?>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Addresstypen") ?>:
      &nbsp;&nbsp;
      <?php echo getLngt("Rechnungsadr.") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_adt_change2[]" value="2" tabindex="36" disabled>
      &nbsp;&nbsp;
      <?php echo getLngt("Abhol-/Lieferadr.") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_adt_change2[]" value="4" tabindex="38" disabled>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>
  
  <div>
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("Tel.*, Mobil, Fax") ?>:</div>
    <div>
      <input class="f8np1" type="text" name="f_usr_phone" value="<?php echo $f_usr_phone ?>" tabindex="40">
      <input class="f8np1" type="text" name="f_usr_phone2" value="<?php echo $f_usr_phone2 ?>" tabindex="50">
      <input class="f8np1" type="text" name="f_usr_fax" value="<?php echo $f_usr_fax ?>" tabindex="60">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Steuernr.") ?>: <input class="f8np1" type="text" name="f_cmp_tax_idno" value="<?php echo $f_cmp_tax_idno ?>" size="30" tabindex="70" disabled>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px"); ?>
  <div>  
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("E-Mail") ?>:</div>
    <div>
      <input class="f8np1" type="text" name="f_usr_email" value="<?php echo $f_usr_email ?>" size="40" tabindex="80">
      &nbsp;&nbsp;
      <?php echo getLngt("Mail bei") ?>:&nbsp;
      <?php echo getLngt("Erledigung") ?>:&nbsp;
      <input class="f8np1" type="radio" name="f_cs_jbstatusmail" value="0" <?php echo $f_cs_jbstatusmail_0 ?> tabindex="90" disabled> N
      <input class="f8np1" type="radio" name="f_cs_jbstatusmail" value="1" <?php echo $f_cs_jbstatusmail_1 ?> tabindex="94" disabled> J
      &nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Erfassung") ?>:&nbsp;
      <input class="f8np1" type="radio" name="f_cs_jbstatusmail3" value="0" <?php echo $f_cs_jbstatusmail3_0 ?> tabindex="98" disabled> N
      <input class="f8np1" type="radio" name="f_cs_jbstatusmail3" value="1" <?php echo $f_cs_jbstatusmail3_1 ?> tabindex="100" disabled> J
      &nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Abholung") ?>:&nbsp;
      <input class="f8np1" type="radio" name="f_cs_jbstatusmail2" value="0" <?php echo $f_cs_jbstatusmail2_0 ?> tabindex="102" disabled> N
      <input class="f8np1" type="radio" name="f_cs_jbstatusmail2" value="1" <?php echo $f_cs_jbstatusmail2_1 ?> tabindex="104" disabled> J
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("Bank, BLZ, Kto.") ?>:</div>
    <div>
      <input class="f8np1" type="text" name="f_cmp_bank" value="<?php echo $f_cmp_bank ?>" size="50" tabindex="110" disabled>
      <input class="f8np1" type="text" name="f_cmp_bankno" value="<?php echo $f_cmp_bankno ?>" tabindex="120" disabled>
      <input class="f8np1" type="text" name="f_cmp_bankacc" value="<?php echo $f_cmp_bankacc ?>" tabindex="130" disabled>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input class="f8np1" type="radio" name="f_cmp_bankmode" value="0" <?php echo $f_cmp_bankmode_0 ?> tabindex="140" disabled> <?php echo getLngt("Rechnung") ?>
      <input class="f8np1" type="radio" name="f_cmp_bankmode" value="1" <?php echo $f_cmp_bankmode_1 ?> tabindex="150" disabled> <?php echo getLngt("Einzug") ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("Str.*, Hausnr.*") ?>:</div>
    <div>
      <div style="float:left">
        <input class="f8np1" type="text" name="f_ad_street" value="<?php echo $f_ad_street ?>" size="50" tabindex="160">
        <input class="f8np1" type="text" name="f_cmp_hsno" value="<?php echo $f_cmp_hsno ?>" size="5" tabindex="170">
        &nbsp;&nbsp;
      </div>
      <?php echo defineButtonType08("...", "action_ad", "searchAddress();", "20", "left"); ?>
      <div>
        &nbsp;&nbsp;
        <input type="checkbox" name="f_noaddressvalidation[]" value="1" tabindex="175">&nbsp;<?php echo getLngt("(Keine Prüfung)") ?>
      </div>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("PLZ*, Ort*") ?>:</div>
    <div>
      <input class="f8np1" type="text" name="f_ad_zipcode" value="<?php echo $f_ad_zipcode ?>" size="5" tabindex="180">
      <input class="f8np1" type="text" name="f_ad_city" value="<?php echo $f_ad_city ?>" size="50" tabindex="190">
      <select class="f8np1" name="f_ad_country" tabindex="195">
        <?php echo getCountryCodesAsOptions($f_ad_country); ?>
      </select>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("Übernahme") ?>:</div>
    <div>
      <input class="f8np1" type="radio" name="f_ad_changemode" value="0" checked tabindex="212" disabled> <?php echo getLngt("Keine") ?>
      <input class="f8np1" type="radio" name="f_ad_changemode" value="1" tabindex="213" disabled> <?php echo getLngt("Nur Hauptkostenstelle") ?>
      <input class="f8np1" type="radio" name="f_ad_changemode" value="2" tabindex="214" disabled> <?php echo getLngt("Alle Kostenstellen") ?>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Addresstypen") ?>:
      &nbsp;&nbsp;
      <?php echo getLngt("Rechnungsadr.") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_adt_change[]" value="2" tabindex="216" disabled>
      &nbsp;&nbsp;
      <?php echo getLngt("Abhol-/Lieferadr.") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_adt_change[]" value="4" tabindex="218" disabled>
    </div>
  </div>  
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("Name, Vorname") ?>:</div>
    <div>
      <input class="f8np1" type="text" name="f_usr_name" value="<?php echo $f_usr_name ?>" size="50" tabindex="225">&nbsp;
      <input class="f8np1" type="text" name="f_usr_firstname" value="<?php echo $f_usr_firstname ?>" size="50" tabindex="230">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px"); ?>
  <div>  
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("Login, Passwort") ?>:</div>
    <div>
      <input class="f8np1" type="text" name="f_usr_account" value="<?php echo $f_usr_account ?>" tabindex="240" disabled>
      <?php echo $setPasswordForNewUserOutput ?>
      <?php echo $setPassword2ForNewUserOutput ?> <?php echo getLngt("(Wiederholung)") ?>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>
  
  <div>
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("Rabatt, Porto") ?>:</div>
    <div>
      <input class="f8np1" type="text" name="f_cs_discount" value="<?php echo $f_cs_discount ?>" size="5" maxlength="5" tabindex="270">%
      <input class="f8np1" type="text" name="f_cmp_postage" value="<?php echo $f_cmp_postage ?>" size="5" maxlength="5" tabindex="280" disabled>€
      &nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Rabatt-Eintrag auf Fixpreis") ?>:&nbsp;
      <input class="f8np1" type="checkbox" name="f_cs_fixprice_discount[]" value="1" <?php echo $f_cs_fixprice_discount_0 ?> tabindex="285">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Provision") ?>:&nbsp;
      <input class="f8np1" type="text" name="f_cs_prov" value="<?php echo $f_cs_prov ?>" size="5" maxlength="5" onChange="javascript:checkCsProv();" tabindex="287" disabled>%
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Sortierfeld") ?>:&nbsp;
      <input class="f8np1" type="text" name="f_cmp_match2" value="<?php echo $f_cmp_match2 ?>" size="10" maxlength="50" tabindex="290">
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("MwSt, Branche") ?>:</div>
    <div>
      <div style="float:left">
        <input class="f8np1" type="text" name="g_tx_value" value="<?php echo $g_tx_value ?>" size="4" disabled >
        <input class="f8np1" type="text" name="g_tx_sign" value="<?php echo $g_tx_sign ?>" size="15" disabled >
        &nbsp;&nbsp;
      </div>
      <?php echo defineButtonType08("...", "action_tx", "searchTx();", "20", "left", "2"); ?>
      <div style="float:left">
        <a href="javascript:clearTx();" tabindex="310"><img src="../images/waste.png" border="0" height="15" width="12"></a>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input class="f8np1" type="text" name="g_br_key" value="<?php echo $g_br_key ?>" size="4" disabled >
        <input class="f8np1" type="text" name="g_br_name" value="<?php echo $g_br_name ?>" size="15" disabled >
        &nbsp;&nbsp;
      </div>
      <?php echo defineButtonType08("...", "action_tx", "searchBr();", "20", "left", "2"); ?>
      <div style="float:left">
        <a href="javascript:clearBr();" tabindex="330"><img src="../images/waste.png" border="0" height="15" width="12"></a>
      </div>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("Rechnung") ?>:</div>
    <div>
      <div style="float:left">
        <input class="f8np1" type="text" name="g_cscad_comp" value="<?php echo $g_cscad_comp ?>" size="20" disabled >
        &nbsp;&nbsp;
      </div>
      <?php echo defineButtonType08("...", "action_tx", "searchCsCsc('110100000000','');", "20", "left", "2"); ?>
      <div style="float:left">
        <a href="javascript:clearPayer();" tabindex="340"><img src="../images/waste.png" border="0" height="15" width="12"></a> <?php echo getLngt("(Drittzahler)") ?>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <?php echo getLngt("R. an Zentrale") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_cmp_inv2hq[]" value="1" <?php echo $f_cmp_inv2hq_0 ?> tabindex="350" disabled>
        &nbsp;&nbsp;
        <?php echo getLngt("Einzelr.") ?>&nbsp;<input class="f8np1" type="checkbox" name="f_cmp_inv2hq[]" value="2" <?php echo $f_cmp_inv2hq_1 ?> tabindex="360" disabled>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <?php echo getLngt("Komm.-Nr.") ?>:&nbsp;
        <input class="f8np1" type="radio" name="f_cs_commission_no" value="0" <?php echo $f_cs_commission_no_0 ?> tabindex="370"> <?php echo getLngt("Nein") ?>
        <input class="f8np1" type="radio" name="f_cs_commission_no" value="1" <?php echo $f_cs_commission_no_1 ?> tabindex="380"> <?php echo getLngt("Ja") ?>
        &nbsp;&nbsp;&nbsp;&nbsp;
      </div>        
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px", "", "left"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("Vermittlung") ?>:</div>
    <div>
      <?php echo getLngt("Listenkunde") ?>: <input class="f8np1" type="checkbox" name="f_cs_jobbatch[]" value="1" <?php echo $f_cs_jobbatch_0 ?> tabindex="390" disabled>
      &nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Nur Anforderungen") ?>:&nbsp;
      <input class="f8np1" type="checkbox" name="f_cs_cr_fav_only[]" value="1" <?php echo $f_cs_cr_fav_only_0 ?> tabindex="400" disabled>
      &nbsp;&nbsp;&nbsp;&nbsp;
      <?php echo getLngt("Rechnungskurztext") ?>: <input class="f8np1" type="checkbox" name="f_cs_invtext_mode[]" value="1" <?php echo $f_cs_invtext_mode_0 ?> tabindex="402" disabled>
      &nbsp;&nbsp;&nbsp;&nbsp;
    </div>
  </div>
  <?php echo htmlDivLineSpacer("10px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("Bemerkung") ?>:</div>
    <div>
      <textarea class="f8np1" name="f_cmp_remark" cols="90" rows="1" tabindex="410"><?php echo $f_cmp_remark ?></textarea>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("Freitext") ?>:</div>
    <div>
      <textarea class="f8np1" name="f_cmp_match" cols="90" rows="1" tabindex="420"><?php echo $f_cmp_match ?></textarea>
    </div>
  </div>
  <?php echo htmlDivLineSpacer("5px"); ?>
  <div>
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("Intern") ?>:</div>
    <div>
      <textarea class="f8np1" name="f_cmp_remark2" cols="90" rows="1" tabindex="430"><?php echo $f_cmp_remark2 ?></textarea>
    </div>
  </div>
  
  <?php echo htmlDivLineSpacer("15px"); ?>

  <div>
    <div <?php echo setStyleHtmlDiv("110px","left"); ?>><?php echo getLngt("Preise, Rabatte") ?>:</div>
    <div>
      <?php echo $serviceLink1 ?>&nbsp;&nbsp;
      <?php echo $serviceLink2 ?>&nbsp;&nbsp;
      <?php echo $serviceLink3 ?>&nbsp;&nbsp;
      <?php echo $serviceLink4 ?>
      &nbsp;&nbsp;
      Abrechnung:
      <input class="f8np1" type="radio" name="f_cs_invmode" value="0" <?php echo $f_cs_invmode_0 ?> disabled tabindex=""> <?php echo getLngt("Serv.") ?>
      <input class="f8np1" type="radio" name="f_cs_invmode" value="1" <?php echo $f_cs_invmode_1 ?> tabindex=""> <?php echo getLngt("PLZ") ?>
      <input class="f8np1" type="radio" name="f_cs_invmode" value="2" <?php echo $f_cs_invmode_2 ?> tabindex=""> <?php echo getLngt("Bereich") ?>
    </div>
  </div>
  
  <?php echo htmlDivLineSpacer("15px"); ?>

  <div>
    <?php echo $buttonFilter ?>
    <?php echo $buttonCourier ?>
    <?php echo $buttonCostcenter ?>
    <?php echo $buttonService ?>
    <?php echo $buttonAuthentication ?>
    <?php echo $buttonVisibility ?>
    <?php echo $buttonCashmode ?>    
    <?php echo defineButtonType08(getLngt("Speichern"), "action_save", "document.forms[0].f_act.value='" . $f_actText . "';finishPage();", "90", "left", "3"); ?>
    <?php echo $buttonCopy ?>
    <?php echo $buttonSetToCs ?>
    <?php echo $buttonGroup ?>
    <?php echo defineButtonType08(getLngt("Druckversion"), "action_prt", "openPrintLayout();", "90", "left", "3"); ?>
    <?php echo defineButtonType08(getLngt("Zurücksetzen"), "action_reset", "clearAllFields();", "90", "left", "3"); ?>
    <?php echo defineButtonType08(getLngt("Schließen"), "action_close", "window.close();", "90", "left", "3"); ?>
  </div>
  
  <?php echo htmlDivLineSpacer("20px", "", "left"); ?>

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

</html>
