<?php
class show_report_new_class {
	
    function show_report_new_class($reportFileName,$paramsx,$border="") {
        // require_once("http://localhost:8080/JavaBridge/java/Java.inc");
        $reportsPath =_REPORT_PATH;
        $reportsTemp=$reportsPath;
        //$jasperReportsLib =_REPORT_LIPS;
        //$handle = @opendir($jasperReportsLib);
        $limitPage = LIMIT_PAGE_REPORT;

        // mysqli variable
        $mysql_link = mysqli_connect(_SERVER_DB, _USER_DB, _PASS_DB, _NAME_DB) or die(mysqli_error());

        if ($reportFileName == "") {
            throw new Exception('Empty File Name');
        }

        if(!isset($_REQUEST['type'])) {
            $type="html";
        }
        else {
            $type=$_REQUEST['type'];
        }

        try {
                        	
            switch($type) {
                case "html":
                    require_once _REPORT_PATH . $reportFileName . ".php";

/*
                case "excel":
                    $exporter = new java("net.sf.jasperreports.engine.export.JExcelApiExporter");
                    $exParm = java("net.sf.jasperreports.engine.export.JExcelApiExporterParameter");
//                      $exporter = new java("net.sf.jasperreports.engine.export.JRXlsExporter");
//                      $exParm = java("net.sf.jasperreports.engine.export.JRXlsExporterParameter");
                    $javaOutputStream = new Java("java.io.ByteArrayOutputStream");
                    $exporter->setParameter($exParm->JASPER_PRINT, $print);
                    $exporter->setParameter($exParm->OUTPUT_STREAM, $javaOutputStream);
//                      $exporter->setParameter($exParm->OUTPUT_FILE_NAME, "d:/p.xls");
                    $exporter->setParameter($exParm->IS_ONE_PAGE_PER_SHEET, false);
                    $exporter->setParameter($exParm->IS_DETECT_CELL_TYPE, true);
                    $exporter->setParameter($exParm->IS_WHITE_PAGE_BACKGROUND, false);
                    $exporter->setParameter($exParm->IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, false);
                    $exporter->setParameter($exParm->IS_IGNORE_GRAPHICS, false);
                    $exporter->setParameter($exParm->is_Image_Border_Fix_Enabled, true);

                    $exporter->exportReport();
//                          set_time_limit(120);
//                          java_set_file_encoding("ISO-8859-1");
                    header('Content-Description: File Transfer');
                    header('Content-Type: application/octet-stream');
                    header('Content-Disposition: attachment; filename=print.xls');
                    header('Content-Transfer-Encoding: binary');
                    header('Expires: 0');
                    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                    header('Pragma: public');
//                      header('Content-Length: ' . filesize("d:/p.xls"));

                    ob_clean();
                    flush();
                    echo  java_cast($javaOutputStream->toByteArray(),"S");
                    break;

                case "pdf":
//                          $exporter = new java("net.sf.jasperreports.engine.export.JExcelApiExporter");
//                          $exParm = java("net.sf.jasperreports.engine.export.JExcelApiExporterParameter");
//                          $exporter = new java("net.sf.jasperreports.engine.export.JRXlsExporter");
//                          $exParm = java("net.sf.jasperreports.engine.export.JRXlsExporterParameter");

                    $exporter = new java("net.sf.jasperreports.engine.export.JRPdfExporter");
                    $exParm = java("net.sf.jasperreports.engine.JRExporterParameter");

                    $javaOutputStream = new Java("java.io.ByteArrayOutputStream");
                    $exporter->setParameter($exParm->JASPER_PRINT, $print);
                    $exporter->setParameter($exParm->OUTPUT_STREAM, $javaOutputStream);
//                          $exporter->setParameter($exParm->OUTPUT_FILE_NAME, "d:/p.xls");
//                          $exporter->setParameter($exParm->IS_ONE_PAGE_PER_SHEET, false);
//                          $exporter->setParameter($exParm->IS_DETECT_CELL_TYPE, true);
//                          $exporter->setParameter($exParm->IS_WHITE_PAGE_BACKGROUND, false);
//                          $exporter->setParameter($exParm->IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, false);
//                          $exporter->setParameter($exParm->IS_IGNORE_GRAPHICS, false);
//                          $exporter->setParameter($exParm->is_Image_Border_Fix_Enabled, true);


                    $exporter->exportReport();
//                          set_time_limit(120);
//                            java_set_file_encoding("ISO-8859-1");
                                        header('Content-Type: application/pdf');
                                        header('Content-Transfer-Encoding: binary');
                                        header('Content-disposition: attachment; filename="print.pdf"');
                                        header('Pragma: no-cache');
                                        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                                        header('Expires: 0');
//                            header('Content-Length: ' . filesize("d:/p.xls"));

                                            ob_clean();
                                            flush();
                                            echo   java_cast($javaOutputStream->toByteArray(),"S");
                break;*/
            }

        } catch (Exception $e) {   
            echo 'Caught exception: ',  $e->getMessage(), "\n";

        }

                                
    }
}

