コード例 #1
0
ファイル: Json.php プロジェクト: robjacoby/xlr8u
 /**
  * Deploys content
  *
  * @see library/Bvb/Bvb_Grid::deploy()
  * @return void
  */
 public function deploy()
 {
     $this->setRecordsPerPage(0);
     parent::deploy();
     header('Content-Type', 'application/json');
     $grid = array('titles' => $this->buildTitles(), 'rows' => $this->buildGrid(), 'sqlexp' => $this->buildSqlexp());
     die(Zend_Json::encode($grid));
 }
コード例 #2
0
ファイル: JqgridController.php プロジェクト: Aeryris/grid
 public function exportAction()
 {
     // construct JqGrid and let it configure
     $grid1 = Bvb_Grid::factory('Bvb_Grid_Deploy_JqGrid', $this->_config, '', array('csv' => array($this, 'configG1PostCsv')));
     $this->configG1($grid1, $this->_getParam('onlyFromPolynesia', 'false') === 'true');
     // pass grids to view and deploy() them there
     $this->view->g1 = $grid1->deploy();
     $this->render('index');
 }
コード例 #3
0
 public function setUp()
 {
     parent::setUp();
     $this->grid = Bvb_Grid::factory('csv');
     $this->grid->setParam('module', 'default');
     $this->grid->setParam('controller', 'site');
     $this->grid->setView(new Zend_View(array()));
     $this->grid->setExport(array('csv'));
 }
コード例 #4
0
ファイル: TestHelper.php プロジェクト: Aeryris/grid
 public function deployGrid($select = null)
 {
     if ($select === null) {
         $select = $this->db->select()->from('unit');
     }
     $this->grid->setSource(new Bvb_Grid_Source_Zend_Select($select));
     $grid = $this->grid->deploy();
     $this->controller->getResponse()->setBody($grid);
     return $grid;
 }
コード例 #5
0
ファイル: Json.php プロジェクト: ocpyosep78/Booking
 /**
  * Deploys content
  *
  * @see library/Bvb/Bvb_Grid::deploy()
  * @return void
  */
 public function deploy()
 {
     $this->setRecordsPerPage(0);
     parent::deploy();
     header('Content-Type', 'application/json');
     $grid = array('titles' => $this->buildTitles(), 'rows' => $this->buildGrid(), 'sqlexp' => $this->buildSqlexp());
     if (!$this->getDeployOption('return', false)) {
         echo Zend_Json::encode($grid);
         die;
     } else {
         return Zend_Json::encode($grid);
     }
 }
