浏览代码

Mutualize code of substitutions for emails

Laurent Destailleur 7 年之前
父节点
当前提交
252f038468

+ 4 - 2
htdocs/admin/mails_templates.php

@@ -835,6 +835,8 @@ if ($resql)
                         if ($value == 'private')
                         {
                         	$align="center";
+                        	if ($valuetoshow) $valuetoshow=yn($valuetoshow);
+                        	else $valuetoshow='';
                         }
                         if ($value == 'position')
                         {
@@ -1042,12 +1044,12 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='')
 			{
 				if (empty($user->admin))
 				{
-					print $form->selectyesno($fieldlist[$field], '1');
+					print $form->selectyesno($fieldlist[$field], '1', 1);
 				}
 				else
 				{
 					//print '<input type="text" '.$size.'class="flat'.($class?' '.$class:'').'" value="1" name="'.$fieldlist[$field].'">';
-					print $form->selectyesno($fieldlist[$field], (isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
+					print $form->selectyesno($fieldlist[$field], (isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''), 1);
 				}
 			}
 			else

+ 51 - 48
htdocs/comm/mailing/card.php

@@ -57,24 +57,17 @@ $hookmanager->initHooks(array('mailingcard','globalcard'));
 
 // Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
 $object->substitutionarray=FormMail::getAvailableSubstitKey('emailing');
-$object->substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
-
-$object->substitutionarrayfortest=array(
-    '__ID__' => 'TESTIdRecord',
-    //'__EMAIL__' => 'TESTEMail',			// Done into "send" action
-    '__LASTNAME__' => 'TESTLastname',
-    '__FIRSTNAME__' => 'TESTFirstname',
-    '__MAILTOEMAIL__' => 'TESTMailtoEmail',
-    '__OTHER1__' => 'TESTOther1',
-    '__OTHER2__' => 'TESTOther2',
-    '__OTHER3__' => 'TESTOther3',
-    '__OTHER4__' => 'TESTOther4',
-    '__OTHER5__' => 'TESTOther5',
-	'__SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$user->signature:''),
-    '__CHECK_READ__' => 'TagCheckMail',
-	'__UNSUBSCRIBE__' => 'TagUnsubscribe'
-		//,'__PERSONALIZED__' => 'TESTPersonalized'	// Not used yet
-);
+
+
+// Set $object->substitutionarrayfortest
+$signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$user->signature:'');
+
+$targetobject = null;		// Not defined with mass emailing
+
+$parameters=array('mode'=>'emailing');
+$substitutionarray=FormMail::getAvailableSubstitKey('emailing', $targetobject);
+
+$object->substitutionarrayfortest = $substitutionarray;
 
 // List of sending methods
 $listofmethods=array();
@@ -205,24 +198,28 @@ if (empty($reshook))
 	                    $tmpfield=explode('=',$other[2],2); $other3=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
 	                    $tmpfield=explode('=',$other[3],2); $other4=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
 	                    $tmpfield=explode('=',$other[4],2); $other5=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
+
 	                    $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$user->signature:'');
 
-	                    // Array of possible substitutions (See also fie mailing-send.php that should manage same substitutions)
-						$substitutionarray=array(
-								'__ID__' => $obj->source_id,
-								'__EMAIL__' => $obj->email,
-								'__LASTNAME__' => $obj->lastname,
-								'__FIRSTNAME__' => $obj->firstname,
-								'__MAILTOEMAIL__' => '<a href="mailto:'.$obj->email.'">'.$obj->email.'</a>',
-								'__OTHER1__' => $other1,
-								'__OTHER2__' => $other2,
-								'__OTHER3__' => $other3,
-								'__OTHER4__' => $other4,
-								'__OTHER5__' => $other5,
-								'__SIGNATURE__' => $signature,	// Signature is empty when ran from command line or taken from user in parameter)
-								'__CHECK_READ__' => '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>',
-								'__UNSUBSCRIBE__' => '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>'
-						);
+	                    $targetobject = null;		// Not defined with mass emailing
+	                    $parameters=array('mode'=>'emailing');
+	                    $substitutionarray=getCommonSubstitutionArray($langs, 2, array('object','objectamount'), $targetobject);			// Note: On mass emailing, this is null because be don't know object
+
+	                    // Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
+						$substitutionarray['__ID__'] = $obj->source_id;
+						$substitutionarray['__EMAIL__'] = $obj->email;
+						$substitutionarray['__LASTNAME__'] = $obj->lastname;
+						$substitutionarray['__FIRSTNAME__'] = $obj->firstname;
+						$substitutionarray['__MAILTOEMAIL__'] = '<a href="mailto:'.$obj->email.'">'.$obj->email.'</a>';
+						$substitutionarray['__OTHER1__'] = $other1;
+						$substitutionarray['__OTHER2__'] = $other2;
+						$substitutionarray['__OTHER3__'] = $other3;
+						$substitutionarray['__OTHER4__'] = $other4;
+						$substitutionarray['__OTHER5__'] = $other5;
+						$substitutionarray['__SIGNATURE__'] = $signature;	// Signature is empty when ran from command line or taken from user in parameter)
+						$substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
+						$substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>';
+
 						$onlinepaymentenabled = 0;
 						if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
 						if (! empty($conf->paybox->enabled)) $onlinepaymentenabled++;