// 14.03.2020 : backup Jasper report java class
class show_report_class {
	
	function show_report_class($reportFileName,$paramsx,$border="") {
//         pr($paramsx);
		require_once("http://localhost:8080/JavaBridge/java/Java.inc");
		$reportsPath =_REPORT_PATH;
		$jasperReportsLib =_REPORT_LIPS;
		$reportsTemp=$reportsPath;
		$handle = @opendir($jasperReportsLib);
                $limitPage = LIMIT_PAGE_REPORT;
                
		while(($new_item = readdir($handle))!==false) {
				$java_library_path .= 'file:'.$jasperReportsLib.'/'.$new_item .';';
		}
		try {
                        java_require($java_library_path);

                        $Conn = new Java("org.altic.jasperReports.JdbcConnection");
                        $Conn->setDriver("com.mysql.jdbc.Driver");
                        $Conn->setConnectString("jdbc:mysql://"._SERVER_DB."/"._NAME_DB."?characterEncoding=UTF8");
                        $Conn->setUser(_USER_DB);
                        $Conn->setPassword(_PASS_DB);
                        $sJcm = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
                        $params = new Java("java.util.HashMap");
                        foreach ($paramsx as $key => $value) {
                           $params->put($value["name"], convertValue($value["value"],$value["type"]));
                        }
                        $sJfm = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
                        if(!file_exists($reportsPath .$reportFileName.".jasper")) {
                                $report = $sJcm->compileReport($reportsPath .$reportFileName.".jrxml");
                                $print = $sJfm->fillReport($report,$params,$Conn->getConnection());
                        }
                        else {
                                $report = $reportsPath .$reportFileName.".jasper";
                                $print = $sJfm->fillReport($report,$params,$Conn->getConnection());
                        }
                        $sJem = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
				
                        if(!isset($_REQUEST['type'])) {
                            $type="html";
                        }
                        else {
                            $type=$_REQUEST['type'];
                        }
                        
                        switch($type) {
                            case "html":
                                $exporter = new java("net.sf.jasperreports.engine.export.JRHtmlExporter");
                                $exParm =  java("net.sf.jasperreports.engine.export.JRHtmlExporterParameter");

                                $header="   <head>
                                                <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1' />
                                                  <style type='text/css'>
                                                        body
                                                        {
                                                                color: black;
                                                                background-color: white;
                                                                margin: 0px 0px 0px 0px;


                                                        }
                                                        $border
                                                        span.breakhere {page-break-before: always}

                                                </style>
                                            </head>
                                            <html>

                                            <script type='text/javascript' src='script/report.js'></script>
                                            <body>		
                                                    <script>function test(n,m) {
                                                            window.location='#JR_PAGE_ANCHOR_0_'+m;
                                                    }

                                            </script>								
                                        ";
                                $record_count=$print->getPages()->size();
                                $record_count_int=(int)"$record_count";
                                if(!$_REQUEST['page']) {
                                  $_REQUEST['page']=1;
                                }
                                  
                                $record1= ($_REQUEST['page']-1) * $limitPage;
                                $record2=$record1 + $limitPage -1;
//                              echo "record1 : $record1 \n";
//                              echo "record2 : $record2*$record_count_int";
                                 
                                for($i=$record_count_int-1;$i>$record2;$i--) {
//                                  echo $record2."#";
                                    $print->removePage(new Java('java.lang.Integer',$record2+1 ));
                                }
//
//
                                for($i=0;$i<$record1;$i++) {
                                             $print->removePage(new Java('java.lang.Integer',0 ));
                                }
                               
                                $footer=" 	<script>showListLaporan2('query2.php?code=xx&page_count={$record_count}&page={$_REQUEST['page']}');</script>
							
                                                </body>
                                                </html> 
                                                <script>reSizeLaporan();</script>";
							 
                                $javaOutputStream = new Java("java.io.ByteArrayOutputStream");
                                $exporter->setParameter($exParm->JASPER_PRINT, $print);
                                $exporter->setParameter($exParm->OUTPUT_STREAM, $javaOutputStream);
                                $exporter->setParameter($exParm->SIZE_UNIT, "pt");
    //                          $exporter->setParameter($exParm->PAGE_INDEX, new Java('java.lang.Integer',7 ) );
                                $exporter->setParameter($exParm->BETWEEN_PAGES_HTML,"<span class='breakhere'></span>");
                                $exporter->setParameter($exParm->HTML_HEADER, $header);
                                $exporter->setParameter($exParm->HTML_FOOTER, $footer);
                                $exporter->setParameter($exParm->IS_WRAP_BREAK_WORD,new Java('java.lang.Boolean', "true") );
                                #$exporter->setParameter($exParm->IS_USING_IMAGES_TO_ALIGN,new Java('java.lang.Boolean', "false") );
                                #$exporter->setParameter($exParm->IS_WRAP_BREAK_WORD,new Java('java.lang.Boolean', "false") );
				
                                $exporter->exportReport();	
                                echo java_cast($javaOutputStream->toByteArray(),"S");
                                break;
                        
                            case "excel":
                                $exporter = new java("net.sf.jasperreports.engine.export.JExcelApiExporter");
                                $exParm = java("net.sf.jasperreports.engine.export.JExcelApiExporterParameter");
        //                      $exporter = new java("net.sf.jasperreports.engine.export.JRXlsExporter");
        //                      $exParm = java("net.sf.jasperreports.engine.export.JRXlsExporterParameter");
                                $javaOutputStream = new Java("java.io.ByteArrayOutputStream");
                                $exporter->setParameter($exParm->JASPER_PRINT, $print);
                                $exporter->setParameter($exParm->OUTPUT_STREAM, $javaOutputStream);
        //                      $exporter->setParameter($exParm->OUTPUT_FILE_NAME, "d:/p.xls");
                                $exporter->setParameter($exParm->IS_ONE_PAGE_PER_SHEET, false);
                                $exporter->setParameter($exParm->IS_DETECT_CELL_TYPE, true);
                                $exporter->setParameter($exParm->IS_WHITE_PAGE_BACKGROUND, false);
                                $exporter->setParameter($exParm->IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, false);
                                $exporter->setParameter($exParm->IS_IGNORE_GRAPHICS, false);
                                $exporter->setParameter($exParm->is_Image_Border_Fix_Enabled, true);

                                $exporter->exportReport();
        //                          set_time_limit(120);
        //                          java_set_file_encoding("ISO-8859-1");
                                header('Content-Description: File Transfer');
                                header('Content-Type: application/octet-stream');
                                header('Content-Disposition: attachment; filename=print.xls');
                                header('Content-Transfer-Encoding: binary');
                                header('Expires: 0');
                                header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                                header('Pragma: public');
        //                      header('Content-Length: ' . filesize("d:/p.xls"));

                                ob_clean();
                                flush();
                                echo  java_cast($javaOutputStream->toByteArray(),"S");
                                break;
                    
                    case "pdf":
//                          $exporter = new java("net.sf.jasperreports.engine.export.JExcelApiExporter");
//                          $exParm = java("net.sf.jasperreports.engine.export.JExcelApiExporterParameter");
//                          $exporter = new java("net.sf.jasperreports.engine.export.JRXlsExporter");
//                          $exParm = java("net.sf.jasperreports.engine.export.JRXlsExporterParameter");

                        $exporter = new java("net.sf.jasperreports.engine.export.JRPdfExporter");
                        $exParm = java("net.sf.jasperreports.engine.JRExporterParameter");

                        $javaOutputStream = new Java("java.io.ByteArrayOutputStream");
                        $exporter->setParameter($exParm->JASPER_PRINT, $print);
                        $exporter->setParameter($exParm->OUTPUT_STREAM, $javaOutputStream);
//                          $exporter->setParameter($exParm->OUTPUT_FILE_NAME, "d:/p.xls");
//                          $exporter->setParameter($exParm->IS_ONE_PAGE_PER_SHEET, false);
//                          $exporter->setParameter($exParm->IS_DETECT_CELL_TYPE, true);
//                          $exporter->setParameter($exParm->IS_WHITE_PAGE_BACKGROUND, false);
//                          $exporter->setParameter($exParm->IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, false);
//                          $exporter->setParameter($exParm->IS_IGNORE_GRAPHICS, false);
//                          $exporter->setParameter($exParm->is_Image_Border_Fix_Enabled, true);


                        $exporter->exportReport();
//                          set_time_limit(120);
//                            java_set_file_encoding("ISO-8859-1");
					    header('Content-Type: application/pdf');
					    header('Content-Transfer-Encoding: binary');
					    header('Content-disposition: attachment; filename="print.pdf"');
					    header('Pragma: no-cache');
					    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
					    header('Expires: 0');
//                            header('Content-Length: ' . filesize("d:/p.xls"));

						ob_clean();
						flush();
						echo   java_cast($javaOutputStream->toByteArray(),"S");
                    break;
                }
			} catch (JavaException $ex) {
				$trace = new Java("java.io.ByteArrayOutputStream");
				$ex->printStackTrace(new Java("java.io.PrintStream", $trace));
				print "java stack trace: $trace\n";
		}
                
                                
	}
}

