diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index ce5abc27416..7283f9c9db5 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -405,7 +405,7 @@ $tabhelp[21] = array('code'=>$langs->trans("EnterAnyCode")); $tabhelp[22] = array('code'=>$langs->trans("EnterAnyCode")); $tabhelp[23] = array(); $tabhelp[24] = array('code'=>$langs->trans("EnterAnyCode")); -$tabhelp[25] = array('type_template'=>$langs->trans("TemplateForElement"),'private'=>$langs->trans("TemplateIsVisibleByOwnerOnly"), 'position'=>$langs->trans("PositionIntoComboList")); +$tabhelp[25] = array('topic'=>$langs->trans('SeeSubstitutionVars'),'content'=>$langs->trans('SeeSubstitutionVars'),'type_template'=>$langs->trans("TemplateForElement"),'private'=>$langs->trans("TemplateIsVisibleByOwnerOnly"), 'position'=>$langs->trans("PositionIntoComboList")); $tabhelp[26] = array('code'=>$langs->trans("EnterAnyCode")); $tabhelp[27] = array('code'=>$langs->trans("EnterAnyCode")); $tabhelp[28] = array('affect'=>$langs->trans("FollowedByACounter"),'delay'=>$langs->trans("MinimumNoticePeriod"), 'newByMonth'=>$langs->trans("NbAddedAutomatically")); @@ -493,7 +493,7 @@ if ($id == 11) } if ($id == 25) { - // We save list of template type Dolibarr can manage. This list can found by a grep into code on "->param['models']" + // We save list of template email Dolibarr can manage. This list can found by a grep into code on "->param['models']" $elementList = array(); if ($conf->propal->enabled) $elementList['propal_send']=$langs->trans('MailToSendProposal'); if ($conf->commande->enabled) $elementList['order_send']=$langs->trans('MailToSendOrder'); @@ -1017,8 +1017,18 @@ if ($id) } print ''; print ""; + + if ($tabname[$id] == MAIN_DB_PREFIX.'c_email_templates') + { + print '* '.$langs->trans("AvailableVariables").": "; + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + $formmail=new FormMail($db); + $tmp=$formmail->getAvailableSubstitKey('form'); + print join(', ', $tmp); + print ''; + } - $colspan=count($fieldlist)+2; + $colspan=count($fieldlist)+3; if ($id == 4) $colspan++; if (! empty($alabelisused) && $id != 25) // If there is one label among fields, we show legend of * diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index b5f33b5f689..9a7d0349f41 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -32,6 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $langs->load("mails"); @@ -55,27 +56,7 @@ $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); $hookmanager->initHooks(array('mailingcard','globalcard')); // Array of possible substitutions (See also file mailing-send.php that should manage same substitutions) -$object->substitutionarray=array( - '__ID__' => 'IdRecord', - '__EMAIL__' => 'EMail', - '__LASTNAME__' => 'Lastname', - '__FIRSTNAME__' => 'Firstname', - '__MAILTOEMAIL__' => 'TagMailtoEmail', - '__OTHER1__' => 'Other1', - '__OTHER2__' => 'Other2', - '__OTHER3__' => 'Other3', - '__OTHER4__' => 'Other4', - '__OTHER5__' => 'Other5', - '__SIGNATURE__' => 'TagSignature', - '__CHECK_READ__' => 'TagCheckMail', - '__UNSUBSCRIBE__' => 'TagUnsubscribe' - //,'__PERSONALIZED__' => 'Personalized' // Hidden because not used yet -); -if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN)) -{ - $object->substitutionarray['__SECUREKEYPAYPAL__']='SecureKeyPaypal'; - if (! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $object->substitutionarray['__SECUREKEYPAYPAL_MEMBER__']='SecureKeyPaypalUniquePerMember'; -} +$object->substitutionarray=FormMail::getAvailableSubstitKey('emailing'); $object->substitutionarrayfortest=array( '__ID__' => 'TESTIdRecord', @@ -243,8 +224,18 @@ if (empty($reshook)) if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN)) { $substitutionarray['__SECUREKEYPAYPAL__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2); + if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2); else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2); + + if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2); + else $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'order' . $obj->source_id, 2); + + if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2); + else $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2); + + if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2); + else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2); } $substitutionisok=true; complete_substitutions_array($substitutionarray, $langs); diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 6821f6cd376..40a654fef0b 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -2445,13 +2445,8 @@ if ($action == 'create') $formmail->withcancel = 1; // Tableau des substitutions + $formmail->setSubstitFromObject($object); $formmail->substit['__PROPREF__'] = $object->ref; - $formmail->substit['__SIGNATURE__'] = $user->signature; - $formmail->substit['__REFCLIENT__'] = $object->ref_client; - $formmail->substit['__THIRDPARTY_NAME__'] = $object->thirdparty->name; - $formmail->substit['__PROJECT_REF__'] = (is_object($object->projet)?$object->projet->ref:''); - $formmail->substit['__PERSONALIZED__'] = ''; - $formmail->substit['__CONTACTCIVNAME__'] = ''; // Find the good contact adress $custcontact = ''; diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 308da237023..83e83c9bc5d 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -2667,13 +2667,8 @@ if ($action == 'create' && $user->rights->commande->creer) $formmail->withdeliveryreceipt = 1; $formmail->withcancel = 1; // Tableau des substitutions + $formmail->setSubstitFromObject($object); $formmail->substit ['__ORDERREF__'] = $object->ref; - $formmail->substit ['__SIGNATURE__'] = $user->signature; - $formmail->substit ['__REFCLIENT__'] = $object->ref_client; - $formmail->substit ['__THIRDPARTY_NAME__'] = $object->thirdparty->name; - $formmail->substit ['__PROJECT_REF__'] = (is_object($object->projet)?$object->projet->ref:''); - $formmail->substit ['__PERSONALIZED__'] = ''; - $formmail->substit ['__CONTACTCIVNAME__'] = ''; $custcontact = ''; $contactarr = array(); diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 2fcdfb7f6a0..7415aec80c2 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -4150,14 +4150,8 @@ else if ($id > 0 || ! empty($ref)) $formmail->withdeliveryreceipt = 1; $formmail->withcancel = 1; // Tableau des substitutions - $formmail->substit['__REF__'] = $object->ref; - $formmail->substit['__SIGNATURE__'] = $user->signature; - $formmail->substit['__REFCLIENT__'] = $object->ref_client; - $formmail->substit['__THIRDPARTY_NAME__'] = $object->thirdparty->name; - $formmail->substit['__PROJECT_REF__'] = (is_object($object->projet)?$object->projet->ref:''); - $formmail->substit['__PROJECT_NAME__'] = (is_object($object->projet)?$object->projet->title:''); - $formmail->substit['__PERSONALIZED__'] = ''; - $formmail->substit['__CONTACTCIVNAME__'] = ''; + $formmail->setSubstitFromObject($object); + $formmail->substit['__INVREF__'] = $object->ref; // Find the good contact adress $custcontact = ''; diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 8e7064d1893..eb8e7cf868c 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -657,9 +657,10 @@ class FormMail extends Form $langs->load('paypal'); + // Set the paypal message and url link into __PERSONALIZED__ key if ($this->param["models"]=='order_send') { - $url=getPaypalPaymentUrl(0,'order',$this->substit['__ORDERREF__']); + $url=getPaypalPaymentUrl(0,'order',$this->substit['__ORDERREF__']?$this->substit['__ORDERREF__']:$this->substit['__REF__']); $this->substit['__PERSONALIZED__']=str_replace('\n',"\n",$langs->transnoentitiesnoconv("PredefinedMailContentLink",$url)); } if ($this->param["models"]=='facture_send') @@ -908,8 +909,95 @@ class FormMail extends Form return -1; } } + + + + /** + * Set substit array from object + * + * @param Object $object Object to use + * @return void + */ + function setSubstitFromObject($object) + { + $this->substit['__REF__'] = $object->ref; + $this->substit['__SIGNATURE__'] = $user->signature; + $this->substit['__REFCLIENT__'] = $object->ref_client; + $this->substit['__THIRDPARTY_NAME__'] = $object->thirdparty->name; + $this->substit['__PROJECT_REF__'] = (is_object($object->projet)?$object->projet->ref:''); + $this->substit['__PROJECT_NAME__'] = (is_object($object->projet)?$object->projet->title:''); + $this->substit['__PERSONALIZED__'] = ''; + $this->substit['__CONTACTCIVNAME__'] = ''; // Will be replace just before sending + } + + /** + * Set substit array from object + * + * @param Object $object Object to use + * @param string $mode 'form' or 'emailing' + * @return void + */ + function getAvailableSubstitKey($mode='form') + { + global $conf; + + $vars=array(); + + if ($mode == 'form') + { + $vars=array( + '__REF__', + '__REFCLIENT__', + '__THIRDPARTY_NAME__', + '__PROJECT_REF__', + '__PROJECT_NAME__', + '__CONTACTCIVNAME__', + '__PERSONALIZED__', // Paypal link is added here + '__SIGNATURE__', + ); + } + if ($mode == 'emailing') + { + // For mass emailing, we have different keys + $vars=array( + '__ID__' => 'IdRecord', + '__EMAIL__' => 'EMail', + '__LASTNAME__' => 'Lastname', + '__FIRSTNAME__' => 'Firstname', + '__MAILTOEMAIL__' => 'TagMailtoEmail', + '__OTHER1__' => 'Other1', + '__OTHER2__' => 'Other2', + '__OTHER3__' => 'Other3', + '__OTHER4__' => 'Other4', + '__OTHER5__' => 'Other5', + '__SIGNATURE__' => 'TagSignature', + '__CHECK_READ__' => 'TagCheckMail', + '__UNSUBSCRIBE__' => 'TagUnsubscribe' + //,'__PERSONALIZED__' => 'Personalized' // Hidden because not used yet in mass emailing + ); + if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN)) + { + $vars['__SECUREKEYPAYPAL__']='SecureKeyPaypal'; + if (! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) + { + if ($conf->adherent->enabled) $vars['__SECUREKEYPAYPAL_MEMBER__']='SecureKeyPaypalUniquePerMember'; + if ($conf->facture->enabled) $vars['__SECUREKEYPAYPAL_INVOICE__']='SecureKeyPaypalUniquePerInvoice'; + if ($conf->commande->enabled) $vars['__SECUREKEYPAYPAL_ORDER__']='SecureKeyPaypalUniquePerOrder'; + if ($conf->contrat->enabled) $vars['__SECUREKEYPAYPAL_CONTRACTLINE__']='SecureKeyPaypalUniquePerContractLine'; + } + } + else + { + $vars['__SECUREKEYPAYPAL__']=''; + $vars['__SECUREKEYPAYPAL_MEMBER__']=''; + } + } + return $vars; + } + } + /** * ModelMail */ diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index e51841ed499..4c71256baf3 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -1895,10 +1895,8 @@ else if ($id || $ref) $formmail->withdeliveryreceipt=1; $formmail->withcancel=1; // Tableau des substitutions + $formmail->setSubstitFromObject($object); $formmail->substit['__SHIPPINGREF__']=$object->ref; - $formmail->substit['__SIGNATURE__']=$user->signature; - $formmail->substit['__PERSONALIZED__']=''; - $formmail->substit['__CONTACTCIVNAME__']=''; //Find the good contact adress //Find the good contact adress diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index 8d164adaa41..cee1d54d70c 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -1866,10 +1866,8 @@ else if ($id > 0 || ! empty($ref)) $formmail->withcancel=1; // Tableau des substitutions + $formmail->setSubstitFromObject($object); $formmail->substit['__FICHINTERREF__']=$object->ref; - $formmail->substit['__SIGNATURE__']=$user->signature; - $formmail->substit['__PERSONALIZED__']=''; - $formmail->substit['__CONTACTCIVNAME__']=''; //Find the good contact adress $custcontact=''; diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 12924285d37..6c7d3ef1b35 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -2481,13 +2481,9 @@ elseif (! empty($object->id)) $object->fetch_projet(); // Tableau des substitutions - $formmail->substit['__ORDERREF__']=$object->ref; - $formmail->substit['__ORDERSUPPLIERREF__']=$object->ref_supplier; - $formmail->substit['__THIRDPARTY_NAME__'] = $object->thirdparty->name; - $formmail->substit['__PROJECT_REF__'] = (is_object($object->projet)?$object->projet->ref:''); - $formmail->substit['__SIGNATURE__']=$user->signature; - $formmail->substit['__PERSONALIZED__']=''; - $formmail->substit['__CONTACTCIVNAME__']=''; + $formmail->setSubstitFromObject($object); + $formmail->substit['__ORDERSUPPLIERREF__']=$object->ref_supplier; // For backward compatibility + $formmail->substit['__SUPPLIERORDERREF__']=$object->ref_supplier; //Find the good contact adress $custcontact=''; diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index cf1d138dcde..8d9556a72c6 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -2474,11 +2474,9 @@ else $formmail->withbody=1; $formmail->withdeliveryreceipt=1; $formmail->withcancel=1; - // Tableau des substitutions - $formmail->substit['__REF__']=$object->ref; - $formmail->substit['__SIGNATURE__']=$user->signature; - $formmail->substit['__PERSONALIZED__']=''; - $formmail->substit['__CONTACTCIVNAME__']=''; + // Tableau des substitutions + $formmail->setSubstitFromObject($object); + $formmail->substit['__SUPPLIERINVREF__']=$object->ref; //Find the good contact adress $custcontact=''; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 456c8f83c96..6e547d78f6a 100755 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1714,4 +1714,5 @@ ExampleOfNewsMessageForMajorRelease=Dolibarr ERP & CRM %s is available. Version ExampleOfNewsMessageForMaintenanceRelease=Dolibarr ERP & CRM %s is available. Version %s is a maintenance version, so it contains only fixes of bugs. We recommend everybody using an older version to upgrade to this one. As any maintenance release, no new features, nor data structure change is present into this version. You can download it from the download area of http://www.dolibarr.org portal (subdirectory Stable versions). You can read ChangeLog for complete list of changes. MultiPriceRuleDesc=When option "Several level of prices per product/service" is on, you can define different prices (one per price level) for each product. To save you time, you can enter here rule to have price for each level autocalculated according to price of first level, so you will have to enter only price for first level on each product. This page is here to save you time and can be usefull only if your prices for each leve are relative to first level. You can ignore this page in most cases. ModelModulesProduct=Templates for product documents -ToGenerateCodeDefineAutomaticRuleFirst=To be able to generate automatically codes, you must first define a manager to auto define barcode number. \ No newline at end of file +ToGenerateCodeDefineAutomaticRuleFirst=To be able to generate automatically codes, you must first define a manager to auto define barcode number. +SeeSubstitutionVars=See * note for list of possible substitution variables \ No newline at end of file diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index e5f7e54e191..d185e84af00 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -25,6 +25,7 @@ FormatDateHourTextShort=%b %d, %Y, %I:%M %p FormatDateHourText=%B %d, %Y, %I:%M %p DatabaseConnection=Database connection NoTemplateDefined=No template defined for this email type +AvailableVariables=Available substitution variables NoTranslation=No translation NoRecordFound=No record found NoError=No error diff --git a/htdocs/paypal/lib/paypal.lib.php b/htdocs/paypal/lib/paypal.lib.php index f06624cb076..b51086b8e07 100644 --- a/htdocs/paypal/lib/paypal.lib.php +++ b/htdocs/paypal/lib/paypal.lib.php @@ -249,8 +249,8 @@ function getPaypalPaymentUrl($mode,$type,$ref='',$amount='9.99',$freetag='your_f else { $out.='&securekey='.($mode?'':''); - if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + 'order' + order_ref)"; - if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'order' . $ref, 2); + if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + order_ref)"; + if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2); $out.=($mode?'':''); } } @@ -267,8 +267,8 @@ function getPaypalPaymentUrl($mode,$type,$ref='',$amount='9.99',$freetag='your_f else { $out.='&securekey='.($mode?'':''); - if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + 'invoice' + invoice_ref)"; - if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'invoice' . $ref, 2); + if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + invoice_ref)"; + if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2); $out.=($mode?'':''); } } @@ -285,8 +285,8 @@ function getPaypalPaymentUrl($mode,$type,$ref='',$amount='9.99',$freetag='your_f else { $out.='&securekey='.($mode?'':''); - if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + 'contactline' + contractline_ref)"; - if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $ref, 2); + if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + contractline_ref)"; + if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2); $out.=($mode?'':''); } } @@ -303,8 +303,8 @@ function getPaypalPaymentUrl($mode,$type,$ref='',$amount='9.99',$freetag='your_f else { $out.='&securekey='.($mode?'':''); - if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + 'membersubscription' + member_ref)"; - if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $ref, 2); + if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + member_ref)"; + if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2); $out.=($mode?'':''); } } diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php index e20093d8162..5411cee24b6 100644 --- a/htdocs/supplier_proposal/card.php +++ b/htdocs/supplier_proposal/card.php @@ -1930,12 +1930,8 @@ if ($action == 'create') $formmail->withcancel = 1; // Tableau des substitutions - $formmail->substit['__ASKREF__'] = $object->ref; - $formmail->substit['__SIGNATURE__'] = $user->signature; - $formmail->substit['__THIRDPARTY_NAME__'] = $object->thirdparty->name; - $formmail->substit['__PROJECT_REF__'] = (is_object($object->projet)?$object->projet->ref:''); - $formmail->substit['__CONTACTCIVNAME__'] = ''; - $formmail->substit['__PERSONALIZED__'] = ''; + $formmail->setSubstitFromObject($object); + $formmail->substit['__SUPPLIERPROPREF__'] = $object->ref; // Tableau des parametres complementaires $formmail->param['action'] = 'send';