コード例 #6
0
ファイル: Xml.php プロジェクト: ocpyosep78/Booking
 public function deploy()
 {
     $this->checkExportRights();
     $this->setRecordsPerPage(0);
     parent::deploy();
     $grid = '<?xml version="1.0" encoding="' . $this->getCharEncoding() . '"?>' . "\n";
     $grid .= "<grid>\n";
     $grid .= $this->buildTitles();
     $grid .= $this->buildGrid();
     $grid .= $this->buildSqlexp();
     $grid .= "</grid>";
     if (!isset($this->_deploy['save'])) {
         $this->_deploy['save'] = false;
     }
     if (!isset($this->_deploy['download'])) {
         $this->_deploy['download'] = false;
     }
     if ($this->_deploy['save'] != 1 && $this->_deploy['download'] != 1) {
         header("Content-type: application/xml");
     }
     if (!isset($this->_deploy['save']) && !isset($this->options['download'])) {
         echo $grid;
         die;
     }
     if (empty($this->_deploy['name'])) {
         $this->_deploy['name'] = date('H_m_d_H_i_s');
     }
     if (substr($this->_deploy['name'], -4) == '.xml') {
         $this->_deploy['name'] = substr($this->_deploy['name'], 0, -4);
     }
     $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/';
     if (!is_dir($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not a dir');
     }
     if (!is_writable($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not writable');
     }
     file_put_contents($this->_deploy['dir'] . $this->_deploy['name'] . ".xml", $grid);
     if ($this->_deploy['download'] == 1) {
         header('Content-Disposition: attachment; filename="' . $this->_deploy['name'] . '.xml"');
         readfile($this->_deploy['dir'] . $this->_deploy['name'] . '.xml');
     }
     if ($this->_deploy['save'] != 1) {
         unlink($this->_deploy['dir'] . $this->_deploy['name'] . '.xml');
     }
     die;
 }
コード例 #7
0
 public function listAction()
 {
     $config = new Zend_Config_Ini(BASE_PATH . DIRECTORY_SEPARATOR . "configs" . DIRECTORY_SEPARATOR . "grid.ini", 'production');
     $grid = Bvb_Grid::factory('Table', $config);
     $data = $this->_listdata();
     $source = new Bvb_Grid_Source_Array($data);
     $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
     $grid->setSource($source);
     $grid->setImagesUrl("{$baseUrl}/grid/");
     $editColumn = new Bvb_Grid_Extra_Column();
     $editColumn->setPosition('right')->setName('Edit')->setDecorator("<a href=\"{$baseUrl}/admin/subject/edit/id/{{subject_id}}\">Edit</a><input class=\"address-id\" name=\"address_id[]\" type=\"hidden\" value=\"{{subject_id}}\"/>");
     $deleteColumn = new Bvb_Grid_Extra_Column();
     $deleteColumn->setPosition('right')->setName('Delete')->setDecorator("<a class=\"delete-data\" href=\"{$baseUrl}/admin/subject/delete/id/{{subject_id}}\">Delete</a>");
     $grid->addExtraColumns($editColumn, $deleteColumn);
     $grid->updateColumn('subject_id', array('hidden' => true));
     $grid->updateColumn('del', array('hidden' => true));
     $grid->setRecordsPerPage(20);
     $grid->setPaginationInterval(array(5 => 5, 10 => 10, 20 => 20, 30 => 30, 40 => 40, 50 => 50, 100 => 100));
     $grid->setExport(array('print', 'word', 'csv', 'excel', 'pdf'));
     $this->view->grid = $grid->deploy();
 }
コード例 #8
0
ファイル: Grid.php プロジェクト: nandorodpires2/gallery
 /**
  * Adds the default deploy classes dir location
  */
 public static function initDeployClass()
 {
     self::$_deployClassesDir = new Zend_Loader_PluginLoader();
     self::$_deployClassesDir->addPrefixPath('Bvb_Grid_Deploy', 'Bvb/Grid/Deploy/');
 }
コード例 #9
0
ファイル: Table.php プロジェクト: ocpyosep78/Booking
 /**
  * Combines all parts from the output
  * To deploy or to render()
  *
  * @param bool $deploy IF this is the deploy and not a render part
  *
  * @return void
  */
 private function _buildGridRender($deploy = true)
 {
     $bHeader = $this->_buildExtraRows('beforeHeader') . $this->_buildHeader() . $this->_buildExtraRows('afterHeader');
     $bTitles = $this->_buildExtraRows('beforeTitles') . $this->_buildMassActions() . $this->_buildTitlesTable(parent::_buildTitles(), true) . $this->_buildExtraRows('afterTitles');
     $bFilters = $this->_buildExtraRows('beforeFilters') . $this->_buildFiltersTable(parent::_buildFilters()) . $this->_buildExtraRows('afterFilters');
     $bGrid = $this->_buildGridTable(parent::_buildGrid());
     if (!$this->getInfo("hRow,title")) {
         $bSqlExp = $this->_buildExtraRows('beforeSqlExpTable') . $this->_buildSqlexpTable(parent::_buildSqlExp()) . $this->_buildExtraRows('afterSqlExpTable');
     } else {
         $bSqlExp = '';
     }
     $bPagination = $this->_buildExtraRows('beforePagination') . $this->_buildPagination() . $this->_buildExtraRows('afterPagination');
     if ($deploy == true) {
         $this->_renderDeploy['header'] = $bHeader;
         $this->_renderDeploy['titles'] = $bTitles;
         $this->_renderDeploy['filters'] = $bFilters;
         $this->_renderDeploy['grid'] = $bGrid;
         $this->_renderDeploy['sqlExp'] = $bSqlExp;
         $this->_renderDeploy['pagination'] = $bPagination;
     }
     $this->_render['header'] = $bHeader;
     $this->_render['titles'] = $bTitles;
     $this->_render['filters'] = $bFilters;
     $this->_render['grid'] = $bGrid;
     $this->_render['sqlExp'] = $bSqlExp;
     $this->_render['pagination'] = $bPagination;
 }
コード例 #10
0
ファイル: JqGrid.php プロジェクト: robjacoby/xlr8u
 /**
  * Returns the number of records to show per page
  *
  * Is overriden to return always the number of data requested by jqGrid ajax request.
  *
  * @return integer
  */
 public function getRecordsPerPage()
 {
     $perPage = $this->getParam('perPage', false);
     if (false === $perPage) {
         return parent::getRecordsPerPage();
     }
     return $perPage;
 }
コード例 #11
0
ファイル: Print.php プロジェクト: ocpyosep78/Booking
 public function deploy()
 {
     $this->checkExportRights();
     $this->setRecordsPerPage(0);
     parent::deploy();
     if (!$this->_temp['print'] instanceof Bvb_Grid_Template_Print) {
         $this->setTemplate('print', 'print');
     }
     $titles = parent::_buildTitles();
     $wsData = parent::_buildGrid();
     $sql = parent::_buildSqlExp();
     if (!isset($this->_deploy['title'])) {
         $this->_deploy['title'] = '';
     }
     $print = $this->_temp['print']->globalStart();
     $print .= $this->_temp['print']->header();
     //[PT] Títulos
     $print .= $this->_temp['print']->titlesStart();
     foreach ($titles as $value) {
         if (isset($value['field']) && $value['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
             $print .= str_replace("{{value}}", $value['value'], $this->_temp['print']->titlesLoop());
         }
     }
     $print .= $this->_temp['print']->titlesEnd();
     if (is_array($wsData)) {
         if ($this->getInfo('hRow,title') != '') {
             $bar = $wsData;
             $hbar = trim($this->getInfo('hRow,field'));
             $p = 0;
             foreach ($wsData[0] as $value) {
                 if ($value['field'] == $hbar) {
                     $hRowIndex = $p;
                 }
                 $p++;
             }
             $aa = 0;
         }
         $i = 1;
         $aa = 0;
         foreach ($wsData as $row) {
             //horizontal row
             if ($this->getInfo('hRow,title') != '') {
                 if (!isset($bar[$aa - 1][$hRowIndex])) {
                     $bar[$aa - 1][$hRowIndex]['value'] = '';
                 }
                 if ($bar[$aa][$hRowIndex]['value'] != $bar[$aa - 1][$hRowIndex]['value']) {
                     $print .= str_replace("{{value}}", $bar[$aa][$hRowIndex]['value'], $this->_temp['print']->hRow());
                 }
             }
             $i++;
             $print .= $this->_temp['print']->loopStart();
             $a = 1;
             foreach ($row as $value) {
                 $value['value'] = strip_tags($value['value']);
                 if (isset($value['field']) && $value['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
                     $print .= str_replace("{{value}}", $value['value'], $this->_temp['print']->loopLoop());
                 }
             }
             $print .= $this->_temp['print']->loopEnd();
             $aa++;
             $i++;
         }
     }
     // SQL EXPRESSIONS
     if (is_array($sql)) {
         $print .= $this->_temp['print']->sqlExpStart();
         foreach ($sql as $value) {
             $print .= str_replace("{{value}}", $value['value'], $this->_temp['print']->sqlExpLoop());
         }
         $print .= $this->_temp['print']->sqlExpEnd();
     }
     $print .= $this->_temp['print']->globalEnd();
     if (!isset($this->_deploy['save'])) {
         $this->_deploy['save'] = false;
     }
     if (!isset($this->_deploy['download'])) {
         $this->_deploy['download'] = false;
     }
     if ($this->_deploy['save'] != 1 && $this->_deploy['download'] != 1) {
         header("Content-type: text/html");
     }
     if ($this->_deploy['save'] != 1 && $this->_deploy['download'] != 1) {
         echo $print;
         die;
     }
     if (empty($this->_deploy['name'])) {
         $this->_deploy['name'] = date('H_m_d_H_i_s');
     }
     if (substr($this->_deploy['name'], -5) == '.html') {
         $this->_deploy['name'] = substr($this->_deploy['name'], 0, -5);
     }
     $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/';
     if (!is_dir($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not a dir');
     }
     if (!is_writable($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not writable');
     }
     file_put_contents($this->_deploy['dir'] . $this->_deploy['name'] . ".html", $print);
     if ($this->_deploy['download'] == 1) {
         header('Content-Disposition: attachment; filename="' . $this->_deploy['name'] . '.html"');
         readfile($this->_deploy['dir'] . $this->_deploy['name'] . '.html');
     }
     if ($this->_deploy['save'] != 1) {
         unlink($this->_deploy['dir'] . $this->_deploy['name'] . '.html');
     }
     die;
 }
コード例 #12
0
ファイル: Wordx.php プロジェクト: ocpyosep78/Booking
 public function deploy()
 {
     $this->checkExportRights();
     $this->setRecordsPerPage(0);
     parent::deploy();
     if (!$this->_temp['wordx'] instanceof Bvb_Grid_Template_Wordx) {
         $this->setTemplate('wordx', 'wordx');
     }
     $this->templateInfo = $this->_temp['wordx']->options;
     if (!isset($this->_deploy['title'])) {
         $this->_deploy['title'] = '';
     }
     if (!isset($this->_deploy['subtitle'])) {
         $this->_deploy['subtitle'] = '';
     }
     if (!isset($this->_deploy['logo'])) {
         $this->_deploy['logo'] = '';
     }
     if (!isset($this->_deploy['footer'])) {
         $this->_deploy['footer'] = '';
     }
     if (!isset($this->_deploy['save'])) {
         $this->_deploy['save'] = false;
     }
     if (!isset($this->_deploy['download'])) {
         $this->_deploy['download'] = false;
     }
     if ($this->_deploy['save'] != 1 && $this->_deploy['download'] != 1) {
         throw new Exception('Nothing to do. Please specify download&&|save options');
     }
     $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/';
     $this->inicialDir = $this->_deploy['dir'];
     if (empty($this->_deploy['name'])) {
         $this->_deploy['name'] = date('H_m_d_H_i_s');
     }
     if (substr($this->_deploy['name'], -5) == '.docx') {
         $this->_deploy['name'] = substr($this->_deploy['name'], 0, -5);
     }
     if (!is_dir($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not a dir');
     }
     if (!is_writable($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not writable');
     }
     $this->templateDir = explode('/', $this->_deploy['dir']);
     array_pop($this->templateDir);
     $this->templateDir = ucfirst(end($this->templateDir));
     $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/' . ucfirst($this->_deploy['name']) . '/';
     if (!defined('APPLICATION_PATH')) {
         $pathTemplate = substr($this->templateInfo['dir'], 0, -4) . '/';
     } else {
         $pathTemplate = APPLICATION_PATH . '/../' . rtrim($this->getLibraryDir(), '/') . '/' . substr($this->templateInfo['dir'], 0, -4) . '/';
     }
     Bvb_Grid_Deploy_Helper_File::deldir($this->_deploy['dir']);
     Bvb_Grid_Deploy_Helper_File::copyDir($pathTemplate, $this->_deploy['dir']);
     $xml = $this->_temp['wordx']->globalStart();
     $titles = parent::_buildTitles();
     $wsData = parent::_buildGrid();
     $sql = parent::_buildSqlExp();
     # HEADER
     if (file_exists($this->_deploy['logo'])) {
         $data = explode("/", $this->_deploy['logo']);
         copy($this->_deploy['logo'], $this->_deploy['dir'] . 'word/media/' . end($data));
         $logo = $this->_temp['wordx']->logo();
         file_put_contents($this->dir . "word/_rels/header1.xml.rels", $logo);
         $header = str_replace(array('{{title}}', '{{subtitle}}'), array($this->_deploy['title'], $this->_deploy['subtitle']), $this->_temp['wordx']->header());
     } else {
         $header = str_replace(array('{{title}}', '{{subtitle}}'), array($this->_deploy['title'], $this->_deploy['subtitle']), $this->_temp['wordx']->header());
     }
     file_put_contents($this->_deploy['dir'] . "word/header1.xml", $header);
     #BEGIN FOOTER
     $footer = str_replace("{{value}}", $this->_deploy['footer'], $this->_temp['wordx']->footer());
     file_put_contents($this->_deploy['dir'] . "word/footer2.xml", $footer);
     #START DOCUMENT.XML
     $xml = $this->_temp['wordx']->globalStart();
     $xml .= $this->_temp['wordx']->titlesStart();
     foreach ($titles as $value) {
         if (isset($value['field']) && $value['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
             $xml .= str_replace("{{value}}", utf8_encode($value['value']), $this->_temp['wordx']->titlesLoop());
         }
     }
     $xml .= $this->_temp['wordx']->titlesEnd();
     if (is_array($wsData)) {
         if ($this->getInfo('hRow,title') != '') {
             $bar = $wsData;
             $hbar = trim($this->getInfo('hRow,title'));
             $p = 0;
             foreach ($wsData[0] as $value) {
                 if (isset($value['field']) && $value['field'] == $hbar) {
                     $hRowIndex = $p;
                 }
                 $p++;
             }
             $aa = 0;
         }
         $i = 1;
         $aa = 0;
         foreach ($wsData as $row) {
             //A linha horizontal
             if (@$this->getInfo('hRow,title') != '') {
                 if (@$bar[$aa][$hRowIndex]['value'] != @$bar[$aa - 1][$hRowIndex]['value']) {
                     $xml .= str_replace("{{value}}", utf8_encode(@$bar[$aa][$hRowIndex]['value']), $this->_temp['wordx']->hRow());
                 }
             }
             $xml .= $this->_temp['wordx']->loopStart();
             $a = 1;
             foreach ($row as $value) {
                 $value['value'] = strip_tags($value['value']);
                 if (isset($value['field']) && $value['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
                     $xml .= str_replace("{{value}}", utf8_encode($value['value']), $this->_temp['wordx']->loopLoop());
                 }
                 $a++;
             }
             $xml .= $this->_temp['wordx']->loopEnd();
             $aa++;
             $i++;
         }
     }
     if (is_array($sql)) {
         $xml .= $this->_temp['wordx']->sqlExpStart();
         foreach ($sql as $value) {
             $xml .= str_replace("{{value}}", utf8_encode($value['value']), $this->_temp['wordx']->sqlExpLoop());
         }
         $xml .= $this->_temp['wordx']->sqlExpEnd();
     }
     $xml .= $this->_temp['wordx']->globalEnd();
     file_put_contents($this->_deploy['dir'] . "word/document.xml", $xml);
     $final = Bvb_Grid_Deploy_Helper_File::scan_directory_recursively($this->_deploy['dir']);
     $f = explode('|', Bvb_Grid_Deploy_Helper_File::zipPaths($final));
     array_pop($f);
     $zip = new ZipArchive();
     $filename = $this->_deploy['dir'] . $this->_deploy['name'] . ".zip";
     if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
         exit("cannot open <{$filename}>\n");
     }
     foreach ($f as $value) {
         $zip->addFile($value, str_replace($this->_deploy['dir'], '', $value));
     }
     $zip->close();
     rename($filename, $this->inicialDir . $this->_deploy['name'] . '.docx');
     if ($this->_deploy['download'] == 1) {
         header('Content-type: application/word');
         header('Content-Disposition: attachment; filename="' . $this->_deploy['name'] . '.docx"');
         readfile($this->inicialDir . $this->_deploy['name'] . '.docx');
     }
     if ($this->_deploy['save'] != 1) {
         unlink($this->inicialDir . $this->_deploy['name'] . '.docx');
     }
     Bvb_Grid_Deploy_Helper_File::deldir($this->_deploy['dir']);
     die;
 }
コード例 #13
0
ファイル: Grid.php プロジェクト: robjacoby/xlr8u
 /**
  * Defines the default grid configuration
  *
  * @param Zend_Config|array $options Config Options
  *
  * @throws Bvb_Grid_Exception
  * @static
  *
  * @return void
  */
 public static function setDefaultConfig($options)
 {
     if ($options instanceof Zend_Config) {
         $options = $options->toArray();
     } elseif (!is_array($options)) {
         throw new Bvb_Grid_Exception('options must be an instance from Zend_Config or an array');
     }
     self::$_defaultConfig = $options;
 }
コード例 #14
0
ファイル: SiteController.php プロジェクト: Aeryris/grid
 /**
  * Simplify the datagrid creation process
  * @return Bvb_Grid_Deploy_Table
  */
 public function grid($id = '')
 {
     $view = new Zend_View();
     $view->setEncoding('ISO-8859-1');
     $config = new Zend_Config_Ini('./application/grids/grid.ini', 'production');
     $grid = Bvb_Grid::factory('Table', $config, $id);
     $grid->setEscapeOutput(false);
     $grid->setExport(array('xml', 'csv', 'excel', 'pdf'));
     $grid->setView($view);
     #$grid->saveParamsInSession(true);
     #$grid->setCache(array('enable' => array('form'=>false,'db'=>false), 'instance' => Zend_Registry::get('cache'), 'tag' => 'grid'));
     return $grid;
 }
コード例 #15
0
ファイル: Pdf.php プロジェクト: nandorodpires2/gallery
 public function deploy()
 {
     $this->checkExportRights();
     $this->setRecordsPerPage(0);
     parent::deploy();
     $this->_width = 0;
     $colors = array('title' => '#000000', 'subtitle' => '#111111', 'footer' => '#111111', 'header' => '#AAAAAA', 'row1' => '#EEEEEE', 'row2' => '#FFFFFF', 'sqlexp' => '#BBBBBB', 'lines' => '#111111', 'hrow' => '#E4E4F6', 'text' => '#000000', 'filters' => '#F9EDD2', 'filtersBox' => '#DEDEDE');
     $this->_deploy['colors'] = array_merge($colors, (array) $this->_deploy['colors']);
     if (!isset($this->_deploy['save'])) {
         $this->_deploy['save'] = false;
     }
     if (!isset($this->_deploy['download'])) {
         $this->_deploy['download'] = false;
     }
     if ($this->_deploy['save'] != 1 && $this->_deploy['download'] != 1) {
         throw new Exception('Nothing to do. Please specify download&&|save options');
     }
     if (empty($this->_deploy['name'])) {
         $this->_deploy['name'] = date('H_m_d_H_i_s');
     }
     if (substr($this->_deploy['name'], -4) == '.xls') {
         $this->_deploy['name'] = substr($this->_deploy['name'], 0, -4);
     }
     if (!isset($this->_deploy['noPagination'])) {
         $this->_deploy['noPagination'] = 0;
     }
     $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/';
     if (!isset($this->_deploy['dir']) || !is_dir($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not a dir');
     }
     if (!is_writable($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not writable');
     }
     $this->_la = 0;
     $titles = parent::_buildTitles();
     $grid = parent::_BuildGrid();
     $sqlExp = parent::_buildSqlExp();
     $larg = $this->calculateCellSize($titles, $sqlExp, $grid);
     $lengthTotal = array_sum($larg['larg']);
     $this->_cellFontSize = $this->getDeployOption('cellFontSize', 8);
     if (!$this->getInfo('hRow,field')) {
         $this->_info['hRow']['field'] = '';
     }
     if (strtoupper($this->_deploy['orientation']) == 'LANDSCAPE' && strtoupper($this->_deploy['size']) == 'A4') {
         $this->_totalPages = ceil(count($grid) / 26);
     } elseif (strtoupper($this->_deploy['orientation']) == 'LANDSCAPE' && strtoupper($this->_deploy['size']) == 'LETTER') {
         $this->_totalPages = ceil(count($grid) / 27);
     } else {
         $this->_totalPages = ceil(count($grid) / 37);
     }
     if ($this->_totalPages < 1) {
         $this->_totalPages = 1;
     }
     $this->_pdf = new Zend_Pdf();
     $this->_styles['style'] = new Zend_Pdf_Style();
     $this->_styles['style']->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['lines']));
     $this->_styles['topo'] = new Zend_Pdf_Style();
     $this->_styles['topo']->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['header']));
     $this->_styles['td'] = new Zend_Pdf_Style();
     $this->_styles['td']->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['row2']));
     $this->_styles['styleFilters'] = new Zend_Pdf_Style();
     $this->_styles['styleFilters']->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['filters']));
     $this->_styles['styleFiltersBox'] = new Zend_Pdf_Style();
     $this->_styles['styleFiltersBox']->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['filtersBox']));
     $this->_styles['td2'] = new Zend_Pdf_Style();
     $this->_styles['td2']->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['row1']));
     $this->_styles['hRowStyle'] = new Zend_Pdf_Style();
     $this->_styles['hRowStyle']->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['hrow']));
     $this->_styles['styleSql'] = new Zend_Pdf_Style();
     $this->_styles['styleSql']->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['sqlexp']));
     $this->_styles['styleText'] = new Zend_Pdf_Style();
     $this->_styles['styleText']->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['text']));
     $this->buildPageStructure($titles, true);
     $pageWidth = $this->_page->getWidth() - 80;
     $i = 0;
     foreach ($larg['larg'] as $final) {
         $this->_cell[$i] = ceil($final * $pageWidth / $lengthTotal);
         $i++;
     }
     $needed = 0;
     $fix = $larg['fix'];
     $larg = $larg['larg'];
     $perc = array();
     $i = 0;
     foreach ($this->_cell as $key => $value) {
         $perc[$key] = $value - $fix[$key];
         $i++;
     }
     $perc = array();
     foreach ($this->_cell as $key => $value) {
         if ($value + 2 < $fix[$key]) {
             $needed = ceil($fix[$key] - $value);
             $this->_cell[$key] = $fix[$key];
         }
         if ($value > $fix[$key] + 2 + $needed) {
             $this->_cell[$key] = $this->_cell[$key] - $needed;
             $needed = 0;
             $perc[$key] = $this->_cell[$key] - $fix[$key];
         }
     }
     if (array_sum($this->_cell) > $pageWidth) {
         $totalToRemove = array_sum($this->_cell) - $pageWidth;
         foreach ($perc as $key => $value) {
             $this->_cell[$key] = $this->_cell[$key] - round($totalToRemove * $value / array_sum($perc));
         }
     }
     $cellsCount = count($titles);
     if ($this->getInfo('hRow,title') != '') {
         $cellsCount--;
     }
     $largura = ($this->_page->getWidth() - 80) / $cellsCount;
     $this->_height = $this->_page->getHeight() - 120;
     $this->buildPageStructure($titles);
     $this->_page->setFont($this->_font, $this->_cellFontSize);
     $this->_page->setStyle($this->_styles['style']);
     if (is_array($grid)) {
         if ($this->getInfo('hRow,title') != '') {
             $bar = $grid;
             $hbar = trim($this->getInfo('hRow,field'));
             $p = 0;
             foreach ($grid[0] as $value) {
                 if ($value['field'] == $hbar) {
                     $hRowIndex = $p;
                 }
                 $p++;
             }
             $aa = 0;
         }
         $ia = 0;
         $aa = 0;
         foreach ($grid as $value) {
             if ($this->_height <= 80) {
                 $this->buildPageStructure($titles);
             }
             $this->_la = 0;
             $this->_height = $this->_height - 16;
             $i = 0;
             $tdf = $ia % 2 ? $this->_styles['td'] : $this->_styles['td2'];
             $a = 1;
             if ($this->getInfo('hRow,title') != '') {
                 if ($bar[$aa][$hRowIndex]['value'] != @$bar[$aa - 1][$hRowIndex]['value']) {
                     $centrar = $this->_page->getWidth() - 80;
                     $centrar = round($centrar / 2) + 30;
                     if ((int) $this->_la == 0) {
                         $largura1 = 40;
                     } else {
                         $largura1 = $this->_cell[$i - 1] + $largura1;
                     }
                     $this->_page->setStyle($this->_styles['hRowStyle']);
                     $this->_page->drawRectangle($largura1, $this->_height - 8, $this->_page->getWidth() - 39, $this->_height + 16);
                     $this->_page->setStyle($this->_styles['styleText']);
                     $this->_page->drawText($bar[$aa][$hRowIndex]['value'], $centrar, $this->_height + 2, $this->getCharEncoding());
                     $this->_la = 0;
                     $this->_height = $this->_height - 16;
                 }
             }
             $nl = 0;
             $tLines = $this->calculateNumerOfLinesForRecord($value);
             $cellPos = 0;
             foreach ($value as $value1) {
                 $value1['value'] = strip_tags(trim($value1['value']));
                 if ($value1['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
                     if ((int) $this->_la == 0) {
                         $largura1 = 40;
                     } else {
                         $largura1 = $this->_cell[$i - 1] + $largura1;
                     }
                     $this->_page->setStyle($tdf);
                     $this->_page->drawRectangle($largura1, $this->_height + 8, $largura1 + $this->_cell[$i] + 1, $this->_height - 8);
                     $this->_page->setStyle($this->_styles['styleText']);
                     $textToShow = $this->getArrayForPdfRecord($value1['value'], $cellPos, $tLines);
                     $heightSupport = 0;
                     for ($ti = 0; $ti < $tLines; $ti++) {
                         if (!isset($textToShow[$ti])) {
                             continue;
                         }
                         if (count($textToShow) == 1) {
                             $extraHeight = round($tLines / count($textToShow)) + 2;
                         } else {
                             $extraHeight = 0;
                         }
                         $this->_page->drawText($textToShow[$ti], $largura1 + 2, $this->_height - $extraHeight - $heightSupport * 8, $this->getCharEncoding());
                         $heightSupport++;
                     }
                     $this->_la = $largura1;
                     $i++;
                     $nl++;
                     $cellPos++;
                 }
                 $a++;
             }
             $aa++;
             $ia++;
         }
     }
     $this->buildSqlPdf($sqlExp);
     $this->buildShowFiltersInExport();
     $this->_pdf->save($this->_deploy['dir'] . $this->_deploy['name'] . '.pdf');
     if ($this->_deploy['download'] == 1) {
         header('Content-type: application/pdf');
         header('Content-Disposition: attachment; filename="' . $this->_deploy['name'] . '.pdf"');
         readfile($this->_deploy['dir'] . $this->_deploy['name'] . '.pdf');
     }
     if ($this->_deploy['save'] != 1) {
         unlink($this->_deploy['dir'] . $this->_deploy['name'] . '.pdf');
     }
     die;
 }
