Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Rctnet committed Mar 3, 2020
1 parent 7441413 commit c163779
Showing 1 changed file with 56 additions and 60 deletions.
116 changes: 56 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,64 +110,61 @@ See more blog, forum and coming soon report template store in https://jasperphp.
# Generic sample
```php
<?php

use JasperPHP\Report;
use JasperPHP\ado\TTransaction;
use JasperPHP\ado\TLogger;
use JasperPHP\ado\TLoggerHTML;

//use PHPexcel as PHPexcel;
//use \NumberFormatter;
//use PHPexcel as PHPexcel; // experimental
/**
* classe TJasper
*
* @author Rogerio Muniz de Castro <rogerio@quilhasoft.net>
* @version 2015.03.11
* @access restrict
*
* 2015.03.11 -- create
**/
class TJasper
{
* classe TJasper
*
* @author Rogerio Muniz de Castro <rogerio@quilhasoft.com.br>
* @version 2018.10.15
* @access restrict
*
* 2015.03.11 -- create
* 2018.10.15 -- revision and internationalize, add TLogger classes
* */
class TJasper {

private $report;
private $type;
private $param;

/**
* method __construct()
*
* @param $jrxml = a source xmlr filename
* @param $param = a array whith params
*/
public function __construct($jrxml,array $param)
{
$xmlFile= $jrxml;
$this->type = (array_key_exists('type',$param))?$param['type']:'pdf';
error_reporting(0);
switch ($this->type)
{
case 'pdf':
$this->report =new JasperPHP\Report($xmlFile,$param);
JasperPHP\Pdf::prepare($this->report);
* method __construct()
*
* @param $jrxml = a jrxml file name
* @param $param = a array with params to use into jrxml report
*/
public function __construct($jrxml, array $param) {
$GLOBALS['reports'] = array();
$xmlFile = $jrxml;
$this->type = (array_key_exists('type', $param)) ? $param['type'] : 'pdf';
//error_reporting(0);
$this->param = $param;
$this->report = new JasperPHP\Report($xmlFile, $param); // $GLOBALS['reports'][$xmlFile];
switch ($this->type) {
case 'pdf':
JasperPHP\Instructions::prepare($this->report);
break;
case 'xls':
JasperPHP\Excel::prepare();
$this->report =new JasperPHP\Report2XLS($xmlFile,$param);

JasperPHP\Instructions::setProcessor('\JasperPHP\XlsProcessor');
JasperPHP\Instructions::prepare($this->report);
break;
}
}

/**
* method outpage()
*
* @param $type = a type of output. ALERT: xls is experimental
*/

public function outpage($type='pdf'){
public function outpage($type = 'pdf') {
$this->report->generate();
$this->report->out();
switch ($this->type)
{
switch ($this->type) {
case 'pdf':
$pdf = JasperPHP\Pdf::get();
$pdf->Output('Relatorio.pdf',"I");
$pdf = JasperPHP\Instructions::get();
$pdf->Output('report.pdf', "I");
break;
case 'xls':
header('Content-Type: application/vnd.ms-excel');
Expand All @@ -176,33 +173,32 @@ class TJasper
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
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'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0
$objWriter = PHPExcel_IOFactory::createWriter($this->report->wb, 'Excel5');
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'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
$objWriter = PHPExcel_IOFactory::createWriter(JasperPHP\Instructions::$objOutPut, 'Excel5');
$objWriter->save('php://output');
break;
break;
}

}
/**
* method setVariable()
* insert variable into report after output
*
* @param $name = name of variable
* @param $value = value of variable
*/
public function setVariable($name,$value){
$this->report->arrayVariable[$name]['initialValue'] = $value ;

public function setVariable($name, $value) {
$this->report->arrayVariable[$name]['initialValue'] = $value;
}

}
require('autoloader.php') ;
require('../../tecnickcom/tcpdf/tcpdf.php'); // point to tcpdf class previosly instaled ,
// on composer instalation is not necessaty

require('autoloader.php');
require('../../tecnickcom/tcpdf/tcpdf.php'); // point to tcpdf class previosly instaled , (probaly in composer instalations)
require('../../phpoffice/phpexcel/Classes/PHPExcel.php'); // point to tcpdf class previosly instaled , (probaly in composer instalations)
//require('../TCPDF/tcpdf.php'); // point to tcpdf class previosly instaled , (probaly in stand alone instalations)
// on production using composer instalation is not necessaty

$report_name = isset($_GET['report']) ? $_GET['report'] : 'testReport.jrxml'; // sql into testReport.txt report do not select any table.
TTransaction::open('dev');
$jasper = new TJasper('template.jrxml',$_GET);
TTransaction::setLogger(new TLoggerHTML('log.html'));
$jasper = new TJasper($report_name, $_GET);
$jasper->outpage();
?>

Expand Down

0 comments on commit c163779

Please sign in to comment.