From 182dd774b610d563cf96633bea48608e5d53db1d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 7 May 2014 09:33:56 +0200 Subject: [PATCH 01/10] Fix: phpunit regression --- htdocs/core/modules/modExpedition.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/modules/modExpedition.class.php b/htdocs/core/modules/modExpedition.class.php index 9c4a6137d61..f21b2d82ec8 100644 --- a/htdocs/core/modules/modExpedition.class.php +++ b/htdocs/core/modules/modExpedition.class.php @@ -103,7 +103,7 @@ class modExpedition extends DolibarrModules $this->const[$r][3] = ""; $this->const[$r][4] = 0; $r++; - + $this->const[$r][0] = "LIVRAISON_ADDON_PDF"; $this->const[$r][1] = "chaine"; $this->const[$r][2] = "typhon"; @@ -270,7 +270,7 @@ class modExpedition extends DolibarrModules $sql = array( "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][2]."' AND entity = ".$conf->entity, "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[0][2]."','shipping',".$conf->entity.")", - "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[2][2]."' AND entity = ".$conf->entity, + "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[3][2]."' AND entity = ".$conf->entity, "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[3][2]."','delivery',".$conf->entity.")", ); From 7fe5389adf0cc7bc867bed80a58cd30c73582146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 7 May 2014 10:41:43 +0200 Subject: [PATCH 02/10] Updated changelog --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 07cd416c214..469dbcb82f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,7 +14,7 @@ Fix: Pb of records not correctly cleaned when module marge is Fix: [ bug #1341 ] Lastname not added by file or direct input in mass e-mailing. Fix: [ bug #1357 ] Invoice creator state not printed in generated invoice documents. Fix: Suppliers invoice mask fails using {tttt} in numbering. -Fix: pdf template name for typhon was not correctly et when enabling module. +Fix: [ bug #1350 ] pdf template name for typhon was not correctly et when enabling module. Fix: Navigation on notes for shipments was not working. Fix: [ bug #1353 ] Email notifications, wrong URL. Fix: [ bug #1362 ] Note is not saved. From 8681079fa7760b89fba083197355eedccae4c1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 7 May 2014 10:42:13 +0200 Subject: [PATCH 03/10] Fixed CR --- htdocs/core/modules/modExpedition.class.php | 2 +- htdocs/livraison/fiche.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/core/modules/modExpedition.class.php b/htdocs/core/modules/modExpedition.class.php index f21b2d82ec8..bdc74a66cf3 100644 --- a/htdocs/core/modules/modExpedition.class.php +++ b/htdocs/core/modules/modExpedition.class.php @@ -102,7 +102,7 @@ class modExpedition extends DolibarrModules $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/shipment"; $this->const[$r][3] = ""; $this->const[$r][4] = 0; - $r++; + $r++; $this->const[$r][0] = "LIVRAISON_ADDON_PDF"; $this->const[$r][1] = "chaine"; diff --git a/htdocs/livraison/fiche.php b/htdocs/livraison/fiche.php index 32c5c474ba1..49049a20783 100644 --- a/htdocs/livraison/fiche.php +++ b/htdocs/livraison/fiche.php @@ -514,16 +514,16 @@ else // Shipment if (($delivery->origin == 'shipment' || $delivery->origin == 'expedition') && $delivery->origin_id > 0) { - $linkback = ''.$langs->trans("BackToList").''; - - // Ref - print ''.$langs->trans("RefSending").''; - print ''; + $linkback = ''.$langs->trans("BackToList").''; + + // Ref + print ''.$langs->trans("RefSending").''; + print ''; // Nav is hidden because on a delivery receipt of a shipment, if we go on next shipment, we may find no tab (a shipment may not have delivery receipt yet) - //print $form->showrefnav($expedition, 'refshipment', $linkback, 1, 'ref', 'ref'); + //print $form->showrefnav($expedition, 'refshipment', $linkback, 1, 'ref', 'ref'); print $form->showrefnav($expedition, 'refshipment', $linkback, 0, 'ref', 'ref'); - print ''; - } + print ''; + } // Ref print ''.$langs->trans("Ref").''; From fb7f08b33ab48e448063c39c4d66ad78c59d61af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 7 May 2014 10:42:58 +0200 Subject: [PATCH 04/10] Corrected changelog message --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 469dbcb82f6..189dd345490 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,7 +14,7 @@ Fix: Pb of records not correctly cleaned when module marge is Fix: [ bug #1341 ] Lastname not added by file or direct input in mass e-mailing. Fix: [ bug #1357 ] Invoice creator state not printed in generated invoice documents. Fix: Suppliers invoice mask fails using {tttt} in numbering. -Fix: [ bug #1350 ] pdf template name for typhon was not correctly et when enabling module. +Fix: [ bug #1350 ] pdf template name for typhon was not correctly set when enabling module. Fix: Navigation on notes for shipments was not working. Fix: [ bug #1353 ] Email notifications, wrong URL. Fix: [ bug #1362 ] Note is not saved. From e6708a50724132234f17f4aa1253e59c09d80338 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Wed, 7 May 2014 15:05:40 +0200 Subject: [PATCH 05/10] Fix error return project deletion --- htdocs/projet/class/project.class.php | 28 +++++++++++++++++++++++++-- htdocs/projet/fiche.php | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index f8f92dbaf60..f3d29ccf7f8 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -481,26 +481,47 @@ class Project extends CommonObject dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); + if (!$resql) + { + $this->errors[] = $this->db->lasterror(); + $error++; + } $sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet_task"; $sql.= " WHERE fk_projet=" . $this->id; dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); + if (!$resql) + { + $this->errors[] = $this->db->lasterror(); + $error++; + } $sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet"; $sql.= " WHERE rowid=" . $this->id; dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); + if (!$resql) + { + $this->errors[] = $this->db->lasterror(); + $error++; + } $sql = "DELETE FROM " . MAIN_DB_PREFIX . "projet_extrafields"; $sql.= " WHERE fk_object=" . $this->id; + dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); + if (!$resql) + { + $this->errors[] = $this->db->lasterror(); + $error++; + } - if ($resql) + if (empty($error)) { // We remove directory $projectref = dol_sanitizeFileName($this->ref); @@ -539,7 +560,10 @@ class Project extends CommonObject } else { - $this->error = $this->db->lasterror(); + foreach ( $this->errors as $errmsg ) { + dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); + $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); + } dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR); $this->db->rollback(); return -1; diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php index cefa422c4ad..0e5b2cc26a7 100644 --- a/htdocs/projet/fiche.php +++ b/htdocs/projet/fiche.php @@ -64,7 +64,7 @@ $result = restrictedArea($user, 'projet', $object->id); $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); $date_start=dol_mktime(0,0,0,GETPOST('projectmonth','int'),GETPOST('projectday','int'),GETPOST('projectyear','int')); -$date_end=dol_mktime(0,0,0,GETPOST('projectendmonth','int'),GETPOST('projectendday','int'),GETPOST('projectendyear','int'));; +$date_end=dol_mktime(0,0,0,GETPOST('projectendmonth','int'),GETPOST('projectendday','int'),GETPOST('projectendyear','int')); /* From 3f22bc70095e47af406b9b408bf5ec936169dc46 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Wed, 7 May 2014 15:08:44 +0200 Subject: [PATCH 06/10] Better error management in delete project method --- htdocs/projet/class/project.class.php | 33 +++++++++++++++------------ 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index f3d29ccf7f8..43e2137715c 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -533,28 +533,31 @@ class Project extends CommonObject $res = @dol_delete_dir_recursive($dir); if (!$res) { - $this->error = 'ErrorFailToDeleteDir'; - $this->db->rollback(); - return 0; + $this->errors[] = 'ErrorFailToDeleteDir'; + $error++; } } } if (!$notrigger) { - // Call triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface = new Interfaces($this->db); - $result = $interface->run_triggers('PROJECT_DELETE', $this, $user, $langs, $conf); - if ($result < 0) - { - $error++; - $this->errors = $interface->errors; - } - // End call triggers + // Call triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface = new Interfaces($this->db); + $result = $interface->run_triggers('PROJECT_DELETE', $this, $user, $langs, $conf); + if ($result < 0) + { + $error++; + foreach ($interface->errors as $errmsg ) { + dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); + $this->errors[] =$errmsg; + } + } + // End call triggers } - - dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG); + } + + if (empty($error)) { $this->db->commit(); return 1; } From 0e2497e7108bc65b89ee143ad9c33f5ba7a5ddf8 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Wed, 7 May 2014 18:19:46 +0200 Subject: [PATCH 07/10] [ bug #1377 ] Warning: get_class() called without object from outside a class --- htdocs/core/lib/functions2.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 256dc205dd0..1a090087bb4 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1286,7 +1286,7 @@ function getListOfModels($db,$type,$maxfilenamelength=0) $sql.= " WHERE type = '".$type."'"; $sql.= " AND entity IN (0,".(! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)?"1,":"").$conf->entity.")"; - dol_syslog(get_class($this).'::getListOfModels sql='.$sql, LOG_DEBUG); + dol_syslog('/core/lib/function2.lib.php::getListOfModels sql='.$sql, LOG_DEBUG); $resql = $db->query($sql); if ($resql) { From 1bc355830763c60f084d338275c9a8f2ac8430ae Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 7 May 2014 19:06:15 +0200 Subject: [PATCH 08/10] Fix: Better html detection --- htdocs/core/lib/functions.lib.php | 24 ++++------- test/phpunit/FunctionsLibTest.php | 68 +++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 19 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index c3889a41456..9016f81ce34 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3414,13 +3414,13 @@ function picto_required() * Clean a string from all HTML tags and entities * * @param string $StringHtml String to clean - * @param string $removelinefeed Replace also all lines feeds by a space + * @param string $removelinefeed Replace also all lines feeds by a space, otherwise only last one are removed * @param string $pagecodeto Encoding of input/output string * @return string String cleaned */ function dol_string_nohtmltag($StringHtml,$removelinefeed=1,$pagecodeto='UTF-8') { - $pattern = "/<[^>]+>/"; + $pattern = "/<[^<>]+>/"; $temp = dol_html_entity_decode($StringHtml,ENT_COMPAT,$pagecodeto); $temp = preg_replace($pattern,"",$temp); @@ -3486,7 +3486,6 @@ function dol_htmlentitiesbr($stringtoencode,$nl2brmode=0,$pagecodefrom='UTF-8') $newstring=strtr($newstring,array('&'=>'__and__','<'=>'__lt__','>'=>'__gt__','"'=>'__dquot__')); $newstring=dol_htmlentities($newstring,ENT_COMPAT,$pagecodefrom); // Make entity encoding $newstring=strtr($newstring,array('__and__'=>'&','__lt__'=>'<','__gt__'=>'>','__dquot__'=>'"')); - //$newstring=strtr($newstring,array('__li__'=>"
  • \n")); // Restore
  • \n } else { @@ -3530,7 +3529,7 @@ function dol_htmlcleanlastbr($stringtodecode) * Replace html_entity_decode functions to manage errors * * @param string $a Operand a - * @param string $b Operand b + * @param string $b Operand b (ENT_QUOTES=convert simple and double quotes) * @param string $c Operand c * @return string String decoded */ @@ -3670,17 +3669,10 @@ function dol_textishtml($msg,$option=0) { if (preg_match('//i',$msg)) return true; - elseif (preg_match('/
    /i',$msg)) return true; - elseif (preg_match('//i',$msg)) return true; - elseif (preg_match('/
  • /i',$msg)) return true; + elseif (preg_match('/<(br|div|font|img|li|span|strong|table)>/i',$msg)) return true; + elseif (preg_match('/<(br|div|font|img|li|span|strong|table)\s+[^<>\/]*>/i',$msg)) return true; + elseif (preg_match('/<(br|div|font|img|li|span|strong|table)\s+[^<>\/]*\/>/i',$msg)) return true; elseif (preg_match('/&[A-Z0-9]{1,6};/i',$msg)) return true; // Html entities names (http://www.w3schools.com/tags/ref_entities.asp) elseif (preg_match('/&#[0-9]{2,3};/i',$msg)) return true; // Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp) return false; @@ -3688,7 +3680,7 @@ function dol_textishtml($msg,$option=0) } /** - * Concat 2 descriptions (second one after first one) + * Concat 2 descriptions (second one after first one with a new line separator if required) * text1 html + text2 html => text1 + '
    ' + text2 * text1 html + text2 txt => text1 + '
    ' + dol_nl2br(text2) * text1 txt + text2 html => dol_nl2br(text1) + '
    ' + text2 diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 3707a875238..b8414dd170e 100755 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -168,20 +168,35 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase $input='xxx yyy zzz'; $after=dol_textishtml($input); $this->assertTrue($after); - $input='xxx
    '; - $after=dol_textishtml($input); - $this->assertTrue($after); $input='text with
    some div
    '; $after=dol_textishtml($input); $this->assertTrue($after); $input='text with HTML   entities'; $after=dol_textishtml($input); $this->assertTrue($after); + $input='xxx
    '; + $after=dol_textishtml($input); + $this->assertTrue($after); + $input='xxx
    '; + $after=dol_textishtml($input); + $this->assertTrue($after); + $input='xxx
    '; + $after=dol_textishtml($input); + $this->assertTrue($after); + $input='xxx
    '; + $after=dol_textishtml($input); + $this->assertTrue($after); // False $input='xxx < br>'; $after=dol_textishtml($input); $this->assertFalse($after); + $input='xxx '; // is html, assertFalse($after); + $input='xxx '; + $after=dol_textishtml($input); + $this->assertFalse($after); } @@ -208,6 +223,53 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase return true; } + /** + * testDolConcat + * + * @return boolean + */ + public function testDolConcat() + { + $text1="A string 1"; $text2="A string 2"; // text 1 and 2 are text, concat need only \n + $after=dol_concatdesc($text1, $text2); + $this->assertEquals("A string 1\nA string 2",$after); + + $text1="A
    string 1"; $text2="A string 2"; // text 1 is html, concat need
    \n + $after=dol_concatdesc($text1, $text2); + $this->assertEquals("A
    string 1
    \nA string 2",$after); + + $text1="A string 1"; $text2="A string 2"; // text 2 is html, concat need
    \n + $after=dol_concatdesc($text1, $text2); + $this->assertEquals("A string 1
    \nA string 2",$after); + + return true; + } + + + /** + * testDolStringNohtmltag + * + * @return boolean + */ + public function testDolStringNohtmltag() + { + $text="A\nstring\n"; + $after=dol_string_nohtmltag($text,0); + $this->assertEquals("A\nstring",$after,"test1"); + + $text="A string\n\nwith html tag and '<' chars
    \n"; + $after=dol_string_nohtmltag($text, 0); + $this->assertEquals("A string\n\nwith html tag and '<' chars",$after,"test2"); + + $text="A string\n\nwith tag with < chars
    \n"; + $after=dol_string_nohtmltag($text, 1); + $this->assertEquals("A string with tag with < chars",$after,"test3"); + + return true; + } + + + /** * testDolHtmlEntitiesBr * From 16b3ec8923a8880cf0a71c0fb58d4c07cd6c005b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 7 May 2014 19:06:47 +0200 Subject: [PATCH 09/10] Fix: concat of string must use dol_concat. --- htdocs/core/lib/doc.lib.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/htdocs/core/lib/doc.lib.php b/htdocs/core/lib/doc.lib.php index 56ecd40fca2..06074079c2e 100644 --- a/htdocs/core/lib/doc.lib.php +++ b/htdocs/core/lib/doc.lib.php @@ -69,8 +69,6 @@ function doc_getlinedesc($line,$outputlangs,$hideref=0,$hidedesc=0,$issupplierli // Description long of product line if ($desc && ($desc != $label)) { - if ( $libelleproduitservice && empty($hidedesc) ) $libelleproduitservice.="\n"; - if ($desc == '(CREDIT_NOTE)' && $line->fk_remise_except) { $discount=new DiscountAbsolute($db); @@ -83,18 +81,17 @@ function doc_getlinedesc($line,$outputlangs,$hideref=0,$hidedesc=0,$issupplierli $discount->fetch($line->fk_remise_except); $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$discount->ref_facture_source); // Add date of deposit - if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec,'day','',$outputlangs).')'; + if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) $libelleproduitservice.=' ('.dol_print_date($discount->datec,'day','',$outputlangs).')'; } else { if ($idprod) { - if (empty($hidedesc)) - $libelleproduitservice.=$desc; + if (empty($hidedesc)) $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc); } else { - $libelleproduitservice.=$desc; + $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc); } } } @@ -148,7 +145,7 @@ function doc_getlinedesc($line,$outputlangs,$hideref=0,$hidedesc=0,$issupplierli $period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($line->date_end, $format, false, $outputlangs)).')'; } //print '>'.$outputlangs->charset_output.','.$period; - $libelleproduitservice.="\n".$period; + $libelleproduitservice=dol_concatdesc($libelleproduitservice, $period); //print $libelleproduitservice; } From ac27884b887e852dd6eae5bb41dd106f1ffa6d61 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 7 May 2014 19:13:02 +0200 Subject: [PATCH 10/10] Fix: [ bug #1366 ] Special characters are HTML encoded with WYSIWYG module. --- htdocs/includes/odtphp/Segment.php | 8 +++- htdocs/includes/odtphp/odf.php | 70 +++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/htdocs/includes/odtphp/Segment.php b/htdocs/includes/odtphp/Segment.php index 7a6e15ee48b..9bcfa0f65d1 100644 --- a/htdocs/includes/odtphp/Segment.php +++ b/htdocs/includes/odtphp/Segment.php @@ -136,9 +136,15 @@ class Segment implements IteratorAggregate, Countable if (strpos($this->xml, $this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT')) === false) { throw new SegmentException("var $key not found in {$this->getName()}"); } + + $value=$this->odf->htmlToUTFAndPreOdf($value); + $value = $encode ? htmlspecialchars($value) : $value; $value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value; - $this->vars[$this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT')] = str_replace("\n", "", $value); + + $value=$this->odf->preOdfToOdf($value); + + $this->vars[$this->odf->getConfig('DELIMITER_LEFT') . $key . $this->odf->getConfig('DELIMITER_RIGHT')] = $value; return $this; } /** diff --git a/htdocs/includes/odtphp/odf.php b/htdocs/includes/odtphp/odf.php index d2cb8e0b6e1..623fa083ad1 100644 --- a/htdocs/includes/odtphp/odf.php +++ b/htdocs/includes/odtphp/odf.php @@ -122,12 +122,68 @@ class Odf throw new OdfException("var $key not found in the document"); //} } + + $value=$this->htmlToUTFAndPreOdf($value); + $value = $encode ? htmlspecialchars($value) : $value; $value = ($charset == 'ISO-8859') ? utf8_encode($value) : $value; - $this->vars[$tag] = str_replace("\n", "", $value); + + $value=$this->preOdfToOdf($value); + + $this->vars[$tag] = $value; return $this; } + + /** + * Function to convert a HTML string into an ODT string + * + * @param string $value String to convert + */ + public function htmlToUTFAndPreOdf($value) + { + // We decode into utf8, entities + $value=dol_html_entity_decode($value, ENT_QUOTES); + + // We convert html tags + $ishtml=dol_textishtml($value); + if ($ishtml) + { + // If string is "MYPODUCT - Desc bold with é accent
    \n
    \nUn texto en español ?" + // Result after clean must be "MYPODUCT - Desc bold with é accent\n\nUn texto en español ?" + + // We want to ignore \n and we want all
    to be \n + $value=preg_replace('/(\r\n|\r|\n)/i','',$value); + $value=preg_replace('/
    /i',"\n",$value); + $value=preg_replace('/\/]*>/i',"\n",$value); + $value=preg_replace('/\/]*\/>/i',"\n",$value); + + //$value=preg_replace('//','__lt__text:p text:style-name=__quot__bold__quot____gt__',$value); + //$value=preg_replace('/<\/strong>/','__lt__/text:p__gt__',$value); + + $value=dol_string_nohtmltag($value, 0); + } + + return $value; + } + + + /** + * Function to convert a HTML string into an ODT string + * + * @param string $value String to convert + */ + public function preOdfToOdf($value) + { + $value = str_replace("\n", "", $value); + + //$value = str_replace("__lt__", "<", $value); + //$value = str_replace("__gt__", ">", $value); + //$value = str_replace("__quot__", '"', $value); + + return $value; + } + /** * Evaluating php codes inside the ODT and output the buffer (print, echo) inplace of the code * @@ -422,25 +478,25 @@ IMG; public function exportAsAttachedPDF($name="") { global $conf; - + if( $name == "" ) $name = md5(uniqid()); dol_syslog(get_class($this).'::exportAsAttachedPDF $name='.$name, LOG_DEBUG); $this->saveToDisk($name); $execmethod=(empty($conf->global->MAIN_EXEC_USE_POPEN)?1:2); // 1 or 2 - + $name=str_replace('.odt', '', $name); if (!empty($conf->global->MAIN_DOL_SCRIPTS_ROOT)) { $command = $conf->global->MAIN_DOL_SCRIPTS_ROOT.'/scripts/odt2pdf/odt2pdf.sh '.$name; }else { $command = '../../scripts/odt2pdf/odt2pdf.sh '.$name; } - - + + //$dirname=dirname($name); //$command = DOL_DOCUMENT_ROOT.'/includes/odtphp/odt2pdf.sh '.$name.' '.$dirname; - + dol_syslog(get_class($this).'::exportAsAttachedPDF $execmethod='.$execmethod.' Run command='.$command,LOG_DEBUG); if ($execmethod == 1) { @@ -482,7 +538,7 @@ IMG; } else { 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); - + if ($retval==126) { throw new OdfException('Permission execute convert script : ' . $command); }