[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 59/119: prevent divide by zero in formula
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 59/119: prevent divide by zero in formula |
Date: |
Mon, 26 Oct 2020 18:27:21 -0400 (EDT) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 73c1887effb36e7a1d67db04cc893ae5c3eda9ca
Author: Dany De Bontridder <danydb@noalyss.eu>
AuthorDate: Tue Aug 18 19:11:46 2020 +0200
prevent divide by zero in formula
---
include/lib/ac_common.php | 23 ++++++++++++++++++++---
include/lib/impress.class.php | 4 ++++
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php
index 44ee884..ff0f1e8 100644
--- a/include/lib/ac_common.php
+++ b/include/lib/ac_common.php
@@ -209,13 +209,13 @@ function cmpDate($p_date, $p_date_oth)
/***!
* @brief check if the argument is a number
*
- * \param $p_int number to test
+ * @param $p_int number to test
*
- * \return
+ * @return
* - 1 it's a number
* - 0 it is not
*/
-function isNumber(&$p_int)
+function isNumber($p_int)
{
if (strlen(trim($p_int)) == 0)
return 0;
@@ -1375,3 +1375,20 @@ function convert_to_rtf($p_string)
}
return $result;
}
+/**
+ * When it is needed to eval a formula , this function prevent the divide by
zero.
+ * the formula is a math operation to evaluate like : 1.0+2.0/1 (...) , it is
used in "report",
+ * it removes the operation "divide by 0 "
+ *
+ * @param string $p_formula string containing a operation to evaluate
+ *
+ * @see Impress::parse_formula
+ */
+function remove_divide_zero($p_formula)
+{
+ $test=str_replace(" ","",$p_formula).";";
+
$p_formula=preg_replace("![0-9]+\.*[0-9]*/0\.{0,1}0*(\+|-|\*|/|;){1}!","0$1",$test);
+ $p_formula=trim($p_formula,';');
+ return $p_formula;
+}
+
diff --git a/include/lib/impress.class.php b/include/lib/impress.class.php
index 0a8beb3..8ea617f 100644
--- a/include/lib/impress.class.php
+++ b/include/lib/impress.class.php
@@ -153,6 +153,10 @@ class Impress
// $p_eval is true then we eval and returns result
if ( $p_eval == true)
{
+ /*-------------------------------------
+ * Protect againt division by zero
+ */
+ $p_formula=remove_divide_zero($p_formula);
$p_formula="\$result=".$p_formula.";";
eval("$p_formula");
- [Noalyss-commit] [noalyss] 73/119: Contact option : export CSV, (continued)
- [Noalyss-commit] [noalyss] 73/119: Contact option : export CSV, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 67/119: Link between contact option and document, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 75/119: Fix : by default new contact options were not added to document_type, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 63/119: Bug #1839 : : accentuated character broken, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 76/119: Add : upgrade scrip added, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 24/119: Merge branch 'master' of gitlab.noalyss.eu:noalyss/noalyss, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 25/119: erge branch 'dev-7400-7500', Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 33/119: doc, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 41/119: Rewriting of Predefined Operation. You can add new Predefined Operation, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 51/119: Add group of tag to an action, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 59/119: prevent divide by zero in formula,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 65/119: Rewriting of card attributes, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 69/119: Improve Input_Switch , do not echo but returns string, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 66/119: Multiple contact Search on selected attribute, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 77/119: fix upgrade145.sql , default value must be 1 for actif, sql wrong, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 78/119: Fix FollowUp : price Purchase or Sale, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 79/119: protect, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 86/119: Follow up cosmetic add title to anchor, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 87/119: Document Type : CFGACTION cannot add new document, fix order in dialog box, Fix= cannot delete action cause cascade on action_person, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 89/119: upgrade db 146, Dany De Bontridder, 2020/10/26
- [Noalyss-commit] [noalyss] 91/119: Follow-up correct link, Dany De Bontridder, 2020/10/26