88 $this->CachedMultyFS =
get_package(
'cached_multy_fs' ,
'last' , __FILE__ );
89 $this->Database =
get_package(
'database' ,
'last' , __FILE__ );
90 $this->PageJS =
get_package(
'page::page_js' ,
'last' , __FILE__ );
91 $this->ReportUtilities =
get_package(
'report::report_utilities' ,
'last' , __FILE__ );
92 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
93 $this->String =
get_package(
'string' ,
'last' , __FILE__ );
94 $this->Utilities =
get_package(
'utilities' ,
'last' , __FILE__ );
125 $this->PageJS->add_javascript(
"{http_host}/$PackagePath/include/js/report.js" );
128 $Lang->include_strings_js(
'report' );
130 catch( Exception $e )
162 $Reports = $this->ReportUtilities->get_reports_list( $Settings );
167 foreach( $Reports as $i => $r )
170 $Titles [] = basename( $r ,
'.rep' );
173 $Subfolder = $Settings->get_setting(
'subfolder' ,
'' );
174 if( $Subfolder !=
'' )
176 $Subfolder =
'<input type="hidden" name="subfolder" value="'.$Subfolder.
'">';
179 $Code =
"$Subfolder{select:class=width_320 flat;".$Settings->get_all_settings().
';first='.
180 implode(
'|' , $Ids ).
';second='.implode(
'|' , $Titles ).
'}';
184 catch( Exception $e )
220 $Name = $Settings->get_setting(
'name' );
222 $this->Templates [ $Name ] = $Data;
224 catch( Exception $e )
252 private function get_raw_template( &$Settings )
256 $Name = $Settings->get_setting(
'name' ,
false );
258 if( $Name ===
false )
260 $TemplateName = $Settings->get_setting(
'template_package_name' );
261 $TemplateVersion = $Settings->get_setting(
'template_package_version' ,
'last' );
262 $TemplateName = $Settings->get_setting(
'template' );
264 $Path =
_get_package_path_ex( $TemplateName , $TemplateVersion ).
"/res/templates/$TemplateName";
265 $RawTemplate = $this->CachedMultyFS->file_get_contents( $Path );
269 $RawTemplate = $this->Templates[ $Name ];
272 return( $RawTemplate );
274 catch( Exception $e )
306 $RawTemplate = $this->get_raw_template( $Settings );
308 $Records = $this->Utilities->get_records();
312 foreach( $Records as $k => $r )
314 $Template = $RawTemplate;
315 $Template = $this->String->print_record( $Template , $r );
316 $Template = str_replace(
317 array(
'{rowid}' ,
'{recid}' ,
'{odd_factor}' ) ,
318 array( $k + 1 , $k , $k % 2 ?
'odd' :
'even' ) , $Template
326 catch( Exception $e )
358 $Settings->set_undefined(
'id' , md5( microtime(
true ) ) );
359 $Settings->set_undefined(
'package_version' ,
'last' );
361 $Code = $this->CachedMultyFS->get_template( __FILE__ ,
'report_button.tpl' );
363 $Code = $this->String->print_record( $Code , $Settings->get_raw_settings() );
367 catch( Exception $e )
409 if( $Subfolder !=
'' )
411 $ReportsPath .= $Subfolder.
'/';
415 $Reports = $this->Utilities->get_files_from_directory( $ReportsPath ,
'/\.rep/' );
416 $Report = $Reports[ $ReportTemplate ];
417 return( $this->CachedMultyFS->file_get_contents( $Report ) );
419 catch( Exception $e )
443 private function prepare_report_template( &$Package )
447 if( $this->Security->get_gp(
'report_template' ,
'integer' ,
false ) !== false )
451 $this->Security->get_gp(
'report_package_name' ,
'string' ) ,
452 $this->Security->get_gp(
'report_package_version' ,
'string' ,
'last' ) ,
453 $this->Security->get_gp(
'report_template' ,
'integer' ) ,
454 $this->Security->get_gp(
'subfolder' ,
'command' ,
'' )
456 $Package->Output = $this->String->print_record( $ReportTemplate , $Package->Output );
459 catch( Exception $e )
493 private function compile_report( &$Package , $FunctionName , &$Options )
497 call_user_func( array( $Package , $FunctionName ) , $Options );
499 $this->prepare_report_template( $Package );
501 $Extension = $this->Security->get_gp(
'output' ,
'string' ,
'txt' );
502 $Extension = $Options->get_setting(
'output' , $Extension );
504 header(
'HTTP/1.0 200 OK' );
505 header(
'Content-type: application/octet-stream' );
506 header(
'Content-Length: '.strlen( $Package->Output ) );
507 header(
'Content-Disposition: attachment; filename="'.date(
'YmdHid' ).
".$Extension".
'"' );
508 header(
'Connection: close' );
510 $this->Output = $Package->Output;
512 catch( Exception $e )
540 private function get_report_generator( &$Options )
544 $PackageName = $this->Security->get_gp(
'report_package_name' ,
'string' ,
false );
545 $PackageName = $Options->get_setting(
'report_package_name' , $PackageName );
547 if( $PackageName ===
false )
552 $PackageVersion = $this->Security->get_gp(
'report_package_version' ,
'string' ,
'last' );
553 $PackageVersion = $Options->get_setting(
'report_package_version' , $PackageVersion );
555 $Package =
get_package( $PackageName , $PackageVersion , __FILE__ );
559 catch( Exception $e )
587 $Package = $this->get_report_generator( $Options );
589 if( $Package ===
false )
596 $FunctionName = $this->Security->get_gp(
'func_name' ,
'string' ,
'report' );
597 $FunctionName = $Options->get_setting(
'func_name' , $FunctionName );
599 if( method_exists( $Package , $FunctionName ) )
601 $this->compile_report( $Package , $FunctionName , $Options );
605 $Message =
"Method \"$FunctionName\" does not exists in the package \"".get_class( $Package ).
"\"";
606 throw(
new Exception( $Message ) );
608 catch( Exception $e )
642 return( $this->Output );
644 catch( Exception $e )