From 5df1218d9f1a08fc8ec76a472d96911f7491c4f4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 17 Oct 2020 12:59:22 +0200 Subject: [PATCH] Enhance page to setup email templates --- htdocs/admin/mails_templates.php | 131 ++++++++++------------ htdocs/core/actions_sendmails.inc.php | 2 +- htdocs/core/class/html.formmail.class.php | 22 ++-- htdocs/langs/en_US/admin.lang | 4 +- htdocs/langs/en_US/main.lang | 1 + 5 files changed, 76 insertions(+), 84 deletions(-) diff --git a/htdocs/admin/mails_templates.php b/htdocs/admin/mails_templates.php index 1158ee56655..27438e78dea 100644 --- a/htdocs/admin/mails_templates.php +++ b/htdocs/admin/mails_templates.php @@ -147,29 +147,30 @@ $tabfieldcheck = array(); $tabfieldcheck[25] = array(); -// Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact") $elementList = array(); -$sourceList = array(); // 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 && $user->rights->propal->lire) $elementList['propal_send'] = $langs->trans('MailToSendProposal'); -if ($conf->commande->enabled && $user->rights->commande->lire) $elementList['order_send'] = $langs->trans('MailToSendOrder'); -if ($conf->facture->enabled && $user->rights->facture->lire) $elementList['facture_send'] = $langs->trans('MailToSendInvoice'); -if ($conf->expedition->enabled) $elementList['shipping_send'] = $langs->trans('MailToSendShipment'); -if ($conf->reception->enabled) $elementList['reception_send'] = $langs->trans('MailToSendReception'); -if ($conf->ficheinter->enabled) $elementList['fichinter_send'] = $langs->trans('MailToSendIntervention'); -if ($conf->supplier_proposal->enabled) $elementList['supplier_proposal_send'] = $langs->trans('MailToSendSupplierRequestForQuotation'); -if (($conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || ($conf->supplier_order->enabled && $user->rights->supplier_order->lire)) $elementList['order_supplier_send'] = $langs->trans('MailToSendSupplierOrder'); -if (($conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || ($conf->supplier_invoice->enabled && $user->rights->supplier_invoice->lire)) $elementList['invoice_supplier_send'] = $langs->trans('MailToSendSupplierInvoice'); -if ($conf->societe->enabled && $user->rights->societe->lire) $elementList['thirdparty'] = $langs->trans('MailToThirdparty'); -if ($conf->adherent->enabled && $user->rights->adherent->lire) $elementList['member'] = $langs->trans('MailToMember'); -if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementList['contract'] = $langs->trans('MailToSendContract'); -if ($conf->projet->enabled) $elementList['project'] = $langs->trans('MailToProject'); -if ($conf->ticket->enabled && $user->rights->ticket->read) $elementList['ticket_send'] = $langs->trans('MailToTicket'); -if ($conf->recruitment->enabled && $user->rights->recruitment->recruitmentjobposition->read) $elementList['recruitmentcandidature_send'] = $langs->trans('RecruitmentCandidatures'); -if ($conf->agenda->enabled) $elementList['actioncomm_send'] = $langs->trans('MailToSendEventPush'); -$elementList['user'] = $langs->trans('MailToUser'); +// Add all and none after the sort +$elementList['all'] = '-- '.dol_escape_htmltag($langs->trans("All")).' --'; +$elementList['none'] = '-- '.dol_escape_htmltag($langs->trans("None")).' --'; +$elementList['user'] = img_picto('', 'user', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToUser')); +if ($conf->adherent->enabled && $user->rights->adherent->lire) $elementList['member'] = img_picto('', 'object_member', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToMember')); +if ($conf->recruitment->enabled && $user->rights->recruitment->recruitmentjobposition->read) $elementList['recruitmentcandidature_send'] = img_picto('', 'recruitmentcandidature', 'class="paddingright"').dol_escape_htmltag($langs->trans('RecruitmentCandidatures')); +if ($conf->societe->enabled && $user->rights->societe->lire) $elementList['thirdparty'] = img_picto('', 'company', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToThirdparty')); +if ($conf->projet->enabled) $elementList['project'] = img_picto('', 'project', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToProject')); +if ($conf->propal->enabled && $user->rights->propal->lire) $elementList['propal_send'] = dol_escape_htmltag($langs->trans('MailToSendProposal')); +if ($conf->commande->enabled && $user->rights->commande->lire) $elementList['order_send'] = dol_escape_htmltag($langs->trans('MailToSendOrder')); +if ($conf->facture->enabled && $user->rights->facture->lire) $elementList['facture_send'] = dol_escape_htmltag($langs->trans('MailToSendInvoice')); +if ($conf->expedition->enabled) $elementList['shipping_send'] = dol_escape_htmltag($langs->trans('MailToSendShipment')); +if ($conf->reception->enabled) $elementList['reception_send'] = dol_escape_htmltag($langs->trans('MailToSendReception')); +if ($conf->ficheinter->enabled) $elementList['fichinter_send'] = dol_escape_htmltag($langs->trans('MailToSendIntervention')); +if ($conf->supplier_proposal->enabled) $elementList['supplier_proposal_send'] = dol_escape_htmltag($langs->trans('MailToSendSupplierRequestForQuotation')); +if (($conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || ($conf->supplier_order->enabled && $user->rights->supplier_order->lire)) $elementList['order_supplier_send'] = dol_escape_htmltag($langs->trans('MailToSendSupplierOrder')); +if (($conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || ($conf->supplier_invoice->enabled && $user->rights->supplier_invoice->lire)) $elementList['invoice_supplier_send'] = dol_escape_htmltag($langs->trans('MailToSendSupplierInvoice')); +if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementList['contract'] = img_picto('', 'contract', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToSendContract')); +if ($conf->ticket->enabled && $user->rights->ticket->read) $elementList['ticket_send'] = img_picto('', 'ticket', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToTicket')); +if ($conf->agenda->enabled) $elementList['actioncomm_send'] = img_picto('', 'action', 'class="paddingright"').dol_escape_htmltag($langs->trans('MailToSendEventPush')); $parameters = array('elementList'=>$elementList); $reshook = $hookmanager->executeHooks('emailElementlist', $parameters); // Note that $action and $object may have been modified by some hooks @@ -179,11 +180,7 @@ if ($reshook == 0) { } } -// Add all and none after the sort -$elementList['all'] = '-- '.$langs->trans("All").' -- ('.$langs->trans('VisibleEverywhere').')'; -$elementList['none'] = '-- '.$langs->trans("None").' -- ('.$langs->trans('VisibleNowhere').')'; - -asort($elementList); +//asort($elementList); $id = 25; @@ -303,7 +300,7 @@ if (empty($reshook)) } } - // Si verif ok et action modify, on modifie la ligne + // We modify the line if ($ok && GETPOST('actionmodify')) { $rowidcol = "rowid"; @@ -414,7 +411,7 @@ $formadmin = new FormAdmin($db); $help_url = ''; $title = $langs->trans("EMailsSetup"); -llxHeader('', $title); +llxHeader('', $title, $help_url); $linkback = ''; $titlepicto = 'title_setup'; @@ -430,7 +427,6 @@ if ($action == 'delete') { print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$code.'&id='.$id, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1); } -//var_dump($elementList); $sql = "SELECT rowid as rowid, label, type_template, lang, fk_user, private, position, topic, joinfiles, content_lines, content, enabled, active"; @@ -481,7 +477,7 @@ if ($action == 'view') { if ($fieldlist[$field] == 'type') { $valuetoshow = $langs->trans("Type"); } if ($fieldlist[$field] == 'code') { $valuetoshow = $langs->trans("Code"); } if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') { $valuetoshow = $langs->trans("Code"); } - if ($fieldlist[$field] == 'type_template') { $valuetoshow = $langs->trans("TypeOfTemplate"); } + if ($fieldlist[$field] == 'type_template') { $valuetoshow = $langs->trans("TypeOfTemplate"); $align="center"; } if ($fieldlist[$field] == 'private') { $align = 'center'; } if ($fieldlist[$field] == 'position') { $align = 'center'; } @@ -492,7 +488,7 @@ if ($action == 'view') { if ($valuetoshow != '') { - print ''; + print ''; if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) print ''.$valuetoshow.' '.img_help(1, $valuetoshow).''; elseif (!empty($tabhelp[$id][$value])) { @@ -570,14 +566,12 @@ if ($action == 'view') { } elseif ($tmpfieldlist == 'joinfiles') { print ''; } else { - if ($context != 'hide') { - // print ''; - $okforextended = true; - if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) - $okforextended = false; - $doleditor = new DolEditor($tmpfieldlist, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 500, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_4, '90%'); - print $doleditor->Create(1); - } else print ' '; + // print ''; + $okforextended = true; + if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) + $okforextended = false; + $doleditor = new DolEditor($tmpfieldlist, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 180, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_4, '90%'); + print $doleditor->Create(1); } print ''; if ($tmpfieldlist == 'topic') { @@ -591,11 +585,6 @@ if ($action == 'view') { print ''; } - - - $colspan = count($fieldlist) + 1; - //print ' '; // Keep   to have a line with enough height - print ''; print ''; print ''; @@ -641,26 +630,24 @@ if ($resql) // Title line with search boxes print ''; - $filterfound = 0; foreach ($fieldlist as $field => $value) { if ($value == 'label') { print ''; } elseif ($value == 'lang') { print ''; - print $formadmin->select_language($search_lang, 'search_lang', 0, null, 1, 0, 0, 'maxwidth100'); + print $formadmin->select_language($search_lang, 'search_lang', 0, null, 1, 0, 0, 'maxwidth150'); print ''; } elseif ($value == 'fk_user') { print ''; - $restrictid = array(); - if (!$user->admin) $restrictid = array($user->id); - //var_dump($restrictid); - print $form->select_dolusers($search_fk_user, 'search_fk_user', 1, null, 0, 'hierarchyme', null, 0, 0, 1, '', 0, '', 'maxwidth100'); + print $form->select_dolusers($search_fk_user, 'search_fk_user', 1, null, 0, 'hierarchyme', null, 0, 0, 1, '', 0, '', 'maxwidth150'); print ''; } elseif ($value == 'topic') { print ''; } elseif ($value == 'type_template') { - print ''.$form->selectarray('search_type_template', $elementList, $search_type_template, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100 maxwidth100onsmartphone').''; + print ''; + print $form->selectarray('search_type_template', $elementList, $search_type_template, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth150', 1, '', 0, 1); + print ''; } elseif (!in_array($value, array('content', 'content_lines'))) { print ''; } @@ -819,22 +806,26 @@ if ($resql) { if (in_array($fieldlist[$field], array('content', 'content_lines'))) continue; $showfield = 1; - $align = "left"; + $align = ""; + $class = "tddict"; $valuetoshow = $obj->{$fieldlist[$field]}; - if ($value == 'label' || $value == 'topic') - { + if ($value == 'label' || $value == 'topic') { $valuetoshow = dol_escape_htmltag($valuetoshow); } - if ($value == 'type_template') - { - $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow; + if ($value == 'label') { + $class .= ' tdoverflowmax100'; } - if ($value == 'lang' && $valuetoshow) - { + /*if ($value == 'topic') { + $class .= ' tdoverflowmax300'; + }*/ + if ($value == 'type_template') { + $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow; + $align = "center"; + } + if ($value == 'lang' && $valuetoshow) { $valuetoshow = $valuetoshow.' - '.$langs->trans("Language_".$valuetoshow); } - if ($value == 'fk_user') - { + if ($value == 'fk_user') { if ($valuetoshow > 0) { $fuser = new User($db); @@ -842,29 +833,25 @@ if ($resql) $valuetoshow = $fuser->getNomUrl(1); } } - if ($value == 'private') - { + if ($value == 'private') { $align = "center"; if ($valuetoshow) $valuetoshow = yn($valuetoshow); else $valuetoshow = ''; } - if ($value == 'position') - { + if ($value == 'position') { $align = "center"; } - if ($value == 'joinfiles') - { + if ($value == 'joinfiles') { $align = "center"; if ($valuetoshow) $valuetoshow = 1; else $valuetoshow = ''; } + if ($align) $class .= ' '.$align; - $class = 'tddict'; // Show value for field - if ($showfield) - { + if ($showfield) { print ''; - print ''.$valuetoshow.''; + print ''.$valuetoshow.''; } } } @@ -963,7 +950,7 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '') { global $conf, $langs, $user, $db; global $form; - global $elementList, $sourceList; + global $elementList; $formadmin = new FormAdmin($db); @@ -1017,14 +1004,14 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '') // Le type de template elseif ($fieldlist[$field] == 'type_template') { - print ''; + print ''; if ($context == 'edit' && !empty($obj->{$fieldlist[$field]}) && !in_array($obj->{$fieldlist[$field]}, array_keys($elementList))) { // Current tempalte type is an unknown type, so we must keep it as it is. print ''; print $obj->{$fieldlist[$field]}; } else { - print $form->selectarray('type_template', $elementList, (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:''), 1, 0, 0, '', 0, 0, 0, '', 'maxwidth150 maxwidth100onsmartphone'); + print $form->selectarray('type_template', $elementList, (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:''), 1, 0, 0, '', 0, 0, 0, '', 'maxwidth150', 1, '', 0, 1); } print ''; } elseif ($context == 'add' && in_array($fieldlist[$field], array('topic', 'joinfiles', 'content', 'content_lines'))) continue; diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index 5be25002079..196656b983f 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -321,7 +321,7 @@ if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST if ($action == 'send' || $action == 'relance') { - $actionmsg2 = $langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from, 4, 0, 1).' '.$langs->transnoentities('To').' '.CMailFile::getValidAddress($sendto, 4, 0, 1); + $actionmsg2 = $langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from, 4, 0, 1).' '.$langs->transnoentities('at').' '.CMailFile::getValidAddress($sendto, 4, 0, 1); if ($message) { $actionmsg = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from); diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index e2749c5e183..200b50cd512 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -296,6 +296,7 @@ class FormMail extends Form * @param string $addfileaction Name of action when posting file attachments * @param string $removefileaction Name of action when removing file attachments * @return void + * @deprecated */ public function show_form($addfileaction = 'addfile', $removefileaction = 'removefile') { @@ -434,18 +435,20 @@ class FormMail extends Form { setEventMessages($this->error, $this->errors, 'errors'); } + $langs->trans("members"); foreach ($this->lines_model as $line) { - $langs->trans("members"); - if (preg_match('/\((.*)\)/', $line->label, $reg)) - { - $modelmail_array[$line->id] = $langs->trans($reg[1]); // langs->trans when label is __(xxx)__ + $reg = array(); + if (preg_match('/\((.*)\)/', $line->label, $reg)) { + $labeltouse = $langs->trans($reg[1]); // langs->trans when label is __(xxx)__ } else { - $modelmail_array[$line->id] = $line->label; + $labeltouse = $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").' '; + + // We escape the $labeltouse to store it into $modelmail_array. + $modelmail_array[$line->id] = dol_escape_htmltag($labeltouse); + if ($line->lang) $modelmail_array[$line->id] .= ' '.picto_from_langcode($line->lang); + if ($line->private) $modelmail_array[$line->id] .= ' - '.dol_escape_htmltag($langs->trans("Private")).''; } } @@ -454,7 +457,8 @@ class FormMail extends Form { // If list of template is filled $out .= '
'."\n"; - $out .= ''.$langs->trans('SelectMailModel').': '.$this->selectarray('modelmailselected', $modelmail_array, 0, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100'); + $out .= ''.$langs->trans('SelectMailModel').': '; + $out .= $this->selectarray('modelmailselected', $modelmail_array, 0, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1, '', 0, 1); if ($user->admin) $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')), 1); $out .= '   '; $out .= ''; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index a7103a99daa..e59a4c54f07 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1897,7 +1897,7 @@ MailToSendReception=Receptions MailToThirdparty=Third parties MailToMember=Members MailToUser=Users -MailToProject=Projects page +MailToProject=Projects MailToTicket=Tickets ByDefaultInList=Show by default on list view YouUseLastStableVersion=You use the latest stable version @@ -2064,7 +2064,7 @@ MeasuringScaleDesc=The scale is the number of places you have to move the decima TemplateAdded=Template added TemplateUpdated=Template updated TemplateDeleted=Template deleted -MailToSendEventPush=Template for event reminder emails +MailToSendEventPush=Event reminder email SwitchThisForABetterSecurity=Switching this value to %s is recommended for more security DictionaryProductNature= Nature of product CountryIfSpecificToOneCountry=Country (if specific to a given country) \ No newline at end of file diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 789d3836e37..c28280c8330 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -490,6 +490,7 @@ By=By From=From FromDate=From FromLocation=From +at=at to=to To=to and=and