1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| <?PHP
function checkJavaExtension()
{
if(!extension_loaded('java'))
{
$sapi_type = php_sapi_name();
$port = (isset($_SERVER['SERVER_PORT']) && (($_SERVER['SERVER_PORT'])>1024)) ? $_SERVER['SERVER_PORT'] : '8080';
if ($sapi_type == "cgi" || $sapi_type == "cgi-fcgi" || $sapi_type == "cli")
{
if(!(PHP_SHLIB_SUFFIX=="so" && @dl('java.so'))&&!(PHP_SHLIB_SUFFIX=="dll" && @dl('php_java.dll'))&&!(@include_once("C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/JavaBridge/java/Java.inc"))&&!(require_once("C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/JavaBridge/java/Java.inc")))
{
return "java extension not installed.";
}
}
else
{
if(!(@include_once("C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/JavaBridge/java/Java.inc")))
{
require_once("C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/JavaBridge/java/Java.inc");
}
}
}
if(!function_exists("java_get_server_name"))
{
return "The loaded java extension is not the PHP/Java Bridge";
}
return true;
}
/**
* convert a php value to a java one...
* @param string $value
* @param string $className
* @returns boolean success
*/
function convertValue($value, $className)
{
// if we are a string, just use the normal conversion
// methods from the java extension...
try
{
if ($className == 'java.lang.String')
{
$temp = new Java('java.lang.String', $value);
return $temp;
}
else if ($className == 'java.lang.Boolean' ||
$className == 'java.lang.Integer' ||
$className == 'java.lang.Long' ||
$className == 'java.lang.Short' ||
$className == 'java.lang.Double' ||
$className == 'java.math.BigDecimal')
{
$temp = new Java($className, $value);
return $temp;
}
else if ($className == 'java.sql.Timestamp' ||
$className == 'java.sql.Time')
{
$temp = new Java($className);
$javaObject = $temp->valueOf($value);
return $javaObject;
}
}
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;
}
checkJavaExtension();
$objClass = new Java("java.lang.Class");
$objClass->forName('com.mysql.jdbc.Driver');
$objDbm = new Java("java.sql.DriverManager");
$objconn = $objDbm->getConnection("jdbc:mysql://localhost/gestion_missions","root","");
$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
$report = $compileManager->compileReport(realpath("etat/test_etat.jrxml"));
$fillManager = new JavaClass("net.sf.jasperreports.engine.JasperFillManager");
$params = new Java("java.util.HashMap");
$params->put("a", 70);
$emptyDataSource = new Java("net.sf.jasperreports.engine.JREmptyDataSource");
$jasperPrint = $fillManager->fillReport($report, $params, $objconn);
$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
$outputPath = realpath(".")."/"."output.pdf";
$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);
header("Content-type: application/pdf");
readfile($outputPath);
unlink($outputPath);
header('Content-disposition: attachment; filename="'."output.pdf".'.pdf"');
header('Content-Type: application/pdf');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '. @filesize("". "output.pdf".".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."); |
Partager