Exemplo n.º 1
1
<?php

define('JAVA_INC_URL', 'http://localhost:85/JavaBridge/java/Java.inc');
require_once JAVA_INC_URL;
//require_once("http://127.0.0.1:85/JavaBridge/java/Java.inc");
$system = new Java('java.lang.System');
$class = new JavaClass("java.lang.Class");
$class->forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//$class->forName("com.mysql.jdbc.Driver");
$driverManager = new JavaClass("java.sql.DriverManager");
//$conn = $driverManager->getConnection("jdbc:mysql://localhost/stdb?user=sa&password=Tamakogi2012");
$conn = $driverManager->getConnection("jdbc:sqlserver://127.0.0.1;databaseName=st;user=sa;password=Tamakogi2012");
//compliler
$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
$viewer = new JavaClass("net.sf.jasperreports.view.JasperViewer");
$report = $compileManager->compileReport("C:/inetpub/wwwroot/inv_01.jrxml");
//fill
$fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
$params = new Java("java.util.HashMap");
//$params->put("text", "Text");
$params->put("ofYear", 2015.0);
//$params->put("date", convertValue("2007-12-31 0:0:0", "java.sql.Timestamp"));
$emptyDatasource = new JavaClass("net.sf.jasperreports.engine.JREmptyDataSource");
$jasperPrint = $fillManager->fillReport($report, $params, $conn);
$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
$outputPath = realpath(".") . "/" . "output.pdf";
//$exportManager->exportReportToHtml($jasperPrint,$outputPath);
//header("Content-type: application/html");
$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);
header("Content-type: application/pdf");
readfile($outputPath);
Exemplo n.º 2
0
 function compileReporte()
 {
     $ruta = $this->adapter->getReportsPath() . $this->jrxmlName;
     $consulta = $this->query;
     try {
         $jasperxml = new \java("net.sf.jasperreports.engine.xml.JRXmlLoader");
         $jasperDesign = $jasperxml->load(realpath($ruta));
         $query = new \java("net.sf.jasperreports.engine.design.JRDesignQuery");
         if (!empty($consulta)) {
             $consulta = str_replace("\"", "", $consulta);
             $query->setText($consulta);
             $jasperDesign->setQuery($query);
         }
         $compileManager = new \JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
         $report = $compileManager->compileReport($jasperDesign);
     } catch (\JavaException $ex) {
         echo $ex;
     }
     return $report;
 }
