From 35938b194242d893c61d6e1035f8fcfd9064ce94 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 21 Mar 2018 20:06:22 +0100 Subject: [PATCH] NEW Variable __ONLINE_PAYMENT_URL__ available in email templates --- htdocs/core/class/html.formmail.class.php | 3 +- htdocs/core/lib/functions.lib.php | 79 ++++++++++++++--------- htdocs/core/lib/payments.lib.php | 2 +- htdocs/holiday/class/holiday.class.php | 14 ++-- htdocs/langs/en_US/members.lang | 2 +- htdocs/public/payment/newpayment.php | 4 +- 6 files changed, 60 insertions(+), 44 deletions(-) diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index a5446440f31..33aab58eb2e 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -865,7 +865,7 @@ class FormMail extends Form } } - // Complete substitution array + // Complete substitution array with the url to make online payment $paymenturl=''; if (empty($this->substit['__REF__'])) { @@ -883,7 +883,6 @@ class FormMail extends Form $url=getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit['__REF__']); $paymenturl=$url; } - $this->substit['__ONLINE_PAYMENT_URL__']=$paymenturl; //Add lines substitution key from each line diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 88859c21298..746f6c55f13 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5729,11 +5729,31 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob $substitutionarray=array(); - if (empty($exclude) || ! in_array('system', $exclude)) + if (empty($exclude) || ! in_array('user', $exclude)) { - $substitutionarray['__(AnyTranslationKey)__']=$outputlangs->trans('TranslationOfKey'); - $substitutionarray['__[AnyConstantKey]__']=$outputlangs->trans('ValueOfConstant'); - $substitutionarray['__DOL_MAIN_URL_ROOT__']=DOL_MAIN_URL_ROOT; + // Add SIGNATURE into substitutionarray first, so, when we will make the substitution, + // this will include signature content first and then replace var found into content of signature + $signature = $user->signature; + $substitutionarray=array_merge($substitutionarray, array( + '__USER_SIGNATURE__' => (string) (($signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ? dol_trunc(dol_string_nohtmltag($signature), 30) : $signature) : '') + ) + ); + // For backward compatibility + if ($onlykey != 2) + { + $substitutionarray['__SIGNATURE__'] = (string) (($signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ? dol_trunc(dol_string_nohtmltag($signature), 30) : $signature) : ''); + } + + $substitutionarray=array_merge($substitutionarray, array( + '__USER_ID__' => (string) $user->id, + '__USER_LOGIN__' => (string) $user->login, + '__USER_LASTNAME__' => (string) $user->lastname, + '__USER_FIRSTNAME__' => (string) $user->firstname, + '__USER_FULLNAME__' => (string) $user->getFullName($outputlangs), + '__USER_SUPERVISOR_ID__' => (string) ($user->fk_user ? $user->fk_user : '0'), + '__USER_REMOTE_IP__' => (string) $_SERVER['REMOTE_ADDR'] + ) + ); } if ((empty($exclude) || ! in_array('mycompany', $exclude)) && is_object($mysoc)) { @@ -5804,7 +5824,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob $substitutionarray['__REFCLIENT__'] = (isset($object->ref_client) ? $object->ref_client : (isset($object->ref_customer) ? $object->ref_customer : '')); $substitutionarray['__REFSUPPLIER__'] = (isset($object->ref_supplier) ? $object->ref_supplier : ''); - // TODO USe this ? + // TODO Use this ? $msgishtml = 0; $birthday = dol_print_date($object->birth,'day'); @@ -5881,7 +5901,26 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob } } - $substitutionarray['__ONLINE_PAYMENT_URL__'] = 'TODO'; + // Complete substitution array with the url to make online payment + $paymenturl=''; + if (empty($substitutionarray['__REF__'])) + { + $paymenturl=''; + } + else + { + // Set the online payment url link into __ONLINE_PAYMENT_URL__ key + require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; + $outputlangs->load('paypal'); + $typeforonlinepayment='free'; + if (is_object($object) && $object->element == 'commande') $typeforonlinepayment='order'; + if (is_object($object) && $object->element == 'facture') $typeforonlinepayment='invoice'; + if (is_object($object) && $object->element == 'member') $typeforonlinepayment='member'; + $url=getOnlinePaymentUrl(0, $typeforonlinepayment, $substitutionarray['__REF__']); + $paymenturl=$url; + } + + $substitutionarray['__ONLINE_PAYMENT_URL__']=$paymenturl; } } if (empty($exclude) || ! in_array('objectamount', $exclude)) @@ -5931,31 +5970,11 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob )); } - if (empty($exclude) || ! in_array('user', $exclude)) + if (empty($exclude) || ! in_array('system', $exclude)) { - // Add SIGNATURE into substitutionarray first, so, when we will make the substitution, - // this will also replace var found into content of signature - $signature = $user->signature; - $substitutionarray=array_merge($substitutionarray, array( - '__USER_SIGNATURE__' => (string) (($signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ? dol_trunc(dol_string_nohtmltag($signature), 30) : $signature) : '') - ) - ); - // For backward compatibility - if ($onlykey != 2) - { - $substitutionarray['__SIGNATURE__'] = (string) (($signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ? dol_trunc(dol_string_nohtmltag($signature), 30) : $signature) : ''); - } - - $substitutionarray=array_merge($substitutionarray, array( - '__USER_ID__' => (string) $user->id, - '__USER_LOGIN__' => (string) $user->login, - '__USER_LASTNAME__' => (string) $user->lastname, - '__USER_FIRSTNAME__' => (string) $user->firstname, - '__USER_FULLNAME__' => (string) $user->getFullName($outputlangs), - '__USER_SUPERVISOR_ID__' => (string) ($user->fk_user ? $user->fk_user : '0'), - '__USER_REMOTE_IP__' => (string) $_SERVER['REMOTE_ADDR'] - ) - ); + $substitutionarray['__(AnyTranslationKey)__']=$outputlangs->trans('TranslationOfKey'); + $substitutionarray['__[AnyConstantKey]__']=$outputlangs->trans('ValueOfConstant'); + $substitutionarray['__DOL_MAIN_URL_ROOT__']=DOL_MAIN_URL_ROOT; } if (! empty($conf->multicompany->enabled)) { diff --git a/htdocs/core/lib/payments.lib.php b/htdocs/core/lib/payments.lib.php index 73f8e507caf..dbcce928ccf 100644 --- a/htdocs/core/lib/payments.lib.php +++ b/htdocs/core/lib/payments.lib.php @@ -190,7 +190,7 @@ function getOnlinePaymentUrl($mode, $type, $ref='', $amount='9.99', $freetag='yo } } } - if ($type == 'membersubscription') + if ($type == 'member' || $type == 'membersubscription') { $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=membersubscription&ref='.($mode?'':''); if ($mode == 1) $out.='member_ref'; diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index 67ef15c74ef..1e12f9f87eb 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -276,12 +276,12 @@ class Holiday extends CommonObject } /** - * List holidays for a particular user + * List holidays for a particular user or list of users * - * @param int $user_id ID of user to list - * @param string $order Sort order - * @param string $filter SQL Filter - * @return int -1 if KO, 1 if OK, 2 if no result + * @param int|string $user_id ID of user to list, or comma separated list of IDs of users to list + * @param string $order Sort order + * @param string $filter SQL Filter + * @return int -1 if KO, 1 if OK, 2 if no result */ function fetchByUser($user_id, $order='', $filter='') { @@ -321,8 +321,8 @@ class Holiday extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua"; $sql.= " WHERE cp.entity IN (".getEntity('holiday').")"; - $sql.= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau - $sql.= " AND cp.fk_user = ".$user_id; + $sql.= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid"; // Hack pour la recherche sur le tableau + $sql.= " AND cp.fk_user IN (".$user_id.")"; // Filtre de séléction if(!empty($filter)) { diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang index b6e872097b5..befb763d60c 100644 --- a/htdocs/langs/en_US/members.lang +++ b/htdocs/langs/en_US/members.lang @@ -183,4 +183,4 @@ EmailSentToMember=Email sent to member at %s SendReminderForExpiredSubscriptionTitle=Send reminder by email for expired subscription SendReminderForExpiredSubscription=Send reminder by email to members when subscription is about to expire (parameter is number of days before end of subscription to send the remind) YourSubscriptionHasExpired=Your subscription has expired -ThisIsContentOfSubscriptionReminderEmail=This is a email to remind you that your subscription is about to expire. +ThisIsContentOfSubscriptionReminderEmail=This is an email to remind you that your subscription is about to expire. diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 7dbd85bf29b..1a7b336b4bc 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -46,7 +46,7 @@ require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php'; // Security check // No check on module enabled. Done later according to $validpaymentmethod -$langs->loadLangs(array("main","other","dict","bills","companies","errors","paybox")); // File with generic data +$langs->loadLangs(array("main","other","dict","bills","companies","errors","paybox","paypal")); // File with generic data $action=GETPOST('action','aZ09'); @@ -157,8 +157,6 @@ $urlko=preg_replace('/&$/','',$urlko); // Remove last & if (! empty($conf->paypal->enabled)) { - $langs->load("paypal"); - require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php'; require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypalfunctions.lib.php';