diff --git a/htdocs/blockedlog/admin/registration.php b/htdocs/blockedlog/admin/registration.php index f5eb27e2514..e7572b104c6 100644 --- a/htdocs/blockedlog/admin/registration.php +++ b/htdocs/blockedlog/admin/registration.php @@ -1,7 +1,7 @@ - * Copyright (C) 2017-2018 Laurent Destailleur - * Copyright (C) 2024-2026 Frédéric France +/* Copyright (C) 2017 ATM Consulting + * Copyright (C) 2017-2026 Laurent Destailleur + * Copyright (C) 2024-2026 Frédéric France * Copyright (C) 2026 MDW * * This program is free software; you can redistribute it and/or modify @@ -99,6 +99,25 @@ if ($action == 'update') { $error++; } + $country_code = GETPOST("BLOCKEDLOG_REGISTRATION_COUNTRY_CODE"); + $tmpthirdparty = new Societe($db); + $tmpthirdparty->country_code = $country_code; + $tmpthirdparty->country_id = getCountry($country_code, '3', $db, $langs, 0); + $tmpthirdparty->idprof1 = GETPOST("BLOCKEDLOG_REGISTRATION_IDPROF1"); + + // Check validity of email + if (!isValidEMail(GETPOST("BLOCKEDLOG_REGISTRATION_EMAIL"))) { + setEventMessages($langs->trans("ErrorBadEMail", GETPOST("BLOCKEDLOG_REGISTRATION_EMAIL")), null, 'errors'); + $error++; + } + + // Check validity of prof id + if ($tmpthirdparty->idprof1 && isValidProfIds(1, $tmpthirdparty) <= 0) { + $langs->loadLangs(array("errors", "companies")); + setEventMessages($langs->trans("ErrorBadValueForParameter", $tmpthirdparty->idprof1, $langs->transcountry("ProfId1Short", $tmpthirdparty->country_code)), null, 'errors'); + $error++; + } + $company_name = GETPOST("BLOCKEDLOG_REGISTRATION_NAME"); $company_email = GETPOST("BLOCKEDLOG_REGISTRATION_EMAIL"); $company_country_code = GETPOST("BLOCKEDLOG_REGISTRATION_COUNTRY_CODE"); diff --git a/htdocs/core/lib/profid.lib.php b/htdocs/core/lib/profid.lib.php index 666e81121b0..c2415c9d388 100644 --- a/htdocs/core/lib/profid.lib.php +++ b/htdocs/core/lib/profid.lib.php @@ -246,3 +246,52 @@ function isValidTinForES($str) //Can not be verified return -4; } + + +/** + * Check the validity of a professional identifier according to the properties (country) of the company (siren, siret, ...) + * + * @param int $idprof 1,2,3,4 (Example: 1=siren, 2=siret, 3=naf, 4=rcs/rm) + * @param Societe $thirdparty Object societe + * @return int Return integer <=0 if KO, >0 if OK + */ +function isValidProfIds($idprof, $thirdparty) +{ + $ok = 1; + + if (getDolGlobalString('MAIN_DISABLEPROFIDRULES')) { + return 1; + } + + // Check SIREN + if ($idprof == 1 && $thirdparty->country_code == 'FR' && !isValidSiren($thirdparty->idprof1)) { + return -1; + } + + // Check SIRET + if ($idprof == 2 && $thirdparty->country_code == 'FR' && !isValidSiret($thirdparty->idprof2)) { + return -1; + } + + // Verify CIF/NIF/NIE if pays ES + if ($idprof == 1 && $thirdparty->country_code == 'ES') { + return isValidTinForES($thirdparty->idprof1); + } + + // Verify NIF if country is PT + if ($idprof == 1 && $thirdparty->country_code == 'PT' && !isValidTinForPT($thirdparty->idprof1)) { + return -1; + } + + // Verify NIF if country is DZ + if ($idprof == 1 && $thirdparty->country_code == 'DZ' && !isValidTinForDZ($thirdparty->idprof1)) { + return -1; + } + + // Verify ID Prof 1 if country is BE + if ($idprof == 1 && $thirdparty->country_code == 'BE' && !isValidTinForBE($thirdparty->idprof1)) { + return -1; + } + + return $ok; +} diff --git a/htdocs/societe/canvas/company/actions_card_company.class.php b/htdocs/societe/canvas/company/actions_card_company.class.php index ae1adbdee4b..bc9da5ce3b6 100644 --- a/htdocs/societe/canvas/company/actions_card_company.class.php +++ b/htdocs/societe/canvas/company/actions_card_company.class.php @@ -150,7 +150,7 @@ class ActionsCardCompany extends ActionsCardCommon for ($i = 1; $i <= 4; $i++) { $this->tpl['langprofid'.$i] = $langs->transcountry('ProfId'.$i, $this->object->country_code); - $this->tpl['checkprofid'.$i] = $this->object->id_prof_check($i, $this->object); + $this->tpl['checkprofid'.$i] = $this->object->id_prof_check($i); $this->tpl['urlprofid'.$i] = $this->object->id_prof_url($i, $this->object); } diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 30e5c20c047..9b9207aa2b9 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -3112,8 +3112,8 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($canvasdisplayactio print ''.$idprof.''; $key = 'idprof'.$i; print dol_print_profids($object->$key, 'ProfId'.$i, $object->country_code, 1); - if ($object->$key) { - if ($object->id_prof_check($i, $object) > 0) { + if (!empty($object->$key)) { + if ($object->id_prof_check($i) > 0) { $profidurl = $object->id_prof_url($i, $object); if (!empty($profidurl)) { print '   '.$profidurl; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 75400fef6d7..f4a051407d5 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -4271,67 +4271,29 @@ class Societe extends CommonObject // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Check the validity of a professional identifier according to the country of the company (siren, siret, ...) + * Check the validity of a professional identifier according to the properties (country) of the thirdparty (siren, siret, ...) * * @param int $idprof 1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm) - * @param Societe $soc Object societe * @return int Return integer <=0 if KO, >0 if OK - * TODO better to have this in a lib than into a business class */ - public function id_prof_check($idprof, $soc) + public function id_prof_check($idprof) { // phpcs:enable - $ok = 1; - - if (getDolGlobalString('MAIN_DISABLEPROFIDRULES')) { - return 1; - } - - // load the library necessary to check the professional identifiers + // Load the library necessary to check the professional identifiers require_once DOL_DOCUMENT_ROOT.'/core/lib/profid.lib.php'; - // Check SIREN - if ($idprof == 1 && $soc->country_code == 'FR' && !isValidSiren($this->idprof1)) { - return -1; - } - - // Check SIRET - if ($idprof == 2 && $soc->country_code == 'FR' && !isValidSiret($this->idprof2)) { - return -1; - } - - //Verify CIF/NIF/NIE if pays ES - if ($idprof == 1 && $soc->country_code == 'ES') { - return isValidTinForES($this->idprof1); - } - - //Verify NIF if country is PT - if ($idprof == 1 && $soc->country_code == 'PT' && !isValidTinForPT($this->idprof1)) { - return -1; - } - - //Verify NIF if country is DZ - if ($idprof == 1 && $soc->country_code == 'DZ' && !isValidTinForDZ($this->idprof1)) { - return -1; - } - - //Verify ID Prof 1 if country is BE - if ($idprof == 1 && $soc->country_code == 'BE' && !isValidTinForBE($this->idprof1)) { - return -1; - } - - return $ok; + return isValidProfIds($idprof, $this); } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Return an url to check online a professional id or empty string + * Return an url to check online a professional id or empty string * - * @param int $idprof 1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm) - * @param Societe $thirdparty Object thirdparty - * @return string Url or empty string if no URL known - * TODO better in a lib than into business class + * @param int $idprof 1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm) + * @param Societe $thirdparty Object thirdparty + * @return string Url or empty string if no URL known + * TODO better to have this in the lib profid.lib.php rather than into this business class */ public function id_prof_url($idprof, $thirdparty) { diff --git a/test/phpunit/SocieteTest.php b/test/phpunit/SocieteTest.php index 14e2ddb90a3..9b627fa6d07 100644 --- a/test/phpunit/SocieteTest.php +++ b/test/phpunit/SocieteTest.php @@ -225,10 +225,10 @@ class SocieteTest extends CommonClassTest $localobject->country_code = 'FR'; $localobject->idprof1 = 493861496; $localobject->idprof2 = 49386149600021; - $result = $localobject->id_prof_check(1, $localobject); // Must be > 0 + $result = $localobject->id_prof_check(1); // Must be > 0 print __METHOD__." OK FR idprof1 result=".$result."\n"; $this->assertGreaterThanOrEqual(1, $result); - $result = $localobject->id_prof_check(2, $localobject); // Must be > 0 + $result = $localobject->id_prof_check(2); // Must be > 0 print __METHOD__." OK FR idprof2 result=".$result."\n"; $this->assertGreaterThanOrEqual(1, $result); @@ -236,17 +236,17 @@ class SocieteTest extends CommonClassTest $localobject->country_code = 'FR'; $localobject->idprof1 = 'id1ko'; $localobject->idprof2 = 'id2ko'; - $result = $localobject->id_prof_check(1, $localobject); // Must be <= 0 + $result = $localobject->id_prof_check(1); // Must be <= 0 print __METHOD__." KO FR idprof1 result=".$result."\n"; $this->assertLessThan(1, $result); - $result = $localobject->id_prof_check(2, $localobject); // Must be <= 0 + $result = $localobject->id_prof_check(2); // Must be <= 0 print __METHOD__." KO FR idprof2 result=".$result."\n"; $this->assertLessThan(1, $result); // KO ES $localobject->country_code = 'ES'; $localobject->idprof1 = 'id1ko'; - $result = $localobject->id_prof_check(1, $localobject); // Must be <= 0 + $result = $localobject->id_prof_check(1); // Must be <= 0 print __METHOD__." KO ES idprof1 result=".$result."\n"; $this->assertLessThan(1, $result); @@ -254,10 +254,10 @@ class SocieteTest extends CommonClassTest $localobject->country_code = 'AR'; $localobject->idprof1 = 'id1ko'; $localobject->idprof2 = 'id2ko'; - $result = $localobject->id_prof_check(1, $localobject); // Must be > 0 + $result = $localobject->id_prof_check(1); // Must be > 0 print __METHOD__." OK AR idprof1 result=".$result."\n"; $this->assertGreaterThanOrEqual(0, $result); - $result = $localobject->id_prof_check(2, $localobject); // Must be > 0 + $result = $localobject->id_prof_check(2); // Must be > 0 print __METHOD__." OK AR idprof2 result=".$result."\n"; $this->assertGreaterThanOrEqual(1, $result);