@@ -230,18 +227,20 @@ if (empty($reshook))
 						if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
 						{
 							$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);
-							else $substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
-
-							if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
-							else $substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
-
-							if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
-							else $substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
-
-							if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
-							else $substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
+							if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
+							{
+								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=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_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);
+							}
 						}
 						/* For backward compatibility */
 						if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN))
@@ -261,6 +260,7 @@ if (empty($reshook))
 							else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
 						}
 						//$substitutionisok=true;
+
 	                    complete_substitutions_array($substitutionarray, $langs);
 						$newsubject=make_substitutions($subject,$substitutionarray);
 						$newmessage=make_substitutions($message,$substitutionarray);
@@ -431,9 +431,12 @@ if (empty($reshook))
 			$msgishtml=-1;	// Inconnu par defaut
 			if (preg_match('/[\s\t]*<html>/i',$object->body)) $msgishtml=1;
 
-			$object->substitutionarrayfortest['__EMAIL__'] = $object->sendto;		// other are set at begin of page
+			// other are set at begin of page
+			$object->substitutionarrayfortest['__EMAIL__'] = $object->sendto;
+			$object->substitutionarrayfortest['__MAILTOEMAIL__'] = '<a href="mailto:'.$object->sendto.'">'.$object->sendto.'</a>';
 
 			// Pratique les substitutions sur le sujet et message
+	        complete_substitutions_array($object->substitutionarrayfortest, $langs);
 			$tmpsujet=make_substitutions($object->sujet,$object->substitutionarrayfortest);
 			$tmpbody=make_substitutions($object->body,$object->substitutionarrayfortest);
 
@@ -1073,7 +1076,7 @@ else
 				$formmail->substit=$object->substitutionarrayfortest;
 				// Tableau des parametres complementaires du post
 				$formmail->param["action"]="send";
-				$formmail->param["models"]="body";
+				$formmail->param["models"]='none';
 				$formmail->param["mailid"]=$object->id;
 				$formmail->param["returnurl"]=$_SERVER['PHP_SELF']."?id=".$object->id;
 

+ 2 - 2
htdocs/contrat/card.php

@@ -2251,7 +2251,7 @@ else
 			}
 			$formmail->substit['__CONTRACT_NEXT_EXPIRATION_DATE__'] = dol_print_date($datenextexpiration, 'dayrfc');
 			$formmail->substit['__CONTRACT_NEXT_EXPIRATION_DATETIME__'] = dol_print_date($datenextexpiration, 'standard');
-			$formmail->substit['__PERSONALIZED__']='';
+			$formmail->substit['__PERSONALIZED__']='';		// deprecated
 			$formmail->substit['__CONTACTCIVNAME__']='';
 
 			$custcontact = '';
@@ -2276,7 +2276,7 @@ else
 
 			// Tableau des parametres complementaires
 			$formmail->param['action'] = 'send';
-			$formmail->param['models'] = 'contract_send';
+			$formmail->param['models'] = 'contract';
 			$formmail->param['models_id']=GETPOST('modelmailselected','int');
 			$formmail->param['contractid'] = $object->id;
 			$formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id;

+ 1 - 1
htdocs/core/class/html.form.class.php

@@ -5828,7 +5828,7 @@ class Form
      *  @param	int      	$useempty		1=Add empty line
      *	@return	string						See option
      */
-    function selectyesno($htmlname,$value='',$option=0,$disabled=false,$useempty='')
+    function selectyesno($htmlname, $value='', $option=0, $disabled=false, $useempty='')
     {
         global $langs;
 

+ 66 - 114
htdocs/core/class/html.formmail.class.php

@@ -293,13 +293,17 @@ class FormMail extends Form
 			}
 
         	// Get message template for $this->param["models"] into c_email_templates
