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


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


getSecHttpVars("1",array("f_fileName","cscIdRoot","customerId","cscIdActual"));

// Check for authentication access and granted rights
$usrAccessArray["hq"] = "1"; $usrAccessArray["cs"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
authCheckEmployeeRights($emp_id, "6", "1");


if ($f_fileName != "") :

   // Get the secret filename
   getDbFieldValues("exportfiles",array("expf_cryptname"),array("hq_id",$hq_id,"cs_id",$customerId,"expf_name",$f_fileName));
   $f_secretFileName = $expf_cryptname;

   if ($f_secretFileName != "") :

      $mimeType = "text/plain";
      $mode = "r";
      if (ENCRYPT_EXPORTDATA == "1") : 
         $mimeType = "application/octet-stream";
         $mode = "rb";
      endif;

      $gmnow = gmdate('D, d M Y H:i:s') . ' GMT';
      header("Content-type: " . $mimeType);
      header('Expires: ' . $gmnow);
      header('Content-Disposition: attachment; filename="' . $f_fileName . '"');
      header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
      header('Pragma: public');

      $fileContent = "";
      if (is_file(EXPORT_PATH . $f_secretFileName)) :
         $fileContent = readFromFile(EXPORT_PATH . $f_secretFileName, "", $mode);
      endif;
      echo $fileContent;

   endif;
endif;
?>
