Exemplo n.º 1
0
 /**
  * Action - report
  * display table data in a report in HTML or PDF format
  * 
  * Access to the action is possible in the following paths:
  * - /admin/user/report
  *
  * @return void
  */
 public function reportAction()
 {
     try {
         $params = $this->getRequest()->getParams();
         // Тип отчета
         $report_type = $params['type'];
         // Таблица для отчета
         $table = $params['table'];
         // Получим данные по отчету
         $reportData = $this->_getReportData($table);
         // Получим данные для отчета
         switch ($report_type) {
             case 'html':
                 $templater = Default_Plugin_SysBox::createViewSmarty();
                 // Отображается в режиме отчета
                 $templater->report = TRUE;
                 //------ Установим параметры и переменные HTML ------
                 // ---- Титл -----
                 $templater->title_name = $reportData['html']['title_report'];
                 $templater->title_logo = $reportData['html']['logo_report'];
                 // ---- Заголовок -----
                 $templater->column_model = $reportData['html']['column_model'];
                 $templater->is_group_head = isset($reportData['html']['is_group_head']) ? $reportData['html']['is_group_head'] : 0;
                 // ---- Нижний колонтитул -----
                 $templater->rows_footer = $reportData['html']['rows_footer'];
                 $templater->footer_colspan = $reportData['html']['footer_colspan'];
                 // ---- Тело таблицы -----
                 $templater->rows_body = $reportData['html']['rows_body'];
                 $templater->is_row_header = isset($reportData['html']['is_row_header']) ? $reportData['html']['is_row_header'] : 0;
                 // Получим результат шаблона
                 $html = $templater->render('reports/report-table.tpl');
                 $this->sendJson(array('result' => $this->Translate('Создан отчет в формате HTML'), 'html' => $html));
                 break;
             case 'pdf':
                 // Проверим наличие файла mpdf.php
                 // Если нет, то выдадим ошибку!
                 $path = APPLICATION_BASE . '/library/mPDF/mpdf.php';
                 if (!is_file($path)) {
                     throw new Exception($this->Translate('Не установлена библиотека mPDF', '/library/mPDF', 'http://www.mpdf1.com/mpdf/index.php?page=Download'));
                 }
                 // Создадим обьект шаблона
                 if ($this->_isAjaxRequest) {
                     $templater = Default_Plugin_SysBox::createViewSmarty();
                 } else {
                     $templater = $this->view;
                 }
                 //------ Установим параметры и переменные HTML ------
                 // ---- Титл -----
                 $templater->title_name = $reportData['html']['title_report'];
                 $templater->title_logo = $reportData['html']['logo_report'];
                 // ---- Заголовок -----
                 $templater->column_model = $reportData['html']['column_model'];
                 $templater->is_group_head = isset($reportData['html']['is_group_head']) ? $reportData['html']['is_group_head'] : 0;
                 // ---- Нижний колонтитул -----
                 $templater->rows_footer = $reportData['html']['rows_footer'];
                 $templater->footer_colspan = $reportData['html']['footer_colspan'];
                 // ---- Тело таблицы -----
                 $templater->rows_body = $reportData['html']['rows_body'];
                 $templater->is_row_header = isset($reportData['pdf']['is_row_header']) ? $reportData['pdf']['is_row_header'] : 0;
                 // Получим результат шаблона
                 $html = $templater->render('reports/table.tpl');
                 // Установим имя отчета PDF
                 // в названии файла будет присутствовать хеш полученного HTML
                 // это нужно для того, чтобы не создавать существующих файлов
                 $md5Html = md5($html);
                 $report = $table . '_' . $md5Html;
                 // Установим параметры для отчета PDF
                 $pdfParams['pdfReport'] = $report;
                 $pdfParams['html'] = $html;
                 $pdfParams['isCommonFont'] = FALSE;
                 $pdfParams['pathStylesheet'] = 'css/report/blue-style.css';
                 //phpinfo blue-style
                 $pdfParams['headerLeftMargin'] = $reportData['pdf']['title_report'];
                 $pdfParams['headerCentreMargin'] = $reportData['pdf']['logo_report'];
                 $pdfParams['pageFormat'] = $reportData['pdf']['pageFormat'];
                 ob_start();
                 // Получим имя файла и проверим его наличие
                 $filename = Default_Plugin_SysBox::getPath_For_FilePDF($report);
                 if (file_exists($filename)) {
                     // Файл уже существует
                     sleep(1);
                     // Получить URL PDF файла
                     $urlFilePDF = Default_Plugin_SysBox::getFullUrl_For_FilePDF($report);
                     $this->sendJson(array('result' => $this->Translate('Этот отчет уже существует'), 'url_file_pdf' => $urlFilePDF));
                 } else {
                     // Создадим отчет...
                     // Удалим ранее созданные отчеты
                     // Получим директорию с файлами отчетов
                     $patch_dir = Default_Plugin_SysBox::getPath_For_FilePDF('');
                     // Получим обьект построения дерева файлов
                     $ft = new Default_Plugin_FileTree($patch_dir);
                     // создадим дерево файлов
                     $report_del = $table . '_*.pdf';
                     $ft->readTree(array('name' => $report_del));
                     // удалим файлы и директории
                     $result = $ft->delFiles();
                     // Создать PDF файл из HTML
                     $urlFilePDF = Default_Plugin_SysBox::mpdfGenerator_Html2PDF($pdfParams);
                     $this->sendJson(array('result' => $this->Translate('Создан отчет в формате PDF'), 'url_file_pdf' => $urlFilePDF));
                 }
                 break;
             case 'exel':
                 break;
             default:
                 break;
         }
     } catch (Exception $exc) {
         $jsons = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка формирования отчета') . '</em>', Default_Plugin_SysBox::getMessageError($exc)));
         $this->sendJson($jsons);
     }
 }