-			$model_id=0;
-        	if (array_key_exists('models_id',$this->param))
-        	{
-        		$model_id=$this->param["models_id"];
-        	}
-        	$arraydefaultmessage=$this->getEMailTemplate($this->db, $this->param["models"], $user, $outputlangs, $model_id);
-			//var_dump($this->param["models"]);
+			$arraydefaultmessage=array();
+			if ($this->param['models'] != 'none')
+			{
+				$model_id=0;
+        		if (array_key_exists('models_id',$this->param))
+        		{
+	        		$model_id=$this->param["models_id"];
+        		}
+	        	$arraydefaultmessage=$this->getEMailTemplate($this->db, $this->param["models"], $user, $outputlangs, $model_id);
+			}
+        	//var_dump($this->param["models"]);
         	//var_dump($model_id);
         	//var_dump($arraydefaultmessage);
 
@@ -325,18 +329,21 @@ class FormMail extends Form
         		$out.= '<input type="hidden" id="'.$key.'" name="'.$key.'" value="'.$value.'" />'."\n";
         	}
 
-        	$result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs);
-        	if ($result < 0)
+        	if ($this->param['models'] != 'none')
         	{
-        		setEventMessages($this->error, $this->errors, 'errors');
-        	}
-        	$modelmail_array=array();
-        	foreach($this->lines_model as $line)
-        	{
-        		$modelmail_array[$line->id]=$line->label;
-        		if ($line->lang) $modelmail_array[$line->id].=' ('.$line->lang.')';
-        		if ($line->private) $modelmail_array[$line->id].=' - '.$langs->trans("Private");
-        		//if ($line->fk_user != $user->id) $modelmail_array[$line->id].=' - '.$langs->trans("By").' ';
+	        	$result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs);
+	        	if ($result < 0)
+	        	{
+	        		setEventMessages($this->error, $this->errors, 'errors');
+	        	}
+	        	$modelmail_array=array();
+	        	foreach($this->lines_model as $line)
+	        	{
+	        		$modelmail_array[$line->id]=$line->label;
+	        		if ($line->lang) $modelmail_array[$line->id].=' ('.$line->lang.')';
+	        		if ($line->private) $modelmail_array[$line->id].=' - '.$langs->trans("Private");
+	        		//if ($line->fk_user != $user->id) $modelmail_array[$line->id].=' - '.$langs->trans("By").' ';
+	        	}
         	}
 
         	// Zone to select its email template
@@ -769,7 +776,7 @@ class FormMail extends Form
 	       				$paymenturl=$url;
         			}
         		}
-        		$this->substit['__PERSONALIZED__']=$paymenturl;
+        		$this->substit['__PERSONALIZED__']=$paymenturl;			// deprecated
         		$this->substit['__ONLINE_PAYMENT_URL__']=$paymenturl;
 
                 //Add lines substitution key from each line