コード例 #16
0
ファイル: Ods.php プロジェクト: ocpyosep78/Booking
 public function deploy()
 {
     $this->checkExportRights();
     $this->setRecordsPerPage(0);
     parent::deploy();
     if (!$this->_temp['ods'] instanceof Bvb_Grid_Template_Ods) {
         $this->setTemplate('ods', 'ods');
     }
     $this->templateInfo = $this->_temp['ods']->options;
     if (!isset($this->_deploy['title'])) {
         $this->_deploy['title'] = '';
     }
     if (!isset($this->_deploy['subtitle'])) {
         $this->_deploy['subtitle'] = '';
     }
     if (!isset($this->_deploy['logo'])) {
         $this->_deploy['logo'] = '';
     }
     if (!isset($this->_deploy['footer'])) {
         $this->_deploy['footer'] = '';
     }
     if (!isset($this->_deploy['save'])) {
         $this->_deploy['save'] = false;
     }
     if (!isset($this->_deploy['download'])) {
         $this->_deploy['download'] = false;
     }
     if ($this->_deploy['save'] != 1 && $this->_deploy['download'] != 1) {
         throw new Exception('Nothing to do. Please specify download&&|save options');
     }
     $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/';
     $this->inicialDir = $this->_deploy['dir'];
     if (empty($this->_deploy['name'])) {
         $this->_deploy['name'] = date('H_m_d_H_i_s');
     }
     if (substr($this->_deploy['name'], -5) == '.docx') {
         $this->_deploy['name'] = substr($this->_deploy['name'], 0, -5);
     }
     if (!is_dir($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not a dir');
     }
     if (!is_writable($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not writable');
     }
     $this->templateDir = explode('/', $this->templateInfo['dir']);
     array_pop($this->templateDir);
     $this->templateDir = ucfirst(end($this->templateDir));
     $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/' . ucfirst($this->_deploy['name']) . '/';
     if (!defined(APPLICATION_PATH)) {
         $pathTemplate = substr($this->templateInfo['dir'], 0, -4) . '/';
     } else {
         $pathTemplate = APPLICATION_PATH . '/../' . rtrim($this->getLibraryDir(), '/') . '/' . substr($this->templateInfo['dir'], 0, -4) . '/';
     }
     Bvb_Grid_Deploy_Helper_File::deldir($this->_deploy['dir']);
     Bvb_Grid_Deploy_Helper_File::copyDir($pathTemplate, $this->_deploy['dir']);
     $xml = $this->_temp['ods']->globalStart();
     $titles = parent::_buildTitles();
     $wsData = parent::_buildGrid();
     $sql = parent::_buildSqlExp();
     // START CONTENT.XML
     $xml = $this->_temp['ods']->globalStart();
     $xml .= $this->_temp['ods']->titlesStart();
     foreach ($titles as $value) {
         $xml .= str_replace("{{value}}", utf8_encode($value['value']), $this->_temp['ods']->titlesLoop());
     }
     $xml .= $this->_temp['ods']->titlesEnd();
     if (is_array($wsData)) {
         foreach ($wsData as $row) {
             $xml .= $this->_temp['ods']->loopStart();
             foreach ($row as $value) {
                 $xml .= str_replace("{{value}}", utf8_encode(strip_tags($value['value'])), $this->_temp['ods']->loopLoop());
             }
             $xml .= $this->_temp['ods']->loopEnd();
         }
     }
     if (is_array($sql)) {
         $xml .= $this->_temp['ods']->sqlExpStart();
         foreach ($sql as $value) {
             $xml .= str_replace("{{value}}", utf8_encode($value['value']), $this->_temp['ods']->sqlExpLoop());
         }
         $xml .= $this->_temp['ods']->sqlExpEnd();
     }
     $xml .= $this->_temp['ods']->globalEnd();
     file_put_contents($this->_deploy['dir'] . "content.xml", $xml);
     $final = Bvb_Grid_Deploy_Helper_File::scan_directory_recursively($this->_deploy['dir']);
     $f = explode('|', Bvb_Grid_Deploy_Helper_File::zipPaths($final));
     array_pop($f);
     $zip = new ZipArchive();
     $filename = $this->_deploy['dir'] . $this->_deploy['name'] . ".zip";
     if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
         exit("cannot open <{$filename}>\n");
     }
     foreach ($f as $value) {
         $zip->addFile($value, str_replace($this->_deploy['dir'], '', $value));
     }
     $zip->close();
     rename($filename, $this->inicialDir . $this->_deploy['name'] . '.ods');
     if ($this->_deploy['download'] == 1) {
         header('Content-type: application/vnd.oasis.opendocument.spreadsheet');
         header('Content-Disposition: attachment; filename="' . $this->_deploy['name'] . '.ods"');
         readfile($this->inicialDir . $this->_deploy['name'] . '.ods');
     }
     if ($this->_deploy['save'] != 1) {
         unlink($this->inicialDir . $this->_deploy['name'] . '.ods');
     }
     Bvb_Grid_Deploy_Helper_File::deldir($this->_deploy['dir']);
     die;
 }
コード例 #17
0
ファイル: Bvb_GridTest.php プロジェクト: Aeryris/grid
 public function testDefaultConfig()
 {
     $this->assertEquals(count(Bvb_Grid::getDefaultConfig()), 0);
 }
コード例 #18
0
ファイル: Ofc.php プロジェクト: Aeryris/grid
    public function deploy()
    {
        $this->checkExportRights();
        if ($this->_filesLocation === null) {
            throw new Bvb_Grid_Exception($this->__("Please set Javascript and Flash file locations using SetFilesLocation()"));
        }
        $grid = array();
        $newData = array();
        $label = array();
        $result = array();
        parent::deploy();
        $data = parent::_buildGrid();
        if (count($data) == 0) {
            $this->_deploymentContent = '';
            return;
        }
        foreach ($data as $value) {
            foreach ($value as $final) {
                $result[$final['field']][] = is_numeric($final['value']) ? $final['value'] : strip_tags($final['value']);
            }
        }
        if (is_string($this->_xLabels) && isset($result[$this->_xLabels])) {
            $this->_xLabels = $result[$this->_xLabels];
        }
        $graph = new OFC_Chart();
        $title = new OFC_Elements_Title($this->_title);
        $title->set_style($this->_style);
        $graph->set_title($title);
        foreach ($this->_chartOptions as $key => $value) {
            $graph->{$key}($value);
        }
        if (count($this->_xLabels) > 0) {
            $x = new OFC_Elements_Axis_X();
            $x_axis_labels = new OFC_Elements_Axis_X_Label_Set();
            foreach ($this->_xAxisOptions as $key => $value) {
                $x_axis_labels->{$key}($value);
            }
            $x_axis_labels->set_labels($this->_xLabels);
            $x->set_labels($x_axis_labels);
            foreach ($this->_xLabelsOptions as $key => $value) {
                $x->{$key}($value);
            }
            $graph->set_x_axis($x);
        }
        if (!empty($this->_xLegendText) && !empty($this->_xLegendStyle)) {
            $x_legend = new OFC_Elements_Legend_X($this->_xLegendText);
            $x_legend->set_style($this->_xLegendStyle);
            $graph->set_x_legend($x_legend);
        }
        $min = 0;
        $max = 0;
        if (count($this->_values) == 0) {
            $this->setValues(key($result));
        }
        foreach ($this->_values as $key => $value) {
            if (is_array($value)) {
                $support = $value;
                sort($support);
                if (reset($support) < $min) {
                    $min = reset($support);
                }
                if (end($support) > $max) {
                    $max = end($support);
                }
                unset($support);
                $options = $this->_chartOptionsValues[$value];
                if (isset($options['chartType'])) {
                    $this->setChartType($options['chartType']);
                }
                $bar = new $this->_type();
                foreach ($options as $key => $prop) {
                    $bar->{$key}($prop);
                }
                $this->_type();
                $pie = array();
                if ($this->_type == 'Pie') {
                    foreach ($value as $key => $title) {
                        $pie[] = array('value' => $title, 'label' => $this->_xLabels[$key]);
                    }
                    $bar->set_values($pie);
                } else {
                    $bar->set_values($value);
                }
                $graph->add_element($bar);
            } elseif (is_string($value) && isset($result[$value])) {
                $options = $this->_chartOptionsValues[$value];
                if (isset($options['chartType'])) {
                    $this->setChartType($options['chartType']);
                }
                $bar = new $this->_type();
                foreach ($options as $key => $prop) {
                    $bar->{$key}($prop);
                }
                $value = array_map(create_function('$item', ' return (float)$item; '), $result[$value]);
                $support = $value;
                sort($support);
                if (reset($support) < $min) {
                    $min = reset($support);
                }
                if (end($support) > $max) {
                    $max = end($support);
                }
                unset($support);
                $pie = array();
                if ($this->_type == 'OFC_Charts_Pie') {
                    foreach ($value as $key => $title) {
                        $pie[] = array('value' => $title, 'label' => $this->_xLabels[$key]);
                    }
                    $bar->set_values($pie);
                } else {
                    $bar->set_values($value);
                }
                $graph->add_element($bar);
            }
        }
        $max = $max * 1.05;
        $y = new OFC_Elements_Axis_Y();
        $y->set_range($min, $max, ceil($max / 4));
        $graph->add_y_axis($y);
        $final = $graph->toPrettyString();
        if (!is_string($this->_chartId)) {
            $this->_chartId = 'chart_' . rand(1, 10000);
        }
        $script = '
        swfobject.embedSWF(
        "' . $this->_filesLocation['flash'] . '", "' . $this->_chartId . '",
        "' . $this->_chartDimensions['x'] . '", "' . $this->_chartDimensions['y'] . '", "9.0.0", "expressInstall.swf",{"id":"' . $this->_chartId . '"},{"z-index":"1","wmode":"transparent"} );

        function open_flash_chart_data(id)
        {
            return JSON.stringify(window[id]);
        }

        function findSWF(movieName) {
          if (navigator.appName.indexOf("Microsoft")!= -1) {
            return window[movieName];
          } else {
            return document[movieName];
          }
        }
        var ' . $this->_chartId . ' = ' . $final . ';';
        $final = '<div id="' . $this->_chartId . '" >
        loading...
        <br/>
        <p>
        Please note that this content requires flash player 9.0.0</br>
        To test for your version of flash, <a href="http://www.bobbyvandersluis.com/swfobject/testsuite_2_1/test_api_getflashplayerversion.html" target="_blank">click here</a>
        </p>
        </div>';
        if (!$this->_multiple) {
            $final = '<div style="width: 100%;text-align: center">' . $final . '</div>';
        }
        $this->getView()->headScript()->appendFile($this->_filesLocation['js']);
        $this->getView()->headScript()->appendFile($this->_filesLocation['json']);
        $this->getView()->headScript()->appendScript($script);
        $this->_deploymentContent = $final;
        return $this;
    }
コード例 #19
0
ファイル: Pdf.php プロジェクト: robjacoby/xlr8u
 public function deploy()
 {
     $this->checkExportRights();
     $this->setRecordsPerPage(0);
     parent::deploy();
     $width = 0;
     $colors = array('title' => '#000000', 'subtitle' => '#111111', 'footer' => '#111111', 'header' => '#AAAAAA', 'row1' => '#EEEEEE', 'row2' => '#FFFFFF', 'sqlexp' => '#BBBBBB', 'lines' => '#111111', 'hrow' => '#E4E4F6', 'text' => '#000000', 'filters' => '#F9EDD2', 'filtersBox' => '#DEDEDE');
     $this->_deploy['colors'] = array_merge($colors, (array) $this->_deploy['colors']);
     $la = '';
     if (!isset($this->_deploy['save'])) {
         $this->_deploy['save'] = false;
     }
     if (!isset($this->_deploy['download'])) {
         $this->_deploy['download'] = false;
     }
     if ($this->_deploy['save'] != 1 && $this->_deploy['download'] != 1) {
         throw new Exception('Nothing to do. Please specify download&&|save options');
     }
     if (empty($this->_deploy['name'])) {
         $this->_deploy['name'] = date('H_m_d_H_i_s');
     }
     if (substr($this->_deploy['name'], -4) == '.xls') {
         $this->_deploy['name'] = substr($this->_deploy['name'], 0, -4);
     }
     if (!isset($this->_deploy['noPagination'])) {
         $this->_deploy['noPagination'] = 0;
     }
     $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/';
     if (!isset($this->_deploy['dir']) || !is_dir($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not a dir');
     }
     if (!is_writable($this->_deploy['dir'])) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not writable');
     }
     $larg = self::calculateCellSize();
     $lengthTotal = array_sum($larg);
     $cellFontSize = 8;
     //set font
     $titulos = parent::_buildTitles();
     $sql = parent::_buildSqlExp();
     $grid = parent::_BuildGrid();
     if (!$this->getInfo('hRow,field')) {
         $this->_info['hRow']['field'] = '';
     }
     if (strtoupper($this->_deploy['orientation']) == 'LANDSCAPE' && strtoupper($this->_deploy['size']) == 'A4') {
         $totalPaginas = ceil(count($grid) / 26);
     } elseif (strtoupper($this->_deploy['orientation']) == 'LANDSCAPE' && strtoupper($this->_deploy['size']) == 'LETTER') {
         $totalPaginas = ceil(count($grid) / 27);
     } else {
         $totalPaginas = ceil(count($grid) / 37);
     }
     if ($totalPaginas < 1) {
         $totalPaginas = 1;
     }
     $pdf = new Zend_Pdf();
     // Create new Style
     $style = new Zend_Pdf_Style();
     $style->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['lines']));
     $topo = new Zend_Pdf_Style();
     $topo->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['header']));
     $td = new Zend_Pdf_Style();
     $td->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['row2']));
     $styleFilters = new Zend_Pdf_Style();
     $styleFilters->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['filters']));
     $styleFiltersBox = new Zend_Pdf_Style();
     $styleFiltersBox->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['filtersBox']));
     $td2 = new Zend_Pdf_Style();
     $td2->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['row1']));
     $hRowStyle = new Zend_Pdf_Style();
     $hRowStyle->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['hrow']));
     $styleSql = new Zend_Pdf_Style();
     $styleSql->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['sqlexp']));
     $styleText = new Zend_Pdf_Style();
     $styleText->setFillColor(new Zend_Pdf_Color_Html($this->_deploy['colors']['text']));
     // Add new page to the document
     if (strtoupper($this->_deploy['size'] = 'LETTER') && strtoupper($this->_deploy['orientation']) == 'LANDSCAPE') {
         $page = $pdf->newPage(Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE);
     } elseif (strtoupper($this->_deploy['size'] = 'LETTER') && strtoupper($this->_deploy['orientation']) != 'LANDSCAPE') {
         $page = $pdf->newPage(Zend_Pdf_Page::SIZE_LETTER);
     } elseif (strtoupper($this->_deploy['size'] != 'A4') && strtoupper($this->_deploy['orientation']) == 'LANDSCAPE') {
         $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE);
     } else {
         $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
     }
     $page->setStyle($style);
     $pdf->pages[] = $page;
     $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
     $page->setFont($font, 14);
     //$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
     if (file_exists($this->_deploy['logo'])) {
         $image = Zend_Pdf_Image::imageWithPath($this->_deploy['logo']);
         list($width, $height, $type, $attr) = getimagesize($this->_deploy['logo']);
         $page->drawImage($image, 40, $page->getHeight() - $height - 40, 40 + $width, $page->getHeight() - 40);
     }
     $page->drawText($this->__($this->_deploy['title']), $width + 70, $page->getHeight() - 70, $this->getCharEncoding());
     $page->setFont($font, $cellFontSize);
     $page->drawText($this->__($this->_deploy['subtitle']), $width + 70, $page->getHeight() - 80, $this->getCharEncoding());
     //Iniciar a contagem de páginas
     $pagina = 1;
     $page->drawText($this->_deploy['footer'], 40, 40, $this->getCharEncoding());
     if (@$this->_deploy['noPagination'] != 1) {
         $page->drawText($this->__($this->_deploy['page']) . ' ' . $pagina . '/' . $totalPaginas, $page->getWidth() - strlen($this->__($this->_deploy['page'])) * $cellFontSize - 50, 40, $this->getCharEncoding());
     }
     $page->setFont($font, $cellFontSize);
     $pl = $page->getWidth() - 80;
     $i = 0;
     foreach ($larg as $final) {
         $cell[$i] = round($final * $pl / $lengthTotal);
         $i++;
     }
     $cellsCount = count($titulos);
     if ($this->getInfo('hRow,title') != '') {
         $cellsCount--;
     }
     $largura = ($page->getWidth() - 80) / $cellsCount;
     $altura = $page->getHeight() - 120;
     $i = 0;
     $page->setFont($font, $cellFontSize + 1);
     foreach ($titulos as $value) {
         if ($value['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
             if ((int) $la == 0) {
                 $largura1 = 40;
             } else {
                 $largura1 = $cell[$i - 1] + $largura1;
             }
             $page->setStyle($topo);
             $page->drawRectangle($largura1, $altura - 4, $largura1 + $cell[$i] + 1, $altura + 12);
             $page->setStyle($styleText);
             $page->drawText($value['value'], $largura1 + 2, $altura, $this->getCharEncoding());
             $la = $largura1;
             $i++;
         }
     }
     $page->setFont($font, $cellFontSize);
     $page->setStyle($style);
     if (is_array($grid)) {
         if ($this->getInfo('hRow,title') != '') {
             $bar = $grid;
             $hbar = trim($this->getInfo('hRow,field'));
             $p = 0;
             foreach ($grid[0] as $value) {
                 if ($value['field'] == $hbar) {
                     $hRowIndex = $p;
                 }
                 $p++;
             }
             $aa = 0;
         }
         $ia = 0;
         $aa = 0;
         foreach ($grid as $value) {
             if ($altura <= 80) {
                 // Add new page to the document
                 if (strtoupper($this->_deploy['size'] = 'LETTER') && strtoupper($this->_deploy['orientation']) == 'LANDSCAPE') {
                     $page = $pdf->newPage(Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE);
                 } elseif (strtoupper($this->_deploy['size'] = 'LETTER') && strtoupper($this->_deploy['orientation']) != 'LANDSCAPE') {
                     $page = $pdf->newPage(Zend_Pdf_Page::SIZE_LETTER);
                 } elseif (strtoupper($this->_deploy['size'] != 'A4') && strtoupper($this->_deploy['orientation']) == 'LANDSCAPE') {
                     $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE);
                 } else {
                     $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
                 }
                 $page->setStyle($style);
                 $pdf->pages[] = $page;
                 $pagina++;
                 $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
                 $page->setFont($font, 14);
                 //$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
                 if (file_exists($this->_deploy['logo'])) {
                     $image = Zend_Pdf_Image::imageWithPath($this->_deploy['logo']);
                     list($width, $height, $type, $attr) = getimagesize($this->_deploy['logo']);
                     $page->drawImage($image, 40, $page->getHeight() - $height - 40, 40 + $width, $page->getHeight() - 40);
                 }
                 $page->drawText($this->__($this->_deploy['title']), $width + 70, $page->getHeight() - 70, $this->getCharEncoding());
                 $page->setFont($font, $cellFontSize);
                 $page->drawText($this->__($this->_deploy['subtitle']), $width + 70, $page->getHeight() - 80, $this->getCharEncoding());
                 //set font
                 $altura = $page->getHeight() - 120;
                 $page->drawText($this->__($this->_deploy['footer']), 40, 40, $this->getCharEncoding());
                 if ($this->_deploy['noPagination'] != 1) {
                     $page->drawText($this->__($this->_deploy['page']) . ' ' . $pagina . '/' . $totalPaginas, $page->getWidth() - strlen($this->__($this->_deploy['page'])) * $cellFontSize - 50, 40, $this->getCharEncoding());
                 }
                 //
                 reset($titulos);
                 $i = 0;
                 $largura1 = 40;
                 $page->setFont($font, $cellFontSize + 1);
                 foreach ($titulos as $title) {
                     if ($title['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
                         if ((int) $la == 0) {
                             $largura1 = 40;
                         } else {
                             $largura1 = $cell[$i - 1] + $largura1;
                         }
                         $page->setStyle($topo);
                         $page->drawRectangle($largura1, $altura - 4, $largura1 + $cell[$i] + 1, $altura + 12);
                         $page->setStyle($style);
                         $page->drawText($title['value'], $largura1 + 2, $altura, $this->getCharEncoding());
                         $la = $largura1;
                         $i++;
                     }
                 }
                 $page->setFont($font, $cellFontSize);
             }
             $la = 0;
             $altura = $altura - 16;
             $i = 0;
             $tdf = $ia % 2 ? $td : $td2;
             $a = 1;
             //A linha horizontal
             if ($this->getInfo('hRow,title') != '') {
                 if ($bar[$aa][$hRowIndex]['value'] != $bar[$aa - 1][$hRowIndex]['value']) {
                     $centrar = $page->getWidth() - 80;
                     $centrar = round($centrar / 2) + 30;
                     if ((int) $la == 0) {
                         $largura1 = 40;
                     } else {
                         $largura1 = $cell[$i - 1] + $largura1;
                     }
                     $page->setStyle($hRowStyle);
                     $page->drawRectangle($largura1, $altura - 4, $page->getWidth() - 40, $altura + 12);
                     $page->setStyle($styleText);
                     $page->drawText($bar[$aa][$hRowIndex]['value'], $centrar, $altura, $this->getCharEncoding());
                     $la = 0;
                     $altura = $altura - 16;
                 }
             }
             ////////////
             //Vamos saber qauntas linhas tem este registo
             $nlines = array();
             $nl = 0;
             foreach ($value as $lines) {
                 $line = $this->widthForStringUsingFontSize(strip_tags(trim($lines['value'])), $font, 8);
                 $nlines[] = ceil($line / $cell[$nl]);
                 $nl++;
             }
             sort($nlines);
             $totalLines = end($nlines);
             $nl = 0;
             foreach ($value as $value1) {
                 $value1['value'] = strip_tags(trim($value1['value']));
                 if ($value1['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
                     if ((int) $la == 0) {
                         $largura1 = 40;
                     } else {
                         $largura1 = $cell[$i - 1] + $largura1;
                     }
                     $page->setStyle($tdf);
                     $page->drawRectangle($largura1, $altura - 4, $largura1 + $cell[$i] + 1, $altura + 12);
                     $page->setStyle($styleText);
                     $page->drawText($value1['value'], $largura1 + 2, $altura, $this->getCharEncoding());
                     $la = $largura1;
                     $i++;
                     $nl++;
                 }
                 $a++;
             }
             $aa++;
             $ia++;
         }
     }
     $la = 0;
     $altura = $altura - 16;
     $i = 0;
     if (is_array($sql)) {
         foreach ($sql as $value) {
             if ((int) $la == 0) {
                 $largura1 = 40;
             } else {
                 $largura1 = $cell[$i - 1] + $largura1;
             }
             $page->setStyle($styleSql);
             $page->drawRectangle($largura1, $altura - 4, $largura1 + $cell[$i], $altura + 12);
             $page->setStyle($styleText);
             $page->drawText($value['value'], $largura1 + 2, $altura, $this->getCharEncoding());
             $la = $largura1;
             $la = $largura1;
             $i++;
         }
     }
     $la = 0;
     $altura = $altura - 16;
     $i = 0;
     if (is_array($this->_showFiltersInExport) || $this->_showFiltersInExport == true) {
         if (is_array($this->_showFiltersInExport) && is_array($this->_filtersValues)) {
             $this->_showFiltersInExport = array_merge($this->_showFiltersInExport, $this->_filtersValues);
         } elseif (is_array($this->_showFiltersInExport)) {
             $this->_showFiltersInExport = $this->_showFiltersInExport;
         } elseif (is_array($this->_filtersValues)) {
             $this->_showFiltersInExport = $this->_filtersValues;
         }
         if (count($this->_showFiltersInExport) > 0) {
             $page->setStyle($styleFilters);
             $page->drawRectangle(40, $altura - 4, array_sum($cell) + 41, $altura + 12);
             $page->setStyle($styleText);
             $tLarg = $this->widthForStringUsingFontSize($this->__('Filtered by:'), $font);
             $i = 0;
             $page->setStyle($styleFiltersBox);
             $page->drawRectangle(40, $altura - 4, $tLarg + 50, $altura + 12);
             $page->setStyle($styleText);
             $text = '     ' . $this->__('Filtered by:') . '     ';
             foreach ($this->_showFiltersInExport as $key => $value) {
                 if ($keyHelper = $this->getField($key)) {
                     $key = $keyHelper['title'];
                 }
                 if (is_array($value)) {
                     foreach ($value as $newName => $newValue) {
                         $text .= $this->__($key) . ' - ' . $this->__(ucfirst($newName)) . ': ' . $this->__($newValue) . '    |    ';
                     }
                 } else {
                     $text .= $this->__($key) . ': ' . $this->__($value) . '    |    ';
                 }
                 $i++;
             }
             $page->drawText($text, $tLarg + 3, $altura, $this->getCharEncoding());
         }
     }
     $pdf->save($this->_deploy['dir'] . $this->_deploy['name'] . '.pdf');
     if ($this->_deploy['download'] == 1) {
         header('Content-type: application/pdf');
         header('Content-Disposition: attachment; filename="' . $this->_deploy['name'] . '.pdf"');
         readfile($this->_deploy['dir'] . $this->_deploy['name'] . '.pdf');
     }
     if ($this->_deploy['save'] != 1) {
         unlink($this->_deploy['dir'] . $this->_deploy['name'] . '.pdf');
     }
     die;
 }
コード例 #20
0
ファイル: Excel.php プロジェクト: robjacoby/xlr8u
    /**
     * Deploys
     *
     * @return void
     * @see library/Bvb/Bvb_Grid::deploy()
     */
    public function deploy()
    {
        $this->setRecordsPerPage(0);
        parent::deploy();
        if (!isset($this->options['title'])) {
            $this->options['title'] = 'ZFDatagrid';
        }
        $titles = parent::_buildTitles();
        $wsData = parent::_buildGrid();
        $sql = parent::_buildSqlExp();
        if (is_array($wsData) && count($wsData) > 65569) {
            throw new Bvb_Grid_Exception('Maximum number of records allowed is 65569');
        }
        $xml = '<?xml version="1.0"?><?mso-application progid="Excel.Sheet"?>
<Workbook xmlns:x="urn:schemas-microsoft-com:office:excel"
  xmlns="urn:schemas-microsoft-com:office:spreadsheet"
  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">';
        $xml .= '<Worksheet ss:Name="' . $this->options['title'] . '" ss:Description="' . $this->options['title'] . '"><ss:Table>';
        $xml .= '<ss:Row>';
        foreach ($titles as $value) {
            $type = !is_numeric($value['value']) ? 'String' : 'Number';
            $xml .= '<ss:Cell><Data ss:Type="' . $type . '">' . $value['value'] . '</Data></ss:Cell>';
        }
        $xml .= '</ss:Row>';
        if (is_array($wsData)) {
            foreach ($wsData as $row) {
                $xml .= '<ss:Row>';
                $a = 1;
                foreach ($row as $value) {
                    $value['value'] = strip_tags($value['value']);
                    $type = !is_numeric($value['value']) ? 'String' : 'Number';
                    $xml .= '<ss:Cell><Data ss:Type="' . $type . '">' . $value['value'] . '</Data></ss:Cell>';
                    $a++;
                }
                $xml .= '</ss:Row>';
            }
        }
        if (is_array($sql)) {
            $xml .= '<ss:Row>';
            foreach ($sql as $value) {
                $type = !is_numeric($value['value']) ? 'String' : 'Number';
                $xml .= '<ss:Cell><Data ss:Type="' . $type . '">' . $value['value'] . '</Data></ss:Cell>';
            }
            $xml .= '</ss:Row>';
        }
        $xml .= '</ss:Table></Worksheet>';
        $xml .= '</Workbook>';
        if (!isset($this->_deploy['save'])) {
            $this->_deploy['save'] = false;
        }
        if (!isset($this->_deploy['download'])) {
            $this->_deploy['download'] = false;
        }
        if ($this->_deploy['save'] != 1 && $this->_deploy['download'] != 1) {
            throw new Exception('Nothing to do. Please specify download&&|save options');
        }
        if (empty($this->_deploy['name'])) {
            $this->_deploy['name'] = date('H_m_d_H_i_s');
        }
        if (substr($this->_deploy['name'], -4) == '.xls') {
            $this->_deploy['name'] = substr($this->_deploy['name'], 0, -4);
        }
        $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/';
        if (!is_dir($this->_deploy['dir']) && $this->_deploy['save'] == 1) {
            throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not a dir');
        }
        if (!is_writable($this->_deploy['dir']) && $this->_deploy['save'] == 1) {
            throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not writable');
        }
        if ($this->_deploy['save'] == 1) {
            file_put_contents($this->_deploy['dir'] . $this->_deploy['name'] . ".xls", $xml);
        }
        if ($this->_deploy['download'] == 1) {
            header('Content-type: application/excel');
            header('Content-Disposition: attachment; filename="' . $this->_deploy['name'] . '.xls"');
            echo $xml;
        }
        die;
    }
コード例 #21
0
ファイル: model.php プロジェクト: tapiau/muyo
 /**
  * TODO: move to external class / trait
  * @param string $export Name of deploy
  * @param null|mixed $source
  * @return Bvb_Grid
  */
 public function getDataTable($export = 'JqGrid', $source = null)
 {
     if (is_null($source)) {
         $source = new Lib_Grid_Source_Model($this);
     }
     $config = $this->getGridConfig();
     $id = Lib_Grid::buildId($export, $source, isset($config->bvbParams->id_prefix) ? $config->bvbParams->id_prefix : null);
     $requestParams = Zend_Controller_Front::getInstance()->getRequest()->getParams();
     if (isset($requestParams['q']) && $requestParams['q'] == $id && isset($requestParams['_exportTo'])) {
         $requestParams['_exportTo' . $id] = $requestParams['_exportTo'];
     }
     /**
      * @var Bvb_Grid $grid
      */
     $grid = Bvb_Grid::factory($export, $config, $id, array(), $requestParams);
     if ($export == 'JqGrid') {
         Lib_Grid::prepareDeploy($grid, $config, $source);
     } elseif ($export == 'Pdf') {
         $config->export->pdf = 'Pdf';
         $config->disableExport = false;
         Lib_Grid::prepareDeploy($grid, $config, $source);
     }
     return $grid;
 }
コード例 #22
0
ファイル: Csv.php プロジェクト: ocpyosep78/Booking
 /**
  * Deploy method
  *
  * @return boolean FALSE if error
  */
 public function deploy()
 {
     // prepare data
     $this->_prepareOptions();
     parent::deploy();
     if ($this->getDeployOption('download')) {
         // send first headers
         ob_end_clean();
         header('Content-Description: File Transfer');
         header('Cache-Control: public, must-revalidate, max-age=0');
         // HTTP/1.1
         header('Pragma: public');
         header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
         // Date in the past
         header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
         header("Content-Type: application/csv");
         header('Content-Disposition: attachment; filename="' . $this->getFileName() . '"');
         header('Content-Transfer-Encoding: binary');
     }
     if ($this->getDeployOption('store')) {
         // open file handler
         $this->_outFile = fopen($this->_deploy['dir'] . $this->getFileName(), "w");
     }
     // export header
     if (!$this->getDeployOption('skipHeaders')) {
         $this->csvAddData($this->buildTitles());
     }
     $i = 0;
     do {
         $i += $this->_recordsPerPage;
         $this->csvAddData($this->buildGrid());
         $this->csvAddData($this->buildSqlexp());
         // get next page
         $this->getSource()->buildQueryLimit($this->_recordsPerPage, $i);
         $this->_result = $this->getSource()->execute();
     } while (count($this->_result));
     if ($this->getDeployOption('store')) {
         // close file handler
         fclose($this->_outFile);
     }
     if ($this->getDeployOption('download')) {
         // we set special headers and uploaded data, there is nothing more we could do
         die;
     }
     return true;
 }
コード例 #23
0
ファイル: Word.php プロジェクト: Aeryris/grid
 public function deploy()
 {
     $this->checkExportRights();
     $this->setRecordsPerPage(0);
     parent::deploy();
     if (!$this->_temp['word'] instanceof Bvb_Grid_Template_Word) {
         $this->setTemplate('word', 'word');
     }
     $titles = parent::_buildTitles();
     $wsData = parent::_buildGrid();
     $sql = parent::_buildSqlExp();
     $xml = $this->_temp['word']->globalStart();
     $xml .= $this->_temp['word']->titlesStart();
     foreach ($titles as $value) {
         if ($value['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
             $xml .= str_replace("{{value}}", $value['value'], $this->_temp['word']->titlesLoop());
         }
     }
     $xml .= $this->_temp['word']->titlesEnd();
     if (is_array($wsData)) {
         if ($this->getInfo('hRow,title') != '') {
             $bar = $wsData;
             $hbar = trim($this->getInfo('hRow,title'));
             $p = 0;
             foreach ($wsData[0] as $value) {
                 if ($value['field'] == $hbar) {
                     $hRowIndex = $p;
                 }
                 $p++;
             }
             $aa = 0;
         }
         $i = 1;
         $aa = 0;
         foreach ($wsData as $row) {
             //A linha horizontal
             if ($this->getInfo('hRow,title') != '') {
                 if (!isset($bar[$aa - 1][$hRowIndex])) {
                     $bar[$aa - 1][$hRowIndex]['value'] = '';
                 }
                 if ($bar[$aa][$hRowIndex]['value'] != $bar[$aa - 1][$hRowIndex]['value']) {
                     $xml .= str_replace("{{value}}", $bar[$aa][$hRowIndex]['value'], $this->_temp['word']->hRow());
                 }
             }
             $xml .= $this->_temp['word']->loopStart();
             $a = 1;
             foreach ($row as $value) {
                 $value['value'] = strip_tags($value['value']);
                 if (@$value['field'] != $this->getInfo('hRow,field') && $this->getInfo('hRow,title') != '' || $this->getInfo('hRow,title') == '') {
                     $xml .= str_replace("{{value}}", $value['value'], $this->_temp['word']->loopLoop(2));
                 }
                 $a++;
             }
             $xml .= $this->_temp['word']->loopEnd();
             $aa++;
             $i++;
         }
     }
     if (is_array($sql)) {
         $xml .= $this->_temp['word']->sqlExpStart();
         foreach ($sql as $value) {
             $xml .= str_replace("{{value}}", $value['value'], $this->_temp['word']->sqlExpLoop());
         }
         $xml .= $this->_temp['word']->sqlExpEnd();
     }
     $xml .= $this->_temp['word']->globalEnd();
     if (!isset($this->_deploy['save'])) {
         $this->_deploy['save'] = false;
     }
     if (!isset($this->_deploy['download'])) {
         $this->_deploy['download'] = false;
     }
     if ($this->_deploy['save'] != 1 && $this->_deploy['download'] != 1) {
         throw new Exception('Nothing to do. Please specify download&&|save options');
     }
     if (empty($this->_deploy['name'])) {
         $this->_deploy['name'] = date('H_m_d_H_i_s');
     }
     if (substr($this->_deploy['name'], -4) == '.doc') {
         $this->_deploy['name'] = substr($this->_deploy['name'], 0, -4);
     }
     $this->_deploy['dir'] = rtrim($this->_deploy['dir'], '/') . '/';
     if (!is_dir($this->_deploy['dir']) && $this->_deploy['save'] == 1) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not a dir');
     }
     if (!is_writable($this->_deploy['dir']) && $this->_deploy['save'] == 1) {
         throw new Bvb_Grid_Exception($this->_deploy['dir'] . ' is not writable');
     }
     if ($this->_deploy['save'] == 1) {
         file_put_contents($this->_deploy['dir'] . $this->_deploy['name'] . ".doc", $xml);
     }
     if ($this->_deploy['download'] == 1) {
         header('Content-type: application/word');
         header('Content-Disposition: attachment; filename="' . $this->_deploy['name'] . '.doc"');
         echo $xml;
     }
     die;
 }