PageRenderTime 66ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/TEMPLATE/Reports/class/ExportXLS.inc.php

https://bitbucket.org/Lahiru_LCB/sep_wd_07
PHP | 808 lines | 394 code | 138 blank | 276 comment | 42 complexity | c804e8867bb68f4e9ff8f5f2021949cd MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. class ExportXLS{
  3. public $wb;
  4. public $ws;
  5. public $arrayband;
  6. public $arraypageHeader;
  7. public $arraypageFooter;
  8. public $arraydetail;
  9. public $arraybackground;
  10. public $arraytitle;
  11. public $arraysummary;
  12. public $arraygroup;
  13. public $relativex=0;
  14. public $relativey=0;
  15. public $lastrow=0;
  16. public $pageHeight;
  17. public $pageWidth;
  18. public $cols=array();
  19. public $rows=array();
  20. public $vunitmultiply=1;
  21. public $hunitmultiply=0.15;
  22. public $headerbandheight;
  23. public $arraysqltable;
  24. public $global_pointer;
  25. public $detailrowcount;
  26. public $headerrowcount;
  27. public $arrayVariable;
  28. public $arrayParameter;
  29. public $arraygroupfoot;
  30. public $arraygrouphead;
  31. public function ExportXLS($raw,$filename){
  32. include dirname(__FILE__)."/PHPExcel.php";
  33. $this->wb = new PHPExcel();
  34. $this->ws=$this->wb->getActiveSheet(0);
  35. //$this->ws->getStyleByColumnAndRow($pColumn, $pRow)->getFill()->getStartColor()
  36. $this->arrayband=$raw->arrayband;
  37. $this->arraypageHeader=$raw->arraypageHeader;
  38. $this->arraypageFooter=$raw->arraypageFooter;
  39. $this->arraydetail=$raw->arraydetail;
  40. $this->arraybackground=$raw->arraybackground;
  41. $this->arraytitle=$raw->arraytitle;
  42. $this->arraysummary=$raw->arraysummary;
  43. $this->arraygroup=$raw->arraygroup;
  44. $this->arraylastPageFooter=$raw->arraylastPageFooter;
  45. //$this->arraypageFooter=$raw->arraypageFooter;
  46. $this->headerbandheight=$raw->headerbandheight;
  47. $this->arraysqltable=$raw->arraysqltable;
  48. $this->pageWidth=$raw->arrayPageSetting['pageWidth'];
  49. $this->pageHeight=$raw->pageHeight;
  50. $this->arrayVariable=$raw->arrayVariable;
  51. $this->arrayParameter=$raw->arrayParameter;
  52. $this->arraygroupfoot=$raw->arraygroupfoot;
  53. $this->arraygrouphead=$raw->arraygrouphead;
  54. /*
  55. $this->xls =& $this->workbook->addWorksheet('Sheet1');
  56. $this->xls->setMarginLeft($raw->arrayPageSetting["leftMargin"]);
  57. $this->xls->setMarginRight($raw->arrayPageSetting["rightMargin"]);
  58. $this->xls->setMarginTop($raw->arrayPageSetting["topMargin"]);
  59. $this->xls->setMarginBottom($raw->arrayPageSetting["bottomMargin"]);
  60. */
  61. $this->global_pointer=0;
  62. $this->arrangeColumn();
  63. foreach ($raw->arrayband as $band) {
  64. // $this->currentband=$band["name"]; // to know current where current band in!
  65. switch($band["name"]) {
  66. case "title":
  67. if($raw->arraytitle[0]["height"]>0){
  68. $this->title();
  69. // echo "end title<br/><br/>";
  70. }
  71. break;
  72. case "pageHeader":
  73. if($raw->arraypageHeader[0]["height"]>0){
  74. $this->pageHeader();
  75. // echo "end header<hr>";
  76. }
  77. break;
  78. case "detail":
  79. if($raw->arraydetail[0]["height"]>0){
  80. $this->detail();
  81. // echo "end detail<br/><br/>";
  82. }
  83. break;
  84. case "pageFooter":
  85. if($raw->arraylastPageFooter[0]["height"]==0 && $raw->arraypageFooter[0]["height"]>0){
  86. $this->pageFooter();
  87. // echo "end detail<br/><br/>";
  88. }
  89. break;
  90. case "lastPageFooter":
  91. if($raw->arraylastPageFooter[0]["height"]>0){
  92. $this->lastPageFooter();
  93. // echo "end detail<br/><br/>";
  94. }
  95. break;
  96. case "summary":
  97. if($raw->arraysummary[0]["height"]>0){
  98. $this->summary();
  99. // echo "end detail<br/><br/>";
  100. }
  101. break;
  102. case "group":
  103. $this->group_pointer=$band["groupExpression"];
  104. $this->group_name=$band["gname"];
  105. break;
  106. default:
  107. break;
  108. }
  109. }
  110. // die;
  111. // Redirect output to a clientâ&#x20AC;&#x2122;s web browser (Excel2007)
  112. if($filename=='')
  113. $filename="report.xls";
  114. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  115. header('Content-Disposition: inline;attachment;filename="'.$filename.'"');
  116. header('Cache-Control: max-age=0');
  117. $objWriter = PHPExcel_IOFactory::createWriter($this->wb, 'Excel5');
  118. $objWriter->save('php://output');
  119. }
  120. public function arrangeColumn(){
  121. $cols=array();
  122. $cx=0;
  123. foreach($this->arraypageHeader as $out){
  124. // print_r($out);echo "<hr>";
  125. if($out['type']=="SetXY"){
  126. $cols[]=intval($out['x']);
  127. $cx=intval($out['x']);
  128. }
  129. if($out['type']=="Cell" ||$out['type']=="MultiCell"){
  130. $cols[]=intval($out['width'] + $cx);
  131. // echo $out['width']." + $cx <hr>";
  132. }
  133. //print_r($cols);echo "<hr>";
  134. }
  135. $i=0;
  136. foreach($this->arraydetail as $out){
  137. if($out['type']=="SetXY"){
  138. $cols[]=intval($out['x']);
  139. $cx=intval($out['x']);
  140. }
  141. if($out['type']=="Cell" ||$out['type']=="MultiCell"){
  142. $cols[]=intval($out['width'] + $cx);
  143. //echo $out['width']." + $cx <hr>";
  144. }
  145. // echo $i.".".$out['type']."=",$out['x'].$out['txt'].":"; print_r($cols);echo "<hr>";
  146. $i++;
  147. }
  148. foreach($this->arraygrouphead as $out){
  149. // print_r($out);echo "<hr>";
  150. if($out['type']=="SetXY"){
  151. $cols[]=intval($out['x']);
  152. $cx=intval($out['x']);
  153. }
  154. if($out['type']=="Cell" ||$out['type']=="MultiCell"){
  155. $cols[]=intval($out['width'] + $cx);
  156. // echo $out['width']." + $cx <hr>";
  157. }
  158. //print_r($cols);echo "<hr>";
  159. }
  160. foreach($this->arraygroupfooter as $out){
  161. // print_r($out);echo "<hr>";
  162. if($out['type']=="SetXY"){
  163. $cols[]=intval($out['x']);
  164. $cx=intval($out['x']);
  165. }
  166. if($out['type']=="Cell" ||$out['type']=="MultiCell"){
  167. $cols[]=intval($out['width'] + $cx);
  168. // echo $out['width']." + $cx <hr>";
  169. }
  170. //print_r($cols);echo "<hr>";
  171. }
  172. foreach($this->arraypageFooter as $out){
  173. // print_r($out);echo "<hr>";
  174. if($out['type']=="SetXY"){
  175. $cols[]=intval($out['x']);
  176. $cx=intval($out['x']);
  177. }
  178. if($out['type']=="Cell" ||$out['type']=="MultiCell"){
  179. $cols[]=intval($out['width'] + $cx);
  180. // echo $out['width']." + $cx <hr>";
  181. }
  182. //print_r($cols);echo "<hr>";
  183. }
  184. foreach($this->arraylastPageFooter as $out){
  185. // print_r($out);echo "<hr>";
  186. if($out['type']=="SetXY"){
  187. $cols[]=intval($out['x']);
  188. $cx=intval($out['x']);
  189. }
  190. if($out['type']=="Cell" ||$out['type']=="MultiCell"){
  191. $cols[]=intval($out['width'] + $cx);
  192. // echo $out['width']." + $cx <hr>";
  193. }
  194. //print_r($cols);echo "<hr>";
  195. }
  196. // print_r($cols);echo "<hr>";
  197. $cols=array_unique($cols);
  198. sort($cols);
  199. $i=0;
  200. foreach($cols as $index => $xposition){
  201. $nextxposition=$cols[($i+1)];
  202. if($nextxposition=="")
  203. $nextxposition=$this->pageWidth;
  204. // echo " $index ($nextxposition-$xposition)";echo "<hr>";
  205. $this->ws->getColumnDimensionByColumn($index)->setWidth($this->hunitmultiply*($nextxposition-$xposition));
  206. $this->cols=array_merge($this->cols, array("c".$xposition=>$i));
  207. $i++;
  208. }
  209. }
  210. public function arrangeRows($myband,$debug){
  211. $this->rows=array();
  212. $rows=array();
  213. $ch=0;
  214. foreach($myband as $out){
  215. // print_r($out);echo "<hr>";
  216. if($out['type']=="SetXY"){
  217. $rows[]=intval($out['y']);
  218. $ch=intval($out['y']);
  219. }
  220. if($out['type']=="Cell" ||$out['type']=="MultiCell"){
  221. $rows[]=intval($out['height'] + $ch);
  222. }
  223. }
  224. $rows[]=intval($myband[0]['height']);
  225. $rows=array_unique($rows);
  226. sort($rows);
  227. // print_r($rows);echo "<hr>";
  228. $i=1;
  229. foreach($rows as $index => $yposition){
  230. $nextyposition=$rows[($i+1)];
  231. //if($nextyposition=="")
  232. // $nextyposition=30;
  233. $this->ws->getRowDimension($index+ $this->lastrow)->setRowHeight($this->vunitmultiply*($nextyposition-$yposition));
  234. $this->rows=array_merge($this->rows, array("r".$yposition=>$i));
  235. $i++;
  236. }
  237. //echo "step2:";print_r($this->rows);
  238. $this->lastrow=$i+$this->lastrow;
  239. return ($i-2);
  240. }
  241. public function title(){
  242. $this->titlerowcount=$this->arrangeRows($this->arraytitle,true);
  243. $i=0;
  244. foreach($this->arraytitle as $out){
  245. $this->display($out,$this->maxrow,false);
  246. $i++;
  247. }
  248. $this->maxrow+=$this->titlerowcount;
  249. }
  250. public function pageHeader(){
  251. $this->headerrowcount= $this->arrangeRows($this->arraypageHeader);
  252. $this->maxrow=$this->headerrowcount;
  253. foreach($this->arraypageHeader as $out){
  254. $this->display($out,0);
  255. }
  256. // $this->lastrow--;
  257. // echo "header:".$this->lastrow;echo "<hr>";
  258. }
  259. public function detail(){
  260. $this->detailrowcount=$this->arrangeRows($this->arraydetail);
  261. $this->groupheadrowcount=$this->arrangeRows($this->arraygrouphead);
  262. $this->groupfootrowcount=$this->arrangeRows($this->arraygroupfoot);
  263. $i=0;
  264. $this->showGroupHeader();
  265. $this->maxrow+=$this->groupheadrowcount;
  266. $isgroupfooterprinted=false;
  267. foreach($this->arraysqltable as $row){
  268. $this->variable_calculation($i, $this->arraysqltable[$this->global_pointer][$this->group_pointer]);
  269. if($this->global_pointer>0&&
  270. ($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
  271. if($isgroupfooterprinted==true)
  272. $gfoot=0;
  273. /*
  274. * if($i>0){
  275. $this->showGroupFooter();
  276. $this->maxrow+=$this->groupfootrowcount+2;
  277. }
  278. *
  279. */
  280. $this->showGroupHeader();
  281. $this->maxrow+=$this->groupheadrowcount;
  282. $isgroupfooterprinted=false;
  283. $this->footershowed=false;
  284. $this->group_count["$this->group_name"]=1; // We're on the first row of the group.
  285. }//finish check new group
  286. $this->currentband='detail';
  287. foreach($this->arraydetail as $out){
  288. //($this->headerrowcount+($this->detailrowcount*$i)
  289. $this->display($out,$this->maxrow);
  290. }
  291. $this->maxrow+=$this->detailrowcount;
  292. if($this->global_pointer>0&&
  293. ($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
  294. if($isgroupfooterprinted==true)
  295. $gfoot=0;
  296. if($i>0){
  297. $this->showGroupFooter();
  298. $this->maxrow+=$this->groupfootrowcount+1;
  299. }
  300. $isgroupfooterprinted=true;
  301. $this->footershowed=true;
  302. $this->group_count["$this->group_name"]=1; // We're on the first row of the group.
  303. }//finish check new group
  304. foreach($this->group_count as &$cntval) {
  305. $cntval++;
  306. }
  307. $this->report_count++;
  308. $this->global_pointer++;
  309. $i++;
  310. }
  311. //$this->showGroupFooter();
  312. // $this->maxrow+=$this->groupfootrowcount+2;
  313. }
  314. public function showGroupHeader() {
  315. $this->currentband='groupHeader';
  316. $bandheight=$this->arraygrouphead[0]['height'];
  317. // $this->grouheadrowcount=$this->arrangeRows($this->arraygrouphead);
  318. $this->groufootrowcount=$this->arrangeRows($this->arraygroupfoot);
  319. //$this->arrangeRows($this->arraygroupfoot);
  320. foreach ($this->arraygrouphead as $out) {
  321. $this->display($out,$this->maxrow);
  322. }
  323. }
  324. public function showGroupFooter() {
  325. $this->currentband='groupFooter';
  326. $bandheight=$this->arraygroupfoot[0]['height'];
  327. foreach ($this->arraygroupfoot as $out) {
  328. $this->display($out,$this->maxrow);
  329. }
  330. $this->currentband='';
  331. }
  332. public function pageFooter(){
  333. $this->footerrowcount=$this->arrangeRows($this->arraypageFooter);
  334. foreach($this->arraypageFooter as $out){
  335. $this->display($out,$this->maxrow);
  336. }
  337. $this->maxrow+=$this->footerrowcount;
  338. }
  339. public function lastPageFooter(){
  340. //print_r($this->arraylastPageFooter);echo "<hr>lastpage footer";
  341. $this->lastfooterrowcount=$this->arrangeRows($this->arraylastPageFooter,true);
  342. $i=0;
  343. foreach($this->arraylastPageFooter as $out){
  344. $this->display($out,$this->maxrow,false);
  345. $i++;
  346. }
  347. $this->maxrow+=$this->lastfooterrowcount;
  348. }
  349. public function summary(){
  350. $this->summaryrowcount=$this->arrangeRows($this->arraysummary);
  351. foreach($this->arraysummary as $out){
  352. $this->display($out,$this->lastrow);
  353. }
  354. $this->maxrow+=$this->summaryrowcount;
  355. }
  356. public function display($arraydata,$rowpos,$debug){
  357. if($debug==true){
  358. print_r($arraydata);echo "<hr>";
  359. }
  360. switch($arraydata['type']){
  361. case "MultiCell":
  362. // echo 'start1';
  363. if($this->relativey=="")
  364. $this->relativey=0;
  365. //echo "$this->relativex,
  366. // ($this->relativey+$rowpos),".
  367. //$this->analyse_expression($arraydata['txt'])."<hr>";
  368. // echo "$this->relativex,
  369. // ($this->relativey+$rowpos), ".
  370. // $this->cols['c'.($this->mergex+$arraydata['width'])].",".
  371. // "($this->relativey+$rowpos-1)".$this->analyse_expression($arraydata['txt'])."<hr/>";
  372. // if($debug==true)
  373. // echo 'start2'.$this->relativex .",".
  374. // "($this->relativey+$rowpos), ".
  375. // "(".$this->cols['c'.($this->mergex+$arraydata['width'])]."-1),".
  376. // " ($this->relativey+$rowpos)"
  377. ;
  378. $this->ws->mergeCellsByColumnAndRow(
  379. $this->relativex,
  380. ($this->relativey+$rowpos),
  381. ($this->cols['c'.($this->mergex+$arraydata['width'])]-1),
  382. ($this->relativey+$rowpos)
  383. );
  384. // echo 'start3';
  385. $txt=$this->analyse_expression($arraydata['txt']);
  386. //if($arraydata['pattern']!='pattern')
  387. // $txt= $this->formatText ($txt, $arraydata['pattern']);
  388. //echo 'start4';
  389. $this->ws->setCellValueByColumnAndRow($this->relativex,
  390. ($this->relativey+$rowpos),$txt);
  391. //echo 'start5';
  392. if($arraydata['align']=='C')
  393. $this->ws->getStyleByColumnAndRow($this->relativex, ($this->relativey+$rowpos))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  394. elseif($arraydata['align']=='R')
  395. $this->ws->getStyleByColumnAndRow($this->relativex, ($this->relativey+$rowpos))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  396. else
  397. $this->ws->getStyleByColumnAndRow($this->relativex, ($this->relativey+$rowpos))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  398. //echo PHPExcel_Style_Alignment::HORIZONTAL_RIGHT ."<hr>";
  399. break;
  400. case "Cell":
  401. //echo "$this->relativex,".
  402. // ($this->relativey+$this->rows['r'.$rowpos]).",".
  403. // $this->analyse_expression($arraydata['txt'])."<hr>";
  404. $this->ws->setCellValueByColumnAndRow($this->relativex,
  405. ($this->relativey+$rowpos),$this->analyse_expression($arraydata['txt']));
  406. break;
  407. case "SetXY":
  408. $this->relativex=$this->cols['c'.intval($arraydata['x'])];
  409. $this->relativey=$this->rows['r'.intval($arraydata['y'])];
  410. $this->mergex=$arraydata['x'];
  411. $this->mergey=$arraydata['y'];
  412. // echo $this->relativey .'-'. $arraydata['y'];
  413. break;
  414. case "SetFont":
  415. $f=$this->ws->getStyleByColumnAndRow($this->relativex, ($this->relativey+$rowpos))->getFont();
  416. $f->setName($arraydata['font'].'');
  417. $f-> setSize(intVal($arraydata["fontsize"]));
  418. if(strpos($arraydata['fontstyle'],'B')>0)
  419. $f->setBold(true);
  420. else
  421. $f->setBold(false);
  422. if(strpos($arraydata['fontstyle'],'U')>0)
  423. $f->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
  424. else
  425. $f->setUnderline(PHPExcel_Style_Font::UNDERLINE_NONE);
  426. if(strpos($arraydata['fontstyle'],'I')>0)
  427. $f->setItalic(true);
  428. else
  429. $f->setItalic(false);
  430. break;
  431. case "SetTextColor":
  432. //echo PHPExcel_Style_Color::COLOR_RED;
  433. $cl= str_replace('#','',$arraydata['forecolor']);
  434. if($cl!=''){
  435. $this->ws->getStyleByColumnAndRow($this->relativex, ($this->relativey+$rowpos))->getFont()->getColor()->setARGB("FF".$cl);
  436. }
  437. break;
  438. case "SetFillColor":
  439. $cl= str_replace('#','',$arraydata['backcolor']);
  440. if($cl!=''){
  441. $this->ws->getStyleByColumnAndRow($this->relativex, ($this->relativey+$rowpos))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
  442. $this->ws->getStyleByColumnAndRow($this->relativex, ($this->relativey+$rowpos))->getFill()->getStartColor()->setARGB('FF'.$cl);
  443. }
  444. break;
  445. case "Line":
  446. break;
  447. case "SetLineWidth":
  448. break;
  449. case "SetDrawColor":
  450. break;
  451. case "SetFillColor":
  452. break;
  453. }
  454. }
  455. public function analyse_expression($data) {
  456. $arrdata=explode("+",$data);
  457. $i=0;
  458. foreach($arrdata as $num=>$out) {
  459. $i++;
  460. $arrdata[$num]=str_replace('"',"",$out);
  461. $this->arraysqltable[$this->global_pointer][substr($out,3,-1)];
  462. if($out == 'new java.util.Date()'){
  463. $arrdata[$num]=date("Y-m-d H:i:s");
  464. }
  465. if(substr($out,0,3)=='$F{') {
  466. $arrdata[$num]=$this->arraysqltable[$this->global_pointer][substr($out,3,-1)];
  467. }
  468. elseif(substr($out,0,3)=='$V{') {
  469. //### A new function to handle iReport's "+-/*" expressions.
  470. // It works like a cheap calculator, without precedences, so 1+2*3 will be 9, NOT 7.
  471. $p1=3;
  472. $p2=strpos($out,"}");
  473. if ($p2!==false){
  474. $total=&$this->arrayVariable[substr($out,$p1,$p2-$p1)]["ans"];
  475. $p1=$p2+1;
  476. while ($p1<strlen($out)){
  477. if (strpos("+-/*",substr($out,$p1,1))!==false) $opr=substr($out,$p1,1);
  478. else $opr="";
  479. $p1=strpos($out,'$V{',$p1)+3;
  480. $p2=strpos($out,"}",$p1);
  481. if ($p2!==false){ $nbr=&$this->arrayVariable[substr($out,$p1,$p2-$p1)]["ans"];
  482. switch ($opr){
  483. case "+": $total+=$nbr;
  484. break;
  485. case "-": $total-=$nbr;
  486. break;
  487. case "*": $total*=$nbr;
  488. break;
  489. case "/": $total/=$nbr;
  490. break;
  491. }
  492. }
  493. $p1=$p2+1;
  494. }
  495. }
  496. $arrdata[$num]=$total;
  497. //### End of modifications, below is the original line.
  498. // $arrdata[$num]=&$this->arrayVariable[substr($out,3,-1)]["ans"];
  499. }
  500. elseif(substr($out,0,3)=='$P{') {
  501. $arrdata[$num]=$this->arrayParameter[substr($out,3,-1)];
  502. }
  503. // echo "<br/>";
  504. }
  505. if($this->left($data,3)=='"("' && $this->right($data,3)=='")"') {
  506. $total=0;
  507. foreach($arrdata as $num=>$out) {
  508. if($num>0 && $num<$i)
  509. $total+=$out;
  510. }
  511. return $total;
  512. }
  513. else {
  514. return implode($arrdata);
  515. }
  516. }
  517. function right($value, $count) {
  518. return substr($value, ($count*-1));
  519. }
  520. function left($string, $count) {
  521. return substr($string, 0, $count);
  522. }
  523. public function variable_calculation($rowno) {
  524. // $this->variable_calculation($rownum, $this->arraysqltable[$this->global_pointer][$this->group_pointer]);
  525. // print_r($this->arraysqltable);
  526. foreach($this->arrayVariable as $k=>$out) {
  527. // echo $out['resetType']. "<br/><br/>";
  528. switch($out["calculation"]) {
  529. case "Sum":
  530. $value=$this->arrayVariable[$k]["ans"];
  531. if($out['resetType']==''){
  532. if(isset($this->arrayVariable[$k]['class'])&&$this->arrayVariable[$k]['class']=="java.sql.Time") {
  533. // foreach($this->arraysqltable as $table) {
  534. $value=$this->time_to_sec($value);
  535. $value+=$this->time_to_sec($this->arraysqltable[$rowno]["$out[target]"]);
  536. //$sum=$sum+substr($table["$out[target]"],0,2)*3600+substr($table["$out[target]"],3,2)*60+substr($table["$out[target]"],6,2);
  537. // }
  538. //$sum= floor($sum / 3600).":".floor($sum%3600 / 60);
  539. //if($sum=="0:0"){$sum="00:00";}
  540. $value=$this->sec_to_time($value);
  541. }
  542. else {
  543. // foreach($this->arraysqltable as $table) {
  544. $value+=$this->arraysqltable[$rowno]["$out[target]"];
  545. // $table[$out["target"]];
  546. // }
  547. }
  548. }// finisish resettype=''
  549. else //reset type='group'
  550. {if( $this->arraysqltable[$this->global_pointer][$this->group_pointer]!=$this->arraysqltable[$this->global_pointer-1][$this->group_pointer])
  551. $value=0;
  552. // 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]"];
  553. if(isset($this->arrayVariable[$k]['class'])&&$this->arrayVariable[$k]['class']=="java.sql.Time") {
  554. $value+=$this->time_to_sec($this->arraysqltable[$rowno]["$out[target]"]);
  555. //$sum= floor($sum / 3600).":".floor($sum%3600 / 60);
  556. //if($sum=="0:0"){$sum="00:00";}
  557. $value=$this->sec_to_time($value);
  558. }
  559. else {
  560. $value+=$this->arraysqltable[$rowno]["$out[target]"];
  561. }
  562. }
  563. $this->arrayVariable[$k]["ans"]=$value;
  564. // echo ",$value<br/>";
  565. break;
  566. case "Average":
  567. $sum=0;
  568. if(isset($this->arrayVariable[$k]['class'])&&$this->arrayVariable[$k]['class']=="java.sql.Time") {
  569. $m=0;
  570. //$value=$this->arrayVariable[$k]["ans"];
  571. //$value=$this->time_to_sec($value);
  572. //$value+=$this->time_to_sec($this->arraysqltable[$rowno]["$out[target]"]);
  573. foreach($this->arraysqltable as $table) {
  574. $m++;
  575. $sum=$sum+$this->time_to_sec($table["$out[target]"]);
  576. // echo ",".$table["$out[target]"]."<br/>";
  577. }
  578. $sum=$this->sec_to_time($sum/$m);
  579. // echo "Total:".$sum."<br/>";
  580. $this->arrayVariable[$k]["ans"]=$sum;
  581. }
  582. else {
  583. $this->arrayVariable[$k]["ans"]=$sum;
  584. $m=0;
  585. foreach($this->arraysqltable as $table) {
  586. $m++;
  587. $sum=$sum+$table["$out[target]"];
  588. }
  589. $this->arrayVariable[$k]["ans"]=$sum/$m;
  590. }
  591. break;
  592. case "DistinctCount":
  593. break;
  594. case "Lowest":
  595. foreach($this->arraysqltable as $table) {
  596. $lowest=$table[$out["target"]];
  597. if($table[$out["target"]]<$lowest) {
  598. $lowest=$table[$out["target"]];
  599. }
  600. $this->arrayVariable[$k]["ans"]=$lowest;
  601. }
  602. break;
  603. case "Highest":
  604. $out["ans"]=0;
  605. foreach($this->arraysqltable as $table) {
  606. if($table[$out["target"]]>$out["ans"]) {
  607. $this->arrayVariable[$k]["ans"]=$table[$out["target"]];
  608. }
  609. }
  610. break;
  611. //### A Count for groups, as a variable. Not tested yet, but seemed to work in print_r()
  612. case "Count":
  613. $value=$this->arrayVariable[$k]["ans"];
  614. if( $this->arraysqltable[$this->global_pointer][$this->group_pointer]!=$this->arraysqltable[$this->global_pointer-1][$this->group_pointer])
  615. $value=0;
  616. $value++;
  617. $this->arrayVariable[$k]["ans"]=$value;
  618. break;
  619. //### End of modification
  620. default:
  621. $out["target"]=0; //other cases needed, temporary leave 0 if not suitable case
  622. break;
  623. }
  624. }
  625. }
  626. }