PageRenderTime 81ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/TEMPLATE/Reports/class/PHPJasperXML.inc.php

https://bitbucket.org/Lahiru_LCB/sep_wd_07
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
  1. <?php
  2. //version 0.8c
  3. class PHPJasperXML {
  4. private $adjust=1.2;
  5. public $version=0.8;
  6. private $pdflib;
  7. private $lang;
  8. private $previousarraydata;
  9. public $debugsql=false;
  10. private $myconn;
  11. private $con;
  12. public $group_name;
  13. public $newPageGroup = false;
  14. private $curgroup=0;
  15. private $groupno=0;
  16. private $footershowed=true;
  17. private $titleheight=0;
  18. private $report_count=1; //### New declaration (variable exists in original too)
  19. private $group_count = array(); //### New declaration
  20. public function PHPJasperXML($lang="en",$pdflib="TCPDF") {
  21. $this->lang=$lang;
  22. error_reporting(0);
  23. $this->pdflib=$pdflib;
  24. }
  25. public function connect($db_host,$db_user,$db_pass,$db_or_dsn_name,$cndriver="mysql") {
  26. $this->db_host=$db_host;
  27. $this->db_user=$db_user;
  28. $this->db_pass=$db_pass;
  29. $this->db_or_dsn_name=$db_or_dsn_name;
  30. $this->cndriver=$cndriver;
  31. if($cndriver=="mysql") {
  32. if(!$this->con) {
  33. $this->myconn = @mysql_connect($db_host,$db_user,$db_pass);
  34. if($this->myconn) {
  35. $seldb = @mysql_select_db($db_or_dsn_name,$this->myconn);
  36. if($seldb) {
  37. $this->con = true;
  38. return true;
  39. }
  40. else {
  41. return false;
  42. }
  43. } else {
  44. return false;
  45. }
  46. } else {
  47. return true;
  48. }
  49. return true;
  50. }elseif($cndriver=="psql") {
  51. global $pgport;
  52. if($pgport=="" || $pgport==0)
  53. $pgport=5432;
  54. $conn_string = "host=$db_host port=$pgport dbname=$db_or_dsn_name user=$db_user password=$db_pass";
  55. $this->myconn = pg_connect($conn_string);
  56. if($this->myconn) {
  57. $this->con = true;
  58. return true;
  59. }else
  60. return false;
  61. }
  62. else {
  63. if(!$this->con) {
  64. $this->myconn = odbc_connect($db_or_dsn_name,$db_user,$db_pass);
  65. if( $this->myconn) {
  66. $this->con = true;
  67. return true;
  68. } else {
  69. return false;
  70. }
  71. } else {
  72. return true;
  73. }
  74. }
  75. }
  76. public function disconnect($cndriver="mysql") {
  77. if($cndriver=="mysql") {
  78. if($this->con) {
  79. if(@mysql_close()) {
  80. $this->con = false;
  81. return true;
  82. }
  83. else {
  84. return false;
  85. }
  86. }
  87. }elseif($cndriver=="psql") {
  88. $this->con = false;
  89. pg_close($this->myconn);
  90. }
  91. else {
  92. $this->con = false;
  93. odbc_close( $this->myconn);
  94. }
  95. }
  96. public function xml_dismantle($xml) {
  97. $this->page_setting($xml);
  98. foreach ($xml as $k=>$out) {
  99. switch($k) {
  100. case "parameter":
  101. $this->parameter_handler($out);
  102. break;
  103. case "queryString":
  104. $this->queryString_handler($out);
  105. break;
  106. case "field":
  107. $this->field_handler($out);
  108. break;
  109. case "variable":
  110. $this->variable_handler($out);
  111. break;
  112. case "group":
  113. $this->group_handler($out);
  114. break;
  115. case "subDataset":
  116. $this->subDataset_handler($out);
  117. break;
  118. case "background":
  119. $this->pointer=&$this->arraybackground;
  120. $this->pointer[]=array("height"=>$out->band["height"],"splitType"=>$out->band["splitType"]);
  121. foreach ($out as $bg) {
  122. $this->default_handler($bg);
  123. }
  124. break;
  125. default:
  126. foreach ($out as $object) {
  127. eval("\$this->pointer=&"."\$this->array$k".";");
  128. $this->arrayband[]=array("name"=>$k);
  129. if($k=='detail')
  130. $this->detailbandheight=$object["height"]+0;
  131. elseif($k=='pageHeader')
  132. $this->headerbandheight=$object["height"]+0;
  133. elseif($k=='pageFooter')
  134. $this->footerbandheight=$object["height"]+0;
  135. elseif($k=='lastPageFooter')
  136. $this->lastfooterbandheight=$object["height"]+0;
  137. elseif($k=='summary')
  138. $this->summarybandheight=$object["height"]+0;
  139. $this->pointer[]=array("type"=>"band","height"=>$object["height"],"splitType"=>$object["splitType"],"y_axis"=>$this->y_axis);
  140. $this->default_handler($object);
  141. }
  142. $this->y_axis=$this->y_axis+$out->band["height"]; //after handle , then adjust y axis
  143. break;
  144. }
  145. }
  146. }
  147. public function subDataset_handler($data){
  148. $this->subdataset[$data['name'].'']= $data->queryString;
  149. }
  150. //read level 0,Jasperreport page setting
  151. public function page_setting($xml_path) {
  152. $this->arrayPageSetting["orientation"]="P";
  153. $this->arrayPageSetting["name"]=$xml_path["name"];
  154. $this->arrayPageSetting["language"]=$xml_path["language"];
  155. $this->arrayPageSetting["pageWidth"]=$xml_path["pageWidth"];
  156. $this->arrayPageSetting["pageHeight"]=$xml_path["pageHeight"];
  157. if(isset($xml_path["orientation"])) {
  158. $this->arrayPageSetting["orientation"]=substr($xml_path["orientation"],0,1);
  159. }
  160. $this->arrayPageSetting["columnWidth"]=$xml_path["columnWidth"];
  161. $this->arrayPageSetting["leftMargin"]=$xml_path["leftMargin"];
  162. $this->arrayPageSetting["rightMargin"]=$xml_path["rightMargin"];
  163. $this->arrayPageSetting["topMargin"]=$xml_path["topMargin"];
  164. $this->y_axis=$xml_path["topMargin"];
  165. $this->arrayPageSetting["bottomMargin"]=$xml_path["bottomMargin"];
  166. }
  167. public function parameter_handler($xml_path) {
  168. // $defaultValueExpression=str_replace('"','',$xml_path->defaultValueExpression);
  169. // if($defaultValueExpression!='')
  170. // $this->arrayParameter[$xml_path["name"].'']=$defaultValueExpression;
  171. // else
  172. $this->arrayParameter[$xml_path["name"].''];
  173. }
  174. public function queryString_handler($xml_path) {
  175. $this->sql =$xml_path;
  176. if(isset($this->arrayParameter)) {
  177. foreach($this->arrayParameter as $v => $a) {
  178. $this->sql = str_replace('$P{'.$v.'}', $a, $this->sql);
  179. }
  180. }
  181. }
  182. public function field_handler($xml_path) {
  183. $this->arrayfield[]=$xml_path["name"];
  184. }
  185. public function variable_handler($xml_path) {
  186. $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"]);
  187. }
  188. public function group_handler($xml_path) {
  189. // $this->arraygroup=$xml_path;
  190. if($xml_path["isStartNewPage"]=="true")
  191. $this->newPageGroup=true;
  192. else
  193. $this->newPageGroup="";
  194. foreach($xml_path as $tag=>$out) {
  195. switch ($tag) {
  196. case "groupHeader":
  197. $this->pointer=&$this->arraygroup[$xml_path["name"]]["groupHeader"];
  198. $this->pointer=&$this->arraygrouphead;
  199. $this->arraygroupheadheight=$out->band["height"];
  200. $this->arrayband[]=array("name"=>"group", "gname"=>$xml_path["name"],"isStartNewPage"=>$xml_path["isStartNewPage"],"groupExpression"=>substr($xml_path->groupExpression,3,-1));
  201. $this->pointer[]=array("type"=>"band","height"=>$out->band["height"]+0,"y_axis"=>"","groupExpression"=>substr($xml_path->groupExpression,3,-1));
  202. //### Modification for group count
  203. $gnam=$xml_path["name"];
  204. $this->gnam=$xml_path["name"];
  205. $this->group_count["$gnam"]=1; // Count rows of groups, we're on the first row of the group.
  206. //### End of modification
  207. foreach($out as $band) {
  208. $this->default_handler($band);
  209. }
  210. $this->y_axis=$this->y_axis+$out->band["height"]; //after handle , then adjust y axis
  211. break;
  212. case "groupFooter":
  213. $this->pointer=&$this->arraygroup[$xml_path["name"]]["groupFooter"];
  214. $this->pointer=&$this->arraygroupfoot;
  215. $this->arraygroupfootheight=$out->band["height"];
  216. $this->pointer[]=array("type"=>"band","height"=>$out->band["height"]+0,"y_axis"=>"","groupExpression"=>substr($xml_path->groupExpression,3,-1));
  217. foreach($out as $b=>$band) {
  218. $this->default_handler($band);
  219. }
  220. break;
  221. default:
  222. break;
  223. }
  224. }
  225. }
  226. public function default_handler($xml_path) {
  227. foreach($xml_path as $k=>$out) {
  228. switch($k) {
  229. case "staticText":
  230. $this->element_staticText($out);
  231. break;
  232. case "image":
  233. $this->element_image($out);
  234. break;
  235. case "line":
  236. $this->element_line($out);
  237. break;
  238. case "rectangle":
  239. $this->element_rectangle($out);
  240. break;
  241. case "ellipse":
  242. $this->element_ellipse($out);
  243. break;
  244. case "textField":
  245. $this->element_textField($out);
  246. break;
  247. // case "stackedBarChart":
  248. // $this->element_barChart($out,'StackedBarChart');
  249. // break;
  250. // case "barChart":
  251. // $this->element_barChart($out,'BarChart');
  252. // break;
  253. // case "pieChart":
  254. // $this->element_pieChart($out);
  255. // break;
  256. // case "pie3DChart":
  257. // $this->element_pie3DChart($out);
  258. // break;
  259. // case "lineChart":
  260. // $this->element_lineChart($out);
  261. // break;
  262. // case "stackedAreaChart":
  263. // $this->element_areaChart($out,'stackedAreaChart');
  264. // break;
  265. case "stackedBarChart":
  266. $this->element_Chart($out,'stackedBarChart');
  267. break;
  268. case "barChart":
  269. $this->element_Chart($out,'barChart');
  270. break;
  271. case "pieChart":
  272. $this->element_Chart($out,'pieChart');
  273. break;
  274. case "pie3DChart":
  275. $this->element_pie3DChart($out,'pie3DChart');
  276. break;
  277. case "lineChart":
  278. $this->element_Chart($out,'lineChart');
  279. break;
  280. case "stackedAreaChart":
  281. $this->element_Chart($out,'stackedAreaChart');
  282. break;
  283. case "subreport":
  284. $this->element_subReport($out);
  285. break;
  286. default:
  287. break;
  288. }
  289. };
  290. }
  291. public function element_staticText($data) {
  292. $align="L";
  293. $fill=0;
  294. $border=0;
  295. $fontsize=10;
  296. $font="helvetica";
  297. $fontstyle="";
  298. $textcolor = array("r"=>0,"g"=>0,"b"=>0);
  299. $fillcolor = array("r"=>255,"g"=>255,"b"=>255);
  300. $txt="";
  301. $rotation="";
  302. $drawcolor=array("r"=>0,"g"=>0,"b"=>0);
  303. $height=$data->reportElement["height"];
  304. $stretchoverflow="true";
  305. $printoverflow="false";
  306. if(isset($data->reportElement["forecolor"])) {
  307. $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)));
  308. }
  309. if(isset($data->reportElement["backcolor"])) {
  310. $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)));
  311. }
  312. if($data->reportElement["mode"]=="Opaque") {
  313. $fill=1;
  314. }
  315. if(isset($data["isStretchWithOverflow"])&&$data["isStretchWithOverflow"]=="true") {
  316. $stretchoverflow="true";
  317. }
  318. if(isset($data->reportElement["isPrintWhenDetailOverflows"])&&$data->reportElement["isPrintWhenDetailOverflows"]=="true") {
  319. $printoverflow="true";
  320. $stretchoverflow="false";
  321. }
  322. if((isset($data->box))&&($data->box->pen["lineWidth"]>0)) {
  323. $border=1;
  324. if(isset($data->box->pen["lineColor"])) {
  325. $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)));
  326. }
  327. }
  328. if(isset($data->textElement["textAlignment"])) {
  329. $align=$this->get_first_value($data->textElement["textAlignment"]);
  330. }
  331. if(isset($data->textElement["rotation"])) {
  332. $rotation=$data->textElement["rotation"];
  333. }
  334. if(isset($data->textElement->font["pdfFontName"])) {
  335. $font=$data->textElement->font["pdfFontName"];
  336. }
  337. if(isset($data->textElement->font["size"])) {
  338. $fontsize=$data->textElement->font["size"];
  339. }
  340. if(isset($data->textElement->font["isBold"])&&$data->textElement->font["isBold"]=="true") {
  341. $fontstyle=$fontstyle."B";
  342. }
  343. if(isset($data->textElement->font["isItalic"])&&$data->textElement->font["isItalic"]=="true") {
  344. $fontstyle=$fontstyle."I";
  345. }
  346. if(isset($data->textElement->font["isUnderline"])&&$data->textElement->font["isUnderline"]=="true") {
  347. $fontstyle=$fontstyle."U";
  348. }
  349. if(isset($data->reportElement["key"])) {
  350. $height=$fontsize*$this->adjust;
  351. }
  352. $this->pointer[]=array("type"=>"SetXY","x"=>$data->reportElement["x"],"y"=>$data->reportElement["y"],"hidden_type"=>"SetXY");
  353. $this->pointer[]=array("type"=>"SetTextColor",'forecolor'=>$data->reportElement["forecolor"].'',"r"=>$textcolor["r"],"g"=>$textcolor["g"],"b"=>$textcolor["b"],"hidden_type"=>"textcolor");
  354. $this->pointer[]=array("type"=>"SetDrawColor","r"=>$drawcolor["r"],"g"=>$drawcolor["g"],"b"=>$drawcolor["b"],"hidden_type"=>"drawcolor");
  355. $this->pointer[]=array("type"=>"SetFillColor",'backcolor'=>$data->reportElement["backcolor"].'',"r"=>$fillcolor["r"],"g"=>$fillcolor["g"],"b"=>$fillcolor["b"],"hidden_type"=>"fillcolor");
  356. $this->pointer[]=array("type"=>"SetFont","font"=>$font,"fontstyle"=>$fontstyle,"fontsize"=>$fontsize,"hidden_type"=>"font");
  357. //"height"=>$data->reportElement["height"]
  358. //### UTF-8 characters, a must for me.
  359. $txtEnc=utf8_decode($data->text);
  360. $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);
  361. //### End of modification, below is the original line
  362. // $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);
  363. }
  364. public function element_image($data) {
  365. $imagepath=$data->imageExpression;
  366. //$imagepath= substr($data->imageExpression, 1, -1);
  367. //$imagetype= substr($imagepath,-3);
  368. switch($data[scaleImage]) {
  369. case "FillFrame":
  370. $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");
  371. break;
  372. default:
  373. $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");
  374. break;
  375. }
  376. }
  377. public function element_line($data) { //default line width=0.567(no detect line width)
  378. $drawcolor=array("r"=>0,"g"=>0,"b"=>0);
  379. $hidden_type="line";
  380. if(isset($data->reportElement["forecolor"])) {
  381. $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)));
  382. }
  383. $this->pointer[]=array("type"=>"SetDrawColor","r"=>$drawcolor["r"],"g"=>$drawcolor["g"],"b"=>$drawcolor["b"],"hidden_type"=>"drawcolor");
  384. if(isset($data->reportElement[positionType])&&$data->reportElement[positionType]=="FixRelativeToBottom") {
  385. $hidden_type="relativebottomline";
  386. }
  387. if($data->reportElement["width"][0]+0 > $data->reportElement["height"][0]+0) //width > height means horizontal line
  388. {
  389. $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);
  390. }
  391. elseif($data->reportElement["height"][0]+0>$data->reportElement["width"][0]+0) //vertical line
  392. {
  393. $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);
  394. }
  395. $this->pointer[]=array("type"=>"SetDrawColor","r"=>0,"g"=>0,"b"=>0,"hidden_type"=>"drawcolor");
  396. $this->pointer[]=array("type"=>"SetFillColor","r"=>255,"g"=>255,"b"=>255,"hidden_type"=>"fillcolor");
  397. }
  398. public function element_rectangle($data) {
  399. $radius=$data['radius'];
  400. $drawcolor=array("r"=>0,"g"=>0,"b"=>0);
  401. $fillcolor=array("r"=>255,"g"=>255,"b"=>255);
  402. if(isset($data->reportElement["forecolor"])) {
  403. $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)));
  404. }
  405. if(isset($data->reportElement["backcolor"]) ) {
  406. $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)));
  407. }
  408. $this->pointer[]=array("type"=>"SetDrawColor","r"=>$drawcolor["r"],"g"=>$drawcolor["g"],"b"=>$drawcolor["b"],"hidden_type"=>"drawcolor");
  409. $this->pointer[]=array("type"=>"SetFillColor","r"=>$fillcolor["r"],"g"=>$fillcolor["g"],"b"=>$fillcolor["b"],"hidden_type"=>"fillcolor");
  410. if($radius=='')
  411. $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"]);
  412. else
  413. $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"]);
  414. $this->pointer[]=array("type"=>"SetDrawColor","r"=>0,"g"=>0,"b"=>0,"hidden_type"=>"drawcolor");
  415. $this->pointer[]=array("type"=>"SetFillColor","r"=>255,"g"=>255,"b"=>255,"hidden_type"=>"fillcolor");
  416. }
  417. public function element_ellipse($data) {
  418. $drawcolor=array("r"=>0,"g"=>0,"b"=>0);
  419. $fillcolor=array("r"=>255,"g"=>255,"b"=>255);
  420. if(isset($data->reportElement["forecolor"])) {
  421. $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)));
  422. }
  423. if(isset($data->reportElement["backcolor"])) {
  424. $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)));
  425. }
  426. //$color=array("r"=>$drawcolor["r"],"g"=>$drawcolor["g"],"b"=>$drawcolor["b"]);
  427. $this->pointer[]=array("type"=>"SetFillColor","r"=>$fillcolor["r"],"g"=>$fillcolor["g"],"b"=>$fillcolor["b"],"hidden_type"=>"fillcolor");
  428. $this->pointer[]=array("type"=>"SetDrawColor","r"=>$drawcolor["r"],"g"=>$drawcolor["g"],"b"=>$drawcolor["b"],"hidden_type"=>"drawcolor");
  429. $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);
  430. $this->pointer[]=array("type"=>"SetDrawColor","r"=>0,"g"=>0,"b"=>0,"hidden_type"=>"drawcolor");
  431. $this->pointer[]=array("type"=>"SetFillColor","r"=>255,"g"=>255,"b"=>255,"hidden_type"=>"fillcolor");
  432. }
  433. public function element_textField($data) {
  434. $align="L";
  435. $fill=0;
  436. $border=0;
  437. $fontsize=10;
  438. $font="helvetica";
  439. $rotation="";
  440. $fontstyle="";
  441. $textcolor = array("r"=>0,"g"=>0,"b"=>0);
  442. $fillcolor = array("r"=>255,"g"=>255,"b"=>255);
  443. $stretchoverflow="false";
  444. $printoverflow="false";
  445. $height=$data->reportElement["height"];
  446. $drawcolor=array("r"=>0,"g"=>0,"b"=>0);
  447. if(isset($data->reportElement["forecolor"])) {
  448. $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)));
  449. }
  450. if(isset($data->reportElement["backcolor"])) {
  451. $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)));
  452. }
  453. if($data->reportElement["mode"]=="Opaque") {
  454. $fill=1;
  455. }
  456. if(isset($data["isStretchWithOverflow"])&&$data["isStretchWithOverflow"]=="true") {
  457. $stretchoverflow="true";
  458. }
  459. if(isset($data->reportElement["isPrintWhenDetailOverflows"])&&$data->reportElement["isPrintWhenDetailOverflows"]=="true") {
  460. $printoverflow="true";
  461. }
  462. if(isset($data->box)&&$data->box->pen["lineWidth"]>0) {
  463. $border=1;
  464. if(isset($data->box->pen["lineColor"])) {
  465. $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)));
  466. }
  467. }
  468. if(isset($data->reportElement["key"])) {
  469. $height=$fontsize*$this->adjust;
  470. }
  471. if(isset($data->textElement["textAlignment"])) {
  472. $align=$this->get_first_value($data->textElement["textAlignment"]);
  473. }
  474. if(isset($data->textElement["rotation"])) {
  475. $rotation=$data->textElement["rotation"];
  476. }
  477. if(isset($data->textElement->font["pdfFontName"])) {
  478. $font=$data->textElement->font["pdfFontName"];
  479. }
  480. if(isset($data->textElement->font["size"])) {
  481. $fontsize=$data->textElement->font["size"];
  482. }
  483. if(isset($data->textElement->font["isBold"])&&$data->textElement->font["isBold"]=="true") {
  484. $fontstyle=$fontstyle."B";
  485. }
  486. if(isset($data->textElement->font["isItalic"])&&$data->textElement->font["isItalic"]=="true") {
  487. $fontstyle=$fontstyle."I";
  488. }
  489. if(isset($data->textElement->font["isUnderline"])&&$data->textElement->font["isUnderline"]=="true") {
  490. $fontstyle=$fontstyle."U";
  491. }
  492. $this->pointer[]=array("type"=>"SetXY","x"=>$data->reportElement["x"],"y"=>$data->reportElement["y"],"hidden_type"=>"SetXY");
  493. $this->pointer[]=array("type"=>"SetTextColor","forecolor"=>$data->reportElement["forecolor"],"r"=>$textcolor["r"],"g"=>$textcolor["g"],"b"=>$textcolor["b"],"hidden_type"=>"textcolor");
  494. $this->pointer[]=array("type"=>"SetDrawColor","r"=>$drawcolor["r"],"g"=>$drawcolor["g"],"b"=>$drawcolor["b"],"hidden_type"=>"drawcolor");
  495. $this->pointer[]=array("type"=>"SetFillColor","backcolor"=>$data->reportElement["backcolor"],"r"=>$fillcolor["r"],"g"=>$fillcolor["g"],"b"=>$fillcolor["b"],"hidden_type"=>"fillcolor");
  496. $this->pointer[]=array("type"=>"SetFont","font"=>$font,"fontstyle"=>$fontstyle,"fontsize"=>$fontsize,"hidden_type"=>"font");
  497. //$data->hyperlinkReferenceExpression=$this->analyse_expression($data->hyperlinkReferenceExpression);
  498. //if( $data->hyperlinkReferenceExpression!=''){echo "$data->hyperlinkReferenceExpression";die;}
  499. switch ($data->textFieldExpression) {
  500. case 'new java.util.Date()':
  501. //### New: =>date("Y.m.d.",....
  502. $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));
  503. //### End of modification
  504. break;
  505. case '"Page "+$V{PAGE_NUMBER}+" of"':
  506. $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"]);
  507. break;
  508. case '$V{PAGE_NUMBER}':
  509. if(isset($data["evaluationTime"])&&$data["evaluationTime"]=="Report") {
  510. $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"]);
  511. }
  512. else {
  513. $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"]);
  514. }
  515. break;
  516. case '" " + $V{PAGE_NUMBER}':
  517. $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"]);
  518. break;
  519. case '$V{REPORT_COUNT}':
  520. //### $this->report_count=0;
  521. $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"]);
  522. break;
  523. case '$V{'.$this->gnam.'_COUNT}':
  524. // case '$V{'.$this->arrayband[0]["gname"].'_COUNT}':
  525. //### $this->group_count=0;
  526. $gnam=$this->arrayband[0]["gname"];
  527. $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"]);
  528. break;
  529. default:
  530. $writeHTML=false;
  531. if($data->reportElement->property["name"]=="writeHTML")
  532. $writeHTML=$data->reportElement->property["value"];
  533. if(isset($data->reportElement["isPrintRepeatedValues"]))
  534. $isPrintRepeatedValues=$data->reportElement["isPrintRepeatedValues"];
  535. $this->pointer[]=array("type"=>"MultiCell","width"=>$data->reportElement["width"],"height"=>$height,"txt"=>$data->textFieldExpression,
  536. "border"=>$border,"align"=>$align,"fill"=>$fill,
  537. "hidden_type"=>"field","soverflow"=>$stretchoverflow,"poverflow"=>$printoverflow,
  538. "printWhenExpression"=>$data->reportElement->printWhenExpression,
  539. "link"=>substr($data->hyperlinkReferenceExpression,1,-1),"pattern"=>$data["pattern"],
  540. "writeHTML"=>$writeHTML,"isPrintRepeatedValues"=>$isPrintRepeatedValues,"rotation"=>$rotation);
  541. break;
  542. }
  543. }
  544. public function element_subReport($data) {
  545. // $b=$data->subreportParameter;
  546. $srsearcharr=array('.jasper','"',"'",' ','$P{SUBREPORT_DIR}+');
  547. $srrepalcearr=array('.jrxml',"","",'',$this->arrayParameter['SUBREPORT_DIR']);
  548. if (strpos($data->subreportExpression,'$P{SUBREPORT_DIR}') === false){
  549. $subreportExpression=str_replace($srsearcharr,$srrepalcearr,$data->subreportExpression);
  550. }
  551. else{
  552. $subreportExpression=str_replace($srsearcharr,$srrepalcearr,$data->subreportExpression);
  553. }
  554. $b=array();
  555. foreach($data as $name=>$out){
  556. if($name=='subreportParameter'){
  557. $b[$out['name'].'']=$out->subreportParameterExpression;
  558. }
  559. }//loop to let multiple parameter pass to subreport pass to subreport
  560. $this->pointer[]=array("type"=>"subreport", "x"=>$data->reportElement["x"], "y"=>$data->reportElement["y"],
  561. "width"=>$data->reportElement["width"], "height"=>$data->reportElement["height"],
  562. "subreportparameterarray"=>$b,"connectionExpression"=>$data->connectionExpression,
  563. "subreportExpression"=>$subreportExpression,"hidden_type"=>"subreport");
  564. }
  565. public function transferDBtoArray($host,$user,$password,$db_or_dsn_name,$cndriver="mysql") {
  566. $this->m=0;
  567. if(!$this->connect($host,$user,$password,$db_or_dsn_name,$cndriver)) //connect database
  568. {
  569. echo "Fail to connect database";
  570. exit(0);
  571. }
  572. if($this->debugsql==true) {
  573. echo $this->sql;
  574. die;
  575. }
  576. if($cndriver=="odbc") {
  577. $result=odbc_exec( $this->myconn,$this->sql);
  578. while ($row = odbc_fetch_array($result)) {
  579. foreach($this->arrayfield as $out) {
  580. $this->arraysqltable[$this->m]["$out"]=$row["$out"];
  581. }
  582. $this->m++;
  583. }
  584. }elseif($cndriver=="psql") {
  585. pg_send_query($this->myconn,$this->sql);
  586. $result = pg_get_result($this->myconn);
  587. while ($row = pg_fetch_array($result, NULL, PGSQL_ASSOC)) {
  588. foreach($this->arrayfield as $out) {
  589. $this->arraysqltable[$this->m]["$out"]=$row["$out"];
  590. }
  591. $this->m++;
  592. }
  593. }
  594. else {
  595. $result = @mysql_query($this->sql); //query from db
  596. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  597. foreach($this->arrayfield as $out) {
  598. $this->arraysqltable[$this->m]["$out"]=$row["$out"];
  599. }
  600. $this->m++;
  601. }
  602. }
  603. //close connection to db
  604. }
  605. public function time_to_sec($time) {
  606. $hours = substr($time, 0, -6);
  607. $minutes = substr($time, -5, 2);
  608. $seconds = substr($time, -2);
  609. return $hours * 3600 + $minutes * 60 + $seconds;
  610. }
  611. public function sec_to_time($seconds) {
  612. $hours = floor($seconds / 3600);
  613. $minutes = floor($seconds % 3600 / 60);
  614. $seconds = $seconds % 60;
  615. return sprintf("%d:%02d:%02d", $hours, $minutes, $seconds);
  616. }
  617. public function orivariable_calculation() {
  618. foreach($this->arrayVariable as $k=>$out) {
  619. // echo $out['resetType']. "<br/><br/>";
  620. switch($out["calculation"]) {
  621. case "Sum":
  622. $sum=0;
  623. if(isset($this->arrayVariable[$k]['class'])&&$this->arrayVariable[$k]['class']=="java.sql.Time") {
  624. foreach($this->arraysqltable as $table) {
  625. $sum=$sum+$this->time_to_sec($table["$out[target]"]);
  626. //$sum=$sum+substr($table["$out[target]"],0,2)*3600+substr($table["$out[target]"],3,2)*60+substr($table["$out[target]"],6,2);
  627. }
  628. //$sum= floor($sum / 3600).":".floor($sum%3600 / 60);
  629. //if($sum=="0:0"){$sum="00:00";}
  630. $sum=$this->sec_to_time($sum);
  631. }
  632. else {
  633. foreach($this->arraysqltable as $table) {
  634. $sum=$sum+$table[$out["target"]];
  635. $table[$out["target"]];
  636. }
  637. }
  638. $this->arrayVariable[$k]["ans"]=$sum;
  639. break;
  640. case "Average":
  641. $sum=0;
  642. if(isset($this->arrayVariable[$k]['class'])&&$this->arrayVariable[$k]['class']=="java.sql.Time") {
  643. $m=0;
  644. foreach($this->arraysqltable as $table) {
  645. $m++;
  646. $sum=$sum+$this->time_to_sec($table["$out[target]"]);
  647. }
  648. $sum=$this->sec_to_time($sum/$m);
  649. $this->arrayVariable[$k]["ans"]=$sum;
  650. }
  651. else {
  652. $this->arrayVariable[$k]["ans"]=$sum;
  653. $m=0;
  654. foreach($this->arraysqltable as $table) {
  655. $m++;
  656. $sum=$sum+$table["$out[target]"];
  657. }
  658. $this->arrayVariable[$k]["ans"]=$sum/$m;
  659. }
  660. break;
  661. case "DistinctCount":
  662. break;
  663. case "Lowest":
  664. foreach($this->arraysqltable as $table) {
  665. $lowest=$table[$out["target"]];
  666. if($table[$out["target"]]<$lowest) {
  667. $lowest=$table[$out["target"]];
  668. }
  669. $this->arrayVariable[$k]["ans"]=$lowest;
  670. }
  671. break;
  672. case "Highest":
  673. $out["ans"]=0;
  674. foreach($this->arraysqltable as $table) {
  675. if($table[$out["target"]]>$out["ans"]) {
  676. $this->arrayVariable[$k]["ans"]=$table[$out["target"]];
  677. }
  678. }
  679. break;
  680. //### A Count for groups, as a variable. Not tested yet, but seemed to work in print_r()
  681. case "Count":
  682. $value=$this->arrayVariable[$k]["ans"];
  683. if( $this->arraysqltable[$this->global_pointer][$this->group_pointer]!=$this->arraysqltable[$this->global_pointer-1][$this->group_pointer])
  684. $value=0;
  685. $value++;
  686. $this->arrayVariable[$k]["ans"]=$value;
  687. break;
  688. //### End of modification
  689. default:
  690. $out["target"]=0; //other cases needed, temporary leave 0 if not suitable case
  691. break;
  692. }
  693. }
  694. }
  695. public function variable_calculation($rowno) {
  696. // $this->variable_calculation($rownum, $this->arraysqltable[$this->global_pointer][$this->group_pointer]);
  697. // print_r($this->arraysqltable);
  698. foreach($this->arrayVariable as $k=>$out) {
  699. // echo $out['resetType']. "<br/><br/>";
  700. switch($out["calculation"]) {
  701. case "Sum":
  702. $value=$this->arrayVariable[$k]["ans"];
  703. if($out['resetType']==''){
  704. if(isset($this->arrayVariable[$k]['class'])&&$this->arrayVariable[$k]['class']=="java.sql.Time") {
  705. // foreach($this->arraysqltable as $table) {
  706. $value=$this->time_to_sec($value);
  707. $value+=$this->time_to_sec($this->arraysqltable[$rowno]["$out[target]"]);
  708. //$sum=$sum+substr($table["$out[target]"],0,2)*3600+substr($table["$out[target]"],3,2)*60+substr($table["$out[target]"],6,2);
  709. // }
  710. //$sum= floor($sum / 3600).":".floor($sum%3600 / 60);
  711. //if($sum=="0:0"){$sum="00:00";}
  712. $value=$this->sec_to_time($value);
  713. }
  714. else {
  715. // foreach($this->arraysqltable as $table) {
  716. $value+=$this->arraysqltable[$rowno]["$out[target]"];
  717. // $table[$out["target"]];
  718. // }
  719. }
  720. }// finisish resettype=''
  721. else //reset type='group'
  722. {if( $this->arraysqltable[$this->global_pointer][$this->group_pointer]!=$this->arraysqltable[$this->global_pointer-1][$this->group_pointer])
  723. $value=0;
  724. // 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]"];
  725. if(isset($this->arrayVariable[$k]['class'])&&$this->arrayVariable[$k]['class']=="java.sql.Time") {
  726. $value+=$this->time_to_sec($this->arraysqltable[$rowno]["$out[target]"]);
  727. //$sum= floor($sum / 3600).":".floor($sum%3600 / 60);
  728. //if($sum=="0:0"){$sum="00:00";}
  729. $value=$this->sec_to_time($value);
  730. }
  731. else {
  732. $value+=$this->arraysqltable[$rowno]["$out[target]"];
  733. }
  734. }
  735. $this->arrayVariable[$k]["ans"]=$value;
  736. // echo ",$value<br/>";
  737. break;
  738. case "Average":
  739. $sum=0;
  740. if(isset($this->arrayVariable[$k]['class'])&&$this->arrayVariable[$k]['class']=="java.sql.Time") {
  741. $m=0;
  742. //$value=$this->arrayVariable[$k]["ans"];
  743. //$value=$this->time_to_sec($value);
  744. //$value+=$this->time_to_sec($this->arraysqltable[$rowno]["$out[target]"]);
  745. foreach($this->arraysqltable as $table) {
  746. $m++;
  747. $sum=$sum+$this->time_to_sec($table["$out[target]"]);
  748. // echo ",".$table["$out[target]"]."<br/>";
  749. }
  750. $sum=$this->sec_to_time($sum/$m);
  751. // echo "Total:".$sum."<br/>";
  752. $this->arrayVariable[$k]["ans"]=$sum;
  753. }
  754. else {
  755. $this->arrayVariable[$k]["ans"]=$sum;
  756. $m=0;
  757. foreach($this->arraysqltable as $table) {
  758. $m++;
  759. $sum=$sum+$table["$out[target]"];
  760. }
  761. $this->arrayVariable[$k]["ans"]=$sum/$m;
  762. }
  763. break;
  764. case "DistinctCount":
  765. break;
  766. case "Lowest":
  767. foreach($this->arraysqltable as $table) {
  768. $lowest=$table[$out["target"]];
  769. if($table[$out["target"]]<$lowest) {
  770. $lowest=$table[$out["target"]];
  771. }
  772. $this->arrayVariable[$k]["ans"]=$lowest;
  773. }
  774. break;
  775. case "Highest":
  776. $out["ans"]=0;
  777. foreach($this->arraysqltable as $table) {
  778. if($table[$out["target"]]>$out["ans"]) {
  779. $this->arrayVariable[$k]["ans"]=$table[$out["target"]];
  780. }
  781. }
  782. break;
  783. //### A Count for groups, as a variable. Not tested yet, but seemed to work in print_r()
  784. case "Count":
  785. $value=$this->arrayVariable[$k]["ans"];
  786. if( $this->arraysqltable[$this->global_pointer][$this->group_pointer]!=$this->arraysqltable[$this->global_pointer-1][$this->group_pointer])
  787. $value=0;
  788. $value++;
  789. $this->arrayVariable[$k]["ans"]=$value;
  790. break;
  791. //### End of modification
  792. default:
  793. $out["target"]=0; //other cases needed, temporary leave 0 if not suitable case
  794. break;
  795. }
  796. }
  797. }
  798. public function outpage($out_method="I",$filename="") {
  799. if($this->lang=="cn") {
  800. if($this->arrayPageSetting["orientation"]=="P") {
  801. $this->pdf=new PDF_Unicode($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageWidth"],$this->arrayPageSetting["pageHeight"]));
  802. $this->pdf->AddUniGBhwFont("uGB");
  803. }
  804. else {
  805. $this->pdf=new PDF_Unicode($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageHeight"],$this->arrayPageSetting["pageWidth"]));
  806. $this->pdf->AddUniGBhwFont("uGB");
  807. }
  808. }
  809. else {
  810. if($this->pdflib=="TCPDF") {
  811. if($this->arrayPageSetting["orientation"]=="P")
  812. $this->pdf=new TCPDF($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageWidth"],$this->arrayPageSetting["pageHeight"]));
  813. else
  814. $this->pdf=new TCPDF($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageHeight"],$this->arrayPageSetting["pageWidth"]));
  815. $this->pdf->setPrintHeader(false);
  816. $this->pdf->setPrintFooter(false);
  817. }elseif($this->pdflib=="FPDF") {
  818. if($this->arrayPageSetting["orientation"]=="P")
  819. $this->pdf=new FPDF($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageWidth"],$this->arrayPageSetting["pageHeight"]));
  820. else
  821. $this->pdf=new FPDF($this->arrayPageSetting["orientation"],'pt',array($this->arrayPageSetting["pageHeight"],$this->arrayPageSetting["pageWidth"]));
  822. }
  823. elseif($this->pdflib=="XLS"){
  824. include dirname(__FILE__)."/ExportXLS.inc.php";
  825. $xls= new ExportXLS($this,$filename);
  826. die;
  827. }
  828. }
  829. //$this->arrayPageSetting["language"]=$xml_path["language"];
  830. $this->pdf->SetLeftMargin($this->arrayPageSetting["leftMargin"]);
  831. $this->pdf->SetRightMargin($this->arrayPageSetting["rightMargin"]);
  832. $this->pdf->SetTopMargin($this->arrayPageSetting["topMargin"]);
  833. $this->pdf->SetAutoPageBreak(true,$this->arrayPageSetting["bottomMargin"]/2);
  834. $this->pdf->AliasNbPages();
  835. $this->global_pointer=0;
  836. foreach ($this->arrayband as $band) {
  837. // $this->currentband=$band["name"]; // to know current where current band in!
  838. switch($band["name"]) {
  839. case "title":
  840. if($this->arraytitle[0]["height"]>0)
  841. $this->title();
  842. break;
  843. case "pageHeader":
  844. if(!$this->newPageGroup) {
  845. $headerY = $this->arrayPageSetting["topMargin"]+$this->arraypageHeader[0]["height"];
  846. $this->pageHeader($headerY);
  847. }else {
  848. $this->pageHeaderNewPage();
  849. }
  850. break;
  851. case "detail":
  852. if(!$this->newPageGroup) {
  853. $this->detail();
  854. }else {
  855. $this->detailNewPage();
  856. //$this->groupNewPage();
  857. }
  858. break;
  859. case "group":
  860. $this->group_pointer=$band["groupExpression"];
  861. $this->group_name=$band["gname"];
  862. break;
  863. default:
  864. break;
  865. }
  866. }
  867. if($filename=="")
  868. $filename=$this->arrayPageSetting["name"].".pdf";
  869. $this->disconnect($this->cndriver);
  870. return $this->pdf->Output($filename,$out_method); //send out the complete page
  871. }
  872. public function element_pieChart($data){
  873. $height=$data->chart->reportElement["height"];
  874. $width=$data->chart->reportElement["width"];
  875. $x=$data->chart->reportElement["x"];
  876. $y=$data->chart->reportElement["y"];
  877. $charttitle['position']=$data->chart->chartTitle['position'];
  878. $charttitle['text']=$data->chart->chartTitle->titleExpression;
  879. $chartsubtitle['text']=$data->chart->chartSubTitle->subtitleExpression;
  880. $chartLegendPos=$data->chart->chartLegend['position'];
  881. $dataset=$data->pieDataset->dataset->datasetRun['subDataset'];
  882. $seriesexp=$data->pieDataset->keyExpression;
  883. $valueexp=$data->pieDataset->valueExpression;
  884. $bb=$data->pieDataset->dataset->datasetRun['subDataset'];
  885. $sql=$this->arraysubdataset["$bb"]['sql'];
  886. // $ylabel=$data->linePlot->valueAxisLabelExpression;
  887. $param=array();
  888. foreach($data->categoryDataset->dataset->datasetRun->datasetParameter as $tag=>$value){
  889. $param[]= array("$value[name]"=>$value->datasetParameterExpression);
  890. }
  891. // print_r($param);
  892. $this->pointer[]=array('type'=>'PieChart','x'=>$x,'y'=>$y,'height'=>$height,'width'=>$width,'charttitle'=>$charttitle,
  893. 'chartsubtitle'=> $chartsubtitle,
  894. 'chartLegendPos'=> $chartLegendPos,'dataset'=>$dataset,'seriesexp'=>$seriesexp,
  895. 'valueexp'=>$valueexp,'param'=>$param,'sql'=>$sql,'ylabel'=>$ylabel);
  896. }
  897. public function element_pie3DChart($data){
  898. }
  899. public function element_Chart($data,$type){
  900. $seriesexp=array();
  901. $catexp=array();
  902. $valueexp=array();
  903. $labelexp=array();
  904. $height=$data->chart->reportElement["height"];
  905. $width=$data->chart->reportElement["width"];
  906. $x=$data->chart->reportElement["x"];
  907. $y=$data->chart->reportElement["y"];
  908. $charttitle['position']=$data->chart->chartTitle['position'];
  909. $titlefontname=$data->chart->chartTitle->font['pdfFontName'];
  910. $titlefontsize=$data->chart->chartTitle->font['size'];
  911. $charttitle['text']=$data->chart->chartTitle->titleExpression;
  912. $chartsubtitle['text']=$data->chart->chartSubTitle->subtitleExpression;
  913. $chartLegendPos=$data->chart->chartLegend['position'];
  914. $dataset=$data->categoryDataset->dataset->datasetRun['subDataset'];
  915. $subcatdataset=$data->categoryDataset;
  916. //echo $subcatdataset;
  917. $i=0;
  918. foreach($subcatdataset as $cat => $catseries){
  919. foreach($catseries as $a => $series){
  920. if("$series->categoryExpression"!=''){
  921. array_push( $seriesexp,"$series->seriesExpression");
  922. array_push( $catexp,"$series->categoryExpression");
  923. array_push( $valueexp,"$series->valueExpression");
  924. array_push( $labelexp,"$series->labelExpression");
  925. }
  926. }
  927. }
  928. $bb=$data->categoryDataset->dataset->datasetRun['subDataset'];
  929. $sql=$this->arraysubdataset[$bb]['sql'];
  930. switch($type){
  931. case "barChart":
  932. $ylabel=$data->barPlot->valueAxisLabelExpression;
  933. $xlabel=$data->barPlot->categoryAxisLabelExpression;
  934. $maxy=$data->barPlot->rangeAxisMaxValueExpression;
  935. $miny=$data->barPlot->rangeAxisMinValueExpression;
  936. break;
  937. case "lineChart":
  938. $ylabel=$data->linePlot->valueAxisLabelExpression;
  939. $xlabel=$data->linePlot->categoryAxisLabelExpression;
  940. $maxy=$data->linePlot->rangeAxisMaxValueExpression;
  941. $miny=$data->linePlot->rangeAxisMinValueExpression;
  942. $showshape=$data->linePlot["isShowShapes"];
  943. break;
  944. case "stackedAreaChart":
  945. $ylabel=$data->areaPlot->valueAxisLabelExpression;
  946. $xlabel=$data->areaPlot->categoryAxisLabelExpression;
  947. $maxy=$data->areaPlot->rangeAxisMaxValueExpression;
  948. $miny=$data->areaPlot->rangeAxisMinValueExpression;
  949. break;
  950. }
  951. $param=array();
  952. foreach($data->categoryDataset->dataset->datasetRun->datasetParameter as $tag=>$value){
  953. $param[]= array("$value[name]"=>$value->datasetParameterExpression);
  954. }
  955. if($maxy!='' && $miny!=''){
  956. $scalesetting=array(0=>array("Min"=>$miny,"Max"=>$maxy));
  957. }
  958. else
  959. $scalesetting="";
  960. $this->pointer[]=array('type'=>$type,'x'=>$x,'y'=>$y,'height'=>$height,'width'=>$width,'charttitle'=>$charttitle,
  961. 'chartsubtitle'=> $chartsubtitle,
  962. 'chartLegendPos'=> $chartLegendPos,'dataset'=>$dataset,'seriesexp'=>$seriesexp,
  963. 'catexp'=>$catexp,'valueexp'=>$valueexp,'labelexp'=>$labelexp,'param'=>$param,'sql'=>$sql,'xlabel'=>$xlabel,'showshape'=>$showshape,
  964. 'titlefontsize'=>$titlefontname,'titlefontsize'=>$titlefontsize,'scalesetting'=>$scalesetting);
  965. }
  966. // public function element_lineChart($data){
  967. //
  968. // $seriesexp=array();
  969. // $catexp=array();
  970. // $valueexp=array();
  971. // $labelexp=array();
  972. // $height=$data->chart->reportElement["height"];
  973. // $width=$data->chart->reportElement["width"];
  974. // $x=$data->chart->reportElement["x"];
  975. // $y=$data->chart->reportElement["y"];
  976. // $charttitle['position']=$data->chart->chartTitle['position'];
  977. // $titlefontname=$data->chart->chartTitle->font['pdfFontName'];
  978. // $titlefontsize=$data->chart->chartTitle->font['size'];
  979. // $charttitle['text']=$data->chart->chartTitle->titleExpression;
  980. // $chartsubtitle['text']=$data->chart->chartSubTitle->subtitleExpression;
  981. // $chartLegendPos=$data->chart->chartLegend['position'];
  982. // $dataset=$data->categoryDataset->dataset->datasetRun['subDataset'];
  983. // $subcatdataset=$data->categoryDataset;
  984. // //echo $subcatdataset;
  985. // $i=0;
  986. // foreach($subcatdataset as $cat => $catseries){
  987. // foreach($catseries as $a => $series){
  988. // if("$series->categoryExpression"!=''){
  989. // array_push( $seriesexp,"$series->seriesExpression");
  990. // array_push( $catexp,"$series->categoryExpression");
  991. // array_push( $valueexp,"$series->valueExpression");
  992. // array_push( $labelexp,"$series->labelExpression");
  993. // }
  994. //
  995. // }
  996. //
  997. // }
  998. //
  999. //
  1000. // $bb=$data->categoryDataset->dataset->datasetRun['subDataset'];
  1001. // $sql=$this->arraysubdataset[$bb]['sql'];
  1002. // $ylabel=$data->linePlot->valueAxisLabelExpression;
  1003. // $xlabel=$data->linePlot->categoryAxisLabelExpression;
  1004. // $showshape=$data->linePlot["isShowShapes"];
  1005. //
  1006. //
  1007. // $param=array();
  1008. // foreach($data->categoryDataset->dataset->datasetRun->datasetParameter as $tag=>$value){
  1009. // $param[]= array("$value[name]"=>$value->datasetParameterExpression);
  1010. // }
  1011. // $maxy=$data->barPlot->rangeAxisMaxValueExpression;
  1012. // $miny=$data->barPlot->rangeAxisMinValueExpression;
  1013. // if($maxy!='' && $miny!=''){
  1014. // $scalesetting=array(0=>array("Min"=>$miny,"Max"=>$maxy));
  1015. // }
  1016. // else
  1017. // $scalesetting="";
  1018. //
  1019. // $this->pointer[]=array('type'=>'LineChart','x'=>$x,'y'=>$y,'height'=>$height,'width'=>$width,'charttitle'=>$charttitle,
  1020. // 'chartsubtitle'=> $chartsubtitle,
  1021. // 'chartLegendPos'=> $chartLegendPos,'dataset'=>$dataset,'seriesexp'=>$seriesexp,
  1022. // 'catexp'=>$catexp,'valueexp'=>$valueexp,'labelexp'=>$labelexp,'param'=>$param,'sql'=>$sql,'xlabel'=>$xlabel,'showshape'=>$showshape,
  1023. // 'titlefontsize'=>$titlefontname,'titlefontsize'=>$titlefontsize,'scalesetting'=>$scalesetting);
  1024. //
  1025. // }
  1026. //
  1027. //
  1028. // public function element_barChart($data,$type='BarChart'){
  1029. //
  1030. // $seriesexp=array();
  1031. // $catexp=array();
  1032. // $valueexp=array();
  1033. // $labelexp=array();
  1034. // $height=$data->chart->reportElement["height"];
  1035. // $width=$data->chart->reportElement["width"];
  1036. // $x=$data->chart->reportElement["x"];
  1037. // $y=$data->chart->reportElement["y"];
  1038. // $charttitle['position']=$data->chart->chartTitle['position'];
  1039. // $titlefontname=$data->chart->chartTitle->font['pdfFontName'];
  1040. // $titlefontsize=$data->chart->chartTitle->font['size'];
  1041. // $charttitle['text']=$data->chart->chartTitle->titleExpression;
  1042. // $chartsubtitle['text']=$data->chart->chartSubTitle->subtitleExpression;
  1043. //
  1044. //
  1045. // $chartLegendPos=$data->chart->chartLegend['position'];
  1046. // $dataset=$data->categoryDataset->dataset->datasetRun['subDataset'];
  1047. // $subcatdataset=$data->categoryDataset;
  1048. //
  1049. // //echo $subcatdataset;
  1050. // foreach($subcatdataset as $cat => $catseries){
  1051. // foreach($catseries as $a => $series){
  1052. // if("$series->categoryExpression"!=''){
  1053. // array_push( $seriesexp,"$series->seriesExpression");
  1054. // array_push( $catexp,"$series->categoryExpression");
  1055. // array_push( $valueexp,"$series->valueExpression");
  1056. // array_push( $labelexp,"$series->labelExpression");
  1057. // }
  1058. // }
  1059. //
  1060. // }
  1061. //
  1062. // $bb=$data->categoryDataset->dataset->datasetRun['subDataset'];
  1063. // $sql=$this->arraysubdataset[$bb]['sql'];
  1064. // $ylabel=$data->barPlot->valueAxisLabelExpression;
  1065. // $xlabel=$data->barPlot->categoryAxisLabelExpression;
  1066. // $maxy=$data->barPlot->rangeAxisMaxValueExpression;
  1067. // $miny=$data->barPlot->rangeAxisMinValueExpression;
  1068. // if($maxy!='' && $miny!=''){
  1069. // $scalesetting=array(0=>array("Min"=>$miny,"Max"=>$maxy));
  1070. // }
  1071. // else
  1072. // $scalesetting="";
  1073. //
  1074. // $param=array();
  1075. // foreach($data->categoryDataset->dataset->datasetRun->datasetParameter as $tag=>$value){
  1076. // $param[]= array("$value[name]"=>$value->datasetParameterExpression);
  1077. // }
  1078. //// print_r($param);
  1079. //
  1080. // $this->pointer[]=array('type'=>$type,'x'=>$x,'y'=>$y,'height'=>$height,'width'=>$width,'charttitle'=>$charttitle,
  1081. // 'chartsubtitle'=> $chartsubtitle,
  1082. // 'chartLegendPos'=> $chartLegendPos,'dataset'=>$dataset,'seriesexp'=>$seriesexp,
  1083. // 'catexp'=>$catexp,'valueexp'=>$valueexp,'labelexp'=>$labelexp,'param'=>$param,'sql'=>$sql,'ylabel'=>$ylabel,'xlabel'=>$xlabel,
  1084. // 'titlefontsize'=>$titlefontname,'titlefontsize'=>$titlefontsize,'scalesetting'=>$scalesetting);
  1085. //
  1086. // }
  1087. public function setChartColor(){
  1088. $k=0;
  1089. $this->chart->setColorPalette($k,0,255,88);$k++;
  1090. $this->chart->setColorPalette($k,121,88,255);$k++;
  1091. $this->chart->setColorPalette($k,255,91,99);$k++;
  1092. $this->chart->setColorPalette($k,255,0,0);$k++;
  1093. $this->chart->setColorPalette($k,0,0,100);$k++;
  1094. $this->chart->setColorPalette($k,200,0,100);$k++;
  1095. $this->chart->setColorPalette($k,0,100,0);$k++;
  1096. $this->chart->setColorPalette($k,100,0,0);$k++;
  1097. $this->chart->setColorPalette($k,200,0,0);$k++;
  1098. $this->chart->setColorPalette($k,0,0,200);$k++;
  1099. $this->chart->setColorPalette($k,50,0,0);$k++;
  1100. $this->chart->setColorPalette($k,100,0,50);$k++;
  1101. $this->chart->setColorPalette($k,0,50,0);$k++;
  1102. $this->chart->setColorPalette($k,100,50,0);$k++;
  1103. $this->chart->setColorPalette($k,50,100,50);$k++;
  1104. $this->chart->setColorPalette($k,0,255,0);$k++;
  1105. $this->chart->setColorPalette($k,100,50,0);$k++;
  1106. $this->chart->setColorPalette($k,200,100,50);$k++;
  1107. $this->chart->setColorPalette($k,100,50,200);$k++;
  1108. $this->chart->setColorPalette($k,0,200,0);$k++;
  1109. $this->chart->setColorPalette($k,200,100,0);$k++;
  1110. $this->chart->setColorPalette($k,200,50,50);$k++;
  1111. $this->chart->setColorPalette($k,50,50,50);$k++;
  1112. $this->chart->setColorPalette($k,200,100,100);$k++;
  1113. $this->chart->setColorPalette($k,50,50,100);$k++;
  1114. $this->chart->setColorPalette($k,100,0,200);$k++;
  1115. $this->chart->setColorPalette($k,200,50,100);$k++;
  1116. $this->chart->setColorPalette($k,100,100,200);$k++;
  1117. $this->chart->setColorPalette($k,0,0,50);$k++;
  1118. $this->chart->setColorPalette($k,50,250,200);$k++;
  1119. $this->chart->setColorPalette($k,100,250,200);$k++;
  1120. $this->chart->setColorPalette($k,10,10,10);$k++;
  1121. $this->chart->setColorPalette($k,20,30,50);$k++;
  1122. $this->chart->setColorPalette($k,80,150,200);$k++;
  1123. $this->chart->setColorPalette($k,30,70,20);$k++;
  1124. $this->chart->setColorPalette($k,33,60,0);$k++;
  1125. $this->chart->setColorPalette($k,150,0,200);$k++;
  1126. $this->chart->setColorPalette($k,20,60,50);$k++;
  1127. $this->chart->setColorPalette($k,50,250,250);$k++;
  1128. $this->chart->setColorPalette($k,33,250,70);$k++;
  1129. }
  1130. public function showLineChart($data,$y_axis){
  1131. global $tmpchartfolder,$pchartfolder;
  1132. if($pchartfolder=="")
  1133. $pchartfolder="./pchart2";
  1134. //echo "$pchartfolder/class/pData.class.php";die;
  1135. include_once("$pchartfolder/class/pData.class.php");
  1136. include_once("$pchartfolder/class/pDraw.class.php");
  1137. include_once("$pchartfolder/class/pImage.class.php");
  1138. if($tmpchartfolder=="")
  1139. $tmpchartfolder=$pchartfolder."/cache";
  1140. $w=$data['width']+0;
  1141. $h=$data['height']+0;
  1142. $legendpos=$data['chartLegendPos'];
  1143. //$legendpos="Right";
  1144. $seriesexp=$data['seriesexp'];
  1145. $catexp=$data['catexp'];
  1146. $valueexp=$data['valueexp'];
  1147. $labelexp=$data['labelexp'];
  1148. $ylabel=$data['ylabel'].'';
  1149. $xlabel=$data['xlabel'].'';
  1150. $ylabel = str_replace(array('"',"'"),'',$ylabel);
  1151. $xlabel = str_replace(array('"',"'"),'',$xlabel);
  1152. $scalesetting=$data['scalesetting'];
  1153. $x=$data['x'];
  1154. $y1=$data['y'];
  1155. $legendx=0;
  1156. $legendy=0;
  1157. $titlefontname=$data['titlefontname'].'';
  1158. $titlefontsize=$data['titlefontsize']+0;
  1159. $DataSet = new pData();
  1160. foreach($catexp as $a=>$b)
  1161. $catexp1[]= str_replace(array('"',"'"), '',$b);
  1162. $n=0;
  1163. $DataSet->addPoints($catexp1,'S00');
  1164. $DataSet->setSerieDescription('S00','asdasd');
  1165. //$DataSet->AddSerie('S0');
  1166. //$DataSet->SetSerieName('S0',"Cat");
  1167. $DataSet->setAbscissa('S00');
  1168. $n=$n+1;
  1169. $ds=trim($data['dataset']);
  1170. if($ds!=""){
  1171. $sql=$this->subdataset[$ds];
  1172. $param=$data['param'];
  1173. foreach($param as $p)
  1174. foreach($p as $tag =>$value)
  1175. $sql=str_replace('$P{'.$tag.'}',$value, $sql);
  1176. $sql=$this->changeSubDataSetSql($sql);
  1177. }
  1178. else
  1179. $sql=$this->sql;
  1180. $result = @mysql_query($sql); //query from db
  1181. $chartdata=array();
  1182. $i=0;
  1183. //echo $sql."<br/><br/>";
  1184. $seriesname=array();
  1185. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  1186. $j=0;
  1187. foreach($row as $key => $value){
  1188. //$chartdata[$j][$i]=$value;
  1189. if($value=='')
  1190. $value=0;
  1191. if($key==str_replace(array('$F{','}'),'',$seriesexp[0]))
  1192. array_push($seriesname,$value);
  1193. else
  1194. foreach($valueexp as $v => $y){
  1195. if($key==str_replace(array('$F{','}'),'',$y)){
  1196. $chartdata[$i][$j]=(int)$value;
  1197. $j++;
  1198. }
  1199. }
  1200. }
  1201. $i++;
  1202. }
  1203. if($i==0)
  1204. return 0;
  1205. foreach($seriesname as $s=>$v){
  1206. $DataSet->addPoints($chartdata[$s],"$v");
  1207. // $DataSet->AddSerie("$v");
  1208. }
  1209. $DataSet->setAxisName(0,$ylabel);
  1210. $this->chart = new pImage($w,$h,$DataSet);
  1211. //$c = new pChart($w,$h);
  1212. //$this->setChartColor();
  1213. $this->chart->drawRectangle(1,1,$w-2,$h-2);
  1214. $legendfontsize=8;
  1215. $this->chart->setFontProperties(array('FontName'=>"$pchartfolder/fonts/calibri.ttf",'FontSize'=>$legendfontsize));
  1216. $Title=$data['charttitle']['text'];
  1217. switch($legendpos){
  1218. case "Top":
  1219. $legendmode=array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL);
  1220. $lgsize=$this->chart->getLegendSize($legendmode);
  1221. $diffx=$w-$lgsize['Width'];
  1222. if($diffx>0)
  1223. $legendx=$diffx/2;
  1224. else
  1225. $legendx=0;
  1226. //$legendy=$h-$lgsize['Height']+$legendfontsize;
  1227. if($legendy<0)$legendy=0;
  1228. if($Title==''){
  1229. $graphareay1=5;
  1230. $legendy=$graphareay1+5;
  1231. $graphareax1=40;
  1232. $graphareax2=$w-10 ;
  1233. $graphareay2=$h-$legendfontsize-15;
  1234. }
  1235. else{
  1236. $graphareay1=30;
  1237. $legendy=$graphareay1+5;
  1238. $graphareax1=40;
  1239. $graphareax2=$w-10 ;
  1240. $graphareay2=$h-$legendfontsize-15;
  1241. }
  1242. break;
  1243. case "Left":
  1244. $legendmode=array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_VERTICAL);
  1245. $lgsize=$this->chart->getLegendSize($legendmode);
  1246. $legendx=$lgsize['Width'];
  1247. if($Title==''){
  1248. $legendy=10;
  1249. $graphareay1=5;
  1250. $graphareax1=$legendx+5;
  1251. $graphareax2=$w-5;
  1252. $graphareay2=$h-20;
  1253. }
  1254. else{
  1255. $legendy=30;
  1256. $graphareay1=40;
  1257. $graphareax1=$legendx+5;
  1258. $graphareax2=$w-5 ;
  1259. $graphareay2=$h-20;
  1260. }
  1261. break;
  1262. case "Right":
  1263. $legendmode=array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_VERTICAL);
  1264. $lgsize=$this->chart->getLegendSize($legendmode);
  1265. $legendx=$w-$lgsize['Width'];
  1266. if($Title==''){
  1267. $legendy=10;
  1268. $graphareay1=5;
  1269. $graphareax1=40;
  1270. $graphareax2=$legendx-5 ;
  1271. $graphareay2=$h-20;
  1272. }
  1273. else{
  1274. $legendy=30;
  1275. $graphareay1=30;
  1276. $graphareax1=40;
  1277. $graphareax2=$legendx-5 ;
  1278. $graphareay2=$h-20;
  1279. }
  1280. break;
  1281. case "Bottom":
  1282. $legendmode=array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL);
  1283. $lgsize=$this->chart->getLegendSize($legendmode);
  1284. $diffx=$w-$lgsize['Width'];
  1285. if($diffx>0)
  1286. $legendx=$diffx/2;
  1287. else
  1288. $legendx=0;
  1289. $legendy=$h-$lgsize['Height']+$legendfontsize;
  1290. if($legendy<0)$legendy=0;
  1291. if($Title==''){
  1292. $graphareay1=5;
  1293. $graphareax1=40;
  1294. $graphareax2=$w-10 ;
  1295. $graphareay2=$legendy-$legendfontsize-15;
  1296. }
  1297. else{
  1298. $graphareay1=30;
  1299. $graphareax1=40;
  1300. $graphareax2=$w-10 ;
  1301. $graphareay2=$legendy-$legendfontsize-15;
  1302. }
  1303. break;
  1304. default:
  1305. $legendmode=array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL);
  1306. $lgsize=$this->chart->getLegendSize($legendmode);
  1307. $diffx=$w-$lgsize['Width'];
  1308. if($diffx>0)
  1309. $legendx=$diffx/2;
  1310. else
  1311. $legendx=0;
  1312. $legendy=$h-$lgsize['Height']+$legendfontsize;
  1313. if($legendy<0)$legendy=0;
  1314. if($Title==''){
  1315. $graphareay1=5;
  1316. $graphareax1=40;
  1317. $graphareax2=$w-10 ;
  1318. $graphareay2=$legendy-$legendfontsize-15;
  1319. }
  1320. else{
  1321. $graphareay1=30;
  1322. $graphareax1=40;
  1323. $graphareax2=$w-10 ;
  1324. $graphareay2=$legendy-$legendfontsize-15;
  1325. }
  1326. break;
  1327. }
  1328. //echo "$graphareax1,$graphareay1,$graphareax2,$graphareay2";die;
  1329. //print_r($lgsize);die;
  1330. $this->chart->setGraphArea($graphareax1,$graphareay1,$graphareax2,$graphareay2);
  1331. $this->chart->setFontProperties(array('FontName'=>"$pchartfolder/fonts/calibri.ttf",'FontSize'=>8));
  1332. //if($type=='StackedBarChart')
  1333. // $scalesetting=array("Floating"=>TRUE,"GridR"=>200, "GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE, "CycleBackground"=>TRUE,
  1334. // "DrawSubTicks"=>TRUE,"Mode"=>SCALE_MODE_ADDALL_START0,"DrawArrows"=>TRUE,"ArrowSize"=>6);
  1335. //else
  1336. $ScaleSpacing=5;
  1337. $scalesetting= $scaleSettings = array("XMargin"=>10,"YMargin"=>10,"Floating"=>TRUE,"GridR"=>200,"GridG"=>200,
  1338. "GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE,"Mode"=>SCALE_MODE_START0,'ScaleSpacing'=>$ScaleSpacing);
  1339. $this->chart->drawScale($scalesetting);
  1340. $this->chart->drawLegend($legendx,$legendy,$legendmode);
  1341. $Title = str_replace(array('"',"'"),'',$data['charttitle']['text']);
  1342. if($Title!=''){
  1343. $titlefontsize+0;
  1344. if($titlefontsize==0)
  1345. $titlefontsize=8;
  1346. if($titlefontname=='')
  1347. $titlefontname='calibri';
  1348. $titlefontname=strtolower($titlefontname);
  1349. $textsetting=array('DrawBox'=>FALSE,'FontSize'=>$titlefontsize,'FontName'=>"$pchartfolder/fonts/".$titlefontname.".ttf",'align'=>TEXT_ALIGN_TOPMIDDLE);
  1350. $this->chart->drawText($w/3,($titlefontsize+10),$Title,$textsetting);
  1351. }
  1352. $this->chart->setFontProperties(array('FontName'=>"$pchartfolder/fonts/calibri.ttf",'FontSize'=>7));
  1353. $this->chart->drawLineChart();
  1354. $randomchartno=rand();
  1355. $photofile="$tmpchartfolder/chart$randomchartno.png";
  1356. $this->chart->Render($photofile);
  1357. if(file_exists($photofile)){
  1358. $this->pdf->Image($photofile,$x+$this->arrayPageSetting["leftMargin"],$y_axis+$y1,$w,$h,"PNG");
  1359. unlink($photofile);
  1360. }
  1361. }
  1362. public function showBarChart($data,$y_axis,$type='barChart'){
  1363. global $tmpchartfolder,$pchartfolder;
  1364. if($pchartfolder=="")
  1365. $pchartfolder="./pchart2";
  1366. //echo "$pchartfolder/class/pData.class.php";die;
  1367. include_once("$pchartfolder/class/pData.class.php");
  1368. include_once("$pchartfolder/class/pDraw.class.php");
  1369. include_once("$pchartfolder/class/pImage.class.php");
  1370. if($tmpchartfolder=="")
  1371. $tmpchartfolder=$pchartfolder."/cache";
  1372. $w=$data['width']+0;
  1373. $h=$data['height']+0;
  1374. $legendpos=$data['chartLegendPos'];
  1375. //$legendpos="Right";
  1376. $seriesexp=$data['seriesexp'];
  1377. $catexp=$data['catexp'];
  1378. $valueexp=$data['valueexp'];
  1379. $labelexp=$data['labelexp'];
  1380. $ylabel=$data['ylabel'].'';
  1381. $xlabel=$data['xlabel'].'';
  1382. $ylabel = str_replace(array('"',"'"),'',$ylabel);
  1383. $xlabel = str_replace(array('"',"'"),'',$xlabel);
  1384. $scalesetting=$data['scalesetting'];
  1385. $x=$data['x'];
  1386. $y1=$data['y'];
  1387. $legendx=0;
  1388. $legendy=0;
  1389. $titlefontname=$data['titlefontname'].'';
  1390. $titlefontsize=$data['titlefontsize']+0;
  1391. $DataSet = new pData();
  1392. foreach($catexp as $a=>$b)
  1393. $catexp1[]= str_replace(array('"',"'"), '',$b);
  1394. $n=0;
  1395. $DataSet->addPoints($catexp1,'S00');
  1396. $DataSet->setSerieDescription('S00','asdasd');
  1397. //$DataSet->AddSerie('S0');
  1398. //$DataSet->SetSerieName('S0',"Cat");
  1399. $DataSet->setAbscissa('S00');
  1400. $n=$n+1;
  1401. $ds=trim($data['dataset']);
  1402. if($ds!=""){
  1403. $sql=$this->subdataset[$ds];
  1404. $param=$data['param'];
  1405. foreach($param as $p)
  1406. foreach($p as $tag =>$value)
  1407. $sql=str_replace('$P{'.$tag.'}',$value, $sql);
  1408. $sql=$this->changeSubDataSetSql($sql);
  1409. }
  1410. else
  1411. $sql=$this->sql;
  1412. $result = @mysql_query($sql); //query from db
  1413. $chartdata=array();
  1414. $i=0;
  1415. //echo $sql."<br/><br/>";
  1416. $seriesname=array();
  1417. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  1418. $j=0;
  1419. foreach($row as $key => $value){
  1420. //$chartdata[$j][$i]=$value;
  1421. if($value=='')
  1422. $value=0;
  1423. if($key==str_replace(array('$F{','}'),'',$seriesexp[0]))
  1424. array_push($seriesname,$value);
  1425. else
  1426. foreach($valueexp as $v => $y){
  1427. if($key==str_replace(array('$F{','}'),'',$y)){
  1428. $chartdata[$i][$j]=(int)$value;
  1429. $j++;
  1430. }
  1431. }
  1432. }
  1433. $i++;
  1434. }
  1435. if($i==0)
  1436. return 0;
  1437. foreach($seriesname as $s=>$v){
  1438. $DataSet->addPoints($chartdata[$s],"$v");
  1439. // $DataSet->AddSerie("$v");
  1440. }
  1441. $DataSet->setAxisName(0,$ylabel);
  1442. $this->chart = new pImage($w,$h,$DataSet);
  1443. //$c = new pChart($w,$h);
  1444. //$this->setChartColor();
  1445. $this->chart->drawRectangle(1,1,$w-2,$h-2);
  1446. $legendfontsize=8;
  1447. $this->chart->setFontProperties(array('FontName'=>"$pchartfolder/fonts/calibri.ttf",'FontSize'=>$legendfontsize));
  1448. $Title=$data['charttitle']['text'];
  1449. switch($legendpos){
  1450. case "Top":
  1451. $legendmode=array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL);
  1452. $lgsize=$this->chart->getLegendSize($legendmode);
  1453. $diffx=$w-$lgsize['Width'];
  1454. if($diffx>0)
  1455. $legendx=$diffx/2;
  1456. else
  1457. $legendx=0;
  1458. //$legendy=$h-$lgsize['Height']+$legendfontsize;
  1459. if($legendy<0)$legendy=0;
  1460. if($Title==''){
  1461. $graphareay1=15;
  1462. $legendy=$graphareay1+5;
  1463. $graphareax1=40;
  1464. $graphareax2=$w-10 ;
  1465. $graphareay2=$h-$legendfontsize-15;
  1466. }
  1467. else{
  1468. $graphareay1=30;
  1469. $legendy=$graphareay1+5;
  1470. $graphareax1=40;
  1471. $graphareax2=$w-10 ;
  1472. $graphareay2=$h-$legendfontsize-15;
  1473. }
  1474. break;
  1475. case "Left":
  1476. $legendmode=array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_VERTICAL);
  1477. $lgsize=$this->chart->getLegendSize($legendmode);
  1478. $legendx=$lgsize['Width'];
  1479. if($Title==''){
  1480. $legendy=10;
  1481. $graphareay1=10;
  1482. $graphareax1=$legendx+5;
  1483. $graphareax2=$w-5;
  1484. $graphareay2=$h-20;
  1485. }
  1486. else{
  1487. $legendy=30;
  1488. $graphareay1=40;
  1489. $graphareax1=$legendx+5;
  1490. $graphareax2=$w-5 ;
  1491. $graphareay2=$h-20;
  1492. }
  1493. break;
  1494. case "Right":
  1495. $legendmode=array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_VERTICAL);
  1496. $lgsize=$this->chart->getLegendSize($legendmode);
  1497. $legendx=$w-$lgsize['Width'];
  1498. if($Title==''){
  1499. $legendy=10;
  1500. $graphareay1=5;
  1501. $graphareax1=40;
  1502. $graphareax2=$legendx-5 ;
  1503. $graphareay2=$h-20;
  1504. }
  1505. else{
  1506. $legendy=30;
  1507. $graphareay1=30;
  1508. $graphareax1=40;
  1509. $graphareax2=$legendx-5 ;
  1510. $graphareay2=$h-20;
  1511. }
  1512. break;
  1513. case "Bottom":
  1514. $legendmode=array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL);
  1515. $lgsize=$this->chart->getLegendSize($legendmode);
  1516. $diffx=$w-$lgsize['Width'];
  1517. if($diffx>0)
  1518. $legendx=$diffx/2;
  1519. else
  1520. $legendx=0;
  1521. $legendy=$h-$lgsize['Height']+$legendfontsize;
  1522. if($legendy<0)$legendy=0;
  1523. if($Title==''){
  1524. $graphareay1=15;
  1525. $graphareax1=40;
  1526. $graphareax2=$w-10 ;
  1527. $graphareay2=$legendy-$legendfontsize-15;
  1528. }
  1529. else{
  1530. $graphareay1=30;
  1531. $graphareax1=40;
  1532. $graphareax2=$w-10 ;
  1533. $graphareay2=$legendy-$legendfontsize-15;
  1534. }
  1535. break;
  1536. default:
  1537. $legendmode=array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL);
  1538. $lgsize=$this->chart->getLegendSize($legendmode);
  1539. $diffx=$w-$lgsize['Width'];
  1540. if($diffx>0)
  1541. $legendx=$diffx/2;
  1542. else
  1543. $legendx=0;
  1544. $legendy=$h-$lgsize['Height']+$legendfontsize;
  1545. if($legendy<0)$legendy=0;
  1546. if($Title==''){
  1547. $graphareay1=15;
  1548. $graphareax1=40;
  1549. $graphareax2=$w-10 ;
  1550. $graphareay2=$legendy-$legendfontsize-15;
  1551. }
  1552. else{
  1553. $graphareay1=30;
  1554. $graphareax1=40;
  1555. $graphareax2=$w-10 ;
  1556. $graphareay2=$legendy-$legendfontsize-15;
  1557. }
  1558. break;
  1559. }
  1560. //echo "$graphareax1,$graphareay1,$graphareax2,$graphareay2";die;
  1561. //print_r($lgsize);die;
  1562. $this->chart->setGraphArea($graphareax1,$graphareay1,$graphareax2,$graphareay2);
  1563. $this->chart->setFontProperties(array('FontName'=>"$pchartfolder/fonts/calibri.ttf",'FontSize'=>8));
  1564. if($type=='stackedBarChart')
  1565. $scalesetting=array("Floating"=>TRUE,"GridR"=>200, "GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE, "CycleBackground"=>TRUE,
  1566. "DrawSubTicks"=>TRUE,"Mode"=>SCALE_MODE_ADDALL_START0,"ArrowSize"=>6);
  1567. else
  1568. $scalesetting=array("Floating"=>TRUE,"GridR"=>200, "GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE, "CycleBackground"=>TRUE,
  1569. "DrawSubTicks"=>TRUE,"Mode"=>SCALE_MODE_START0,"ArrowSize"=>6);
  1570. $this->chart->drawScale($scalesetting);
  1571. $this->chart->drawLegend($legendx,$legendy,$legendmode);
  1572. $Title = str_replace(array('"',"'"),'',$data['charttitle']['text']);
  1573. if($Title!=''){
  1574. $titlefontsize+0;
  1575. if($titlefontsize==0)
  1576. $titlefontsize=8;
  1577. if($titlefontname=='')
  1578. $titlefontname='calibri';
  1579. $titlefontname=strtolower($titlefontname);
  1580. $textsetting=array('DrawBox'=>FALSE,'FontSize'=>$titlefontsize,'FontName'=>"$pchartfolder/fonts/".$titlefontname.".ttf",'align'=>TEXT_ALIGN_TOPMIDDLE);
  1581. //print_r($textsetting);die;
  1582. $this->chart->drawText($w/3,($titlefontsize+10),$Title,$textsetting);
  1583. }
  1584. $this->chart->setFontProperties(array('FontName'=>"$pchartfolder/fonts/calibri.ttf",'FontSize'=>7));
  1585. if($type=='stackedBarChart')
  1586. $this->chart->drawStackedBarChart();
  1587. else
  1588. $this->chart->drawBarChart();
  1589. $randomchartno=rand();
  1590. $photofile="$tmpchartfolder/chart$randomchartno.png";
  1591. $this->chart->Render($photofile);
  1592. if(file_exists($photofile)){
  1593. $this->pdf->Image($photofile,$x+$this->arrayPageSetting["leftMargin"],$y_axis+$y1,$w,$h,"PNG");
  1594. unlink($photofile);
  1595. }
  1596. }
  1597. public function showAreaChart($data,$y_axis,$type){
  1598. global $tmpchartfolder,$pchartfolder;
  1599. if($pchartfolder=="")
  1600. $pchartfolder="./pchart2";
  1601. //echo "$pchartfolder/class/pData.class.php";die;
  1602. include_once("$pchartfolder/class/pData.class.php");
  1603. include_once("$pchartfolder/class/pDraw.class.php");
  1604. include_once("$pchartfolder/class/pImage.class.php");
  1605. if($tmpchartfolder=="")
  1606. $tmpchartfolder=$pchartfolder."/cache";
  1607. $w=$data['width']+0;
  1608. $h=$data['height']+0;
  1609. $legendpos=$data['chartLegendPos'];
  1610. //$legendpos="Right";
  1611. $seriesexp=$data['seriesexp'];
  1612. $catexp=$data['catexp'];
  1613. $valueexp=$data['valueexp'];
  1614. $labelexp=$data['labelexp'];
  1615. $ylabel=$data['ylabel'].'';
  1616. $xlabel=$data['xlabel'].'';
  1617. $ylabel = str_replace(array('"',"'"),'',$ylabel);
  1618. $xlabel = str_replace(array('"',"'"),'',$xlabel);
  1619. $scalesetting=$data['scalesetting'];
  1620. $x=$data['x'];
  1621. $y1=$data['y'];
  1622. $legendx=0;
  1623. $legendy=0;
  1624. $titlefontname=$data['titlefontname'].'';
  1625. $titlefontsize=$data['titlefontsize']+0;
  1626. $DataSet = new pData();
  1627. foreach($catexp as $a=>$b)
  1628. $catexp1[]= str_replace(array('"',"'"), '',$b);
  1629. $n=0;
  1630. $DataSet->addPoints($catexp1,'S00');
  1631. $DataSet->setSerieDescription('S00','asdasd');
  1632. //$DataSet->AddSerie('S0');
  1633. //$DataSet->SetSerieName('S0',"Cat");
  1634. $DataSet->setAbscissa('S00');
  1635. $n=$n+1;
  1636. $ds=trim($data['dataset']);
  1637. if($ds!=""){
  1638. $sql=$this->subdataset[$ds];
  1639. $param=$data['param'];
  1640. foreach($param as $p)
  1641. foreach($p as $tag =>$value)
  1642. $sql=str_replace('$P{'.$tag.'}',$value, $sql);
  1643. $sql=$this->changeSubDataSetSql($sql);
  1644. }
  1645. else
  1646. $sql=$this->sql;
  1647. $result = @mysql_query($sql); //query from db
  1648. $chartdata=array();
  1649. $i=0;
  1650. //echo $sql."<br/><br/>";
  1651. $seriesname=array();
  1652. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  1653. $j=0;
  1654. foreach($row as $key => $value){
  1655. //$chartdata[$j][$i]=$value;
  1656. if($value=='')
  1657. $value=0;
  1658. if($key==str_replace(array('$F{','}'),'',$seriesexp[0]))
  1659. array_push($seriesname,$value);
  1660. else
  1661. foreach($valueexp as $v => $y){
  1662. if($key==str_replace(array('$F{','}'),'',$y)){
  1663. $chartdata[$i][$j]=(int)$value;
  1664. $j++;
  1665. }
  1666. }
  1667. }
  1668. $i++;
  1669. }
  1670. if($i==0)
  1671. return 0;
  1672. foreach($seriesname as $s=>$v){
  1673. $DataSet->addPoints($chartdata[$s],"$v");
  1674. // $DataSet->AddSerie("$v");
  1675. }
  1676. $DataSet->setAxisName(0,$ylabel);
  1677. $this->chart = new pImage($w,$h,$DataSet);
  1678. //$c = new pChart($w,$h);
  1679. //$this->setChartColor();
  1680. $this->chart->drawRectangle(1,1,$w-2,$h-2);
  1681. $legendfontsize=8;
  1682. $this->chart->setFontProperties(array('FontName'=>"$pchartfolder/fonts/calibri.ttf",'FontSize'=>$legendfontsize));
  1683. $Title=$data['charttitle']['text'];
  1684. switch($legendpos){
  1685. case "Top":
  1686. $legendmode=array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL);
  1687. $lgsize=$this->chart->getLegendSize($legendmode);
  1688. $diffx=$w-$lgsize['Width'];
  1689. if($diffx>0)
  1690. $legendx=$diffx/2;
  1691. else
  1692. $legendx=0;
  1693. //$legendy=$h-$lgsize['Height']+$legendfontsize;
  1694. if($legendy<0)$legendy=0;
  1695. if($Title==''){
  1696. $graphareay1=5;
  1697. $legendy=$graphareay1+5;
  1698. $graphareax1=40;
  1699. $graphareax2=$w-10 ;
  1700. $graphareay2=$h-$legendfontsize-15;
  1701. }
  1702. else{
  1703. $graphareay1=30;
  1704. $legendy=$graphareay1+5;
  1705. $graphareax1=40;
  1706. $graphareax2=$w-10 ;
  1707. $graphareay2=$h-$legendfontsize-15;
  1708. }
  1709. break;
  1710. case "Left":
  1711. $legendmode=array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_VERTICAL);
  1712. $lgsize=$this->chart->getLegendSize($legendmode);
  1713. $legendx=$lgsize['Width'];
  1714. if($Title==''){
  1715. $legendy=10;
  1716. $graphareay1=5;
  1717. $graphareax1=$legendx+5;
  1718. $graphareax2=$w-5;
  1719. $graphareay2=$h-20;
  1720. }
  1721. else{
  1722. $legendy=30;
  1723. $graphareay1=40;
  1724. $graphareax1=$legendx+5;
  1725. $graphareax2=$w-5 ;
  1726. $graphareay2=$h-20;
  1727. }
  1728. break;
  1729. case "Right":
  1730. $legendmode=array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_VERTICAL);
  1731. $lgsize=$this->chart->getLegendSize($legendmode);
  1732. $legendx=$w-$lgsize['Width'];
  1733. if($Title==''){
  1734. $legendy=10;
  1735. $graphareay1=5;
  1736. $graphareax1=40;
  1737. $graphareax2=$legendx-5 ;
  1738. $graphareay2=$h-20;
  1739. }
  1740. else{
  1741. $legendy=30;
  1742. $graphareay1=30;
  1743. $graphareax1=40;
  1744. $graphareax2=$legendx-5 ;
  1745. $graphareay2=$h-20;
  1746. }
  1747. break;
  1748. case "Bottom":
  1749. $legendmode=array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL);
  1750. $lgsize=$this->chart->getLegendSize($legendmode);
  1751. $diffx=$w-$lgsize['Width'];
  1752. if($diffx>0)
  1753. $legendx=$diffx/2;
  1754. else
  1755. $legendx=0;
  1756. $legendy=$h-$lgsize['Height']+$legendfontsize;
  1757. if($legendy<0)$legendy=0;
  1758. if($Title==''){
  1759. $graphareay1=5;
  1760. $graphareax1=40;
  1761. $graphareax2=$w-10 ;
  1762. $graphareay2=$legendy-$legendfontsize-15;
  1763. }
  1764. else{
  1765. $graphareay1=30;
  1766. $graphareax1=40;
  1767. $graphareax2=$w-10 ;
  1768. $graphareay2=$legendy-$legendfontsize-15;
  1769. }
  1770. break;
  1771. default:
  1772. $legendmode=array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL);
  1773. $lgsize=$this->chart->getLegendSize($legendmode);
  1774. $diffx=$w-$lgsize['Width'];
  1775. if($diffx>0)
  1776. $legendx=$diffx/2;
  1777. else
  1778. $legendx=0;
  1779. $legendy=$h-$lgsize['Height']+$legendfontsize;
  1780. if($legendy<0)$legendy=0;
  1781. if($Title==''){
  1782. $graphareay1=5;
  1783. $graphareax1=40;
  1784. $graphareax2=$w-10 ;
  1785. $graphareay2=$legendy-$legendfontsize-15;
  1786. }
  1787. else{
  1788. $graphareay1=30;
  1789. $graphareax1=40;
  1790. $graphareax2=$w-10 ;
  1791. $graphareay2=$legendy-$legendfontsize-15;
  1792. }
  1793. break;
  1794. }
  1795. //echo "$graphareax1,$graphareay1,$graphareax2,$graphareay2";die;
  1796. //print_r($lgsize);die;
  1797. $this->chart->setGraphArea($graphareax1,$graphareay1,$graphareax2,$graphareay2);
  1798. $this->chart->setFontProperties(array('FontName'=>"$pchartfolder/fonts/calibri.ttf",'FontSize'=>8));
  1799. //if($type=='StackedBarChart')
  1800. // $scalesetting=array("Floating"=>TRUE,"GridR"=>200, "GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE, "CycleBackground"=>TRUE,
  1801. // "DrawSubTicks"=>TRUE,"Mode"=>SCALE_MODE_ADDALL_START0,"DrawArrows"=>TRUE,"ArrowSize"=>6);
  1802. //else
  1803. $ScaleSpacing=5;
  1804. $scalesetting= $scaleSettings = array("XMargin"=>10,"YMargin"=>10,"Floating"=>TRUE,"GridR"=>200,"GridG"=>200,
  1805. "GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE,"Mode"=>SCALE_MODE_ADDALL_START0,'ScaleSpacing'=>$ScaleSpacing);
  1806. $this->chart->drawScale($scalesetting);
  1807. $this->chart->drawLegend($legendx,$legendy,$legendmode);
  1808. $Title = str_replace(array('"',"'"),'',$data['charttitle']['text']);
  1809. if($Title!=''){
  1810. $titlefontsize+0;
  1811. if($titlefontsize==0)
  1812. $titlefontsize=8;
  1813. if($titlefontname=='')
  1814. $titlefontname='calibri';
  1815. $titlefontname=strtolower($titlefontname);
  1816. $textsetting=array('DrawBox'=>FALSE,'FontSize'=>$titlefontsize,'FontName'=>"$pchartfolder/fonts/".$titlefontname.".ttf",'align'=>TEXT_ALIGN_TOPMIDDLE);
  1817. $this->chart->drawText($w/3,($titlefontsize+10),$Title,$textsetting);
  1818. }
  1819. $this->chart->setFontProperties(array('FontName'=>"$pchartfolder/fonts/calibri.ttf",'FontSize'=>7));
  1820. $this->chart->drawStackedAreaChart(array("Surrounding"=>60));
  1821. $randomchartno=rand();
  1822. $photofile="$tmpchartfolder/chart$randomchartno.png";
  1823. $this->chart->Render($photofile);
  1824. if(file_exists($photofile)){
  1825. $this->pdf->Image($photofile,$x+$this->arrayPageSetting["leftMargin"],$y_axis+$y1,$w,$h,"PNG");
  1826. unlink($photofile);
  1827. }
  1828. }
  1829. private function changeSubDataSetSql($sql){
  1830. foreach($this->currentrow as $name =>$value)
  1831. $sql=str_replace('$F{'.$name.'}',$value,$sql);
  1832. foreach($this->arrayParameter as $name=>$value)
  1833. $sql=str_replace('$P{'.$name.'}',$value,$sql);
  1834. foreach($this->arrayVariable as $name=>$value){
  1835. $sql=str_replace('$V{'.$value['target'].'}',$value['ans'],$sql);
  1836. }
  1837. //print_r($this->arrayparameter);
  1838. //variable not yet implemented
  1839. return $sql;
  1840. }
  1841. public function background() {
  1842. foreach ($this->arraybackground as $out) {
  1843. switch($out["hidden_type"]) {
  1844. case "field":
  1845. $this->display($out,$this->arrayPageSetting["topMargin"],true);
  1846. break;
  1847. default:
  1848. $this->display($out,$this->arrayPageSetting["topMargin"],false);
  1849. break;
  1850. }
  1851. }
  1852. }
  1853. public function pageHeader($headerY) {
  1854. $this->currentband='pageHeader';// to know current where current band in!
  1855. $this->pdf->AddPage();
  1856. $this->background();
  1857. if(isset($this->arraypageHeader)) {
  1858. $this->arraypageHeader[0]["y_axis"]=$this->arrayPageSetting["topMargin"];
  1859. }
  1860. foreach ($this->arraypageHeader as $out) {
  1861. switch($out["hidden_type"]) {
  1862. case "field":
  1863. $this->display($out,$this->arraypageHeader[0]["y_axis"],true);
  1864. break;
  1865. default:
  1866. $this->display($out,$this->arraypageHeader[0]["y_axis"],false);
  1867. break;
  1868. }
  1869. }
  1870. $this->currentband='';
  1871. }
  1872. public function pageHeaderNewPage() {
  1873. $this->currentband='pageHeader';
  1874. $this->pdf->AddPage();
  1875. $this->background();
  1876. if(isset($this->arraypageHeader)) {
  1877. $this->arraypageHeader[0]["y_axis"]=$this->arrayPageSetting["topMargin"];
  1878. }
  1879. foreach ($this->arraypageHeader as $out) {
  1880. switch($out["hidden_type"]) {
  1881. case "textfield":
  1882. $this->display($out,$this->arraypageHeader[0]["y_axis"],true);
  1883. break;
  1884. default:
  1885. $this->display($out,$this->arraypageHeader[0]["y_axis"],true);
  1886. break;
  1887. }
  1888. }
  1889. $this->showGroupHeader($this->arrayPageSetting["topMargin"]+$this->arraypageHeader[0]["height"]);
  1890. }
  1891. public function title() {
  1892. $this->currentband='title';
  1893. $this->pdf->AddPage();
  1894. $this->background();
  1895. $this->titleheight=$this->arraytitle[0]["height"];
  1896. //print_r($this->arraytitle);die;
  1897. if(isset($this->arraytitle)) {
  1898. $this->arraytitle[0]["y_axis"]=$this->arrayPageSetting["topMargin"];
  1899. }
  1900. foreach ($this->arraytitle as $out) {
  1901. switch($out["hidden_type"]) {
  1902. case "field":
  1903. $this->display($out,$this->arraytitle[0]["y_axis"],true);
  1904. break;
  1905. default:
  1906. $this->display($out,$this->arraytitle[0]["y_axis"],false);
  1907. break;
  1908. }
  1909. }
  1910. $this->currentband='';
  1911. }
  1912. public function summary($y) {
  1913. //$this->pdf->AddPage();
  1914. //$this->background();
  1915. $this->currentband='summary';
  1916. $this->titlesummary=$this->arraysummary[0]["height"];
  1917. //print_r($this->arraytitle);die;
  1918. foreach ($this->arraysummary as $out) {
  1919. switch($out["hidden_type"]) {
  1920. case "field":
  1921. $this->display($out,$y,true);
  1922. break;
  1923. default:
  1924. $this->display($out,$y,false);
  1925. break;
  1926. }
  1927. }
  1928. $this->currentband='';
  1929. }
  1930. public function group($headerY) {
  1931. $gname=$this->arrayband[0]["gname"]."";
  1932. if(isset($this->arraypageHeader)) {
  1933. $this->arraygroup[$gname]["groupHeader"][0]["y_axis"]=$headerY;
  1934. }
  1935. if(isset($this->arraypageFooter)) {
  1936. $this->arraygroup[$gname]["groupFooter"][0]["y_axis"]=$this->arrayPageSetting["pageHeight"]-$this->arraypageFooter[0]["height"]-$this->arrayPageSetting["bottomMargin"]-$this->arraygroup[$gname]["groupFooter"][0]["height"];
  1937. }
  1938. else {
  1939. $this->arraygroup[$gname]["groupFooter"][0]["y_axis"]=$this->arrayPageSetting["pageHeight"]-$this->arrayPageSetting["bottomMargin"]-$this->arraygroup[$gname]["groupFooter"][0]["height"];
  1940. }
  1941. if(isset($this->arraygroup)) {
  1942. foreach($this->arraygroup[$gname] as $name=>$out) {
  1943. switch($name) {
  1944. case "groupHeader":
  1945. //### $this->group_count=0;
  1946. foreach($out as $path) { //print_r($out);
  1947. switch($path["hidden_type"]) {
  1948. case "field":
  1949. $this->display($path,$this->arraygroup[$gname]["groupHeader"][0]["y_axis"],true);
  1950. break;
  1951. default:
  1952. $this->display($path,$this->arraygroup[$gname]["groupHeader"][0]["y_axis"],false);
  1953. break;
  1954. }
  1955. }
  1956. break;
  1957. case "groupFooter":
  1958. foreach($out as $path) {
  1959. switch($path["hidden_type"]) {
  1960. case "field":
  1961. $this->display($path,$this->arraygroup[$gname]["groupFooter"][0]["y_axis"],true);
  1962. break;
  1963. default:
  1964. $this->display($path,$this->arraygroup[$gname]["groupFooter"][0]["y_axis"],false);
  1965. break;
  1966. }
  1967. }
  1968. break;
  1969. default:
  1970. break;
  1971. }
  1972. }
  1973. }
  1974. }
  1975. public function groupNewPage() {
  1976. $gname=$this->arrayband[0]["gname"]."";
  1977. if(isset($this->arraypageHeader)) {
  1978. $this->arraygroup[$gname]["groupHeader"][0]["y_axis"]=$this->arrayPageSetting["topMargin"]+$this->arraypageHeader[0]["height"];
  1979. }
  1980. if(isset($this->arraypageFooter)) {
  1981. $this->arraygroup[$gname]["groupFooter"][0]["y_axis"]=$this->arrayPageSetting["pageHeight"]-$this->arraypageFooter[0]["height"]-$this->arrayPageSetting["bottomMargin"]-$this->arraygroup[$gname]["groupFooter"][0]["height"];
  1982. }
  1983. else {
  1984. $this->arraygroup[$gname]["groupFooter"][0]["y_axis"]=$this->arrayPageSetting["pageHeight"]-$this->arrayPageSetting["bottomMargin"]-$this->arraygroup[$gname]["groupFooter"][0]["height"];
  1985. }
  1986. if(isset($this->arraygroup)) {
  1987. foreach($this->arraygroup[$gname] as $name=>$out) {
  1988. switch($name) {
  1989. case "groupHeader":
  1990. foreach($out as $path) {
  1991. switch($path["hidden_type"]) {
  1992. case "field":
  1993. $this->display($path,$this->arraygroup[$gname]["groupHeader"][0]["y_axis"],true);
  1994. break;
  1995. default:
  1996. $this->display($path,$this->arraygroup[$gname]["groupHeader"][0]["y_axis"],false);
  1997. break;
  1998. }
  1999. }
  2000. break;
  2001. case "groupFooter":
  2002. foreach($out as $path) {
  2003. switch($path["hidden_type"]) {
  2004. case "field":
  2005. $this->display($path,$this->arraygroup[$gname]["groupFooter"][0]["y_axis"],true);
  2006. break;
  2007. default:
  2008. $this->display($path,$this->arraygroup[$gname]["groupFooter"][0]["y_axis"],false);
  2009. break;
  2010. }
  2011. }
  2012. break;
  2013. default:
  2014. break;
  2015. }
  2016. }
  2017. }
  2018. }
  2019. public function pageFooter() {
  2020. $this->currentband='pageFooter';
  2021. if(isset($this->arraypageFooter)) {
  2022. foreach ($this->arraypageFooter as $out) {
  2023. switch($out["hidden_type"]) {
  2024. case "field":
  2025. $this->display($out,$this->arrayPageSetting["pageHeight"]-$this->arraypageFooter[0]["height"]-$this->arrayPageSetting["bottomMargin"],true);
  2026. break;
  2027. default:
  2028. $this->display($out,$this->arrayPageSetting["pageHeight"]-$this->arraypageFooter[0]["height"]-$this->arrayPageSetting["bottomMargin"],false);
  2029. break;
  2030. }
  2031. }
  2032. }
  2033. else {
  2034. $this->lastPageFooter();
  2035. }
  2036. $this->currentband='';
  2037. }
  2038. public function lastPageFooter() {
  2039. $this->currentband='lastPageFooter';
  2040. if(isset($this->arraylastPageFooter)) {
  2041. foreach ($this->arraylastPageFooter as $out) {
  2042. switch($out["hidden_type"]) {
  2043. case "field":
  2044. $this->display($out,$this->arrayPageSetting["pageHeight"]-$this->arraylastPageFooter[0]["height"]-$this->arrayPageSetting["bottomMargin"],true);
  2045. break;
  2046. default:
  2047. $this->display($out,$this->arrayPageSetting["pageHeight"]-$this->arraylastPageFooter[0]["height"]-$this->arrayPageSetting["bottomMargin"],false);
  2048. break;
  2049. }
  2050. }
  2051. }
  2052. $this->currentband='';
  2053. }
  2054. public function NbLines($w,$txt) {
  2055. //Computes the number of lines a MultiCell of width w will take
  2056. $cw=&$this->pdf->CurrentFont['cw'];
  2057. if($w==0)
  2058. $w=$this->pdf->w-$this->pdf->rMargin-$this->pdf->x;
  2059. $wmax=($w-2*$this->pdf->cMargin)*1000/$this->pdf->FontSize;
  2060. $s=str_replace("\r",'',$txt);
  2061. $nb=strlen($s);
  2062. if($nb>0 and $s[$nb-1]=="\n")
  2063. $nb--;
  2064. $sep=-1;
  2065. $i=0;
  2066. $j=0;
  2067. $l=0;
  2068. $nl=1;
  2069. while($i<$nb) {
  2070. $c=$s[$i];
  2071. if($c=="\n") {
  2072. $i++;
  2073. $sep=-1;
  2074. $j=$i;
  2075. $l=0;
  2076. $nl++;
  2077. continue;
  2078. }
  2079. if($c==' ')
  2080. $sep=$i;
  2081. $l+=$cw[$c];
  2082. if($l>$wmax) {
  2083. if($sep==-1) {
  2084. if($i==$j)
  2085. $i++;
  2086. }
  2087. else
  2088. $i=$sep+1;
  2089. $sep=-1;
  2090. $j=$i;
  2091. $l=0;
  2092. $nl++;
  2093. }
  2094. else
  2095. $i++;
  2096. }
  2097. return $nl;
  2098. }
  2099. public function printlongtext($fontfamily,$fontstyle,$fontsize){
  2100. //$this->gotTextOverPage=false;
  2101. $this->pageFooter();
  2102. $this->pageHeader();
  2103. $this->hideheader==true;
  2104. $this->currentband='detail';
  2105. $this->pdf->SetFont($fontfamily,$fontstyle,$fontsize);
  2106. $this->pdf->SetTextColor($this->forcetextcolor_r,$this->forcetextcolor_g,$this->forcetextcolor_b);
  2107. //$this->pdf->SetTextColor(44,123,4);
  2108. $this->pdf->SetFillColor($this->forcefillcolor_r,$this->forcefillcolor_g,$this->forcefillcolor_b);
  2109. $bltxt=$this->continuenextpageText;
  2110. $this->pdf->SetY($this->arraypageHeader[0]["height"]+15);
  2111. $this->pdf->SetX($bltxt['x']);
  2112. $maxheight=$this->arrayPageSetting["pageHeight"]-$this->arraypageFooter[0]["height"]-$this->pdf->GetY()-$bltxt['height'];
  2113. $this->pdf->MultiCell($bltxt['width'],$bltxt['height'],$bltxt['txt'],
  2114. $bltxt['border'],
  2115. $bltxt['align'],$bltxt['fill'],$bltxt['ln'],'','',$bltxt['reset'],
  2116. $bltxt['streth'],$bltxt['ishtml'],$bltxt['autopadding'],$maxheight-$bltxt['height']);
  2117. if($this->pdf->balancetext!=''){
  2118. $this->continuenextpageText=array('width'=>$bltxt["width"], 'height'=>$bltxt["height"],
  2119. 'txt'=>$this->pdf->balancetext, 'border'=>$bltxt["border"] ,'align'=>$bltxt["align"], 'fill'=>$bltxt["fill"],'ln'=>1,
  2120. 'x'=>$bltxt['x'],'y'=>'','reset'=>true,'streth'=>0,'ishtml'=>false,'autopadding'=>true);
  2121. $this->pdf->balancetext='';
  2122. $this->printlongtext($fontfamily,$fontstyle,$fontsize);
  2123. }
  2124. //echo $this->currentband;
  2125. if( $this->pdf->balancetext=='' && $this->currentband=='detail'){
  2126. if($this->maxpagey['page_'.($this->pdf->getPage()-1)]=='')
  2127. $this->maxpagey['page_'.($this->pdf->getPage()-1)]=$this->pdf->GetY();
  2128. else{
  2129. if($this->maxpagey['page_'.($this->pdf->getPage()-1)]<$this->pdf->GetY())
  2130. $this->maxpagey['page_'.($this->pdf->getPage()-1)]=$this->pdf->GetY();
  2131. }
  2132. }
  2133. }
  2134. public function detail() {
  2135. $currentpage= $this->pdf->getNumPages();
  2136. $this->maxpagey=array();
  2137. $this->currentband='detail';
  2138. $this->arraydetail[0]["y_axis"]=$this->arraydetail[0]["y_axis"]- $this->titleheight;
  2139. $field_pos_y=$this->arraydetail[0]["y_axis"];
  2140. $biggestY=0;
  2141. $tempY=$this->arraydetail[0]["y_axis"];
  2142. if(isset($this->SubReportCheckPoint))
  2143. $checkpoint=$this->SubReportCheckPoint;
  2144. // else
  2145. // $checkpoint=$this->arraydetail[0]["y_axis"];
  2146. $checkpoint=$this->arraydetail[0]["y_axis"];
  2147. // $this->pdf->SetY($checkpoint);
  2148. // $this->pdf->MultiCell(200,10,"====",1);
  2149. $gheader=$this->showGroupHeader($this->arrayPageSetting["topMargin"]+$this->arraypageHeader[0]["height"]);
  2150. $isgroupfooterprinted=false;
  2151. // $this->pdf->SetY($checkpoint+$gheader);
  2152. // $this->pdf->MultiCell(200,10,"????",1);
  2153. $this->maxpagey=array('page_0'=>$checkpoint);
  2154. $rownum=0;
  2155. if($this->arraysqltable) {
  2156. $n=0;
  2157. foreach($this->arraysqltable as $row) {
  2158. // $this->currentband='detail';
  2159. $n++;
  2160. $currentpage= $this->pdf->getNumPages();
  2161. $this->pdf->lastPage();
  2162. $this->hideheader==false;
  2163. if($n>1)
  2164. $checkpoint=$this->maxpagey['page_'.($this->pdf->getNumPages()-1)];
  2165. // echo $checkpoint."<br/>";
  2166. $pageheight=$this->arrayPageSetting["pageHeight"];
  2167. $footerheight=$this->footerbandheight;
  2168. $headerheight=$this->headerbandheight;
  2169. $bottommargin=$this->arrayPageSetting["bottomMargin"];
  2170. $detailheight=$this->detailbandheight;
  2171. //if content near page footer
  2172. if($checkpoint>= $pageheight- $footerheight -$bottommargin- $detailheight-1){
  2173. $this->pageFooter();
  2174. $this->pageHeader();
  2175. $currentpage= $this->pdf->getNumPages();
  2176. $checkpoint=$this->arrayPageSetting["topMargin"]+$this->arraypageHeader[0]["height"];//$this->arraydetail[0]["y_axis"]- $this->titleheight;
  2177. $this->maxpagey[($this->pdf->getPage()-1)]=$checkpoint;
  2178. }
  2179. if(isset($this->arrayVariable)) //if self define variable existing, go to do the calculation
  2180. $this->variable_calculation($rownum, $this->arraysqltable[$this->global_pointer][$this->group_pointer]);
  2181. if(isset($this->arraygroup)&&($this->global_pointer>0)&&
  2182. ($this->arraysqltable[$this->global_pointer][$this->group_pointer]!=$this->arraysqltable[$this->global_pointer-1][$this->group_pointer])){ //check the group's groupExpression existed and same or not
  2183. if($isgroupfooterprinted==true){
  2184. $gfoot=0;
  2185. }
  2186. $ghheight=$this->showGroupHeader($checkpoint+$gfoot);
  2187. $isgroupfooterprinted=false;
  2188. $checkpoint=$checkpoint+$gfoot+$ghheight;//after group header add height band, so detail no crash with group header.
  2189. $this->footershowed=true;
  2190. $this->pdf->SetY($checkpoint);
  2191. $this->group_count["$this->group_name"]=1; // We're on the first row of the group.
  2192. }
  2193. $this->currentband='detail';
  2194. /* begin page handling*/
  2195. //begin page handling
  2196. foreach ($this->arraydetail as $out) {
  2197. // echo $out["hidden_type"]."<br/>";
  2198. switch ($out["hidden_type"]) {
  2199. case "field":
  2200. // $txt=$this->analyse_expression($compare["txt"]);
  2201. $maxheight=$this->arrayPageSetting["pageHeight"]-$this->arraypageFooter[0]["height"]-$this->pdf->GetY()-15;
  2202. $this->prepare_print_array=array("type"=>"MultiCell","width"=>$out["width"],"height"=>$out["height"],"txt"=>$out["txt"],
  2203. "border"=>$out["border"],"align"=>$out["align"],"fill"=>$out["fill"],"hidden_type"=>$out["hidden_type"],
  2204. "printWhenExpression"=>$out["printWhenExpression"],"soverflow"=>$out["soverflow"],"poverflow"=>$out["poverflow"],"link"=>$out["link"],
  2205. "pattern"=>$out["pattern"],"writeHTML"=>$out["writeHTML"],"isPrintRepeatedValues"=>$out["isPrintRepeatedValues"]);
  2206. $this->display($this->prepare_print_array,0,true,$maxheight);
  2207. // $checkpoint=$this->arraydetail[0]["y_axis"];
  2208. break;
  2209. case "relativebottomline":
  2210. //$this->relativebottomline($out,$tempY);
  2211. $this->relativebottomline($out,$biggestY);
  2212. break;
  2213. case "subreport":
  2214. $this->display($out,$checkpoint);
  2215. break;
  2216. default:
  2217. //echo $out["hidden_type"]."=".print_r($out,true)."<br/><br/>";
  2218. $this->display($out,$checkpoint);
  2219. $maxheight=$this->arrayPageSetting["pageHeight"]-$this->arraypageFooter[0]["height"]-$this->pdf->GetY()-15;
  2220. // $checkpoint=$this->arraydetail[0]["y_axis"];
  2221. //$checkpoint=$this->pdf->GetY();
  2222. break;
  2223. }
  2224. $this->pdf->setPage($currentpage);
  2225. }
  2226. $this->pdf->lastPage();
  2227. // if($this->SubReportCheckPoint>0)
  2228. // $biggestY=$this->SubReportCheckPoint;
  2229. // $this->SubReportCheckPoint=0; //if subreport return position
  2230. if(isset($this->arraygroup)&&
  2231. ($this->arraysqltable[$this->global_pointer][$this->group_pointer]!=$this->arraysqltable[$this->global_pointer+1][$this->group_pointer])){
  2232. $pageheight=$this->arrayPageSetting["pageHeight"];
  2233. $footerheight=$this->footerbandheight;
  2234. $headerheight=$this->headerbandheight;
  2235. $topmargin=$this->arrayPageSetting["topMargin"];
  2236. $bottommargin=$this->arrayPageSetting["bottomMargin"];
  2237. $detailheight=$this->detailbandheight;
  2238. $gfootheight=$this->arraygroupfoot[0]['height'];
  2239. $currentY=$this->maxpagey['page_'.($this->pdf->getNumPages()-1)];
  2240. if(($currentY+$gfootheight) < ($pageheight-$bottommargin-$footerheight)){
  2241. $gfoot= $this->showGroupFooter($this->maxpagey['page_'.($this->pdf->getPage()-1)]);
  2242. $checkpoint=$this->maxpagey['page_'.($this->pdf->getNumPages()-1)]+$gfoot;
  2243. }else{
  2244. $this->pageFooter();
  2245. $hhead= $this->pageHeader($this->arrayPageSetting["topMargin"]+$this->arraypageHeader[0]["height"]);
  2246. // $checkpoint=$this->maxpagey['page_'.($this->pdf->getNumPages()-1)]+$gfoot;
  2247. $gfoot= $this->showGroupFooter($headerheight+$this->arrayPageSetting["topMargin"]);
  2248. $isgroupfooterprinted=true;
  2249. // $this->pdf->Cell(100,30,"New pages footer",1);
  2250. $checkpoint=$gfoot+$headerheight+$this->arrayPageSetting["topMargin"];//$hhead+$this->arrayPageSetting["topMargin"]+$this->arraypageHeader[0]["height"]+$gfoot;
  2251. $this->maxpagey['page_'.($this->pdf->getNumPages()-1)]= $checkpoint;
  2252. }
  2253. $this->currentband='detail';
  2254. }
  2255. foreach($this->group_count as &$cntval) {
  2256. $cntval++;
  2257. }
  2258. $this->report_count++;
  2259. $this->global_pointer++;
  2260. $rownum++;
  2261. $this->pdf->lastpage();
  2262. $headerY=$checkpoint;
  2263. }
  2264. $this->global_pointer--;
  2265. }else {
  2266. echo "No data found";
  2267. exit(0);
  2268. }
  2269. // $this->global_pointer--;
  2270. if($this->arraysummary[0]["height"]>0)
  2271. $this->summary($checkpoint);
  2272. if(isset($this->arraylastPageFooter))
  2273. $this->lastPageFooter();
  2274. else
  2275. $this->pageFooter();
  2276. $this->currentband='';
  2277. }
  2278. public function detailNewPage() {
  2279. $currentpage= $this->pdf->getNumPages();
  2280. $this->maxpagey=array();
  2281. $this->currentband='detail';
  2282. $this->arraydetail[0]["y_axis"]=$this->arraydetail[0]["y_axis"]- $this->titleheight;
  2283. $field_pos_y=$this->arraydetail[0]["y_axis"];
  2284. $biggestY=0;
  2285. $tempY=$this->arraydetail[0]["y_axis"];
  2286. if(isset($this->SubReportCheckPoint))
  2287. $checkpoint=$this->SubReportCheckPoint;
  2288. // else
  2289. // $checkpoint=$this->arraydetail[0]["y_axis"];
  2290. $checkpoint=$this->arraydetail[0]["y_axis"];
  2291. // $this->pdf->SetY($checkpoint);
  2292. // $this->pdf->MultiCell(200,10,"====",1);
  2293. // $gheader=$this->showGroupHeader($this->arrayPageSetting["topMargin"]+$this->arraypageHeader[0]["height"]);
  2294. // $this->pdf->SetY($checkpoint+$gheader);
  2295. // $this->pdf->MultiCell(200,10,"????",1);
  2296. $this->maxpagey=array('page_0'=>$checkpoint);
  2297. $rownum=0;
  2298. if($this->arraysqltable) {
  2299. $n=0;
  2300. foreach($this->arraysqltable as $row) {
  2301. // $this->currentband='detail';
  2302. $n++;
  2303. $currentpage= $this->pdf->getNumPages();
  2304. $this->pdf->lastPage();
  2305. if($n>1)
  2306. $checkpoint=$this->maxpagey['page_'.($this->pdf->getNumPages()-1)];
  2307. // echo $checkpoint."<br/>";
  2308. $pageheight=$this->arrayPageSetting["pageHeight"];
  2309. $footerheight=$this->footerbandheight;
  2310. $headerheight=$this->headerbandheight;
  2311. $bottommargin=$this->arrayPageSetting["bottomMargin"];
  2312. $detailheight=$this->detailbandheight;
  2313. $topmargin=$this->arrayPageSetting["topmargin"];
  2314. //if content near page footer
  2315. if($checkpoint>= $pageheight- $footerheight -$bottommargin- $detailheight-1){
  2316. $this->pageFooter();
  2317. $this->pageHeaderNewPage();
  2318. $this->pdf->lastpage();
  2319. $currentpage= $this->pdf->getNumPages();
  2320. $checkpoint=$this->arrayPageSetting["topMargin"]+$this->arraypageHeader[0]["height"]+$this->arraygrouphead[0]['height'];//$this->arraydetail[0]["y_axis"]- $this->titleheight;
  2321. // $this->pdf->Cell(300,10,"$currentY+$gfootheight > $pageheight-$bottommargin-$footerheight",1);
  2322. $this->maxpagey[($this->pdf->getPage()-1)]=$checkpoint;
  2323. }
  2324. if(isset($this->arrayVariable)) //if self define variable existing, go to do the calculation
  2325. $this->variable_calculation($rownum, $this->arraysqltable[$this->global_pointer][$this->group_pointer]);
  2326. if(isset($this->arraygroup)&&($this->global_pointer>0)&&
  2327. ($this->arraysqltable[$this->global_pointer][$this->group_pointer]!=$this->arraysqltable[$this->global_pointer-1][$this->group_pointer])){ //check the group's groupExpression existed and same or not
  2328. $this->pageFooter();
  2329. $this->pageHeaderNewPage();
  2330. $this->pdf->lastPage();
  2331. $currentpage= $this->pdf->getNumPages();
  2332. $checkpoint=$this->arrayPageSetting["topMargin"]+$this->arraypageHeader[0]["height"]+$this->arraygrouphead[0]['height'];
  2333. $this->maxpagey[($this->pdf->getPage()-1)]=$checkpoint;
  2334. $this->footershowed=true;
  2335. $this->group_count["$this->group_name"]=1; // We're on the first row of the group.
  2336. }
  2337. $this->currentband='detail';
  2338. /* begin page handling*/
  2339. // $this->pdf->Cell(200,10,"?*$checkpoint");
  2340. //begin page handling
  2341. foreach ($this->arraydetail as $out) {
  2342. // echo $out["hidden_type"]."<br/>";
  2343. switch ($out["hidden_type"]) {
  2344. case "field":
  2345. // $txt=$this->analyse_expression($compare["txt"]);
  2346. // $this->pdf->SetY($checkpoint);
  2347. $maxheight=$this->arrayPageSetting["pageHeight"]-$this->arraypageFooter[0]["height"]-$this->pdf->GetY()-10;
  2348. $this->prepare_print_array=array("type"=>"MultiCell","width"=>$out["width"],"height"=>$out["height"],"txt"=>$out["txt"],
  2349. "border"=>$out["border"],"align"=>$out["align"],"fill"=>$out["fill"],"hidden_type"=>$out["hidden_type"],
  2350. "printWhenExpression"=>$out["printWhenExpression"],"soverflow"=>$out["soverflow"],"poverflow"=>$out["poverflow"],"link"=>$out["link"],
  2351. "pattern"=>$out["pattern"],"writeHTML"=>$out["writeHTML"],"isPrintRepeatedValues"=>$out["isPrintRepeatedValues"]);
  2352. // $this->pdf->Cell(300,10,"==$checkpoint --",1);
  2353. $this->display($this->prepare_print_array,0,true,$maxheight);
  2354. // $checkpoint=$this->arraydetail[0]["y_axis"];
  2355. break;
  2356. case "relativebottomline":
  2357. //$this->relativebottomline($out,$tempY);
  2358. $this->relativebottomline($out,$biggestY);
  2359. break;
  2360. case "":
  2361. ;
  2362. break;
  2363. default:
  2364. $this->display($out,$checkpoint);
  2365. break;
  2366. }
  2367. $this->pdf->setPage($currentpage);
  2368. }
  2369. $this->pdf->lastPage();
  2370. if($this->SubReportCheckPoint>0)
  2371. $biggestY=$this->SubReportCheckPoint; $this->SubReportCheckPoint=0; //if subreport return position
  2372. if(isset($this->arraygroup)&&
  2373. ($this->arraysqltable[$this->global_pointer][$this->group_pointer]!=$this->arraysqltable[$this->global_pointer+1][$this->group_pointer])){
  2374. $pageheight=$this->arrayPageSetting["pageHeight"];
  2375. $footerheight=$this->footerbandheight;
  2376. $headerheight=$this->headerbandheight;
  2377. $topmargin=$this->arrayPageSetting["topMargin"];
  2378. $bottommargin=$this->arrayPageSetting["bottomMargin"];
  2379. $detailheight=$this->detailbandheight;
  2380. $gfootheight=$this->arraygroupfoot[0]['height'];
  2381. $currentY=$this->maxpagey['page_'.($this->pdf->getNumPages()-1)];
  2382. // $this->pdf->Cell(300,10,"$currentY+$gfootheight > $pageheight-$bottommargin-$footerheight",1);
  2383. if(($currentY+$gfootheight) < ($pageheight-$bottommargin-$footerheight)){
  2384. $gfoot= $this->showGroupFooter($this->maxpagey['page_'.($this->pdf->getPage()-1)]);
  2385. $checkpoint=$this->maxpagey['page_'.($this->pdf->getNumPages()-1)]+$gfoot;
  2386. }else{
  2387. $gfoot= $this->showGroupFooter($this->maxpagey['page_'.($this->pdf->getPage()-1)]);
  2388. $checkpoint=$this->maxpagey['page_'.($this->pdf->getNumPages()-1)]+$gfoot;
  2389. // $this->pageHeader();
  2390. // $this->pageHeader($this->arrayPageSetting["topMargin"]+$this->arraypageHeader[0]["height"]);
  2391. // $gfoot= $this->showGroupFooter($this->maxpagey['page_'.($this->pdf->getPage()-1)]);
  2392. // $checkpoint=$this->maxpagey['page_'.($this->pdf->getNumPages()-1)]+$gfoot;
  2393. }
  2394. $this->currentband='detail';
  2395. }
  2396. foreach($this->group_count as &$cntval) {
  2397. $cntval++;
  2398. }
  2399. $this->report_count++;
  2400. $this->global_pointer++;
  2401. $rownum++;
  2402. $this->pdf->lastpage();
  2403. $headerY=$checkpoint;
  2404. }
  2405. $this->global_pointer--;
  2406. }else {
  2407. echo "No data found";
  2408. exit(0);
  2409. }
  2410. $this->global_pointer--;
  2411. if($this->arraysummary[0]["height"]>0)
  2412. $this->summary($checkpoint);
  2413. if(isset($this->arraylastPageFooter))
  2414. $this->lastPageFooter();
  2415. else
  2416. $this->pageFooter();
  2417. $this->currentband='';
  2418. }
  2419. /*
  2420. public function detailNewPage() {
  2421. $this->arraydetail[0]["y_axis"]=$this->arraydetail[0]["y_axis"]- $this->titleheight;
  2422. $field_pos_y=$this->arraydetail[0]["y_axis"];
  2423. $biggestY=0;
  2424. $checkpoint=$this->arraydetail[0]["y_axis"];
  2425. $tempY=$this->arraydetail[0]["y_axis"];
  2426. $i=0;
  2427. if($this->arraysqltable) {
  2428. $oo=0;
  2429. foreach($this->arraysqltable as $row) {
  2430. $oo++;
  2431. //check the group's groupExpression existed and same or not
  2432. if(isset($this->arraygroup)&&($this->global_pointer>0)&&($this->arraysqltable[$this->global_pointer][$this->group_pointer]!=$this->arraysqltable[$this->global_pointer-1][$this->group_pointer])) {
  2433. if(isset($this->arrayVariable)) //if self define variable existing, go to do the calculation
  2434. {
  2435. $this->variable_calculation($rownum, $this->arraysqltable[$this->global_pointer][$this->group_pointer]);
  2436. }
  2437. $this->pageFooter();
  2438. $this->pageHeaderNewPage();
  2439. $checkpoint=$this->arraydetail[0]["y_axis"];
  2440. $biggestY = 0;
  2441. $tempY=$this->arraydetail[0]["y_axis"];
  2442. //### $this->group_count=0;
  2443. $this->group_count["$this->group_name"]=1;
  2444. //### End of modification
  2445. }
  2446. foreach($this->arraydetail as $compare) //this loop is to count possible biggest Y of the coming row
  2447. {$this->currentrow=$this->arraysqltable[$this->global_pointer];
  2448. switch($compare["hidden_type"]) {
  2449. case "field":
  2450. $txt=$this->analyse_expression($row["$compare[txt]"]);
  2451. //check group footer existed or not
  2452. if(isset($this->arraygroup[$this->group_name]["groupFooter"])&&(($checkpoint+($compare["height"]*$txt))>($this->arrayPageSetting[pageHeight]-$this->arraygroup["$this->group_name"][groupFooter][0]["height"]-$this->arrayPageSetting["bottomMargin"]))) {
  2453. // $this->showGroupHeader();
  2454. $this->showGroupFooter();
  2455. $this->pageFooter();
  2456. // $this->pdf->AddPage();
  2457. // $this->background();
  2458. $this->pageHeaderNewPage();
  2459. $checkpoint=$this->arraydetail[0]["y_axis"];
  2460. $biggestY=0;
  2461. $tempY=$this->arraydetail[0]["y_axis"];
  2462. }
  2463. //check pagefooter existed or not
  2464. elseif(isset($this->arraypageFooter)&&(($checkpoint+($compare["height"]*($this->NbLines($compare["width"],$txt))))>($this->arrayPageSetting["pageHeight"]-$this->arraypageFooter[0]["height"]-$this->arrayPageSetting["bottomMargin"]))) {
  2465. $this->showGroupFooter();
  2466. $this->pageFooter();
  2467. // $this->pdf->AddPage();
  2468. $this->pageHeaderNewPage();
  2469. // $this->showGroupHeader();
  2470. // $this->background();
  2471. $headerY = $this->arrayPageSetting["topMargin"]+$this->arraypageHeader[0]["height"];
  2472. $checkpoint=$this->arraydetail[0]["y_axis"];
  2473. $biggestY=0;
  2474. $tempY=$this->arraydetail[0]["y_axis"];
  2475. }
  2476. //check lastpagefooter existed or not
  2477. elseif(isset($this->arraylastPageFooter)&&(($checkpoint+($compare["height"]*($this->NbLines($compare["width"],$txt))))>($this->arrayPageSetting["pageHeight"]-$this->arraylastPageFooter[0]["height"]-$this->arrayPageSetting["bottomMargin"]))) {
  2478. $this->showGroupFooter();
  2479. $this->lastPageFooter();
  2480. // $this->pdf->AddPage();
  2481. // $this->background();
  2482. $this->pageHeaderNewPage();
  2483. // $this->showGroupHeader();
  2484. $checkpoint=$this->arraydetail[0]["y_axis"];
  2485. $biggestY=0;
  2486. $tempY=$this->arraydetail[0]["y_axis"];
  2487. }
  2488. if(($checkpoint+($compare["height"]*($this->NbLines($compare["width"],$txt))))>$tempY) {
  2489. $tempY=$checkpoint+($compare["height"]*($this->NbLines($compare["width"],$txt)));
  2490. }
  2491. break;
  2492. case "relativebottomline":
  2493. break;
  2494. case "report_count":
  2495. // $this->report_count++;
  2496. break;
  2497. case "group_count":
  2498. //### $this->group_count++;
  2499. break;
  2500. default:
  2501. $this->display($compare,$checkpoint);
  2502. break;
  2503. }
  2504. }
  2505. if($checkpoint+$this->arraydetail[0]["height"]>($this->arrayPageSetting["pageHeight"]-$this->arraypageFooter[0]["height"]-$this->arrayPageSetting["bottomMargin"])) //check the upcoming band is greater than footer position or not
  2506. {
  2507. $this->pageFooter();
  2508. // $this->pdf->AddPage();
  2509. // $this->background();
  2510. $headerY = $this->arrayPageSetting["topMargin"]+$this->arraypageHeader[0]["height"];
  2511. $this->pageHeaderNewPage();
  2512. // $this->showGroupHeader();
  2513. $checkpoint=$this->arraydetail[0]["y_axis"];
  2514. $biggestY=0;
  2515. $tempY=$this->arraydetail[0]["y_axis"];
  2516. }
  2517. foreach ($this->arraydetail as $out) {
  2518. $this->currentrow=$this->arraysqltable[$this->global_pointer];
  2519. switch ($out["hidden_type"]) {
  2520. case "field":
  2521. $this->prepare_print_array=array("type"=>"MultiCell","width"=>$out["width"],"height"=>$out["height"],"txt"=>$out["txt"],"border"=>$out["border"],"align"=>$out["align"],"fill"=>$out["fill"],"hidden_type"=>$out["hidden_type"],"printWhenExpression"=>$out["printWhenExpression"],"soverflow"=>$out["soverflow"],"poverflow"=>$out["poverflow"],"link"=>$out["link"],"pattern"=>$out["pattern"]);
  2522. $this->display($this->prepare_print_array,0,true);
  2523. if($this->pdf->GetY() > $biggestY) {
  2524. $biggestY = $this->pdf->GetY();
  2525. }
  2526. break;
  2527. case "relativebottomline":
  2528. //$this->relativebottomline($out,$tempY);
  2529. $this->relativebottomline($out,$biggestY);
  2530. break;
  2531. default:
  2532. $this->display($out,$checkpoint);
  2533. //$checkpoint=$this->pdf->GetY();
  2534. break;
  2535. }
  2536. }
  2537. $this->pdf->SetY($biggestY);
  2538. if($biggestY>$checkpoint+$this->arraydetail[0]["height"]) {
  2539. $checkpoint=$biggestY;
  2540. }
  2541. elseif($biggestY<$checkpoint+$this->arraydetail[0]["height"]) {
  2542. $checkpoint=$checkpoint+$this->arraydetail[0]["height"];
  2543. }
  2544. else {
  2545. $checkpoint=$biggestY;
  2546. }
  2547. if(isset($this->arraygroup)&&($this->global_pointer>0)&&($this->arraysqltable[$this->global_pointer][$this->group_pointer]!=$this->arraysqltable[$this->global_pointer+1][$this->group_pointer]))
  2548. $this->showGroupFooter($tempY);
  2549. //if(isset($this->arraygroup)){$this->global_pointer++;}
  2550. $this->global_pointer++;
  2551. }
  2552. }else {
  2553. echo utf8_decode("Sorry cause there is not result from this query.");
  2554. exit(0);
  2555. }
  2556. $this->global_pointer--;
  2557. $rownum++;
  2558. if($this->arraysummary[0]["height"]>0)
  2559. $this->summary();
  2560. if(isset($this->arraylastPageFooter)) {
  2561. // $this->showGroupFooter();
  2562. $this->lastPageFooter();
  2563. }
  2564. else {
  2565. // $this->showGroupFooter();
  2566. $this->pageFooter();
  2567. }
  2568. }
  2569. */
  2570. public function showGroupHeader($y) {
  2571. $this->currentband='groupHeader';
  2572. $bandheight=$this->arraygrouphead[0]['height'];
  2573. foreach ($this->arraygrouphead as $out) {
  2574. $this->display($out,$y,true);
  2575. }
  2576. $this->currentband='';
  2577. return $bandheight;
  2578. }
  2579. public function showGroupFooter($y) {
  2580. $this->currentband='groupFooter';
  2581. //$this->pdf->MultiCell(100,10,"???1-$y,XY=". $this->pdf->GetX().",". $this->pdf->GetY());
  2582. $bandheight=$this->arraygroupfoot[0]['height'];
  2583. foreach ($this->arraygroupfoot as $out) {
  2584. $this->display($out,$y,true);
  2585. }
  2586. $this->footershowed=true;
  2587. $this->currentband='';
  2588. return $bandheight;
  2589. //$this->pdf->MultiCell(100,10,"???1-$y,XY=". $this->pdf->GetX().",". $this->pdf->GetY());
  2590. $this->footershowed=true;
  2591. return $bandheight;
  2592. //$this->pdf->MultiCell(100,10,"???1-$y,XY=". $this->pdf->GetX().",". $this->pdf->GetY());
  2593. }
  2594. public function display($arraydata,$y_axis=0,$fielddata=false,$maxheight=0) {
  2595. //print_r($arraydata);echo "<br/>";
  2596. // $this->pdf->Cell(10,10,"SSSS");
  2597. $this->Rotate($arraydata["rotation"]);
  2598. if($arraydata["rotation"]!=""){
  2599. if($arraydata["rotation"]=="Left"){
  2600. $w=$arraydata["width"];
  2601. $arraydata["width"]=$arraydata["height"];
  2602. $arraydata["height"]=$w;
  2603. $this->pdf->SetXY($this->pdf->GetX()-$arraydata["width"],$this->pdf->GetY());
  2604. }
  2605. elseif($arraydata["rotation"]=="Right"){
  2606. $w=$arraydata["width"];
  2607. $arraydata["width"]=$arraydata["height"];
  2608. $arraydata["height"]=$w;
  2609. $this->pdf->SetXY($this->pdf->GetX(),$this->pdf->GetY()-$arraydata["height"]);
  2610. }
  2611. elseif($arraydata["rotation"]=="UpsideDown"){
  2612. //soverflow"=>$stretchoverflow,"poverflow"
  2613. $arraydata["soverflow"]=true;
  2614. $arraydata["poverflow"]=true;
  2615. // $w=$arraydata["width"];
  2616. // $arraydata["width"]=$arraydata["height"];
  2617. //$arraydata["height"]=$w;
  2618. $this->pdf->SetXY($this->pdf->GetX()- $arraydata["width"],$this->pdf->GetY()-$arraydata["height"]);
  2619. }
  2620. }
  2621. if($arraydata["type"]=="SetFont") {
  2622. if($arraydata["font"]=='uGB')
  2623. $this->pdf->isUnicode=true;
  2624. else
  2625. $this->pdf->isUnicode=false;
  2626. $this->pdf->SetFont($arraydata["font"],$arraydata["fontstyle"],$arraydata["fontsize"]);
  2627. }
  2628. elseif($arraydata["type"]=="subreport") {
  2629. $this->runSubReport($arraydata,$y_axis);
  2630. // $y_axis=$this->SubReportCheckPoint;
  2631. }
  2632. elseif($arraydata["type"]=="MultiCell") {
  2633. if($fielddata==false) {
  2634. $this->checkoverflow($arraydata,$this->updatePageNo($arraydata["txt"]),'',$maxheight);
  2635. }
  2636. elseif($fielddata==true) {
  2637. $this->checkoverflow($arraydata,$this->updatePageNo($this->analyse_expression($arraydata["txt"],$arraydata["isPrintRepeatedValues"] )),$maxheight);
  2638. }
  2639. }
  2640. elseif($arraydata["type"]=="SetXY") {
  2641. $this->pdf->SetXY($arraydata["x"]+$this->arrayPageSetting["leftMargin"],$arraydata["y"]+$y_axis);
  2642. }
  2643. elseif($arraydata["type"]=="Cell") {
  2644. $this->pdf->Cell($arraydata["width"],$arraydata["height"],$this->updatePageNo($arraydata["txt"]),$arraydata["border"],$arraydata["ln"],$arraydata["align"],$arraydata["fill"],$arraydata["link"]);
  2645. }
  2646. elseif($arraydata["type"]=="Rect"){
  2647. if($arraydata['mode']=='Transparent')
  2648. $style='';
  2649. else
  2650. $style='FD';
  2651. $this->pdf->Rect($arraydata["x"]+$this->arrayPageSetting["leftMargin"],$arraydata["y"]+$y_axis,$arraydata["width"],$arraydata["height"],
  2652. $style);
  2653. }
  2654. elseif($arraydata["type"]=="RoundedRect"){
  2655. if($arraydata['mode']=='Transparent')
  2656. $style='';
  2657. else
  2658. $style='FD';
  2659. $this->pdf->RoundedRect($arraydata["x"]+$this->arrayPageSetting["leftMargin"], $arraydata["y"]+$y_axis, $arraydata["width"],$arraydata["height"], $arraydata["radius"], '1111',
  2660. $style,array('color'=>$arraydata['drawcolor']),$arraydata['fillcolor']);
  2661. }
  2662. elseif($arraydata["type"]=="Ellipse"){
  2663. $this->pdf->Ellipse($arraydata["x"]+$arraydata["width"]/2+$this->arrayPageSetting["leftMargin"], $arraydata["y"]+$y_axis+$arraydata["height"]/2, $arraydata["width"]/2,$arraydata["height"]/2,
  2664. 0,0,360,'FD',array('color'=>$arraydata['drawcolor']),$arraydata['fillcolor']);
  2665. }
  2666. elseif($arraydata["type"]=="Image") {
  2667. $path=$this->analyse_expression($arraydata["path"]);
  2668. $imgtype=substr($path,-3);
  2669. if($imgtype=='jpg')
  2670. $imgtype="JPEG";
  2671. if(file_exists($path))
  2672. $this->pdf->Image($path,$arraydata["x"]+$this->arrayPageSetting["leftMargin"],$arraydata["y"]+$y_axis,$arraydata["width"],$arraydata["height"],$imgtype,$arraydata["link"]);
  2673. }
  2674. elseif($arraydata["type"]=="SetTextColor") {
  2675. $this->textcolor_r=$arraydata['r'];
  2676. $this->textcolor_g=$arraydata['g'];
  2677. $this->textcolor_b=$arraydata['b'];
  2678. if($this->hideheader==true && $this->currentband=='pageHeader')
  2679. $this->pdf->SetTextColor(100,33,30);
  2680. else
  2681. $this->pdf->SetTextColor($arraydata["r"],$arraydata["g"],$arraydata["b"]);
  2682. }
  2683. elseif($arraydata["type"]=="SetDrawColor") {
  2684. $this->drawcolor_r=$arraydata['r'];
  2685. $this->drawcolor_g=$arraydata['g'];
  2686. $this->drawcolor_b=$arraydata['b'];
  2687. $this->pdf->SetDrawColor($arraydata["r"],$arraydata["g"],$arraydata["b"]);
  2688. }
  2689. elseif($arraydata["type"]=="SetLineWidth") {
  2690. $this->pdf->SetLineWidth($arraydata["width"]);
  2691. }
  2692. elseif($arraydata["type"]=="Line") {
  2693. $this->pdf->Line($arraydata["x1"]+$this->arrayPageSetting["leftMargin"],$arraydata["y1"]+$y_axis,$arraydata["x2"]+$this->arrayPageSetting["leftMargin"],$arraydata["y2"]+$y_axis);
  2694. }
  2695. elseif($arraydata["type"]=="SetFillColor") {
  2696. $this->fillcolor_r=$arraydata['r'];
  2697. $this->fillcolor_g=$arraydata['g'];
  2698. $this->fillcolor_b=$arraydata['b'];
  2699. $this->pdf->SetFillColor($arraydata["r"],$arraydata["g"],$arraydata["b"]);
  2700. }
  2701. elseif($arraydata["type"]=="lineChart") {
  2702. $this->showLineChart($arraydata, $y_axis);
  2703. }
  2704. elseif($arraydata["type"]=="barChart") {
  2705. $this->showBarChart($arraydata, $y_axis,'barChart');
  2706. }
  2707. elseif($arraydata["type"]=="stackedBarChart") {
  2708. $this->showBarChart($arraydata, $y_axis,'stackedBarChart');
  2709. }
  2710. elseif($arraydata["type"]=="stackedAreaChart") {
  2711. $this->showAreaChart($arraydata, $y_axis,$arraydata["type"]);
  2712. }
  2713. }
  2714. public function relativebottomline($path,$y) {
  2715. $extra=$y-$path["y1"];
  2716. $this->display($path,$extra);
  2717. }
  2718. public function updatePageNo($s) {
  2719. return str_replace('$this->PageNo()', $this->pdf->PageNo(),$s);
  2720. }
  2721. public function staticText($xml_path) {//$this->pointer[]=array("type"=>"SetXY","x"=>$xml_path->reportElement["x"],"y"=>$xml_path->reportElement["y"]);
  2722. }
  2723. public function checkoverflow($arraydata,$txt="",$maxheight=0) {
  2724. $this->print_expression($arraydata);
  2725. if($this->print_expression_result==true) {
  2726. if($arraydata["link"]) {
  2727. $arraydata["link"]=$this->analyse_expression($arraydata["link"],"");
  2728. }
  2729. if($arraydata["writeHTML"]==1 && $this->pdflib=="TCPDF") {
  2730. $this->pdf->writeHTML($txt);
  2731. $this->pdf->Ln();
  2732. if($this->currentband=='detail'){
  2733. if($this->maxpagey['page_'.($this->pdf->getPage()-1)]=='')
  2734. $this->maxpagey['page_'.($this->pdf->getPage()-1)]=$this->pdf->GetY();
  2735. else{
  2736. if($this->maxpagey['page_'.($this->pdf->getPage()-1)]<$this->pdf->GetY())
  2737. $this->maxpagey['page_'.($this->pdf->getPage()-1)]=$this->pdf->GetY();
  2738. }
  2739. }
  2740. }
  2741. elseif($arraydata["poverflow"]=="true"&&$arraydata["soverflow"]=="false") {
  2742. $this->pdf->Cell($arraydata["width"], $arraydata["height"], $this->formatText($txt, $arraydata["pattern"]),$arraydata["border"],"",$arraydata["align"],$arraydata["fill"],$arraydata["link"]);
  2743. $this->pdf->Ln();
  2744. if($this->currentband=='detail'){
  2745. if($this->maxpagey['page_'.($this->pdf->getPage()-1)]=='')
  2746. $this->maxpagey['page_'.($this->pdf->getPage()-1)]=$this->pdf->GetY();
  2747. else{
  2748. if($this->maxpagey['page_'.($this->pdf->getPage()-1)]<$this->pdf->GetY())
  2749. $this->maxpagey['page_'.($this->pdf->getPage()-1)]=$this->pdf->GetY();
  2750. }
  2751. }
  2752. }
  2753. elseif($arraydata["poverflow"]=="false"&&$arraydata["soverflow"]=="false") {
  2754. while($this->pdf->GetStringWidth($txt) > $arraydata["width"]) {
  2755. $txt=substr_replace($txt,"",-1);
  2756. }
  2757. $this->pdf->Cell($arraydata["width"], $arraydata["height"],$this->formatText($txt, $arraydata["pattern"]),
  2758. $arraydata["border"],"",$arraydata["align"],$arraydata["fill"],$arraydata["link"]);
  2759. $this->pdf->Ln();
  2760. if($this->currentband=='detail'){
  2761. if($this->maxpagey['page_'.($this->pdf->getPage()-1)]=='')
  2762. $this->maxpagey['page_'.($this->pdf->getPage()-1)]=$this->pdf->GetY();
  2763. else{
  2764. if($this->maxpagey['page_'.($this->pdf->getPage()-1)]<$this->pdf->GetY())
  2765. $this->maxpagey['page_'.($this->pdf->getPage()-1)]=$this->pdf->GetY();
  2766. }
  2767. }
  2768. }
  2769. elseif($arraydata["poverflow"]=="false"&&$arraydata["soverflow"]=="true") {
  2770. $x=$this->pdf->GetX();
  2771. $this->pdf->MultiCell($arraydata["width"], $arraydata["height"], $this->formatText($txt, $arraydata["pattern"]), $arraydata["border"]
  2772. ,$arraydata["align"], $arraydata["fill"],1,'','',true,0,false,true,$maxheight);
  2773. if( $this->pdf->balancetext=='' && $this->currentband=='detail'){
  2774. if($this->maxpagey['page_'.($this->pdf->getPage()-1)]=='')
  2775. $this->maxpagey['page_'.($this->pdf->getPage()-1)]=$this->pdf->GetY();
  2776. else{
  2777. if($this->maxpagey['page_'.($this->pdf->getPage()-1)]<$this->pdf->GetY())
  2778. $this->maxpagey['page_'.($this->pdf->getPage()-1)]=$this->pdf->GetY();
  2779. }
  2780. }
  2781. //$this->pageFooter();
  2782. if($this->pdf->balancetext!='' ){
  2783. $this->continuenextpageText=array('width'=>$arraydata["width"], 'height'=>$arraydata["height"], 'txt'=>$this->pdf->balancetext,
  2784. 'border'=>$arraydata["border"] ,'align'=>$arraydata["align"], 'fill'=>$arraydata["fill"],'ln'=>1,
  2785. 'x'=>$x,'y'=>'','reset'=>true,'streth'=>0,'ishtml'=>false,'autopadding'=>true);
  2786. $this->pdf->balancetext='';
  2787. $this->forcetextcolor_b=$this->textcolor_b;
  2788. $this->forcetextcolor_g=$this->textcolor_g;
  2789. $this->forcetextcolor_r=$this->textcolor_r;
  2790. $this->forcefillcolor_b=$this->fillcolor_b;
  2791. $this->forcefillcolor_g=$this->fillcolor_g;
  2792. $this->forcefillcolor_r=$this->fillcolor_r;
  2793. if($this->continuenextpageText)
  2794. $this->printlongtext($this->pdf->getFontFamily(),$this->pdf->getFontStyle(),$this->pdf->getFontSize());
  2795. }
  2796. }
  2797. else {
  2798. //MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0) {
  2799. $this->pdf->MultiCell($arraydata["width"], $arraydata["height"], $this->formatText($txt, $arraydata["pattern"]), $arraydata["border"],
  2800. $arraydata["align"], $arraydata["fill"],1,'','',true,0,true,true,$maxheight);
  2801. if( $this->pdf->balancetext=='' && $this->currentband=='detail'){
  2802. if($this->maxpagey['page_'.($this->pdf->getPage()-1)]=='')
  2803. $this->maxpagey['page_'.($this->pdf->getPage()-1)]=$this->pdf->GetY();
  2804. else{
  2805. if($this->maxpagey['page_'.($this->pdf->getPage()-1)]<$this->pdf->GetY())
  2806. $this->maxpagey['page_'.($this->pdf->getPage()-1)]=$this->pdf->GetY();
  2807. }
  2808. }
  2809. if($this->pdf->balancetext!=''){
  2810. $this->continuenextpageText=array('width'=>$arraydata["width"], 'height'=>$arraydata["height"], 'txt'=>$this->pdf->balancetext,
  2811. 'border'=>$arraydata["border"] ,'align'=>$arraydata["align"], 'fill'=>$arraydata["fill"],'ln'=>1,
  2812. 'x'=>$x,'y'=>'','reset'=>true,'streth'=>0,'ishtml'=>false,'autopadding'=>true);
  2813. $this->pdf->balancetext='';
  2814. $this->forcetextcolor_b=$this->textcolor_b;
  2815. $this->forcetextcolor_g=$this->textcolor_g;
  2816. $this->forcetextcolor_r=$this->textcolor_r;
  2817. $this->forcefillcolor_b=$this->fillcolor_b;
  2818. $this->forcefillcolor_g=$this->fillcolor_g;
  2819. $this->forcefillcolor_r=$this->fillcolor_r;
  2820. $this->gotTextOverPage=true;
  2821. if($this->continuenextpageText)
  2822. $this->printlongtext($this->pdf->getFontFamily(),$this->pdf->getFontStyle(),$this->pdf->getFontSize());
  2823. }
  2824. }
  2825. }
  2826. $this->print_expression_result=false;
  2827. }
  2828. public function hex_code_color($value) {
  2829. $r=hexdec(substr($value,1,2));
  2830. $g=hexdec(substr($value,3,2));
  2831. $b=hexdec(substr($value,5,2));
  2832. return array("r"=>$r,"g"=>$g,"b"=>$b);
  2833. }
  2834. public function get_first_value($value) {
  2835. return (substr($value,0,1));
  2836. }
  2837. function right($value, $count) {
  2838. return substr($value, ($count*-1));
  2839. }
  2840. function left($string, $count) {
  2841. return substr($string, 0, $count);
  2842. }
  2843. public function analyse_expression($data,$isPrintRepeatedValue="true") {
  2844. $arrdata=explode("+",$data);
  2845. $i=0;
  2846. foreach($arrdata as $num=>$out) {
  2847. $i++;
  2848. $arrdata[$num]=str_replace('"',"",$out);
  2849. $this->arraysqltable[$this->global_pointer][substr($out,3,-1)];
  2850. if(substr($out,0,3)=='$F{') {
  2851. if($isPrintRepeatedValue=="true" ||$isPrintRepeatedValue=="") {
  2852. $arrdata[$num]=$this->arraysqltable[$this->global_pointer][substr($out,3,-1)];
  2853. }
  2854. else {
  2855. if($this->previousarraydata[$arrdata[$num]]==$this->arraysqltable[$this->global_pointer][substr($out,3,-1)]) {
  2856. $arrdata[$num]="";
  2857. }
  2858. else {
  2859. $arrdata[$num]=$this->arraysqltable[$this->global_pointer][substr($out,3,-1)];
  2860. $this->previousarraydata[$out]=$this->arraysqltable[$this->global_pointer][substr($out,3,-1)];
  2861. }
  2862. }
  2863. // echo $arrdata[$num]."==";
  2864. }
  2865. elseif(substr($out,0,3)=='$V{') {
  2866. //### A new function to handle iReport's "+-/*" expressions.
  2867. // It works like a cheap calculator, without precedences, so 1+2*3 will be 9, NOT 7.
  2868. $p1=3;
  2869. $p2=strpos($out,"}");
  2870. if ($p2!==false){
  2871. $total=&$this->arrayVariable[substr($out,$p1,$p2-$p1)]["ans"];
  2872. $p1=$p2+1;
  2873. while ($p1<strlen($out)){
  2874. if (strpos("+-/*",substr($out,$p1,1))!==false) $opr=substr($out,$p1,1);
  2875. else $opr="";
  2876. $p1=strpos($out,'$V{',$p1)+3;
  2877. $p2=strpos($out,"}",$p1);
  2878. if ($p2!==false){ $nbr=&$this->arrayVariable[substr($out,$p1,$p2-$p1)]["ans"];
  2879. switch ($opr){
  2880. case "+": $total+=$nbr;
  2881. break;
  2882. case "-": $total-=$nbr;
  2883. break;
  2884. case "*": $total*=$nbr;
  2885. break;
  2886. case "/": $total/=$nbr;
  2887. break;
  2888. }
  2889. }
  2890. $p1=$p2+1;
  2891. }
  2892. }
  2893. $arrdata[$num]=$total;
  2894. //### End of modifications, below is the original line.
  2895. // $arrdata[$num]=&$this->arrayVariable[substr($out,3,-1)]["ans"];
  2896. }
  2897. elseif(substr($out,0,3)=='$P{') {
  2898. $arrdata[$num]=$this->arrayParameter[substr($out,3,-1)];
  2899. }
  2900. // echo "<br/>";
  2901. }
  2902. if($this->left($data,3)=='"("' && $this->right($data,3)=='")"') {
  2903. $total=0;
  2904. foreach($arrdata as $num=>$out) {
  2905. if($num>0 && $num<$i)
  2906. $total+=$out;
  2907. }
  2908. return $total;
  2909. }
  2910. else {
  2911. return implode($arrdata);
  2912. }
  2913. }
  2914. public function formatText($txt,$pattern) {
  2915. if($pattern=="###0")
  2916. return number_format($txt,0,"","");
  2917. elseif($pattern=="#,##0")
  2918. return number_format($txt,0,".",",");
  2919. elseif($pattern=="###0.0")
  2920. return number_format($txt,1,".","");
  2921. elseif($pattern=="#,##0.0")
  2922. return number_format($txt,1,".",",");
  2923. elseif($pattern=="###0.00")
  2924. return number_format($txt,2,".","");
  2925. elseif($pattern=="#,##0.00")
  2926. return number_format($txt,2,".",",");
  2927. elseif($pattern=="###0.000")
  2928. return number_format($txt,3,".","");
  2929. elseif($pattern=="#,##0.000")
  2930. return number_format($txt,3,".",",");
  2931. elseif($pattern=="#,##0.0000")
  2932. return number_format($txt,4,".",",");
  2933. elseif($pattern=="###0.0000")
  2934. return number_format($txt,4,".","");
  2935. elseif($pattern=="dd/MM/yyyy" && $txt !="")
  2936. return date("d/m/Y",strtotime($txt));
  2937. elseif($pattern=="MM/dd/yyyy" && $txt !="")
  2938. return date("m/d/Y",strtotime($txt));
  2939. elseif($pattern=="yyyy/MM/dd" && $txt !="")
  2940. return date("Y/m/d",strtotime($txt));
  2941. elseif($pattern=="dd-MMM-yy" && $txt !="")
  2942. return date("d-M-Y",strtotime($txt));
  2943. elseif($pattern=="dd-MMM-yy" && $txt !="")
  2944. return date("d-M-Y",strtotime($txt));
  2945. elseif($pattern=="dd/MM/yyyy h.mm a" && $txt !="")
  2946. return date("d/m/Y h:i a",strtotime($txt));
  2947. elseif($pattern=="dd/MM/yyyy HH.mm.ss" && $txt !="")
  2948. return date("d-m-Y H:i:s",strtotime($txt));
  2949. else
  2950. return $txt;
  2951. }
  2952. public function print_expression($data) {
  2953. $expression=$data["printWhenExpression"];
  2954. $expression=str_replace('$F{','$this->arraysqltable[$this->global_pointer][',$expression);
  2955. $expression=str_replace('$P{','$this->arraysqltable[$this->global_pointer][',$expression);
  2956. $expression=str_replace('$V{','$this->arraysqltable[$this->global_pointer][',$expression);
  2957. $expression=str_replace('}',']',$expression);
  2958. $this->print_expression_result=false;
  2959. if($expression!="") {
  2960. eval('if('.$expression.'){$this->print_expression_result=true;}');
  2961. }
  2962. elseif($expression=="") {
  2963. $this->print_expression_result=true;
  2964. }
  2965. }
  2966. public function runSubReport($d,$current_y) {
  2967. $this->insubReport=1;
  2968. foreach($d["subreportparameterarray"] as $name=>$b) {
  2969. $t = $b->subreportParameterExpression;
  2970. $arrdata=explode("+",$t);
  2971. $i=0;
  2972. foreach($arrdata as $num=>$out) {
  2973. $i++;
  2974. // $arrdata[$num]=str_replace('"',"",$out);
  2975. if(substr($b,0,3)=='$F{') {
  2976. $arrdata2[$name.'']=$this->arraysqltable[$this->global_pointer][substr($b,3,-1)];
  2977. }
  2978. elseif(substr($b,0,3)=='$V{') {
  2979. $arrdata2[$name.'']=&$this->arrayVariable[substr($b,3,-1)]["ans"];
  2980. }
  2981. elseif(substr($b,0,3)=='$P{') {
  2982. $arrdata2[$name.'']=$this->arrayParameter[substr($b,3,-1)];
  2983. }
  2984. }
  2985. $t=implode($arrdata);
  2986. }
  2987. /* if($this->currentband=='pageHeader'){
  2988. $this->includeSubReport($d,$arrdata2,$current_y);
  2989. }
  2990. if($this->currentband=='pageFooter'){
  2991. $this->includeSubReport($d,$arrdata2,$current_y);
  2992. }
  2993. if($this->currentband=='lastPageFooter'){
  2994. $this->includeSubReport($d,$arrdata2,$current_y);
  2995. }
  2996. if($this->currentband=='groupHeader'){
  2997. $this->includeSubReport($d,$arrdata2,$current_y);
  2998. }
  2999. if($this->currentband=='groupFooter'){
  3000. $this->includeSubReport($d,$arrdata2,$current_y);
  3001. }
  3002. if($this->currentband=='summary'){
  3003. $this->includeSubReport($d,$arrdata2,$current_y);
  3004. }
  3005. if($this->currentband=='detail'){
  3006. $this->includeSubReport($d,$arrdata2,$current_y);
  3007. }
  3008. */
  3009. $this->includeSubReport($d,$arrdata2,$current_y);
  3010. $this->insubReport=0;
  3011. }
  3012. public function transferXMLtoArray($fileName) {
  3013. if(!file_exists($fileName))
  3014. echo "File - $fileName does not exist";
  3015. else {
  3016. $xmlAry = $this->xmlobj2arr(simplexml_load_file($fileName));
  3017. foreach($xmlAry[header] as $key => $value)
  3018. $this->arraysqltable["$this->m"]["$key"]=$value;
  3019. foreach($xmlAry[detail][record]["$this->m"] as $key2 => $value2)
  3020. $this->arraysqltable["$this->m"]["$key2"]=$value2;
  3021. }
  3022. // if(isset($this->arrayVariable)) //if self define variable existing, go to do the calculation
  3023. // $this->variable_calculation();
  3024. }
  3025. public function includeSubReport($d,$arrdata,$current_y){
  3026. include_once ("PHPJasperXMLSubReport.inc.php");
  3027. $srxml= simplexml_load_file($d['subreportExpression']);
  3028. $PHPJasperXMLSubReport= new PHPJasperXMLSubReport($this->lang,$this->pdflib,$d['x']);
  3029. $PHPJasperXMLSubReport->arrayParameter=$arrdata;
  3030. $PHPJasperXMLSubReport->debugsql=$this->debugsql;
  3031. $PHPJasperXMLSubReport->xml_dismantle($srxml);
  3032. $this->passAllArrayDatatoSubReport($PHPJasperXMLSubReport,$d,$current_y);
  3033. $PHPJasperXMLSubReport->transferDBtoArray($this->db_host,$this->db_user,$this->db_pass,$this->db_or_dsn_name);
  3034. $PHPJasperXMLSubReport->pdf=$this->pdf;
  3035. $PHPJasperXMLSubReport->outpage(); //page output method I:standard output D:Download file
  3036. $this->SubReportCheckPoint=$PHPJasperXMLSubReport->SubReportCheckPoint;
  3037. $PHPJasperXMLSubReport->MainPageCurrentY=0;
  3038. }
  3039. public function passAllArrayDatatoSubReport($PHPJasperXMLSubReport,$d,$current_y){
  3040. $PHPJasperXMLSubReport->arrayMainPageSetting=$this->arrayPageSetting;
  3041. if(isset($this->arraypageHeader)) {
  3042. $PHPJasperXMLSubReport->arrayPageSetting["subreportpageHeight"]=$PHPJasperXMLSubReport->arrayPageSetting["pageHeight"];
  3043. $PHPJasperXMLSubReport->arrayMainpageHeader=$this->arraypageHeader;
  3044. $PHPJasperXMLSubReport->arrayMainpageFooter=$this->arraypageFooter;
  3045. if($this->currentband=='pageHeader'){ ///here need to add more conditions to fulfill different band subreport
  3046. $PHPJasperXMLSubReport->TopHeightFromMainPage=$PHPJasperXMLSubReport->arrayMainPageSetting["topMargin"]+$d['y'];
  3047. }
  3048. else{
  3049. $PHPJasperXMLSubReport->TopHeightFromMainPage=$PHPJasperXMLSubReport->arrayMainPageSetting["topMargin"]
  3050. +$PHPJasperXMLSubReport->arrayMainpageHeader[0]["height"]+$d['y'];
  3051. }
  3052. ###set different initial Y for subreport of each detail loop of main report
  3053. if($current_y>$PHPJasperXMLSubReport->TopHeightFromMainPage){$PHPJasperXMLSubReport->TopHeightFromMainPage=$current_y+$d['y'];}
  3054. ###
  3055. $PHPJasperXMLSubReport->BottomHeightFromMainPage=$PHPJasperXMLSubReport->arrayMainPageSetting["bottomMargin"]
  3056. +$PHPJasperXMLSubReport->arrayMainpageFooter[0]["height"];
  3057. $PHPJasperXMLSubReport->arrayPageSetting["leftMargin"]=$PHPJasperXMLSubReport->arrayPageSetting["leftMargin"]+$this->arrayPageSetting["leftMargin"];
  3058. ###Set fixed pageHeight constant despite the changes of $PHPJasperXMLSubReport->TopHeightFromMainPage due to subreport in Detail band
  3059. $PHPJasperXMLSubReport->arrayPageSetting["pageHeight"]=$this->arrayPageSetting["pageHeight"]
  3060. -($PHPJasperXMLSubReport->arrayMainPageSetting["topMargin"]
  3061. +$PHPJasperXMLSubReport->arrayMainpageHeader[0]["height"]+$d['y'])
  3062. -$this->arraypageFooter[0]["height"]
  3063. -$PHPJasperXMLSubReport->arrayMainPageSetting["bottomMargin"]-$d['y'];
  3064. ###
  3065. // $PHPJasperXMLSubReport->arrayPageSetting["pageHeight"]=$this->arrayPageSetting["pageHeight"]
  3066. // -$PHPJasperXMLSubReport->TopHeightFromMainPage
  3067. // -$this->arraypageFooter[0]["height"]
  3068. // -$PHPJasperXMLSubReport->arrayMainPageSetting["bottomMargin"]-$d['y'];
  3069. // $PHPJasperXMLSubReport->arrayPageSetting['topMargin']=$PHPJasperXMLSubReport->arrayPageSetting['topMargin']
  3070. // +$PHPJasperXMLSubReport->arrayMainPageSetting["topMargin"]
  3071. // +$PHPJasperXMLSubReport->arrayMainpageHeader[0]["height"];
  3072. // elseif($this->currentband=='detail'){
  3073. //// $PHPJasperXMLSubReport->MainPageCurrentY=$current_y;
  3074. // }
  3075. }
  3076. if(isset($this->arraypageFooter)) {
  3077. $PHPJasperXMLSubReport->arrayMainpageFooter=$this->arraypageFooter;
  3078. }
  3079. if(isset($this->arraygroup)) {
  3080. $PHPJasperXMLSubReport->arrayMaingroup=$this->arraygroup;
  3081. }
  3082. if(isset($this->arraylastPageFooter)) {
  3083. $PHPJasperXMLSubReport->arrayMainlastPageFooter=$this->arraylastPageFooter;
  3084. }
  3085. if(isset($this->arraytitle)) {
  3086. $PHPJasperXMLSubReport->arrayMaintitle=$this->arraytitle;
  3087. }
  3088. }
  3089. //wrote by huzursuz at mailinator dot com on 02-Feb-2009 04:44
  3090. //http://hk.php.net/manual/en/function.get-object-vars.php
  3091. public function xmlobj2arr($Data) {
  3092. if (is_object($Data)) {
  3093. foreach (get_object_vars($Data) as $key => $val)
  3094. $ret[$key] = $this->xmlobj2arr($val);
  3095. return $ret;
  3096. }
  3097. elseif (is_array($Data)) {
  3098. foreach ($Data as $key => $val)
  3099. $ret[$key] = $this->xmlobj2arr($val);
  3100. return $ret;
  3101. }
  3102. else
  3103. return $Data;
  3104. }
  3105. private function Rotate($type, $x=-1, $y=-1)
  3106. {
  3107. if($type=="")
  3108. $angle=0;
  3109. elseif($type=="Left")
  3110. $angle=90;
  3111. elseif($type=="Right")
  3112. $angle=270;
  3113. elseif($type=="UpsideDown")
  3114. $angle=180;
  3115. if($x==-1)
  3116. $x=$this->pdf->getX();
  3117. if($y==-1)
  3118. $y=$this->pdf->getY();
  3119. if($this->angle!=0)
  3120. $this->pdf->_out('Q');
  3121. $this->angle=$angle;
  3122. if($angle!=0)
  3123. {
  3124. $angle*=M_PI/180;
  3125. $c=cos($angle);
  3126. $s=sin($angle);
  3127. $cx=$x*$this->pdf->k;
  3128. $cy=($this->pdf->h-$y)*$this->pdf->k;
  3129. $this->pdf->_out(sprintf('q %.5f %.5f %.5f %.5f %.2f %.2f cm 1 0 0 1 %.2f %.2f cm', $c, $s, -$s, $c, $cx, $cy, -$cx, -$cy));
  3130. }
  3131. }
  3132. }