[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 03/08: php8.1 : compatibility
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 03/08: php8.1 : compatibility |
Date: |
Tue, 30 Aug 2022 03:19:04 -0400 (EDT) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit d606c1d6faa7545f5b962bb1a625c2653f94a81f
Author: Dany De Bontridder <dany@alchimerys.be>
AuthorDate: Sat Aug 27 16:54:30 2022 +0200
php8.1 : compatibility
---
include/class/acc_account.class.php | 2 +-
include/class/acc_account_ledger.class.php | 2 +-
include/class/acc_balance.class.php | 4 +-
include/class/acc_ledger.class.php | 4 +-
include/class/card_property.class.php | 2 +-
include/class/contact.class.php | 2 +-
include/class/document.class.php | 10 ++--
include/class/fiche.class.php | 10 ++--
include/class/print_ledger_detail_item.class.php | 6 +--
include/compta_fin_saldo.inc.php | 4 +-
include/lib/ac_common.php | 30 ++++++++++-
include/lib/data_sql.class.php | 2 +-
include/lib/database_core.class.php | 2 +-
include/lib/itext.class.php | 2 +-
include/lib/pdf_core.class.php | 2 +-
include/menu.inc.php | 7 ++-
include/template/ledger_detail_fin.php | 3 +-
unit-test/include/lib/ac_commonTest.php | 69 ++++++++++++++++++++++++
18 files changed, 131 insertions(+), 32 deletions(-)
diff --git a/include/class/acc_account.class.php
b/include/class/acc_account.class.php
index 1f28ce976..e5c7e10f1 100644
--- a/include/class/acc_account.class.php
+++ b/include/class/acc_account.class.php
@@ -130,7 +130,7 @@ class Acc_Account
if ( $count > 0)
throw new Exception (_("Poste en double"),EXC_DUPLICATE);
- if (trim($this->data_sql->pcm_lib)=="")
+ if (noalyss_trim($this->data_sql->pcm_lib)=="")
throw new Exception (_("Libellé vide"),EXC_PARAM_VALUE);
// can not depend of itself
diff --git a/include/class/acc_account_ledger.class.php
b/include/class/acc_account_ledger.class.php
index eee68a370..858b94487 100644
--- a/include/class/acc_account_ledger.class.php
+++ b/include/class/acc_account_ledger.class.php
@@ -634,7 +634,7 @@ class Acc_Account_Ledger
function belong_ledger($p_jrn)
{
$filter=$this->db->get_value("select jrn_def_class_cred from jrn_def
where jrn_def_id=$1", array($p_jrn));
- if ( trim ($filter) == '')
+ if ( noalyss_trim ($filter) == '')
return 0;
$valid_cred=explode(" ",$filter);
diff --git a/include/class/acc_balance.class.php
b/include/class/acc_balance.class.php
index b9c5df774..074710ba9 100644
--- a/include/class/acc_balance.class.php
+++ b/include/class/acc_balance.class.php
@@ -88,12 +88,12 @@ class Acc_Balance
$and=" and ";
}
- if ( strlen(trim($this->from_poste)) != 0 && $this->from_poste!=-1 )
+ if ( strlen(noalyss_trim($this->from_poste)) != 0 &&
$this->from_poste!=-1 )
{
$from_poste=" $and j_poste::text >= '".$this->from_poste."'";
$and=" and ";
}
- if ( strlen(trim($this->to_poste)) != 0 && $this->to_poste!=-1 )
+ if ( strlen(noalyss_trim($this->to_poste)) != 0 &&
$this->to_poste!=-1 )
{
$to_poste=" $and j_poste::text <= '".$this->to_poste."'";
$and=" and ";
diff --git a/include/class/acc_ledger.class.php
b/include/class/acc_ledger.class.php
index b64a642ff..a5ba23aaa 100644
--- a/include/class/acc_ledger.class.php
+++ b/include/class/acc_ledger.class.php
@@ -1709,7 +1709,7 @@ class Acc_Ledger extends jrn_def_sql
$card.=$comma.$item['deb'];
$comma=',';
}
- if (strlen(trim($item['cred']))!='')
+ if (strlen(noalyss_trim($item['cred']))!=0)
{
$card.=$comma.$item['cred'];
$comma=',';
@@ -2230,7 +2230,7 @@ class Acc_Ledger extends jrn_def_sql
$min_date);
}
$saldo=$bank_card->get_bk_balance($cond);
- $ret['amount']=bcsub($saldo['debit'], $saldo['credit']);
+ $ret['amount']=noalyss_bcsub($saldo['debit'], $saldo['credit']);
}
return $ret;
}
diff --git a/include/class/card_property.class.php
b/include/class/card_property.class.php
index d9fcf211f..881ad3da2 100644
--- a/include/class/card_property.class.php
+++ b/include/class/card_property.class.php
@@ -595,7 +595,7 @@ class Card_Property
}
// Normal traitement
$sql="update fiche_detail set ad_value=$1 where jft_id=$2";
- $p_fiche->cn->exec_sql($sql,
array(strip_tags($value->av_text), $jft_id));
+ $p_fiche->cn->exec_sql($sql,
array(noalyss_strip_tags($value->av_text), $jft_id));
}
if ($commit)
{
diff --git a/include/class/contact.class.php b/include/class/contact.class.php
index 94da9dfa4..f45392c4e 100644
--- a/include/class/contact.class.php
+++ b/include/class/contact.class.php
@@ -68,7 +68,7 @@ class contact extends Fiche
$bar=navigation_bar($offset,$all_contact,$_SESSION[SESSION_KEY.'g_pagesize'],$page);
// set a filter ?
$search="";
- if ( trim($p_search) != "" )
+ if ( noalyss_trim($p_search) != "" )
{
$search=" and f_id in
(select f_id from fiche_Detail
diff --git a/include/class/document.class.php b/include/class/document.class.php
index 4b8764604..65b903ca9 100644
--- a/include/class/document.class.php
+++ b/include/class/document.class.php
@@ -1806,11 +1806,11 @@ class Document
{
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_value=noalyss_str_replace('&', '&', $p_value);
+ $p_value=noalyss_str_replace('<', '<', $p_value);
+ $p_value=noalyss_str_replace('>', '>', $p_value);
+ $p_value=noalyss_str_replace('"', '"', $p_value);
+ $p_value=noalyss_str_replace("'", ''', $p_value);
}
$p_buffer=preg_replace('/'.$p_pattern.'/i', $p_value, $p_buffer,
$p_limit);
}
diff --git a/include/class/fiche.class.php b/include/class/fiche.class.php
index e17467a65..99bed6455 100644
--- a/include/class/fiche.class.php
+++ b/include/class/fiche.class.php
@@ -1242,7 +1242,7 @@ class Fiche
$res=$this->cn->exec_sql($sql,[$this->id,$p_attr]);
if ( Database::num_row($res) == 0 ) return true;
$text=Database::fetch_result($res,0,0);
- return (strlen(trim($text)) > 0)?false:true;
+ return (strlen(noalyss_trim($text)) > 0)?false:true;
}
@@ -1291,7 +1291,7 @@ class Fiche
list($max,$min)=$tPeriode->get_limit($exercice);
- if ( trim($p_search) != "" )
+ if ( noalyss_trim($p_search) != "" )
{
$search.=" and f_id in
(select distinct f_id from fiche_detail
@@ -1622,7 +1622,7 @@ class Fiche
$filter_jrn=$this->cn->make_list("select
jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",
array($jrn));
- if (trim($filter_jrn)!='')
+ if (noalyss_trim($filter_jrn)!='')
$fp1=" fd_id in (".$filter_jrn.")";
else
$fp1="fd_id < 0";
@@ -1630,7 +1630,7 @@ class Fiche
$filter_jrn=$this->cn->make_list("select
jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",
array($jrn));
- if (trim($filter_jrn)!='')
+ if (noalyss_trim($filter_jrn)!='')
$fp2=" fd_id in (".$filter_jrn.")";
else
$fp2="fd_id < 0";
@@ -1643,7 +1643,7 @@ class Fiche
$filter_fd_id=' true';
break;
default:
- if (trim($typecard)!='')
+ if (noalyss_trim($typecard)!='')
$filter_fd_id=' fd_id in ('.$typecard.')';
else
$filter_fd_id=' fd_id < 0';
diff --git a/include/class/print_ledger_detail_item.class.php
b/include/class/print_ledger_detail_item.class.php
index c34629437..531927aa2 100644
--- a/include/class/print_ledger_detail_item.class.php
+++ b/include/class/print_ledger_detail_item.class.php
@@ -127,9 +127,9 @@ class Print_Ledger_Detail_Item extends Print_Ledger
$this->write_cell(20, $high, nbm($row['tot_tva_np']), 1, 0,
'R', true);
$this->write_cell(20, $high, nbm($row['other_tax_amount']), 1,
0, 'R', true);
$this->write_cell(20, $high, nbm($row['tot_vat']), 1, 0, 'R',
true);
- $sum=bcadd($row['htva'],$row['tot_vat']);
- $sum=bcadd($row['other_tax_amount'],$sum);
- $sum=bcsub($sum,$row['tot_tva_np']);
+ $sum=noalyss_bcadd($row['htva'],$row['tot_vat']);
+ $sum=noalyss_bcadd($row['other_tax_amount'],$sum);
+ $sum=noalyss_bcsub($sum,$row['tot_tva_np']);
$this->write_cell(20, $high, nbm($sum), 1, 0, 'R', true);
$internal=$row['jr_internal'];
$this->line_new(6);
diff --git a/include/compta_fin_saldo.inc.php b/include/compta_fin_saldo.inc.php
index 72355df75..7e90935a8 100644
--- a/include/compta_fin_saldo.inc.php
+++ b/include/compta_fin_saldo.inc.php
@@ -121,9 +121,9 @@ for ($i=0; $i<$nb_array; $i++)
$array[$i]->strAttribut(ATTR_DEF_QUICKCODE)).
"</TD>";
- $saldo_rec=bcsub($saldo_reconcilied['debit'],
+ $saldo_rec=noalyss_bcsub($saldo_reconcilied['debit'],
$saldo_reconcilied['credit']);
- $diff=bcsub($saldo_not_reconcilied['debit'],
+ $diff=noalyss_bcsub($saldo_not_reconcilied['debit'],
$saldo_not_reconcilied['credit']);
echo "<TD >".
$array[$i]->strAttribut(ATTR_DEF_NAME).
diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php
index 038d60edb..cbb5a9a51 100644
--- a/include/lib/ac_common.php
+++ b/include/lib/ac_common.php
@@ -137,7 +137,7 @@ function findSide($p_number)
function nbm($p_number,$p_dec = 2)
{
- if (trim($p_number) == '')
+ if (noalyss_trim($p_number) == '')
return '';
if ($p_number == 0)
return "0,00";
@@ -217,7 +217,7 @@ function cmpDate($p_date, $p_date_oth)
*/
function isNumber($p_int)
{
- if (strlen(trim($p_int)) == 0)
+ if (strlen(noalyss_trim($p_int)) == 0)
return 0;
if (is_numeric($p_int) === true)
return 1;
@@ -838,6 +838,7 @@ function shrink_date($p_date)
*/
function smaller_date($p_date)
{
+ if (empty ($p_date)) return "";
$str_date = substr($p_date, 0, 6) . substr($p_date, 8, 2);
return $str_date;
}
@@ -1585,3 +1586,28 @@ function add_http_link($text)
return $ret;
}
+function noalyss_trim($p_string) {
+ if ($p_string===null) return "";
+ else return trim($p_string);
+}
+function noalyss_str_replace($search,$replace,$string) {
+ if ($string===null) return "";
+ else return str_replace($search,$replace,$string);
+}
+function noalyss_bcsub($p_first,$p_second)
+{
+ $p_first=(empty($p_first))?0:$p_first;
+ $p_second=(empty($p_second))?0:$p_second;
+ return bcsub($p_first,$p_second);
+}
+function noalyss_bcadd($p_first,$p_second)
+{
+ $p_first=(empty($p_first))?0:$p_first;
+ $p_second=(empty($p_second))?0:$p_second;
+ return bcadd($p_first,$p_second);
+}
+function noalyss_strip_tags($p_string)
+{
+ if ($p_string===null) return "";
+ return strip_tags($p_string);
+}
\ No newline at end of file
diff --git a/include/lib/data_sql.class.php b/include/lib/data_sql.class.php
index 5bfbaf40a..61b685cc6 100644
--- a/include/lib/data_sql.class.php
+++ b/include/lib/data_sql.class.php
@@ -198,7 +198,7 @@ abstract class Data_SQL
{
foreach ($this->name as $key)
{
- if (trim($this->$key)=='')
+ if (noalyss_trim($this->$key)=='')
$this->$key=null;
}
return 0;
diff --git a/include/lib/database_core.class.php
b/include/lib/database_core.class.php
index c21a9da90..19dbbc0cf 100644
--- a/include/lib/database_core.class.php
+++ b/include/lib/database_core.class.php
@@ -1000,7 +1000,7 @@ class DatabaseCore
foreach ($forbid_sql as $forbid_key) {
if (stripos($p_sql,$forbid_key) !== false)
{
- throw new Exception(_("Possible SQL inject",EXC_INVALID));
+ throw new Exception(_("Possible SQL inject"),EXC_INVALID);
}
}
diff --git a/include/lib/itext.class.php b/include/lib/itext.class.php
index 831d6729e..5b66168e9 100644
--- a/include/lib/itext.class.php
+++ b/include/lib/itext.class.php
@@ -51,7 +51,7 @@ class IText extends HtmlInput
$this->id=($this->id=="")?$this->name:$this->id;
// Double quote makes troubles
- $this->value=str_replace('"','',$this->value);
+ $this->value=noalyss_str_replace('"','',$this->value);
$t= 'title="'.$this->title.'" ';
$autofocus=($this->autofocus)?" autofocus ":"";
diff --git a/include/lib/pdf_core.class.php b/include/lib/pdf_core.class.php
index 750899953..8c1f4b850 100644
--- a/include/lib/pdf_core.class.php
+++ b/include/lib/pdf_core.class.php
@@ -196,7 +196,7 @@ class PDF_Core extends TFPDF
for ($i=0;$i < $size ; $i++)
{
$a=$cell[$i];
- $a->text= str_replace("\\", "", $a->text);
+ $a->text= noalyss_str_replace("\\", "", $a->text);
switch ($a->type)
{
case "M":
diff --git a/include/menu.inc.php b/include/menu.inc.php
index 1fa3ac8a8..e2303a633 100644
--- a/include/menu.inc.php
+++ b/include/menu.inc.php
@@ -174,10 +174,13 @@ for ($i = 0; $i < Database::num_row($ret); $i++)
break;
}
$class = ( $i % 2 == 0) ? $class = ' class="odd"' : $class = '
class="even"';
+ // compatibility 8.1 , null is not an empty string
+ $me_description=($row->me_description===null)?"":_($row->me_description);
+ $me_menu=($row->me_menu===null)?"":_($row->me_menu);
echo "<tr $class>";
echo td($js);
- echo td(_($row->me_menu));
- echo td(h(_($row->me_description)));
+ echo td($me_menu);
+ echo td(h($me_description));
echo td(h($row->me_type));
echo td(h($row->me_file));
echo td(h($row->me_url));
diff --git a/include/template/ledger_detail_fin.php
b/include/template/ledger_detail_fin.php
index 2b6696747..a262ec0b6 100644
--- a/include/template/ledger_detail_fin.php
+++ b/include/template/ledger_detail_fin.php
@@ -4,7 +4,8 @@
$str_anc="";
?><?php require_once NOALYSS_TEMPLATE.'/ledger_detail_top.php'; ?>
<div class="content" style="padding:0;">
-<?php
+<?php
+ $cn=Dossier::connect();
$owner=new Noalyss_Parameter_Folder($cn);
?>
diff --git a/unit-test/include/lib/ac_commonTest.php
b/unit-test/include/lib/ac_commonTest.php
index e86faa254..2508a5279 100644
--- a/unit-test/include/lib/ac_commonTest.php
+++ b/unit-test/include/lib/ac_commonTest.php
@@ -302,4 +302,73 @@ class Ac_CommonTest extends TestCase
$this->assertEquals("l''éléphant",Database::escape_string("l'éléphant"));
$this->assertEquals("l\''éléphant",Database::escape_string("l\'éléphant"));
}
+ function dataNoalyss_trim()
+ {
+ return array(["0","0"],
+ [" 0 1 1 1 ","0 1 1 1"],
+ [null,""],
+ );
+ }
+
+ /**
+ * @brief Comptability PHP 8.1 , null is not consider as an empty string
+ * @param $param
+ * @param $result
+ * @return void
+ * @dataProvider dataNoalyss_trim
+ */
+ function testNoalyss_trim($param,$result)
+ {
+ $this->assertEquals($result,noalyss_trim($param));
+ }
+ function dataNoalyss_replace() {
+ return array(["0","/","0A0A","/A/A"],
+ ["A","*","0A0A","0*0*"],
+ ["0","/",null,""],
+ ["0","/","",""]
+ );
+ }
+
+ /**
+ * @brief Comptability PHP 8.1 , null is not consider as an empty string
+ * @dataProvider dataNoalyss_replace
+ */
+ function testNoalyss_replace($search,$replace,$string,$expected)
+ {
+
$this->assertEquals($expected,noalyss_str_replace($search,$replace,$string));
+ }
+ function dataNoalyss_bcsub() {
+ return array(
+ [1,2,-1],
+ [0,2,-2],
+ ["",2,-2],
+ [null,2,-2]
+ );
+ }
+
+ /**
+ * @brief Comptability PHP 8.1 , null is not consider as an empty string
+ * @dataProvider dataNoalyss_bcsub
+ */
+ function testNoalyss_bcsub($numbera,$numberb,$expected)
+ {
+ $this->assertEquals($expected,noalyss_bcsub($numbera,$numberb));
+ }
+ function dataNoalyss_strip_tags() {
+ return array(
+ [null,""],
+ ["",""],
+ ["0","0"],
+ ["<script>0</script>","0"],
+ );
+ }
+
+ /**
+ * @brief Comptability PHP 8.1 , null is not consider as an empty string
+ * @dataProvider dataNoalyss_strip_tags
+ */
+ function testNoalyss_strip_tags($string,$expected)
+ {
+ $this->assertEquals($expected,noalyss_strip_tags($string));
+ }
}
- [Noalyss-commit] [noalyss] branch master updated (30359ca4b -> 70f91d472), Dany De Bontridder, 2022/08/30
- [Noalyss-commit] [noalyss] 02/08: Cosmetic : small screen keep folder color, Dany De Bontridder, 2022/08/30
- [Noalyss-commit] [noalyss] 04/08: Ageing Balance : remove limit date, Dany De Bontridder, 2022/08/30
- [Noalyss-commit] [noalyss] 05/08: Translation, Dany De Bontridder, 2022/08/30
- [Noalyss-commit] [noalyss] 01/08: Cosmetic : highlight row, Dany De Bontridder, 2022/08/30
- [Noalyss-commit] [noalyss] 03/08: php8.1 : compatibility,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 06/08: PhpUnit test for Fiche, Dany De Bontridder, 2022/08/30
- [Noalyss-commit] [noalyss] 07/08: PhpUnit test insert and update of alphanumeric accounting, Dany De Bontridder, 2022/08/30
- [Noalyss-commit] [noalyss] 08/08: Improve translation and test, Dany De Bontridder, 2022/08/30