/TEMPLATE/Reports/class/PHPJasperXML.inc.php
PHP | 3829 lines | 2955 code | 399 blank | 475 comment | 198 complexity | 3e2ded497e7c7e38aac9c7aac9fce426 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
- //version 0.8c
- class PHPJasperXML {
- private $adjust=1.2;
- public $version=0.8;
- private $pdflib;
- private $lang;
- private $previousarraydata;
- public $debugsql=false;
- private $myconn;
- private $con;
- public $group_name;
- public $newPageGroup = false;
- private $curgroup=0;
- private $groupno=0;
- private $footershowed=true;
- private $titleheight=0;
- private $report_count=1; //### New declaration (variable exists in original too)
- private $group_count = array(); //### New declaration
- public function PHPJasperXML($lang="en",$pdflib="TCPDF") {
- $this->lang=$lang;
- error_reporting(0);
- $this->pdflib=$pdflib;
- }
- public function connect($db_host,$db_user,$db_pass,$db_or_dsn_name,$cndriver="mysql") {
- $this->db_host=$db_host;
- $this->db_user=$db_user;
- $this->db_pass=$db_pass;
- $this->db_or_dsn_name=$db_or_dsn_name;
- $this->cndriver=$cndriver;
- if($cndriver=="mysql") {
- if(!$this->con) {
- $this->myconn = @mysql_connect($db_host,$db_user,$db_pass);
- if($this->myconn) {
- $seldb = @mysql_select_db($db_or_dsn_name,$this->myconn);
- if($seldb) {
- $this->con = true;
- return true;
- }
- else {
- return false;
- }
- } else {
- return false;
- }
- } else {
- return true;
- }
- return true;
- }elseif($cndriver=="psql") {
- global $pgport;
- if($pgport=="" || $pgport==0)
- $pgport=5432;
- $conn_string = "host=$db_host port=$pgport dbname=$db_or_dsn_name user=$db_user password=$db_pass";
- $this->myconn = pg_connect($conn_string);
- if($this->myconn) {
- $this->con = true;
- return true;
- }else
- return false;
- }
- else {
- if(!$this->con) {
- $this->myconn = odbc_connect($db_or_dsn_name,$db_user,$db_pass);
- if( $this->myconn) {
- $this->con = true;
- return true;
- } else {
- return false;
- }
- } else {
- return true;
- }
- }
- }
- public function disconnect($cndriver="mysql") {
- if($cndriver=="mysql") {
- if($this->con) {
- if(@mysql_close()) {
- $this->con = false;
- return true;
- }
- else {
- return false;
- }
- }
- }elseif($cndriver=="psql") {
- $this->con = false;
- pg_close($this->myconn);
- }
- else {
- $this->con = false;
- odbc_close( $this->myconn);
- }
- }
- public function xml_dismantle($xml) {
- $this->page_setting($xml);
- foreach ($xml as $k=>$out) {
- switch($k) {
- case "parameter":
- $this->parameter_handler($out);
- break;
- case "queryString":
- $this->queryString_handler($out);
- break;
- case "field":
- $this->field_handler($out);
- break;
- case "variable":
- $this->variable_handler($out);
- break;
- case "group":
- $this->group_handler($out);
- break;
- case "subDataset":
- $this->subDataset_handler($out);
- break;
- case "background":
- $this->pointer=&$this->arraybackground;
- $this->pointer[]=array("height"=>$out->band["height"],"splitType"=>$out->band["splitType"]);
- foreach ($out as $bg) {
- $this->default_handler($bg);
- }
- break;
- default:
- foreach ($out as $object) {
- eval("\$this->pointer=&"."\$this->array$k".";");
- $this->arrayband[]=array("name"=>$k);
- if($k=='detail')
- $this->detailbandheight=$object["height"]+0;
- elseif($k=='pageHeader')
- $this->headerbandheight=$object["height"]+0;
- elseif($k=='pageFooter')
- $this->footerbandheight=$object["height"]+0;
- elseif($k=='lastPageFooter')
- $this->lastfooterbandheight=$object["height"]+0;
- elseif($k=='summary')
- $this->summarybandheight=$object["height"]+0;
-
- $this->pointer[]=array("type"=>"band","height"=>$object["height"],"splitType"=>$object["splitType"],"y_axis"=>$this->y_axis);
- $this->default_handler($object);
- }
- $this->y_axis=$this->y_axis+$out->band["height"]; //after handle , then adjust y axis
- break;
- }
- }
- }
- public function subDataset_handler($data){
- $this->subdataset[$data['name'].'']= $data->queryString;
- }
- //read level 0,Jasperreport page setting
- public function page_setting($xml_path) {
- $this->arrayPageSetting["orientation"]="P";
- $this->arrayPageSetting["name"]=$xml_path["name"];
- $this->arrayPageSetting["language"]=$xml_path["language"];
- $this->arrayPageSetting["pageWidth"]=$xml_path["pageWidth"];
- $this->arrayPageSetting["pageHeight"]=$xml_path["pageHeight"];
- if(isset($xml_path["orientation"])) {
- $this->arrayPageSetting["orientation"]=substr($xml_path["orientation"],0,1);
- }
- $this->arrayPageSetting["columnWidth"]=$xml_path["columnWidth"];
- $this->arrayPageSetting["leftMargin"]=$xml_path["leftMargin"];
- $this->arrayPageSetting["rightMargin"]=$xml_path["rightMargin"];
- $this->arrayPageSetting["topMargin"]=$xml_path["topMargin"];
- $this->y_axis=$xml_path["topMargin"];
- $this->arrayPageSetting["bottomMargin"]=$xml_path["bottomMargin"];
- }
- public function parameter_handler($xml_path) {
- // $defaultValueExpression=str_replace('"','',$xml_path->defaultValueExpression);
- // if($defaultValueExpression!='')
- // $this->arrayParameter[$xml_path["name"].'']=$defaultValueExpression;
- // else
- $this->arrayParameter[$xml_path["name"].''];
- }
- public function queryString_handler($xml_path) {
- $this->sql =$xml_path;
- if(isset($this->arrayParameter)) {
- foreach($this->arrayParameter as $v => $a) {
- $this->sql = str_replace('$P{'.$v.'}', $a, $this->sql);
- }
- }
- }
- public function field_handler($xml_path) {
- $this->arrayfield[]=$xml_path["name"];
- }
- public function variable_handler($xml_path) {
- $this->arrayVariable["$xml_path[name]"]=array("calculation"=>$xml_path["calculation"],"target"=>substr($xml_path->variableExpression,3,-1),"class"=>$xml_path["class"] , "resetType"=>$xml_path["resetType"]);
- }
- public function group_handler($xml_path) {
- // $this->arraygroup=$xml_path;
- if($xml_path["isStartNewPage"]=="true")
- $this->newPageGroup=true;
- else
- $this->newPageGroup="";
- foreach($xml_path as $tag=>$out) {
- switch ($tag) {
- case "groupHeader":
- $this->pointer=&$this->arraygroup[$xml_path["name"]]["groupHeader"];
- $this->pointer=&$this->arraygrouphead;
- $this->arraygroupheadheight=$out->band["height"];
- $this->arrayband[]=array("name"=>"group", "gname"=>$xml_path["name"],"isStartNewPage"=>$xml_path["isStartNewPage"],"groupExpression"=>substr($xml_path->groupExpression,3,-1));
- $this->pointer[]=array("type"=>"band","height"=>$out->band["height"]+0,"y_axis"=>"","groupExpression"=>substr($xml_path->groupExpression,3,-1));
- //### Modification for group count
- $gnam=$xml_path["name"];
- $this->gnam=$xml_path["name"];
- $this->group_count["$gnam"]=1; // Count rows of groups, we're on the first row of the group.
- //### End of modification
- foreach($out as $band) {
- $this->default_handler($band);
- }
- $this->y_axis=$this->y_axis+$out->band["height"]; //after handle , then adjust y axis
- break;
- case "groupFooter":
- $this->pointer=&$this->arraygroup[$xml_path["name"]]["groupFooter"];
- $this->pointer=&$this->arraygroupfoot;
- $this->arraygroupfootheight=$out->band["height"];
- $this->pointer[]=array("type"=>"band","height"=>$out->band["height"]+0,"y_axis"=>"","groupExpression"=>substr($xml_path->groupExpression,3,-1));
- foreach($out as $b=>$band) {
- $this->default_handler($band);
- }
- break;
- default:
- break;
- }
- }
- }
- public function default_handler($xml_path) {
- foreach($xml_path as $k=>$out) {
- switch($k) {
- case "staticText":
- $this->element_staticText($out);
- break;
- case "image":
- $this->element_image($out);
- break;
- case "line":
- $this->element_line($out);
- break;
- case "rectangle":
- $this->element_rectangle($out);
- break;
- case "ellipse":
- $this->element_ellipse($out);
- break;
- case "textField":
- $this->element_textField($out);
- break;
- // case "stackedBarChart":
- // $this->element_barChart($out,'StackedBarChart');
- // break;
- // case "barChart":
- // $this->element_barChart($out,'BarChart');
- // break;
- // case "pieChart":
- // $this->element_pieChart($out);
- // break;
- // case "pie3DChart":
- // $this->element_pie3DChart($out);
- // break;
- // case "lineChart":
- // $this->element_lineChart($out);
- // break;
- // case "stackedAreaChart":
- // $this->element_areaChart($out,'stackedAreaChart');
- // break;
- case "stackedBarChart":
- $this->element_Chart($out,'stackedBarChart');
- break;
- case "barChart":
- $this->element_Chart($out,'barChart');
- break;
- case "pieChart":
- $this->element_Chart($out,'pieChart');
- break;
- case "pie3DChart":
- $this->element_pie3DChart($out,'pie3DChart');
- break;
- case "lineChart":
- $this->element_Chart($out,'lineChart');
- break;
- case "stackedAreaChart":
- $this->element_Chart($out,'stackedAreaChart');
- break;
- case "subreport":
- $this->element_subReport($out);
- break;
- default:
- break;
- }
- };
- }
- public function element_staticText($data) {
- $align="L";
- $fill=0;
- $border=0;
- $fontsize=10;
- $font="helvetica";
- $fontstyle="";
- $textcolor = array("r"=>0,"g"=>0,"b"=>0);
- $fillcolor = array("r"=>255,"g"=>255,"b"=>255);
- $txt="";
- $rotation="";
- $drawcolor=array("r"=>0,"g"=>0,"b"=>0);
- $height=$data->reportElement["height"];
- $stretchoverflow="true";
- $printoverflow="false";
- if(isset($data->reportElement["forecolor"])) {
-
- $textcolor = array('forecolor'=>$data->reportElement["forecolor"],"r"=>hexdec(substr($data->reportElement["forecolor"],1,2)),"g"=>hexdec(substr($data->reportElement["forecolor"],3,2)),"b"=>hexdec(substr($data->reportElement["forecolor"],5,2)));
- }
- if(isset($data->reportElement["backcolor"])) {
- $fillcolor = array('backcolor'=>$data->reportElement["backcolor"],"r"=>hexdec(substr($data->reportElement["backcolor"],1,2)),"g"=>hexdec(substr($data->reportElement["backcolor"],3,2)),"b"=>hexdec(substr($data->reportElement["backcolor"],5,2)));
- }
- if($data->reportElement["mode"]=="Opaque") {
- $fill=1;
- }
- if(isset($data["isStretchWithOverflow"])&&$data["isStretchWithOverflow"]=="true") {
- $stretchoverflow="true";
- }
- if(isset($data->reportElement["isPrintWhenDetailOverflows"])&&$data->reportElement["isPrintWhenDetailOverflows"]=="true") {
- $printoverflow="true";
- $stretchoverflow="false";
- }
- if((isset($data->box))&&($data->box->pen["lineWidth"]>0)) {
- $border=1;
- if(isset($data->box->pen["lineColor"])) {
- $drawcolor=array("r"=>hexdec(substr($data->box->pen["lineColor"],1,2)),"g"=>hexdec(substr($data->box->pen["lineColor"],3,2)),"b"=>hexdec(substr($data->box->pen["lineColor"],5,2)));
- }
- }
- if(isset($data->textElement["textAlignment"])) {
- $align=$this->get_first_value($data->textElement["textAlignment"]);
- }
- if(isset($data->textElement["rotation"])) {
- $rotation=$data->textElement["rotation"];
- }
- if(isset($data->textElement->font["pdfFontName"])) {
- $font=$data->textElement->font["pdfFontName"];
- }
- if(isset($data->textElement->font["size"])) {
- $fontsize=$data->textElement->font["size"];
- }
- if(isset($data->textElement->font["isBold"])&&$data->textElement->font["isBold"]=="true") {
- $fontstyle=$fontstyle."B";
- }
- if(isset($data->textElement->font["isItalic"])&&$data->textElement->font["isItalic"]=="true") {
- $fontstyle=$fontstyle."I";
- }
- if(isset($data->textElement->font["isUnderline"])&&$data->textElement->font["isUnderline"]=="true") {
- $fontstyle=$fontstyle."U";
- }
- if(isset($data->reportElement["key"])) {
- $height=$fontsize*$this->adjust;
- }
- $this->pointer[]=array("type"=>"SetXY","x"=>$data->reportElement["x"],"y"=>$data->reportElement["y"],"hidden_type"=>"SetXY");
- $this->pointer[]=array("type"=>"SetTextColor",'forecolor'=>$data->reportElement["forecolor"].'',"r"=>$textcolor["r"],"g"=>$textcolor["g"],"b"=>$textcolor["b"],"hidden_type"=>"textcolor");
- $this->pointer[]=array("type"=>"SetDrawColor","r"=>$drawcolor["r"],"g"=>$drawcolor["g"],"b"=>$drawcolor["b"],"hidden_type"=>"drawcolor");
- $this->pointer[]=array("type"=>"SetFillColor",'backcolor'=>$data->reportElement["backcolor"].'',"r"=>$fillcolor["r"],"g"=>$fillcolor["g"],"b"=>$fillcolor["b"],"hidden_type"=>"fillcolor");
- $this->pointer[]=array("type"=>"SetFont","font"=>$font,"fontstyle"=>$fontstyle,"fontsize"=>$fontsize,"hidden_type"=>"font");
- //"height"=>$data->reportElement["height"]
- //### UTF-8 characters, a must for me.
- $txtEnc=utf8_decode($data->text);
- $this->pointer[]=array("type"=>"MultiCell","width"=>$data->reportElement["width"],"height"=>$height,"txt"=>$txtEnc,"border"=>$border,"align"=>$align,"fill"=>$fill,"hidden_type"=>"statictext","soverflow"=>$stretchoverflow,"poverflow"=>$printoverflow,"rotation"=>$rotation);
- //### End of modification, below is the original line
- // $this->pointer[]=array("type"=>"MultiCell","width"=>$data->reportElement["width"],"height"=>$height,"txt"=>$data->text,"border"=>$border,"align"=>$align,"fill"=>$fill,"hidden_type"=>"statictext","soverflow"=>$stretchoverflow,"poverflow"=>$printoverflow,"rotation"=>$rotation);
- }
- public function element_image($data) {
- $imagepath=$data->imageExpression;
- //$imagepath= substr($data->imageExpression, 1, -1);
- //$imagetype= substr($imagepath,-3);
- switch($data[scaleImage]) {
- case "FillFrame":
- $this->pointer[]=array("type"=>"Image","path"=>$imagepath,"x"=>$data->reportElement["x"]+0,"y"=>$data->reportElement["y"]+0,"width"=>$data->reportElement["width"]+0,"height"=>$data->reportElement["height"]+0,"imgtype"=>$imagetype,"link"=>substr($data->hyperlinkReferenceExpression,1,-1),"hidden_type"=>"image");
- break;
- default:
- $this->pointer[]=array("type"=>"Image","path"=>$imagepath,"x"=>$data->reportElement["x"]+0,"y"=>$data->reportElement["y"]+0,"width"=>$data->reportElement["width"]+0,"height"=>$data->reportElement["height"]+0,"imgtype"=>$imagetype,"link"=>substr($data->hyperlinkReferenceExpression,1,-1),"hidden_type"=>"image");
- break;
- }
- }
- public function element_line($data) { //default line width=0.567(no detect line width)
- $drawcolor=array("r"=>0,"g"=>0,"b"=>0);
- $hidden_type="line";
- if(isset($data->reportElement["forecolor"])) {
- $drawcolor=array("r"=>hexdec(substr($data->reportElement["forecolor"],1,2)),"g"=>hexdec(substr($data->reportElement["forecolor"],3,2)),"b"=>hexdec(substr($data->reportElement["forecolor"],5,2)));
- }
- $this->pointer[]=array("type"=>"SetDrawColor","r"=>$drawcolor["r"],"g"=>$drawcolor["g"],"b"=>$drawcolor["b"],"hidden_type"=>"drawcolor");
- if(isset($data->reportElement[positionType])&&$data->reportElement[positionType]=="FixRelativeToBottom") {
- $hidden_type="relativebottomline";
- }
- if($data->reportElement["width"][0]+0 > $data->reportElement["height"][0]+0) //width > height means horizontal line
- {
- $this->pointer[]=array("type"=>"Line", "x1"=>$data->reportElement["x"],"y1"=>$data->reportElement["y"],"x2"=>$data->reportElement["x"]+$data->reportElement["width"],"y2"=>$data->reportElement["y"]+$data->reportElement["height"]-1,"hidden_type"=>$hidden_type);
- }
- elseif($data->reportElement["height"][0]+0>$data->reportElement["width"][0]+0) //vertical line
- {
- $this->pointer[]=array("type"=>"Line", "x1"=>$data->reportElement["x"],"y1"=>$data->reportElement["y"],"x2"=>$data->reportElement["x"]+$data->reportElement["width"]-1,"y2"=>$data->reportElement["y"]+$data->reportElement["height"],"hidden_type"=>$hidden_type);
- }
- $this->pointer[]=array("type"=>"SetDrawColor","r"=>0,"g"=>0,"b"=>0,"hidden_type"=>"drawcolor");
- $this->pointer[]=array("type"=>"SetFillColor","r"=>255,"g"=>255,"b"=>255,"hidden_type"=>"fillcolor");
- }
- public function element_rectangle($data) {
-
- $radius=$data['radius'];
- $drawcolor=array("r"=>0,"g"=>0,"b"=>0);
-
- $fillcolor=array("r"=>255,"g"=>255,"b"=>255);
-
- if(isset($data->reportElement["forecolor"])) {
- $drawcolor=array("r"=>hexdec(substr($data->reportElement["forecolor"],1,2)),"g"=>hexdec(substr($data->reportElement["forecolor"],3,2)),"b"=>hexdec(substr($data->reportElement["forecolor"],5,2)));
- }
-
- if(isset($data->reportElement["backcolor"]) ) {
- $fillcolor=array("r"=>hexdec(substr($data->reportElement["backcolor"],1,2)),"g"=>hexdec(substr($data->reportElement["backcolor"],3,2)),"b"=>hexdec(substr($data->reportElement["backcolor"],5,2)));
- }
- $this->pointer[]=array("type"=>"SetDrawColor","r"=>$drawcolor["r"],"g"=>$drawcolor["g"],"b"=>$drawcolor["b"],"hidden_type"=>"drawcolor");
- $this->pointer[]=array("type"=>"SetFillColor","r"=>$fillcolor["r"],"g"=>$fillcolor["g"],"b"=>$fillcolor["b"],"hidden_type"=>"fillcolor");
-
- if($radius=='')
- $this->pointer[]=array("type"=>"Rect","x"=>$data->reportElement["x"],"y"=>$data->reportElement["y"],"width"=>$data->reportElement["width"],"height"=>$data->reportElement["height"],"hidden_type"=>"rect","drawcolor"=>$drawcolor,"fillcolor"=>$fillcolor,"mode"=>$data->reportElement["mode"]);
- else
- $this->pointer[]=array("type"=>"RoundedRect","x"=>$data->reportElement["x"],"y"=>$data->reportElement["y"],"width"=>$data->reportElement["width"],"height"=>$data->reportElement["height"],"hidden_type"=>"roundedrect","radius"=>$radius,"drawcolor"=>$drawcolor,"fillcolor"=>$fillcolor,"mode"=>$data->reportElement["mode"]);
- $this->pointer[]=array("type"=>"SetDrawColor","r"=>0,"g"=>0,"b"=>0,"hidden_type"=>"drawcolor");
- $this->pointer[]=array("type"=>"SetFillColor","r"=>255,"g"=>255,"b"=>255,"hidden_type"=>"fillcolor");
- }
- public function element_ellipse($data) {
- $drawcolor=array("r"=>0,"g"=>0,"b"=>0);
- $fillcolor=array("r"=>255,"g"=>255,"b"=>255);
- if(isset($data->reportElement["forecolor"])) {
- $drawcolor=array("r"=>hexdec(substr($data->reportElement["forecolor"],1,2)),"g"=>hexdec(substr($data->reportElement["forecolor"],3,2)),"b"=>hexdec(substr($data->reportElement["forecolor"],5,2)));
- }
- if(isset($data->reportElement["backcolor"])) {
- $fillcolor=array("r"=>hexdec(substr($data->reportElement["backcolor"],1,2)),"g"=>hexdec(substr($data->reportElement["backcolor"],3,2)),"b"=>hexdec(substr($data->reportElement["backcolor"],5,2)));
- }
-
- //$color=array("r"=>$drawcolor["r"],"g"=>$drawcolor["g"],"b"=>$drawcolor["b"]);
- $this->pointer[]=array("type"=>"SetFillColor","r"=>$fillcolor["r"],"g"=>$fillcolor["g"],"b"=>$fillcolor["b"],"hidden_type"=>"fillcolor");
- $this->pointer[]=array("type"=>"SetDrawColor","r"=>$drawcolor["r"],"g"=>$drawcolor["g"],"b"=>$drawcolor["b"],"hidden_type"=>"drawcolor");
- $this->pointer[]=array("type"=>"Ellipse","x"=>$data->reportElement["x"],"y"=>$data->reportElement["y"],"width"=>$data->reportElement["width"],"height"=>$data->reportElement["height"],"hidden_type"=>"ellipse","drawcolor"=>$drawcolor,"fillcolor"=>$fillcolor);
- $this->pointer[]=array("type"=>"SetDrawColor","r"=>0,"g"=>0,"b"=>0,"hidden_type"=>"drawcolor");
- $this->pointer[]=array("type"=>"SetFillColor","r"=>255,"g"=>255,"b"=>255,"hidden_type"=>"fillcolor");
- }
-
- public function element_textField($data) {
- $align="L";
- $fill=0;
- $border=0;
- $fontsize=10;
- $font="helvetica";
- $rotation="";
- $fontstyle="";
- $textcolor = array("r"=>0,"g"=>0,"b"=>0);
- $fillcolor = array("r"=>255,"g"=>255,"b"=>255);
- $stretchoverflow="false";
- $printoverflow="false";
- $height=$data->reportElement["height"];
- $drawcolor=array("r"=>0,"g"=>0,"b"=>0);
- if(isset($data->reportElement["forecolor"])) {
- $textcolor = array("r"=>hexdec(substr($data->reportElement["forecolor"],1,2)),"g"=>hexdec(substr($data->reportElement["forecolor"],3,2)),"b"=>hexdec(substr($data->reportElement["forecolor"],5,2)));
- }
- if(isset($data->reportElement["backcolor"])) {
- $fillcolor = array("r"=>hexdec(substr($data->reportElement["backcolor"],1,2)),"g"=>hexdec(substr($data->reportElement["backcolor"],3,2)),"b"=>hexdec(substr($data->reportElement["backcolor"],5,2)));
- }
- if($data->reportElement["mode"]=="Opaque") {
- $fill=1;
- }
- if(isset($data["isStretchWithOverflow"])&&$data["isStretchWithOverflow"]=="true") {
- $stretchoverflow="true";
- }
- if(isset($data->reportElement["isPrintWhenDetailOverflows"])&&$data->reportElement["isPrintWhenDetailOverflows"]=="true") {
- $printoverflow="true";
- }
- if(isset($data->box)&&$data->box->pen["lineWidth"]>0) {
- $border=1;
- if(isset($data->box->pen["lineColor"])) {
- $drawcolor=array("r"=>hexdec(substr($data->box->pen["lineColor"],1,2)),"g"=>hexdec(substr($data->box->pen["lineColor"],3,2)),"b"=>hexdec(substr($data->box->pen["lineColor"],5,2)));
- }
- }
- if(isset($data->reportElement["key"])) {
- $height=$fontsize*$this->adjust;
- }
- if(isset($data->textElement["textAlignment"])) {
- $align=$this->get_first_value($data->textElement["textAlignment"]);
- }
- if(isset($data->textElement["rotation"])) {
- $rotation=$data->textElement["rotation"];
- }
- if(isset($data->textElement->font["pdfFontName"])) {
- $font=$data->textElement->font["pdfFontName"];
- }
- if(isset($data->textElement->font["size"])) {
- $fontsize=$data->textElement->font["size"];
- }
- if(isset($data->textElement->font["isBold"])&&$data->textElement->font["isBold"]=="true") {
- $fontstyle=$fontstyle."B";
- }
- if(isset($data->textElement->font["isItalic"])&&$data->textElement->font["isItalic"]=="true") {
- $fontstyle=$fontstyle."I";
- }
- if(isset($data->textElement->font["isUnderline"])&&$data->textElement->font["isUnderline"]=="true") {
- $fontstyle=$fontstyle."U";
- }
- $this->pointer[]=array("type"=>"SetXY","x"=>$data->reportElement["x"],"y"=>$data->reportElement["y"],"hidden_type"=>"SetXY");
- $this->pointer[]=array("type"=>"SetTextColor","forecolor"=>$data->reportElement["forecolor"],"r"=>$textcolor["r"],"g"=>$textcolor["g"],"b"=>$textcolor["b"],"hidden_type"=>"textcolor");
- $this->pointer[]=array("type"=>"SetDrawColor","r"=>$drawcolor["r"],"g"=>$drawcolor["g"],"b"=>$drawcolor["b"],"hidden_type"=>"drawcolor");
- $this->pointer[]=array("type"=>"SetFillColor","backcolor"=>$data->reportElement["backcolor"],"r"=>$fillcolor["r"],"g"=>$fillcolor["g"],"b"=>$fillcolor["b"],"hidden_type"=>"fillcolor");
- $this->pointer[]=array("type"=>"SetFont","font"=>$font,"fontstyle"=>$fontstyle,"fontsize"=>$fontsize,"hidden_type"=>"font");
- //$data->hyperlinkReferenceExpression=$this->analyse_expression($data->hyperlinkReferenceExpression);
- //if( $data->hyperlinkReferenceExpression!=''){echo "$data->hyperlinkReferenceExpression";die;}
- switch ($data->textFieldExpression) {
- case 'new java.util.Date()':
- //### New: =>date("Y.m.d.",....
- $this->pointer[]=array ("type"=>"MultiCell","width"=>$data->reportElement["width"],"height"=>$height,"txt"=>date("Y-m-d H:i:s"),"border"=>$border,"align"=>$align,"fill"=>$fill,"hidden_type"=>"date","soverflow"=>$stretchoverflow,"poverflow"=>$printoverflow,"link"=>substr($data->hyperlinkReferenceExpression,1,-1));
- //### End of modification
- break;
- case '"Page "+$V{PAGE_NUMBER}+" of"':
- $this->pointer[]=array("type"=>"MultiCell","width"=>$data->reportElement["width"],"height"=>$height,"txt"=>'Page $this->PageNo() of',"border"=>$border,"align"=>$align,"fill"=>$fill,"hidden_type"=>"pageno","soverflow"=>$stretchoverflow,"poverflow"=>$printoverflow,"link"=>substr($data->hyperlinkReferenceExpression,1,-1),"pattern"=>$data["pattern"]);
- break;
- case '$V{PAGE_NUMBER}':
- if(isset($data["evaluationTime"])&&$data["evaluationTime"]=="Report") {
- $this->pointer[]=array("type"=>"MultiCell","width"=>$data->reportElement["width"],"height"=>$height,"txt"=>'{nb}',"border"=>$border,"align"=>$align,"fill"=>$fill,"hidden_type"=>"pageno","soverflow"=>$stretchoverflow,"poverflow"=>$printoverflow,"link"=>substr($data->hyperlinkReferenceExpression,1,-1),"pattern"=>$data["pattern"]);
- }
- else {
- $this->pointer[]=array("type"=>"MultiCell","width"=>$data->reportElement["width"],"height"=>$height,"txt"=>'$this->PageNo()',"border"=>$border,"align"=>$align,"fill"=>$fill,"hidden_type"=>"pageno","soverflow"=>$stretchoverflow,"poverflow"=>$printoverflow,"link"=>substr($data->hyperlinkReferenceExpression,1,-1),"pattern"=>$data["pattern"]);
- }
- break;
- case '" " + $V{PAGE_NUMBER}':
- $this->pointer[]=array("type"=>"MultiCell","width"=>$data->reportElement["width"],"height"=>$height,"txt"=>' {nb}',"border"=>$border,"align"=>$align,"fill"=>$fill,"hidden_type"=>"nb","soverflow"=>$stretchoverflow,"poverflow"=>$printoverflow,"link"=>substr($data->hyperlinkReferenceExpression,1,-1),"pattern"=>$data["pattern"]);
- break;
- case '$V{REPORT_COUNT}':
- //### $this->report_count=0;
- $this->pointer[]=array("type"=>"MultiCell","width"=>$data->reportElement["width"],"height"=>$height,"txt"=>&$this->report_count,"border"=>$border,"align"=>$align,"fill"=>$fill,"hidden_type"=>"report_count","soverflow"=>$stretchoverflow,"poverflow"=>$printoverflow,"link"=>substr($data->hyperlinkReferenceExpression,1,-1),"pattern"=>$data["pattern"]);
- break;
- case '$V{'.$this->gnam.'_COUNT}':
- // case '$V{'.$this->arrayband[0]["gname"].'_COUNT}':
- //### $this->group_count=0;
- $gnam=$this->arrayband[0]["gname"];
- $this->pointer[]=array("type"=>"MultiCell","width"=>$data->reportElement["width"],"height"=>$height,"txt"=>&$this->group_count["$this->gnam"],"border"=>$border,"align"=>$align,"fill"=>$fill,"hidden_type"=>"group_count","soverflow"=>$stretchoverflow,"poverflow"=>$printoverflow,"link"=>substr($data->hyperlinkReferenceExpression,1,-1),"pattern"=>$data["pattern"]);
- break;
- default:
- $writeHTML=false;
- if($data->reportElement->property["name"]=="writeHTML")
- $writeHTML=$data->reportElement->property["value"];
- if(isset($data->reportElement["isPrintRepeatedValues"]))
- $isPrintRepeatedValues=$data->reportElement["isPrintRepeatedValues"];
- $this->pointer[]=array("type"=>"MultiCell","width"=>$data->reportElement["width"],"height"=>$height,"txt"=>$data->textFieldExpression,
- "border"=>$border,"align"=>$align,"fill"=>$fill,
- "hidden_type"=>"field","soverflow"=>$stretchoverflow,"poverflow"=>$printoverflow,
- "printWhenExpression"=>$data->reportElement->printWhenExpression,
- "link"=>substr($data->hyperlinkReferenceExpression,1,-1),"pattern"=>$data["pattern"],
- "writeHTML"=>$writeHTML,"isPrintRepeatedValues"=>$isPrintRepeatedValues,"rotation"=>$rotation);
- break;
- }
- }
- public function element_subReport($data) {
- // $b=$data->subreportParameter;
- $srsearcharr=array('.jasper','"',"'",' ','$P{SUBREPORT_DIR}+');
- $srrepalcearr=array('.jrxml',"","",'',$this->arrayParameter['SUBREPORT_DIR']);
- if (strpos($data->subreportExpression,'$P{SUBREPORT_DIR}') === false){
- $subreportExpression=str_replace($srsearcharr,$srrepalcearr,$data->subreportExpression);
- }
- else{
- $subreportExpression=str_replace($srsearcharr,$srrepalcearr,$data->subreportExpression);
- }
- $b=array();
- foreach($data as $name=>$out){
- if($name=='subreportParameter'){
- $b[$out['name'].'']=$out->subreportParameterExpression;
- }
- }//loop to let multiple parameter pass to subreport pass to subreport
- $this->pointer[]=array("type"=>"subreport", "x"=>$data->reportElement["x"], "y"=>$data->reportElement["y"],
- "width"=>$data->reportElement["width"], "height"=>$data->reportElement["height"],
- "subreportparameterarray"=>$b,"connectionExpression"=>$data->connectionExpression,
- "subreportExpression"=>$subreportExpression,"hidden_type"=>"subreport");
- }
- public function transferDBtoArray($host,$user,$password,$db_or_dsn_name,$cndriver="mysql") {
- $this->m=0;
- if(!$this->connect($host,$user,$password,$db_or_dsn_name,$cndriver)) //connect database
- {
- echo "Fail to connect database";
- exit(0);
- }
- if($this->debugsql==true) {
- echo $this->sql;
- die;
- }
- if($cndriver=="odbc") {
- $result=odbc_exec( $this->myconn,$this->sql);
- while ($row = odbc_fetch_array($result)) {
- foreach($this->arrayfield as $out) {
- $this->arraysqltable[$this->m]["$out"]=$row["$out"];
- }
- $this->m++;
- }
- }elseif($cndriver=="psql") {
- pg_send_query($this->myconn,$this->sql);
- $result = pg_get_result($this->myconn);
- while ($row = pg_fetch_array($result, NULL, PGSQL_ASSOC)) {
- foreach($this->arrayfield as $out) {
- $this->arraysqltable[$this->m]["$out"]=$row["$out"];
- }
- $this->m++;
- }
- }
- else {
- $result = @mysql_query($this->sql); //query from db
- while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
- foreach($this->arrayfield as $out) {
- $this->arraysqltable[$this->m]["$out"]=$row["$out"];
- }
- $this->m++;
- }
- }
- //close connection to db
- }
- public function time_to_sec($time) {
- $hours = substr($time, 0, -6);
- $minutes = substr($time, -5, 2);
- $seconds = substr($time, -2);
- return $hours * 3600 + $minutes * 60 + $seconds;
- }
- public function sec_to_time($seconds) {
- $hours = floor($seconds / 3600);
- $minutes = floor($seconds % 3600 / 60);
- $seconds = $seconds % 60;
- return sprintf("%d:%02d:%02d", $hours, $minutes, $seconds);
- }
- public function orivariable_calculation() {
- foreach($this->arrayVariable as $k=>$out) {
- // echo $out['resetType']. "<br/><br/>";
- switch($out["calculation"]) {
- case "Sum":
- $sum=0;
- if(isset($this->arrayVariable[$k]['class'])&&$this->arrayVariable[$k]['class']=="java.sql.Time") {
- foreach($this->arraysqltable as $table) {
- $sum=$sum+$this->time_to_sec($table["$out[target]"]);
- //$sum=$sum+substr($table["$out[target]"],0,2)*3600+substr($table["$out[target]"],3,2)*60+substr($table["$out[target]"],6,2);
- }
- //$sum= floor($sum / 3600).":".floor($sum%3600 / 60);
- //if($sum=="0:0"){$sum="00:00";}
- $sum=$this->sec_to_time($sum);
- }
- else {
- foreach($this->arraysqltable as $table) {
- $sum=$sum+$table[$out["target"]];
- $table[$out["target"]];
- }
- }
- $this->arrayVariable[$k]["ans"]=$sum;
- break;
- case "Average":
- $sum=0;
- if(isset($this->arrayVariable[$k]['class'])&&$this->arrayVariable[$k]['class']=="java.sql.Time") {
- $m=0;
- foreach($this->arraysqltable as $table) {
- $m++;
- $sum=$sum+$this->time_to_sec($table["$out[target]"]);
- }
- $sum=$this->sec_to_time($sum/$m);
- $this->arrayVariable[$k]["ans"]=$sum;
- }
- else {
- $this->arrayVariable[$k]["ans"]=$sum;
- $m=0;
- foreach($this->arraysqltable as $table) {
- $m++;
- $sum=$sum+$table["$out[target]"];
- }
- $this->arrayVariable[$k]["ans"]=$sum/$m;
- }
- break;
- case "DistinctCount":
- break;
- case "Lowest":
- foreach($this->arraysqltable as $table) {
- $lowest=$table[$out["target"]];
- if($table[$out["target"]]<$lowest) {
- $lowest=$table[$out["target"]];
- }
- $this->arrayVariable[$k]["ans"]=$lowest;
- }
- break;
- case "Highest":
- $out["ans"]=0;
- foreach($this->arraysqltable as $table) {
- if($table[$out["target"]]>$out["ans"]) {
- $this->arrayVariable[$k]["ans"]=$table[$out["target"]];
- }
- }
- break;
- //### A Count for groups, as a variable. Not tested yet, but seemed to work in print_r()
- case "Count":
- $value=$this->arrayVariable[$k]["ans"];
- if( $this->arraysqltable[$this->global_pointer][$this->group_pointer]!=$this->arraysqltable[$this->global_pointer-1][$this->group_pointer])
- $value=0;
- $value++;
- $this->arrayVariable[$k]["ans"]=$value;
- break;
- //### End of modification
- default:
- $out["target"]=0; //other cases needed, temporary leave 0 if not suitable case
- break;
- }
- }
- }
- public function variable_calculation($rowno) {
- // $this->variable_calculation($rownum, $this->arraysqltable[$this->global_pointer][$this->group_pointer]);
- // print_r($this->arraysqltable);
- foreach($this->arrayVariable as $k=>$out) {
- // echo $out['resetType']. "<br/><br/>";
- switch($out["calculation"]) {
- case "Sum":
- $value=$this->arrayVariable[$k]["ans"];
- if($out['resetType']==''){
- if(isset($this->arrayVariable[$k]['class'])&&$this->arrayVariable[$k]['class']=="java.sql.Time") {
- // foreach($this->arraysqltable as $table) {
- $value=$this->time_to_sec($value);
- $value+=$this->time_to_sec($this->arraysqltable[$rowno]["$out[target]"]);
- //$sum=$sum+substr($table["$out[target]"],0,2)*3600+substr($table["$out[target]"],3,2)*60+substr($table["$out[target]"],6,2);
- // }
- //$sum= floor($sum / 3600).":".floor($sum%3600 / 60);
- //if($sum=="0:0"){$sum="00:00";}
- $value=$this->sec_to_time($value);
- }
- else {
- // foreach($this->arraysqltable as $table) {
- $value+=$this->arraysqltable[$rowno]["$out[target]"];
- // $table[$out["target"]];
- // }
- }
- }// finisish resettype=''
- else //reset type='group'
- {if( $this->arraysqltable[$this->global_pointer][$this->group_pointer]!=$this->arraysqltable[$this->global_pointer-1][$this->group_pointer])
- $value=0;
- // echo $this->global_pointer.",".$this->group_pointer.",".$this->arraysqltable[$this->global_pointer][$this->group_pointer].",".$this->arraysqltable[$this->global_pointer-1][$this->group_pointer].",".$this->arraysqltable[$rowno]["$out[target]"];
- if(isset($this->arrayVariable[$k]['class'])&&$this->arrayVariable[$k]['class']=="java.sql.Time") {
- $value+=$this->time_to_sec($this->arraysqltable[$rowno]["$out[target]"]);
- //$sum= floor($sum / 3600).":".floor($sum%3600 / 60);
- //if($sum=="0:0"){$sum="00:00";}
- $value=$this->sec_to_time($value);
- }
- else {
- $value+=$this->arraysqltable[$rowno]["$out[target]"];
- }
- }
- $this->arrayVariable[$k]["ans"]=$value;
- // echo ",$value<br/>";
- break;
- case "Average":
- $sum=0;
- if(isset($this->arrayVariable[$k]['class'])&&$this->arrayVariable[$k]['class']=="java.sql.Time") {
- $m=0;
- //$value=$this->arrayVariable[$k]["ans"];
- //$value=$this->time_to_sec($value);
- //$value+=$this->time_to_sec($this->arraysqltable[$rowno]["$out[target]"]);
- foreach($this->arraysqltable as $table) {
- $m++;
- $sum=$sum+$this->time_to_sec($table["$out[target]"]);
- // echo ",".$table["$out[target]"]."<br/>";
- }
- $sum=$this->sec_to_time($sum/$m);
- // echo "Total:".$sum."<br/>";
- $this->arrayVariable[$k]["ans"]=$sum;
- }
- else {
- $this->arrayVariable[$k]["ans"]=$sum;
- $m=0;
- foreach($this->arraysqltable as $table) {
- $m++;
- $sum=$sum+$table["$out[target]"];
- }
- $this->arrayVariable[$k]["ans"]=$sum/$m;
- }
- break;
- case "DistinctCount":
- break;
- case "Lowest":
- foreach($this->arraysqltable as $table) {
- $lowest=$table[$out["target"]];
- if($table[$out["target"]]<$lowest) {
- $lowest=$table[$out["target"]];
- }
- $this->arrayVariable[$k]["ans"]=$lowest;
- }
- break;
- case "Highest":
- $out["ans"]=0;
- foreach($this->arraysqltable as $table) {
- if($table[$out["target"]]>$out["ans"]) {
- $this->arrayVariable[$k]["ans"]=$table[$out["target"]];
- }
- }
- break;
- //### A Count for groups, as a variable. Not tested yet, but seemed to work in print_r()
- case "Count":
- $value=$this->arrayVariable[$k]["ans"];
- if( $this->arraysqltable[$this->global_pointer][$this->group_pointer]!=$this->arraysqltable[$this->global_pointer-1][$this->group_pointer])
- $value=0;
- $value++;
- $this->arrayVariable[$k]["ans"]=$value;
- break;
- //### End of modification
- default:
- $out["target"]=0; //other cases needed, temporary leave 0 if not suitable case
- break;
- }
- }
- }
- public function outpage($out_method="I",$filename="") {
-
- if($this->lang=="cn") {
- if($this->arrayPageSetting["orientation"]=="P") {
- $this->pdf=new PDF_Unicode($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageWidth"],$this->arrayPageSetting["pageHeight"]));
- $this->pdf->AddUniGBhwFont("uGB");
- }
- else {
- $this->pdf=new PDF_Unicode($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageHeight"],$this->arrayPageSetting["pageWidth"]));
- $this->pdf->AddUniGBhwFont("uGB");
- }
- }
- else {
- if($this->pdflib=="TCPDF") {
- if($this->arrayPageSetting["orientation"]=="P")
- $this->pdf=new TCPDF($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageWidth"],$this->arrayPageSetting["pageHeight"]));
- else
- $this->pdf=new TCPDF($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageHeight"],$this->arrayPageSetting["pageWidth"]));
- $this->pdf->setPrintHeader(false);
- $this->pdf->setPrintFooter(false);
- }elseif($this->pdflib=="FPDF") {
- if($this->arrayPageSetting["orientation"]=="P")
- $this->pdf=new FPDF($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageWidth"],$this->arrayPageSetting["pageHeight"]));
- else
- $this->pdf=new FPDF($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageHeight"],$this->arrayPageSetting["pageWidth"]));
- }
- elseif($this->pdflib=="XLS"){
-
-
- include dirname(__FILE__)."/ExportXLS.inc.php";
- $xls= new ExportXLS($this,$filename);
- die;
- }
- }
- //$this->arrayPageSetting["language"]=$xml_path["language"];
- $this->pdf->SetLeftMargin($this->arrayPageSetting["leftMargin"]);
- $this->pdf->SetRightMargin($this->arrayPageSetting["rightMargin"]);
- $this->pdf->SetTopMargin($this->arrayPageSetting["topMargin"]);
- $this->pdf->SetAutoPageBreak(true,$this->arrayPageSetting["bottomMargin"]/2);
- $this->pdf->AliasNbPages();
- $this->global_pointer=0;
- foreach ($this->arrayband as $band) {
- // $this->currentband=$band["name"]; // to know current where current band in!
- switch($band["name"]) {
- case "title":
- if($this->arraytitle[0]["height"]>0)
- $this->title();
- break;
- case "pageHeader":
- if(!$this->newPageGroup) {
- $headerY = $this->arrayPageSetting["topMargin"]+$this->arraypageHeader[0]["height"];
- $this->pageHeader($headerY);
- }else {
- $this->pageHeaderNewPage();
- }
- break;
- case "detail":
- if(!$this->newPageGroup) {
- $this->detail();
- }else {
- $this->detailNewPage();
- //$this->groupNewPage();
- }
- break;
- case "group":
- $this->group_pointer=$band["groupExpression"];
- $this->group_name=$band["gname"];
- break;
- default:
- break;
- }
- }
- if($filename=="")
- $filename=$this->arrayPageSetting["name"].".pdf";
- $this->disconnect($this->cndriver);
- return $this->pdf->Output($filename,$out_method); //send out the complete page
- }
- public function element_pieChart($data){
- $height=$data->chart->reportElement["height"];
- $width=$data->chart->reportElement["width"];
- $x=$data->chart->reportElement["x"];
- $y=$data->chart->reportElement["y"];
- $charttitle['position']=$data->chart->chartTitle['position'];
- $charttitle['text']=$data->chart->chartTitle->titleExpression;
- $chartsubtitle['text']=$data->chart->chartSubTitle->subtitleExpression;
- $chartLegendPos=$data->chart->chartLegend['position'];
- $dataset=$data->pieDataset->dataset->datasetRun['subDataset'];
- $seriesexp=$data->pieDataset->keyExpression;
- $valueexp=$data->pieDataset->valueExpression;
- $bb=$data->pieDataset->dataset->datasetRun['subDataset'];
- $sql=$this->arraysubdataset["$bb"]['sql'];
- // $ylabel=$data->linePlot->valueAxisLabelExpression;
- $param=array();
- foreach($data->categoryDataset->dataset->datasetRun->datasetParameter as $tag=>$value){
- $param[]= array("$value[name]"=>$value->datasetParameterExpression);
- }
- // print_r($param);
- $this->pointer[]=array('type'=>'PieChart','x'=>$x,'y'=>$y,'height'=>$height,'width'=>$width,'charttitle'=>$charttitle,
- 'chartsubtitle'=> $chartsubtitle,
- 'chartLegendPos'=> $chartLegendPos,'dataset'=>$dataset,'seriesexp'=>$seriesexp,
- 'valueexp'=>$valueexp,'param'=>$param,'sql'=>$sql,'ylabel'=>$ylabel);
- }
- public function element_pie3DChart($data){
- }
- public function element_Chart($data,$type){
- $seriesexp=array();
- $catexp=array();
- $valueexp=array();
- $labelexp=array();
- $height=$data->chart->reportElement["height"];
- $width=$data->chart->reportElement["width"];
- $x=$data->chart->reportElement["x"];
- $y=$data->chart->reportElement["y"];
- $charttitle['position']=$data->chart->c…
Large files files are truncated, but you can click here to view the full file