Exemplo n.º 2
0
 /**
  * Copy user directory for uploading files
  * 
  * @param string $username 
  * @return bool 
  */
 static function copyUsersUploadDir()
 {
     $config = Zend_Registry::get('config');
     $patchSource = $config['paths']['backup']['dir'] . '/upload';
     $patchSource = Default_Plugin_PathBox::normalize($patchSource);
     $patchDest = APPLICATION_PUBLIC . '/upload';
     $patchDest = Default_Plugin_PathBox::normalize($patchDest);
     //-------------------------
     if (!is_dir($patchDest)) {
         if (!mkdir($patchDest)) {
             throw new Exception("Failed to create folders...'{$patchDest}'.");
         }
         if (is_dir($patchSource)) {
             // Get the FileTree object
             $ft = new Default_Plugin_FileTree($patchSource);
             // Create tree of files
             $ft->readTree();
             // Copy the current fileset to another location
             if ($ft->writeTo($patchDest) === FALSE) {
                 throw new Exception("Could not be copied '{$patchSource}' to '{$patchDest}'.");
             } else {
                 $ft->delFiles();
                 // Delete this source
             }
         } else {
             throw new Exception("There is no this dir '{$patchSource}'.");
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Action - rebuild
  * rebuild the search index
  *
  * Access to the action is possible in the following paths:
  * - /search/rebuild
  * @return void
  */
 public function rebuildAction()
 {
     $result = TRUE;
     $err_msg = '';
     $json = array();
     //-------------------
     try {
         // Задержка условная
         sleep(3);
         $indexFullpath = Default_Model_DbTable_BlogPost::getIndexFullpath();
         if (is_dir($indexFullpath)) {
             // Получим обьект построения дерева файлов
             $ft = new Default_Plugin_FileTree($indexFullpath);
             // создадим дерево файлов
             $ft->readTree();
             // удалим файлы и директории
             $result = $ft->delFiles();
             if ($result) {
                 // удалим пустую директорию
                 $result = rmdir($indexFullpath);
             }
         }
         $index = Zend_Search_Lucene::create($indexFullpath);
         $options = array('status' => Default_Model_DbTable_BlogPost::STATUS_LIVE);
         $posts = Default_Model_DbTable_BlogPost::GetPosts(Zend_Registry::get('db'), $options);
         foreach ($posts as $post) {
             $index->addDocument($post->getIndexableDocument());
         }
         $index->commit();
         $message = array('<em>' . $this->Translate("Восстановление поискового индекса") . '!</em>', $this->Translate("Восстановление поискового индекса завершилось успешно") . '.');
         if ($this->_isAjaxRequest) {
             $json['class_message'] = 'information';
             $json['messages'] = $message;
             $json['$result'] = $result;
         }
     } catch (Exception $ex) {
         $err_msg = $ex->getMessage();
         $message = array('<em>' . $this->Translate("Ошибка восстановления поискового индекса") . '!</em>', $err_msg);
         if ($this->_isAjaxRequest) {
             $json['class_message'] = 'warning';
             $json['messages'] = $message;
             $json['$result'] = $result;
         } else {
             $logger = Zend_Registry::get('Zend_Log');
             $logger->warn('Error rebuilding search index: ' . $ex->getMessage());
             $result = FALSE;
         }
     }
     if ($this->_isAjaxRequest) {
         $this->sendJson($json);
     } else {
         $this->view->result = $result;
         if ($result) {
             $this->view->class_message = 'information';
         } else {
             $this->view->err_msg = $err_msg;
             $this->view->class_message = 'warning';
         }
         $this->view->message = $message;
         $this->_breadcrumbs->addStep($this->Translate('Восстановление поискового индекса'));
     }
 }