Better file name management

This commit is contained in:
fhenry 2013-04-20 11:03:23 +02:00
parent 96126d9c99
commit ffb97010c9
2 changed files with 497 additions and 492 deletions

View File

@ -448,12 +448,16 @@ IMG;
*/ */
public function exportAsAttachedPDF($name="") public function exportAsAttachedPDF($name="")
{ {
global $conf;
if( $name == "" ) $name = md5(uniqid()); if( $name == "" ) $name = md5(uniqid());
//dol_syslog(get_class($this).'::exportAsAttachedPDF $name='.$name, LOG_DEBUG); //dol_syslog(get_class($this).'::exportAsAttachedPDF $name='.$name, LOG_DEBUG);
$this->saveToDisk($name); $this->saveToDisk($name);
$execmethod=(empty($conf->global->MAIN_EXEC_USE_POPEN)?1:2); // 1 or 2 $execmethod=(empty($conf->global->MAIN_EXEC_USE_POPEN)?1:2); // 1 or 2
$name=str_replace('.odt', '', $name);
$command = DOL_DOCUMENT_ROOT.'/includes/odtphp/odt2pdf.sh '.$name; $command = DOL_DOCUMENT_ROOT.'/includes/odtphp/odt2pdf.sh '.$name;
//dol_syslog('$execmethod='.$execmethod.' Run command='.$command); //dol_syslog('$execmethod='.$execmethod.' Run command='.$command);
if ($execmethod == 1) if ($execmethod == 1)
@ -487,11 +491,12 @@ IMG;
throw new OdfException("headers already sent ($filename at $linenum)"); throw new OdfException("headers already sent ($filename at $linenum)");
} }
if (!empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
header('Content-type: application/pdf'); header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="'.$name.'.pdf"'); header('Content-Disposition: attachment; filename="'.$name.'.pdf"');
readfile("$name.pdf"); readfile("$name.pdf");
//unlink("$name.odt"); }
//unlink("$name.pdf"); unlink("$name.odt");
} else { } else {
//dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG); //dol_syslog(get_class($this).'::exportAsAttachedPDF $ret_val='.$retval, LOG_DEBUG);
//dol_syslog(get_class($this).'::exportAsAttachedPDF $output_arr='.var_export($output_arr,true), LOG_DEBUG); //dol_syslog(get_class($this).'::exportAsAttachedPDF $output_arr='.var_export($output_arr,true), LOG_DEBUG);

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# @copyright GPL License 2010 - Vikas Mahajan - http://vikasmahajan.wordpress.com # @copyright GPL License 2010 - Vikas Mahajan - http://vikasmahajan.wordpress.com
if [ -f $1 ] if [ -f "$1.odt" ]
then then
pgrep -U `id -u` soffice pgrep -U `id -u` soffice
if [ $? -ne 0 ] if [ $? -ne 0 ]
@ -9,7 +9,7 @@ then
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
sleep 2 sleep 2
fi fi
jodconverter $1 "$1.pdf" jodconverter "$1.odt" "$1.pdf"
if [ $? -ne 0 ] if [ $? -ne 0 ]
then then
echo "Error while converting odt to pdf" echo "Error while converting odt to pdf"