protected function _genExportWithMapping($po_result, $pn_exporter_id)
 {
     // Can user batch export?
     if (!$this->request->user->canDoAction('can_batch_export_metadata')) {
         $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/3440?r=' . urlencode($this->request->getFullUrlPath()));
         return;
     }
     // Can user export records of this type?
     if (!$this->request->user->canDoAction('can_export_' . $this->ops_tablename)) {
         $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/3430?r=' . urlencode($this->request->getFullUrlPath()));
         return;
     }
     $t_exporter = new ca_data_exporters($pn_exporter_id);
     if (!($t_exporter->getPrimaryKey() > 0)) {
         $this->postError(3420, _t("Could not load export mapping"), "BaseFindController->_genExportWithMapping()");
         return;
     }
     if (substr(get_class($this), 0, 6) == 'Browse') {
         $vs_export_filename = Configuration::load()->get($this->ops_tablename . '_batch_export_filename');
     } else {
         $vs_export_filename = preg_replace("/[^\\p{L}\\p{N}\\-]/", '_', $this->opo_result_context->getSearchExpression());
         $vs_export_filename = preg_replace("/[\\_]+/", '_', $vs_export_filename);
     }
     $vs_tmp_file = tempnam(caGetTempDirPath(), 'export');
     ca_data_exporters::exportRecordsFromSearchResult($t_exporter->get('exporter_code'), $po_result, $vs_tmp_file);
     header('Content-Type: ' . $t_exporter->getContentType() . '; charset=UTF-8');
     header('Content-Disposition: attachment; filename="' . $vs_export_filename . '.' . $t_exporter->getFileExtension() . '"');
     header('Content-Transfer-Encoding: binary');
     readfile($vs_tmp_file);
     @unlink($vs_tmp_file);
     exit;
 }
 /**
  * Prepare export generated by ExportData action
  */
 public function SetupBatchExport()
 {
     $o_conf = Configuration::load();
     $o_session = $this->getRequest()->getSession();
     if (!($vn_exporter_id = $o_session->getVar('exporter_id'))) {
         $this->getResponse()->setRedirect($this->getRequest()->config->get('error_display_url') . '/n/3420?r=' . urlencode($this->getRequest()->getFullUrlPath()));
         return;
     }
     $t_exporter = new ca_data_exporters($vn_exporter_id);
     if (!$t_exporter->getPrimaryKey()) {
         $this->getResponse()->setRedirect($this->getRequest()->config->get('error_display_url') . '/n/3420?r=' . urlencode($this->getRequest()->getFullUrlPath()));
         return;
     }
     $t_subject = $t_exporter->getAppDatamodel()->getInstanceByTableNum($t_exporter->get('table_num'), true);
     // alternate destinations
     $va_alt_dest = $o_conf->getAssoc('exporter_alternate_destinations');
     $this->getView()->setVar('exporter_alternate_destinations', $va_alt_dest);
     // filename set via request wins
     $vs_filename = $this->getRequest()->getParameter('file_name', pString);
     // otherwise get from config file
     if (!$vs_filename) {
         if ($vs_filename = $o_conf->get($t_subject->tableName() . "_batch_export_filename")) {
             // config setting comes without file extension
             $vs_filename = $vs_filename . '.' . $t_exporter->getFileExtension();
         }
     }
     // still no filename? -> go for hardcoded default
     if (!$vs_filename) {
         $vs_filename = 'batch_export.' . $t_exporter->getFileExtension();
     }
     // pass to view
     $this->getView()->setVar('file_name', $vs_filename);
     $this->render('export/export_destination_html.php');
 }