Made a button, busy icon when clicked, nothing happens

I created a button like this:

<input type="button" id="SaveToExcel" name="save" value="Export
to Excel" class="BtnUnpressed"><br>

I call the export function using jQuery like this:

$('#SaveToExcel').mouseup(function() { FileserversGrid.toExcel("http://pathtofile/generate.php"); });

After I click the button, the cursor changes to busy, the status bar in my browser shows that it is connecting to the server and waiting on a response, but nothing happens. No file dialog is displayed, no new tabs, no new windows…nothing. I unzipped the PHP zip and call it with an absolute path as shown above. I know the PHP file is being called because I put this in it:

system("ls > file");

and there is a file called “file” with the contents of an ls in the same directory as generate.php.

Also, it is creating a bunch of files like these in the folder that contains generate.php:

-rw------- 1 <user> <group> 0 2012-03-28 09:56 phpxltmpWFHUez -rw------- 1 <user> <group> 0 2012-03-28 10:10 phpxltmpvDtyIE




Sorry for all of the posts, but I keep finding more information that may be helpful to the debug effort.

I added export to PDF functionality and it works perfectly. I did everything exactly the same. All of the code is literally side-by-side and the only differences are button IDs in the jQuery statements and the function calls to create the excel document and PDF document. The folder hierarchy was created exactly the same way.

Hi,
when you call export script it creates debug__xxxx_xx_xx.xml file with some information. Please, attach one of this files. By the way, debug mode may be turned off in generate.php:

$debug = false;

Are you using the last export version from here?
viewtopic.php?f=23&t=20151

I downloaded the entire grid library from the dhtmlx website a week or two ago, so I think my version of the export file should be new.

It is generating the xml correctly. Here is an example with two rows: debug_2012_03_29__11_43_29.zip (443 Bytes)

The temp files it keeps trying to make called phpxltmp* are zero size, which seems to be the problem. It’s like it can’t write to the file or something, but the permissions should be set such that it can.


I found out some more information about where it is dying. I was correct when I assumed the zero length temp file had something to do with it. I searched for the name of the temp file as follows:

03/29/12 12:04:21 > grep xltmp lib/PHPExcel/*/* lib/PHPExcel/Writer/Excel2007.php: $pFilename = @tempnam('./', 'phpxltmp');

So I went to lib/PHPExcel/Write/Excel2007.php and started adding debug statements. I put the following statement in many places in order to see where execution stopped:

system("ls > fileN");

and here is the result:


The errant line of code is as follows:

$objZip = new $zipClass();

And here is some even better information:

errno:2048 errstr:date(): It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Denver' for 'MDT/-6.0/DST' instead errfile:<path to file>/common/toexcel/generate.php errline:17

Your error handler is not very good, so I spruced it up a little by doing this:

[code]function PDFErrorHandler ($errno, $errstr, $errfile, $errline) {
global $xmlString;

system("echo \"errno:$errno\nerrstr:$errstr\nerrfile:$errfile\nerrline:$errline\" > errfile");


if ($errno < 1024) {
	error_log($xmlString, 3, 'error_report_'.date("Y_m_d__H_i_s").'.xml');

// exit(1);
}

}[/code]

The system(“echo…”) produced the error codes shown above. This doesn’t explain why the Excel2007.php file is dying, but it’s something.

And yet more debug information…

It died while executing printGridExcel() in gridExcelGenerator.php;

public function printGrid($xml) { $this->headerParse($xml->head); $this->footerParse($xml->foot); $this->mainParse($xml); $this->collectionsParse($xml->coll_options); $this->rowsParse($xml->row); $this->printGridExcel(); }

So, let’s go to that function. Then it died while executing $this->wrapper->outXLS(…):

public function printGridExcel() { $this->wrapper = new gridExcelWrapper(); $this->wrapper->createXLS(...); $this->wrapper->headerPrint(...); for ($i = 0; $i < count($this->rows); $i++) $this->wrapper->rowPrint(...); $this->wrapper->footerPrint(...); $this->wrapper->outXLS($this->title, $this->outputType); }

That is in another file, so let’s go there. In gridExcelWrapper.php it dies while trying to execute $objWriter->save(‘php://output’);

[code] public function outXLS($title, $type = ‘Excel2007’) {
$this->excel->getActiveSheet()->setTitle($title);
$this->excel->setActiveSheetIndex(0);

	switch (strtolower($type)) {
		case 'excel2003':
			$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
			header('Content-Type: application/vnd.ms-excel');
			header('Content-Disposition: attachment;filename="grid.xls"');
			header('Cache-Control: max-age=0');
			break;
		case 'csv':
			$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'CSV');
			$objWriter->setDelimiter(';');
			header("Content-type: application/csv");
			header("Content-Disposition: attachment; filename=grid.csv");
			header("Pragma: no-cache");
			header("Expires: 0");
			break;
		case 'excel2007':
		default:
			$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel2007');
			header('Content-Type: application/xlsx');
			header('Content-Disposition: attachment;filename="grid.xlsx"');
			header('Cache-Control: max-age=0');
			break;
	}
	$objWriter->save('php://output'); 
}[/code]

I don’t know where to go from here.

Oh, nevermind, tracing through the broken printGrid stuff lead me right back to the initial problem statement:

$objzip = new $zipClass();

Something about that just isn’t working correctly.

Finally, I think I figured it out. You should put a big warning on your website that PHP must be compiled with --enable-zip, otherwise this will not work.

The ZipArchive class can’t be found on my system. I don’t know for sure that this is the only problem because I’m stuck, but it’s certainly part of it. Once I am able to move past this, I’ll post an update.

[code]class PHPExcel_Settings
{
/** constants */
const PCLZIP = ‘PHPExcel_Shared_ZipArchive’;
const ZIPARCHIVE = ‘ZipArchive’;

private static $_zipClass	= self::ZIPARCHIVE;
    ...

}[/code]

Trying to create a new instance of ZipArchive fails.

Hi,
so much text, but it’s really good job :wink: .
By the way, you was the first one with such problem.

Sorry for all the posts. I just wanted to be thorough so you could see what I had already tried. I also like to document things in case someone else searches for a solution to the same issue.

Google fodder: “dhtmlxgrid export to Excel needs ZipArchive class support by building PHP with --enable-zip”

Oh, sorry, one other thing. Why didn’t the error log show that the class was unknown? It looks like the error output was setup with E_ALL, so that makes me think it would have complained to stdout. This would have been much easier if the log showed the error :smiley:

Hi,
error_reporting outputs information about sent xml config. But it hides info about error. We will think about more efficient debugging. Thanks for your feedback.