@@ -1038,8 +1045,7 @@ class FormMail extends Form
 
 
 	/**
-	 * Set substit array from object. This is call when suggesting the email template into forms to send email.
-	 * TODO Replace with getCommonSubstitutionArray with param onlykey = 2
+	 * Set substit array from object. This is call when suggesting the email template into forms before sending email.
 	 *
 	 * @param	CommonObject	$object		   Object to use
 	 * @param   Translate  		$outputlangs   Object lang
@@ -1049,34 +1055,12 @@ class FormMail extends Form
 	function setSubstitFromObject($object, $outputlangs=null)
 	{
 		global $conf, $user;
-		$this->substit['__REF__'] = $object->ref;
-		$this->substit['__REFCLIENT__'] = isset($object->ref_client) ? $object->ref_client : (isset($object->ref_customer) ? $object->ref_customer : '');
-		$this->substit['__REFSUPPLIER__'] = isset($object->ref_supplier) ? $object->ref_supplier : '';
-
-		$this->substit['__DATE_YMD__'] = isset($object->date) ? dol_print_date($object->date, 'day', 0, $outputlangs) : '';
-		$this->substit['__DATE_DUE_YMD__'] = isset($object->date_lim_reglement)? dol_print_date($object->date_lim_reglement, 'day', 0, $outputlangs) : '';
-		$this->substit['__AMOUNT__'] = price($object->total_ttc);
-		$this->substit['__AMOUNT_EXCL_TAX__'] = price($object->total_ht);
-		$this->substit['__AMOUNT_VAT__'] = price($object->total_tva);
-
-		$this->substit['__THIRDPARTY_ID__'] = (is_object($object->thirdparty)?$object->thirdparty->id:'');
-		$this->substit['__THIRDPARTY_NAME__'] = (is_object($object->thirdparty)?$object->thirdparty->name:'');
-
-		$this->substit['__PROJECT_ID__'] = (is_object($object->projet)?$object->projet->id:'');
-		$this->substit['__PROJECT_REF__'] = (is_object($object->projet)?$object->projet->ref:'');
-		$this->substit['__PROJECT_NAME__'] = (is_object($object->projet)?$object->projet->title:'');
-
-		$this->substit['__SIGNATURE__'] = $user->signature;
-		$this->substit['__PERSONALIZED__'] = '';
-		$this->substit['__CONTACTCIVNAME__'] = '';	// Will be replace just before sending
-
-        // Create dynamic tags for __EXTRAFIELD_FIELD__
-        $extrafields = new ExtraFields($this->db);
-        $extralabels = $extrafields->fetch_name_optionals_label($object->table_element, true);
-        $object->fetch_optionals($object->id, $extralabels);
-        foreach ($extrafields->attribute_label as $key => $label) {
-            $this->substit['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key];
-        }
+
+		$parameters=array('mode'=>$mode);
+		$tmparray=getCommonSubstitutionArray($outputlangs, 0, null, $object);
+		complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
+
+		$this->substit=$tmparray;
 
         // Fill substit_lines with each object lines content
         if (is_array($object->lines))
@@ -1127,55 +1111,43 @@ class FormMail extends Form
 	{
 		global $conf, $langs;
 
-		$vars=array();
-
 		if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines')
 		{
-			$vars=array(
-				'__REF__'=>'__REF__',
-				'__REFCLIENT__'=>'__REFCLIENT__',
-				'__REFSUPPLIER__'=>'__REFSUPPLIER__',
-			    '__THIRDPARTY_ID__'=>'__THIRDPARTY_ID__',
-			    '__THIRDPARTY_NAME__'=>'__THIRDPARTY_NAME__',
-			    '__PROJECT_ID__'=>'__PROJECT_ID__',
-			    '__PROJECT_REF__'=>'__PROJECT_REF__',
-			    '__PROJECT_NAME__'=>'__PROJECT_NAME__',
-				'__CONTACTCIVNAME__'=>'__CONTACTCIVNAME__',
-				'__AMOUNT__'=>'__AMOUNT__',
-				'__AMOUNT_EXCL_TAX__'=>'__AMOUNT_EXCL_TAX__',
-				'__AMOUNT_VAT__'=>'__AMOUNT_VAT__',
-				'__ONLINE_PAYMENT_URL__'=>'__ONLINE_PAYMENT_URL__',
-				'__SIGNATURE__'=>'__SIGNATURE__',
-			    '__PERSONALIZED__'=>'__PERSONALIZED__',					// deprecated
-			);
+			$parameters=array('mode'=>$mode);
+			$tmparray=getCommonSubstitutionArray($langs, 2, null, $object);			// Note: On email templated edition, this is null because it is related to all type of objects
+			complete_substitutions_array($tmparray, $langs, null, $parameters);
+
 			if ($mode == 'formwithlines')
 			{
-			    $vars[] = '__LINES__';      // Will be set by the get_form function
+			    $tmparray['__LINES__'] = '__LINES__';      // Will be set by the get_form function
 			}
 			if ($mode == 'formforlines')
 			{
-			    $vars[] = '__QUANTITY__';   // Will be set by the get_form function
+			    $tmparray['__QUANTITY__'] = '__QUANTITY__';   // Will be set by the get_form function
 			}
 		}
+
 		if ($mode == 'emailing')
 		{
+			$parameters=array('mode'=>$mode);
+			$tmparray=getCommonSubstitutionArray($langs, 2, array('object','objectamount'), $object);			// Note: On email templated edition, this is null because it is related to all type of objects
+			complete_substitutions_array($tmparray, $langs, null, $parameters);
+
 			// For mass emailing, we have different keys
-			$vars=array(
-			    '__ID__' => 'IdRecord',
-			    '__EMAIL__' => 'EMailRecipient',
-			    '__LASTNAME__' => 'Lastname',
-			    '__FIRSTNAME__' => 'Firstname',
-			    '__MAILTOEMAIL__' => 'TagMailtoEmail',
-			    '__OTHER1__' => 'Other1',
-			    '__OTHER2__' => 'Other2',
-			    '__OTHER3__' => 'Other3',
-			    '__OTHER4__' => 'Other4',
-			    '__OTHER5__' => 'Other5',
-			    '__SIGNATURE__' => 'TagSignature',
-			    '__CHECK_READ__' => 'TagCheckMail',
-				'__UNSUBSCRIBE__' => 'TagUnsubscribe'
+			$tmparray['__ID__'] = 'IdRecord';
+			$tmparray['__EMAIL__'] = 'EMailRecipient';
+			$tmparray['__LASTNAME__'] = 'Lastname';
+			$tmparray['__FIRSTNAME__'] = 'Firstname';
+			$tmparray['__MAILTOEMAIL__'] = 'TagMailtoEmail';
+			$tmparray['__OTHER1__'] = 'Other1';
+			$tmparray['__OTHER2__'] = 'Other2';
+			$tmparray['__OTHER3__'] = 'Other3';
+			$tmparray['__OTHER4__'] = 'Other4';
+			$tmparray['__OTHER5__'] = 'Other5';
+			$tmparray['__SIGNATURE__'] = 'TagSignature';
+			$tmparray['__CHECK_READ__'] = 'TagCheckMail';
+			$tmparray['__UNSUBSCRIBE__'] = 'TagUnsubscribe';
 				//,'__PERSONALIZED__' => 'Personalized'	// Hidden because not used yet in mass emailing
-			);
 
 			$onlinepaymentenabled = 0;
 			if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
@@ -1183,13 +1155,13 @@ class FormMail extends Form
 			if (! empty($conf->stripe->enabled)) $onlinepaymentenabled++;
 			if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
 			{
-				$vars['__SECUREKEYPAYMENT__']=$conf->global->PAYMENT_SECURITY_TOKEN;
+				$tmparray['__SECUREKEYPAYMENT__']=$conf->global->PAYMENT_SECURITY_TOKEN;
 				if (! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
 				{
-					if ($conf->adherent->enabled) $vars['__SECUREKEYPAYMENT_MEMBER__']='SecureKeyPAYMENTUniquePerMember';
-					if ($conf->facture->enabled)  $vars['__SECUREKEYPAYMENT_INVOICE__']='SecureKeyPAYMENTUniquePerInvoice';
-					if ($conf->commande->enabled) $vars['__SECUREKEYPAYMENT_ORDER__']='SecureKeyPAYMENTUniquePerOrder';
-					if ($conf->contrat->enabled)  $vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='SecureKeyPAYMENTUniquePerContractLine';
+					if ($conf->adherent->enabled) $tmparray['__SECUREKEYPAYMENT_MEMBER__']='SecureKeyPAYMENTUniquePerMember';
+					if ($conf->facture->enabled)  $tmparray['__SECUREKEYPAYMENT_INVOICE__']='SecureKeyPAYMENTUniquePerInvoice';
+					if ($conf->commande->enabled) $tmparray['__SECUREKEYPAYMENT_ORDER__']='SecureKeyPAYMENTUniquePerOrder';
+					if ($conf->contrat->enabled)  $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__']='SecureKeyPAYMENTUniquePerContractLine';
 				}
 			}
 			else
@@ -1202,36 +1174,16 @@ class FormMail extends Form
 				$vars['__SECUREKEYPAYMENT_CONTRACTLINE__']='';
 				*/
 			}
