diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php index e1a5e5270..c74691575 100644 --- a/include/class_acc_ledger.php +++ b/include/class_acc_ledger.php @@ -2305,7 +2305,7 @@ class Acc_Ledger extends jrn_def_sql $value = 0; return $value; } - + /** * @brief create the invoice and saved it as attachment to the * operation, @@ -2321,7 +2321,8 @@ class Acc_Ledger extends jrn_def_sql $doc->f_id = $e_client; $doc->md_id = $gen_doc; $doc->ag_id = 0; - $doc->Generate($p_array); + $filename=""; + $doc->Generate($p_array,$p_array['e_pj']); // Move the document to the jrn $doc->MoveDocumentPj($internal); // Update the comment with invoice number, if the comment is empty diff --git a/include/class_document.php b/include/class_document.php index 55fba3be6..1f7c70324 100644 --- a/include/class_document.php +++ b/include/class_document.php @@ -62,16 +62,28 @@ class Document $this->db->exec_sql($sql); } - + function compute_filename($pj,$filename) + { + foreach (array('/','*','<','>',';',',','\\','.',':') as $i) { + $pj= str_replace($i, "-",$pj); + } + // save the suffix + $pos_prefix=strrpos($filename,"."); + if ($pos_prefix == 0) $pos_prefix=strlen($filename); + $filename_no=substr($filename,0,$pos_prefix); + $filename_suff=substr($filename,$pos_prefix,strlen($filename)); + $new_filename= strtolower($filename_no."-".$pj.$filename_suff); + return $new_filename; + } /*! * \brief Generate the document, Call $this-\>Replace to replace * tag by value - *\p_array contains the data normally it is the $_POST - * + *@param p_array contains the data normally it is the $_POST + *@param contains the new filename * \return an array : the url where the generated doc can be found, the name * of the file and his mimetype */ - function Generate($p_array) + function Generate($p_array,$p_filename="") { // create a temp directory in /tmp to unpack file and to parse it $dirname=tempnam($_ENV['TMP'],'doc_'); @@ -144,7 +156,10 @@ class Document $file_to_parse=$filename; } + if ( $p_filename !="") { + $this->d_filename=$this->compute_filename($p_filename, $this->d_filename); + } $this->SaveGenerated($dirname.DIRECTORY_SEPARATOR.$file_to_parse); // Invoice $ret='Document généré'; @@ -244,7 +259,7 @@ class Document if ( strpos($value,'ERROR') != false ) $value=""; /* * Change type of cell to numeric - * allow numeric cel in ODT for the formatting and formula + * allow numeric cel in ODT for the formatting and formula */ if ( is_numeric($value) && $p_type=='OOo') {