11 * format = [empty=xls] , 'gnumeric' (download format)
12 * debug = true => download xml.
18 require_once 'Pman.php';
19 class Pman_Core_GnumericToExcel extends Pman
23 $au = $this->getAuthUser();
25 die("NOT authenticated");
27 $this->authUser = $au;
31 function get($v, $opts=array())
35 function post($fname) {
37 $ml = (int) ini_get('suhosin.post.max_value_length');
38 if (empty($_POST['xml'])) {
39 header("HTTP/1.0 400 Internal Server Error");
40 die( $ml ? "Suhosin Patch enabled - try and disable it!!!" : 'no XML sent');
43 if (empty($_POST['xml'])) {
44 header("HTTP/1.0 400 Internal Server Error");
45 die("Missing XML attribute");
49 $xml = iconv("UTF-8", "UTF-8//IGNORE", $xml);
51 //$xml = str_replace('�', 'e', $xml);
52 //$xml = str_replace("\xA0", ' ', $xml);
53 //$xml = str_replace("�", 'dia.',$xml);
55 //$this->addEvent("DOWNLOAD", false, isset($_REQUEST['title']) ? $_REQUEST['title'] : '???');
58 if (!empty($_POST['format']) && $_POST['format']=='gnumeric') {
59 if (empty($_POST['debug'])) {
60 header('Content-type: application/x-gnumeric');
61 header('Content-Disposition: attachment; filename="' .addslashes($fname). '.gnumeric"');
63 header('Content-type: text/xml');
70 $outfmt = 'Gnumeric_Excel:excel_biff8';
71 $mime = 'application/vnd.ms-excel';
72 /* if (!empty($_POST['format']) && $_POST['format']=='xlsx') {
73 $outfmt = 'Gnumeric_Excel:xlsx';
75 $mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
81 $srcTmp = $this->tempName('gnumeric');
82 $targetTmp = $this->tempName($ext);
83 // write the gnumeric file...
84 $fh = fopen($srcTmp,'w');
89 require_once 'System.php';
90 $xvfb = System::which('xvfb-run');
92 $ss = System::which('ssconvert');
93 $cmd = $xvfb . " -a " . $ss.
94 " --import-encoding=Gnumeric_XmlIO:sax" .
95 " --export-type={$outfmt} " .
96 $srcTmp . ' ' . $targetTmp . ' 2>&1';
98 //passthru($cmd);exit;
103 if (!file_exists($targetTmp) || !filesize($targetTmp)) {
104 header("HTTP/1.0 400 Internal Server Error - Convert error");
105 die("ERROR CONVERTING?:" . $cmd ."\n<BR><BR> OUTPUT:". htmlspecialchars($out));
107 if (!empty($_POST['format']) && $_POST['format']=='xlsx') {
108 require_once 'File/Convert.php';
109 $cc = new File_Convert($targetTmp,'application/vnd.ms-excel');
110 $targetTmp = $cc->convert('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
120 $fname = basename($targetTmp);
122 $fname .= preg_match('/\.' . $ext . '/i', $fname) ? '' : ('.' . $ext); // make sure it ends in xls..
124 header('Content-type: ' . $mime);
125 header('Content-Disposition: attachment; filename="' .addslashes($fname). '"');
126 header('Content-length: '. filesize($targetTmp));
127 header("Content-Transfer-Encoding: binary");
128 if ($file = fopen($targetTmp, 'rb')) {
129 while(!feof($file) and (connection_status()==0)) {
130 print(fread($file, 1024*8));