-
-			// Old vars removed from doc
-			/*
-			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__']='';
-			}*/
 		}
 
-		$parameters=array('mode'=>$mode);
-		$tmparray=getCommonSubstitutionArray($langs, 2, null, $object);
-		complete_substitutions_array($tmparray, $langs, null, $parameters);
+		$tmparray['__(AnyTranslationKey)__']="Translation";
+
 		foreach($tmparray as $key => $val)
 		{
-		    $vars[$key]=$key;
+			if (empty($val)) $tmparray[$key]=$key;
 		}
 
-		return $vars;
+		return $tmparray;
 	}
 
 }

+ 81 - 61
htdocs/core/lib/functions.lib.php

@@ -5227,38 +5227,69 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob
             '__MYCOMPANY_COUNTRY_ID__' => $mysoc->country_id
         ));
     }
-    if (is_object($object) && (empty($exclude) || ! in_array('object', $exclude)))
+    if (($onlykey || is_object($object)) && (empty($exclude) || ! in_array('object', $exclude)))
     {
-	    $substitutionarray['__ID__'] = $object->id;
-    	$substitutionarray['__REF__'] = $object->ref;
-    	$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 : '');
-
-    	if (is_object($object->thirdparty) && $object->thirdparty->id > 0)
+    	if ($onlykey)
     	{
-    		$substitutionarray['__THIRDPARTY_ID__'] = (is_object($object->thirdparty)?$object->thirdparty->id:'');
-    		$substitutionarray['__THIRDPARTY_NAME__'] = (is_object($object->thirdparty)?$object->thirdparty->name:'');
+		    $substitutionarray['__ID__'] = '__ID__';
+	    	$substitutionarray['__REF__'] = '__REF__';
+	    	$substitutionarray['__REFCLIENT__'] = '__REFCLIENT__';
+	    	$substitutionarray['__REFSUPPLIER__'] = '__REFSUPPLIER__';
+	    	$substitutionarray['__EXTRAFIELD_XXX__'] = '__EXTRAFIELD_XXX__';
+
+    		$substitutionarray['__THIRDPARTY_ID__'] = '__THIRDPARTY_ID__';
+    		$substitutionarray['__THIRDPARTY_NAME__'] = '__THIRDPARTY_NAME__';
+
+    		$substitutionarray['__PROJECT_ID__'] = '__PROJECT_ID__';
+    		$substitutionarray['__PROJECT_REF__'] = '__PROJECT_REF__';
+    		$substitutionarray['__PROJECT_NAME__'] = '__PROJECT_REF__';
+
+	    	$substitutionarray['__CONTRACT_NEXT_EXPIRATION_DATE__'] = 'Date for next expired service';
+    		$substitutionarray['__CONTRACT_NEXT_EXPIRATION_DATETIME__'] = 'Date and hour for next expired service';
+
+    		$substitutionarray['__ONLINE_PAYMENT_URL__'] = 'LinkToPayOnlineIfApplicable';
+    		$substitutionarray['__SECUREKEYPAYMENT__'] = 'Security key (if key is not unique per record)';
+    		$substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = 'Security key for payment on a member subscription (one key per member)';
+    		$substitutionarray['__SECUREKEYPAYMENT_ORDER__'] = 'Security key for payment on an order';
+    		$substitutionarray['__SECUREKEYPAYMENT_INVOICE__'] = 'Security key for payment on an invoice';
+    		$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = 'Security key for payment on a a service';
     	}
