From 034378a9588da5cb0b29614d7acda402a53e9783 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Tue, 4 May 2021 00:58:29 +0200 Subject: [PATCH 1/6] Add online substitution keys link in mailing --- htdocs/comm/mailing/card.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index c3ef480d2ae..98b3622d5ef 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -222,14 +222,23 @@ if (empty($reshook)) { $onlinepaymentenabled++; } if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN)) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; + $substitutionarray['__ONLINEPAYMENTLINK_MEMBER__'] = getOnlinePaymentUrl(0, 'member', $obj->source_id); + $substitutionarray['__ONLINEPAYMENTLINK_DONATION__'] = getOnlinePaymentUrl(0, 'donation', $obj->source_id); + $substitutionarray['__ONLINEPAYMENTLINK_ORDER__'] = getOnlinePaymentUrl(0, 'order', $obj->source_id); + $substitutionarray['__ONLINEPAYMENTLINK_INVOICE__'] = getOnlinePaymentUrl(0, 'invoice', $obj->source_id); + $substitutionarray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = getOnlinePaymentUrl(0, 'contractline', $obj->source_id); + $substitutionarray['__SECUREKEYPAYMENT__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2); if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { $substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2); + $substitutionarray['__SECUREKEYPAYMENT_DONATION__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2); $substitutionarray['__SECUREKEYPAYMENT_ORDER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2); $substitutionarray['__SECUREKEYPAYMENT_INVOICE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2); $substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2); } else { - $substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'membersubscription'.$obj->source_id, 2); + $substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'member'.$obj->source_id, 2); + $substitutionarray['__SECUREKEYPAYMENT_DONATION__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'donation'.$obj->source_id, 2); $substitutionarray['__SECUREKEYPAYMENT_ORDER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'order'.$obj->source_id, 2); $substitutionarray['__SECUREKEYPAYMENT_INVOICE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'invoice'.$obj->source_id, 2); $substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'contractline'.$obj->source_id, 2); From 9ab7f4ec0194c910a94fd5c4a1e66ddef329d456 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Tue, 4 May 2021 01:41:32 +0200 Subject: [PATCH 2/6] Add tooltip for new substitution keys --- htdocs/core/class/html.formmail.class.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index f56b9f6070e..ff38cdcf282 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1592,15 +1592,23 @@ class FormMail extends Form $tmparray['__SECUREKEYPAYMENT__'] = $conf->global->PAYMENT_SECURITY_TOKEN; if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { if ($conf->adherent->enabled) { + $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember'; $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember'; } + if ($conf->donation->enabled) { + $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation'; + $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation'; + } if ($conf->facture->enabled) { + $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice'; $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice'; } if ($conf->commande->enabled) { + $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder'; $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder'; } if ($conf->contrat->enabled) { + $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine'; $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine'; } } From 729a5677ad4610e39f0f5e88dbc777cdd9cb67ed Mon Sep 17 00:00:00 2001 From: daraelmin Date: Tue, 4 May 2021 01:53:46 +0200 Subject: [PATCH 3/6] Group tooltip by key type --- htdocs/core/class/html.formmail.class.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index ff38cdcf282..96f6ee0a741 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1592,25 +1592,37 @@ class FormMail extends Form $tmparray['__SECUREKEYPAYMENT__'] = $conf->global->PAYMENT_SECURITY_TOKEN; if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { if ($conf->adherent->enabled) { - $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember'; $tmparray['__SECUREKEYPAYMENT_MEMBER__'] = 'SecureKeyPAYMENTUniquePerMember'; } if ($conf->donation->enabled) { - $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation'; $tmparray['__SECUREKEYPAYMENT_DONATION__'] = 'SecureKeyPAYMENTUniquePerDonation'; } if ($conf->facture->enabled) { - $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice'; $tmparray['__SECUREKEYPAYMENT_INVOICE__'] = 'SecureKeyPAYMENTUniquePerInvoice'; } if ($conf->commande->enabled) { - $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder'; $tmparray['__SECUREKEYPAYMENT_ORDER__'] = 'SecureKeyPAYMENTUniquePerOrder'; } if ($conf->contrat->enabled) { - $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine'; $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'SecureKeyPAYMENTUniquePerContractLine'; } + + //Online payement link + if ($conf->adherent->enabled) { + $tmparray['__ONLINEPAYMENTLINK_MEMBER__'] = 'OnlinePaymentLinkUniquePerMember'; + } + if ($conf->donation->enabled) { + $tmparray['__ONLINEPAYMENTLINK_DONATION__'] = 'OnlinePaymentLinkUniquePerDonation'; + } + if ($conf->facture->enabled) { + $tmparray['__ONLINEPAYMENTLINK_INVOICE__'] = 'OnlinePaymentLinkUniquePerInvoice'; + } + if ($conf->commande->enabled) { + $tmparray['__ONLINEPAYMENTLINK_ORDER__'] = 'OnlinePaymentLinkUniquePerOrder'; + } + if ($conf->contrat->enabled) { + $tmparray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = 'OnlinePaymentLinkUniquePerContractLine'; + } } } else { /* No need to show into tooltip help, option is not enabled From b04dfcadc77d26e8863413dc4af7d05b6c98cfbe Mon Sep 17 00:00:00 2001 From: daraelmin Date: Tue, 4 May 2021 21:55:19 +0200 Subject: [PATCH 4/6] Add function to get html online payment link --- htdocs/core/lib/payments.lib.php | 39 ++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/htdocs/core/lib/payments.lib.php b/htdocs/core/lib/payments.lib.php index 494a92d33e3..90fba70464c 100644 --- a/htdocs/core/lib/payments.lib.php +++ b/htdocs/core/lib/payments.lib.php @@ -3,6 +3,7 @@ * Copyright (C) 2013 Marcos García * Copyright (C) 2018 Frédéric France * Copyright (C) 2020 Abbes Bahfir + * Copyright (C) 2021 Waël Almoman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,8 +27,7 @@ * @param Paiement $object Current payment object * @return array Tabs for the payment section */ -function payment_prepare_head(Paiement $object) -{ +function payment_prepare_head(Paiement $object) { global $langs, $conf; $h = 0; @@ -61,8 +61,7 @@ function payment_prepare_head(Paiement $object) * @param int $id ID of bank line * @return array Tabs for the Bankline section */ -function bankline_prepare_head($id) -{ +function bankline_prepare_head($id) { global $langs, $conf; $h = 0; @@ -96,8 +95,7 @@ function bankline_prepare_head($id) * @param Paiement $object Current payment object * @return array Tabs for the payment section */ -function payment_supplier_prepare_head(Paiement $object) -{ +function payment_supplier_prepare_head(Paiement $object) { global $langs, $conf; $h = 0; @@ -130,8 +128,7 @@ function payment_supplier_prepare_head(Paiement $object) * @param string $paymentmethod Filter on this payment method (''=none, 'paypal', ...) * @return array Array of valid payment method */ -function getValidOnlinePaymentMethods($paymentmethod = '') -{ +function getValidOnlinePaymentMethods($paymentmethod = '') { global $conf, $langs; $validpaymentmethod = array(); @@ -155,14 +152,13 @@ function getValidOnlinePaymentMethods($paymentmethod = '') } /** - * Return string with full Url + * Return string with full online payment Url * * @param string $type Type of URL ('free', 'order', 'invoice', 'contractline', 'membersubscription' ...) * @param string $ref Ref of object * @return string Url string */ -function showOnlinePaymentUrl($type, $ref) -{ +function showOnlinePaymentUrl($type, $ref) { global $langs; // Load translation files required by the page @@ -178,6 +174,21 @@ function showOnlinePaymentUrl($type, $ref) return $out; } +/** + * Return string with HTML link for online payment + * + * @param string $type Type of URL ('free', 'order', 'invoice', 'contractline', 'membersubscription' ...) + * @param string $ref Ref of object + * @param string $label Text or HTML tag to display, if empty it display the URL + * @return string Url string + */ +function getHtmlOnlinePaymentLink($type, $ref, $label='') { + $url = getOnlinePaymentUrl(0, $type, $ref); + $label = $label ? $label : $url; + return''.$label.''; +} + + /** * Return string with full Url * @@ -189,8 +200,7 @@ function showOnlinePaymentUrl($type, $ref) * @param string $localorexternal 0=Url for browser, 1=Url for external access * @return string Url string */ -function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_tag', $localorexternal = 0) -{ +function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_tag', $localorexternal = 0) { global $conf, $dolibarr_main_url_root; $ref = str_replace(' ', '', $ref); @@ -355,8 +365,7 @@ function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag * @param Object $object Object related to payment * @return void */ -function htmlPrintOnlinePaymentFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null) -{ +function htmlPrintOnlinePaymentFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null) { global $conf; // Juridical status From 866857c111ae2523294b40a0e40d910d43aaf3b6 Mon Sep 17 00:00:00 2001 From: daraelmin Date: Tue, 4 May 2021 21:57:59 +0200 Subject: [PATCH 5/6] Html link instead of url in substitutionarray --- htdocs/comm/mailing/card.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index 98b3622d5ef..ce260a44a35 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -223,11 +223,11 @@ if (empty($reshook)) { } if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN)) { require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; - $substitutionarray['__ONLINEPAYMENTLINK_MEMBER__'] = getOnlinePaymentUrl(0, 'member', $obj->source_id); - $substitutionarray['__ONLINEPAYMENTLINK_DONATION__'] = getOnlinePaymentUrl(0, 'donation', $obj->source_id); - $substitutionarray['__ONLINEPAYMENTLINK_ORDER__'] = getOnlinePaymentUrl(0, 'order', $obj->source_id); - $substitutionarray['__ONLINEPAYMENTLINK_INVOICE__'] = getOnlinePaymentUrl(0, 'invoice', $obj->source_id); - $substitutionarray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = getOnlinePaymentUrl(0, 'contractline', $obj->source_id); + $substitutionarray['__ONLINEPAYMENTLINK_MEMBER__'] = getHtmlOnlinePaymentLink('member', $obj->source_id); + $substitutionarray['__ONLINEPAYMENTLINK_DONATION__'] = getHtmlOnlinePaymentLink('donation', $obj->source_id); + $substitutionarray['__ONLINEPAYMENTLINK_ORDER__'] = getHtmlOnlinePaymentLink('order', $obj->source_id); + $substitutionarray['__ONLINEPAYMENTLINK_INVOICE__'] = getHtmlOnlinePaymentLink('invoice', $obj->source_id); + $substitutionarray['__ONLINEPAYMENTLINK_CONTRACTLINE__'] = getHtmlOnlinePaymentLink('contractline', $obj->source_id); $substitutionarray['__SECUREKEYPAYMENT__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2); if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { From fb3c8e698ed028cad7d5c707e1ea1c70343be14a Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 4 May 2021 20:59:32 +0000 Subject: [PATCH 6/6] Fixing style errors. --- htdocs/core/lib/payments.lib.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/htdocs/core/lib/payments.lib.php b/htdocs/core/lib/payments.lib.php index 90fba70464c..59d9eb4aa4c 100644 --- a/htdocs/core/lib/payments.lib.php +++ b/htdocs/core/lib/payments.lib.php @@ -27,7 +27,8 @@ * @param Paiement $object Current payment object * @return array Tabs for the payment section */ -function payment_prepare_head(Paiement $object) { +function payment_prepare_head(Paiement $object) +{ global $langs, $conf; $h = 0; @@ -61,7 +62,8 @@ function payment_prepare_head(Paiement $object) { * @param int $id ID of bank line * @return array Tabs for the Bankline section */ -function bankline_prepare_head($id) { +function bankline_prepare_head($id) +{ global $langs, $conf; $h = 0; @@ -95,7 +97,8 @@ function bankline_prepare_head($id) { * @param Paiement $object Current payment object * @return array Tabs for the payment section */ -function payment_supplier_prepare_head(Paiement $object) { +function payment_supplier_prepare_head(Paiement $object) +{ global $langs, $conf; $h = 0; @@ -128,7 +131,8 @@ function payment_supplier_prepare_head(Paiement $object) { * @param string $paymentmethod Filter on this payment method (''=none, 'paypal', ...) * @return array Array of valid payment method */ -function getValidOnlinePaymentMethods($paymentmethod = '') { +function getValidOnlinePaymentMethods($paymentmethod = '') +{ global $conf, $langs; $validpaymentmethod = array(); @@ -158,7 +162,8 @@ function getValidOnlinePaymentMethods($paymentmethod = '') { * @param string $ref Ref of object * @return string Url string */ -function showOnlinePaymentUrl($type, $ref) { +function showOnlinePaymentUrl($type, $ref) +{ global $langs; // Load translation files required by the page @@ -182,7 +187,8 @@ function showOnlinePaymentUrl($type, $ref) { * @param string $label Text or HTML tag to display, if empty it display the URL * @return string Url string */ -function getHtmlOnlinePaymentLink($type, $ref, $label='') { +function getHtmlOnlinePaymentLink($type, $ref, $label = '') +{ $url = getOnlinePaymentUrl(0, $type, $ref); $label = $label ? $label : $url; return''.$label.''; @@ -200,7 +206,8 @@ function getHtmlOnlinePaymentLink($type, $ref, $label='') { * @param string $localorexternal 0=Url for browser, 1=Url for external access * @return string Url string */ -function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_tag', $localorexternal = 0) { +function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_tag', $localorexternal = 0) +{ global $conf, $dolibarr_main_url_root; $ref = str_replace(' ', '', $ref); @@ -365,7 +372,8 @@ function getOnlinePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag * @param Object $object Object related to payment * @return void */ -function htmlPrintOnlinePaymentFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null) { +function htmlPrintOnlinePaymentFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null) +{ global $conf; // Juridical status