Ejemplo n.º 1
0
 /**
  * Ação para exportar os dados do grid para XLS
  */
 public function xlsAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $json = new ZendT_Json_Result();
     try {
         $result = $this->configReport('xls');
         $file = new ZendT_File($result['name'] . '.xls', $result['content'], 'application/vnd.ms-excel');
         $json->setResult($file->toArrayJson());
     } catch (ZendT_Exception $ex) {
         $json->setException($ex);
     }
     echo $json->render();
 }
Ejemplo n.º 2
0
 /**
  *
  * @return string 
  */
 public function render($type = '')
 {
     $content = parent::render();
     if ($type == 'PDF') {
         return $content;
     }
     $title = $this->_options['title'];
     $name = strtolower(str_replace(array(' '), array('-'), utf8_decode($title)));
     $nameIframe = strtolower('ifr' . clearAccent($name));
     $driver = strtolower($this->_options['driver']);
     $download = Zend_Controller_Front::getInstance()->getRequest()->getParam('download');
     $iframeDownload = Zend_Controller_Front::getInstance()->getRequest()->getParam('iframeDownload');
     $iframeHeight = Zend_Controller_Front::getInstance()->getRequest()->getParam('iframeHeight');
     if (!$driver) {
         $driver = 'pdf';
     }
     $file = new ZendT_File($name . '.' . $driver, $content, 'application/' . strtolower($driver));
     $fileUri = $file->toArrayJson();
     $cmdHtml = '';
     $src = ZendT_Url::getBaseUrl() . '/file';
     if ($driver == 'xls' || $download) {
         $src .= '/download';
         $width = 0;
         $height = 0;
         if (!$iframeDownload) {
             $cmdHtml .= '<div class="ui-widget ui-state-default ui-corner-all" style="height:30px;padding:5px;">' . "\n";
             $cmdHtml .= '    <span style="float:left;" class="ui-icon ui-icon-arrowstop-1-s"></span>' . "\n";
             $cmdHtml .= '    <span style="float:left;"><a href="javascript:javascript:downloadReport();">Se o download não iniciar automaticamente clique aqui.</a></span>' . "\n";
             $cmdHtml .= '    <span style="clear:both"></span>' . "\n";
             $cmdHtml .= '</div>' . "\n";
         }
     } else {
         if ($driver == 'html') {
             return $content;
         } else {
             $src .= '/pdf';
             $width = '100%';
             $height = '520';
             if (isset($this->_options['width'])) {
                 $width = $this->_options['width'];
             }
             if (isset($this->_options['height'])) {
                 $height = $this->_options['height'];
             }
         }
     }
     $src .= '?filename=' . $fileUri['filename'];
     $src .= '&type=' . $fileUri['type'];
     $src .= '&name=' . $fileUri['name'];
     $src .= '#zoom=120';
     $cmdHtml .= '<iframe';
     $cmdHtml .= ' id="' . $nameIframe . '"';
     $cmdHtml .= ' name="' . $nameIframe . '"';
     $cmdHtml .= ' src="' . $src . '"';
     $cmdHtml .= ' width="' . $width . '"';
     $cmdHtml .= ' height="100%"';
     $cmdHtml .= ' style="min-height:' . $height . 'px"';
     $cmdHtml .= ' border="0"';
     $cmdHtml .= ' frameborder="0"';
     $cmdHtml .= ' align="center"';
     $cmdHtml .= ' noresize="noresize"';
     $cmdHtml .= ' scrolling="yes"';
     if ($iframeDownload) {
         $cmdHtml .= ' onload="history.go(-1);"';
     }
     $cmdHtml .= '></iframe>';
     $cmdHtml .= '<script>function downloadReport(){this.' . $nameIframe . '.location = \'' . $src . '\'; }</script>';
     return $cmdHtml;
 }
