From 991a499dd6c29c8f4d728c6676912589f8fc00c3 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Wed, 30 Aug 2023 10:02:18 +0200 Subject: [PATCH 01/16] PHP8.1 deprecated --- html/direct.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/html/direct.php b/html/direct.php index 1f10466a4..7c1a4b2c6 100644 --- a/html/direct.php +++ b/html/direct.php @@ -29,10 +29,11 @@ MaintenanceMode("block.html"); $cn=Dossier::connect(); global $g_user; +$http=new \HttpInput(); $g_user=new Noalyss_user($cn); $g_user->Check(); -$g_user->check_dossier($_GET['gDossier']); -$res=$cn->exec_sql("select distinct code,description from get_profile_menu($1) where code ~* $2 or description ~* $3 order by code limit 5 ",array($g_user->get_profile(),$_POST['acs'],$_POST['acs'])); +$g_user->check_dossier($http->get('gDossier')); +$res=$cn->exec_sql("select distinct code,description from get_profile_menu($1) where code ~* $2 or description ~* $2 order by code limit 5 ",array($g_user->get_profile(),$http->post("acs"))); $nb=Database::num_row($res); echo ""; if ( $nb == 0 ) { From 3f784b2465c228a9fbcba9ca71c5aed8ece46e60 Mon Sep 17 00:00:00 2001 From: Dany wm DB Date: Mon, 21 Aug 2023 20:42:58 +0200 Subject: [PATCH 02/16] compatibility PHP8.1 --- include/template/module.php | 4 ++-- include/template/profile_menu_display_module.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/template/module.php b/include/template/module.php index 8fa2be0e6..50c7b0fda 100644 --- a/include/template/module.php +++ b/include/template/module.php @@ -124,7 +124,7 @@ endif;?> } ?>
  • - > + >
  • } ?>
  • - > + " >
  • - +

    From 546fe2f3f5170195559b8639834c4b86af7d1aff Mon Sep 17 00:00:00 2001 From: Dany wm DB Date: Fri, 1 Sep 2023 18:25:13 +0200 Subject: [PATCH 03/16] Bug cannot update description in FOLLOW->event --- include/ajax/ajax_follow_up.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/ajax/ajax_follow_up.php b/include/ajax/ajax_follow_up.php index 7bce55c0f..5a8b885b9 100644 --- a/include/ajax/ajax_follow_up.php +++ b/include/ajax/ajax_follow_up.php @@ -31,7 +31,7 @@ global $g_user; /* * Ajax for modifying the description , does not support ITextarea + enrich text * - * + */ if ($op=='update_comment_followUp') { $input=$http->request('input'); @@ -75,7 +75,7 @@ if ($op=='update_comment_followUp') } return; } -*/ + // Modify followup if ($op == 'followup_comment_oneedit') { From 1c727f960b912c34a0c5ebdac0c95e83d0344eb4 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Fri, 15 Sep 2023 19:12:03 +0200 Subject: [PATCH 04/16] Default currency For Sale , correct default currency remove hard coded EUR --- include/class/acc_ledger_sale.class.php | 9 ++- include/export/export_fiche_balance_pdf.php | 75 ++++++++------------- 2 files changed, 33 insertions(+), 51 deletions(-) diff --git a/include/class/acc_ledger_sale.class.php b/include/class/acc_ledger_sale.class.php index f742ce1b6..c8ca25eb4 100644 --- a/include/class/acc_ledger_sale.class.php +++ b/include/class/acc_ledger_sale.class.php @@ -1051,7 +1051,8 @@ if ( $g_parameter->MY_TVA_USE=="Y") { EOF; - + $sql_currency=new Currency_SQL($this->cn,$p_currency_code); + $iso_code=$sql_currency->getp("cr_code_iso"); if ($p_currency_code !=0) { $r.=<< - {$tot_eur} EUR + {$tot_eur} {$iso_code} EOF; } } else { + $sql_currency=new Currency_SQL($this->cn,$p_currency_code); + $iso_code=$sql_currency->getp("cr_code_iso"); // without VAT $r.=<< @@ -1102,7 +1105,7 @@ EOF; {$rate} {$p_currency_rate} - {$tot_eur} EUR + {$tot_eur} {$iso_code} EOF; diff --git a/include/export/export_fiche_balance_pdf.php b/include/export/export_fiche_balance_pdf.php index 0a0031527..8db11a6a3 100644 --- a/include/export/export_fiche_balance_pdf.php +++ b/include/export/export_fiche_balance_pdf.php @@ -32,10 +32,16 @@ $gDossier=dossier::id(); $cn=Dossier::connect(); $g_user->Check(); $g_user->check_dossier($gDossier); -$name=$cn->get_value('select fd_label from fiche_def where fd_id=$1',array($_GET['cat'])); + +$http=new HttpInput(); + +$cat = $http->get("cat"); +$histo = $http->get("histo"); + +$name=$cn->get_value('select fd_label from fiche_def where fd_id=$1',array($cat)); $pdf=new PDF($cn); -$pdf->setDossierInfo(" Periode : ".$_GET['start']." - ".$_GET['end']); +$pdf->setDossierInfo(" Periode : ".$http->get('start')." - ".$http->get('end')); $pdf->AliasNbPages(); $pdf->AddPage(); @@ -46,9 +52,9 @@ $allcard=(isset($_GET['allcard']))?1:0; /* * Balance */ -if ( $_GET['histo'] == 4 || $_GET['histo']==5) +if ($histo == 4 || $histo==5) { - $fd=new Fiche_Def($cn,$_REQUEST['cat']); + $fd=new Fiche_Def($cn,$http->request('cat')); if ($allcard==1 && $fd->hasAttribute(ATTR_DEF_ACCOUNT) == false ) { $pdf->write_cell(0,10, "Cette catégorie n'ayant pas de poste comptable n'a pas de balance"); @@ -64,7 +70,7 @@ if ( $_GET['histo'] == 4 || $_GET['histo']==5) } else { - $afiche[0]=array('fd_id'=>$_REQUEST['cat']); + $afiche[0]=array('fd_id'=>$http->request('cat')); } if ( $allcard==0 && empty($afiche)) @@ -96,26 +102,16 @@ if ( $_GET['histo'] == 4 || $_GET['histo']==5) $idx=0;$sum_deb=0;$sum_cred=0;bcscale(4); for ($i=0;$i < count($aCard);$i++) { - if ( isDate($_REQUEST['start']) == null || isDate ($_REQUEST['end']) == null ) exit; - $filter= " (j_date >= to_date('".$_REQUEST['start']."','DD.MM.YYYY') ". - " and j_date <= to_date('".$_REQUEST['end']."','DD.MM.YYYY')) "; + if ( isDate($http->request('start')) == null || isDate ($http->request('end')) == null ) exit; + $filter= " (j_date >= to_date('".$http->request('start')."','DD.MM.YYYY') ". + " and j_date <= to_date('".$http->request('end')."','DD.MM.YYYY')) "; $oCard=new Fiche($cn,$aCard[$i]['f_id']); $solde=$oCard->get_solde_detail($filter); if ( $solde['debit'] == 0 && $solde['credit']==0) continue; /* only not purged card */ - if ($_GET['histo'] == 5 && $solde['debit'] == $solde['credit']) continue; - - if ( $idx % 2 == 0 ) - { - $pdf->SetFillColor(220,221,255); - $fill=1; - } - else - { - $pdf->SetFillColor(0,0,0); - $fill=0; - } - $idx++; + if ($histo == 5 && $solde['debit'] == $solde['credit']) continue; + $fill=$pdf->is_fill($idx); + $idx++; $side=''; if(bcsub($solde['credit'],$solde['debit']) < 0) $side='Deb.'; if(bcsub($solde['credit'],$solde['debit']) > 0) $side='Cred.'; @@ -132,16 +128,8 @@ if ( $_GET['histo'] == 4 || $_GET['histo']==5) $pdf->write_cell(20,7,$side,0,0,'C',$fill); $pdf->line_new(); } - if ( $idx % 2 == 0 ) - { - $pdf->SetFillColor(220,221,255); - $fill=1; - } - else - { - $pdf->SetFillColor(0,0,0); - $fill=0; - } + $fill=$pdf->is_fill($idx); + $idx++; // Sum by category $pdf->write_cell(30,7,"",0,0,'L',$fill); @@ -173,7 +161,7 @@ else } else { - $afiche[0] = array('fd_id' => $_REQUEST['cat']); + $afiche[0] = array('fd_id' => $http->request('cat')); } $fic=new Fiche($cn); for ($e = 0; $e < count($afiche); $e++) @@ -194,25 +182,25 @@ else $fic = new Fiche($cn, $row_fiche['f_id']); $letter = new Lettering_Card($cn); $letter->set_parameter('quick_code', $fic->strAttribut(ATTR_DEF_QUICKCODE)); - $letter->set_parameter('start', $_GET['start']); - $letter->set_parameter('end', $_GET['end']); + $letter->set_parameter('start',$http->request('start')); + $letter->set_parameter('end',$http->request('end')); // all - if ($_GET['histo'] == 0) + if ($histo == 0) { $letter->get_all(); } // lettered - if ($_GET['histo'] == 1) + if ($histo == 1) { $letter->get_letter(); } // unlettered - if ($_GET['histo'] == 2) + if ($histo == 2) { $letter->get_unletter(); } - if ($_GET['histo'] == 6) + if ($histo == 6) { $letter->get_letter_diff(); } @@ -240,16 +228,7 @@ else $prog=0; for ($i = 0; $i < count($letter->content); $i++) { - if ($i % 2 == 0) - { - $pdf->SetFillColor(220, 221, 255); - $fill = 1; - } - else - { - $pdf->SetFillColor(0, 0, 0); - $fill = 0; - } + $fill=$pdf->is_fill($i); $pdf->SetFont('DejaVuCond', '', 7); $row = $letter->content[$i]; $str_date = shrink_date($row['j_date_fmt']); From debfa65ed12795ec34e7af9fcbde4076c8a462b9 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Fri, 15 Sep 2023 19:13:00 +0200 Subject: [PATCH 05/16] correct global g_parameter --- include/class/acc_ledger_search.class.php | 3 ++- include/template/ledger_search.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/class/acc_ledger_search.class.php b/include/class/acc_ledger_search.class.php index 673b2720c..de404825e 100644 --- a/include/class/acc_ledger_search.class.php +++ b/include/class/acc_ledger_search.class.php @@ -104,7 +104,8 @@ class Acc_Ledger_Search */ function search_form() { - global $g_user; + global $g_user,$g_parameter; + $g_parameter=new Noalyss_Parameter_Folder($this->cn); $http=new HttpInput(); $r=""; $bledger_param=json_encode(array( diff --git a/include/template/ledger_search.php b/include/template/ledger_search.php index a5ac3bba8..6a8010f03 100644 --- a/include/template/ledger_search.php +++ b/include/template/ledger_search.php @@ -1,7 +1,7 @@ From 3d8265f89fc8223304fa743ac5757a87f5076dab Mon Sep 17 00:00:00 2001 From: sparkyx Date: Fri, 15 Sep 2023 19:15:32 +0200 Subject: [PATCH 06/16] Comptability PHP8.1 remove deprecated null string --- include/lib/pdf_core.class.php | 4 ++-- include/template/stock_histo.php | 4 ++-- include/template/stock_summary_table.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/lib/pdf_core.class.php b/include/lib/pdf_core.class.php index d46355f3c..3b4563889 100644 --- a/include/lib/pdf_core.class.php +++ b/include/lib/pdf_core.class.php @@ -264,7 +264,7 @@ class PDF_Core extends TFPDF $this->bigger=0; } /** - * If the step is even then return 1 and set the backgroup color to blue , otherwise + * @brief If the step is even then return 1 and set the backgroup color to blue , otherwise * returns 0, and set the background color to white * It is use to compute alternated colored row , it the parameter fill in write_cell and * cell @@ -281,7 +281,7 @@ class PDF_Core extends TFPDF $this->SetFillColor(255, 255, 255); $fill = 0; } - return $p_step; + return $fill; } diff --git a/include/template/stock_histo.php b/include/template/stock_histo.php index bdb496de5..2c61a5a10 100644 --- a/include/template/stock_histo.php +++ b/include/template/stock_histo.php @@ -59,12 +59,12 @@ diff --git a/include/template/stock_summary_table.php b/include/template/stock_summary_table.php index 485bd74dc..a191be1da 100644 --- a/include/template/stock_summary_table.php +++ b/include/template/stock_summary_table.php @@ -89,7 +89,7 @@ : From 1c99430ecf1a208570fee6b62fed14be50676a09 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Fri, 15 Sep 2023 19:23:34 +0200 Subject: [PATCH 07/16] Remove dead code remove dead code : useless file and menu --- include/constant.php | 2 +- include/export/export_fiche_pdf.php | 233 ---------------------------- include/sql/patch/upgrade189.sql | 6 + 3 files changed, 7 insertions(+), 234 deletions(-) delete mode 100644 include/export/export_fiche_pdf.php create mode 100644 include/sql/patch/upgrade189.sql diff --git a/include/constant.php b/include/constant.php index 6e2607785..a5fd19ee9 100644 --- a/include/constant.php +++ b/include/constant.php @@ -116,7 +116,7 @@ if (!defined("NOALYSS_PACKAGE_REPOSITORY")) { if (!defined("SYSINFO_DISPLAY")) { define("SYSINFO_DISPLAY", TRUE); } -define("DBVERSION", 189); +define("DBVERSION", 190); define("MONO_DATABASE", 25); define("DBVERSIONREPO", 20); define('NOTFOUND', '--not found--'); diff --git a/include/export/export_fiche_pdf.php b/include/export/export_fiche_pdf.php deleted file mode 100644 index d6efa5d28..000000000 --- a/include/export/export_fiche_pdf.php +++ /dev/null @@ -1,233 +0,0 @@ -category, export in PDF the history of a category - * of card - * @bug NOT USED MUST BE REMOVED - */ -if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis'); -// Security we check if user does exist and his privilege -require_once NOALYSS_INCLUDE.'/lib/ac_common.php'; - -/* Security */ -$gDossier=dossier::id(); -$cn=Dossier::connect(); -$g_user->Check(); -$g_user->check_dossier($gDossier); - -$pdf=new PDF($cn); -$pdf->setDossierInfo(" Periode : ".$_GET['start']." - ".$_GET['end']); -$pdf->AliasNbPages(); -$pdf->AddPage(); -$name=$cn->get_value('select fd_label from fiche_def where fd_id=$1',array($_GET['cat'])); -$pdf->SetFont('DejaVu','BI',14); -$pdf->write_cell(0,8,$name,0,1,'C'); -$pdf->SetTitle($name,1); -$pdf->SetAuthor('NOALYSS'); -$http=new HttpInput(); -$start=$http->request('start'); -$end=$http->request('end'); -if ( isDate($start) == null || isDate ($end) == null ) return; - -/* balance */ -if ( $_GET['histo'] == 4 ) -{ - $cat=$http->request('cat'); - $fd=new Fiche_Def($cn,$cat); - if ( $fd->hasAttribute(ATTR_DEF_ACCOUNT) == false ) - { - $pdf->write_cell(0,10, _("Cette catégorie n'ayant pas de poste comptable n'a pas de balance")); - //Save PDF to file - $fDate=date('dmy-Hi'); - $pdf->Output("category-$fDate.pdf", 'D'); - exit; - } - $aCard=$cn->get_array("select f_id,ad_value from fiche join fiche_Detail using (f_id) where ad_id=1 and fd_id=$1 order by 2 ",array($cat)); - - if ( empty($aCard)) - { - $pdf->write_cell(0,10, _("Aucune fiche trouvée"));//Save PDF to file - $fDate=date('dmy-Hi'); - $pdf->Output("category-$fDate.pdf", 'D'); - exit; - } - $pdf->SetFont('DejaVuCond','',7); - $pdf->write_cell(30,7,'Quick Code',0,0,'L',0); - $pdf->write_cell(80,7,'Libellé',0,0,'L',0); - $pdf->write_cell(20,7,'Débit',0,0,'R',0); - $pdf->write_cell(20,7,'Crédit',0,0,'R',0); - $pdf->write_cell(20,7,'Solde',0,0,'R',0); - $pdf->write_cell(20,7,'D/C',0,0,'C',0); - $pdf->line_new(); - $idx=0; - $filter= " (j_date >= to_date('".$start."','DD.MM.YYYY') ". - " and j_date <= to_date('".$end."','DD.MM.YYYY')) "; - for ($i=0;$i < count($aCard);$i++) - { - $oCard=new Fiche($cn,$aCard[$i]['f_id']); - $solde=$oCard->get_solde_detail($filter); - if ( $solde['debit'] == 0 && $solde['credit']==0) continue; - - if ( $idx % 2 == 0 ) - { - $pdf->SetFillColor(220,221,255); - $fill=1; - } - else - { - $pdf->SetFillColor(0,0,0); - $fill=0; - } - $idx++; - - $pdf->write_cell(30,7,$oCard->strAttribut(ATTR_DEF_QUICKCODE),0,0,'L',$fill); - $pdf->write_cell(80,7,$oCard->strAttribut(ATTR_DEF_NAME),0,0,'L',$fill); - $pdf->write_cell(20,7,sprintf('%.02f',$solde['debit']),0,0,'R',$fill); - $pdf->write_cell(20,7,sprintf('%.02f',$solde['credit']),0,0,'R',$fill); - $pdf->write_cell(20,7,sprintf('%.02f',abs($solde['solde'])),0,0,'R',$fill); - $pdf->write_cell(20,7,(($solde['solde']<0)?'CRED':'DEB'),0,0,'C',$fill); - $pdf->line_new(); - } -} -else -{ - $array=Fiche::get_fiche_def($cn,$_GET['cat'],'name_asc'); - /* - * You show now the result - */ - if ($array == null ) - { - exit(); - } - $tab=array(13,25,55,20,20,12,20); - $align=array('L','L','L','R','R','R','R'); - - foreach($array as $row_fiche) - { - $row=new Fiche($cn,$row_fiche['f_id']); - $letter=new Lettering_Card($cn); - $letter->set_parameter('quick_code',$row->strAttribut(ATTR_DEF_QUICKCODE)); - $letter->set_parameter('start',$_GET['start']); - $letter->set_parameter('end',$_GET['end']); - // all - if ( $_GET['histo'] == 0 ) - { - $letter->get_all(); - } - - // lettered - if ( $_GET['histo'] == 1 ) - { - $letter->get_letter(); - } - // unlettered - if ( $_GET['histo'] == 2 ) - { - $letter->get_unletter(); - } - /* skip if nothing to display */ - if (count($letter->content) == 0 ) continue; - $pdf->SetFont('DejaVuCond','',10); - $fiche=new Fiche($cn,$row_fiche['f_id']); - $pdf->write_cell(0,7,$fiche->strAttribut(ATTR_DEF_NAME),1,1,'C'); - - $pdf->SetFont('DejaVuCond','',7); - - $pdf->write_cell($tab[0],7,'Date'); - $pdf->write_cell($tab[1],7,'ref'); - $pdf->write_cell($tab[1],7,'Int.'); - $pdf->write_cell($tab[2],7,'Comm'); - $pdf->write_cell(40,7,'Montant',0,0,'C'); - $pdf->write_cell($tab[5],7,'Let.',0,0,'R'); - $pdf->write_cell($tab[6],7,'Som. Let.',0,0,'R'); - $pdf->line_new(); - - $amount_deb=0; - $amount_cred=0; - for ($i=0;$icontent);$i++) - { - if ( $i % 2 == 0 ) - { - $pdf->SetFillColor(220,221,255); - $fill=1; - } - else - { - $pdf->SetFillColor(0,0,0); - $fill=0; - } - $pdf->SetFont('DejaVuCond','',7); - $row=$letter->content[$i]; - $str_date=shrink_date($row['j_date_fmt']); - - $pdf->write_cell($tab[0],4,$str_date,0,0,$align[0],$fill); - $pdf->write_cell($tab[1],4,$row['jr_pj_number'],0,0,$align[1],$fill); - $pdf->write_cell($tab[1],4,$row['jr_internal'],0,0,$align[1],$fill); - $pdf->write_cell($tab[2],4,$row['jr_comment'],0,0,$align[2],$fill); - if ( $row['j_debit'] == 't') - { - $pdf->write_cell($tab[3],4,sprintf('%10.2f',$row['j_montant']),0,0,$align[4],$fill); - $amount_deb+=$row['j_montant']; - $pdf->write_cell($tab[4],4,"",0,0,'C',$fill); - } - else - { - $pdf->write_cell($tab[3],4,"",0,0,'C',$fill); - $pdf->write_cell($tab[4],4,sprintf('%10.2f',$row['j_montant']),0,0,$align[4],$fill); - $amount_cred+=$row['j_montant']; - } - if ($row['letter'] != -1 ) - { - $pdf->write_cell($tab[5],4,strtoupper(base_convert($row['letter'],10,36)),0,0,$align[5],$fill); - // get sum for this lettering - $sql="select sum(j_montant) from jrnx where j_debit=$1 and j_id in ". - " (select j_id from jnt_letter join letter_deb using (jl_id) where jl_id=$2 union ". - " select j_id from jnt_letter join letter_cred using (jl_id) where jl_id=$3)"; - $sum=$cn->get_value($sql,array($row['j_debit'],$row['letter'],$row['letter'])); - $pdf->write_cell($tab[6],4,sprintf('%.2f',$sum),'0','0','R',$fill); - } - else - $pdf->write_cell($tab[5],4,"",0,0,'R',$fill); - $pdf->line_new(); - } - $pdf->SetFillColor(0,0,0); - $pdf->SetFont('DejaVuCond','B',8); - $debit =sprintf('Debit : % 12.2f',$amount_deb); - $credit=sprintf('Credit : % 12.2f',$amount_cred); - if ( $amount_deb>$amount_cred) $s='solde débiteur'; - else $s='solde crediteur'; - $solde =sprintf('%s : % 12.2f',$s,(abs(round($amount_cred-$amount_deb,2)))); - - $pdf->write_cell(0,6,$debit,0,0,'R'); - $pdf->line_new(4); - $pdf->write_cell(0,6,$credit,0,0,'R'); - $pdf->line_new(4); - $pdf->write_cell(0,6,$solde,0,0,'R'); - $pdf->line_new(4); - - $pdf->line_new(); - } -} -//Save PDF to file -$fDate=date('dmy-Hi'); -$pdf->Output("category-$fDate.pdf", 'D'); -exit; diff --git a/include/sql/patch/upgrade189.sql b/include/sql/patch/upgrade189.sql new file mode 100644 index 000000000..ef3abe35a --- /dev/null +++ b/include/sql/patch/upgrade189.sql @@ -0,0 +1,6 @@ +begin; + +delete from menu_ref where me_code='PDF:fiche'; + +insert into version (val,v_description) values (190,'remove dead code'); +commit; \ No newline at end of file From 4bf2ca815181df863a8cfffc733b51beec0369e5 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sat, 16 Sep 2023 12:42:57 +0200 Subject: [PATCH 08/16] task #2297: Suppression $_REQUEST dossier.class.php --- include/class/dossier.class.php | 56 ++++++++++--------- .../{dossier.Test.php => dossierTest.php} | 33 +++++++++++ 2 files changed, 63 insertions(+), 26 deletions(-) rename unit-test/include/class/{dossier.Test.php => dossierTest.php} (63%) diff --git a/include/class/dossier.class.php b/include/class/dossier.class.php index f7442efce..e4aafdcf1 100644 --- a/include/class/dossier.class.php +++ b/include/class/dossier.class.php @@ -50,11 +50,10 @@ class Dossier $this->dos_id=$p_id; } - /*!\brief return the $_REQUEST['gDossier'] after a check */ + /*!\brief return the 'gDossier' value after a check */ static function id() { - self::check(); $http=new HttpInput(); return $http->request('gDossier','number'); @@ -127,11 +126,12 @@ class Dossier return $nb_folder; } - /*! - * \brief Return all the users - * as an array + /** + * \brief Return all the users as an array but NOALYSS_ADMINISTRATOR, that user cannot be changed by the + * interface for administrating user + * \param SQL $sql sql string to add to the query : + * \note that string MUST be the result of Database::escape_string */ - function get_user_folder($sql="") { @@ -162,20 +162,21 @@ class Dossier return $res; } - /*!\brief check if gDossier is set */ + /*!\brief check if gDossier is set + * ?? dead code ??? + */ static function check() { - if (!isset($_REQUEST['gDossier'])) - { - echo_error('Dossier inconnu '); - exit('Dossier invalide '); + try { + $http=new HttpInput(); + $id=$http->request("gDossier","number"); + if ($id > 999999 || $id < 0) throw new \Exception(_("Dossier max dépassé")); + } catch (\Exception $e) { + + die('Dossier invalide '); } - $id=$_REQUEST['gDossier']; - if (is_numeric($id)==0|| - strlen($id)>6|| - $id>999999) - exit('gDossier Invalide : '.$id); + } /*! @@ -184,27 +185,30 @@ class Dossier static function get() { - self::check(); - return "gDossier=".$_REQUEST['gDossier']; + $http=new \HttpInput(); + return "gDossier=".$http->request("gDossier","number"); } - /*!\brief return a string to set gDossier into a FORM */ + /*! + * \brief return a string to set gDossier into a FORM + */ static function hidden() { - self::check(); - return ''; + $http=new \HttpInput(); + + return ''; } /*!\brief retrieve the name of the current dossier */ static function name($id=0) { - self::check(); + $http=new \HttpInput(); $cn=new Database(); - $id=($id==0)?$_REQUEST['gDossier']:$id; - $name=$cn->get_value("select dos_name from ac_dossier where dos_id=$1", array($_REQUEST['gDossier'])); + $id=($id==0)?$http->request("gDossier","number"):$id; + $name=$cn->get_value("select dos_name from ac_dossier where dos_id=$1", array($id)); return $name; } @@ -419,9 +423,9 @@ class Dossier */ static function set_current($p_dossier) { + self::check($p_dossier); put_global([ [ "key"=>"gDossier","value"=>$p_dossier]]); - self::check(); - + } } diff --git a/unit-test/include/class/dossier.Test.php b/unit-test/include/class/dossierTest.php similarity index 63% rename from unit-test/include/class/dossier.Test.php rename to unit-test/include/class/dossierTest.php index 3e06982b9..25f2416c9 100644 --- a/unit-test/include/class/dossier.Test.php +++ b/unit-test/include/class/dossierTest.php @@ -59,4 +59,37 @@ class DossierTest extends TestCase $obj->load(); $this->assertEquals(DOSSIER,$obj->get_parameter("id"),"Not the right folder"); } + /** + * @testdox check + */ + public function testCheck() + { + $_REQUEST['gDossier']='14'; + \Dossier::check(); + $this->assertTrue(true, 'check has failed'); + } + /** + * @testdox hidden function + */ + function testHidden() + { + $_REQUEST['gDossier']='14'; + $this->assertEquals('', \Dossier::hidden()); + } + /** + * @testdox get function + */ + function testGet() + { + $_REQUEST['gDossier']='14'; + $this->assertEquals('gDossier=14', \Dossier::get()); + } + /** + * @testdox set current dossier + */ + function testSetCurrentDossier() + { + \Dossier::set_current(15); + $this->assertEquals(15, \Dossier::id()); + } } From 479306c564eeae9a681b4675cac8f7ab7852f60d Mon Sep 17 00:00:00 2001 From: sparkyx Date: Wed, 20 Sep 2023 14:13:18 +0200 Subject: [PATCH 09/16] PHP Compatibility 8.1 --- include/tfpdf/tfpdf.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/tfpdf/tfpdf.php b/include/tfpdf/tfpdf.php index 6000a9fb2..17f135b90 100644 --- a/include/tfpdf/tfpdf.php +++ b/include/tfpdf/tfpdf.php @@ -2257,14 +2257,14 @@ function UTF8ToUTF16BE($str, $setbom=true) { if ($setbom) { $outstr .= "\xFE\xFF"; // Byte Order Mark (BOM) } - $outstr .= mb_convert_encoding($str, 'UTF-16BE', 'UTF-8'); + $outstr .= mb_convert_encoding($str??"", 'UTF-16BE', 'UTF-8'); return $outstr; } // Converts UTF-8 strings to codepoints array function UTF8StringToArray($str) { $out = array(); - $len = strlen($str); + $len = strlen($str??""); for ($i = 0; $i < $len; $i++) { $uni = -1; $h = ord($str[$i]); From 9d92671ed13b6da3bbea365b37fd2a2cdaab80be Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sat, 14 Oct 2023 13:44:14 +0200 Subject: [PATCH 10/16] Improve Manage_Table : search button if modify or delete is on the left --- include/lib/manage_table_sql.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/lib/manage_table_sql.class.php b/include/lib/manage_table_sql.class.php index 9fb1f7df3..ae181b58c 100644 --- a/include/lib/manage_table_sql.class.php +++ b/include/lib/manage_table_sql.class.php @@ -824,8 +824,10 @@ function check() } $nb_order=count($this->a_order); $virg=""; $result=""; + // filter only on visible column - $visible=0; + $visible=($this->icon_mod=='left')?1:0; + $visible=$visible+( ($this->icon_del=='left')?1:0); for ($e=0; $e<$nb_order; $e++) { if ($this->get_property_visible($this->a_order[$e])==TRUE) From 7b13bbfe534334e4bb724ada9dcdda5eca92a6da Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sun, 12 Nov 2023 22:13:47 +0100 Subject: [PATCH 11/16] Documentation --- html/css/style-classic7.css | 6 +++--- html/js/acc_ledger.js | 3 +++ include/class/extension.class.php | 1 + include/class/periode.class.php | 10 +++++----- include/lib/database_core.class.php | 31 +++++++++++++++++++---------- include/lib/html_input.class.php | 27 +++++++++++++------------ include/lib/inplace_edit.class.php | 8 ++++++-- 7 files changed, 52 insertions(+), 34 deletions(-) diff --git a/html/css/style-classic7.css b/html/css/style-classic7.css index 92579a4a5..101a95a02 100644 --- a/html/css/style-classic7.css +++ b/html/css/style-classic7.css @@ -2388,11 +2388,12 @@ td.selectedmenu { } .v-large { display: none;} +/* + * Comment in follow-up + */ .field_follow_up { margin-top:1px; - white-space: -moz-pre-wrap; - white-space: pre-wrap; border:1px solid blue; } @@ -2433,7 +2434,6 @@ td.selectedmenu { text-decoration: none; color:blue; font-size:1.7em; - font-size: 1.7rem; padding: 0px; margin: 0px; background-color: inherit; diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js index 7cb77c916..5ad1e921b 100644 --- a/html/js/acc_ledger.js +++ b/html/js/acc_ledger.js @@ -1246,6 +1246,7 @@ function op_save(obj) onFailure: null, onSuccess: function (req){ if (req.responseText !=='OK') { + console.error("D2. op_save") smoke.alert(req.responseText); } } @@ -1283,6 +1284,7 @@ function op_save(obj) $(divid).innerHTML.evalScripts(); remove_waiting_box(); } catch (e) { + console.error("D1. op_save") alert_box("1038"+e.message) } } @@ -1294,6 +1296,7 @@ function op_save(obj) return false; } catch (e) { + console.error("F1. op_save") alert_box(e.message); } } diff --git a/include/class/extension.class.php b/include/class/extension.class.php index 988f6702d..bf60cbdad 100644 --- a/include/class/extension.class.php +++ b/include/class/extension.class.php @@ -148,6 +148,7 @@ class Extension extends Menu_Ref_sql throw new Exception(_('Profil inexistant'), 10); } // Menu exists + \Noalyss\Dbg::echo_var(1,__FILE__.__LINE__. "p_module to find $p_module"); $module=new Menu_Ref($cn, $p_module); if ($module->me_code==null) { diff --git a/include/class/periode.class.php b/include/class/periode.class.php index 2cbafa44b..f2981638b 100644 --- a/include/class/periode.class.php +++ b/include/class/periode.class.php @@ -54,11 +54,11 @@ class Periode { $r=<<$jrn_def_id, - \$p_id=>$p_id, - \$status => $status, - \$p_start => $p_start, - \$p_end => $p_end, + \$jrn_def_id=>$this->jrn_def_id, + \$p_id=>$this->p_id, + \$status => $this->status, + \$p_start => $this->p_start, + \$p_end => $this->p_end, ] EOF; return $r; diff --git a/include/lib/database_core.class.php b/include/lib/database_core.class.php index 36eb417d5..56831a3c6 100644 --- a/include/lib/database_core.class.php +++ b/include/lib/database_core.class.php @@ -169,7 +169,7 @@ class DatabaseCore return $this; } - /** + /** * \brief send a sql string to the database * \param $p_string sql string * \param $p_array array for the SQL string (see pg_query_params) @@ -480,7 +480,7 @@ class DatabaseCore } /** - * Returns only one row from a query + * @brief Returns only one row from a query * @param string $p_sql * @param array $p_array * @return array , idx = column of the table or null if nothing is found @@ -735,7 +735,8 @@ class DatabaseCore return false; } - /**\brief wrapper for the function pg_num_rows + /** + * \brief wrapper for the function pg_num_rows * \param $ret is the result of a exec_sql * \return number of line affected */ @@ -745,7 +746,8 @@ class DatabaseCore return pg_num_rows($ret); } - /**\brief wrapper for the function pg_fetch_array + /** + * \brief wrapper for the function pg_fetch_array * \param $ret is the result of a pg_exec * \param $p_indice is the index * \param $p_indice is the index @@ -757,7 +759,8 @@ class DatabaseCore return pg_fetch_array($ret, $p_indice,$p_mode); } - /**\brief wrapper for the function pg_fetch_all + /** + * \brief wrapper for the function pg_fetch_all * \param $ret is the result of pg_exec (exec_sql) * \return double array (row x col ) or false */ @@ -767,7 +770,8 @@ class DatabaseCore return pg_fetch_all($ret); } - /**\brief wrapper for the function pg_fetch_all + /** + * \brief wrapper for the function pg_fetch_all * \param $ret is the result of pg_exec (exec_sql) * \param $p_row is the indice of the row * \param $p_col is the indice of the col @@ -790,7 +794,8 @@ class DatabaseCore return pg_fetch_row($ret, $p_row); } - /**\brief wrapper for the function pg_lo_unlink + /** + * \brief wrapper for the function pg_lo_unlink * \param $p_oid is the of oid * \return return the result of the operation */ @@ -838,7 +843,8 @@ class DatabaseCore return pg_lo_export($this->db, $p_oid, $tmp_file); } - /**\brief wrapper for the function pg_lo_export + /** + * \brief wrapper for the function pg_lo_export * \param $p_filename is the filename * \param $tmp is the file * \return result of the operation @@ -849,7 +855,8 @@ class DatabaseCore return pg_lo_import($this->db, $p_filename); } - /**\brief wrapper for the function pg_escape_string + /** + * \brief wrapper for the function pg_escape_string * \param $p_string is the string to escape * \return escaped string */ @@ -861,7 +868,8 @@ class DatabaseCore return pg_escape_string($cn->db,$p_string); } - /**\brief wrapper for the function pg_close + /** + * \brief wrapper for the function pg_close */ function close() @@ -870,7 +878,8 @@ class DatabaseCore $this->is_open = FALSE; } - /**\brief + /** + * \brief * \param * \return * \note diff --git a/include/lib/html_input.class.php b/include/lib/html_input.class.php index 9ea2e3b1d..bef615f6a 100755 --- a/include/lib/html_input.class.php +++ b/include/lib/html_input.class.php @@ -102,7 +102,8 @@ var $css_size; $this->readOnly=$p_read; } - /*!\brief set the extra javascript property for the INPUT field + /*! + * \brief set the extra javascript property for the INPUT field * \param $p_name name of the parameter * \param $p_value default value of this parameter */ @@ -440,7 +441,7 @@ var $css_size; } /** - * close button for the HTML popup + * @brief close button for the HTML popup * @see add_div modify_operation * @param $div_name is the name of the div to remove */ @@ -470,7 +471,7 @@ var $css_size; } /** - * Return a html string with an anchor which close the inside popup. (top-right corner) + * @brief Return a html string with an anchor which close the inside popup. (top-right corner) * @param name of the DIV to close * @deprecated * @see Icon_Action::close @@ -481,7 +482,7 @@ var $css_size; } /** - * Anchor Html with javascript + * @brief Anchor Html with javascript * @param $action action action to perform (message) without onclick * @param $javascript javascript to execute * @param $id is the DOM element id @@ -501,7 +502,7 @@ var $css_size; } /** - * button Html with javascript + * @brief button Html with javascript * @param $action action action to perform (message) without onclick * @param $javascript javascript to execute * @param $id is the DOM element id @@ -521,7 +522,7 @@ var $css_size; } /** - * Image to click , + * @brief Image to click , * @param string $p_image filename of the image under image/ * @param string $p_js javascript when the image is clicked * @param string $p_message Message @@ -534,7 +535,7 @@ var $css_size; } /** - * button Html image + * @brief button Html image * @param $javascript javascript to execute * @param $id id of the button * @param $class class of the button @@ -553,7 +554,7 @@ var $css_size; } /** - * Return a html string with an anchor to hide a div, put it in the right corner + * @brief Return a html string with an anchor to hide a div, put it in the right corner * @param $action action action to perform (message) * @param $javascript javascript * @note not protected against html @@ -577,7 +578,7 @@ var $css_size; } /** - * show the detail of a card + * @brief show the detail of a card */ static function card_detail($p_qcode, $pname='', $p_style="", $p_nohistory=false) @@ -591,7 +592,7 @@ var $css_size; } /** - * transform request data to hidden + * @brief transform request data to hidden * @param $array is an of indices * @param $request name of the superglobal $_POST $_GET $_REQUEST(default) * @return html string with the hidden data @@ -625,7 +626,7 @@ var $css_size; return $r; } /** - * Transform a double array as a HTML string with hidden html value + * @brief Transform a double array as a HTML string with hidden html value * array has the formarray ["name"]="x",array['value']="y") the key name will be the hidden input name; * @param double $array */ @@ -652,7 +653,7 @@ var $css_size; } /** - * transform $_GET data to hidden + * @brief transform $_GET data to hidden * @param $array is an of indices * @see HtmlInput::request_to_hidden * @return html string with the hidden data @@ -1167,7 +1168,7 @@ var $css_size; } /** - * Insert attribute inside a INPUT TYPE, these attribute can be retrieved + * @brief Insert attribute inside a INPUT TYPE, these attribute can be retrieved * in javascript with element.getAttribute or changed with element.setAttribute * example insert my_attribute into a checkbox * @return string to insert into the HTML node diff --git a/include/lib/inplace_edit.class.php b/include/lib/inplace_edit.class.php index 6e631320e..dd22acafd 100644 --- a/include/lib/inplace_edit.class.php +++ b/include/lib/inplace_edit.class.php @@ -30,7 +30,11 @@ * You need an ajax to response and modify the data. Some parameters will be sent * by default when you click on the element * - input : htmlInput object serialized - * - action : ok or cancel , nothing if you just want to display the input + * - ieaction : ok or cancel , nothing if you just want to display the input + * + * Very important it is the DOM ID of the HtmlInput element, it must unique. For the date + * set a uniq dom id, otherwise it fails + * $id_limit_date->id=uniqid("date"); * * @example inplace_edit.test.php */ @@ -111,7 +115,7 @@ EOF; function value() { $v=$this->input->get_value(); - $v=html_entity_decode($v); + $v=html_entity_decode($v??""); if ( $this->input instanceof ITextarea) { echo '

    ';
    
    From 86852bc4252e5dde7a04277393086355b12a6cc6 Mon Sep 17 00:00:00 2001
    From: sparkyx 
    Date: Sun, 12 Nov 2023 22:22:27 +0100
    Subject: [PATCH 12/16] PHP8.2 deprecated
    
    ---
     include/class/acc_bilan.class.php | 5 ++++-
     include/class/dossier.class.php   | 2 +-
     include/header_print.php          | 5 ++++-
     include/lib/ac_common.php         | 7 +++++--
     include/lib/noalyss_csv.class.php | 2 +-
     5 files changed, 15 insertions(+), 6 deletions(-)
    
    diff --git a/include/class/acc_bilan.class.php b/include/class/acc_bilan.class.php
    index 9b30ed5e1..3f398e09c 100644
    --- a/include/class/acc_bilan.class.php
    +++ b/include/class/acc_bilan.class.php
    @@ -398,7 +398,10 @@ class Acc_Bilan
             $regex="/<<\\$[A-Z]*[0-9]*>>/";
             $lt="<";
             $gt=">";
    -	$header_txt=utf8_encode(header_txt($this->db));
    +	// convert to UTF8
    +	$header_txt=iconv('ISO-8859-1','UTF-8//IGNORE',header_txt($this->db));
    +	
    +	
     
             while ( !feof($p_file) )
             {
    diff --git a/include/class/dossier.class.php b/include/class/dossier.class.php
    index e4aafdcf1..46c53e615 100644
    --- a/include/class/dossier.class.php
    +++ b/include/class/dossier.class.php
    @@ -171,7 +171,7 @@ class Dossier
             try {
                 $http=new HttpInput();
                 $id=$http->request("gDossier","number");
    -            if ($id > 999999 || $id < 0) throw new \Exception(_("Dossier max dépassé"));
    +            if ($id > 999999 || $id < 0) throw new \Exception(_("Dossier max dépassé "));
             } catch (\Exception $e) {
     
                 die('Dossier invalide ');
    diff --git a/include/header_print.php b/include/header_print.php
    index 7a510a068..8f4aaacf5 100644
    --- a/include/header_print.php
    +++ b/include/header_print.php
    @@ -34,7 +34,10 @@ function header_txt($p_cn)
         $soc=$own->MY_NAME;
     
         $date=date('d / m / Y H:i ');
    -    $dossier=utf8_decode(" Dossier : ".dossier::name());
    +    $str=sprintf(" Dossier : %s",dossier::name());
    +    // convert to latin1
    +    $dossier=iconv('UTF-8','ISO-8859-1//IGNORE',$str);
    +    
         return $dossier." ".$soc." ".$date;
     }
     
    diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php
    index cf3d0300e..dcab67a9f 100644
    --- a/include/lib/ac_common.php
    +++ b/include/lib/ac_common.php
    @@ -1374,14 +1374,17 @@ if(!function_exists('tracedebug')) {
       }
     }
     /**
    - * @brief encode the string for RTF, return a stringu
    + * @brief encode the string for RTF, return a string
      * @param $p_string string to convert
      * @return string
      */
     function convert_to_rtf($p_string)
     {
         $result="";
    -    $p_string2=utf8_decode($p_string);
    +    // convert to latin 
    +    $p_string2=iconv('UTF-8','ISO-8859-1//IGNORE',$p_string);
    + 
    +    
         $nb_result=strlen($p_string2);
         for ($i = 0 ; $i < $nb_result ; $i++ ){
             if (ord($p_string[$i]) < 127 ) {
    diff --git a/include/lib/noalyss_csv.class.php b/include/lib/noalyss_csv.class.php
    index 47a2acdb8..dbd389afd 100644
    --- a/include/lib/noalyss_csv.class.php
    +++ b/include/lib/noalyss_csv.class.php
    @@ -181,7 +181,7 @@ class Noalyss_Csv
         protected function encode($str)
        {
            if ($this->encoding=="utf8") return $str;
    -       if ($this->encoding=="latin1") return utf8_decode ($str);
    +       if ($this->encoding=="latin1") return  iconv('UTF-8','ISO-8859-1//IGNORE',$str); 
            throw new Exception(_("Encodage invalide"));
        }
         /**
    
    From a0d1c26eafe015d78bf35e2465f08430c4f50acf Mon Sep 17 00:00:00 2001
    From: sparkyx 
    Date: Sat, 2 Dec 2023 18:01:53 +0100
    Subject: [PATCH 13/16] Task #2309 mot de passe  fort
    
    ---
     html/ajax_misc.php                      |  15 ++++
     html/install.php                        |  14 ++-
     html/js/noalyss_script.js               |  54 ++++++++++-
     include/ajax/ajax_preference.php        |  29 ++++--
     include/class/noalyss_user.class.php    |   3 +-
     include/lib/ac_common.php               | 115 +++++++++++++++++++++++-
     include/recover.php                     |  21 +----
     include/user.inc.php                    |  36 +++++++-
     include/user_detail.inc.php             |   2 +
     unit-test/include/lib/ac_commonTest.php |  42 +++++++++
     10 files changed, 296 insertions(+), 35 deletions(-)
    
    diff --git a/html/ajax_misc.php b/html/ajax_misc.php
    index 3227b94aa..1ee537040 100644
    --- a/html/ajax_misc.php
    +++ b/html/ajax_misc.php
    @@ -113,7 +113,22 @@ if ($op == "progressBar") {
         return;
     }
     
    +//-------------------------------------------------------------------------------------------
    +// check password
    +//-------------------------------------------------------------------------------------------
    +if ($op=='password_chk') {
    +    $cnt = $http->request("pass");
    +    $result=check_password_strength($cnt)['msg'];
    +    if (count($result) == 0) {
    +        echo json_response(["password" => "ok", "msg" => 0]);
    +    } else {
    +        $str="";
    +        foreach ($result as $item) {$str.=sprintf("
  • %s
  • ",$item);} + echo json_response(["password" => "nok", "msg" => '
      '.$str.'
    ']); + } + return; +} $html = var_export($_REQUEST, true); set_language(); if ( LOGINPUT) diff --git a/html/install.php b/html/install.php index f4c5a90e9..9ec75f0a9 100644 --- a/html/install.php +++ b/html/install.php @@ -233,7 +233,19 @@ if (isset($_POST['save_config'])) { $err++; } - + // check strenght password admin + $passw_error=check_password_strength($cpassword_admin); + if ( count($passw_error['msg'])>0) { + echo '

    '; + echo _("Mot de passe trop faible"); + echo '

    '; + echo '
      '; + foreach ($passw_error['msg'] as $error) { + echo "
    1. ",$error,"
    2. "; + } + echo '
    '; + $err++; + } // check password and admin not containing quote or double quote // if ( strpos($cpassword_admin,'"') !== false diff --git a/html/js/noalyss_script.js b/html/js/noalyss_script.js index 3e6301e22..e78c118f2 100644 --- a/html/js/noalyss_script.js +++ b/html/js/noalyss_script.js @@ -3786,9 +3786,13 @@ function updatePreference() method: "post", parameters: param, onSuccess: function (req) { - var style = req.responseText.evalJSON(); + var answer = req.responseText.evalJSON(); // $('pagestyle').setAttribute('href', style.style); - removeDiv('preference_div'); + if ( answer['psw']=='NOK') { + smoke.alert(answer['msg']); + } else { + removeDiv('preference_div'); + } } }); } catch (e) @@ -4224,4 +4228,50 @@ function event_display_main(p_dossier) { { alert_box(e.message); } +} + +/** + * @brief check if password is strong or not, update a DIV element + * @param p_pass_domid DOM ID of the INPUT element with the password + * @param p_result_domid DOM ID of the element to update + */ +function check_password_strength(p_pass_domid,p_result_domid,details) +{ + try + { + if ( $(p_pass_domid).value=="") { $(p_result_domid).update("");return;} + var queryString= { + 'op':"password_chk" + ,pass:$(p_pass_domid).value + }; + var action = new Ajax.Request( + "ajax_misc.php" , + { + method:'GET', + parameters:queryString, + onFailure:ajax_misc_failure, + onSuccess:function(req){ + remove_waiting_box(); + if (req.responseText == 'NOCONX') { + return; + } + var answer=req.responseJSON; + console.debug(answer); + if (answer['password']=='nok') { + + $(p_pass_domid).setStyle("background-color:red"); + if ( details) { + $(p_result_domid).update(answer['msg']) + } + return; + } + $(p_pass_domid).setStyle("background-color: lightgreen"); + $(p_result_domid).update("") + } + } + ); + }catch( e) + { + alert_box(e.message); + } } \ No newline at end of file diff --git a/include/ajax/ajax_preference.php b/include/ajax/ajax_preference.php index 99a0bdf45..f66c6cb99 100644 --- a/include/ajax/ajax_preference.php +++ b/include/ajax/ajax_preference.php @@ -84,8 +84,9 @@ if ( $action == 'display_form' ) Mot de passe : - + + @@ -321,20 +322,32 @@ if ($action == 'save') $csv_decimal=$http->post("csv_decimal","number"); $csv_encoding=$http->post("csv_encoding"); $firstday=$http->post("selFirstDay","number"); - + $password="OK"; + $msg =""; if (noalyss_strlentrim($pass_1) != 0 && noalyss_strlentrim($pass_2) != 0) { if ( $g_user->save_password($_POST['pass_1'],$pass_2) ) - { $g_user->password_to_session() ; + { + $g_user->password_to_session() ; } else { /** * password not changed - */ - + */ + $password="NOK"; + $msg=""; + if ( $_POST['pass_1'] !== $pass_2) { + $msg = _("Mot de passe ne correspondent pas"); + $msg .="
    "; + } + $a_pass_error=check_password_strength($_POST['pass_1']); + if ( count($a_pass_error['msg']) != 0 ) { + foreach($a_pass_error['msg'] as $pass_error) { + $msg.=$pass_error."
    "; + } + } + } - - } if ( $inside_dossier) { @@ -366,6 +379,6 @@ if ($action == 'save') { $style = "style-classic7.css"; } - json_response(["style"=>$style]); + json_response(["style"=>$style,'psw'=>$password,'msg'=>$msg]); } diff --git a/include/class/noalyss_user.class.php b/include/class/noalyss_user.class.php index 890f7d886..b9b10e2df 100644 --- a/include/class/noalyss_user.class.php +++ b/include/class/noalyss_user.class.php @@ -1635,11 +1635,12 @@ class Noalyss_User * @brief Save the password of the current user * @param string $p_pass1 password (clear) * @param string $p_pass2 for confirming password (clear) + * @see check_password_strength() * @return true : password successfully changed otherwise false */ function save_password($p_pass1, $p_pass2) { - if ($p_pass1==$p_pass2) + if ($p_pass1==$p_pass2 && count(check_password_strength($p_pass1)['msg'])==0) { $repo=new Database(); $l_pass=md5($p_pass1); diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php index dcab67a9f..82ea4dbac 100644 --- a/include/lib/ac_common.php +++ b/include/lib/ac_common.php @@ -1416,10 +1416,13 @@ function remove_divide_zero($p_formula) * @brief Create randomly a string * @param int $p_length length of the generate string */ -function generate_random_string($p_length) +function generate_random_string($p_length,$special=1) { $string=""; - $chaine="abcdefghijklmnpqrstuvwxyABCDEFGHIJKLMNPQRSTUVWXY0123456789*/+-="; + if ($special == 1) + $chaine="abcdefghijklmnpqrstuvwxyABCDEFGHIJKLMNPQRSTUVWXY0123456789*/+-="; + if ($special == 0) + $chaine="abcdefghijklmnpqrstuvwxyABCDEFGHIJKLMNPQRSTUVWXY0123456789"; $microtime=microtime(true)*microtime(true)*100; srand(0); srand((int)$microtime); @@ -1663,3 +1666,111 @@ function MaintenanceMode($p_file) exit; } } + +/** + * @brief returns an double array with the error found and code , if the count is 0 then the password is very string, 5 means it is + * empty ,4 weak, ... the array contains the errors, [msg]=>array message [code] => array of code + * Codes are + * - 1 : too short + * - 2 : missing digit + * - 3 : missing lowercase letter + * - 4 : missing uppercase letter + * - 5 : too many time same letter or symbol.. + * - 6 : missing special char + * + * If the password is strong returns an empty array + * + * @param $password string + * @code + + $error = check_password_strength($password); + if ( count($error['msg']) > 0 ) { + echo "password to weak"; + foreach ($error['msg'] as $item_error) { + echo "error $item_error"; + } + + } else { + echo "OK password strong"; + } + + * @endcode + */ +function check_password_strength($password) { + $errors=array(); + $error_code=array(); + + $len=strlen($password??""); + if ( $len < 8) { + $errors[] = _("mot de passe de 8 lettres minimum"); + $error_code[]=1; + } + + if (!preg_match("#[0-9]+#", $password)) { + $errors[] = _("mot de passe doit inclure au moins un chiffre"); + $error_code[]=2; + } + + if (!preg_match("#[a-z]+#", $password)) { + $errors[] = _("mot de passe doit inclure au moins une minuscule"); + $error_code[]=3; + } + if (!preg_match("#[A-Z]+#", $password)) { + $errors[] = _("mot de passe doit inclure au moins une majuscule"); + $error_code[]=4; + } + + if ( $len > 0 ) { + $cnt_diff=count(count_chars($password,1)); + $ratio_diff=$len/$cnt_diff; + + if ($ratio_diff > 2) { + $errors[] = _("Trop souvent le(s) même(s) symbole(s)"); + $error_code[]=5; + } + $special_char=preg_replace('/[[:alnum:]]/','',$password); + if ( strlen($special_char??"")==0) + { + $errors[] = _("mot de passe doit inclure au moins un caractére spécial '+-/*[...'"); + $error_code[]=6; + + } + } + + return array( 'msg'=>$errors, 'code'=>$error_code); +} +/** + * @brief generate a strong random password + * @param $car int length of the password, minimum 8 + * + */ +function generate_random_password($car):string +{ + $string=""; + $car=($car < 8 )?8:$car; + $max_loop=20;$loop=0; + do + { + $loop++; + $string=""; + $chaine="abcdefghijklmnpqrstuvwxy"; + // srand( (int)microtime()*1020030); + for ($i=0; $i<$car; $i++) + { + $string .= $chaine[rand()%strlen($chaine)]; + } + $chaine="ABCDEFGHIJKLMNPQRSTUVWXY"; + for ($i=0;$i<2;$i++) { + $string[rand()%$car]=$chaine[rand()%strlen($chaine)];; + } + $chaine="0123456789"; + for ($i=0;$i<2;$i++) { + $string[rand()%$car]=$chaine[rand()%strlen($chaine)];; + } + $special_set="+-/*;,.=:&()[]"; + $special_car=$special_set[rand()%strlen($special_set)]; + $string[rand()%$car]=$special_car; + // echo $string."\n"; + }while ( count(check_password_strength($string)['msg'])> 0 && $loop<$max_loop); + return $string; +} \ No newline at end of file diff --git a/include/recover.php b/include/recover.php index 026863f65..ed8d7ad47 100644 --- a/include/recover.php +++ b/include/recover.php @@ -17,27 +17,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // Copyright (2014) Author Dany De Bontridder +require_once NOALYSS_INCLUDE.'/lib/ac_common.php'; if (!defined('RECOVER')) die('Appel direct ne sont pas permis'); define('SIZE_REQUEST', 70); -/** - * @brief generate a random string of char - * @param $car int length of the string - */ -function generate_random($car) -{ - $string=""; - $chaine="abcdefghijklmnpqrstuvwxyABCDEFGHIJKLMNPQRSTUVWXY0123456789"; - srand((double) microtime()*1020030); - for ($i=0; $i<$car; $i++) - { - $string .= $chaine[rand()%strlen($chaine)]; - } - return $string; -} + $http=new HttpInput(); /** * @file @@ -89,8 +76,8 @@ elseif ($action=="send_email") : if ($valid==true): - $request_id=generate_random(SIZE_REQUEST); - $user_password=generate_random(10); + $request_id=generate_random_string(SIZE_REQUEST,special: 0); + $user_password=generate_random_password(10); // exist a valid request for this user ? $exist_request= $cn->get_array("select request , password from recover_pass where use_id=$1 and created_on > now() - interval '12 hours'",[$user_id]); diff --git a/include/user.inc.php b/include/user.inc.php index c714f83e5..dddccd752 100644 --- a/include/user.inc.php +++ b/include/user.inc.php @@ -35,6 +35,7 @@ echo '
    '; if ( isset ($_POST["ADD"]) ) { $cn=new Database(); + $a_result =check_password_strength($_POST['PASS']); $pass5=md5($_POST['PASS']); $new_user=new Noalyss_user($cn,0); $new_user->first_name=$http->post('FNAME'); @@ -45,11 +46,18 @@ if ( isset ($_POST["ADD"]) ) $login=str_replace(" ","",$login); $login=strtolower($login); $new_user->login=$login; - $new_user->setPassword($pass5); + $new_user->email=$http->post('EMAIL',"string",''); if ( trim($login)=="") { alert(_("Le login ne peut pas être vide")); + }elseif (count($a_result['msg']) > 0){ + // password too weak + $msg=''._("Mot de passe inchangé").''; + foreach ($a_result['msg'] as $result ) { + $msg.="$result
    "; + } + alert($msg); } else { @@ -101,8 +109,18 @@ if ($sbaction == "save") } if ( trim($_POST['password'])<>'') { - $UserChange->setPassword(md5($_POST['password'])); - $UserChange->save(); + $a_result =check_password_strength($_POST['password']); + if (count($a_result['msg']) > 0){ + // password too weak + $msg=''._("Mot de passe inchangé").''; + foreach ($a_result['msg'] as $result ) { + $msg.="$result
    "; + } + alert($msg); + } else { + $UserChange->setPassword(md5($_POST['password'])); + $UserChange->save(); + } } else { @@ -168,9 +186,19 @@ if ( isset($_REQUEST['det']) && $sbaction=="") - + + + + + + + + + id == false) $UserChange->load(); $it_pass=new IText('password'); +$it_pass->javascript='onkeyup="check_password_strength(\'password\',\'password_info\',1)"'; $it_pass->value=""; ?>
    @@ -81,6 +82,7 @@ $it_pass->value=""; input();?> + diff --git a/unit-test/include/lib/ac_commonTest.php b/unit-test/include/lib/ac_commonTest.php index 10483089a..91f2ff39c 100644 --- a/unit-test/include/lib/ac_commonTest.php +++ b/unit-test/include/lib/ac_commonTest.php @@ -424,4 +424,46 @@ EOF; $this->assertEquals(strtoupper($expect),strtoupper(preg_replace("/\s+/",'',faxTo('123'))),); } + + /** + * supply data for user password + * @return array[$password, $weakness] 0 means strong password + */ + public function dataCheck_password_strength() + { + return array( + ["AAAAAAA",5] + ,["123456789",3] + ,["Az123456789",1] + ,["",4] + ,["+",4] + ,["AAAA121212abx",2] + ,["Az&123456789",0] + ,["l5F8Cny=",0] + ); + } + /** + * @testDoc test the check_password_strength function + * @dataProvider dataCheck_password_strength() + */ + public function testCheck_password_strength($p_password,$p_cnt) + { + + $count=count(check_password_strength($p_password)['msg']); + $this->assertTrue($count ==$p_cnt,"error : $p_password weak password $count" ); + + } + + public function testGenerate_strong_password() + { + + for ($i = 0; $i < 100; $i++) + { + $pass=generate_random_password(5); + + $this->assertTrue( count(check_password_strength($pass)['msg'])==0 + ,"error cannot generate strong password get $pass"); + } + } + } From cb77460e3b79e5b9e3d1197167871cc7cdf46ac9 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sat, 2 Dec 2023 18:19:29 +0100 Subject: [PATCH 14/16] ergo --- html/css/style-classic7.css | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/html/css/style-classic7.css b/html/css/style-classic7.css index 101a95a02..86376d701 100644 --- a/html/css/style-classic7.css +++ b/html/css/style-classic7.css @@ -912,7 +912,7 @@ a#smallanchorbutton, .smallbutton, a.smallbutton,div.content a.smallbutton .butt font-family: SansationLight; } td.tool { - border: 1px solid gray; + border: 1px grey solid ; background-color: #FFFFFF; border-bottom-width: 2px; text-align:center; @@ -927,7 +927,7 @@ td.tool { } } td.toolselected { - border: 1px solid gray; + border: 1px grey solid; color: #FFFFFF; border-bottom-width: 2px; text-align:center; @@ -2421,7 +2421,7 @@ td.selectedmenu { * go_up */ #go_up { - background-color: gray; + background-color: grey; border:0px; box-shadow: none; color:blue; @@ -3388,3 +3388,11 @@ li.li-active { text-decoration: underline wavy; margin-left:4rem; } +/** + * result of password strength + */ + #info_passid { + position:absolute; + background-color: yellow; + color:red; + } \ No newline at end of file From ff0bc1651eb83039334d8d64e335e2fea05d082f Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sat, 2 Dec 2023 18:20:11 +0100 Subject: [PATCH 15/16] Update link to https://www.noalyss.eu instead of http --- include/class/pdf.class.php | 2 +- include/class/pdf_land.class.php | 2 +- include/class/print_ledger_detail.class.php | 2 +- include/class/print_ledger_detail_item.class.php | 2 +- include/class/print_ledger_fin.class.php | 2 +- include/class/print_ledger_misc.class.php | 2 +- include/class/print_ledger_simple.class.php | 2 +- include/class/print_ledger_simple_without_vat.class.php | 2 +- include/constant.php | 4 ++-- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/class/pdf.class.php b/include/class/pdf.class.php index 167175598..3cc88e39a 100644 --- a/include/class/pdf.class.php +++ b/include/class/pdf.class.php @@ -72,7 +72,7 @@ class PDF extends PDF_Core parent::Cell(0,8,'Date '.$this->date." - Page ".$this->PageNo().'/{nb}',0,0,'C'); parent::Ln(3); // Created by NOALYSS - parent::Cell(0,8,'Created by NOALYSS, online on http://www.noalyss.eu',0,0,'C',false,'http://www.noalyss.eu'); + parent::Cell(0,8,'Created by NOALYSS, online on https://www.noalyss.eu',0,0,'C',false,'https://www.noalyss.eu'); } /** *@brief retrieve the client name and quick_code diff --git a/include/class/pdf_land.class.php b/include/class/pdf_land.class.php index 3cb5d0863..d807330c3 100644 --- a/include/class/pdf_land.class.php +++ b/include/class/pdf_land.class.php @@ -71,7 +71,7 @@ class PDFLand extends PDF $this->Cell(0,8,'Date '.$this->date." - Page ".$this->PageNo().'/{nb}',0,0,'C'); $this->Ln(3); // Created by NOALYSS - $this->Cell(0,8,'Created by NOALYSS, online on http://www.noalyss.eu',0,0,'C',false,'http://www.noalyss.eu'); + $this->Cell(0,8,'Created by NOALYSS, online on https://www.noalyss.eu',0,0,'C',false,'https://www.noalyss.eu'); } } \ No newline at end of file diff --git a/include/class/print_ledger_detail.class.php b/include/class/print_ledger_detail.class.php index 9d6a62126..87bed1772 100644 --- a/include/class/print_ledger_detail.class.php +++ b/include/class/print_ledger_detail.class.php @@ -64,7 +64,7 @@ class Print_Ledger_Detail extends Print_Ledger //Page number $this->Cell(0,8,'Date '.$this->date." - Page ".$this->PageNo().'/{nb}',0,0,'L'); // Created by NOALYSS - $this->Cell(0,8,'Created by NOALYSS, online on http://www.noalyss.eu',0,0,'R',false,'http://www.noalyss.eu'); + $this->Cell(0,8,'Created by NOALYSS, online on https://www.noalyss.eu',0,0,'R',false,'https://www.noalyss.eu'); } diff --git a/include/class/print_ledger_detail_item.class.php b/include/class/print_ledger_detail_item.class.php index a29507128..84399c08c 100644 --- a/include/class/print_ledger_detail_item.class.php +++ b/include/class/print_ledger_detail_item.class.php @@ -75,7 +75,7 @@ class Print_Ledger_Detail_Item extends Print_Ledger //Page number $this->Cell(30,8,'Date '.$this->date." - Page ".$this->PageNo().'/{nb}',0,0,'L'); // Created by NOALYSS - $this->Cell(0,8,'Created by NOALYSS, online on http://www.noalyss.eu',0,0,'R',false,'http://www.noalyss.eu'); + $this->Cell(0,8,'Created by NOALYSS, online on https://www.noalyss.eu',0,0,'R',false,'https://www.noalyss.eu'); } diff --git a/include/class/print_ledger_fin.class.php b/include/class/print_ledger_fin.class.php index cf4827b16..7352df6dc 100644 --- a/include/class/print_ledger_fin.class.php +++ b/include/class/print_ledger_fin.class.php @@ -89,7 +89,7 @@ class Print_Ledger_Financial extends Print_Ledger $this->Cell(0,8,'Date '.$this->date." - Page ".$this->PageNo().'/{nb}',0,0,'C'); $this->Ln(3); // Created by NOALYSS - $this->Cell(0,8,'Created by NOALYSS, online on http://www.noalyss.eu',0,0,'C',false,'http://www.noalyss.eu'); + $this->Cell(0,8,'Created by NOALYSS, online on https://www.noalyss.eu',0,0,'C',false,'https://www.noalyss.eu'); } /** diff --git a/include/class/print_ledger_misc.class.php b/include/class/print_ledger_misc.class.php index 77a7774cb..1cdf29456 100644 --- a/include/class/print_ledger_misc.class.php +++ b/include/class/print_ledger_misc.class.php @@ -62,7 +62,7 @@ class Print_Ledger_Misc extends Print_Ledger $this->Cell(0,6,'Date '.$this->date." - Page ".$this->PageNo().'/{nb}',0,0,'C'); $this->Ln(3); // Created by NOALYSS - $this->Cell(0,6,'Created by NOALYSS, online on http://www.noalyss.eu',0,0,'C',false,'http://www.noalyss.eu'); + $this->Cell(0,6,'Created by NOALYSS, online on https://www.noalyss.eu',0,0,'C',false,'https://www.noalyss.eu'); } /** *@brief print the pdf diff --git a/include/class/print_ledger_simple.class.php b/include/class/print_ledger_simple.class.php index 05ec0f7e6..5ac660b18 100644 --- a/include/class/print_ledger_simple.class.php +++ b/include/class/print_ledger_simple.class.php @@ -243,7 +243,7 @@ class Print_Ledger_Simple extends \Print_Ledger //Page number $this->Cell(0,8,'Date '.$this->date." - Page ".$this->PageNo().'/{nb}',0,0,'L'); // Created by NOALYSS - $this->Cell(0,8,'Created by NOALYSS, online on http://www.noalyss.eu',0,0,'R',false,'http://www.noalyss.eu'); + $this->Cell(0,8,'Created by NOALYSS, online on https://www.noalyss.eu',0,0,'R',false,'https://www.noalyss.eu'); } diff --git a/include/class/print_ledger_simple_without_vat.class.php b/include/class/print_ledger_simple_without_vat.class.php index d2b9668d3..844101732 100644 --- a/include/class/print_ledger_simple_without_vat.class.php +++ b/include/class/print_ledger_simple_without_vat.class.php @@ -135,7 +135,7 @@ class Print_Ledger_Simple_Without_Vat extends Print_Ledger //Page number $this->Cell(0,8,'Date '.$this->date." - Page ".$this->PageNo().'/{nb}',0,0,'L'); // Created by NOALYSS - $this->Cell(0,8,'Created by NOALYSS, online on http://www.noalyss.eu',0,0,'R',false,'http://www.noalyss.eu'); + $this->Cell(0,8,'Created by NOALYSS, online on https://www.noalyss.eu',0,0,'R',false,'https://www.noalyss.eu'); } /** diff --git a/include/constant.php b/include/constant.php index a5fd19ee9..b939750d7 100644 --- a/include/constant.php +++ b/include/constant.php @@ -106,9 +106,9 @@ $version_noalyss = SVNINFO; // If you don't want to be notified of the update if (!defined("SITE_UPDATE")) - define("SITE_UPDATE", 'http://www.noalyss.eu/last_version.txt'); + define("SITE_UPDATE", 'https://www.noalyss.eu/last_version.txt'); if (!defined("SITE_UPDATE_PLUGIN")) - define("SITE_UPDATE_PLUGIN", 'http://www.noalyss.eu/plugin_last_version.txt'); + define("SITE_UPDATE_PLUGIN", 'https://www.noalyss.eu/plugin_last_version.txt'); if (!defined("NOALYSS_PACKAGE_REPOSITORY")) { define("NOALYSS_PACKAGE_REPOSITORY", "https://package.noalyss.eu/"); } From 4f1d7e155a56280d098b863e5267823ac5d465e0 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sat, 2 Dec 2023 18:20:27 +0100 Subject: [PATCH 16/16] Improve documentation --- include/lib/manage_table_sql.class.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/lib/manage_table_sql.class.php b/include/lib/manage_table_sql.class.php index ae181b58c..98951e7e8 100644 --- a/include/lib/manage_table_sql.class.php +++ b/include/lib/manage_table_sql.class.php @@ -75,6 +75,26 @@ * @endcode * + * The afterSaveFct is the function called after saving, the param is the HTML Element + @code PHP +// to redirect : we take the pk_id and redirect to another location + + $obj=$this->get_object_name(); + $url=DRIVINGSCHOOL_URL; + $script=<<