function show_report($reportFileName,$paramsx,$border="",$limitPage=_LIMIT_PAGE_REPORT) {
   $r=new show_report_class($reportFileName,$paramsx,$border,$limitPage);
   // $r=new show_report_new_class($reportFileName,$paramsx,$border,$limitPage);
}

/*function show_report_test($reportFileName,$paramsx,$border="") {
    require_once("http://localhost:8080/JavaBridge/java/Java.inc");
   
    $reportsPath ="C:/wamp_new/www/isdmi/";
    $reportsPathx ="C:/wamp_new/www/isdmi/report/crprint01_invoice.jasper";
    $jasperReportsLib = "C:/Program Files/Java/ireport_lib/lib";
    $reportsTemp=$reportsPath;
    $handle = @opendir($jasperReportsLib);
  
    while(($new_item = readdir($handle))!==false) {
            $java_library_path .= 'file:'.$jasperReportsLib.'/'.$new_item .';';
    }
    try {
             
            java_require($java_library_path);
            
            $Conn = new Java("org.altic.jasperReports.JdbcConnection");	
            $Conn->setDriver("com.mysql.jdbc.Driver");
            $Conn->setConnectString("jdbc:mysql://localhost/isdmi");
            $Conn->setUser("root");
            $Conn->setPassword("");
          
            $sJcm = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
           
           
//            die($reportsPathx);
//            $report = $sJcm->compileReport($reportsPathx);


            $params = new Java("java.util.HashMap");
           
            foreach ($paramsx as $key => $value) {
               $params->put($value["name"], convertValue($value["value"],$value["type"]));
            }

            $sJfm = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
            if(!file_exists($reportsPath .$reportFileName.".jasper")) {
                $report = $sJcm->compileReport($reportsPath .$reportFileName.".jrxml");
                $print = $sJfm->fillReport($report,$params,$Conn->getConnection());
            }
            else {
                $report = $reportsPath .$reportFileName.".jasper";
                $print = $sJfm->fillReport($report,$params,$Conn->getConnection());
            }
            
            $sJem = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
    		
//            $r="pdf";
            $r="html";
            
            if($r=="pdf") {
//                  set_time_limit(120);
//                  java_set_file_encoding("ISO-8859-1");
//                  $exporter = new java("net.sf.jasperreports.engine.export.JRPdfExporter");
//                  $exParm = java("net.sf.jasperreports.engine.JRExporterParameter");
//                  $exporter->setParameter($exParm->JASPER_PRINT, $report);
//                  $exporter->setParameter($exParm->OUTPUT_STREAM, $javaOutputStream);
//                  $exporter->exportReport();
//                  header('Content-Type: application/pdf');
//                  header('Content-Transfer-Encoding: binary');
//                  header('Content-disposition: attachment; filename="'.$reportFileName.'.pdf"');
//                  header('Pragma: no-cache');
//                  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
//                  header('Expires: 0');
//                  echo java_cast($javaOutputStream->toByteArray(),"S");
              //  outputPDF($print,$reportFileName);
                @unlink($reportsTemp .$reportFileName.".pdf");
                $sJem->exportReportToPdfFile($print, $reportsTemp .$reportFileName.".pdf");
                if (file_exists($reportsPath .$reportFileName.".pdf")){

                     header("Content-type: application/pdf");
                     header('Content-disposition: attachment; filename="'.$reportFileName.'.pdf"');
                     header('Content-Type: application/pdf');
                     header('Content-Transfer-Encoding: binary');
                     header('Content-Length: '. @filesize($reportsPath . $reportFileName.".pdf"));
                     header('Pragma: no-cache');
                     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                     header('Expires: 0');
                     set_time_limit(0);
                     @readfile($reportsPath .$reportFileName.".pdf") or die("problem occurs.");
                      unlink($reportsPath .$reportFileName.".pdf");
                 }
            }
            else {
                  
                    // @unlink($reportsPath .$reportFileName.".html");
                    // $sJem->exportReportToHtmlFile($print, $reportsPath .$reportFileName.".html");
                    // $m=uniqid();
                    // header("Location:".$reportFileName.".html?m=".$m);
                 

//                set_time_limit(120);


                  $exporter = new java("net.sf.jasperreports.engine.export.JRHtmlExporter");
                  $exParm =  java("net.sf.jasperreports.engine.export.JRHtmlExporterParameter");

                  $header="<head>
                                    <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1' />
                                    <style type='text/css'>
                                        body
                                        {
                                            color: black;
                                            background-color: white;
                                            margin: 0px 0px 0px 0px;
                                           

                                        }
                                        $border
                                        span.breakhere {page-break-before: always}

                                    </style>
                                </head>
                                <html>
                                <body>   
                                
                            ";
                   $footer=" <script>
                                function reSizeLaporan()
                                    {
                                    //alert('suhut');
                                    var gContainer=parent;

                                    try{
                                    var oBody=document.body;
                                    var oFrame=gContainer.document.getElementById('iframe_laporan');
                                        if(oFrame.style.width>oBody.scrollWidth  + (oBody.offsetWidth - oBody.clientWidth)) {
                                                oFrame.style.width='100%';
                                              oFrame.style.height = oBody.scrollHeight  + (oBody.offsetHeight - oBody.clientHeight);
                                              oFrame.style.width = oBody.scrollWidth  + (oBody.offsetWidth - oBody.clientWidth);
                                         }
                                         else {
                                                 // oFrame.style.width='100%';
                                                 oFrame.style.height = oBody.scrollHeight  + (oBody.offsetHeight - oBody.clientHeight);
                                                 oFrame.style.width = oBody.scrollWidth  + (oBody.offsetWidth - oBody.clientWidth);

                                         }
                                           document.getElementById('iframe_laporan').style.display='';
                                    }

                                    //An  error is raised if the IFrame domain != its container's domain
                                    catch(e)
                                    {
                                    //window.status  ='Error: ' + e.number + ';  ' + e.description;
                                    }
                                    }
                                   
                                </script>

                                </body>
                               </html> <script> reSizeLaporan();</script>";

//                   $javaOutputStream = new java("java.io.ByteArrayOutputStream");
//                   set_time_limit(120);
//                  java_set_file_encoding("ISO-8859-1");
                  $exporter->setParameter($exParm->JASPER_PRINT, $print);
//                $exporter->setParameter($exParm->OUTPUT_STREAM, $javaOutputStream);
                  $exporter->setParameter($exParm->OUTPUT_FILE_NAME,$reportsPath .$reportFileName.".html");
                  $exporter->setParameter($exParm->SIZE_UNIT, "pt");
//                $exporter->setParameter($exParm->IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,new Java('java.lang.Boolean', "true") );
//                $exporter->setParameter($exParm->IS_OUTPUT_IMAGES_TO_DIR,new Java('java.lang.Boolean', "true") );
//                $exporter->setParameter($exParm->IS_USING_IMAGES_TO_ALIGN,new Java('java.lang.Boolean', "false") );

					

             
                   $exporter->setParameter($exParm->BETWEEN_PAGES_HTML,"<span class='breakhere'></span>");
                   $exporter->setParameter($exParm->HTML_HEADER, $header);
                   $exporter->setParameter($exParm->HTML_FOOTER, $footer);
                   $exporter->setParameter($exParm->IS_WRAP_BREAK_WORD,new Java('java.lang.Boolean', "true") );
                  

                
                  $exporter->exportReport();
				
//                  echo java_cast($javaOutputStream->toByteArray(),"S");
                    $m=uniqid();
                    header("Location:".$reportFileName.".html?m=".$m);	   
            }

    } catch (JavaException $ex) {
             $trace = new Java("java.io.ByteArrayOutputStream");
            $ex->printStackTrace(new Java("java.io.PrintStream", $trace));
            print "java stack trace: $trace\n";
    }

    
}*/