Ejemplo n.º 3
0
 public function pluploadAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $json = new ZendT_Json_Result();
     try {
         $targetDir = ZendT_Lib::getTmpDir() . '/files/' . DIRECTORY_SEPARATOR . "plupload";
         // Create target dir
         if (!file_exists($targetDir)) {
             @($result = mkdir($targetDir));
             if (!$result) {
                 throw new ZendT_Exception_Error('Não foi possível criar o diretório "$targetDir".', 1001);
             }
         }
         if (!file_exists($targetDir)) {
             @($result = mkdir($targetDir));
             if (!$result) {
                 throw new ZendT_Exception_Error('Não foi possível criar o diretório "$targetDir".', 1001);
             }
         }
         //$targetDir = 'uploads';
         $cleanupTargetDir = true;
         // Remove old files
         $maxFileAge = 1 * 3600;
         // Temp file age in seconds
         // 5 minutes execution time
         @set_time_limit(5 * 60);
         // Uncomment this one to fake upload time
         // usleep(5000);
         // Get parameters
         $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
         $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
         $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
         // Clean the fileName for security reasons
         $fileName = removeAccent(trim($fileName));
         $fileName = preg_replace('/[^\\w\\._]+/', '_', $fileName);
         $fileName = str_replace(' ', '_', $fileName);
         // Make sure the fileName is unique but only if chunking is disabled
         if ($chunks < 2 && file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName)) {
             $ext = strrpos($fileName, '.');
             $fileName_a = substr($fileName, 0, $ext);
             $fileName_b = substr($fileName, $ext);
             $count = 1;
             while (file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName_a . '_' . $count . $fileName_b)) {
                 $count++;
             }
             $fileName = $fileName_a . '_' . $count . $fileName_b;
         }
         $filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName;
         // Remove old temp files
         if ($cleanupTargetDir && is_dir($targetDir) && ($dir = opendir($targetDir))) {
             while (($file = readdir($dir)) !== false) {
                 $tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file;
                 // Remove temp file if it is older than the max age and is not the current file
                 if (preg_match('/\\.part$/', $file) && filemtime($tmpfilePath) < time() - $maxFileAge && $tmpfilePath != "{$filePath}.part") {
                     @unlink($tmpfilePath);
                 }
             }
             closedir($dir);
         } else {
             throw new ZendT_Exception_Error('Failed to open temp directory.', 100);
         }
         // Look for the content type header
         if (isset($_SERVER["HTTP_CONTENT_TYPE"])) {
             $contentType = $_SERVER["HTTP_CONTENT_TYPE"];
         }
         if (isset($_SERVER["CONTENT_TYPE"])) {
             $contentType = $_SERVER["CONTENT_TYPE"];
         }
         // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5
         if (strpos($contentType, "multipart") !== false) {
             if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
                 // Open temp file
                 $out = fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
                 if ($out) {
                     // Read binary input stream and append it to temp file
                     $in = fopen($_FILES['file']['tmp_name'], "rb");
                     if ($in) {
                         while ($buff = fread($in, 4096)) {
                             fwrite($out, $buff);
                         }
                     } else {
                         throw new ZendT_Exception_Error('Failed to open input stream.', 101);
                     }
                     fclose($in);
                     fclose($out);
                     @unlink($_FILES['file']['tmp_name']);
                 } else {
                     throw new ZendT_Exception_Error('Failed to open output stream.', 102);
                 }
             } else {
                 throw new ZendT_Exception_Error('Failed to move uploaded file.', 103);
             }
         } else {
             // Open temp file
             $out = fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
             if ($out) {
                 // Read binary input stream and append it to temp file
                 $in = fopen("php://input", "rb");
                 if ($in) {
                     while ($buff = fread($in, 4096)) {
                         fwrite($out, $buff);
                     }
                 } else {
                     throw new ZendT_Exception_Error('Failed to open input stream.', 104);
                 }
                 fclose($in);
                 fclose($out);
             } else {
                 throw new ZendT_Exception_Error('Failed to open output stream.', 105);
             }
         }
         // Check if file has been uploaded
         if (!$chunks || $chunk == $chunks - 1) {
             // Strip the temp .part suffix off
             @($result = rename("{$filePath}.part", $filePath));
             if (!$result) {
                 throw new ZendT_Exception_Error('Não foi possível renomear o arquivo.', 1002);
             }
         }
         if ($this->getRequest()->getParam('platform')) {
             $_file = new ZendT_File($fileName, file_get_contents($filePath), $_FILES['file']['type']);
             if (file_exists($filePath)) {
                 unlink($filePath);
             }
             $infoFile = $_file->toArrayJson();
             $infoFile['size'] = $_FILES['file']['size'];
             $infoFile['type'] = $_FILES['file']['type'];
             $json->setResult($infoFile);
         } else {
             $json->setResult(base64_encode($filePath));
         }
     } catch (Exception $Ex) {
         $json->setException($Ex);
     }
     echo $json->toRpc();
 }