Initial import
This commit is contained in:
69
application/controllers/tools/Reportdownload.php
Normal file
69
application/controllers/tools/Reportdownload.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
//ini_set('display_errors', '1');
|
||||
//ini_set('display_startup_errors', '1');
|
||||
//error_reporting(E_ALL);
|
||||
//url
|
||||
// http://riau.aplikasi.web.id/birt/frameset?__report=report/one/lab/rpt_test_email.rptdesign&__format=pdf&username=adhi&PID=32626&tm=1591680178071
|
||||
class Reportdownload extends MY_Controller
|
||||
{
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
function index() {
|
||||
//__report=report/one/lab/rpt_test_email.rptdesign&__format=pdf&username=adhi&PID=32626&tm=1591680178071
|
||||
$gets = $this->input->get();
|
||||
$order_header_id = $gets["PID"];
|
||||
$report = $gets["__report"];
|
||||
$report_name = $this->create_report_name($order_header_id,$report);
|
||||
$this->dl_report($gets,$report_name);
|
||||
}
|
||||
function create_report_name($id,$rpt) {
|
||||
$sql = "select T_OrderHeaderLabNumberExt, fn_get_name(T_OrderHeaderM_PatientID) name
|
||||
from t_orderheader where T_OrderHeaderID = ? ";
|
||||
$query = $this->db->query($sql,array($id));
|
||||
$nolab = "unknown-$id";
|
||||
$name = "unknown";
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
if (count($rows) > 0 ) {
|
||||
$name = str_replace(" ", "_", $rows[0]["name"]);
|
||||
$nolab = $rows[0]["T_OrderHeaderLabNumberExt"];
|
||||
}
|
||||
}
|
||||
$pos = strpos($rpt, "rpt_");
|
||||
$rptname = "DEFAULT";
|
||||
if ($pos > 0 ) {
|
||||
$epos = strpos($rpt,"_email");
|
||||
if ($epos > 0 && $epos > $pos ) {
|
||||
$rptname = substr($rpt, $pos + 4 , $epos - $pos - 4 );
|
||||
$rptname = strtoupper($rptname);
|
||||
}
|
||||
}
|
||||
switch($rptname) {
|
||||
case "TEST" :
|
||||
$rptname = "LAB";
|
||||
break;
|
||||
|
||||
}
|
||||
return $rptname . "-" . $nolab . "-" . $name . ".pdf";
|
||||
}
|
||||
function dl_report($prm, $name) {
|
||||
$url = "http://localhost/birt/frameset?" ;
|
||||
$qry = "";
|
||||
foreach($prm as $k => $v) {
|
||||
if ($qry != "" ) $qry .= "&";
|
||||
$qry .= $k . "=" . urlencode($v);
|
||||
}
|
||||
$url .= $qry ;
|
||||
$data = file_get_contents($url);
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename=' . $name);
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Connection: Keep-Alive');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: public');
|
||||
//header('Content-Length: ' . $size);
|
||||
echo $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user