-
-    	if (is_object($object->projet) && $object->projet->id > 0)
+    	else
     	{
-    		$substitutionarray['__PROJECT_ID__'] = (is_object($object->projet)?$object->projet->id:'');
-    		$substitutionarray['__PROJECT_REF__'] = (is_object($object->projet)?$object->projet->ref:'');
-    		$substitutionarray['__PROJECT_NAME__'] = (is_object($object->projet)?$object->projet->title:'');
-    	}
+		    $substitutionarray['__ID__'] = $object->id;
+	    	$substitutionarray['__REF__'] = $object->ref;
+	    	$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 : '');
+
+	    	if (is_object($object->thirdparty) && $object->thirdparty->id > 0)
+	    	{
+	    		$substitutionarray['__THIRDPARTY_ID__'] = (is_object($object->thirdparty)?$object->thirdparty->id:'');
+	    		$substitutionarray['__THIRDPARTY_NAME__'] = (is_object($object->thirdparty)?$object->thirdparty->name:'');
+	    	}
 
-    	// Create dynamic tags for __EXTRAFIELD_FIELD__
-    	if ($object->table_element && $object->id > 0)
-    	{
-	    	$extrafieldstmp = new ExtraFields($db);
-	    	$extralabels = $extrafieldstmp->fetch_name_optionals_label($object->table_element, true);
-	    	$object->fetch_optionals($object->id, $extralabels);
-	    	foreach ($extrafieldstmp->attribute_label as $key => $label) {
-	    		$substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key];
+	    	if (is_object($object->projet) && $object->projet->id > 0)
+	    	{
+	    		$substitutionarray['__PROJECT_ID__'] = (is_object($object->projet)?$object->projet->id:'');
+	    		$substitutionarray['__PROJECT_REF__'] = (is_object($object->projet)?$object->projet->ref:'');
+	    		$substitutionarray['__PROJECT_NAME__'] = (is_object($object->projet)?$object->projet->title:'');
+	    	}
+
+	    	// Create dynamic tags for __EXTRAFIELD_FIELD__
+	    	if ($object->table_element && $object->id > 0)
+	    	{
+		    	$extrafieldstmp = new ExtraFields($db);
+		    	$extralabels = $extrafieldstmp->fetch_name_optionals_label($object->table_element, true);
+		    	$object->fetch_optionals($object->id, $extralabels);
+		    	foreach ($extrafieldstmp->attribute_label as $key => $label) {
+		    		$substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key];
+		    	}
 	    	}
-    	}
 
