예제 #1
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>";
    }
}
예제 #2
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;
 }
예제 #3
0
 /**
  * Configura el schema para la conexion toba_db que se le provee
  * @param toba_db $conexion
  * @return JDBC 
  */
 protected function configurar_bd(&$conexion)
 {
     $params = $conexion->get_parametros();
     //Creamos la conexión JDBC
     $con = new Java("org.altic.jasperReports.JdbcConnection");
     //Seteamos el driver jdbc
     $con->setDriver("org.postgresql.Driver");
     $port = isset($params['puerto']) ? ":" . $params['puerto'] : '';
     $con->setConnectString("jdbc:postgresql://" . $params['profile'] . $port . '/' . $params['base']);
     //Especificamos los datos de la conexión, cabe aclarar que esta conexion es la del servidor de producción
     $con->setUser($params['usuario']);
     $con->setPassword($params['clave']);
     $con1 = $con->getConnection();
     if (isset($params['schema'])) {
         $sql = "SET search_path = \"{$params['schema']}\", \"public\";";
         $stmt = $con1->createStatement();
         $stmt->executeUpdate($sql);
         toba::logger()->debug("Seteo el esquema por defecto para el reporte: {$sql}");
     }
     return $con1;
 }
            } 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);
            } else {
                if ($v["paratype"] == "Entero") {
                    $JAVA_PAR = new Java("java.lang.Integer", (int) $v["value"]);
                    $parameters->put($v["paraname"], $JAVA_PAR);
                    //$parameters->put($v["paraname"],$JAVA_PAR);
                } else {
                    if ($v["paratype"] == "Cadena") {
 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);
     }
 }
예제 #6
0
$jasperReportsLib = "/home/ccharly/publichtml/utils/jasperlib";
if (extension_loaded('java')) {
    $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);