diff --git a/src/classes/reports/report.class.php b/src/classes/reports/report.class.php index 61bb808..f522614 100644 --- a/src/classes/reports/report.class.php +++ b/src/classes/reports/report.class.php @@ -496,6 +496,15 @@ abstract class Report { return $this->_arrOutputTargetDetails; } + /* + * Helper function to return the OutputTarget + */ + public function GetOutputTarget() + { + // return OutputTarget + return $this->_outputTarget; + } + /* * Helper function to trigger initialisation */ @@ -546,15 +555,18 @@ abstract class Report { /* * This function outputs the report to the browser in the desired format! */ - public function OutputReport($szOutputBuffer) + public function OutputReport($szOutputBuffer, &$szErrorStr) { global $gl_root_path; + // Helper variable, init with buffer + $szFinalOutput = $szOutputBuffer; + $res = SUCCESS; + // Simple HTML Output! if ( $this->_outputFormat == REPORT_OUTPUT_HTML ) { - // HTML Header - echo $szOutputBuffer; + // do nothing } else if ( $this->_outputFormat == REPORT_OUTPUT_PDF ) { @@ -568,8 +580,51 @@ abstract class Report { // $pdf->SetFontSize(12); $pdf->WriteHTML( $szOutputBuffer ); // Header('Content-Type: application/pdf'); - $pdf->Output('', 'I'); // Output to STANDARD Input! + $szFinalOutput = $pdf->Output('', 'S'); // Output to STANDARD Input! } + + // Simple HTML Output! + if ( $this->_outputTarget == REPORT_TARGET_STDOUT ) + { + // Kindly output to browser + echo $szFinalOutput; + $res = SUCCESS; + } + else if ( $this->_outputTarget == REPORT_TARGET_FILE ) + { + // Get Filename first + if ( isset($this->_arrOutputTargetDetails['filename']) ) + { + // Get Filename property + $szFilename = $this->_arrOutputTargetDetails['filename']; + + // Create file and Write Report into it! + $handle = @fopen($szFilename, "w"); + if ( $handle === false ) + { + $szErrorStr = "Could not create '" . $szFilename . "'!"; + $res = ERROR; + } + else + { + fwrite($handle, $szFinalOutput); + fflush($handle); + fclose($handle); + + // For result + $szErrorStr = "Results were saved into '" . $szFilename . "'"; + $res = SUCCESS; + } + } + else + { + $szErrorStr = "The parameter 'filename' was missing."; + $res = ERROR; + } + } + + // return result + return $res; } } diff --git a/src/lang/en/main.php b/src/lang/en/main.php index 03941cf..4969ae1 100644 --- a/src/lang/en/main.php +++ b/src/lang/en/main.php @@ -348,6 +348,8 @@ $content['LN_ORACLE_WHOIS'] = "WHOIS Lookup for '%1' value '%2'"; $content['LN_REPORT_FILTERTYPE_DATE'] = "Date"; $content['LN_REPORT_FILTERTYPE_NUMBER'] = "Number"; $content['LN_REPORT_FILTERTYPE_STRING'] = "String"; - + $content['LN_GEN_SUCCESS_WHILEREPORTGEN'] = "Report was successfully generated"; + $content['LN_GEN_ERROR_REPORTFAILEDTOGENERATE'] = "Failed to generate report, error details: %1"; + $content['LN_GEN_SUCCESS_REPORTWASGENERATED_DETAILS'] = "Successfully generated report: %1"; ?> \ No newline at end of file diff --git a/src/reportgenerator.php b/src/reportgenerator.php index 987dcbd..d64955c 100644 --- a/src/reportgenerator.php +++ b/src/reportgenerator.php @@ -55,6 +55,7 @@ InitReportModules(); // --- READ CONTENT Vars $content['error_occured'] = false; +$content['report_success'] = false; if ( isset($_GET['op']) ) $content['op'] = DB_RemoveBadChars($_GET['op']); @@ -82,63 +83,6 @@ else $content['error_occured'] = "error"; $content['error_details'] = $content['LN_GEN_ERROR_MISSINGSAVEDREPORTID']; } - -/* -if ( isset($_GET['width']) ) -{ - $content['chart_width'] = intval($_GET['width']); - - // Limit Chart Size for now - if ( $content['chart_width'] < 100 ) - $content['chart_width'] = 100; - else if ( $content['chart_width'] > 1000 ) - $content['chart_width'] = 1000; -} -else - $content['chart_width'] = 100; - -if ( isset($_GET['byfield']) ) -{ - if ( isset($fields[ $_GET['byfield'] ]) ) - { - $content['chart_field'] = $_GET['byfield']; - $content['chart_fieldtype'] = $fields[ $content['chart_field'] ]['FieldType']; - } - else - { - $content['error_occured'] = true; - $content['error_details'] = $content['LN_GEN_ERROR_INVALIDFIELD']; - } -} -else -{ - $content['error_occured'] = true; - $content['error_details'] = $content['LN_GEN_ERROR_MISSINGCHARTFIELD']; -} - -if ( isset($_GET['maxrecords']) ) -{ - // read and verify value - $content['maxrecords'] = intval($_GET['maxrecords']); - if ( $content['maxrecords'] < 2 || $content['maxrecords'] > 100 ) - $content['maxrecords'] = 10; -} -else - $content['maxrecords'] = 10; - -if ( isset($_GET['showpercent']) ) -{ - // read and verify value - $content['showpercent'] = intval($_GET['showpercent']); - if ( $content['showpercent'] >= 1 ) - $content['showpercent'] = 1; - else - $content['showpercent'] = 0; -} -else - $content['showpercent'] = 0; -*/ - // --- // --- BEGIN CREATE TITLE @@ -218,9 +162,20 @@ if ( !$content['error_occured'] ) // Parse template $page -> parser($content, $myReportObj->GetBaseFileName()); - // Output to browser - $myReportObj->OutputReport( $page ->result() ); - //$page->output(); + // Output the result + $res = $myReportObj->OutputReport( $page ->result(), $szErrorStr ); + if ( $res == SUCCESS && $myReportObj->GetOutputTarget() != REPORT_TARGET_STDOUT ) + { + // Output wasn't STDOUT, so we need to display what happened to the user + $content['report_success'] = true; + $content['error_details'] = GetAndReplaceLangStr($content["LN_GEN_SUCCESS_REPORTWASGENERATED_DETAILS"], $szErrorStr); + } + else if ( $res == ERROR ) + { + // Output failed, display what happened to the user + $content['error_occured'] = true; + $content['error_details'] = GetAndReplaceLangStr($content["LN_GEN_ERROR_REPORTFAILEDTOGENERATE"], $szErrorStr); + } // --- } } @@ -240,11 +195,14 @@ if ( !$content['error_occured'] ) } // Output error if necessary -if ( $content['error_occured'] ) +if ( $content['error_occured'] || $content['report_success'] ) { -// $content['TITLE'] = InitPageTitle(); - $content['TITLE'] .= " :: " . $content['LN_GEN_ERROR_WHILEREPORTGEN']; + if ( $content['error_occured'] ) + $content['TITLE'] .= " :: " . $content['LN_GEN_ERROR_WHILEREPORTGEN']; + else + $content['TITLE'] .= " :: " . $content['LN_GEN_SUCCESS_WHILEREPORTGEN']; + // Create template Parser and output results InitTemplateParser(); $page -> parser($content, "reportgenerator.html"); $page -> output(); diff --git a/src/templates/reportgenerator.html b/src/templates/reportgenerator.html index 815de57..d241ed4 100644 --- a/src/templates/reportgenerator.html +++ b/src/templates/reportgenerator.html @@ -8,6 +8,7 @@
@@ -22,6 +23,23 @@ |
+ {LN_GEN_SUCCESS_WHILEREPORTGEN}+ |
+|
{LN_GEN_MESSAGEDETAILS} | +
+ + {error_details} + + |
+