-    	$substitutionarray['__ONLINE_PAYMENT_URL__'] = 'LinkToPayOnlineIfApplicable';
+    		$substitutionarray['__CONTRACT_NEXT_EXPIRATION_DATE__'] = 'TODO';
+	    	$substitutionarray['__CONTRACT_NEXT_EXPIRATION_DATETIME__'] = 'TODO';
+
+	    	$substitutionarray['__ONLINE_PAYMENT_URL__'] = 'TODO';
+    	}
     }
     if (empty($exclude) || ! in_array('objectamount', $exclude))
     {
@@ -5280,41 +5311,35 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob
     {
         include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
 
-        if (! empty($onlykey))
-        {
-            $tmp=$tmp2=$tmp3=$tmp4=$tmp5=array();
-        }
-        else
-        {
-            $tmp=dol_getdate(dol_now(), true);
-            $tmp2=dol_get_prev_day($tmp['mday'], $tmp['mon'], $tmp['year']);
-            $tmp3=dol_get_prev_month($tmp['mday'], $tmp['mon'], $tmp['year']);
-            $tmp4=dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']);
-            $tmp5=dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']);
-        }
+        $tmp=dol_getdate(dol_now(), true);
+        $tmp2=dol_get_prev_day($tmp['mday'], $tmp['mon'], $tmp['year']);
+        $tmp3=dol_get_prev_month($tmp['mday'], $tmp['mon'], $tmp['year']);
+        $tmp4=dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']);
+        $tmp5=dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']);
+
         $substitutionarray=array_merge($substitutionarray, array(
-            '__DAY__' => $tmp['mday'],
-            '__MONTH__' => $tmp['mon'],
-            '__YEAR__' => $tmp['year'],
-            '__PREVIOUS_DAY__' => $tmp2['day'],
-            '__PREVIOUS_MONTH__' => $tmp3['month'],
-            '__PREVIOUS_YEAR__' => ($tmp['year'] - 1),
-            '__NEXT_DAY__' => $tmp4['day'],
-            '__NEXT_MONTH__' => $tmp5['month'],
-            '__NEXT_YEAR__' => ($tmp['year'] + 1),
+            '__DAY__' => (string) $tmp['mday'],
+            '__MONTH__' => (string) $tmp['mon'],
+            '__YEAR__' => (string) $tmp['year'],
+            '__PREVIOUS_DAY__' => (string) $tmp2['day'],
+            '__PREVIOUS_MONTH__' => (string) $tmp3['month'],
+            '__PREVIOUS_YEAR__' => (string) ($tmp['year'] - 1),
+            '__NEXT_DAY__' => (string) $tmp4['day'],
+            '__NEXT_MONTH__' => (string) $tmp5['month'],
+            '__NEXT_YEAR__' => (string) ($tmp['year'] + 1),
         ));
     }
 
     if (empty($exclude) || ! in_array('user', $exclude))
     {
         $substitutionarray=array_merge($substitutionarray, array(
-            '__USER_ID__' => $user->id,
-            '__USER_LOGIN__' => $user->login,
-            '__USER_LASTNAME__' => $user->lastname,
-            '__USER_FIRSTNAME__' => $user->firstname,
-            '__USER_FULLNAME__' => $user->getFullName($outputlangs),
-            '__USER_SUPERVISOR_ID__' => $user->fk_user,
-        	'__SIGNATURE__' => (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ? dol_trunc(dol_string_nohtmltag($user->signature), 30) : $user->signature) : '')
+            '__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,
+        	'__SIGNATURE__' => (string) (($user->signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ? dol_trunc(dol_string_nohtmltag($user->signature), 30) : $user->signature) : '')
         ));
     }
     if (! empty($conf->multicompany->enabled))
