<?php
  include_once ("../include/global.inc.php");
  $doNotIncludeGeocode = "1";
  // include_once ("../import/import.php");
  include_once ("../include/inc_file.inc.php");
  // include_once ("../include/ftp.inc.php");

 
  // Check HTTP-Parameters
  getSecHttpVars("1",array("f_act", "customerId", "cscIdRoot", "cscIdCurrent", "statusMessage", "deactivateMenu",
                           "mode", "hqId", "mdId", "csId", "cmpId", "f_day", "f_month", "f_year", "f_day_to", "f_month_to", "f_year_to"));

  if ($mode != "") :
     header("Content-Type: text/html; charset=ISO-8859-1\n");
  endif;

// echo "alert('" . $mode . "' + '" . $hqId . "' + '" . $csId . "' + '" . $cmpId . "');";


  if ($mode == "1") :
     $rootDirDefault = "";
     // Get number of documents
     // Need $hqId and csEid of the selected payer only!!!
     $objNumOfFiles = 0;  // Init
     if ($hqId != "" && ($csId != "" || $cscIdCurrent != "" || $cmpId != "")) :

        if ($csId == "" && $cscIdCurrent != "") :
          $csId = getFieldValueFromId("costcenter","csc_id",$cscIdCurrent,"cs_id");
        endif;

        if ($csId != "") :
           $csEid = getFieldValueFromId("customer","cs_id",$csId,"cs_eid");
        else :
           $csEid = getFieldValueFromId("customer","cmp_id",$cmpId,"cs_eid");
        endif;

        $serverListArray = array();
        $serverList = getParameterValue("0", "FTP_IMPORT_SERVERLIST", $hqId);
        if ($serverList == "") : $serverList = getParameterValue("0", "FTP_IMPORT_SERVERLIST", "0"); endif;
        if ($serverList != "") : $serverListArray = spliti(",",$serverList); endif;
        $serverListArrayLen = count($serverListArray);

        $servername = $serverListArray[0];   // Use first entry as default for. Should exist!!!

        if ($servername != "") :
           $upload_path = getFieldValueFromId("mandator","md_id",$mdId,"md_doc_path");
//           $upload_path = getParameterValue("0", "FTP_DOWNLOADPATH_" . $servername, $hqId);
           // if ($upload_path == "") : $upload_path = getParameterValue("0", "FTP_LOCALPATH_" . $servername, "0"); endif;
           if ($upload_path == "") : $upload_path = "../import/upload/"; endif;
           // E.g. $upload_path = "../import/upload/HTG/" !!!

           $dirSpecialForObjType = getParameterValue("0", "DATATRANSFER_DIRECTORY_CS", $hqId);    // Path for upload customer files
           if ($dirSpecialForObjType == "") : $dirSpecialForObjType = "90b1a8efc903576bbb2d6e2a79b00a5e"; endif;

           // Check for headquartes
           if ($hqId != "") :
              $hqMnemonic = getFieldValueFromId("headquarters","hq_id",$hqId,"hq_mnemonic");
              if ($hqMnemonic == "") : $hqMnemonic = "MISC" ; endif;
              $rootDirDefault .= $hqMnemonic . "/";
              $dirSpecialForObjType .= "/" . $hqMnemonic . "/";
           endif;

           // Upload path
           $upload_path = $upload_path . $dirSpecialForObjType;
// echo $upload_path . "<br>";
           $objNumOfFiles = getNumOfFilesByFilterInFolder($upload_path, $csEid, "1");            // "-1" <=> Folder does not exist
        // else :  
        //    // No documents => Therefore there are no documents for the customer, too.  ($objNumOfFiles = 0; !!!)
        endif;
     endif;
     echo "retValue = '" . $objNumOfFiles . "';\n";


  elseif ($mode == "2") :

     // ...


  elseif ($mode == "3") :

     // ...

  endif;
?>  
