From 40434773c7b808725097f6ad767d3000b55bd814 Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Tue, 12 Mar 2024 18:22:59 +0100 Subject: [PATCH 1/5] New buttons for edit and delete pre_post prompt for each function --- htdocs/ai/admin/custom_prompt.php | 38 ++++++++++++++++++++++++++++++- htdocs/langs/en_US/help.lang | 1 + 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/htdocs/ai/admin/custom_prompt.php b/htdocs/ai/admin/custom_prompt.php index c784e9ae3b8..8f93431e363 100644 --- a/htdocs/ai/admin/custom_prompt.php +++ b/htdocs/ai/admin/custom_prompt.php @@ -126,6 +126,25 @@ if ($action == 'update' && !GETPOST('cancel')) { $action = 'edit'; } +if ($action == 'confirm_deleteproperty') { + $key = GETPOST('key', 'alpha'); + + //var_dump($currentConfigurations[$key]);exit; + if (isset($currentConfigurations[$key])) { + unset($currentConfigurations[$key]); + + $newConfigurationsJson = json_encode($currentConfigurations, JSON_UNESCAPED_UNICODE); + $res = dolibarr_set_const($db, 'AI_CONFIGURATIONS_PROMPT', $newConfigurationsJson, 'chaine', 0, '', $conf->entity); + if ($res) { + header("Location: ".$_SERVER['PHP_SELF']); + setEventMessages($langs->trans("SetupDeleted"), null, 'mesgs'); + exit; + } else { + setEventMessages($langs->trans("ErrorDeleting"), null, 'errors'); + } + } +} + /* * View @@ -152,11 +171,25 @@ $newbutton = ''; print load_fiche_titre($langs->trans("AIPromptForFeatures"), $newbutton, ''); +if ($action == 'deleteproperty') { + $formconfirm = $form->formconfirm( + $_SERVER["PHP_SELF"].'?key='.urlencode(GETPOST('key', 'alpha')), + $langs->trans('Delete'), + $langs->trans('ConfirmDeleteProperty', GETPOST('key', 'alpha')), + 'confirm_deleteproperty', + '', + 0, + 1 + ); + print $formconfirm; +} + if ($action == 'edit') { $out .= '
'; $out .= ''; $out .= ''; + $out .= ''; $out .= ''; $out .= ''; @@ -235,7 +268,10 @@ if ($action == 'edit' || $action == 'create') { $out .= ''; $out .= ''; - $out .= ''; + $out .= ''; $out .= ''; $out .= ''; $out .= ''; diff --git a/htdocs/langs/en_US/help.lang b/htdocs/langs/en_US/help.lang index 17a6104d59a..ccfb6d8468d 100644 --- a/htdocs/langs/en_US/help.lang +++ b/htdocs/langs/en_US/help.lang @@ -21,3 +21,4 @@ LinkToGoldMember=You can call one of the trainers preselected by Dolibarr for yo PossibleLanguages=Supported languages SubscribeToFoundation=Help the Dolibarr project, subscribe to the foundation SeeOfficalSupport=For official Dolibarr support in your language:
%s +ConfirmDeleteProperty=Are you sure you want to delete this property ? \ No newline at end of file From fc732b1be5f479ed55ee4e3fff238b4d4ff220ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Tue, 12 Mar 2024 18:49:29 +0100 Subject: [PATCH 2/5] fix mod barcode product --- .../barcode/mod_barcode_product_standard.php | 27 ++++++++--------- .../mod_barcode_thirdparty_standard.php | 30 ++++++++----------- .../modules/barcode/modules_barcode.class.php | 8 ++--- phpstan.neon.dist | 1 - 4 files changed, 28 insertions(+), 38 deletions(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index ea68cd1810a..31859eb4ead 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -109,10 +109,10 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode * Return an example of result returned by getNextValue * * @param Translate $langs Object langs - * @param Product $objproduct Object product + * @param ?Product $objproduct Object product * @return string Return string example */ - public function getExample($langs, $objproduct = 0) + public function getExample($langs, $objproduct = null) { $examplebarcode = $this->getNextValue($objproduct, ''); if (!$examplebarcode) { @@ -155,18 +155,19 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode return $out; } + /** * Return next value * - * @param CommonObject $objproduct Object product - * @param string $type Type of barcode (EAN, ISBN, ...) - * @return string Value if OK, '' if module not configured, <0 if KO + * @param ?CommonObject $objproduct Object product (not used) + * @param string $type Type of barcode (EAN, ISBN, ...) + * @return string Value if OK, '' if module not configured, <0 if KO */ - public function getNextValue($objproduct, $type = '') + public function getNextValue($objproduct = null, $type = '') { - global $db, $conf; + global $db; - if (!$objproduct instanceof Product) { + if (is_object($objproduct) && !$objproduct instanceof Product) { dol_syslog(get_class($this)."::getNextValue used on incompatible".get_class($objproduct), LOG_ERR); return -1; } @@ -178,13 +179,8 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode $type = getDolGlobalString('PRODUIT_DEFAULT_BARCODE_TYPE'); } //get barcode type configuration for products if $type not set - // TODO - // Get Mask value - $mask = ''; - if (getDolGlobalString('BARCODE_STANDARD_PRODUCT_MASK')) { - $mask = getDolGlobalString('BARCODE_STANDARD_PRODUCT_MASK'); - } + $mask = getDolGlobalString('BARCODE_STANDARD_PRODUCT_MASK'); if (empty($mask)) { $this->error = 'NotConfigured'; @@ -216,7 +212,8 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode } } //End barcode with key - return $numFinal; + + return $numFinal; } diff --git a/htdocs/core/modules/barcode/mod_barcode_thirdparty_standard.php b/htdocs/core/modules/barcode/mod_barcode_thirdparty_standard.php index a0e94fd69a1..0113e7dfb39 100644 --- a/htdocs/core/modules/barcode/mod_barcode_thirdparty_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_thirdparty_standard.php @@ -72,10 +72,11 @@ class mod_barcode_thirdparty_standard extends ModeleNumRefBarCode } - /** Return description of module + /** + * Return description of module * - * @param Translate $langs Object langs - * @return string Description of module + * @param Translate $langs Object langs + * @return string Description of module */ public function info($langs) { @@ -120,10 +121,10 @@ class mod_barcode_thirdparty_standard extends ModeleNumRefBarCode * Return an example of result returned by getNextValue * * @param Translate $langs Object langs - * @param Societe $objthirdparty Object third-party + * @param ?Societe $objthirdparty Object third-party * @return string Return string example */ - public function getExample($langs, $objthirdparty = 0) + public function getExample($langs, $objthirdparty = null) { $examplebarcode = $this->getNextValue($objthirdparty, ''); if (!$examplebarcode) { @@ -169,13 +170,13 @@ class mod_barcode_thirdparty_standard extends ModeleNumRefBarCode /** * Return next value * - * @param CommonObject $objthirdparty Object third-party + * @param ?CommonObject $objthirdparty Object third-party * @param string $type Type of barcode (EAN, ISBN, ...) * @return string Value if OK, '' if module not configured, <0 if KO */ - public function getNextValue($objthirdparty, $type = '') + public function getNextValue($objthirdparty = null, $type = '') { - global $db, $conf; + global $db; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/barcode.lib.php'; // to be able to call function barcode_gen_ean_sum($ean) @@ -184,13 +185,8 @@ class mod_barcode_thirdparty_standard extends ModeleNumRefBarCode $type = getDolGlobalString('GENBARCODE_BARCODETYPE_THIRDPARTY'); } //get barcode type configuration for companies if $type not set - // TODO - // Get Mask value - $mask = ''; - if (getDolGlobalString('BARCODE_STANDARD_THIRDPARTY_MASK')) { - $mask = getDolGlobalString('BARCODE_STANDARD_THIRDPARTY_MASK'); - } + $mask = getDolGlobalString('BARCODE_STANDARD_THIRDPARTY_MASK'); if (empty($mask)) { $this->error = 'NotConfigured'; @@ -222,6 +218,7 @@ class mod_barcode_thirdparty_standard extends ModeleNumRefBarCode } } //End barcode with key + return $numFinal; } @@ -242,10 +239,6 @@ class mod_barcode_thirdparty_standard extends ModeleNumRefBarCode */ public function verif($db, &$code, $thirdparty, $thirdparty_type, $type) { - global $conf; - - //var_dump($code.' '.$thirdparty->ref.' '.$thirdparty_type);exit; - require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; $result = 0; @@ -273,6 +266,7 @@ class mod_barcode_thirdparty_standard extends ModeleNumRefBarCode } dol_syslog(get_class($this)."::verif type=".$thirdparty_type." result=".$result); + return $result; } diff --git a/htdocs/core/modules/barcode/modules_barcode.class.php b/htdocs/core/modules/barcode/modules_barcode.class.php index e037b9e0a09..7a283f5189f 100644 --- a/htdocs/core/modules/barcode/modules_barcode.class.php +++ b/htdocs/core/modules/barcode/modules_barcode.class.php @@ -62,11 +62,11 @@ abstract class ModeleNumRefBarCode extends CommonNumRefGenerator /** * Return next value available * - * @param CommonObject $objcommon Object Product, Thirdparty - * @param string $type Type of barcode (EAN, ISBN, ...) - * @return string Value + * @param ?CommonObject $objcommon Object Product, Thirdparty + * @param string $type Type of barcode (EAN, ISBN, ...) + * @return string Value */ - public function getNextValue($objcommon, $type = '') + public function getNextValue($objcommon = null, $type = '') { global $langs; return $langs->trans("Function_getNextValue_InModuleNotWorking"); diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 78867274e30..c354dfd5d84 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -54,7 +54,6 @@ parameters: - '#(\$force_dolibarr_lib|\$dolibarr_main_db).*in empty\(\) is never defined.#' - '#Sprain\\SwissQrBill\\#' - '#Constructor of class .* has an unused parameter #' - - '#Default value of the parameter#' internalErrorsCountLimit: 50 cache: nodesByFileCountMax: 512 From 37b22d5b90a2054b633a074ca4456efba885a14f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Tue, 12 Mar 2024 18:51:20 +0100 Subject: [PATCH 3/5] fix mod barcode product --- phpstan.neon.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c354dfd5d84..78867274e30 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -54,6 +54,7 @@ parameters: - '#(\$force_dolibarr_lib|\$dolibarr_main_db).*in empty\(\) is never defined.#' - '#Sprain\\SwissQrBill\\#' - '#Constructor of class .* has an unused parameter #' + - '#Default value of the parameter#' internalErrorsCountLimit: 50 cache: nodesByFileCountMax: 512 From 6fd62a3591ae4e521901330a68e928fcdbe53261 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Mar 2024 20:22:23 +0100 Subject: [PATCH 4/5] Fix duplicate --- htdocs/langs/en_US/help.lang | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/langs/en_US/help.lang b/htdocs/langs/en_US/help.lang index ccfb6d8468d..17a6104d59a 100644 --- a/htdocs/langs/en_US/help.lang +++ b/htdocs/langs/en_US/help.lang @@ -21,4 +21,3 @@ LinkToGoldMember=You can call one of the trainers preselected by Dolibarr for yo PossibleLanguages=Supported languages SubscribeToFoundation=Help the Dolibarr project, subscribe to the foundation SeeOfficalSupport=For official Dolibarr support in your language:
%s -ConfirmDeleteProperty=Are you sure you want to delete this property ? \ No newline at end of file From a467b0f9f6579381c81d00a30b10d1e204735062 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Mar 2024 20:31:01 +0100 Subject: [PATCH 5/5] Fix trans --- htdocs/ai/admin/custom_prompt.php | 2 +- htdocs/langs/en_US/admin.lang | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/ai/admin/custom_prompt.php b/htdocs/ai/admin/custom_prompt.php index 8f93431e363..ee62b646604 100644 --- a/htdocs/ai/admin/custom_prompt.php +++ b/htdocs/ai/admin/custom_prompt.php @@ -175,7 +175,7 @@ if ($action == 'deleteproperty') { $formconfirm = $form->formconfirm( $_SERVER["PHP_SELF"].'?key='.urlencode(GETPOST('key', 'alpha')), $langs->trans('Delete'), - $langs->trans('ConfirmDeleteProperty', GETPOST('key', 'alpha')), + $langs->trans('ConfirmDeleteSetup', GETPOST('key', 'alpha')), 'confirm_deleteproperty', '', 0, diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index e632b93088a..576180c6371 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -2425,6 +2425,7 @@ LargeModern=Large - Modern SpecialCharActivation=Enable the button to open a virtual keyboard to enter special characters DeleteExtrafield=Delete extrafield ConfirmDeleteExtrafield=Do you confirm deletion of the field %s ? All data saved into this field will be definitely deleted +ConfirmDeleteSetup=Are you sure you want to delete the setup for %s ? ExtraFieldsSupplierInvoicesRec=Complementary attributes (templates invoices) ExtraFieldsSupplierInvoicesLinesRec=Complementary attributes (template invoice lines) ParametersForTestEnvironment=Parameters for test environment
'.$arrayofaifeatures[$key]['picto'].' '.$langs->trans($arrayofaifeatures[$key]['label']).''.$arrayofaifeatures[$key]['picto'].' '.$langs->trans($arrayofaifeatures[$key]['label']); + $out .= ''.img_edit().''; + $out .= ''.img_delete().''; + $out .= '