PageRenderTime 62ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/mcmis/reportico/swoutput.php

http://mcmis.googlecode.com/
PHP | 2671 lines | 2629 code | 10 blank | 32 comment | 4 complexity | 7204378dc67e4f3523a6587627bcf9fa MD5 | raw file
Possible License(s): LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. Reportico - PHP Reporting Tool
  4. Copyright (C) 2010-2011 Peter Deed
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. * File: reportico.php
  17. *
  18. * Base class for all report output formats.
  19. * Defines base functionality for handling report
  20. * page headers, footers, group headers, group trailers
  21. * data lines
  22. *
  23. * @link http://www.reportico.org/
  24. * @copyright 2010-2011 Peter Deed
  25. * @author Peter Deed <info@reportico.org>
  26. * @package Reportico
  27. * @version $Id: swoutput.php,v 1.7 2011-10-14 10:49:17 root Exp $
  28. */
  29. class reportico_report extends reportico_object
  30. {
  31. var $query_set = array();
  32. var $document;
  33. var $report_file = "";
  34. var $page_width;
  35. var $page_height;
  36. var $page_length = 65;
  37. var $page_count = 0;
  38. var $page_line_count = 0;
  39. var $line_count = 0;
  40. var $page_number;
  41. var $columns;
  42. var $last_line = false;
  43. var $query;
  44. var $reporttitle;
  45. var $body_display = "show";
  46. var $graph_display = "show";
  47. var $text = "";
  48. var $attributes = array (
  49. "TopMargin" => "4%",
  50. "BottomMargin" => "2%",
  51. "RightMargin" => "5%",
  52. "LeftMargin" => "5%",
  53. "BodyStart" => "10%",
  54. "BodyEnd" => "10%",
  55. "ReportTitle" => "Set Report Title"
  56. );
  57. function reportico_report()
  58. {
  59. reportico_object::reportico_object();
  60. $this->formats = array(
  61. "body_style" => "blankline",
  62. "after_header" => "blankline",
  63. "before_trailer" => "blankline",
  64. "after_trailer" => "blankline"
  65. );
  66. }
  67. function reportico_string_to_php($in_string)
  68. {
  69. // first change '(colval)' parameters
  70. $out_string = $in_string;
  71. if ( preg_match_all( "/{([^}]*)/", $out_string, $matches ) )
  72. {
  73. foreach ( $matches[1] as $match )
  74. {
  75. $first = substr($match, 0, 1);
  76. if ( $first == "=" )
  77. {
  78. $crit = substr ( $match, 1 );
  79. $out_string = preg_replace("/\{$match\}/",
  80. $this->query->lookup_queries[$crit]->
  81. get_criteria_clause(false,false,true),
  82. $out_string);
  83. }
  84. }
  85. }
  86. if ( preg_match("/date\((.*)\)/", $out_string, $match) )
  87. {
  88. $dt = preg_replace("/[\"']/", "", date($match[1]));
  89. $out_string = preg_replace("/date\(.*\)/i", "$dt", $out_string);
  90. }
  91. $out_string = preg_replace('/date("\(.*\)")/', "$this->page_count",
  92. $out_string);
  93. $out_string = preg_replace('/pageno\(\)/', "$this->page_count",
  94. $out_string);
  95. $out_string = preg_replace('/page\(\)/', "$this->page_count",
  96. $out_string);
  97. $out_string = preg_replace('/{page}/', "$this->page_count",
  98. $out_string);
  99. $out_string = preg_replace('/{#page}/', "$this->page_count",
  100. $out_string);
  101. $out_string = preg_replace('/{title}/', $this->reporttitle,
  102. $out_string);
  103. return($out_string);
  104. }
  105. function set_query (&$query)
  106. {
  107. $this->query =& $query;
  108. $this->columns =& $query->columns;
  109. }
  110. function set_columns (&$columns)
  111. {
  112. $this->columns =& $columns;
  113. }
  114. function start ()
  115. {
  116. $this->body_display = $this->query->derive_attribute( "bodyDisplay", "show" );
  117. $this->graph_display = $this->query->derive_attribute( "graphDisplay", "show" );
  118. $this->page_line_count = 0;
  119. $this->line_count = 0;
  120. $this->page_count = 0;
  121. $this->debug("Base Start **");
  122. $this->reporttitle = $this->query->derive_attribute("ReportTitle",
  123. "Set Report Title");
  124. $pos = 5;
  125. }
  126. function finish ()
  127. {
  128. $this->last_line = true;
  129. $this->debug("Base finish");
  130. $this->after_group_trailers();
  131. if ( $this->page_count > 0 )
  132. $this->finish_page();
  133. }
  134. function begin_page()
  135. {
  136. $this->debug("Base New Page");
  137. $this->page_count ++;
  138. $this->page_line_count = 0;
  139. }
  140. function before_format_criteria_selection()
  141. {
  142. }
  143. function format_criteria_selection_set()
  144. {
  145. if ( get_request_item("target_show_criteria") )
  146. {
  147. $this->before_format_criteria_selection();
  148. foreach ( $this->query->lookup_queries as $name => $crit)
  149. {
  150. $label = "";
  151. $value = "";
  152. if ( get_request_item($name."_FROMDATE_DAY", "" ) )
  153. {
  154. $label = $crit->derive_attribute("column_title", $crit->query_name);
  155. $label = sw_translate($label);
  156. $mth = get_request_item($name."_FROMDATE_MONTH","") + 1;
  157. $value = get_request_item($name."_FROMDATE_DAY","")."/".
  158. $mth."/".
  159. get_request_item($name."_FROMDATE_YEAR","");
  160. if ( get_request_item($name."_TODATE_DAY", "" ) )
  161. {
  162. $mth = get_request_item($name."_TODATE_MONTH","") + 1;
  163. $value .= "-";
  164. $value .= get_request_item($name."_TODATE_DAY","")."/".
  165. $mth."/".
  166. get_request_item($name."_TODATE_YEAR","");
  167. }
  168. }
  169. else if ( get_request_item("HIDDEN_".$name."_FROMDATE", "" ) )
  170. {
  171. $label = $crit->derive_attribute("column_title", $crit->query_name);
  172. $label = sw_translate($label);
  173. $value = get_request_item("HIDDEN_".$name."_FROMDATE","");
  174. if ( get_request_item("HIDDEN_".$name."_TODATE", "" ) )
  175. {
  176. $value .= "-";
  177. $value .= get_request_item("HIDDEN_".$name."_TODATE");
  178. }
  179. }
  180. else if ( get_request_item("MANUAL_".$name, "" ) )
  181. {
  182. $label = $crit->derive_attribute("column_title", $crit->query_name);
  183. $label = sw_translate($label);
  184. $value = get_request_item("MANUAL_".$name."_FROMDATE","");
  185. $value .= get_request_item("MANUAL_".$name, "");
  186. }
  187. if ( $label || $value )
  188. $this->format_criteria_selection($label, $value);
  189. }
  190. $this->after_format_criteria_selection();
  191. }
  192. }
  193. function after_format_criteria_selection()
  194. {
  195. }
  196. function page_headers()
  197. {
  198. $this->format_page_header_start();
  199. foreach($this->query->page_headers as $ph)
  200. {
  201. $this->format_page_header($ph);
  202. }
  203. $this->format_page_header_end();
  204. }
  205. function page_footers()
  206. {
  207. $this->format_page_footer_start();
  208. foreach($this->query->page_footers as $ph)
  209. {
  210. $this->format_page_footer($ph);
  211. }
  212. $this->format_page_footer_end();
  213. }
  214. function finish_page()
  215. {
  216. $this->debug("Base Finish Page");
  217. }
  218. function new_line()
  219. {
  220. $this->debug(" Base New Page");
  221. }
  222. function format_format($column_item)
  223. {
  224. return;
  225. }
  226. function format_page_header(&$header)
  227. {
  228. return;
  229. }
  230. function format_page_footer(&$header)
  231. {
  232. return;
  233. }
  234. function format_page_header_start()
  235. {
  236. return;
  237. }
  238. function format_page_header_end()
  239. {
  240. return;
  241. }
  242. function format_page_footer_start()
  243. {
  244. return;
  245. }
  246. function format_page_footer_end()
  247. {
  248. return;
  249. }
  250. function format_column(& $column_item)
  251. {
  252. $this->debug(" Base Format Column");
  253. }
  254. function new_column_header()
  255. {
  256. $this->debug("Base New Page");
  257. }
  258. function new_column()
  259. {
  260. $this->debug("New Column");
  261. }
  262. function show_column_header(& $column_item)
  263. {
  264. $this->debug("Show Column Header");
  265. if ( !is_object($column_item) )
  266. return(false);
  267. $disp = $column_item->derive_attribute(
  268. "column_display", "show" );
  269. if ( $disp == "hide" )
  270. return false;
  271. return true;
  272. }
  273. function publish()
  274. {
  275. $this->debug("Base Publish");
  276. }
  277. function begin_line()
  278. {
  279. return;
  280. }
  281. function end_line()
  282. {
  283. return;
  284. }
  285. function format_column_trailer(&$trailer_col, &$value_col, $trailer_first = false)
  286. {
  287. }
  288. function format_column_trailer_before_line()
  289. {
  290. }
  291. function check_graphic_fit()
  292. {
  293. return true;
  294. }
  295. function each_line($val)
  296. {
  297. $this->debug("Base Each Line");
  298. if ( $this->page_count == 0 )
  299. {
  300. $this->begin_page();
  301. // Print Criteria Items at top of report
  302. $this->format_criteria_selection_set();
  303. //$this->page_headers();
  304. }
  305. $this->after_group_trailers();
  306. $this->before_group_headers();
  307. $this->page_line_count++;
  308. $this->line_count++;
  309. // Add relevant values to any graphs
  310. foreach ( $this->query->graphs as $k => $v )
  311. {
  312. $gr =& $this->query->graphs[$k];
  313. if ( !$gr ) continue;
  314. foreach ( $gr->plots as $k1 => $v1 )
  315. {
  316. $pl =& $gr->plots[$k1];
  317. $col = get_query_column($pl["name"], $this->query->columns ) ;
  318. $gr->add_plot_value($pl["name"],
  319. $col->column_value);
  320. }
  321. if ( $gr->xlabel_column )
  322. {
  323. $col1 = get_query_column($gr->xlabel_column, $this->query->columns ) ;
  324. $gr->add_xlabel( $col1->column_value);
  325. }
  326. }
  327. $this->debug("Line: ".$this->page_line_count."/".$this->line_count);
  328. }
  329. function after_group_trailers()
  330. {
  331. $trailer_first = true;
  332. if ( $this->line_count <= 0 )
  333. {
  334. // No group trailers as it's the first page
  335. }
  336. else
  337. {
  338. //Plot After Group Trailers
  339. if ( count($this->query->groups) == 0 )
  340. return;
  341. end($this->query->groups);
  342. do
  343. {
  344. $group = current($this->query->groups);
  345. if ( $this->query->changed($group->group_name) || $this->last_line)
  346. {
  347. $lev = 0;
  348. $tolev = 0;
  349. while ( $lev <= $tolev )
  350. {
  351. if ( $lev == 0 )
  352. $this->apply_format($group, "before_trailer");
  353. $this->format_group_trailer_start($trailer_first);
  354. $this->format_column_trailer_before_line();
  355. $junk = 0;
  356. $wc = count($this->columns);
  357. foreach ( $this->query->display_order_set["column"] as $w )
  358. {
  359. if ( !$this->show_column_header($w) )
  360. continue;
  361. if ( array_key_exists($w->query_name, $group->trailers) )
  362. {
  363. if ( count($group->trailers[$w->query_name]) >= $lev + 1 )
  364. {
  365. $colgrp =& $group->trailers[$w->query_name][$lev];
  366. $this->format_column_trailer($w, $colgrp,$trailer_first);
  367. }
  368. else
  369. $this->format_column_trailer($w, $junk,$trailer_first);
  370. if ( $group->max_level > $tolev )
  371. {
  372. $tolev = $group->max_level;
  373. }
  374. }
  375. else
  376. {
  377. $this->format_column_trailer($w, $junk, $trailer_first);
  378. }
  379. } // foreach
  380. if ( $trailer_first )
  381. $trailer_first = false;
  382. $lev++;
  383. $this->end_line();
  384. } // while
  385. }
  386. }
  387. while( prev($this->query->groups) );
  388. // Plot After Group Graphs
  389. end($this->query->groups);
  390. do
  391. {
  392. $group = current($this->query->groups);
  393. if ( $this->query->changed($group->group_name) || $this->last_line)
  394. {
  395. if ( !function_exists( "imagecreatefromstring" ) )
  396. trigger_error("Function imagecreatefromstring does not exist - ensure PHP is installed with GD option" );
  397. if ( function_exists( "imagecreatefromstring" ) &&
  398. $this->graph_display &&
  399. get_checkbox_value("target_show_graph"))
  400. if ( $graph =& $this->query->get_graph_by_name($group->group_name) )
  401. {
  402. if ( $url_string = $graph->generate_url_params() )
  403. {
  404. $this->plot_graph($graph);
  405. }
  406. }
  407. }
  408. }
  409. while( prev($this->query->groups) );
  410. }
  411. }
  412. function plot_graph(&$graph)
  413. {
  414. }
  415. function apply_format($item, $format)
  416. {
  417. $formatval = $item->get_format($format);
  418. $this->format_format($formatval);
  419. }
  420. function format_group_trailer_start($first = false)
  421. {
  422. return;
  423. }
  424. function format_group_trailer_end()
  425. {
  426. return;
  427. }
  428. function format_group_header_start()
  429. {
  430. return;
  431. }
  432. function format_group_header_end()
  433. {
  434. return;
  435. }
  436. function before_group_headers()
  437. {
  438. $changect = 0;
  439. reset($this->query->groups);
  440. foreach ( $this->query->groups as $name => $group)
  441. {
  442. if ( ( $group->group_name == "REPORT_BODY" && $this->line_count == 0 ) || $this->query->changed($group->group_name) )
  443. {
  444. if ( $changect == 0 && $this->page_line_count > 0)
  445. {
  446. $changect++;
  447. $this->apply_format($group, "before_header");
  448. $this->format_group_header_start();
  449. }
  450. else if ( $changect == 0 || 1)
  451. {
  452. //echo "wow<br>";
  453. $this->format_group_header_start();
  454. }
  455. for ($i = 0; $i < count($group->headers); $i++ )
  456. {
  457. $col =& $group->headers[$i];
  458. //echo "heder $i<br>";
  459. $this->format_group_header($col);
  460. }
  461. if ( $graph =& $this->query->get_graph_by_name($group->group_name) )
  462. {
  463. $graph->clear_data();
  464. }
  465. $this->format_group_header_end();
  466. $this->apply_format($group, "after_header");
  467. }
  468. //echo "done ($group->group_name<br>";
  469. }
  470. //echo "change ".$changect."Line count ".$this->page_line_count."<BR>";
  471. if ( $changect > 0 || $this->page_line_count == 0 )
  472. {
  473. $this->format_headers();
  474. }
  475. }
  476. function format_group_header(&$col)
  477. {
  478. return;
  479. }
  480. function format_headers()
  481. {
  482. return;
  483. }
  484. }
  485. /**
  486. * Class reportico_report_array
  487. *
  488. * Allows a reportico data query to send its output to an
  489. * array. generally used internally for storing data
  490. * from user criteria selection lists.
  491. */
  492. class reportico_report_array extends reportico_report
  493. {
  494. var $record_template;
  495. var $results = array();
  496. function reportico_report_array ()
  497. {
  498. $this->page_width = 595;
  499. $this->page_height = 842;
  500. $this->column_spacing = "2%";
  501. }
  502. function start ()
  503. {
  504. reportico_report::start();
  505. $results=array();
  506. $ct=0;
  507. }
  508. function finish ()
  509. {
  510. reportico_report::finish();
  511. }
  512. function format_column(& $column_item)
  513. {
  514. if ( !$this->show_column_header($column_item) )
  515. return;
  516. $k =& $column_item->column_value;
  517. $padstring = str_pad($k,20);
  518. }
  519. function each_line($val)
  520. {
  521. reportico_report::each_line($val);
  522. // Set the values for the fields in the record
  523. $record = array();
  524. foreach ( $this->query->display_order_set["column"] as $col )
  525. {
  526. $qn = get_query_column($col->query_name, $this->columns ) ;
  527. $this->results[$qn->query_name][] = $qn->column_value;
  528. $ct = count($this->results[$qn->query_name]);
  529. }
  530. }
  531. }
  532. /**
  533. * Class reportico_report_array
  534. *
  535. * Allows a reportico data query to send its output to an
  536. * array. generally used internally for storing data
  537. * from user criteria selection lists.
  538. */
  539. class reportico_report_table extends reportico_report
  540. {
  541. var $abs_top_margin;
  542. var $abs_bottom_margin;
  543. var $abs_left_margin;
  544. var $abs_right_margin;
  545. var $record_template;
  546. var $target_table = "unknown";
  547. function reportico_report_table ($in_table="unknown")
  548. {
  549. $this->target_table = "unknown";
  550. $this->page_width = 595;
  551. $this->page_height = 842;
  552. $this->column_spacing = "2%";
  553. }
  554. function start ()
  555. {
  556. reportico_report::start();
  557. // Create the target table
  558. $ds =& $this->query->datasource->ado_connection;
  559. $dict = NewDataDictionary($ds);
  560. if (!$dict)
  561. die;
  562. if (!$dict) return;
  563. $flds = "";
  564. $ct=0;
  565. foreach ( $this->columns as $col )
  566. {
  567. if ( $ct++ > 0 )
  568. $flds = $flds.",";
  569. $colname = preg_replace('/ /', '_', $col->query_name);
  570. $flds = $flds.$colname." ".$col->column_type;
  571. if ( $col->column_length > 0 )
  572. $flds = $flds."(".$col->column_length.")";
  573. }
  574. $opts = array('REPLACE','mysql' => 'TYPE=ISAM', 'oci8' => 'TABLESPACE USERS');
  575. $sqli = ($dict->CreateTableSQL($this->target_table,$flds, $opts));
  576. for ($i = 0; $i < count($sqli); $i++)
  577. {
  578. $sql = $sqli[$i];
  579. $sql = preg_replace("/CREATE TABLE/", "CREATE TEMP TABLE",$sql);
  580. //print("Executing ..\n$sql");
  581. //echo "<br>";
  582. //$result = mysql_query($sql) ;
  583. $result = $ds->Execute($sql) ;
  584. //printf("SQL returned $result");
  585. //printf("SQL returned $ds".$ds->ErrorMsg());
  586. echo "<br>";
  587. }
  588. //$ds = $this->query->datasource->ado_connection;
  589. $sql = "SELECT * FROM ".$this->target_table." WHERE 0 = 1";
  590. $this->record_template = $ds->Execute($sql);
  591. }
  592. function finish ()
  593. {
  594. reportico_report::finish();
  595. }
  596. function format_column(& $column_item)
  597. {
  598. if ( !$this->show_column_header($column_item) )
  599. return;
  600. $k =& $column_item->column_value;
  601. $padstring = str_pad($k,20);
  602. }
  603. function each_line($val)
  604. {
  605. reportico_report::each_line($val);
  606. // Get the record template
  607. $ds =& $this->query->datasource->ado_connection;
  608. $rs = $this->record_template;
  609. // Set the values for the fields in the record
  610. $record = array();
  611. foreach ( $this->columns as $k => $col )
  612. {
  613. $qn = $this->columns[$k];
  614. $colname = preg_replace('/ /', '_', $qn->query_name);
  615. $record[$colname] = $qn->column_value;
  616. }
  617. // Pass the empty recordset and the array containing the data to insert
  618. // into the GetInsertSQL function. The function will process the data and return
  619. // a fully formatted insert sql statement.
  620. $insertSQL = $ds->GetInsertSQL($rs, $record);
  621. //echo "$insertSQL<br>";
  622. // Insert the record into the database
  623. $ds->Execute($insertSQL);
  624. }
  625. }
  626. // -----------------------------------------------------------------------------
  627. // Class reportico_report_pdf
  628. // -----------------------------------------------------------------------------
  629. class reportico_report_pdf extends reportico_report
  630. {
  631. var $abs_top_margin;
  632. var $abs_bottom_margin;
  633. var $abs_left_margin;
  634. var $abs_right_margin;
  635. var $orientation;
  636. var $page_type;
  637. var $column_order;
  638. var $fontName;
  639. var $fontSize;
  640. var $vsize;
  641. var $justifys = array (
  642. "right" => "R",
  643. "centre" => "C",
  644. "center" => "C",
  645. "left" => "L"
  646. );
  647. var $orientations = array (
  648. "Portrait" => "P",
  649. "Landscape" => "L"
  650. );
  651. var $page_types = array (
  652. "B5" => array ("height" => 709, "width" => 501 ),
  653. "A6" => array ("height" => 421, "width" => 297 ),
  654. "A5" => array ("height" => 595, "width" => 421 ),
  655. "A4" => array ("height" => 842, "width" => 595 ),
  656. "A3" => array ("height" => 1190, "width" => 842 ),
  657. "A2" => array ("height" => 1684, "width" => 1190 ),
  658. "A1" => array ("height" => 2380, "width" => 1684 ),
  659. "A0" => array ("height" => 3368, "width" => 2380 ),
  660. "US-Letter" => array ("height" => 792, "width" => 612 ),
  661. "US-Legal" => array ("height" => 1008, "width" => 612 ),
  662. "US-Ledger" => array ("height" => 792, "width" => 1224 ),
  663. );
  664. var $yjump = 0;
  665. var $vspace = 0;
  666. function reportico_report_pdf ()
  667. {
  668. $this->column_spacing = 5;
  669. }
  670. function start ()
  671. {
  672. reportico_report::start();
  673. $this->debug("PDF Start **");
  674. $this->page_line_count = 0;
  675. $this->fontName = $this->query->get_attribute("pdfFont");
  676. $this->fontSize = $this->query->get_attribute("pdfFontSize");
  677. $this->vsize = $this->fontSize + $this->vspace;
  678. $this->orientation = $this->query->get_attribute("PageOrientation");
  679. $this->page_type = $this->query->get_attribute("PageSize");
  680. if ( $this->orientation == "Portrait" )
  681. {
  682. $this->abs_page_width = $this->page_types[$this->page_type]["width"];
  683. $this->abs_page_height = $this->page_types[$this->page_type]["height"];
  684. }
  685. else
  686. {
  687. $this->abs_page_width = $this->page_types[$this->page_type]["height"];
  688. $this->abs_page_height = $this->page_types[$this->page_type]["width"];
  689. }
  690. $this->abs_top_margin = $this->abs_paging_height($this->query->get_attribute("TopMargin"));
  691. $this->abs_bottom_margin = $this->abs_page_height -
  692. $this->abs_paging_height($this->query->get_attribute("BottomMargin"));
  693. $this->abs_right_margin = $this->abs_page_width -
  694. $this->abs_paging_width($this->query->get_attribute("RightMargin"));
  695. $this->abs_left_margin = $this->abs_paging_width($this->query->get_attribute("LeftMargin"));
  696. require_once("fpdf/fpdf.php");
  697. $this->document = new FPDF($this->orientations[$this->orientation],'pt',$this->page_type);
  698. //if ( $this->report_file )
  699. //pdf_open_file($this->document, $this->report_file.".pdf");
  700. //else
  701. //pdf_open_file($this->document);
  702. $this->document->SetAutoPageBreak(false);
  703. $this->document->SetMargins(0,0,0);
  704. $this->document->SetCreator('Reportico');
  705. $this->document->SetAuthor('Reportico');
  706. $this->document->SetTitle($this->reporttitle);
  707. // Calculate column print and width poistions based on the column start attributes
  708. $looping = true;
  709. foreach ( $this->query->display_order_set["column"] as $k => $w )
  710. {
  711. $col = get_query_column($w->query_name, $this->query->columns ) ;
  712. $startcol = $col->attributes["ColumnStartPDF"];
  713. $colwidth = $col->attributes["ColumnWidthPDF"];
  714. if ( $startcol )
  715. $col->abs_column_start = $this->abs_paging_width($startcol);
  716. else
  717. $col->abs_column_start = 0;
  718. if ( $colwidth )
  719. $col->abs_column_width = $this->abs_paging_width($colwidth);
  720. else
  721. $col->abs_column_width = 0;
  722. //echo "Init ".$col->query_name." - ".$col->abs_column_start."<BR>";
  723. //echo "Init ".$col->query_name." - ".$col->abs_column_width."<BR>";
  724. }
  725. while ( $looping )
  726. {
  727. $fromkey = 0;
  728. $nextkey = 0;
  729. $frompos = 0;
  730. $nextpos = 0;
  731. $topos = 0;
  732. $lastwidth = 0;
  733. $looping = false;
  734. $gapct = 0;
  735. $k = 0;
  736. $colct = count($this->query->display_order_set["column"]);
  737. $coltaken = 0;
  738. $colstocalc = 0;
  739. $colswithwidth = 0;
  740. //echo "<BR>NEW !!<BR>";
  741. foreach ( $this->query->display_order_set["column"] as $k => $w )
  742. {
  743. if ( $w->attributes["column_display"] != "show")
  744. continue;
  745. {
  746. $col = get_query_column($w->query_name, $this->query->columns ) ;
  747. $startcol = $col->abs_column_start;
  748. $colwidth = $col->abs_column_width;
  749. //echo "With ".$w->query_name." $startcol $colwidth $coltaken<BR>";
  750. if ( $startcol )
  751. {
  752. //echo "From $fromkey Pos $frompos Gap $gapct<br>";
  753. if ( /*$fromkey &&*/ $frompos && $gapct )
  754. {
  755. //echo "at end<br>";
  756. //$tokey = $k;
  757. $topos = $col->abs_column_start;
  758. break;
  759. }
  760. else
  761. {
  762. //echo "Settingf to $k<br>";
  763. $fromkey = $k;
  764. $tokey = $k;
  765. $frompos = $col->abs_column_start;
  766. if ( $colwidth )
  767. {
  768. $coltaken += $colwidth;
  769. //echo " reset type 1 ".$col->query_name."<BR>";
  770. $coltaken = 0;
  771. $colswithwidth=1;
  772. $colstocalc=1;
  773. }
  774. else
  775. {
  776. $colstocalc++;
  777. $gapct++;
  778. }
  779. }
  780. $lastct = 0;
  781. }
  782. else
  783. {
  784. //echo "All blank<br>";
  785. if ( /*!$fromkey &*/ !$frompos )
  786. {
  787. $col->abs_column_start = $this->abs_left_margin;
  788. $frompos = $col->abs_column_start;
  789. $fromkey = $k;
  790. }
  791. if ( $colwidth )
  792. {
  793. $coltaken += $colwidth;
  794. //echo "type 2 ".$col->query_name."<BR>";
  795. $colswithwidth++;
  796. }
  797. $colstocalc++;
  798. $tokey =$k;
  799. $gapct++;
  800. $looping = true;
  801. }
  802. }
  803. }
  804. //echo "Here gap $gapct - from $fromkey/$frompos to $tokey/$topos<br>";
  805. if ( !$gapct )
  806. break;
  807. // We have two known positions find total free space between
  808. $calctoend = false;
  809. if ( !$topos )
  810. {
  811. //echo "Calc to end<BR>";
  812. $calctoend = true;
  813. $topos = $this->abs_right_margin;
  814. //echo "until ".$topos." of ".$this->abs_page_width."<BR>";
  815. //echo "gone to ".$this->abs_page_width." - ".$this->abs_right_margin."<BR>";
  816. }
  817. //echo "From pos $frompos to $topos marg = $this->abs_left_margin<BR>";
  818. $totwidth = $topos - $frompos;
  819. if ( $coltaken > $totwidth )
  820. $coltaken = $totwidth;
  821. //echo "Taken $coltaken/$totwidth<br>";
  822. $colno = 0;
  823. $calccolwidth = ( $totwidth - $coltaken ) / (( $colstocalc - $colswithwidth ) );
  824. //echo "$calccolwidth = ( $totwidth - $coltaken ) / (( $colstocalc - $colswithwidth ) )<BR>";
  825. //echo "Total cols to calc $colstocalc - $colswithwidth = $calccolwidth<br>";
  826. $lastpos = $this->abs_left_margin;
  827. for ( $ct = $fromkey; $ct <= $tokey; $ct++ )
  828. {
  829. $col1 =& $this->query->display_order_set["column"][$ct];
  830. if ( $col1->attributes["column_display"] == "show")
  831. {
  832. $abspos = $col1->abs_column_start;
  833. if ( !$abspos )
  834. {
  835. $col1->abs_column_start = $lastpos;
  836. $colwidth = $col1->attributes["ColumnWidthPDF"];
  837. //echo "$ct. we have ".$colwidth."(".$col1->attributes["ColumnWidthPDF"].")<br>";
  838. if ( $colwidth )
  839. {
  840. $col1->abs_column_width = $this->abs_paging_width($colwidth);
  841. $lastpos = $col1->abs_column_start + $col1->abs_column_width;
  842. }
  843. else
  844. {
  845. $col1->abs_column_width = $calccolwidth;
  846. $lastpos = $col1->abs_column_start + $calccolwidth;
  847. }
  848. //echo "$ct. 1 set ".$col->abs_column_start."/".$col->abs_column_width."<BR>";
  849. }
  850. else
  851. {
  852. $colwidth = $col1->attributes["ColumnWidthPDF"];
  853. if ( $colwidth )
  854. {
  855. $col1->abs_column_width = $this->abs_paging_width($colwidth);
  856. $lastpos = $col1->abs_column_start + $col1->abs_column_width;
  857. }
  858. else
  859. {
  860. $col1->abs_column_width = $calccolwidth;
  861. $lastpos = $col1->abs_column_start + $calccolwidth;
  862. }
  863. //echo "$ct. 2 set ".$col1->abs_column_start."/".$col1->abs_column_width."<BR>";
  864. }
  865. }
  866. }
  867. }
  868. /*
  869. $looping = true;
  870. while ( $looping )
  871. {
  872. $looping = false;
  873. $lastpos = false;
  874. $lastkey = false;
  875. $lastqn = false;
  876. $temppos = false;
  877. foreach ( $this->query->display_order_set["column"] as $k => $w )
  878. {
  879. $col =& $this->query->display_order_set["column"][$k];
  880. //echo "$k ->".$col->query_name."/".$col->abs_column_start."<BR>";
  881. if ( $col->attributes["column_display"] == "show")
  882. {
  883. if ( $lastpos )
  884. if ( $col->abs_column_start < $lastpos->abs_column_start )
  885. {
  886. $tempos =& $col;
  887. $this->query->display_order_set["column"][$k] =&
  888. get_query_column($lastqn, $this->query->columns ) ;
  889. $this->query->display_order_set["column"][$lastkey]
  890. = get_query_column($col->query_name, $this->query->columns);
  891. }
  892. $lastpos =& $col;
  893. $lastkey = $k;
  894. $lastqn = $col->query_name;
  895. }
  896. }
  897. }
  898. */
  899. }
  900. function finish ()
  901. {
  902. reportico_report::finish();
  903. $this->debug("Finish");
  904. if ( $this->line_count < 2 )
  905. {
  906. $this->debug ("No Records Found" );
  907. $this->document->Write(5, "No Records Found");
  908. }
  909. $this->document->SetDisplayMode("real");
  910. //$this->document->pdf_close($this->document);
  911. if ( $this->report_file )
  912. {
  913. $this->debug("Saved to $this->report_file");
  914. }
  915. else
  916. {
  917. $this->debug("No pdf file specified !!!");
  918. //$buf = $this->document->pdf_get_buffer($this->document);
  919. $buf = $this->document->Output("", "S");
  920. $len = strlen($buf);
  921. if ( ob_get_length() > 0 )
  922. ob_clean();
  923. header("Content-Type: application/pdf");
  924. header("Content-Length: $len");
  925. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  926. header('Content-Disposition: attachment;filename=reportico.pdf');
  927. print($buf);
  928. die;
  929. // PD $this->document->Close();
  930. }
  931. }
  932. function abs_paging_height($height_string)
  933. {
  934. //if ( preg_match("/(\d*\.*(\d+)(\D*)/", $height_string, $match) )
  935. if ( preg_match("/(\d+)(\D*)/", $height_string, $match) )
  936. {
  937. $height = $match[1];
  938. if ( isset( $match[2] ) )
  939. {
  940. switch ( $match[2] )
  941. {
  942. case "pt":
  943. $height = $height;
  944. break;
  945. case "%":
  946. $height = ( $height * $this->abs_page_height ) / 100;
  947. break;
  948. case "mm":
  949. $height = $height / 0.35277777778;
  950. break;
  951. case "cm":
  952. $height = $height / 0.035277777778;
  953. break;
  954. default:
  955. //handle_error("Unknown Page Sizing Option ".$match[2]);
  956. break;
  957. }
  958. }
  959. }
  960. else
  961. {
  962. $height = $height_string;
  963. //handle_error("Unknown Page Sizing Option $height_string");
  964. }
  965. return $height;
  966. }
  967. function abs_paging_width($width_string)
  968. {
  969. if ( preg_match("/(\d+)(\D*)/", $width_string, $match) )
  970. {
  971. $width = $match[1];
  972. if ( isset( $match[2] ) )
  973. {
  974. switch ( $match[2] )
  975. {
  976. case "pt":
  977. $width = $width;
  978. break;
  979. case "%":
  980. $width = ( $width * $this->abs_page_width ) / 100;
  981. break;
  982. case "mm":
  983. $width = $width / 0.35277777778;
  984. break;
  985. case "cm":
  986. $width = $width / 0.035277777778;
  987. break;
  988. //default:
  989. //handle_error("Unknown Page Sizing Option $width_string");
  990. //break;
  991. }
  992. }
  993. }
  994. else
  995. {
  996. $width = $width_string;
  997. //handle_error("Unknown Page Sizing Option $width_string");
  998. }
  999. return $width;
  1000. }
  1001. function format_column_trailer(&$trailer_col, &$value_col, $trailer_first = false)
  1002. {
  1003. if ( $this->body_display != "show" )
  1004. return;
  1005. if ( $value_col )
  1006. {
  1007. $y = $this->document->GetY();
  1008. // Fetch Group Header Label
  1009. $group_label = $value_col->get_attribute("group_header_label" );
  1010. if ( !$group_label )
  1011. $group_label = $value_col->get_attribute("column_title" );
  1012. if ( !$group_label )
  1013. {
  1014. $group_label = $value_col->query_name;
  1015. $group_label = str_replace("_", " ", $group_label);
  1016. $group_label = ucwords(strtolower($group_label));
  1017. }
  1018. $group_label = sw_translate($group_label);
  1019. // Fetch Group Header Label End Column + display
  1020. $group_xpos = $trailer_col->abs_column_start;
  1021. $wd = $trailer_col->abs_column_width;
  1022. if ( $wd - $this->column_spacing > 0 )
  1023. $wd = $wd - $this->column_spacing;
  1024. $this->document->SetXY($group_xpos, $y);
  1025. $padstring = $value_col->old_column_value;
  1026. $just = $this->justifys[$trailer_col->derive_attribute( "justify", "left")];
  1027. $group_label = $value_col->get_attribute("group_trailer_label" );
  1028. if ( !$group_label )
  1029. $group_label = $value_col->get_attribute("column_title" );
  1030. if ( $group_label && $group_label != "BLANK" )
  1031. $padstring = $group_label.":".$padstring;
  1032. $this->document->CellTrunc($wd,$this->vsize + 2,"$padstring","BT", 0, $just);
  1033. // Fetch Group Header Label Start Column + display
  1034. $group_xpos = $value_col->get_attribute("group_header_label_xpos" );
  1035. if ( !$group_xpos )
  1036. $group_xpos = 0;
  1037. $group_xpos = $this->abs_paging_width($group_xpos);
  1038. $group_xpos = $value_col->abs_column_start;
  1039. $this->document->SetXY($group_xpos, $y);
  1040. $padstring = $group_label;
  1041. $just = $this->justifys[$trailer_col->derive_attribute( "justify", "left")];
  1042. //$this->document->CellTrunc($wd,$this->vsize,"$padstring","T",0,$just);
  1043. //$this->document->Ln();
  1044. }
  1045. }
  1046. function end_line()
  1047. {
  1048. $this->document->Ln();
  1049. }
  1050. function format_page_header_start()
  1051. {
  1052. return;
  1053. }
  1054. function format_page_header_end()
  1055. {
  1056. $this->document->Ln();
  1057. $this->document->Ln();
  1058. }
  1059. function before_format_criteria_selection()
  1060. {
  1061. }
  1062. function format_criteria_selection($label, $value)
  1063. {
  1064. $y = $this->document->GetY();
  1065. $this->yjump = 0;
  1066. // Fetch Group Header Label Start Column + display
  1067. $group_xpos = false;
  1068. if ( !$group_xpos )
  1069. $group_xpos = $this->abs_left_margin;
  1070. $group_xpos = $this->abs_paging_width($group_xpos);
  1071. $this->document->SetXY($group_xpos, $y);
  1072. $padstring = $label;
  1073. $this->document->CellTrunc( 400, $this->vsize, "$padstring");
  1074. // Fetch Group Header Label End Column + display
  1075. $group_xpos = false;
  1076. if ( !$group_xpos )
  1077. $group_xpos = $this->abs_paging_width($group_xpos) + 250;
  1078. $group_xpos = $this->abs_paging_width($group_xpos);
  1079. $this->document->SetXY($group_xpos, $y);
  1080. $qn = get_query_column($col->query_name, $this->query->columns ) ;
  1081. $padstring = $value;
  1082. $this->document->CellTrunc(100, $this->vsize, "$padstring");
  1083. $this->document->Ln();
  1084. $y = $this->document->GetY();
  1085. if ( $this->yjump )
  1086. $this->document->SetY($y + $this->yjump);
  1087. $label = "";
  1088. $value = "";
  1089. }
  1090. function after_format_criteria_selection()
  1091. {
  1092. }
  1093. function format_group_header_start()
  1094. {
  1095. $y = $this->document->GetY();
  1096. $this->document->Ln();
  1097. $y = $this->document->GetY();
  1098. // Throw new page if current position + number headers + line + headers > than bottom margin
  1099. $y = $this->document->GetY();
  1100. $ln = 0;
  1101. foreach ( $this->query->groups as $val )
  1102. $ln += count($val->headers);
  1103. $ln += 5;
  1104. if ( ($y + ($ln * $this->vsize))> $this->abs_bottom_margin )
  1105. {
  1106. $this->finish_page();
  1107. $this->begin_page();
  1108. $x = $this->document->GetX();
  1109. $y = $this->document->GetY();
  1110. }
  1111. }
  1112. function format_group_trailer_start($first=false)
  1113. {
  1114. return;
  1115. }
  1116. function format_group_header_end()
  1117. {
  1118. $this->document->Ln();
  1119. }
  1120. function format_group_trailer_end()
  1121. {
  1122. return;
  1123. }
  1124. function format_group_header(&$col)
  1125. {
  1126. $y = $this->document->GetY();
  1127. $group_label = $col->get_attribute("group_header_label" );
  1128. if ( !$group_label )
  1129. $group_label = $col->get_attribute("column_title" );
  1130. if ( !$group_label )
  1131. {
  1132. $group_label = $col->query_name;
  1133. $group_label = str_replace("_", " ", $group_label);
  1134. $group_label = ucwords(strtolower($group_label));
  1135. }
  1136. $group_label = sw_translate($group_label);
  1137. $this->yjump = 0;
  1138. // Fetch Group Header Label Start Column + display
  1139. $group_xpos = $col->get_attribute("group_header_label_xpos" );
  1140. if ( !$group_xpos )
  1141. $group_xpos = $this->abs_left_margin;
  1142. $group_xpos = $this->abs_paging_width($group_xpos);
  1143. $this->document->SetXY($group_xpos, $y);
  1144. $padstring = $group_label;
  1145. $this->document->CellTrunc( 400, $this->vsize, "$padstring");
  1146. // Fetch Group Header Label End Column + display
  1147. $group_xpos = $col->get_attribute("group_header_data_xpos" );
  1148. if ( !$group_xpos )
  1149. $group_xpos = $this->abs_paging_width($group_xpos) + 250;
  1150. $group_xpos = $this->abs_paging_width($group_xpos);
  1151. $contenttype = $col->derive_attribute( "content_type", $col->query_name);
  1152. if ( $contenttype == "graphic" )
  1153. {
  1154. $qn = get_query_column($col->query_name, $this->query->columns ) ;
  1155. $sql = @preg_replace("/.*imagesql=/", "", $qn->column_value);
  1156. $sql = @preg_replace("/'>$/", "", $sql);
  1157. $str =
  1158. &get_db_image_string(
  1159. $this->query->datasource->driver,
  1160. $this->query->datasource->database,
  1161. $this->query->datasource->host_name,
  1162. $sql,
  1163. $this->query->datasource->ado_connection
  1164. );
  1165. if ( $str )
  1166. {
  1167. $tmpnam = tempnam(SW_TMP_DIR, "dbi");
  1168. $width = $qn->abs_column_width;
  1169. $height = 20;
  1170. $im = imagecreatefromstring($str);
  1171. if ( imagepng($im, $tmpnam.".png" ) )
  1172. {
  1173. $x = $qn->abs_column_start;
  1174. $y = $this->document->GetY();
  1175. $this->document->SetX($group_xpos);
  1176. $h = $this->document->Image($tmpnam.".png", $group_xpos, $y, $width );
  1177. $this->yjump =$h;
  1178. unlink($tmpnam.".png");
  1179. }
  1180. }
  1181. }
  1182. else
  1183. {
  1184. $this->document->SetXY($group_xpos, $y);
  1185. $qn = get_query_column($col->query_name, $this->query->columns ) ;
  1186. $padstring = $qn->column_value;
  1187. $this->document->CellTrunc(100, $this->vsize, "$padstring");
  1188. }
  1189. $this->document->Ln();
  1190. $y = $this->document->GetY();
  1191. if ( $this->yjump )
  1192. $this->document->SetY($y + $this->yjump);
  1193. }
  1194. function format_column_header(& $column_item)
  1195. {
  1196. if ( $this->body_display != "show" )
  1197. return;
  1198. if ( !$this->show_column_header($column_item) )
  1199. return;
  1200. $k =& $column_item->query_name;
  1201. $padstring = $column_item->derive_attribute( "column_title", $column_item->query_name);
  1202. $padstring = str_replace("_", " ", $padstring);
  1203. $padstring = ucwords(strtolower($padstring));
  1204. $padstring = sw_translate($padstring);
  1205. $just = $this->justifys[$column_item->derive_attribute( "justify", "left")];
  1206. $contenttype = $column_item->derive_attribute(
  1207. "content_type", $column_item->query_name);
  1208. $tw = $column_item->abs_column_start;
  1209. $x = $this->document->GetX();
  1210. $y = $this->document->GetY();
  1211. $this->document->SetXY($tw, $y);
  1212. $wd = $column_item->abs_column_width;
  1213. if ( $wd - $this->column_spacing > 0 )
  1214. $wd = $wd - $this->column_spacing;
  1215. if ( !$wd )
  1216. {
  1217. $this->document->Write( "$padstring");
  1218. }
  1219. else
  1220. {
  1221. $this->document->SetX($tw);
  1222. $this->document->CellTrunc($wd, $this->vsize, $padstring,"B",0,$just);
  1223. }
  1224. }
  1225. function plot_graph(&$graph)
  1226. {
  1227. $this->document->Ln();
  1228. $graph->width_actual = check_for_default("GraphWidthPDF", $graph->width_pdf);
  1229. $graph->height_actual = check_for_default("GraphHeightPDF", $graph->height_pdf);
  1230. $graph->title_actual = reportico_assignment::reportico_meta_sql_criteria($this->query, $graph->title, true);
  1231. $graph->xtitle_actual = reportico_assignment::reportico_meta_sql_criteria($this->query, $graph->xtitle, true);
  1232. $graph->ytitle_actual = reportico_assignment::reportico_meta_sql_criteria($this->query, $graph->ytitle, true);
  1233. $handle = $graph->generate_graph_image();
  1234. $tmpnam = tempnam(SW_TMP_DIR, "gph");
  1235. unlink($tmpnam);
  1236. if ( imagepng($handle, $tmpnam.".png" ) )
  1237. {
  1238. $x = $this->document->GetX();
  1239. $y = $this->document->GetY();
  1240. $this->document->SetX( $this->abs_left_margin);
  1241. $width = $graph->width_actual;
  1242. $height = $graph->height_actual;
  1243. if ( $width > ($this->abs_right_margin - $this->abs_left_margin) )
  1244. {
  1245. $height = $height * ( ($this->abs_right_margin - $this->abs_left_margin) / $width );
  1246. $width = ($this->abs_right_margin - $this->abs_left_margin);
  1247. }
  1248. $xaddon = ( $this->abs_right_margin - $this->abs_left_margin - $width ) / 2 ;
  1249. if ( $y + $height >= $this->abs_bottom_margin )
  1250. {
  1251. $this->finish_page();
  1252. $this->begin_page();
  1253. $x = $this->document->GetX();
  1254. $y = $this->document->GetY();
  1255. }
  1256. $this->document->Image($tmpnam.".png", $this->abs_left_margin + $xaddon, $y, $width, $height );
  1257. $y = $this->document->SetY($y + $height);
  1258. $this->document->Ln();
  1259. unlink($tmpnam.".png");
  1260. }
  1261. }
  1262. function format_headers()
  1263. {
  1264. foreach ( $this->columns as $w )
  1265. $this->format_column_header($w);
  1266. $this->document->Ln();
  1267. $this->document->Ln();
  1268. }
  1269. function format_column(& $column_item)
  1270. {
  1271. if ( !$this->show_column_header($column_item) )
  1272. return;
  1273. $k =& $column_item->column_value;
  1274. $tw = $column_item->abs_column_start;
  1275. $wd = $column_item->abs_column_width;
  1276. if ( $wd - $this->column_spacing > 0 )
  1277. $wd = $wd - $this->column_spacing;
  1278. $just = $this->justifys[$column_item->derive_attribute( "justify", "left")];
  1279. $contenttype = $column_item->derive_attribute(
  1280. "content_type", $column_item->query_name);
  1281. if ( $contenttype == "graphic" )
  1282. {
  1283. $sql = @preg_replace("/.*imagesql=/", "", $column_item->column_value);
  1284. $sql = @preg_replace("/'>$/", "", $sql);
  1285. $str =
  1286. &get_db_image_string(
  1287. $this->query->datasource->driver,
  1288. $this->query->datasource->database,
  1289. $this->query->datasource->host_name,
  1290. $sql,
  1291. $this->query->datasource->ado_connection
  1292. );
  1293. if ( $str )
  1294. {
  1295. $tmpnam = tempnam(SW_TMP_DIR, "dbi");
  1296. $width = $column_item->abs_column_width;
  1297. //echo "Widht is ".$column_item->abs_column_width."<BR>";
  1298. $height = 20;
  1299. $im = imagecreatefromstring($str);
  1300. if ( imagepng($im, $tmpnam.".png" ) )
  1301. {
  1302. $x = $column_item->abs_column_start;
  1303. $y = $this->document->GetY();
  1304. $this->document->SetX($x);
  1305. $h = $this->document->Image($tmpnam.".png", $x, $y, $width );
  1306. if ( $h > $this->yjump )
  1307. $this->yjump =$h;
  1308. unlink($tmpnam.".png");
  1309. }
  1310. }
  1311. }
  1312. else
  1313. {
  1314. if ( !$wd )
  1315. $this->document->Write( "$padstring");
  1316. else
  1317. {
  1318. $this->document->SetX($tw);
  1319. $this->document->CellTrunc($wd, $this->vsize, $k,0,0,$just);
  1320. $tw = $this->abs_page_width - $this->abs_right_margin;
  1321. }
  1322. }
  1323. }
  1324. function each_line($val)
  1325. {
  1326. reportico_report::each_line($val);
  1327. $y = $this->document->GetY();
  1328. $this->document->SetXY(50, $y);
  1329. //$this->document->SetY($y+10);
  1330. if ( $y + $this->vsize > $this->abs_bottom_margin )
  1331. {
  1332. $this->finish_page();
  1333. $this->begin_page();
  1334. }
  1335. $this->check_graphic_fit();
  1336. $this->yjump = 0;
  1337. if ( $this->body_display == "show" )
  1338. {
  1339. foreach ( $this->columns as $col )
  1340. {
  1341. $this->format_column($col);
  1342. }
  1343. $this->document->Ln();
  1344. }
  1345. $y = $this->document->GetY();
  1346. if ( $this->yjump )
  1347. $this->document->SetY($y + $this->yjump);
  1348. if ( $y + $this->vsize > $this->abs_bottom_margin )
  1349. {
  1350. $this->finish_page();
  1351. $this->begin_page();
  1352. }
  1353. }
  1354. function check_graphic_fit()
  1355. {
  1356. $will_fit = true;
  1357. $max_height = $this->vsize;
  1358. foreach ( $this->columns as $col )
  1359. {
  1360. $contenttype = $col->derive_attribute( "content_type", $col->query_name);
  1361. if ( $contenttype == "graphic" )
  1362. {
  1363. $qn = get_query_column($col->query_name, $this->query->columns ) ;
  1364. $sql = @preg_replace("/.*imagesql=/", "", $qn->column_value);
  1365. $sql = @preg_replace("/'>$/", "", $sql);
  1366. $str =
  1367. &get_db_image_string(
  1368. $this->query->datasource->driver,
  1369. $this->query->datasource->database,
  1370. $this->query->datasource->host_name,
  1371. $sql,
  1372. $this->query->datasource->ado_connection
  1373. );
  1374. if ( $str )
  1375. {
  1376. //$im = convert_image_string_to_image($str, "png");
  1377. $tmpnam = tempnam(SW_TMP_DIR, "dbi");
  1378. $width = $qn->abs_column_width;
  1379. $height = 20;
  1380. $im = imagecreatefromstring($str);
  1381. if ( imagepng($im, $tmpnam.".png" ) )
  1382. {
  1383. $h = $this->document->ImageHeight($tmpnam.".png", $group_xpos, $y, $width );
  1384. unlink($tmpnam.".png");
  1385. if ( $max_height < $h )
  1386. $max_height = $h;
  1387. }
  1388. }
  1389. //echo "height $h $max_height<br>";
  1390. }
  1391. }
  1392. $y = $this->document->GetY();
  1393. if ( $y + $max_height /*+ 10*/ > $this->abs_bottom_margin )
  1394. {
  1395. //echo "if ( $y + $max_height > $this->abs_bottom_margin )<br>";
  1396. //echo "thorwing<br>";
  1397. $this->finish_page();
  1398. $this->begin_page();
  1399. $this->before_group_headers();
  1400. $this->page_line_count++;
  1401. }
  1402. }
  1403. function page_template()
  1404. {
  1405. $this->debug("Page Template");
  1406. }
  1407. function begin_page()
  1408. {
  1409. reportico_report::begin_page();
  1410. $this->debug("PDF Begin Page\n");
  1411. $this->document->AddPage($this->orientations[$this->orientation]);
  1412. $font = $this->document->SetFont($this->fontName);
  1413. $font = $this->document->SetFontSize($this->vsize);
  1414. $this->document->SetXY($this->abs_left_margin, $this->abs_top_margin);
  1415. reportico_report::page_headers();
  1416. }
  1417. function finish_page()
  1418. {
  1419. $this->debug("Finish Page");
  1420. $this->page_footers();
  1421. //$this->document->pdf_end_page($this->document);
  1422. }
  1423. function publish()
  1424. {
  1425. reportico_report::publish();
  1426. $this->debug("Publish PDF");
  1427. }
  1428. function format_page_header(&$header)
  1429. {
  1430. $startcol = $header->get_attribute("ColumnStartPDF");
  1431. $tw = $this->abs_paging_width($startcol);
  1432. if ( !$tw )
  1433. $tw = $this->abs_right_margin;
  1434. $wd = $header->get_attribute("ColumnWidthPDF");
  1435. if ( !$wd )
  1436. if ( $this->abs_right_margin > $tw )
  1437. $wd = $this->abs_right_margin - $tw;
  1438. else
  1439. $wd = "100%";
  1440. $wd = $this->abs_paging_width($wd);
  1441. $just = $this->justifys[$header->derive_attribute( "justify", "left")];
  1442. $y = $this->abs_top_margin + ( $this->vsize * ( $header->line - 1 ) );
  1443. $this->document->SetXY($tw,$y);
  1444. $tx = $this->reportico_string_to_php(reportico_assignment::reportico_meta_sql_criteria($this->query, $header->text));
  1445. $this->document->CellTrunc($wd, $this->vsize, $tx, 0, 0, $just );
  1446. $this->document->Ln();
  1447. return;
  1448. }
  1449. function format_page_footer(&$footer)
  1450. {
  1451. $startcol = $footer->get_attribute("ColumnStartPDF");
  1452. $tw = $this->abs_paging_width($startcol);
  1453. if ( !$tw )
  1454. $tw = $this->abs_right_margin;
  1455. $wd = $footer->get_attribute("ColumnWidthPDF");
  1456. if ( !$wd )
  1457. if ( $this->abs_right_margin > $tw )
  1458. $wd = $this->abs_right_margin - $tw;
  1459. else
  1460. $wd = "100%";
  1461. $wd = $this->abs_paging_width($wd);
  1462. $just = $this->justifys[$footer->derive_attribute( "justify", "left")];
  1463. $y = $this->abs_bottom_margin + ( $this->vsize * $footer->line );
  1464. $this->document->SetXY($tw, $y);
  1465. //$tx = $this->reportico_string_to_php($footer->text);
  1466. $tx = $this->reportico_string_to_php(reportico_assignment::reportico_meta_sql_criteria($this->query, $footer->text));
  1467. $this->document->CellTrunc($wd, $this->vsize, $tx, 0, 0, $just);
  1468. $this->document->Ln();
  1469. return;
  1470. }
  1471. function format_format($in_value)
  1472. {
  1473. switch($in_value)
  1474. {
  1475. case "blankline" :
  1476. $this->document->Ln();
  1477. break;
  1478. case "solidline" :
  1479. $y = $this->document->GetY();
  1480. $this->document->Line($this->abs_left_margin, $y, $this->abs_page_width - $this->abs_right_margin, $y);
  1481. //$this->document->pdf_stroke($this->document);
  1482. //$font = $this->document->pdf_findfont($this->document, 'Courier', 'host', 0);
  1483. //$this->document->pdf_setfont($this->document, $font, 8.0);
  1484. $this->document->SetXY($this->abs_right_margin, $y);
  1485. $this->document->Ln();
  1486. break;
  1487. case "newpage" :
  1488. $this->finish_page();
  1489. $this->begin_page();
  1490. break;
  1491. default :
  1492. $this->document->Ln();
  1493. break;
  1494. }
  1495. }
  1496. }
  1497. // -----------------------------------------------------------------------------
  1498. // Class reportico_report_html_template
  1499. // -----------------------------------------------------------------------------
  1500. class reportico_report_soap_template extends reportico_report
  1501. {
  1502. var $soapdata = array();
  1503. var $soapline = array();
  1504. var $soapresult = false;
  1505. function start ()
  1506. {
  1507. // Include NuSoap Web Service PlugIn
  1508. //require_once("nusoap.php");
  1509. reportico_report::start();
  1510. $this->reporttitle = $this->query->derive_attribute("ReportTitle", "Set Report Title");
  1511. $this->debug("SOAP Start **");
  1512. }
  1513. function finish ()
  1514. {
  1515. reportico_report::finish();
  1516. $this->debug("HTML End **");
  1517. if ( $this->line_count < 1 )
  1518. {
  1519. $this->soapresult = new soap_fault('Server',100,"No Data Returned","No Data Returned");
  1520. }
  1521. else
  1522. {
  1523. $this->soapdata = array(
  1524. "ReportTitle" => $this->reporttitle,
  1525. "ReportTime" => date("Y-m-d H:I:s T"),
  1526. $this->soapdata
  1527. );
  1528. $this->soapresult =
  1529. new soapval('reportReturn',
  1530. 'ReportDeliveryType',
  1531. $this->soapdata,
  1532. 'http://reportico.org/xsd');
  1533. //$x = $this->soapresult->serialize();
  1534. //var_dump($this->soapresult);
  1535. //var_dump($x);
  1536. }
  1537. }
  1538. function format_column(& $column_item)
  1539. {
  1540. if ( $this->body_display != "show" )
  1541. return;
  1542. if ( !$this->show_column_header($column_item) )
  1543. return;
  1544. $this->soapline[$column_item->query_name] = $column_item->column_value;
  1545. }
  1546. function each_line($val)
  1547. {
  1548. reportico_report::each_line($val);
  1549. if ( $this->page_line_count == 1 )
  1550. {
  1551. //$this->text .="<tr class='swPrpCritLine'>";
  1552. //foreach ( $this->columns as $col )
  1553. //$this->format_column_header($col);
  1554. //$this->text .="</tr>";
  1555. }
  1556. $this->soapline = array();
  1557. foreach ( $this->query->display_order_set["column"] as $col )
  1558. $this->format_column($col);
  1559. $this->soapdata[] = new soapval('ReportLine', 'ReportLineType', $this->soapline);
  1560. }
  1561. function page_template()
  1562. {
  1563. $this->debug("Page Template");
  1564. }
  1565. }
  1566. // -----------------------------------------------------------------------------
  1567. // Class reportico_report_html_template
  1568. // -----------------------------------------------------------------------------
  1569. class reportico_report_html_template extends reportico_report
  1570. {
  1571. var $abs_top_margin;
  1572. var $abs_bottom_margin;
  1573. var $abs_left_margin;
  1574. var $abs_right_margin;
  1575. var $graph_session_placeholder = 0;
  1576. function reportico_report_html_template ()
  1577. {
  1578. return;
  1579. }
  1580. function start ()
  1581. {
  1582. reportico_report::start();
  1583. $this->debug("HTML Start **");
  1584. //pdf_set_info($this->document,'Creator', 'God');
  1585. //pdf_set_info($this->document,'Author', 'Peter');
  1586. //pdf_set_info($this->document,'Title', 'The Title');
  1587. $this->page_line_count = 0;
  1588. $this->abs_top_margin = $this->abs_paging_height($this->get_attribute("TopMargin"));
  1589. $this->abs_bottom_margin = $this->abs_paging_height($this->get_attribute("BottomMargin"));
  1590. $this->abs_right_margin = $this->abs_paging_height($this->get_attribute("RightMargin"));
  1591. $this->abs_left_margin = $this->abs_paging_height($this->get_attribute("LeftMargin"));
  1592. }
  1593. function finish ()
  1594. {
  1595. reportico_report::finish();
  1596. $this->debug("HTML End **");
  1597. if ( $this->line_count < 1 )
  1598. {
  1599. $title = $this->query->derive_attribute("ReportTitle", "Unknown");
  1600. $this->text .= '<H1 class="swRepTitle">'.sw_translate($title).'</H1>';
  1601. $forward = session_request_item('forward_url_get_parameters', '');
  1602. if ( $forward )
  1603. $forward .= "&";
  1604. $this->text .= '<div class="swRepBackBox"><a class="swLinkMenu" href="'.session_request_item('linkbaseurl', SW_USESELF).'?'.$forward.'execute_mode=PREPARE&session_name='.session_id().'">'.sw_translate(SW_MESSAGE_BACK).'</a></div>';
  1605. $this->text .= '<div class="swRepNoRows">No Data Matched Your Criteria</div>';
  1606. }
  1607. if ( $this->report_file )
  1608. {
  1609. $this->debug("Saved to $this->report_file");
  1610. }
  1611. else
  1612. {
  1613. $this->debug("No html file specified !!!");
  1614. $buf = "";
  1615. $len = strlen($buf) + 1;
  1616. print($buf);
  1617. }
  1618. $this->text .= "</TABLE>";
  1619. $this->text .= "</BODY>";
  1620. //$this->text .= "</HTML>";
  1621. }
  1622. function abs_paging_height($height_string)
  1623. {
  1624. $height = (int)$height_string;
  1625. if ( strstr($height_string, "%" ) )
  1626. {
  1627. $height = (int)
  1628. ( $this->page_height * $height_string ) / 100;
  1629. }
  1630. return $height;
  1631. }
  1632. function abs_paging_width($width_string)
  1633. {
  1634. $width = (int)$width_string;
  1635. if ( strstr($width_string, "%" ) )
  1636. {
  1637. $width = (int)
  1638. ( $this->page_width * $width_string ) / 100;
  1639. }
  1640. return $width;
  1641. }
  1642. function format_column_header(& $column_item)
  1643. {
  1644. if ( $this->body_display != "show" )
  1645. return;
  1646. if ( !$this->show_column_header($column_item) )
  1647. return;
  1648. $padstring = $column_item->derive_attribute( "column_title", $column_item->query_name);
  1649. $padstring = str_replace("_", " ", $padstring);
  1650. $padstring = ucwords(strtolower($padstring));
  1651. $padstring = sw_translate($padstring);
  1652. $cw = $column_item->derive_attribute(
  1653. "ColumnWidthHTML", "");
  1654. $just = $column_item->derive_attribute( "justify", "left");
  1655. if ( $cw )
  1656. $this->tag_embed($padstring, "TD", "swRepColHdr", 'align="'.$just.'" width="'.$cw.'"');
  1657. else
  1658. $this->tag_embed($padstring, "TD", "swRepColHdr", 'align="'.$just.'"');
  1659. }
  1660. function tag_embed($output, $tag_type, $class="", $extra="")
  1661. {
  1662. $str = '<'.$tag_type;
  1663. if ( $class ) $str .= ' class="'.$class.'"';
  1664. if ( $extra ) $str .= ' '.$extra.'">';
  1665. $this->text .= $str;
  1666. $this->text .= $output;
  1667. $this->text .= '</'.$tag_type.'>';
  1668. }
  1669. function format_column(& $column_item)
  1670. {
  1671. if ( $this->body_display != "show" )
  1672. return;
  1673. if ( !$this->show_column_header($column_item) )
  1674. return;
  1675. $padstring =& $column_item->column_value;
  1676. $just = $column_item->derive_attribute(
  1677. "justify", "lef…

Large files files are truncated, but you can click here to view the full file