function convertValue($value, $type)  
{  
    // if we are a string, just use the normal conversion  
    // methods from the java extension...  
    try   
    {  
        switch($type) {
            case "string":
               $temp = new Java('java.lang.String', $value);             
            break;
            case "integer":
                $temp = new Java('java.lang.Integer', $value);  
            break;
            case "boolean":
                $temp = new Java('java.lang.Boolean', $value); 
            break;
            case "long":
                $temp = new Java('java.lang.Long', $value);
            break;
            case "short":
                $temp = new Java('java.lang.Short', $value);
            break;
            case "double":
                 $temp = new Java('java.lang.Double', $value);
            break;
            case "bigdecimal":
                 $temp = new Java('java.math.BigDecimal', $value);
            break;
            case "timespamp":                 
                  $temp1 = new Java('java.sql.Timestamp');  
                  $temp = $temp1->valueOf($value);  
            break;
            case "time":
                  $temp1 = new Java('java.sql.Time');  
                  $temp = $temp1->valueOf($value);            
            break;
            case "date":
                  $temp1 = new Java('java.sql.Timestamp');  
                  $temp = $temp1->valueOf($value);  
            break;
            default :
                  die("Type  ".$type." tidak ada ...");
            break;
            
        }
        
        return $temp;
    }  
    
    catch (Exception $err)  
    {  
        echo (  'unable to convert value, ' . $value .  
                ' could not be converted to ' . $className);  
        return false;  
    }
  
    echo (  'unable to convert value, class name '.$className.  
            ' not recognised');  
    return false;  
}

