diff options
author | Kirylka <kirylanoshko@gmail.com> | 2015-03-31 17:56:47 +0300 |
---|---|---|
committer | Kirylka <kirylanoshko@gmail.com> | 2015-03-31 17:56:47 +0300 |
commit | f5f99c335707d9b11d40f1eb0f6ddb5a993fd31a (patch) | |
tree | d9c0d3532ec9f0f2fb68e31d2611282ae0642181 /codebase/ConvertService.php | |
parent | 458f0aead573842f1df00ce2ae00334c27f66585 (diff) | |
download | connector-php-f5f99c335707d9b11d40f1eb0f6ddb5a993fd31a.zip connector-php-f5f99c335707d9b11d40f1eb0f6ddb5a993fd31a.tar.gz connector-php-f5f99c335707d9b11d40f1eb0f6ddb5a993fd31a.tar.bz2 |
Creating a new connector for yii2.
Diffstat (limited to 'codebase/ConvertService.php')
-rw-r--r-- | codebase/ConvertService.php | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/codebase/ConvertService.php b/codebase/ConvertService.php new file mode 100644 index 0000000..9fa3261 --- /dev/null +++ b/codebase/ConvertService.php @@ -0,0 +1,71 @@ +<?php + +namespace DHTMLX\Connector; + +use DHTMLX\Connector\Tools\EventMaster; +/* + @author dhtmlx.com + @license GPL, see license.txt +*/ +class ConvertService{ + private $url; + private $type; + private $name; + private $inline; + + public function __construct($url){ + $this->url = $url; + $this->pdf(); + EventMaster::attach_static("connectorInit",array($this, "handle")); + } + public function pdf($name = "data.pdf", $inline = false){ + $this->type = "pdf"; + $this->name = $name; + $this->inline = $inline; + } + public function excel($name = "data.xls", $inline = false){ + $this->type = "excel"; + $this->name = $name; + $this->inline = $inline; + } + public function handle($conn){ + $conn->event->attach("beforeOutput",array($this,"convert")); + } + private function as_file($size, $name, $inline){ + header('Content-Type: application/force-download'); + header('Content-Type: application/octet-stream'); + header('Content-Type: application/download'); + header('Content-Transfer-Encoding: binary'); + + header('Content-Length: '.$size); + if ($inline) + header('Content-Disposition: inline; filename="'.$name.'";'); + else + header('Content-Disposition: attachment; filename="'.basename($name).'";'); + } + public function convert($conn, $out){ + + $str_out = str_replace("<rows>","<rows profile='color'>", $out); + $str_out = str_replace("<head>","<head><columns>", $str_out); + $str_out = str_replace("</head>","</columns></head>", $str_out); + + if ($this->type == "pdf") + header("Content-type: application/pdf"); + else + header("Content-type: application/ms-excel"); + + $handle = curl_init($this->url); + curl_setopt($handle, CURLOPT_POST, true); + curl_setopt($handle, CURLOPT_HEADER, false); + curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); + curl_setopt($handle, CURLOPT_POSTFIELDS, "grid_xml=".urlencode($str_out)); + + + $out->reset(); + $out->set_type("pdf"); + $out->add(curl_exec($handle)); + $this->as_file(strlen((string)$out), $this->name, $this->inline); + + curl_close($handle); + } +}
\ No newline at end of file |