Exemplo n.º 3
0
function callReport($nomReport, $arrParam)
{
    global $SYS;
    require_once "Java.inc";
    //java_require(dirname(__FILE__)."/jfreechart-1.0.1.jar");
    java_require(dirname(__FILE__) . "/drivers.jar");
    //java_require("/usr/share/java/postgresql-jdbc3.jar");
    try {
        copy("{$SYS["ROOT"]}/JasperReports/phpjasper/Pool/{$nomReport}.jrxml", "/tmp/{$nomReport}.jrxml");
        $jcm = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
        $report = $jcm->compileReport("/tmp/{$nomReport}.jrxml");
        $jfm = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
        $Conn = new Java("org.altic.jasperReports.JdbcConnection");
        $Conn->setDriver("org.postgresql.Driver");
        $Conn->setConnectString("jdbc:mysql://{$_SERVER["SERVER_NAME"]}:3306/{$SYS["mysql"]["DBNAME"]}");
        // Parche tonto
        // 		$Conn->setConnectString("jdbc:postgresql://localhost:5432/{$_SESSION['dbname']}"); //
        $Conn->setUser("ascore");
        $Conn->setPassword("ascore");
        if ($Conn->getConnection()) {
            $parameters = new Java("java.util.HashMap");
            /* PARAMETROS */
            foreach ($arrParam as $n => $v) {
                // Tendré que comprobar el tipo, pasar ad_reference_id por parámetro
                if (isset($v['type'])) {
                    if ($v['type'] == "Date") {
                        $ts1 = text_to_int($v['value']);
                        $JAVA_PAR = new Java("java.util.Date", date("Y", $ts1) - 1900, date("m", $ts1) - 1, date("d", $ts1));
                        $parameters->put($n, $JAVA_PAR);
                    } else {
                        if ($v['type'] == "Integer") {
                            $JAVA_PAR = new Java("java.lang.Integer", $v['value']);
                            //die( "NOMBRE PARAM: $n ; VALOR: {$v['value']} <br />");
                            $parameters->put($n, $JAVA_PAR);
                        } else {
                            if ($v['type'] == "Boolean") {
                                $JAVA_PAR = new Java("java.lang.Boolean", $v['value']);
                                $parameters->put($n, $JAVA_PAR);
                            } else {
                                if ($v['type'] == "Double") {
                                    $JAVA_PAR = new Java("java.lang.Double", $v['value']);
                                    $parameters->put($n, $JAVA_PAR);
                                } else {
                                    $parameters->put($n, $v['value']);
                                }
                            }
                        }
                    }
                } else {
                    $parameters->put($n, $v['value']);
                }
            }
            $parameters->put("REPORT_DIR", "/tmp/tmp/");
            $print = $jfm->fillReport($report, $parameters, $Conn->getConnection());
            $listaPag = $print->getPages();
            $numPag = $listaPag->size();
            if ($numPag == '0') {
                // Mostramos mensaje, el documento no contiene páginas (Usar div similar al session caducada)
                $_SESSION['msgDocInfo'] = "El documento no tiene p&aacute;ginas.";
            } else {
                $filem = time();
                $finalname = "/tmp/{$filem}.pdf";
                $jem = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
                $jem->exportReportToPdfFile($print, $finalname);
                while (ob_end_clean()) {
                }
                if (file_exists($finalname)) {
                    header('Content-type: application/pdf');
                    header("Content-Disposition: attachment; filename=\"{$finalname}\"");
                    readfile($finalname);
                }
                die;
            }
        } else {
            echo "ERRORS";
        }
    } catch (JavaException $ex) {
        /*$trace = new Java("java.io.ByteArrayOutputStream");
        		$ex->printStackTrace(new Java("java.io.PrintStream", $trace));
        		print "java stack trace: $trace\n";*/
        ob_end_clean();
        echo "<pre>ERROR<br>";
        echo "Cause: " . $ex->getCause() . "<br>";
        echo "Message: " . $ex->getMessage() . "</pre>";
    }
}
Exemplo n.º 4
0
 function fillDB($db, $fileInput, $fileOutput, $fileType, $parameters, $classPath, $save)
 {
     $params = $this->prepareParameters($parameters);
     $params->put('REPORT_LOCALE', new Java("java.util.Locale", 'pt', 'BR'));
     $extension = substr($fileInput, strrpos($fileInput, '.'));
     try {
         $sJfm = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
         if ($extension == ".jrxml") {
             $s1 = new JavaClass("net.sf.jasperreports.engine.xml.JRXmlLoader");
             $jasperDesign = $s1->load($fileInput);
             $sJcm = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
             $report = $sJcm->compileReport($jasperDesign);
         } else {
             $report = $fileInput;
         }
         // Create the JDBC Connection
         $conn = new Java("org.altic.jasperReports.JdbcConnection");
         // Call the driver to be used
         $conn->setDriver(\Manager::getConf("db.{$db}.jdbc.driver"));
         // Connection URL
         $conn->setConnectString(\Manager::getConf("db.{$db}.jdbc.db"));
         // Server Connection Username
         $conn->setUser(\Manager::getConf("db.{$db}.user"));
         // Server Connection Password
         $conn->setPassword(\Manager::getConf("db.{$db}.password"));
         $print = $sJfm->fillReport($report, $params, $conn->getConnection());
         $sJem = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
         $output = \Manager::getDownloadURL('report', basename($this->fileOutput), true);
         $sJem->exportReportToPdfFile($print, $fileOutput);
     } catch (Exception $e) {
         dump_java_exception($e);
     }
     return $output;
 }
 function reporte($id = null)
 {
     require_once "http://localhost:8080/JavaBridge/java/Java.inc";
     $parteId = $id;
     $params = new Java("java.util.HashMap");
     $params->put("parteid", $parteId);
     try {
         $jasperxml = new java("net.sf.jasperreports.engine.xml.JRXmlLoader");
         $jasperDesign = $jasperxml->load(realpath("InformedePartes.jrxml"));
         $query = new java("net.sf.jasperreports.engine.design.JRDesignQuery");
         $query->setText("select u.username, p.* ,t.inicial as tinicial, t.final as tfinal, t.entrada as tentrada, t.salida as tsalida,\n\t\t\t\t\t\t\tr.inicial as rinicial, r.final as rfinal, r.entrada as rentrada, r.salida as rsalida,\n\t\t\t\t\t\t\te.inicial as einicial, e.final as efinal,\n\t\t\t\t\t\t\te2.entrada as eeentrada, e2.salida as eesalida, e2.inicial as eeinicial, e2.final as eefinal\n\t\t\t\t\t\tfrom partes p , textos t ,reales r , enteros e,  enteros e2, users u\n\t\t\t\t\t\twhere  p.id=t.parte_id and p.id=r.parte_id and p.id=e.parte_id and p.id=e2.parte_id and p.id={$parteId}\n\t\t\t\t\t\tand e.tipocampos_tipoparte_id=2 and e2.tipocampos_tipoparte_id=6 and u.id=p.usuariovendedor;");
         $jasperDesign->setQuery($query);
         $compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
         $report = $compileManager->compileReport($jasperDesign);
     } catch (JavaException $ex) {
         echo $ex;
     }
     $fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
     $class = new JavaClass("java.lang.Class");
     $class->forName("com.mysql.jdbc.Driver");
     $driverManager = new JavaClass("java.sql.DriverManager");
     //db username and password
     $conn = $driverManager->getConnection("jdbc:mysql://localhost:3306/estacion?zeroDateTimeBehavior=convertToNull", "root", "");
     $jasperPrint = $fillManager->fillReport($report, $params, $conn);
     $exporter = new java("net.sf.jasperreports.engine.JRExporter");
     $outputPath = realpath(".") . "\\" . "InformedePartes.pdf";
     $exporter = new java("net.sf.jasperreports.engine.export.JRPdfExporter");
     $exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->JASPER_PRINT, $jasperPrint);
     $exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->OUTPUT_FILE_NAME, $outputPath);
     header("Content-type: application/pdf");
     header("Content-Disposition: attachment; filename=InformedePartes.pdf");
     $exporter->exportReport();
     readfile($outputPath);
     unlink($outputPath);
 }
                    } else {
                        $tipo = "Cadena";
                    }
                }
                $atomParam["paratype"] = $tipo;
                $atomParam["value"] = $dato;
                $P[] = $atomParam;
            } else {
                $informe = $dato;
            }
        }
    }
}
$it = $URLBASE . $informe . ".jrxml";
$jcm = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
$report = $jcm->compileReport($URLBASE . $informe . ".jrxml");
try {
    $jfm = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
    $Conn = new Java("org.altic.jasperReports.JdbcConnection");
    $Conn->setDriver("com.mysql.jdbc.Driver");
    $Conn->setConnectString("jdbc:mysql://localhost:3306/{$SYS["mysql"]["DBNAME"]}");
    $Conn->setUser($SYS["mysql"]["DBUSER"]);
    $Conn->setPassword($SYS["mysql"]["DBPASS"]);
    if ($Conn->getConnection()) {
        $parameters = new Java("java.util.HashMap");
        foreach ($P as $k => $v) {
            if ($v["paratype"] == "Fecha") {
                ereg("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})", $v["value"], $bloques);
                $ts1 = strtotime($bloques[3] . "-" . $bloques[2] . "-" . $bloques[1]);
                $JAVA_PAR = new Java("java.util.Date", date("y", $ts1) + 100, date("m", $ts1) - 1, date("d", $ts1));
                $parameters->put($v["paraname"], $JAVA_PAR);
 function reporte()
 {
     require_once "http://localhost:8080/JavaBridge/java/Java.inc";
     try {
         $jasperxml = new java("net.sf.jasperreports.engine.xml.JRXmlLoader");
         $jasperDesign = $jasperxml->load(realpath("InformedeUsuarios.jrxml"));
         $query = new java("net.sf.jasperreports.engine.design.JRDesignQuery");
         $query->setText("select users.*, roles.name\n\t\t\t\t\tfrom users INNER JOIN roles ON users.role_id=roles.id");
         $jasperDesign->setQuery($query);
         $compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
         $report = $compileManager->compileReport($jasperDesign);
     } catch (JavaException $ex) {
         echo $ex;
     }
     $fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
     $params = new Java("java.util.HashMap");
     $params->put("title", "Customer");
     $class = new JavaClass("java.lang.Class");
     $class->forName("com.mysql.jdbc.Driver");
     $driverManager = new JavaClass("java.sql.DriverManager");
     //db username and password
     $conn = $driverManager->getConnection("jdbc:mysql://localhost:3306/estacion?zeroDateTimeBehavior=convertToNull", "root", "");
     $jasperPrint = $fillManager->fillReport($report, $params, $conn);
     $exporter = new java("net.sf.jasperreports.engine.JRExporter");
     $outputPath = realpath(".") . "\\" . "InformedeUsuarios.pdf";
     $exporter = new java("net.sf.jasperreports.engine.export.JRPdfExporter");
     $exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->JASPER_PRINT, $jasperPrint);
     $exporter->setParameter(java("net.sf.jasperreports.engine.JRExporterParameter")->OUTPUT_FILE_NAME, $outputPath);
     header("Content-type: application/pdf");
     header("Content-Disposition: attachment; filename=InformedeUsuarios.pdf");
     $exporter->exportReport();
     readfile($outputPath);
     unlink($outputPath);
 }
 public function execute($output, Doctrine_Connection $con = null)
 {
     require_once sfConfig::get('psdf_report_java_inc');
     //Declare the paths where the JRXML Reports are stored)
     $reportFileName = sfConfig::get('psdf_report_dir') . DIRECTORY_SEPARATOR . $this->getFileName();
     $salidaFileName = tempnam(sys_get_temp_dir(), 'jr') . '.' . $output;
     if (!file_exists($reportFileName)) {
         throw new sfException(sprintf('Verificar el archivo <strong>%s</strong> del reporte <strong>%s</strong> no existe en <strong>%s</strong>', $this->getFileName(), $this->getName(), sfConfig::get('psdf_reports_dir')));
     }
     // Corrigo posibles rutas incorrectas en imagenes
     $jrxml = new psdfJrXml($reportFileName);
     $jrxml->fixPathImages(sfConfig::get('psdf_report_resource_dir'));
     $jrxml->file_save();
     // Parametros (a que sea dinamico)
     /* $params['fecha_desde'] = $this->getRequestParameter('fechadesde');
        $params['fecha_hasta'] = $this->getRequestParameter('fechahasta');
        $params['unidadorg_origen'] = $this->getRequestParameter('unidadorg');
        $params['nombre_unidadorg'] = $this->getRequestParameter('rel_busca_unidad');  */
     //Begin the Procedure for the Report
     try {
         // recupera los datos de conexion a la base de datos
         $datos = psdfReportPluginUtil::dataConnection($this->getConnection());
         // Create the JDBC Connection
         $Conn = new Java("org.altic.jasperReports.JdbcConnection");
         // Call the driver to be used
         $Conn->setDriver("org.postgresql.Driver");
         // Connection URL (since it is in the server, it can be defined as localhost)
         $Conn->setConnectString(sprintf("jdbc:postgresql://%s/%s", $datos['host'], $datos['dbname']));
         $Conn->setUser($datos['username']);
         $Conn->setPassword($datos['password']);
         // Compile the JRXML in Jasper
         $sJcm = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
         $report = $sJcm->compileReport($reportFileName);
         //Mapping fields (please refer to the note on top)
         $map = new Java("java.util.HashMap");
         // Parametros
         /*foreach ($this->getParametroConsultas() as $param) {
               $value = $this->getParam($param->getNombre());
               if ($param->getTipo() == 'A') {
                   $map->put($param->getNombre(), $value);
               } else if ($param->getTipo() == 'N') {
                   $map->put($param->getNombre(), new Java('java.lang.Integer', $value));
               } else {// si no es ni A y N es D
                   // Convierto la fecha a dd/MM/yyyy
                   //$fecha = substr($value,0,2).'/'.substr($value,3,2).'/'.substr($value,6,4);
                       $temp = new Java('java.text.SimpleDateFormat', "dd/MM/yyyy");
                   $date = $temp->parse($value);
                   //die('fecha '.$date);
                   $map->put($param->getNombre(), $date);
               }
           }*/
         // What we are using to fill the model
         $sJfm = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
         $print = $sJfm->fillReport($report, $map, $Conn->getConnection());
         // Export the final report format to pdf u other
         $sJem = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
         // a pdf
         if ($output == PluginPsdfReportTable::TO_PDF) {
             $sJem->exportReportToPdfFile($print, $salidaFileName);
             psdfReportPluginUtil::download($salidaFileName, $this->getName() . '.' . $output);
         }
     } catch (JavaException $ex) {
         $trace = new Java("java.io.ByteArrayOutputStream");
         $ex->printStackTrace(new Java("java.io.PrintStream", $trace));
         throw new sfException('java stack trace: ' . $trace);
     }
 }
Exemplo n.º 9
0
 function cetak($rpt, $param_data = array(), $type = "pdf", $ignore_html_pg = TRUE)
 {
     error_reporting(E_ALL);
     ini_set('display_errors', 'On');
     $checkJavaExt = $this->checkJavaExtension();
     if (!$checkJavaExt) {
         return $checkJavaExt;
     }
     // $rpt = 'simple';
     // $report     = dirname(__FILE__)."//..//modules//".active_module()."//reports//{$rpt}.jasper";
     // $reportx    = dirname(__FILE__)."//..//modules//".active_module()."//reports//{$rpt}.jrxml";
     $outputPath = dirname(__FILE__) . "//..//modules//" . active_module() . "//reports//{$rpt}";
     $reportx = dirname(__FILE__) . "//..//modules//" . active_module() . "//reports//{$rpt}.jrxml";
     // $outputPath = sys_get_temp_dir()."//{$rpt}"; //buang ke tmp ajah
     // die ($reportx);
     $compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
     $report = $compileManager->compileReport($reportx);
     $params = new Java("java.util.HashMap");
     foreach ($param_data as $prm => $val) {
         $params->put($prm, $val);
     }
     // if ($type=="html") {
     if ($ignore_html_pg == TRUE) {
         $params->put("IS_IGNORE_PAGINATION", true);
     }
     java('java.lang.Class')->forName('org.postgresql.Driver');
     $conn = java('java.sql.DriverManager')->getConnection("jdbc:postgresql://localhost:{$this->port}/{$this->db}?user={$this->usr}&password={$this->pwd}");
     $emptyDataSource = new Java("net.sf.jasperreports.engine.JREmptyDataSource");
     $fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
     $jasperPrint = $fillManager->fillReport($report, $params, $conn);
     /* */
     // bagus niy cm kayanya bakal tampil diserver.. hmmm nanti dah
     // $viewer = new JavaClass("net.sf.jasperreports.view.JasperViewer");
     // $viewer->viewReport($jasperPrint, false);
     // $conn->close();
     // die();
     /* */
     $exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
     if ($type == "html") {
         $exportManager->exportReportToHtmlFile($jasperPrint, $outputPath);
         header("Content-type: text/html");
     } else {
         $exportManager->exportReportToPdfFile($jasperPrint, $outputPath);
         header("Content-type: application/pdf");
         // paksa donlot ?
         // header('Content-Disposition: attachment;filename="' . $rpt . '.pdf"');
     }
     /* */
     // oh buat ngeprint...
     // $printManager = new JavaClass("net.sf.jasperreports.engine.JasperPrintManager");
     // $printManager->printPages($jasperPrint, 0,0, true);
     /* */
     readfile($outputPath);
     @unlink($outputPath);
     $conn->close();
 }
Exemplo n.º 10
0
 $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");
     // driver
     $Conn->setDriver("com.mysql.jdbc.Driver");
     // url de connexion
     $Conn->setConnectString("jdbc:mysql://localhost/erpmart");
     $Conn->setUser("root");
     // mot de passe
     $Conn->setPassword(null);
     $sJcm = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
     $report = $sJcm->compileReport($reportsPath . $reportFileName . ".jrxml");
     $sJfm = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
     $print = $sJfm->fillReport($report, new Java("java.util.HashMap"), $Conn->getConnection());
     $sJem = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
     $sJem->exportReportToPdfFile($print, $reportsPath . $reportFileName . ".pdf");
     if (file_exists($reportsPath . $reportFileName . ".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.");
     }