Complete work for mutualizing generic substitution system.
This commit is contained in:
parent
6c7179d281
commit
c70beaa56b
@ -264,22 +264,14 @@ if ($mode != 'focus')
|
||||
{
|
||||
if ($mode != 'sortorder')
|
||||
{
|
||||
$substitutionarray=getCommonSubstitutionArray($langs, 0, array('object')); // Must match list into GETPOST
|
||||
$substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
|
||||
$texthelp=$langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
|
||||
// See list into GETPOST
|
||||
$texthelp.='__USERID__<br>';
|
||||
$texthelp.='__SUPERVISORID__<br>';
|
||||
$texthelp.='__MYCOUNTRYID__<br>';
|
||||
$texthelp.='__DAY__<br>';
|
||||
$texthelp.='__MONTH__<br>';
|
||||
$texthelp.='__YEAR__<br>';
|
||||
$texthelp.='__PREVIOUS_DAY__<br>';
|
||||
$texthelp.='__PREVIOUS_MONTH__<br>';
|
||||
$texthelp.='__PREVIOUS_YEAR__<br>';
|
||||
$texthelp.='__NEXT_DAY__<br>';
|
||||
$texthelp.='__NEXT_MONTH__<br>';
|
||||
$texthelp.='__NEXT_YEAR__<br>';
|
||||
if (! empty($conf->multicompany->enabled)) $texthelp.='__ENTITYID__<br>';
|
||||
$textvalue=$form->textwithpicto($langs->trans("Value"), $texthelp, 1, 'help', '', 0, 2, '');
|
||||
foreach($substitutionarray as $key => $val)
|
||||
{
|
||||
$texthelp.=$key.'<br>';
|
||||
}
|
||||
$textvalue=$form->textwithpicto($langs->trans("Value"), $texthelp, 1, 'help', '', 0, 2, ''); // No tooltip on click, this also triggers the sort click
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -349,7 +349,19 @@ if ($action == 'edit') // Edit
|
||||
print '</tr>';
|
||||
|
||||
// Message of the day on home page
|
||||
print '<tr><td class="titlefield">'.$langs->trans("MessageOfDay").'</td><td colspan="2">';
|
||||
$substitutionarray=getCommonSubstitutionArray($langs, 0, array('object'));
|
||||
complete_substitutions_array($substitutionarray, $langs);
|
||||
$substitutionarray['__(AnyTranslationKey)__']=$langs->trans('TranslationKey');
|
||||
|
||||
print '<tr><td class="titlefield">';
|
||||
$texthelp=$langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
|
||||
foreach($substitutionarray as $key => $val)
|
||||
{
|
||||
$texthelp.=$key.'<br>';
|
||||
}
|
||||
print $form->textwithpicto($langs->trans("MessageOfDay"), $texthelp, 1, 'help', '', 0, 2, '');
|
||||
|
||||
print '</td><td colspan="2">';
|
||||
|
||||
$doleditor = new DolEditor('main_motd', (isset($conf->global->MAIN_MOTD)?$conf->global->MAIN_MOTD:''), '', 142, 'dolibarr_notes', 'In', false, true, true, ROWS_4, '90%');
|
||||
$doleditor->Create();
|
||||
@ -367,7 +379,17 @@ if ($action == 'edit') // Edit
|
||||
print '</tr>';
|
||||
|
||||
// Message on login page
|
||||
print '<tr><td>'.$langs->trans("MessageLogin").'</td><td colspan="2">';
|
||||
$substitutionarray=getCommonSubstitutionArray($langs, 0, array('object','user'));
|
||||
complete_substitutions_array($substitutionarray, $langs);
|
||||
$substitutionarray['__(AnyTranslationKey)__']=$langs->trans('TranslationKey');
|
||||
print '<tr><td>';
|
||||
$texthelp=$langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
|
||||
foreach($substitutionarray as $key => $val)
|
||||
{
|
||||
$texthelp.=$key.'<br>';
|
||||
}
|
||||
print $form->textwithpicto($langs->trans("MessageLogin"), $texthelp, 1, 'help', '', 0, 2, '');
|
||||
print '</td><td colspan="2">';
|
||||
$doleditor = new DolEditor('main_home', (isset($conf->global->MAIN_HOME)?$conf->global->MAIN_HOME:''), '', 142, 'dolibarr_notes', 'In', false, true, true, ROWS_4, '90%');
|
||||
$doleditor->Create();
|
||||
print '</td></tr>'."\n";
|
||||
|
||||
@ -59,8 +59,8 @@ $acts[1] = "disable";
|
||||
$actl[0] = img_picto($langs->trans("Disabled"),'switch_off');
|
||||
$actl[1] = img_picto($langs->trans("Activated"),'switch_on');
|
||||
|
||||
$listoffset=GETPOST('listoffset');
|
||||
$listlimit=GETPOST('listlimit')>0?GETPOST('listlimit'):1000;
|
||||
$listoffset=GETPOST('listoffset','alpha');
|
||||
$listlimit=GETPOST('listlimit','alpha')>0?GETPOST('listlimit','alpha'):1000;
|
||||
$active = 1;
|
||||
|
||||
$sortfield = GETPOST("sortfield",'alpha');
|
||||
@ -119,14 +119,14 @@ $formmail=new FormMail($db);
|
||||
if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES))
|
||||
{
|
||||
$tmp=FormMail::getAvailableSubstitKey('formemail');
|
||||
$tmp['__(AnyTransKey)__']='__(AnyTransKey)__';
|
||||
$tmp['__(AnyTranslationKey)__']='__(AnyTranslationKey)__';
|
||||
$helpsubstit = $langs->trans("AvailableVariables").':<br>'.implode('<br>', $tmp);
|
||||
$helpsubstitforlines = $langs->trans("AvailableVariables").':<br>'.implode('<br>', $tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
$tmp=FormMail::getAvailableSubstitKey('formemailwithlines');
|
||||
$tmp['__(AnyTransKey)__']='__(AnyTransKey)__';
|
||||
$tmp['__(AnyTranslationKey)__']='__(AnyTranslationKey)__';
|
||||
$helpsubstit = $langs->trans("AvailableVariables").':<br>'.implode('<br>', $tmp);
|
||||
$tmp=FormMail::getAvailableSubstitKey('formemailforlines');
|
||||
$helpsubstitforlines = $langs->trans("AvailableVariables").':<br>'.implode('<br>', $tmp);
|
||||
|
||||
@ -1059,10 +1059,11 @@ class FormMail extends Form
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of substition keys available.
|
||||
* Get list of substition keys available for emails.
|
||||
* This include the complete_substitutions_array. TODO Include the getCommonSubstitutionArray().
|
||||
*
|
||||
* @param string $mode 'formemail', 'formemailwithlines', 'formemailforlines', 'emailing', ...
|
||||
* @return void
|
||||
* @return array Array of substitution values for emails.
|
||||
*/
|
||||
static function getAvailableSubstitKey($mode='formemail')
|
||||
{
|
||||
@ -1134,8 +1135,8 @@ class FormMail extends Form
|
||||
}
|
||||
}
|
||||
|
||||
$tmparray=array();
|
||||
$parameters=array('mode'=>$mode);
|
||||
$tmparray=getCommonSubstitutionArray($langs);
|
||||
complete_substitutions_array($tmparray, $langs, null, $parameters);
|
||||
foreach($tmparray as $key => $val)
|
||||
{
|
||||
|
||||
@ -5014,8 +5014,100 @@ function dol_concatdesc($text1,$text2,$forxml=false)
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make substition into a string replacing key with vals from $substitutionarray (oldval=>newval)
|
||||
* Return array of possible common substitutions.
|
||||
*
|
||||
* @param Translate $outputlangs Output language
|
||||
* @param int $onlykey Do not calculate heavy values of keys (performance enhancement when we need only the keys)
|
||||
* @param array $exclude Array of family keys we want to exclude. For example array('mycompany', 'object', 'date', 'user', ...)
|
||||
* @param Object $object Object for keys on object
|
||||
* @return array Array of substitutions
|
||||
*/
|
||||
function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
|
||||
{
|
||||
global $conf, $mysoc, $user;
|
||||
|
||||
$substitutionarray=array();
|
||||
|
||||
if (empty($exclude) || ! in_array('mycompany', $exclude))
|
||||
{
|
||||
$substitutionarray=array_merge($substitutionarray, array(
|
||||
'__MYCOMPANY_NAME__' => $mysoc->name,
|
||||
'__MYCOMPANY_EMAIL__' => $mysoc->email,
|
||||
'__MYCOMPANY_PROFID1__' => $mysoc->idprof1,
|
||||
'__MYCOMPANY_PROFID2__' => $mysoc->idprof2,
|
||||
'__MYCOMPANY_PROFID3__' => $mysoc->idprof3,
|
||||
'__MYCOMPANY_PROFID4__' => $mysoc->idprof4,
|
||||
'__MYCOMPANY_PROFID5__' => $mysoc->idprof5,
|
||||
'__MYCOMPANY_PROFID6__' => $mysoc->idprof6,
|
||||
'__MYCOMPANY_CAPITAL__' => $mysoc->capital,
|
||||
'__MYCOMPANY_COUNTRY_ID__' => $mysoc->country_id
|
||||
));
|
||||
}
|
||||
if (empty($exclude) || ! in_array('object', $exclude))
|
||||
{
|
||||
if (is_object($object)) // For backward compatibility
|
||||
{
|
||||
$substitutionarray['__TOTAL_TTC__'] =is_object($object)?$object->total_ttc:'';
|
||||
$substitutionarray['__TOTAL_HT__'] =is_object($object)?$object->total_ht:'';
|
||||
$substitutionarray['__TOTAL_VAT__'] =is_object($object)?($object->total_vat?$object->total_vat:$object->total_tva):'';
|
||||
}
|
||||
$substitutionarray['__AMOUNT__'] =is_object($object)?$object->total_ttc:'';
|
||||
$substitutionarray['__AMOUNT_WO_TAX__']=is_object($object)?$object->total_ht:'';
|
||||
$substitutionarray['__AMOUNT_VAT__'] =is_object($object)?($object->total_vat?$object->total_vat:$object->total_tva):'';
|
||||
}
|
||||
|
||||
if (empty($exclude) || ! in_array('date', $exclude))
|
||||
{
|
||||
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']);
|
||||
}
|
||||
$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),
|
||||
));
|
||||
}
|
||||
|
||||
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
|
||||
));
|
||||
}
|
||||
if (! empty($conf->multicompany->enabled))
|
||||
{
|
||||
$substitutionarray=array_merge($substitutionarray, array('__ENTITY_ID__' => $conf->entity));
|
||||
}
|
||||
|
||||
return $substitutionarray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make substition into a text string, replacing keys with vals from $substitutionarray (oldval=>newval).
|
||||
*
|
||||
* @param string $text Source string in which we must do substitution
|
||||
* @param array $substitutionarray Array with key->val to substitute
|
||||
@ -5034,11 +5126,16 @@ function make_substitutions($text, $substitutionarray, $outputlangs=null)
|
||||
// Make substitution for language keys
|
||||
if (is_object($outputlangs))
|
||||
{
|
||||
while (preg_match('/__\((.*)\)__/', $text, $reg))
|
||||
while (preg_match('/__\(([^\)]*)\)__/', $text, $reg))
|
||||
{
|
||||
// If key is __(TranslationKey|langfile)__, then force load of langfile.lang
|
||||
$tmp=explode('|',$reg[1]);
|
||||
if (! empty($tmp[1])) $outputlangs->load($tmp[1]);
|
||||
|
||||
$msgishtml = 0;
|
||||
if (dol_textishtml($text,1)) $msgishtml = 1;
|
||||
$text = preg_replace('/__\('.preg_quote($reg[1]).'\)__/', $msgishtml?dol_htmlentitiesbr($outputlangs->transnoentitiesnoconv($reg[1])):$outputlangs->transnoentitiesnoconv($reg[1]), $text);
|
||||
|
||||
$text = preg_replace('/__\('.preg_quote($reg[1], '/').'\)__/', $msgishtml?dol_htmlentitiesbr($outputlangs->transnoentitiesnoconv($reg[1])):$outputlangs->transnoentitiesnoconv($reg[1]), $text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -588,38 +588,25 @@ function pdf_pagehead(&$pdf,$outputlangs,$page_height)
|
||||
|
||||
|
||||
/**
|
||||
* Return array of possible substitutions
|
||||
* Return array of possible substitutions for PDF content (without external module substitutions).
|
||||
*
|
||||
* @param Translate $outputlangs Output language
|
||||
* @param Object $object Object
|
||||
* @return array Array of substitutions
|
||||
*/
|
||||
function pdf_getSubstitutionArray($outputlangs)
|
||||
function pdf_getSubstitutionArray($outputlangs, $object=null)
|
||||
{
|
||||
global $conf, $mysoc, $user;
|
||||
$substitutionarray=array(
|
||||
'__MYCOMPANY_NAME__' => $mysoc->name,
|
||||
'__MYCOMPANY_EMAIL__' => $mysoc->email,
|
||||
'__MYCOMPANY_PROFID1__' => $mysoc->idprof1,
|
||||
'__MYCOMPANY_PROFID2__' => $mysoc->idprof2,
|
||||
'__MYCOMPANY_PROFID3__' => $mysoc->idprof3,
|
||||
'__MYCOMPANY_PROFID4__' => $mysoc->idprof4,
|
||||
'__MYCOMPANY_PROFID5__' => $mysoc->idprof5,
|
||||
'__MYCOMPANY_PROFID6__' => $mysoc->idprof6,
|
||||
'__MYCOMPANY_CAPITAL__' => $mysoc->capital,
|
||||
'__USER_ID__' => $user->id,
|
||||
'__USER_LOGIN__' => $user->login,
|
||||
'__USER_LASTNAME__' => $user->lastname,
|
||||
'__USER_FIRSTNAME__' => $user->firstname,
|
||||
'__USER_FULLNAME__' => $user->getFullName($outputlangs)
|
||||
);
|
||||
return $substitutionarray;
|
||||
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
|
||||
$substitutionarray['__FROM_NAME__']='__FROM_NAME__';
|
||||
$substitutionarray['__FROM_EMAIL__']='__FROM_EMAIL__';
|
||||
return $substitutionarray;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a draft watermark on PDF files
|
||||
*
|
||||
* @param TCPDF $pdf Object PDF
|
||||
* @param TCPDF $pdf Object PDF
|
||||
* @param Translate $outputlangs Object lang
|
||||
* @param int $h Height of PDF
|
||||
* @param int $w Width of PDF
|
||||
@ -638,8 +625,8 @@ function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
|
||||
elseif ($unit=='in') $k=72;
|
||||
|
||||
// Make substitution
|
||||
$substitutionarray=pdf_getSubstitutionArray($outputlangs);
|
||||
complete_substitutions_array($substitutionarray,$outputlangs,$object);
|
||||
$substitutionarray=pdf_getSubstitutionArray($outputlangs,null);
|
||||
complete_substitutions_array($substitutionarray,$outputlangs,null);
|
||||
$text=make_substitutions($text,$substitutionarray,$outputlangs);
|
||||
$text=$outputlangs->convToOutputCharset($text);
|
||||
|
||||
@ -867,13 +854,10 @@ function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_bass
|
||||
// Line of free text
|
||||
if (empty($hidefreetext) && ! empty($conf->global->$paramfreetext))
|
||||
{
|
||||
$substitutionarray=pdf_getSubstitutionArray($outputlangs);
|
||||
$substitutionarray=pdf_getSubstitutionArray($outputlangs, $object);
|
||||
// More substitution keys
|
||||
$substitutionarray['__FROM_NAME__']=$fromcompany->name;
|
||||
$substitutionarray['__FROM_EMAIL__']=$fromcompany->email;
|
||||
$substitutionarray['__TOTAL_TTC__']=$object->total_ttc;
|
||||
$substitutionarray['__TOTAL_HT__']=$object->total_ht;
|
||||
$substitutionarray['__TOTAL_VAT__']=$object->total_vat;
|
||||
complete_substitutions_array($substitutionarray,$outputlangs,$object);
|
||||
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray,$outputlangs);
|
||||
$line.=$outputlangs->convToOutputCharset($newfreetext);
|
||||
|
||||
@ -265,15 +265,11 @@ function dol_loginfunction($langs,$conf,$mysoc)
|
||||
$main_home='';
|
||||
if (! empty($conf->global->MAIN_HOME))
|
||||
{
|
||||
$i=0;
|
||||
while (preg_match('/__\(([a-zA-Z|@]+)\)__/i',$conf->global->MAIN_HOME,$reg) && $i < 100)
|
||||
{
|
||||
$tmp=explode('|',$reg[1]);
|
||||
if (! empty($tmp[1])) $langs->load($tmp[1]);
|
||||
$conf->global->MAIN_HOME=preg_replace('/__\('.preg_quote($reg[1]).'\)__/i',$langs->trans($tmp[0]),$conf->global->MAIN_HOME);
|
||||
$i++;
|
||||
}
|
||||
$main_home=dol_htmlcleanlastbr($conf->global->MAIN_HOME);
|
||||
$substitutionarray=getCommonSubstitutionArray($langs);
|
||||
complete_substitutions_array($substitutionarray, $langs);
|
||||
$texttoshow = make_substitutions($conf->global->MAIN_HOME, $substitutionarray, $langs);
|
||||
|
||||
$main_home=dol_htmlcleanlastbr($texttoshow);
|
||||
}
|
||||
|
||||
// Google AD
|
||||
|
||||
@ -88,18 +88,13 @@ if (! empty($conf->global->MAIN_MOTD))
|
||||
$conf->global->MAIN_MOTD=preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>/i','<br>',$conf->global->MAIN_MOTD);
|
||||
if (! empty($conf->global->MAIN_MOTD))
|
||||
{
|
||||
$i=0;
|
||||
while (preg_match('/__\(([a-zA-Z|@]+)\)__/i',$conf->global->MAIN_MOTD,$reg) && $i < 100)
|
||||
{
|
||||
$tmp=explode('|',$reg[1]);
|
||||
if (! empty($tmp[1])) $langs->load($tmp[1]);
|
||||
$conf->global->MAIN_MOTD=preg_replace('/__\('.preg_quote($reg[1]).'\)__/i',$langs->trans($tmp[0]),$conf->global->MAIN_MOTD);
|
||||
$i++;
|
||||
}
|
||||
$substitutionarray=getCommonSubstitutionArray($langs);
|
||||
complete_substitutions_array($substitutionarray, $langs);
|
||||
$texttoshow = make_substitutions($conf->global->MAIN_MOTD, $substitutionarray, $langs);
|
||||
|
||||
print "\n<!-- Start of welcome text -->\n";
|
||||
print '<table width="100%" class="notopnoleftnoright"><tr><td>';
|
||||
print dol_htmlentitiesbr($conf->global->MAIN_MOTD);
|
||||
print dol_htmlentitiesbr($texttoshow);
|
||||
print '</td></tr></table><br>';
|
||||
print "\n<!-- End of welcome text -->\n";
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user