/*function outputHTML($report) {
          $javaOutputStream = new java("java.io.ByteArrayOutputStream");
          set_time_limit(120);
          java_set_file_encoding("ISO-8859-1");
          $exporter = new java("net.sf.jasperreports.engine.export.JRPdfExporter");
          $exParm = java("net.sf.jasperreports.engine.JRExporterParameter");
          $exporter->setParameter($exParm->JASPER_PRINT, $report);
          $exporter->setParameter($exParm->OUTPUT_STREAM, $this->javaOutputStream);
          $exporter->setParameter($exParm->sizeUnit, $javaOutputStream,"pt");

          $exporter->exportReport();
          header('Content-Type: text/html');
          header('Content-Transfer-Encoding: binary');
          header('Content-disposition: attachment; filename="'.$name.'.html"');
          header('Pragma: no-cache');
          header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
          header('Expires: 0');
          echo java_cast($javaOutputStream->toByteArray(),"S");
      }


 function outputPDF($report,$name) {
          set_time_limit(120);
          java_set_file_encoding("ISO-8859-1");
          $exporter = new java("net.sf.jasperreports.engine.export.JRPdfExporter");
          $exParm = java("net.sf.jasperreports.engine.JRExporterParameter");
          $exporter->setParameter($exParm->JASPER_PRINT, $report);
          $exporter->setParameter($exParm->OUTPUT_STREAM, $javaOutputStream);
          $exporter->exportReport();
          header('Content-Type: application/pdf');
          header('Content-Transfer-Encoding: binary');
          header('Content-disposition: attachment; filename="'.$name.'.pdf"');
          header('Pragma: no-cache');
          header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
          header('Expires: 0');
          echo java_cast($javaOutputStream->toByteArray(),"S");
      }

  function outputXLS($report,$name) {
          set_time_limit(120);
          java_set_file_encoding("ISO-8859-1");
          $exporter = new java("net.sf.jasperreports.engine.export.JRXlsExporter");
          $exParm = java("net.sf.jasperreports.engine.JRExporterParameter");
          $exXlsParm = java("net.sf.jasperreports.engine.export.JRXlsExporterParameter");
          $exporter->setParameter($exParm->JASPER_PRINT, $report);
          $exporter->setParameter($exParm->OUTPUT_STREAM, $javaOutputStream);
          $exporter->setParameter($exXlsParm->IS_ONE_PAGE_PER_SHEET, true);
          $exporter->setParameter($exXlsParm->IS_DETECT_CELL_TYPE, true);
          $exporter->exportReport();
          header('Content-Type: application/xls');
          header('Content-Transfer-Encoding: binary');
          header('Content-disposition: attachment; filename="'.$name.'.xls"');
          header('Pragma: no-cache');
          header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
          header('Expires: 0');
          echo java_cast($javaOutputStream->toByteArray(),"S");
      }*/

?>
				
				