@@ -5369,8 +5394,8 @@ function make_substitutions($text, $substitutionarray, $outputlangs=null)
 }
 
 /**
- *  Complete the $substitutionarray with more entries.
- *  Can also add substitution keys coming from external module that had set the "substitutions=1" into module_part array. In this case, method completesubstitutionarray provided by module is called.
+ *  Complete the $substitutionarray with more entries coming from external module that had set the "substitutions=1" into module_part array.
+ *  In this case, method completesubstitutionarray provided by module is called.
  *
  *  @param  array		$substitutionarray		Array substitution old value => new value value
  *  @param  Translate	$outputlangs            Output language
@@ -5386,13 +5411,8 @@ function complete_substitutions_array(&$substitutionarray, $outputlangs, $object
 
 	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 
-	// Add a substitution key for each object property
-	if (is_object($object))
-	{
-		// TODO
-	}
-
 	// Add a substitution key for each extrafields, using key __EXTRA_XXX__
+	// TODO Remove this. Already available into the getCommonSubstitutionArray used to build the substitution array.
 	if (is_object($object) && is_array($object->array_options))
 	{
 		foreach($object->array_options as $key => $val)

+ 1 - 1
htdocs/core/tpl/card_presend.tpl.php

@@ -139,7 +139,7 @@ if ($action == 'presend')
 	// Make substitution in email content
 	$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
 	$substitutionarray['__CHECK_READ__'] = (is_object($object) && is_object($object->thirdparty)) ? '<img src="' . DOL_MAIN_URL_ROOT . '/public/emailing/mailing-read.php?tag=' . $object->thirdparty->tag . '&securitykey=' . urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY) . '" width="1" height="1" style="width:1px;height:1px" border="0"/>' : '';
-	$substitutionarray['__PERSONALIZED__'] = '';
+	$substitutionarray['__PERSONALIZED__'] = '';	// deprecated
 	$substitutionarray['__CONTACTCIVNAME__'] = '';
 	// Add specific substitution for contracts
 	if (is_object($object) && $object->element == 'contrat' && is_array($object->lines))

+ 1 - 1
htdocs/core/tpl/massactions_form.tpl.php

@@ -117,7 +117,7 @@ $formmail->withcancel = 1;
 $substitutionarray = getCommonSubstitutionArray($langs, 0, null, $object);
 $substitutionarray['__EMAIL__'] = $sendto;
 $substitutionarray['__CHECK_READ__'] = (is_object($object) && is_object($object->thirdparty)) ? '<img src="' . DOL_MAIN_URL_ROOT . '/public/emailing/mailing-read.php?tag=' . $object->thirdparty->tag . '&securitykey=' . urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY) . '" width="1" height="1" style="width:1px;height:1px" border="0"/>' : '';
-$substitutionarray['__PERSONALIZED__'] = '';
+$substitutionarray['__PERSONALIZED__'] = '';	// deprecated
 $substitutionarray['__CONTACTCIVNAME__'] = '';
 // Add specific substitution for contracts
 if (is_object($object) && $object->element == 'contrat' && is_array($object->lines))

+ 1 - 1
htdocs/societe/card.php

@@ -2488,7 +2488,7 @@ else
 			$formmail->setSubstitFromObject($object);
 			$formmail->substit['__THIRDPARTY_ID__']=$object->id;		// substit in setSubstitFromObject was wrong for this one
 			$formmail->substit['__THIRDPARTY_NAME__']=$object->name;	// substit in setSubstitFromObject was wrong for this one
-			$formmail->substit['__PERSONALIZED__']='';
+			$formmail->substit['__PERSONALIZED__']='';					// deprecated
 			$formmail->substit['__CONTACTCIVNAME__']='';
 
 			//Find the good contact adress

+ 34 - 28
scripts/emailings/mailing-send.php

@@ -163,22 +163,25 @@ if ($resql)
 	                    $tmpfield=explode('=',$other[4],2); $other5=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
 	                    $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$user->signature:'');
 
-						// Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
-						$substitutionarray=array(
-							'__ID__' => $obj2->source_id,
-							'__EMAIL__' => $obj2->email,
-							'__LASTNAME__' => $obj2->lastname,
-							'__FIRSTNAME__' => $obj2->firstname,
-							'__MAILTOEMAIL__' => '<a href="mailto:'.$obj2->email.'">'.$obj2->email.'</a>',
-							'__OTHER1__' => $other1,
-							'__OTHER2__' => $other2,
-							'__OTHER3__' => $other3,
-							'__OTHER4__' => $other4,
-							'__OTHER5__' => $other5,
-							'__SIGNATURE__' => $signature,	// Signature is empty when ran from command line or taken from user in parameter)
-							'__CHECK_READ__' => '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj2->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>',
-							'__UNSUBSCRIBE__' => '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj2->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>'
-						);
+	                    $object = null;		// Not defined with mass emailing
+	                    $parameters=array('mode'=>'emailing');
+	                    $substitutionarray=getCommonSubstitutionArray($langs, 2, array('object','objectamount'), $object);			// Note: On mass emailing, this is null because we don't know object
+
+	                    // Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
+	                    $substitutionarray['__ID__'] = $obj->source_id;
+	                    $substitutionarray['__EMAIL__'] = $obj->email;
+	                    $substitutionarray['__LASTNAME__'] = $obj->lastname;
+	                    $substitutionarray['__FIRSTNAME__'] = $obj->firstname;
+	                    $substitutionarray['__MAILTOEMAIL__'] = '<a href="mailto:'.$obj->email.'">'.$obj->email.'</a>';
+	                    $substitutionarray['__OTHER1__'] = $other1;
+	                    $substitutionarray['__OTHER2__'] = $other2;
+	                    $substitutionarray['__OTHER3__'] = $other3;
+	                    $substitutionarray['__OTHER4__'] = $other4;
+	                    $substitutionarray['__OTHER5__'] = $other5;
+	                    $substitutionarray['__SIGNATURE__'] = $signature;	// Signature is empty when ran from command line or taken from user in parameter)
+	                    $substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
+	                    $substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>';
+
 						$onlinepaymentenabled = 0;
 						if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
 						if (! empty($conf->paybox->enabled)) $onlinepaymentenabled++;
@@ -186,18 +189,20 @@ if ($resql)
 						if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
 						{
 							$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);
-							else $substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
-
-							if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
-							else $substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
-
-							if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
-							else $substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
-
-							if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
-							else $substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
+							if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
+							{
+								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=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_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);
+							}
 						}
 						/* For backward compatibility */
 						if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN))
@@ -216,6 +221,7 @@ if ($resql)
 							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);
 						}
+
 						complete_substitutions_array($substitutionarray,$langs);
 						$newsubject=make_substitutions($subject,$substitutionarray);
 						$newmessage=make_substitutions($message,$substitutionarray);