From 52e2e71b00c8d630c9bbb7bd45823e7c7679e567 Mon Sep 17 00:00:00 2001 From: FLIO Date: Wed, 21 Dec 2022 11:57:07 +0100 Subject: [PATCH 01/10] Fix(scrutinizer) --- htdocs/public/project/new.php | 68 +++++++++++++++++------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/htdocs/public/project/new.php b/htdocs/public/project/new.php index 7603c046006..62951407fd1 100644 --- a/htdocs/public/project/new.php +++ b/htdocs/public/project/new.php @@ -338,50 +338,50 @@ if (empty($reshook) && $action == 'add') { require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; $object = $proj; - if ($object->email) { - $subject = ''; - $msg = ''; + // if ($object->email) { + // $subject = ''; + // $msg = ''; - // Send subscription email - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; - $formmail = new FormMail($db); - // Set output language - $outputlangs = new Translate('', $conf); - $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang); - // Load traductions files required by page - $outputlangs->loadLangs(array("main", "members", "projects")); - // Get email content from template - $arraydefaultmessage = null; - $labeltouse = $conf->global->PROJECT_EMAIL_TEMPLATE_AUTOLEAD; + // // Send subscription email + // include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + // $formmail = new FormMail($db); + // // Set output language + // $outputlangs = new Translate('', $conf); + // $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang); + // // Load traductions files required by page + // $outputlangs->loadLangs(array("main", "members", "projects")); + // // Get email content from template + // $arraydefaultmessage = null; + // $labeltouse = $conf->global->PROJECT_EMAIL_TEMPLATE_AUTOLEAD; - if (!empty($labeltouse)) { - $arraydefaultmessage = $formmail->getEMailTemplate($db, 'project', $user, $outputlangs, 0, 1, $labeltouse); - } + // if (!empty($labeltouse)) { + // $arraydefaultmessage = $formmail->getEMailTemplate($db, 'project', $user, $outputlangs, 0, 1, $labeltouse); + // } - if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { - $subject = $arraydefaultmessage->topic; - $msg = $arraydefaultmessage->content; - } - if (empty($labeltosue)) { - $labeltouse = '['.$mysoc->name.'] '.$langs->trans("YourMessage"); - $msg = $langs->trans("YourMessageHasBeenReceived"); - } + // if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { + // $subject = $arraydefaultmessage->topic; + // $msg = $arraydefaultmessage->content; + // } + // if (empty($labeltosue)) { + // $labeltouse = '['.$mysoc->name.'] '.$langs->trans("YourMessage"); + // $msg = $langs->trans("YourMessageHasBeenReceived"); + // } - $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); - complete_substitutions_array($substitutionarray, $outputlangs, $object); - $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); - $texttosend = make_substitutions($msg, $substitutionarray, $outputlangs); + // $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); + // complete_substitutions_array($substitutionarray, $outputlangs, $object); + // $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); + // $texttosend = make_substitutions($msg, $substitutionarray, $outputlangs); - if ($subjecttosend && $texttosend) { - $moreinheader = 'X-Dolibarr-Info: send_an_email by public/lead/new.php'."\r\n"; + // if ($subjecttosend && $texttosend) { + // $moreinheader = 'X-Dolibarr-Info: send_an_email by public/lead/new.php'."\r\n"; - $result = $object->send_an_email($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader); - } + // $result = $object->send_an_email($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader); + // } /*if ($result < 0) { $error++; setEventMessages($object->error, $object->errors, 'errors'); }*/ - } + // } if (!empty($backtopage)) { $urlback = $backtopage; From c4521efa57db526986f80197afda81c568a86db8 Mon Sep 17 00:00:00 2001 From: FLIO Date: Mon, 23 Jan 2023 16:31:14 +0100 Subject: [PATCH 02/10] fix(qodana) fix function comment bad return --- htdocs/fichinter/class/api_interventions.class.php | 4 ++-- htdocs/fourn/class/fournisseur.product.class.php | 4 ++-- htdocs/product/class/product.class.php | 4 ++-- .../class/price_global_variable_updater.class.php | 4 ++-- htdocs/product/stock/class/entrepot.class.php | 4 ++-- htdocs/reception/class/api_receptions.class.php | 4 ++-- htdocs/societe/class/api_thirdparties.class.php | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/htdocs/fichinter/class/api_interventions.class.php b/htdocs/fichinter/class/api_interventions.class.php index f96dc3d6aa7..6cd6595432d 100644 --- a/htdocs/fichinter/class/api_interventions.class.php +++ b/htdocs/fichinter/class/api_interventions.class.php @@ -341,7 +341,7 @@ class Interventions extends DolibarrApi * * @url POST {id}/validate * - * @return array + * @return Object */ public function validate($id, $notrigger = 0) { @@ -377,7 +377,7 @@ class Interventions extends DolibarrApi * * @url POST {id}/close * - * @return array + * @return Object */ public function closeFichinter($id) { diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index fa1706a523a..1d764cee490 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -673,7 +673,7 @@ class ProductFournisseur extends Product * @param int $limit Limit * @param int $offset Offset * @param int $socid Filter on a third party id - * @return array Array of ProductFournisseur with new properties to define supplier price + * @return array|int Array of ProductFournisseur with new properties to define supplier price */ public function list_product_fournisseur_price($prodid, $sortfield = '', $sortorder = '', $limit = 0, $offset = 0, $socid = 0) { @@ -1042,7 +1042,7 @@ class ProductFournisseur extends Product * @param string $sortorder Sort order * @param int $limit Limit * @param int $offset Offset - * @return array Array of Log prices + * @return array|int Array of Log prices */ public function listProductFournisseurPriceLog($product_fourn_price_id, $sortfield = '', $sortorder = '', $limit = 0, $offset = 0) { diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 11133d6a6e0..e1251efe8f7 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -4829,7 +4829,7 @@ class Product extends CommonObject /** * Return all parent products for current product (first level only) * - * @return array Array of product + * @return array|int Array of product * @see hasFatherOrChild() */ public function getFather() @@ -4871,7 +4871,7 @@ class Product extends CommonObject * @param int $firstlevelonly Return only direct child * @param int $level Level of recursing call (start to 1) * @param array $parents Array of all parents of $id - * @return array Return array(prodid=>array(0=prodid, 1=>qty, 2=>product type, 3=>label, 4=>incdec, 5=>product ref) + * @return array|int Return array(prodid=>array(0=prodid, 1=>qty, 2=>product type, 3=>label, 4=>incdec, 5=>product ref) */ public function getChildsArbo($id, $firstlevelonly = 0, $level = 1, $parents = array()) { diff --git a/htdocs/product/dynamic_price/class/price_global_variable_updater.class.php b/htdocs/product/dynamic_price/class/price_global_variable_updater.class.php index 317bc7fb5fd..d43a2e3bf56 100644 --- a/htdocs/product/dynamic_price/class/price_global_variable_updater.class.php +++ b/htdocs/product/dynamic_price/class/price_global_variable_updater.class.php @@ -367,7 +367,7 @@ class PriceGlobalVariableUpdater /** * List all price global variables * - * @return array Array of price global variable updaters + * @return array|int Array of price global variable updaters */ public function listUpdaters() { @@ -404,7 +404,7 @@ class PriceGlobalVariableUpdater /** * List all updaters which need to be processed * - * @return array Array of price global variable updaters + * @return array|int Array of price global variable updaters */ public function listPendingUpdaters() { diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index 6e09a81eb7f..d537d7d06cf 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -564,7 +564,7 @@ class Entrepot extends CommonObject /** * Return number of unique different product into a warehouse * - * @return Array Array('nb'=>Nb, 'value'=>Value) + * @return array|int Array('nb'=>Nb, 'value'=>Value) */ public function nb_different_products() { @@ -595,7 +595,7 @@ class Entrepot extends CommonObject /** * Return stock and value of warehosue * - * @return Array Array('nb'=>Nb, 'value'=>Value) + * @return array|int Array('nb'=>Nb, 'value'=>Value) */ public function nb_products() { diff --git a/htdocs/reception/class/api_receptions.class.php b/htdocs/reception/class/api_receptions.class.php index 473650161e2..68da64fcc36 100644 --- a/htdocs/reception/class/api_receptions.class.php +++ b/htdocs/reception/class/api_receptions.class.php @@ -502,7 +502,7 @@ class Receptions extends DolibarrApi * * @url POST {id}/validate * - * @return array + * @return Object * \todo An error 403 is returned if the request has an empty body. * Error message: "Forbidden: Content type `text/plain` is not supported." * Workaround: send this in the body @@ -630,7 +630,7 @@ class Receptions extends DolibarrApi * * @url POST {id}/close * - * @return int + * @return Object */ public function close($id, $notrigger = 0) { diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index c4781c0df6a..f81fd066a2c 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -524,7 +524,7 @@ class Thirdparties extends DolibarrApi * Delete thirdparty * * @param int $id Thirdparty ID - * @return integer + * @return array */ public function delete($id) { @@ -1354,7 +1354,7 @@ class Thirdparties extends DolibarrApi * @param int $id Thirdparty id * @param int $companybankid Companybank id * @param string $model Model of document to generate - * @return void + * @return array * * @url GET {id}/generateBankAccountDocument/{companybankid}/{model} */ From 02f4f470830283fbf5dd7a6690fa4ca51bdab3fe Mon Sep 17 00:00:00 2001 From: FLIO Date: Tue, 24 Jan 2023 23:11:28 +0100 Subject: [PATCH 03/10] fix (qodana) Return value type is not compatible with declared --- htdocs/bom/class/api_boms.class.php | 2 +- htdocs/core/class/commonobject.class.php | 2 +- htdocs/core/db/sqlite3.class.php | 2 +- htdocs/don/class/api_donations.class.php | 2 +- htdocs/ecm/class/ecmdirectory.class.php | 2 +- htdocs/expedition/class/api_shipments.class.php | 4 ++-- htdocs/supplier_proposal/class/supplier_proposal.class.php | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/bom/class/api_boms.class.php b/htdocs/bom/class/api_boms.class.php index fb7d175a229..c2df69b9012 100644 --- a/htdocs/bom/class/api_boms.class.php +++ b/htdocs/bom/class/api_boms.class.php @@ -365,7 +365,7 @@ class Boms extends DolibarrApi * * @url PUT {id}/lines/{lineid} * - * @return array|bool + * @return object|bool */ public function putLine($id, $lineid, $request_data = null) { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 37f250bf92f..7df0c4efe9c 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4277,7 +4277,7 @@ abstract class CommonObject * @param string $field_select name of field we need to get a list * @param string $field_where name of field of object we need to get linked items * @param string $table_element name of association table - * @return array Array of record + * @return array|int Array of record, -1 if empty */ public static function getAllItemsLinkedByObjectID($fk_object_where, $field_select, $field_where, $table_element) { diff --git a/htdocs/core/db/sqlite3.class.php b/htdocs/core/db/sqlite3.class.php index 8c10c26d464..40d0f10baa8 100644 --- a/htdocs/core/db/sqlite3.class.php +++ b/htdocs/core/db/sqlite3.class.php @@ -316,7 +316,7 @@ class DoliDBSqlite3 extends DoliDB * @param string $passwd password * @param string $name name of database (not used for mysql, used for pgsql) * @param integer $port Port of database server - * @return SQLite3 Database access handler + * @return SQLite3|string Database access handler * @see close() */ public function connect($host, $login, $passwd, $name, $port = 0) diff --git a/htdocs/don/class/api_donations.class.php b/htdocs/don/class/api_donations.class.php index f9af0568bf0..eee681cea7b 100644 --- a/htdocs/don/class/api_donations.class.php +++ b/htdocs/don/class/api_donations.class.php @@ -295,7 +295,7 @@ class Donations extends DolibarrApi * @throws RestException 404 * @throws RestException 500 System error * - * @return array + * @return object */ public function validate($id, $idwarehouse = 0, $notrigger = 0) { diff --git a/htdocs/ecm/class/ecmdirectory.class.php b/htdocs/ecm/class/ecmdirectory.class.php index fb9b2a35dd0..21a43565a25 100644 --- a/htdocs/ecm/class/ecmdirectory.class.php +++ b/htdocs/ecm/class/ecmdirectory.class.php @@ -633,7 +633,7 @@ class EcmDirectory extends CommonObject * level Level of line (Added by buildPathFromId call) * * @param int $force Force reload of full arbo even if already loaded in cache $this->cats - * @return array Tableau de array + * @return array|int Tableau de array if OK, -1 if KO */ public function get_full_arbo($force = 0) { diff --git a/htdocs/expedition/class/api_shipments.class.php b/htdocs/expedition/class/api_shipments.class.php index 357683ef35a..e5e1f584f5e 100644 --- a/htdocs/expedition/class/api_shipments.class.php +++ b/htdocs/expedition/class/api_shipments.class.php @@ -502,7 +502,7 @@ class Shipments extends DolibarrApi * * @url POST {id}/validate * - * @return array + * @return object * \todo An error 403 is returned if the request has an empty body. * Error message: "Forbidden: Content type `text/plain` is not supported." * Workaround: send this in the body @@ -630,7 +630,7 @@ class Shipments extends DolibarrApi * * @url POST {id}/close * - * @return int + * @return object */ public function close($id, $notrigger = 0) { diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 1f95e3de5fd..1604cf928e7 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -1942,7 +1942,7 @@ class SupplierProposal extends CommonObject * @param int $offset For pagination * @param string $sortfield Sort criteria * @param string $sortorder Sort order - * @return int -1 if KO, array with result if OK + * @return array|int -1 if KO, array with result if OK */ public function liste_array($shortlist = 0, $draft = 0, $notcurrentuser = 0, $socid = 0, $limit = 0, $offset = 0, $sortfield = 'p.datec', $sortorder = 'DESC') { @@ -2223,7 +2223,7 @@ class SupplierProposal extends CommonObject * * @param User $user Object user * @param int $mode "opened" for askprice to close, "signed" for proposal to invoice - * @return int <0 if KO, >0 if OK + * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK */ public function load_board($user, $mode) { From 4c5bcd02b7e805952e8c5f1ce079432ab9142b14 Mon Sep 17 00:00:00 2001 From: FLIO Date: Wed, 1 Feb 2023 23:31:39 +0100 Subject: [PATCH 04/10] fix (scrutinizer) remove comments and create function send an email TODO --- htdocs/projet/class/project.class.php | 24 +++++++++ htdocs/public/project/new.php | 71 +++++++++++++-------------- 2 files changed, 59 insertions(+), 36 deletions(-) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 79ea13dcd40..b5af4af49d9 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -2313,4 +2313,28 @@ class Project extends CommonObject $this->lines = $taskstatic->getTasksArray(0, $user, $this->id, 0, 0, '', '-1', '', 0, 0, array(), 0, array(), 0, $loadRoleMode); } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Function sending an email to the current member with the text supplied in parameter. + * + * @param string $text Content of message (not html entities encoded) + * @param string $subject Subject of message + * @param array $filename_list Array of attached files + * @param array $mimetype_list Array of mime types of attached files + * @param array $mimefilename_list Array of public names of attached files + * @param string $addr_cc Email cc + * @param string $addr_bcc Email bcc + * @param int $deliveryreceipt Ask a delivery receipt + * @param int $msgishtml 1=String IS already html, 0=String IS NOT html, -1=Unknown need autodetection + * @param string $errors_to erros to + * @param string $moreinheader Add more html headers + * @return int <0 if KO, >0 if OK + */ + public function send_an_email($text, $subject, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $addr_cc = "", $addr_bcc = "", $deliveryreceipt = 0, $msgishtml = -1, $errors_to = '', $moreinheader = '') + { + // phpcs:enable + global $conf, $langs; + // TODO EMAIL + } } diff --git a/htdocs/public/project/new.php b/htdocs/public/project/new.php index dd5424c4f5f..a453e6e0b1e 100644 --- a/htdocs/public/project/new.php +++ b/htdocs/public/project/new.php @@ -334,51 +334,50 @@ if (empty($reshook) && $action == 'add') { if ($result > 0) { require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; $object = $proj; + + if ($object->email) { + $subject = ''; + $msg = ''; - // if ($object->email) { - // $subject = ''; - // $msg = ''; + // Send subscription email + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + $formmail = new FormMail($db); + // Set output language + $outputlangs = new Translate('', $conf); + $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang); + // Load traductions files required by page + $outputlangs->loadLangs(array("main", "members", "projects")); + // Get email content from template + $arraydefaultmessage = null; + $labeltouse = $conf->global->PROJECT_EMAIL_TEMPLATE_AUTOLEAD; - // // Send subscription email - // include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; - // $formmail = new FormMail($db); - // // Set output language - // $outputlangs = new Translate('', $conf); - // $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang); - // // Load traductions files required by page - // $outputlangs->loadLangs(array("main", "members", "projects")); - // // Get email content from template - // $arraydefaultmessage = null; - // $labeltouse = $conf->global->PROJECT_EMAIL_TEMPLATE_AUTOLEAD; + if (!empty($labeltouse)) { + $arraydefaultmessage = $formmail->getEMailTemplate($db, 'project', $user, $outputlangs, 0, 1, $labeltouse); + } - // if (!empty($labeltouse)) { - // $arraydefaultmessage = $formmail->getEMailTemplate($db, 'project', $user, $outputlangs, 0, 1, $labeltouse); - // } + if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { + $subject = $arraydefaultmessage->topic; + $msg = $arraydefaultmessage->content; + } + if (empty($labeltosue)) { + $labeltouse = '['.$mysoc->name.'] '.$langs->trans("YourMessage"); + $msg = $langs->trans("YourMessageHasBeenReceived"); + } - // if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { - // $subject = $arraydefaultmessage->topic; - // $msg = $arraydefaultmessage->content; - // } - // if (empty($labeltosue)) { - // $labeltouse = '['.$mysoc->name.'] '.$langs->trans("YourMessage"); - // $msg = $langs->trans("YourMessageHasBeenReceived"); - // } + $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); + complete_substitutions_array($substitutionarray, $outputlangs, $object); + $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); + $texttosend = make_substitutions($msg, $substitutionarray, $outputlangs); + if ($subjecttosend && $texttosend) { + $moreinheader = 'X-Dolibarr-Info: send_an_email by public/lead/new.php'."\r\n"; - // $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); - // complete_substitutions_array($substitutionarray, $outputlangs, $object); - // $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); - // $texttosend = make_substitutions($msg, $substitutionarray, $outputlangs); - - // if ($subjecttosend && $texttosend) { - // $moreinheader = 'X-Dolibarr-Info: send_an_email by public/lead/new.php'."\r\n"; - - // $result = $object->send_an_email($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader); - // } + $result = $object->send_an_email($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader); + } /*if ($result < 0) { $error++; setEventMessages($object->error, $object->errors, 'errors'); }*/ - // } + } if (!empty($backtopage)) { $urlback = $backtopage; From cc0d9b27f2b3dabc65b3088ef8fc648357d9c9bc Mon Sep 17 00:00:00 2001 From: FLIO Date: Wed, 1 Feb 2023 23:31:53 +0100 Subject: [PATCH 05/10] fix (scrutinizer) remove comments and create function send an email TODO --- htdocs/public/project/new.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/public/project/new.php b/htdocs/public/project/new.php index a453e6e0b1e..726a318c99f 100644 --- a/htdocs/public/project/new.php +++ b/htdocs/public/project/new.php @@ -334,7 +334,7 @@ if (empty($reshook) && $action == 'add') { if ($result > 0) { require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; $object = $proj; - + if ($object->email) { $subject = ''; $msg = ''; From 8f4ab293e0cbf821accfabc29c188b26ad6d5507 Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Fri, 3 Feb 2023 15:23:50 +0100 Subject: [PATCH 06/10] NEW fonctionality delete right manually on modulebuilder --- htdocs/modulebuilder/index.php | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 93550e2c928..28183dfd571 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1942,6 +1942,70 @@ if ($dirins && $action == 'generatepackage') { } +// Delete permission +if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('permskey', 'int')) { + $error = 0; + // load class and check if right exist + $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; + dol_include_once($pathtofile); + $class = 'mod'.$module; + if (class_exists($class)) { + try { + $moduleobj = new $class($db); + } catch (Exception $e) { + $error++; + dol_print_error($db, $e->getMessage()); + } + } + + $permissions = $moduleobj->rights; + $key = (int) GETPOST('permskey', 'int')-1; + //get permission want to delete from permissions array + $x1 = $permissions[$key][1]; + $x2 = $permissions[$key][4]; + $x3 = $permissions[$key][5]; + //prepare right want to delete + $rightTodelete = " + \$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); + \$this->rights[\$r][1] = '$x1'; + \$this->rights[\$r][4] = '$x2'; + \$this->rights[\$r][5] = '$x3'; + \$r++; + "; + + + $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php'; + $check = dolReplaceInFile($moduledescriptorfile, array($rightTodelete => ''."\n")); + if ($check > 0) { + //check if all permissions of object was deleted + $permsForObj = array(); + foreach ($permissions as $perms) { + $permsForObj[] = $perms[4]; + } + $permsForObj = array_count_values($permsForObj); + //var_dump($permsForObj[$permissions[$key][4]]);exit; + if ($permsForObj[$permissions[$key][4]] == 1) { + $delObjStart = dolReplaceInFile($moduledescriptorfile, array('/*'.strtoupper($permissions[$key][4].'*/') => '','/*END '.strtoupper($permissions[$key][4].'*/') => '')); + } + } + if (!$error) { + // check if module is enabled + if (isModEnabled(strtolower($module))) { + $result = unActivateModule(strtolower($module)); + dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity); + if ($result) { + setEventMessages($result, null, 'errors'); + } + header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module); + setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null); + setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings'); + } else { + header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module); + setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null); + exit; + } + } +} // Save file if ($action == 'savefile' && empty($cancel)) { $relofcustom = basename($dirins); From eeb792ba0e62d8dbc4bd074fbcee668551a6966e Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Fri, 3 Feb 2023 15:43:18 +0100 Subject: [PATCH 07/10] fix error --- htdocs/modulebuilder/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 28183dfd571..b1ee4975059 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1975,7 +1975,7 @@ if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('p $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php'; - $check = dolReplaceInFile($moduledescriptorfile, array($rightTodelete => ''."\n")); + $check = dolReplaceInFile($moduledescriptorfile, array($rightTodelete => ''."\n\t\t")); if ($check > 0) { //check if all permissions of object was deleted $permsForObj = array(); From 23d212d9dce614e0ae9b53835cf2f189b6fc1c50 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 7 Feb 2023 13:58:29 +0000 Subject: [PATCH 08/10] Fixing style errors. --- htdocs/modulebuilder/index.php | 241 ++++++++++++++++----------------- 1 file changed, 118 insertions(+), 123 deletions(-) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 758aaaa487c..704870294f0 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1950,31 +1950,31 @@ if ($dirins && $action == 'addright' && !empty($module) && empty($cancel)) { dol_include_once($pathtofile); $class = 'mod'.$module; if (class_exists($class)) { - try { - $moduleobj = new $class($db); - } catch (Exception $e) { - $error++; - dol_print_error($db, $e->getMessage()); - } - } + try { + $moduleobj = new $class($db); + } catch (Exception $e) { + $error++; + dol_print_error($db, $e->getMessage()); + } + } - // verify informations entred - if (!GETPOST('label','alpha')) { + // verify informations entred + if (!GETPOST('label', 'alpha')) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors'); } - if (!GETPOST('permissionObj','alpha')) { + if (!GETPOST('permissionObj', 'alpha')) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rights")), null, 'errors'); } - + $label = GETPOST('label', 'alpha'); - $objectForPerms = strtolower(GETPOST('permissionObj','alpha')); + $objectForPerms = strtolower(GETPOST('permissionObj', 'alpha')); $crud = GETPOST('crud', 'alpha'); // check coherence between crud and label - if ($label == "Read objects of $module" && $crud != "read"){ - $crud = "read"; + if ($label == "Read objects of $module" && $crud != "read") { + $crud = "read"; $label == "Read objects of $module"; } if ($label == "Create/Update objects of $module" && $crud != "write") { @@ -1994,39 +1994,39 @@ if ($dirins && $action == 'addright' && !empty($module) && empty($cancel)) { $existRight = 0; $allObject = array(); - - - for ($i =0; $itrans("ErrorExistingPermission", $langs->transnoentities($label), $langs->transnoentities($objectForPerms)), null, 'errors'); - } + } } // if not found permission for the object - if (!in_array($objectForPerms,array_unique($allObject))){ + if (!in_array($objectForPerms, array_unique($allObject))) { $firstRight++; $existRight = 0; } if (!$error) { - if (isModEnabled(strtolower($module))){ + if (isModEnabled(strtolower($module))) { $result = unActivateModule(strtolower($module)); dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity); if ($result) { setEventMessages($result, null, 'errors'); } header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module); - setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null,'warnings'); + setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings'); } //prepare stirng to add $rightToAdd = " @@ -2037,24 +2037,22 @@ if ($dirins && $action == 'addright' && !empty($module) && empty($cancel)) { \$r++; "; $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php'; - if (!$existRight){ + if (!$existRight) { //var_dump(1);exit; dolReplaceInFile($moduledescriptorfile, array('/*END '.strtoupper($objectForPerms).'*/' => $rightToAdd.'/*END '.strtoupper($objectForPerms).'*/')); setEventMessages($langs->trans('PermissionAddedSuccesfuly'), null); } - if ($firstRight){ + if ($firstRight) { //var_dump(array('/* END MODULEBUILDER PERMISSIONS */' => '/*'.strtoupper($objectForPerms).'*/'.$rightToAdd."/*END ".strtoupper($objectForPerms).'*/'."\n\t\t"."/* END MODULEBUILDER PERMISSIONS */"));exit; dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER PERMISSIONS */' => '/*'.strtoupper($objectForPerms).'*/'.$rightToAdd."/*END ".strtoupper($objectForPerms).'*/'."\n\t\t"."/* END MODULEBUILDER PERMISSIONS */")); setEventMessages($langs->trans('PermissionAddedSuccesfuly'), null); } - } header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module); exit; - } -// Delete permission +// Delete permission if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('permskey', 'int')) { $error = 0; // load class and check if right exist @@ -2062,16 +2060,16 @@ if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('p dol_include_once($pathtofile); $class = 'mod'.$module; if (class_exists($class)) { - try { - $moduleobj = new $class($db); - } catch (Exception $e) { - $error++; - dol_print_error($db, $e->getMessage()); - } - } - + try { + $moduleobj = new $class($db); + } catch (Exception $e) { + $error++; + dol_print_error($db, $e->getMessage()); + } + } + $permissions = $moduleobj->rights; - $key = (int)GETPOST('permskey','int')-1; + $key = (int) GETPOST('permskey', 'int')-1; //get permission want to delete from permissions array $x1 = $permissions[$key][1]; $x2 = $permissions[$key][4]; @@ -2084,41 +2082,40 @@ if ($dirins && $action == 'confirm_deleteright' && !empty($module) && GETPOST('p \$this->rights[\$r][5] = '$x3'; \$r++; "; - + $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php'; $check = dolReplaceInFile($moduledescriptorfile, array($rightTodelete => ''."\n\t\t")); - if ($check > 0) { - //check if all permissions of object was deleted - $permsForObj = array(); - foreach($permissions as $perms){ - $permsForObj[] = $perms[4]; - } - $permsForObj = array_count_values($permsForObj); - //var_dump($permsForObj[$permissions[$key][4]]);exit; - if($permsForObj[$permissions[$key][4]] == 1) { - $delObjStart = dolReplaceInFile($moduledescriptorfile, array('/*'.strtoupper($permissions[$key][4].'*/') => '','/*END '.strtoupper($permissions[$key][4].'*/') => '')); - } - } - if(!$error){ - // check if module is enabled - if (isModEnabled(strtolower($module))){ - $result = unActivateModule(strtolower($module)); - dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity); - if ($result) { - setEventMessages($result, null, 'errors'); - } - header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module); - setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null); - setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null,'warnings'); - exit; - } - else{ - header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module); - setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null); - exit; - } + if ($check > 0) { + //check if all permissions of object was deleted + $permsForObj = array(); + foreach ($permissions as $perms) { + $permsForObj[] = $perms[4]; } + $permsForObj = array_count_values($permsForObj); + //var_dump($permsForObj[$permissions[$key][4]]);exit; + if ($permsForObj[$permissions[$key][4]] == 1) { + $delObjStart = dolReplaceInFile($moduledescriptorfile, array('/*'.strtoupper($permissions[$key][4].'*/') => '','/*END '.strtoupper($permissions[$key][4].'*/') => '')); + } + } + if (!$error) { + // check if module is enabled + if (isModEnabled(strtolower($module))) { + $result = unActivateModule(strtolower($module)); + dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity); + if ($result) { + setEventMessages($result, null, 'errors'); + } + header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module); + setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null); + setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings'); + exit; + } else { + header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module); + setEventMessages($langs->trans('PermissionDeletedSuccesfuly'), null); + exit; + } + } } // Update permission @@ -2129,30 +2126,30 @@ if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& e dol_include_once($pathtofile); $class = 'mod'.$module; if (class_exists($class)) { - try { - $moduleobj = new $class($db); - } catch (Exception $e) { - $error++; - dol_print_error($db, $e->getMessage()); - } - } - // verify informations entred - if (!GETPOST('label','alpha')) { + try { + $moduleobj = new $class($db); + } catch (Exception $e) { + $error++; + dol_print_error($db, $e->getMessage()); + } + } + // verify informations entred + if (!GETPOST('label', 'alpha')) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors'); } - if (!GETPOST('permissionObj','alpha')) { + if (!GETPOST('permissionObj', 'alpha')) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rights")), null, 'errors'); } - + $label = GETPOST('label', 'alpha'); - $objectForPerms = strtolower(GETPOST('permissionObj','alpha')); + $objectForPerms = strtolower(GETPOST('permissionObj', 'alpha')); $crud = GETPOST('crud', 'alpha'); - - if ($label == "Read objects of $module" && $crud != "read"){ - $crud = "read"; + + if ($label == "Read objects of $module" && $crud != "read") { + $crud = "read"; $label == "Read objects of $module"; } if ($label == "Create/Update objects of $module" && $crud != "write") { @@ -2165,7 +2162,7 @@ if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& e } $permissions = $moduleobj->rights; - $r =(int)GETPOST('counter'); + $r =(int) GETPOST('counter'); //get permission want to delete from permissions array $x1 = $permissions[$r-1][1]; $x2 = $permissions[$r-1][4]; @@ -2177,26 +2174,26 @@ if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& e $firstRight = 0; $existRight = 0; $allObject = array(); - - for ($i =0; $itrans("ErrorExistingPermission", $langs->transnoentities($label), $langs->transnoentities($objectForPerms)), null, 'errors'); - } + + for ($i =0; $itrans("ErrorExistingPermission", $langs->transnoentities($label), $langs->transnoentities($objectForPerms)), null, 'errors'); + } + } + } + //prepare right want to delete $right = " \$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); @@ -2205,7 +2202,7 @@ if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& e \$this->rights[\$r][5] = '$x3'; \$r++; "; - + $rightUpdated = " \$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); \$this->rights[\$r][1] = '$label'; @@ -2213,26 +2210,24 @@ if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& e \$this->rights[\$r][5] = '$crud'; \$r++; "; - if(!$error){ - - if (isModEnabled(strtolower($module))){ - $result = unActivateModule(strtolower($module)); - dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity); - if ($result) { - setEventMessages($result, null, 'errors'); - } - header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module); - setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null,'warnings'); + if (!$error) { + if (isModEnabled(strtolower($module))) { + $result = unActivateModule(strtolower($module)); + dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity); + if ($result) { + setEventMessages($result, null, 'errors'); } - - $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php'; - $check = dolReplaceInFile($moduledescriptorfile, array($right => $rightUpdated)); - header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module); - setEventMessages($langs->trans('PermissionUpdatedSuccesfuly'), null); - exit; + setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings'); } - + + $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php'; + $check = dolReplaceInFile($moduledescriptorfile, array($right => $rightUpdated)); + + header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module); + setEventMessages($langs->trans('PermissionUpdatedSuccesfuly'), null); + exit; + } } // Save file if ($action == 'savefile' && empty($cancel)) { From 704faf734af8e885cb8450d5355bea39090e313e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 9 Feb 2023 00:47:33 +0100 Subject: [PATCH 09/10] NEW Auto activate some modules on install (export/import/wysiwyg editor) --- htdocs/admin/index.php | 7 +- htdocs/admin/modules.php | 176 +++++++++--------- htdocs/core/lib/admin.lib.php | 11 +- htdocs/core/menus/standard/eldy.lib.php | 9 +- htdocs/core/modules/DolibarrModules.class.php | 4 + htdocs/core/modules/modFckeditor.class.php | 2 +- htdocs/index.php | 7 +- htdocs/install/step5.php | 53 +++++- 8 files changed, 166 insertions(+), 103 deletions(-) diff --git a/htdocs/admin/index.php b/htdocs/admin/index.php index 87b49c95468..8a563191303 100644 --- a/htdocs/admin/index.php +++ b/htdocs/admin/index.php @@ -105,10 +105,15 @@ print '
'; print '
'; +$nbmodulesnotautoenabled = count($conf->modules); +if (in_array('fckeditor', $conf->modules)) $nbmodulesnotautoenabled--; +if (in_array('export', $conf->modules)) $nbmodulesnotautoenabled--; +if (in_array('import', $conf->modules)) $nbmodulesnotautoenabled--; + // Show info setup module print img_picto('', 'cog', 'class="paddingright valignmiddle double"').' '.$langs->trans("SetupDescriptionLink", DOL_URL_ROOT.'/admin/modules.php?mainmenu=home', $langs->transnoentities("Setup"), $langs->transnoentities("Modules")); print '

'.$langs->trans("SetupDescription4b"); -if (count($conf->modules) <= (empty($conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING) ? 1 : $conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING)) { // If only minimal initial modules enabled +if ($nbmodulesnotautoenabled <= getDolGlobalInt('MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING', 1)) { // If only minimal initial modules enabled $langs->load("errors"); $warnpicto = img_warning($langs->trans("WarningEnableYourModulesApplications"), 'style="padding-right: 6px;"'); print '
'; diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index 837c76adadf..a42ecc5c34d 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -379,99 +379,95 @@ foreach ($modulesdir as $dir) { try { $res = include_once $dir.$file; // A class already exists in a different file will send a non catchable fatal error. if (class_exists($modName)) { - try { - $objMod = new $modName($db); - $modNameLoaded[$modName] = $dir; - if (!$objMod->numero > 0 && $modName != 'modUser') { - dol_syslog('The module descriptor '.$modName.' must have a numero property', LOG_ERR); - } - $j = $objMod->numero; + $objMod = new $modName($db); + $modNameLoaded[$modName] = $dir; + if (!$objMod->numero > 0 && $modName != 'modUser') { + dol_syslog('The module descriptor '.$modName.' must have a numero property', LOG_ERR); + } + $j = $objMod->numero; - $modulequalified = 1; + $modulequalified = 1; - // We discard modules according to features level (PS: if module is activated we always show it) - $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod))); - if ($objMod->version == 'development' && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL < 2))) { - $modulequalified = 0; - } - if ($objMod->version == 'experimental' && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL < 1))) { - $modulequalified = 0; - } - if (preg_match('/deprecated/', $objMod->version) && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL >= 0))) { - $modulequalified = 0; - } + // We discard modules according to features level (PS: if module is activated we always show it) + $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod))); + if ($objMod->version == 'development' && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL < 2))) { + $modulequalified = 0; + } + if ($objMod->version == 'experimental' && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL < 1))) { + $modulequalified = 0; + } + if (preg_match('/deprecated/', $objMod->version) && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL >= 0))) { + $modulequalified = 0; + } - // We discard modules according to property ->hidden - if (!empty($objMod->hidden)) { - $modulequalified = 0; - } + // We discard modules according to property ->hidden + if (!empty($objMod->hidden)) { + $modulequalified = 0; + } - if ($modulequalified > 0) { - $publisher = dol_escape_htmltag($objMod->getPublisher()); - $external = ($objMod->isCoreOrExternalModule() == 'external'); - if ($external) { - if ($publisher) { - $arrayofnatures['external_'.$publisher] = $langs->trans("External").' - '.$publisher; - } else { - $arrayofnatures['external_'] = $langs->trans("External").' - '.$langs->trans("UnknownPublishers"); - } - } - ksort($arrayofnatures); - - // Define array $categ with categ with at least one qualified module - $filename[$i] = $modName; - $modules[$modName] = $objMod; - - // Gives the possibility to the module, to provide his own family info and position of this family - if (is_array($objMod->familyinfo) && !empty($objMod->familyinfo)) { - $familyinfo = array_merge($familyinfo, $objMod->familyinfo); - $familykey = key($objMod->familyinfo); + if ($modulequalified > 0) { + $publisher = dol_escape_htmltag($objMod->getPublisher()); + $external = ($objMod->isCoreOrExternalModule() == 'external'); + if ($external) { + if ($publisher) { + $arrayofnatures['external_'.$publisher] = $langs->trans("External").' - '.$publisher; } else { - $familykey = $objMod->family; + $arrayofnatures['external_'] = $langs->trans("External").' - '.$langs->trans("UnknownPublishers"); } + } + ksort($arrayofnatures); - $moduleposition = ($objMod->module_position ? $objMod->module_position : '50'); - if ($objMod->isCoreOrExternalModule() == 'external' && $moduleposition < 100000) { - // an external module should never return a value lower than '80'. - $moduleposition = '80'; // External modules at end by default - } + // Define array $categ with categ with at least one qualified module + $filename[$i] = $modName; + $modules[$modName] = $objMod; - // Add list of warnings to show into arrayofwarnings and arrayofwarningsext - if (!empty($objMod->warnings_activation)) { - $arrayofwarnings[$modName] = $objMod->warnings_activation; - } - if (!empty($objMod->warnings_activation_ext)) { - $arrayofwarningsext[$modName] = $objMod->warnings_activation_ext; - } - - $familyposition = (empty($familyinfo[$familykey]['position']) ? 0 : $familyinfo[$familykey]['position']); - $listOfOfficialModuleGroups = array('hr', 'technic', 'interface', 'technic', 'portal', 'financial', 'crm', 'base', 'products', 'srm', 'ecm', 'projects', 'other'); - if ($external && !in_array($familykey, $listOfOfficialModuleGroups)) { - // If module is extern and into a custom group (not into an official predefined one), it must appear at end (custom groups should not be before official groups). - if (is_numeric($familyposition)) { - $familyposition = sprintf("%03d", (int) $familyposition + 100); - } - } - - $orders[$i] = $familyposition."_".$familykey."_".$moduleposition."_".$j; // Sort by family, then by module position then number - - // Set categ[$i] - $specialstring = 'unknown'; - if ($objMod->version == 'development' || $objMod->version == 'experimental') { - $specialstring = 'expdev'; - } - if (isset($categ[$specialstring])) { - $categ[$specialstring]++; // Array of all different modules categories - } else { - $categ[$specialstring] = 1; - } - $j++; - $i++; + // Gives the possibility to the module, to provide his own family info and position of this family + if (is_array($objMod->familyinfo) && !empty($objMod->familyinfo)) { + $familyinfo = array_merge($familyinfo, $objMod->familyinfo); + $familykey = key($objMod->familyinfo); } else { - dol_syslog("Module ".get_class($objMod)." not qualified"); + $familykey = $objMod->family; } - } catch (Exception $e) { - dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR); + + $moduleposition = ($objMod->module_position ? $objMod->module_position : '50'); + if ($objMod->isCoreOrExternalModule() == 'external' && $moduleposition < 100000) { + // an external module should never return a value lower than '80'. + $moduleposition = '80'; // External modules at end by default + } + + // Add list of warnings to show into arrayofwarnings and arrayofwarningsext + if (!empty($objMod->warnings_activation)) { + $arrayofwarnings[$modName] = $objMod->warnings_activation; + } + if (!empty($objMod->warnings_activation_ext)) { + $arrayofwarningsext[$modName] = $objMod->warnings_activation_ext; + } + + $familyposition = (empty($familyinfo[$familykey]['position']) ? 0 : $familyinfo[$familykey]['position']); + $listOfOfficialModuleGroups = array('hr', 'technic', 'interface', 'technic', 'portal', 'financial', 'crm', 'base', 'products', 'srm', 'ecm', 'projects', 'other'); + if ($external && !in_array($familykey, $listOfOfficialModuleGroups)) { + // If module is extern and into a custom group (not into an official predefined one), it must appear at end (custom groups should not be before official groups). + if (is_numeric($familyposition)) { + $familyposition = sprintf("%03d", (int) $familyposition + 100); + } + } + + $orders[$i] = $familyposition."_".$familykey."_".$moduleposition."_".$j; // Sort by family, then by module position then number + + // Set categ[$i] + $specialstring = 'unknown'; + if ($objMod->version == 'development' || $objMod->version == 'experimental') { + $specialstring = 'expdev'; + } + if (isset($categ[$specialstring])) { + $categ[$specialstring]++; // Array of all different modules categories + } else { + $categ[$specialstring] = 1; + } + $j++; + $i++; + } else { + dol_syslog("Module ".get_class($objMod)." not qualified"); } } else { print "Warning bad descriptor file : ".$dir.$file." (Class ".$modName." not found into file)
"; @@ -523,12 +519,10 @@ asort($orders); $nbofactivatedmodules = count($conf->modules); -//$conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING = 1000; -/*$moreinfo = $langs->trans("TitleNumberOfActivatedModules"); -$moreinfo2 = ''.($nbofactivatedmodules - 1).' / '.count($modules).''; -if ($nbofactivatedmodules <= (empty($conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING) ? 1 : $conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING)) { - $moreinfo2 .= ' '.img_warning($langs->trans("YouMustEnableOneModule")); -}*/ +$nbmodulesnotautoenabled = count($conf->modules); +if (in_array('fckeditor', $conf->modules)) $nbmodulesnotautoenabled--; +if (in_array('export', $conf->modules)) $nbmodulesnotautoenabled--; +if (in_array('import', $conf->modules)) $nbmodulesnotautoenabled--; print load_fiche_titre($langs->trans("ModulesSetup"), '', 'title_setup'); @@ -539,7 +533,7 @@ if ($mode == 'common' || $mode == 'commonkanban') { $desc .= ' '.$langs->trans("ModulesDesc2", '{picto2}'); $desc = str_replace('{picto}', img_picto('', 'switch_off', 'class="size15x"'), $desc); $desc = str_replace('{picto2}', img_picto('', 'setup', 'class="size15x"'), $desc); - if (!count($conf->modules) <= (empty($conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING) ? 1 : $conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING)) { // If only minimal initial modules enabled + if ($nbmodulesnotautoenabled <= getDolGlobalInt('MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING', 1)) { // If only minimal initial modules enabled $deschelp = '
'.$desc."

\n"; } } @@ -553,7 +547,7 @@ if ($mode == 'develop') { $deschelp = '
'.$langs->trans("ModulesDevelopDesc")."

\n"; } -$head = modules_prepare_head($nbofactivatedmodules, count($modules)); +$head = modules_prepare_head($nbofactivatedmodules, count($modules), $nbmodulesnotautoenabled); if ($mode == 'common' || $mode == 'commonkanban') { diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 92895793082..29d9a9710c8 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -696,11 +696,12 @@ function dolibarr_set_const($db, $name, $value, $type = 'chaine', $visible = 0, /** * Prepare array with list of tabs * - * @param int $nbofactivatedmodules Number if activated modules - * @param int $nboftotalmodules Nb of total modules - * @return array Array of tabs to show + * @param int $nbofactivatedmodules Number if activated modules + * @param int $nboftotalmodules Nb of total modules + * @param int $nbmodulesnotautoenabled Nb of modules not auto enabled that are activated + * @return array Array of tabs to show */ -function modules_prepare_head($nbofactivatedmodules, $nboftotalmodules) +function modules_prepare_head($nbofactivatedmodules, $nboftotalmodules, $nbmodulesnotautoenabled) { global $langs, $conf, $user, $form; @@ -711,7 +712,7 @@ function modules_prepare_head($nbofactivatedmodules, $nboftotalmodules) $head = array(); $mode = empty($conf->global->MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT) ? 'commonkanban' : $conf->global->MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT; $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=".$mode; - if ($nbofactivatedmodules <= (empty($conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING) ? 1 : $conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING)) { // If only minimal initial modules enabled) + if ($nbmodulesnotautoenabled <= getDolGlobalInt('MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING', 1)) { // If only minimal initial modules enabled) //$head[$h][1] = $form->textwithpicto($langs->trans("AvailableModules"), $desc); $head[$h][1] = $langs->trans("AvailableModules"); $head[$h][1] .= $form->textwithpicto('', $langs->trans("YouMustEnableOneModule").'.

'.$desc.'', 1, 'warning'); diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index a4ca1d290a1..76ee88fda2d 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -1087,18 +1087,21 @@ function get_left_menu_home($mainmenu, &$newmenu, $usemenuhider = 1, $leftmenu = $newmenu->add("/admin/index.php?mainmenu=home&leftmenu=setup", $langs->trans("Setup"), 0, $user->admin, '', $mainmenu, 'setup', 0, '', '', '', ''); if ($usemenuhider || empty($leftmenu) || $leftmenu == "setup") { + $nbmodulesnotautoenabled = count($conf->modules); + if (in_array('fckeditor', $conf->modules)) $nbmodulesnotautoenabled--; + if (in_array('export', $conf->modules)) $nbmodulesnotautoenabled--; + if (in_array('import', $conf->modules)) $nbmodulesnotautoenabled--; + // Load translation files required by the page $langs->loadLangs(array("admin", "help")); - $warnpicto = ''; if (empty($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) { $langs->load("errors"); $warnpicto = img_warning($langs->trans("WarningMandatorySetupNotComplete")); } $newmenu->add("/admin/company.php?mainmenu=home", $langs->trans("MenuCompanySetup").$warnpicto, 1); - $warnpicto = ''; - if (count($conf->modules) <= (empty($conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING) ? 1 : $conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING)) { // If only user module enabled + if ($nbmodulesnotautoenabled <= getDolGlobalInt('MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING', 1)) { // If only user module enabled $langs->load("errors"); $warnpicto = img_warning($langs->trans("WarningMandatorySetupNotComplete")); } diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index 8e6bd78632d..e0d7a8741a5 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -365,12 +365,16 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it */ public $phpmin; + public $phpmax; + /** * @var array Minimum version of Dolibarr required by module. * e.g.: Dolibarr ≥ 3.6 = array(3, 6) */ public $need_dolibarr_version; + public $enabled_bydefault; + /** * @var bool Whether to hide the module. */ diff --git a/htdocs/core/modules/modFckeditor.class.php b/htdocs/core/modules/modFckeditor.class.php index 9dd3fce7fcd..76d8ba4eb23 100644 --- a/htdocs/core/modules/modFckeditor.class.php +++ b/htdocs/core/modules/modFckeditor.class.php @@ -63,7 +63,7 @@ class modFckeditor extends DolibarrModules $this->config_page_url = array("fckeditor.php"); // Dependencies - $this->disabled = in_array(constant('JS_CKEDITOR'), array('disabled', 'disabled/')); + $this->disabled = (defined('JS_CKEDITOR') && in_array(constant('JS_CKEDITOR'), array('disabled', 'disabled/'))); $this->depends = array(); $this->requiredby = array('modWebsites'); $this->enabled_bydefault = true; // Will be enabled during install diff --git a/htdocs/index.php b/htdocs/index.php index f1ce8248921..dd1e36d04f8 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -42,12 +42,17 @@ $hookmanager->initHooks(array('index')); * Actions */ +$nbmodulesnotautoenabled = count($conf->modules); +if (in_array('fckeditor', $conf->modules)) $nbmodulesnotautoenabled--; +if (in_array('export', $conf->modules)) $nbmodulesnotautoenabled--; +if (in_array('import', $conf->modules)) $nbmodulesnotautoenabled--; + // Check if company name is defined (first install) if (!isset($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INFO_SOCIETE_NOM)) { header("Location: ".DOL_URL_ROOT."/admin/index.php?mainmenu=home&leftmenu=setup&mesg=setupnotcomplete"); exit; } -if (count($conf->modules) <= (empty($conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING) ? 1 : $conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING)) { // If only user module enabled +if ($nbmodulesnotautoenabled <= getDolGlobalString('MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING', 1)) { // If only user module enabled header("Location: ".DOL_URL_ROOT."/admin/index.php?mainmenu=home&leftmenu=setup&mesg=setupnotcomplete"); exit; } diff --git a/htdocs/install/step5.php b/htdocs/install/step5.php index fc0dcf37799..6598843b882 100644 --- a/htdocs/install/step5.php +++ b/htdocs/install/step5.php @@ -29,6 +29,7 @@ * For installation: * It creates the login admin and set the MAIN_SECURITY_SALT to a random value. * It set the value for MAIN_VERSION_LAST_INSTALL + * It activates some modules * It creates the install.lock and shows the final message. * For upgrade: * It updates the value for MAIN_VERSION_LAST_UPGRADE. @@ -42,6 +43,7 @@ if (file_exists($conffile)) { } require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php'; require_once $dolibarr_main_document_root.'/core/lib/security.lib.php'; // for dol_hash +require_once $dolibarr_main_document_root.'/core/lib/functions2.lib.php'; global $langs; @@ -287,6 +289,9 @@ if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action)) { */ } + // List of modules to enable + $tmparray = array(); + // If we ask to force some modules to be enabled if (!empty($force_install_module)) { if (!defined('DOL_DOCUMENT_ROOT') && !empty($dolibarr_main_document_root)) { @@ -294,9 +299,53 @@ if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action)) { } $tmparray = explode(',', $force_install_module); + } + + $modNameLoaded = array(); + + // Search modules dirs + $modulesdir[] = $dolibarr_main_document_root.'/core/modules/'; + + foreach ($modulesdir as $dir) { + // Load modules attributes in arrays (name, numero, orders) from dir directory + //print $dir."\n
"; + dol_syslog("Scan directory ".$dir." for module descriptor files (modXXX.class.php)"); + $handle = @opendir($dir); + if (is_resource($handle)) { + while (($file = readdir($handle)) !== false) { + if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') { + $modName = substr($file, 0, dol_strlen($file) - 10); + if ($modName) { + if (!empty($modNameLoaded[$modName])) { // In cache of already loaded modules ? + $mesg = "Error: Module ".$modName." was found twice: Into ".$modNameLoaded[$modName]." and ".$dir.". You probably have an old file on your disk.
"; + setEventMessages($mesg, null, 'warnings'); + dol_syslog($mesg, LOG_ERR); + continue; + } + + try { + $res = include_once $dir.$file; // A class already exists in a different file will send a non catchable fatal error. + if (class_exists($modName)) { + $objMod = new $modName($db); + $modNameLoaded[$modName] = $dir; + if (!empty($objMod->enabled_bydefault) && !in_array($file, $tmparray)) { + $tmparray[] = $file; + } + } + } catch (Exception $e) { + dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR); + } + } + } + } + } + } + + // Loop on each modules to activate it + if (!empty($tmparray)) { foreach ($tmparray as $modtoactivate) { $modtoactivatenew = preg_replace('/\.class\.php$/i', '', $modtoactivate); - print $langs->trans("ActivateModule", $modtoactivatenew).'
'; + //print $langs->trans("ActivateModule", $modtoactivatenew).'
'; $file = $modtoactivatenew.'.class.php'; dolibarr_install_syslog('step5: activate module file='.$file); @@ -307,8 +356,10 @@ if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action)) { print 'ERROR: failed to activateModule() file='.$file; } } + //print '
'; } + // Now delete the flag to say install is complete dolibarr_install_syslog('step5: remove MAIN_NOT_INSTALLED const'); $resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_NOT_INSTALLED'"); if (!$resql) { From f444dd8f49f7c2e2deae96853e724cf7bce559b3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 9 Feb 2023 00:58:55 +0100 Subject: [PATCH 10/10] Trans --- htdocs/langs/en_US/admin.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 9706ffedb76..90e520cea25 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1234,7 +1234,7 @@ SetupDescription4=%s -> %s

This software is a suite of m SetupDescription5=Other Setup menu entries manage optional parameters. SetupDescriptionLink=%s - %s SetupDescription3b=Basic parameters used to customize the default behavior of your application (e.g for country-related features). -SetupDescription4b=This software is a suite of many modules/applications. The modules related to your needs must be enabled and configured. Menu entries will appears with the activation of these modules. +SetupDescription4b=This software is a suite of many modules/applications. The modules related to your needs must be activated. Menu entries will appears with the activation of these modules. AuditedSecurityEvents=Security events that are audited NoSecurityEventsAreAduited=No security events are audited. You can enable them from menu %s Audit=Security events