From: Matteo L. <mat...@gm...> - 2004-12-03 07:55:26
|
First of all, thank to all you guys for your wonderful job on the class ... After some trouble I get it working on PHP .. what a wonderful tool ... Some points to spot: 1) There should be an option, in the report tag, to set reportheader behaviour, something like: -don't print page header on first page -print page header before report header -print report header before page header (deafult, actual behaviour). this could be very useful if you want to print logos and header in each page, and include only in the first a report header 2) The XML should be obtained by a socket web request (like fopen in PHP) so you cna handle them dinamically. TO solve this I have written a minimal (alpha) class in PHP to parse the report and cache; the main usage of this is use something like an Include to share header and footer between a whole application ... I also use it to put comments in XML (it's appended to the message) 3) There should really be a way to show errors in PHP pages ... it's very frustrating this way ... Anyway, this tool is going to change my work ... thank you very much ... # ========================================================================= # PHP CLASS : RReport # # Supported (in XML ): # <!-- include report.xml --> # Should be alone on a line, includes the named report. Included report can include others ... # #, // at the beginning of a line let the parser ignore the line <?php dl("librlib.so"); include_once( "class.dbengine.php" ); $REPORT_DIR = "reports"; $REPORT_CACHE_DIR = "reports/cache"; class RReport{ var $_rh; var $dbinit; var $debug; var $formato; var $parametri = Array( ); function RReport( $formato = 'pdf', $debug = 0 ) { $this->_rh = rlib_init( ); $this->formato = $formato; $this->dbinit = 0; $this->debug = 1; } function qbe( $queryname, $table, $example, $limitstart = "", $limitsize = "" ) { global $db; $this->query( $queryname, $db->_qbequery( $table, $example), $limitstart, $limitsize ); } function query( $queryname, $sql ) { global $db; if( $this->dbinit == 0 ){ rlib_add_datasource_mysql($this->_rh, "local_mysql", $db->_dbhost, $db->_dbuser, $db->_dbpass, $db->_dbname ); $this->dbinit = 1; } rlib_add_query_as($this->_rh, "local_mysql", $sql, $queryname ); } function addParameter( $name, $value ) { $this->parametri[$name] = $value; } function addReport( $fn ) { global $REPORT_CACHE_DIR; if( $this->debug || !file_exists( $REPORT_CACHE_DIR . "/" . $fn ) ){ $f = fopen( $REPORT_CACHE_DIR . "/" . $fn, "w" ); fputs( $f, $this->_parseReport( $fn ) ); fclose( $f ); } rlib_add_report( $this->_rh, $REPORT_CACHE_DIR . "/" . $fn ); } function _parseReport( $fn ) { global $REPORT_DIR; global $REPORT_CACHE_DIR; $righe = file( $REPORT_DIR . "/" . $fn ); $ret = ""; for( $i = 0; $i < sizeof( $righe ); $i++ ) { $riga = trim( $righe[$i] ); # ESCLUDO I COMMENTI if( substr( $riga,0,1 ) != "#" && substr( $riga, 0, 2 ) != "//" ) { if( substr( $riga, 0, 4 ) == "<!--" && substr( $riga, -3 ) == "-->" ) { #riga di comando, estraggo ... $words = split( " ", trim( substr( $riga, 4, strlen( $riga ) - 7 ) ) ); switch( strtolower( $words[ 0 ] ) ) { case "include": $ret .= $this->_parseReport( trim( $words[ 1 ] ) ); break; } } else { $ret .= $riga . "\n"; } } } return $ret; } function render( $fn = "stampa.pdf" ) { $pars = array_keys( $this->parametri ); for( $i = 0; $i < sizeof( $pars ); $i++ ){ rlib_add_parameter( $this->_rh, $pars[ $i ], $this->parametri[$pars[$i]] ); } rlib_set_output_format_from_text($this->_rh, $this->formato ); rlib_execute($this->_rh); header(rlib_get_content_type($this->_rh ) ); if( $this->formato == "pdf" ){ header("Content-Disposition: inline; filename=" . $fn ); } rlib_spool($this->_rh); rlib_free($this->_rh); } } ?> |