[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 17/44: Document : replace properly value in t
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 17/44: Document : replace properly value in the OOo file |
Date: |
Wed, 26 Dec 2018 04:29:53 -0500 (EST) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 3a534aa1cb69d1242f89aa58e215b821a4059ae4
Author: Dany De Bontridder <address@hidden>
Date: Fri Nov 23 23:11:04 2018 +0100
Document : replace properly value in the OOo file
---
include/class/document.class.php | 87 ++++++++++++++++++++++++----------------
1 file changed, 52 insertions(+), 35 deletions(-)
diff --git a/include/class/document.class.php b/include/class/document.class.php
index 03258cf..3f0327f 100644
--- a/include/class/document.class.php
+++ b/include/class/document.class.php
@@ -237,7 +237,6 @@ class Document
$lt="<";
$gt=">";
}
-
//read the file
while(! feof($h))
{
@@ -270,33 +269,8 @@ class Document
* Change type of cell to numeric
* allow numeric cel in ODT for the formatting and
formula
*/
- if ( is_numeric($value) && $p_type=='OOo')
- {
- // For libreOffice <=4
-
$searched='/office:value-type="string"><text:p>'.$pattern.'/i';
- $replaced='office:value-type="float"
office:value="'.$value.'"><text:p>'.$pattern;
- $buffer=preg_replace($searched, $replaced,
$buffer,1);
- // For libreOffice >=4
- $searched='/office:value-type="string"
calcext:value-type="string"><text:p>'.$pattern.'/i';
- $replaced='office:value-type="float"
office:value="'.$value.'" calcext:value-type="float"><text:p>'.$pattern;
- $buffer=preg_replace($searched, $replaced,
$buffer,1);
- }
- // replace into the $buffer
- // take the position in the buffer
- $pos=strpos($buffer,$to_remove);
- // get the length of the string to remove
- $len=strlen($to_remove);
- if ( $p_type=='OOo' )
- {
- $value=str_replace('&','&',$value);
- $value=str_replace('<','<',$value);
- $value=str_replace('>','>',$value);
- $value=str_replace('"','"',$value);
- $value=str_replace("'",''',$value);
- }
- $buffer=substr_replace($buffer,$value,$pos,$len);
-
- // if the pattern if found we replace it
+
+ $buffer=\Document::replace_value($buffer,$pattern,
$value, 1,$p_type);
}
}
}
@@ -1111,9 +1085,9 @@ class Document
}
$sell=${'e_march'.$i.'_price'};
$qt=${'e_quant'.$i};
- $tot=bcmul($sell,$qt);
- $tot=bcadd($tot,$tva_amount);
- $sum=bcadd($sum,$tot);
+ $tot=bcmul($sell,$qt);
+ $tot=bcadd($tot,$tva_amount);
+ $sum=bcadd($sum,$tot);
}
$r=round($sum,2);
@@ -1125,10 +1099,10 @@ class Document
{
$tva='e_march'.$i.'_tva_amount';
if (! isset(${$tva})) $tva_amount=0.0;
- else $tva_amount=$
- {
- $tva
- };
+ else {
+ $tva_amount=${$tva};
+ $tva_amount=($tva_amount=="")?0:$tva_amount;
+ }
$sum+=$tva_amount;
$sum=round($sum,2);
}
@@ -1303,5 +1277,48 @@ class Document
$this->db->exec_sql('update document set d_description = $1 where
d_id=$2',
array($p_desc,$this->d_id));
}
+ /**
+ * Replace a pattern with a value in the buffer , handle the change for
OOo type file and amount
+ *
+ * @param string $p_buffer
+ * @param string $_pattern
+ * @param mixed $p_value
+ */
+ static function replace_value($p_buffer, $p_pattern,
$p_value,$p_limit=-1,$p_type='OOo')
+ {
+ $check=$p_pattern;
+ $check=str_replace(['<','>','<','>','='], "", $check);
+ if ( preg_replace('/[^[:alnum:]^_]/', '', $check) != $check)
+ {
+ throw new Exception(sprintf(_("chaine à remplacer [%s] contient un
caractère interdit"), $p_pattern));
+ }
+ $count=0;
+ if (is_numeric($p_value) && $p_type == 'OOo')
+ {
+ /* -- works only with OOo Calc -- */
+ $searched='/office:value-type="string"><text:p>'.$p_pattern.'/i';
+ $replaced='office:value-type="float"
office:value="'.$p_value.'"><text:p>'.$p_value;
+ $p_buffer=preg_replace($searched, $replaced,
$p_buffer,$p_limit,$count);
+ if ( $count == 0) {
+ /* -- work with libreOffice > 5 -- */
+ $searched='/office:value-type="string"
calcext:value-type="string"><text:p>'.$p_pattern.'/i';
+ $replaced='office:value-type="float"
office:value="'.$p_value.'" calcext:value-type="float"><text:p>'.$p_value;
+ $p_buffer=preg_replace($searched, $replaced,
$p_buffer,$p_limit,$count);
+ }
+ }
+ if ($count == 0)
+ {
+ if ( $p_type=='OOo' )
+ {
+ $p_value=str_replace('&','&',$p_value);
+ $p_value=str_replace('<','<',$p_value);
+ $p_value=str_replace('>','>',$p_value);
+ $p_value=str_replace('"','"',$p_value);
+ $p_value=str_replace("'",''',$p_value);
+ }
+ $p_buffer=preg_replace('/'.$p_pattern.'/i', $p_value,
$p_buffer,$p_limit);
+ }
+ return $p_buffer;
+ }
}
- [Noalyss-commit] [noalyss] 07/44: Bug : ajax fails if wait_box does not exist, (continued)
- [Noalyss-commit] [noalyss] 07/44: Bug : ajax fails if wait_box does not exist, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 13/44: adapt to 7.2 : array, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 06/44: adapt to 7.2 ,init, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 10/44: javascript : small bug in alert_box , callback function is not defined, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 14/44: css cosmetic background for selected style-classic7, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 26/44: Version DB 131, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 24/44: Analytic accountancy : fix bug, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 20/44: Document::replace_value handle space before numeric, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 16/44: http_input : fix bug with array, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 35/44: predefined operation , find a label for an accounting thx its value, the pk is now an numeric id, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 17/44: Document : replace properly value in the OOo file,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 40/44: PHP 7.2 : sizeof attribut, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 22/44: Exception rethrow, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 37/44: cfgcurrency : file for the new version : if the file to include does not exist then display a warning and exit, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 05/44: Bug : cannot set group, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 21/44: cosmetic, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 30/44: acc_ledger_fin . translation, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 29/44: Background color, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 27/44: Quant_Fin : set the j_id when an operation is recorded, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 25/44: Currency : SQL quant_fin is adapted, Dany De Bontridder, 2018/12/26
- [Noalyss-commit] [noalyss] 31/44: Indentation, Dany De Bontridder, 2018/12/26