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
|
<?php
/*
@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);
}
}
?>
|