/** * Get the organization name/code used by the long term filename * * @return string */ public function getOrganizationCode() { if (!$this->_orgCode) { $this->_orgCode = $this->currentOrganization->getCode(); if (!$this->_orgCode) { $this->_orgCode = \MUtil_File::cleanupName($this->currentOrganization->getName()); } } return $this->_orgCode; }
/** * Add the elements from the model to the bridge for the current step * * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge * @param \MUtil_Model_ModelAbstract $model */ protected function addStepGenerateExportFile(\MUtil_Model_Bridge_FormBridgeInterface $bridge, \MUtil_Model_ModelAbstract $model) { // Things go really wrong (at the session level) if we run this code // while the finish button was pressed if ($this->isFinishedClicked()) { return; } $this->displayHeader($bridge, $this->_('Creating the export file'), 'h3'); $this->nextDisabled = true; $batch = $this->getExportBatch(); $form = $bridge->getForm(); $batch->setFormId($form->getId()); $batch->autoStart = true; // \MUtil_Registry_Source::$verbose = true; if ($batch->run($this->request)) { exit; } $element = $form->createElement('html', $batch->getId()); if ($batch->isFinished()) { $this->nextDisabled = $batch->getCounter('export_errors'); $batch->autoStart = false; // Keep the filename after $batch->getMessages(true) cleared the previous $downloadName = \MUtil_File::cleanupName($this->trackEngine->getTrackName()) . '.track.txt'; $localFilename = $batch->getSessionVariable('filename'); $this->addMessage($batch->getMessages(true)); $batch->setSessionVariable('downloadname', $downloadName); $batch->setSessionVariable('filename', $localFilename); // Log Export $data = $this->formData; // Remove unuseful data unset($data['button_spacer'], $data['current_step'], $data[$this->csrfId]); // Add useful data $data['localfile'] = '...' . substr($localFilename, -30); $data['downloadname'] = $downloadName; ksort($data); $this->accesslog->logChange($this->request, null, array_filter($data)); if ($this->nextDisabled) { $element->pInfo($this->_('Export errors occurred.')); } else { $p = $element->pInfo($this->_('Export file generated.'), ' '); $p->sprintf($this->plural('Click here if the download does not start automatically in %d second:', 'Click here if the download does not start automatically in %d seconds:', $this->downloadWaitSeconds), $this->downloadWaitSeconds); $p->append(' '); $href = new \MUtil_Html_HrefArrayAttribute(array('file' => 'go', $this->stepFieldName => 'download')); $p->a($href, $downloadName, array('type' => 'application/download')); $metaContent = sprintf('%d;url=%s', $this->downloadWaitSeconds, $href->render($this->view)); $this->view->headMeta($metaContent, 'refresh', 'http-equiv'); } } else { $element->setValue($batch->getPanel($this->view, $batch->getProgressPercentage() . '%')); } $form->activateJQuery(); $form->addElement($element); }
/** * Clean a proposed filename up so it can be used correctly as a filename * @param string $filename Proposed filename * @return string filtered filename */ protected function cleanupName($filename) { $filename = str_replace(array('/', '\\', ':', ' '), '_', $filename); // Remove dot if it starts with one $filename = trim($filename, '.'); return \MUtil_File::cleanupName($filename); }
/** * Performs actual download * * @param \MUtil_Model_Bridge_FormBridgeInterface $bridge * @param \MUtil_Model_ModelAbstract $model */ protected function downloadExportFile() { $this->view->layout()->disableLayout(); \Zend_Controller_Action_HelperBroker::getExistingHelper('viewRenderer')->setNoRender(true); $filename = $this->getExportBatch(false)->getSessionVariable('filename'); $downloadName = \MUtil_File::cleanupName($this->trackEngine->getTrackName()) . '.track.txt'; header("Content-Type: application/download"); header("Content-Disposition: attachment; filename=\"{$downloadName}\""); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: cache"); // HTTP/1.0 readfile($filename); exit; }