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;
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');
62 header('Content-type: text/xml');
67 $srcTmp = ini_get('session.save_path') . '/' .uniqid('gnumeric_').'.gnumeric';
68 $targetTmp = ini_get('session.save_path') . '/' .uniqid('gnumeric_').'.xls';
69 // write the gnumeric file...
70 $fh = fopen($srcTmp,'w');
75 require_once 'System.php';
76 $ss = System::which('ssconvert');
78 " --import-encoding=Gnumeric_XmlIO:sax" .
79 " --export-type=Gnumeric_Excel:excel_biff8 " .
80 $srcTmp . ' ' . $targetTmp . ' 2>&1';
82 //passthru($cmd);exit;
87 if (!file_exists($targetTmp) || !filesize($targetTmp)) {
88 header("HTTP/1.0 400 Internal Server Error - Convert error");
89 die("ERROR CONVERTING?:" . $cmd ."\n<BR><BR> OUTPUT:". htmlspecialchars($out));
92 $fname .= preg_match('/\.xls/i', $fname) ? '' : '.xls'; // make sure it ends in xls..
93 $fh = fopen($targetTmp, 'r');
94 header('Content-type: application/vnd.ms-excel');
95 header('Content-Disposition: attachment; filename="' .addslashes($fname). '"');
97 // will not work on IE... - needs while/fget..