From 75db8061027376a07093d3dac991406d00a91d8d Mon Sep 17 00:00:00 2001 From: ATM-Lucas Date: Fri, 24 Jan 2025 12:23:08 +0100 Subject: [PATCH 1/9] Adding sending mails on product --- htdocs/core/tpl/card_presend.tpl.php | 5 +++++ htdocs/product/card.php | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/htdocs/core/tpl/card_presend.tpl.php b/htdocs/core/tpl/card_presend.tpl.php index d29932c2c20..9a5a12be721 100644 --- a/htdocs/core/tpl/card_presend.tpl.php +++ b/htdocs/core/tpl/card_presend.tpl.php @@ -115,6 +115,11 @@ if ($action == 'presend') { } if ($forcebuilddoc) { // If there is no default value for supplier invoice, we do not generate file, even if modelpdf was set by a manual generation if ((!$file || !is_readable($file)) && method_exists($object, 'generateDocument')) { + + $hidedetails = $hidedetails?$hidedetails:''; + $hidedesc = $hidedetails?$hidedetails:''; + $hideref = $hidedetails?$hidedetails:''; + $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result < 0) { dol_print_error($db, $object->error, $object->errors); diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 5de9cda0342..bcbe53236c5 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1295,6 +1295,14 @@ if (empty($reshook)) { setEventMessages($langs->trans("WarningSelectOneDocument"), null, 'warnings'); } } + + // Actions to send emails + $triggersendname = 'PRODUCT_SENTBYMAIL'; + $paramname = 'id'; + $autocopy = 'MAIN_MAIL_AUTOCOPY_PRODUCT_TO'; + $trackid = 'prod'.$object->id; + include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; + } @@ -3027,6 +3035,9 @@ if ($action != 'create' && $action != 'edit') { print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id, '', $usercancreate); } + //Send + print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&mode=init&token=' . newToken() . '#formmailbeforetitle'); + if (!isset($hookmanager->resArray['no_button_copy']) || $hookmanager->resArray['no_button_copy'] != 1) { if (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) { $cloneProductUrl = ''; @@ -3198,6 +3209,15 @@ if ($action != 'create' && $action != 'edit' && $action != 'delete') { $somethingshown = $formactions->showactions($object, 'product', 0, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for product print ''; + + // Presend form + $modelmail = 'product_send'; // Modèle d'e-mail pour les produits + $defaulttopic = $object->label; // Sujet par défaut + $diroutput = $conf->product->multidir_output[$object->entity]; // Répertoire de sortie + $trackid = 'prod' . $object->id; // ID de suivi + + include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; + } // End of page From ba6f80c307be59843ee1354d16fe12ca4685e592 Mon Sep 17 00:00:00 2001 From: ATM-Lucas Date: Fri, 24 Jan 2025 12:24:43 +0100 Subject: [PATCH 2/9] comm --- htdocs/product/card.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index bcbe53236c5..1efadc81fbf 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -3211,10 +3211,10 @@ if ($action != 'create' && $action != 'edit' && $action != 'delete') { print ''; // Presend form - $modelmail = 'product_send'; // Modèle d'e-mail pour les produits - $defaulttopic = $object->label; // Sujet par défaut - $diroutput = $conf->product->multidir_output[$object->entity]; // Répertoire de sortie - $trackid = 'prod' . $object->id; // ID de suivi + $modelmail = 'product_send'; + $defaulttopic = $object->label; + $diroutput = $conf->product->multidir_output[$object->entity]; + $trackid = 'prod' . $object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; From e3856d0de5a11c137681d493a7075393ed42eafb Mon Sep 17 00:00:00 2001 From: ATM-Lucas Date: Fri, 24 Jan 2025 14:04:30 +0100 Subject: [PATCH 3/9] pre-commit error --- htdocs/core/tpl/card_presend.tpl.php | 1 - htdocs/product/card.php | 2 -- 2 files changed, 3 deletions(-) diff --git a/htdocs/core/tpl/card_presend.tpl.php b/htdocs/core/tpl/card_presend.tpl.php index 9a5a12be721..e0654d487ca 100644 --- a/htdocs/core/tpl/card_presend.tpl.php +++ b/htdocs/core/tpl/card_presend.tpl.php @@ -115,7 +115,6 @@ if ($action == 'presend') { } if ($forcebuilddoc) { // If there is no default value for supplier invoice, we do not generate file, even if modelpdf was set by a manual generation if ((!$file || !is_readable($file)) && method_exists($object, 'generateDocument')) { - $hidedetails = $hidedetails?$hidedetails:''; $hidedesc = $hidedetails?$hidedetails:''; $hideref = $hidedetails?$hidedetails:''; diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 1efadc81fbf..2a0868bcaa3 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1302,7 +1302,6 @@ if (empty($reshook)) { $autocopy = 'MAIN_MAIL_AUTOCOPY_PRODUCT_TO'; $trackid = 'prod'.$object->id; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; - } @@ -3217,7 +3216,6 @@ if ($action != 'create' && $action != 'edit' && $action != 'delete') { $trackid = 'prod' . $object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; - } // End of page From 4afb100767382bdaf926da456c0c9899ab978695 Mon Sep 17 00:00:00 2001 From: ATM-Lucas Date: Fri, 24 Jan 2025 16:52:50 +0100 Subject: [PATCH 4/9] Adding model Mail --- htdocs/admin/mails_templates.php | 3 +++ htdocs/core/class/html.formmail.class.php | 3 ++- htdocs/product/card.php | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/htdocs/admin/mails_templates.php b/htdocs/admin/mails_templates.php index 6f79d58551a..d710306172c 100644 --- a/htdocs/admin/mails_templates.php +++ b/htdocs/admin/mails_templates.php @@ -252,6 +252,9 @@ if (isModEnabled('eventorganization') && $user->hasRight('eventorganization', 'r if (isModEnabled('partnership') && $user->hasRight('partnership', 'read')) { $elementList['partnership_send'] = img_picto('', 'partnership', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToPartnership')); } +if (isModEnabled('product') && !empty($user->rights->produit->lire)) { + $elementList['product_send'] = img_picto('', 'product', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('Product')); +} $parameters = array('elementList' => $elementList); $reshook = $hookmanager->executeHooks('emailElementlist', $parameters); // Note that $action and $object may have been modified by some hooks diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 3f09d2816f7..8964679bc7e 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -534,6 +534,7 @@ class FormMail extends Form $listofmimes = array(); $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined + if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) { if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) { if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param['fileinit']) && is_array($this->param['fileinit'])) { foreach ($this->param['fileinit'] as $path) { @@ -624,7 +625,7 @@ class FormMail extends Form } elseif (!empty($this->param['models']) && in_array($this->param['models'], array( 'propal_send', 'order_send', 'facture_send', 'shipping_send', 'fichinter_send', 'supplier_proposal_send', 'order_supplier_send', - 'invoice_supplier_send', 'thirdparty', 'contract', 'user', 'recruitmentcandidature_send', 'all' + 'invoice_supplier_send', 'thirdparty', 'contract', 'user', 'recruitmentcandidature_send', 'product_send', 'all' ))) { // If list of template is empty $out .= '
'."\n"; diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 2a0868bcaa3..7c3588d0e08 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -3176,6 +3176,10 @@ if (getDolGlobalString('PRODUCT_ADD_FORM_ADD_TO') && $object->id && ($action == * Generated documents */ +if (GETPOST('modelselected')) { + $action = 'presend'; +} + if ($action != 'create' && $action != 'edit' && $action != 'delete') { print '
'; print ''; // ancre From 9c10d36b1b6f96c6327009110a2b707d688c56d0 Mon Sep 17 00:00:00 2001 From: ATM-Lucas Date: Fri, 24 Jan 2025 16:55:13 +0100 Subject: [PATCH 5/9] fault --- htdocs/core/class/html.formmail.class.php | 1152 ++++++++++----------- 1 file changed, 576 insertions(+), 576 deletions(-) diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 8964679bc7e..a5881534518 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -473,7 +473,7 @@ class FormMail extends Form global $conf, $langs, $user, $hookmanager, $form; // Required to show preview wof mail attachments - require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; + require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php'; $formfile = new FormFile($this->db); if (!is_object($form)) { @@ -532,632 +532,632 @@ class FormMail extends Form $listofpaths = array(); $listofnames = array(); $listofmimes = array(); - $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined + $keytoavoidconflict = empty($this->trackid) ? '' : '-' . $this->trackid; // this->trackid must be defined if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) { - if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) { - if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param['fileinit']) && is_array($this->param['fileinit'])) { - foreach ($this->param['fileinit'] as $path) { - if (!empty($path)) { - $this->add_attached_files($path); + if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) { + if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param['fileinit']) && is_array($this->param['fileinit'])) { + foreach ($this->param['fileinit'] as $path) { + if (!empty($path)) { + $this->add_attached_files($path); + } } } } - } - if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) { - $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]); - } - if (!empty($_SESSION["listofnames".$keytoavoidconflict])) { - $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]); - } - if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) { - $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]); - } - - - $out .= "\n".'
'."\n"; - if ($this->withform == 1) { - $out .= '
'."\n"; - - $out .= ''; - $out .= ''; - $out .= ''; - $out .= ''; - $out .= ''; - } - if (!empty($this->withfrom)) { - if (!empty($this->withfromreadonly)) { - $out .= ''; - $out .= ''; + if (!empty($_SESSION["listofpaths" . $keytoavoidconflict])) { + $listofpaths = explode(';', $_SESSION["listofpaths" . $keytoavoidconflict]); } - } - foreach ($this->param as $key => $value) { - if (is_array($value)) { - $out .= "\n"; - } else { - $out .= ''."\n"; + if (!empty($_SESSION["listofnames" . $keytoavoidconflict])) { + $listofnames = explode(';', $_SESSION["listofnames" . $keytoavoidconflict]); } - } - - $modelmail_array = array(); - if ($this->param['models'] != 'none') { - $result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs); - if ($result < 0) { - setEventMessages($this->error, $this->errors, 'errors'); + if (!empty($_SESSION["listofmimes" . $keytoavoidconflict])) { + $listofmimes = explode(';', $_SESSION["listofmimes" . $keytoavoidconflict]); } - foreach ($this->lines_model as $line) { - $reg = array(); - if (preg_match('/\((.*)\)/', $line->label, $reg)) { - $labeltouse = $langs->trans($reg[1]); // langs->trans when label is __(xxx)__ + + $out .= "\n" . '
' . "\n"; + if ($this->withform == 1) { + $out .= '' . "\n"; + + $out .= ''; + $out .= ''; + $out .= ''; + $out .= ''; + $out .= ''; + } + if (!empty($this->withfrom)) { + if (!empty($this->withfromreadonly)) { + $out .= ''; + $out .= ''; + } + } + foreach ($this->param as $key => $value) { + if (is_array($value)) { + $out .= "\n"; } else { - $labeltouse = $line->label; - } - - // 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")).''; + $out .= '' . "\n"; } } - } - // Zone to select email template - if (count($modelmail_array) > 0) { - $model_mail_selected_id = GETPOSTISSET('modelmailselected') ? GETPOSTINT('modelmailselected') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0); + $modelmail_array = array(); + if ($this->param['models'] != 'none') { + $result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs); + if ($result < 0) { + setEventMessages($this->error, $this->errors, 'errors'); + } - // If list of template is filled - $out .= '
'."\n"; - - $out .= $this->selectarray('modelmailselected', $modelmail_array, $model_mail_selected_id, $langs->trans('SelectMailModel'), 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 .= ''; - $out .= '   '; - $out .= '
'; - } elseif (!empty($this->param['models']) && in_array($this->param['models'], array( - 'propal_send', 'order_send', 'facture_send', - 'shipping_send', 'fichinter_send', 'supplier_proposal_send', 'order_supplier_send', - 'invoice_supplier_send', 'thirdparty', 'contract', 'user', 'recruitmentcandidature_send', 'product_send', 'all' - ))) { - // If list of template is empty - $out .= '
'."\n"; - $out .= ''.$langs->trans('SelectMailModel').': '; - $out .= ''; // Do not put 'disabled' on 'option' tag, it is already on 'select' and it makes chrome crazy. - if ($user->admin) { - $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')), 1); - } - $out .= '   '; - $out .= ''; - $out .= '   '; - $out .= '
'; - } else { - $out .= ''; - } - - - $out .= ''."\n"; - - // Substitution array/string - $helpforsubstitution = ''; - if (is_array($this->substit) && count($this->substit)) { - $helpforsubstitution .= $langs->trans('AvailableVariables').' :

'."\n"; - } - foreach ($this->substit as $key => $val) { - // Do not show deprecated variables into the tooltip help of substitution variables - if (in_array($key, array('__NEWREF__', '__REFCLIENT__', '__REFSUPPLIER__', '__SUPPLIER_ORDER_DATE_DELIVERY__', '__SUPPLIER_ORDER_DELAY_DELIVERY__'))) { - continue; - } - $helpforsubstitution .= $key.' -> '.$langs->trans(dol_string_nohtmltag(dolGetFirstLineOfText($val))).'
'; - } - if (is_array($this->substit) && count($this->substit)) { - $helpforsubstitution .= '
'; - } - - /* - if (!empty($this->withsubstit)) { // Unset or set ->withsubstit=0 to disable this. - $out .= '\n"; - }*/ - - // From - if (!empty($this->withfrom)) { - if (!empty($this->withfromreadonly)) { - $out .= '
'; - if (is_numeric($this->withsubstit)) { - $out .= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // Old usage - } else { - $out .= $form->textwithpicto($langs->trans('AvailableVariables'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // New usage - } - $out .= "
'.$langs->trans("MailFrom").''; - - // $this->fromtype is the default value to use to select sender - if (!($this->fromtype === 'user' && $this->fromid > 0) - && !($this->fromtype === 'company') - && !($this->fromtype === 'robot') - && !preg_match('/user_aliases/', $this->fromtype) - && !preg_match('/global_aliases/', $this->fromtype) - && !preg_match('/senderprofile/', $this->fromtype) - ) { - // Use this->fromname and this->frommail or error if not defined - $out .= $this->fromname; - if ($this->frommail) { - $out .= ' <'.$this->frommail.'>'; + foreach ($this->lines_model as $line) { + $reg = array(); + if (preg_match('/\((.*)\)/', $line->label, $reg)) { + $labeltouse = $langs->trans($reg[1]); // langs->trans when label is __(xxx)__ } else { - if ($this->fromtype) { + $labeltouse = $line->label; + } + + // 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")) . ''; + } + } + } + + // Zone to select email template + if (count($modelmail_array) > 0) { + $model_mail_selected_id = GETPOSTISSET('modelmailselected') ? GETPOSTINT('modelmailselected') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0); + + // If list of template is filled + $out .= '
' . "\n"; + + $out .= $this->selectarray('modelmailselected', $modelmail_array, $model_mail_selected_id, $langs->trans('SelectMailModel'), 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 .= ''; + $out .= '   '; + $out .= '
'; + } elseif (!empty($this->param['models']) && in_array($this->param['models'], array( + 'propal_send', 'order_send', 'facture_send', + 'shipping_send', 'fichinter_send', 'supplier_proposal_send', 'order_supplier_send', + 'invoice_supplier_send', 'thirdparty', 'contract', 'user', 'recruitmentcandidature_send', 'product_send', 'all' + ))) { + // If list of template is empty + $out .= '
' . "\n"; + $out .= '' . $langs->trans('SelectMailModel') . ': '; + $out .= ''; // Do not put 'disabled' on 'option' tag, it is already on 'select' and it makes chrome crazy. + if ($user->admin) { + $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup') . ' - ' . $langs->transnoentitiesnoconv('EMails')), 1); + } + $out .= '   '; + $out .= ''; + $out .= '   '; + $out .= '
'; + } else { + $out .= ''; + } + + + $out .= '' . "\n"; + + // Substitution array/string + $helpforsubstitution = ''; + if (is_array($this->substit) && count($this->substit)) { + $helpforsubstitution .= $langs->trans('AvailableVariables') . ' :

' . "\n"; + } + foreach ($this->substit as $key => $val) { + // Do not show deprecated variables into the tooltip help of substitution variables + if (in_array($key, array('__NEWREF__', '__REFCLIENT__', '__REFSUPPLIER__', '__SUPPLIER_ORDER_DATE_DELIVERY__', '__SUPPLIER_ORDER_DELAY_DELIVERY__'))) { + continue; + } + $helpforsubstitution .= $key . ' -> ' . $langs->trans(dol_string_nohtmltag(dolGetFirstLineOfText($val))) . '
'; + } + if (is_array($this->substit) && count($this->substit)) { + $helpforsubstitution .= '
'; + } + + /* + if (!empty($this->withsubstit)) { // Unset or set ->withsubstit=0 to disable this. + $out .= '\n"; + }*/ + + // From + if (!empty($this->withfrom)) { + if (!empty($this->withfromreadonly)) { + $out .= '\n"; - } else { - $out .= '\n"; - } - } - - // To - if (!empty($this->withto) || is_array($this->withto)) { - $out .= $this->getHtmlForTo(); - } - - // To User - if (!empty($this->withtouser) && is_array($this->withtouser) && getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) { - $out .= '\n"; - } - - // With option for one email per recipient - if (!empty($this->withoptiononeemailperrecipient)) { - if (abs($this->withoptiononeemailperrecipient) == 1) { - $out .= ''; - } else { - $out .= ''; - } - } - - // CC - if (!empty($this->withtocc) || is_array($this->withtocc)) { - $out .= $this->getHtmlForCc(); - } - - // To User cc - if (!empty($this->withtoccuser) && is_array($this->withtoccuser) && getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) { - $out .= '\n"; - } - - // CCC - if (!empty($this->withtoccc) || is_array($this->withtoccc)) { - $out .= $this->getHtmlForWithCcc(); - } - - // Replyto - if (!empty($this->withreplyto)) { - if ($this->withreplytoreadonly) { - $out .= ''; - $out .= ''; - $out .= "\n"; - } - } - - // Errorsto - if (!empty($this->witherrorsto)) { - $out .= $this->getHtmlForWithErrorsTo(); - } - - // Ask delivery receipt - if (!empty($this->withdeliveryreceipt) && getDolGlobalInt('MAIN_EMAIL_SUPPORT_ACK')) { - $out .= $this->getHtmlForDeliveryreceipt(); - } - - // Topic - if (!empty($this->withtopic)) { - $out .= $this->getHtmlForTopic($arraydefaultmessage, $helpforsubstitution); - } - - // Attached files - if (!empty($this->withfile)) { - $out .= ''; - $out .= ''; - - $out .= '\n"; } else { - $out .= '
'; + $out .= '\n"; } } - if (is_numeric($this->withfile)) { - // TODO Trick to have param removedfile containing nb of file to delete. But this does not works without javascript - $out .= ''."\n"; - $out .= ''."\n"; - if (count($listofpaths)) { - foreach ($listofpaths as $key => $val) { - $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val))); + // To + if (!empty($this->withto) || is_array($this->withto)) { + $out .= $this->getHtmlForTo(); + } - $entity = (isset($this->param['object_entity']) ? $this->param['object_entity'] : $conf->entity); - if ($entity > 1) { - $relativepathtofile = str_replace('/'.$entity.'/', '/', $relativepathtofile); + // To User + if (!empty($this->withtouser) && is_array($this->withtouser) && getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) { + $out .= '\n"; + } + + // With option for one email per recipient + if (!empty($this->withoptiononeemailperrecipient)) { + if (abs($this->withoptiononeemailperrecipient) == 1) { + $out .= ''; + } else { + $out .= ''; + } + } + + // CC + if (!empty($this->withtocc) || is_array($this->withtocc)) { + $out .= $this->getHtmlForCc(); + } + + // To User cc + if (!empty($this->withtoccuser) && is_array($this->withtoccuser) && getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) { + $out .= '\n"; + } + + // CCC + if (!empty($this->withtoccc) || is_array($this->withtoccc)) { + $out .= $this->getHtmlForWithCcc(); + } + + // Replyto + if (!empty($this->withreplyto)) { + if ($this->withreplytoreadonly) { + $out .= ''; + $out .= ''; + $out .= "\n"; + } + } + + // Errorsto + if (!empty($this->witherrorsto)) { + $out .= $this->getHtmlForWithErrorsTo(); + } + + // Ask delivery receipt + if (!empty($this->withdeliveryreceipt) && getDolGlobalInt('MAIN_EMAIL_SUPPORT_ACK')) { + $out .= $this->getHtmlForDeliveryreceipt(); + } + + // Topic + if (!empty($this->withtopic)) { + $out .= $this->getHtmlForTopic($arraydefaultmessage, $helpforsubstitution); + } + + // Attached files + if (!empty($this->withfile)) { + $out .= ''; + $out .= ''; + + $out .= '\n"; } - $out .= "\n"; - } - - // Message (+ Links to choose layout or ai prompt) - if (!empty($this->withbody)) { - $defaultmessage = GETPOST('message', 'restricthtml'); - if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') { - if ($arraydefaultmessage && $arraydefaultmessage->content) { - $defaultmessage = $arraydefaultmessage->content; - } elseif (!is_numeric($this->withbody)) { - $defaultmessage = $this->withbody; + // Message (+ Links to choose layout or ai prompt) + if (!empty($this->withbody)) { + $defaultmessage = GETPOST('message', 'restricthtml'); + if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') { + if ($arraydefaultmessage && $arraydefaultmessage->content) { + $defaultmessage = $arraydefaultmessage->content; + } elseif (!is_numeric($this->withbody)) { + $defaultmessage = $this->withbody; + } } - } - // Complete substitution array with the url to make online payment - $paymenturl = ''; - // Set the online payment url link into __ONLINE_PAYMENT_URL__ key - require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; - $validpaymentmethod = getValidOnlinePaymentMethods(''); - - if (empty($this->substit['__REF__'])) { // @phan-suppress-current-line PhanTypeMismatchProperty + // Complete substitution array with the url to make online payment $paymenturl = ''; - } else { - $langs->loadLangs(array('paypal', 'other')); - $typeforonlinepayment = 'free'; - if ($this->param["models"] == 'order' || $this->param["models"] == 'order_send') { - $typeforonlinepayment = 'order'; // TODO use detection on something else than template - } - if ($this->param["models"] == 'invoice' || $this->param["models"] == 'facture_send') { - $typeforonlinepayment = 'invoice'; // TODO use detection on something else than template - } - if ($this->param["models"] == 'member') { - $typeforonlinepayment = 'member'; // TODO use detection on something else than template - } - $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit['__REF__']); - $paymenturl = $url; - } + // Set the online payment url link into __ONLINE_PAYMENT_URL__ key + require_once DOL_DOCUMENT_ROOT . '/core/lib/payments.lib.php'; + $validpaymentmethod = getValidOnlinePaymentMethods(''); - if (count($validpaymentmethod) > 0 && $paymenturl) { - $langs->load('other'); - $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace('\n', "\n", $langs->transnoentities("PredefinedMailContentLink", $paymenturl)); - $this->substit['__ONLINE_PAYMENT_URL__'] = $paymenturl; - } elseif (count($validpaymentmethod) > 0) { - $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = '__ONLINE_PAYMENT_TEXT_AND_URL__'; - $this->substit['__ONLINE_PAYMENT_URL__'] = '__ONLINE_PAYMENT_URL__'; - } else { - $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = ''; - $this->substit['__ONLINE_PAYMENT_URL__'] = ''; - } - - $this->substit['__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] = ''; - - // Generate the string with the template for lines repeated and filled for each line - $lines = ''; - $defaultlines = $arraydefaultmessage->content_lines; - if (isset($defaultlines)) { - foreach ($this->substit_lines as $lineid => $substit_line) { - $lines .= make_substitutions($defaultlines, $substit_line)."\n"; - } - } - $this->substit['__LINES__'] = $lines; - - $defaultmessage = str_replace('\n', "\n", $defaultmessage); - - // Deal with format differences between message and some substitution variables (text / HTML) - $atleastonecomponentishtml = 0; - if (strpos($defaultmessage, '__USER_SIGNATURE__') !== false && dol_textishtml($this->substit['__USER_SIGNATURE__'])) { - $atleastonecomponentishtml++; - } - if (strpos($defaultmessage, '__SENDEREMAIL_SIGNATURE__') !== false && dol_textishtml($this->substit['__SENDEREMAIL_SIGNATURE__'])) { - $atleastonecomponentishtml++; - } - if (strpos($defaultmessage, '__ONLINE_PAYMENT_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) { - $atleastonecomponentishtml++; - } - if (strpos($defaultmessage, '__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) { - $atleastonecomponentishtml++; - } - if (dol_textishtml($defaultmessage)) { - $atleastonecomponentishtml++; - } - if ($atleastonecomponentishtml) { - if (!dol_textishtml($this->substit['__USER_SIGNATURE__'])) { - $this->substit['__USER_SIGNATURE__'] = dol_nl2br($this->substit['__USER_SIGNATURE__']); - } - if (!dol_textishtml($this->substit['__SENDEREMAIL_SIGNATURE__'])) { - $this->substit['__SENDEREMAIL_SIGNATURE__'] = dol_nl2br($this->substit['__SENDEREMAIL_SIGNATURE__']); - } - if (!dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) { - $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = dol_nl2br($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__']); - } - if (!dol_textishtml($defaultmessage)) { - $defaultmessage = dol_nl2br($defaultmessage); - } - } - - if (GETPOSTISSET("message") && !GETPOST('modelselected')) { - $defaultmessage = GETPOST("message", "restricthtml"); - } else { - $defaultmessage = make_substitutions($defaultmessage, $this->substit); - // Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty) - $defaultmessage = preg_replace("/^(
)+/", "", $defaultmessage); - $defaultmessage = preg_replace("/^\n+/", "", $defaultmessage); - } - - $out .= ''; - $out .= ''; - $out .= ''; - $out .= ''; - - $out .= ''; - $out .= ''; + $out .= ''; + $out .= ''; + $out .= ''; + + $out .= ''; + $out .= '\n"; } - $out .= "\n"; - } - $out .= '
'; + if (is_numeric($this->withsubstit)) { + $out .= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // Old usage + } else { + $out .= $form->textwithpicto($langs->trans('AvailableVariables'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // New usage + } + $out .= "
' . $langs->trans("MailFrom") . ''; + + // $this->fromtype is the default value to use to select sender + if (!($this->fromtype === 'user' && $this->fromid > 0) + && !($this->fromtype === 'company') + && !($this->fromtype === 'robot') + && !preg_match('/user_aliases/', $this->fromtype) + && !preg_match('/global_aliases/', $this->fromtype) + && !preg_match('/senderprofile/', $this->fromtype) + ) { + // Use this->fromname and this->frommail or error if not defined + $out .= $this->fromname; + if ($this->frommail) { + $out .= ' <' . $this->frommail . '>'; + } else { + if ($this->fromtype) { + $langs->load('errors'); + $out .= ' <' . $langs->trans('ErrorNoMailDefinedForThisUser') . '> '; + } + } + } else { + $liste = array(); + + // Add user email + if (empty($user->email)) { $langs->load('errors'); - $out .= ' <'.$langs->trans('ErrorNoMailDefinedForThisUser').'> '; + $s = $user->getFullName($langs) . ' <' . $langs->trans('ErrorNoMailDefinedForThisUser') . '>'; + } else { + $s = $user->getFullName($langs) . ' <' . $user->email . '>'; } - } - } else { - $liste = array(); + $liste['user'] = array('label' => $s, 'data-html' => $s); - // Add user email - if (empty($user->email)) { - $langs->load('errors'); - $s = $user->getFullName($langs).' <'.$langs->trans('ErrorNoMailDefinedForThisUser').'>'; - } else { - $s = $user->getFullName($langs).' <'.$user->email.'>'; - } - $liste['user'] = array('label' => $s, 'data-html' => $s); - - // Add also company main email - if (getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')) { - $s = (!getDolGlobalString('MAIN_INFO_SOCIETE_NOM') ? $conf->global->MAIN_INFO_SOCIETE_EMAIL : $conf->global->MAIN_INFO_SOCIETE_NOM).' <' . getDolGlobalString('MAIN_INFO_SOCIETE_MAIL').'>'; - $liste['company'] = array('label' => $s, 'data-html' => $s); - } - - // Add also email aliases if there is some - $listaliases = array( - 'user_aliases' => (empty($user->email_aliases) ? '' : $user->email_aliases), - 'global_aliases' => getDolGlobalString('MAIN_INFO_SOCIETE_MAIL_ALIASES'), - ); - - if (!empty($arraydefaultmessage->email_from)) { - $templatemailfrom = ' <'.$arraydefaultmessage->email_from.'>'; - $liste['from_template_'.GETPOST('modelmailselected')] = array('label' => $templatemailfrom, 'data-html' => $templatemailfrom); - } - - // Also add robot email - if (!empty($this->fromalsorobot)) { - if (getDolGlobalString('MAIN_MAIL_EMAIL_FROM') && getDolGlobalString('MAIN_MAIL_EMAIL_FROM') != getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')) { - $s = getDolGlobalString('MAIN_MAIL_EMAIL_FROM'); - if ($this->frommail) { - $s .= ' <' . getDolGlobalString('MAIN_MAIL_EMAIL_FROM').'>'; - } - $liste['main_from'] = array('label' => $s, 'data-html' => $s); + // Add also company main email + if (getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')) { + $s = (!getDolGlobalString('MAIN_INFO_SOCIETE_NOM') ? $conf->global->MAIN_INFO_SOCIETE_EMAIL : $conf->global->MAIN_INFO_SOCIETE_NOM) . ' <' . getDolGlobalString('MAIN_INFO_SOCIETE_MAIL') . '>'; + $liste['company'] = array('label' => $s, 'data-html' => $s); } - } - // Add also email aliases from the c_email_senderprofile table - $sql = "SELECT rowid, label, email FROM ".$this->db->prefix()."c_email_senderprofile"; - $sql .= " WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).")"; - $sql .= " ORDER BY position"; - $resql = $this->db->query($sql); - if ($resql) { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) { - $obj = $this->db->fetch_object($resql); - if ($obj) { - $listaliases['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>'; - } - $i++; + // Add also email aliases if there is some + $listaliases = array( + 'user_aliases' => (empty($user->email_aliases) ? '' : $user->email_aliases), + 'global_aliases' => getDolGlobalString('MAIN_INFO_SOCIETE_MAIL_ALIASES'), + ); + + if (!empty($arraydefaultmessage->email_from)) { + $templatemailfrom = ' <' . $arraydefaultmessage->email_from . '>'; + $liste['from_template_' . GETPOST('modelmailselected')] = array('label' => $templatemailfrom, 'data-html' => $templatemailfrom); } - } else { - dol_print_error($this->db); - } - foreach ($listaliases as $typealias => $listalias) { - $posalias = 0; - $listaliasarray = explode(',', $listalias); - foreach ($listaliasarray as $listaliasval) { - $posalias++; - $listaliasval = trim($listaliasval); - if ($listaliasval) { - $listaliasval = preg_replace('//', '>', $listaliasval); - if (!preg_match('/</', $listaliasval)) { - $listaliasval = '<'.$listaliasval.'>'; + // Also add robot email + if (!empty($this->fromalsorobot)) { + if (getDolGlobalString('MAIN_MAIL_EMAIL_FROM') && getDolGlobalString('MAIN_MAIL_EMAIL_FROM') != getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')) { + $s = getDolGlobalString('MAIN_MAIL_EMAIL_FROM'); + if ($this->frommail) { + $s .= ' <' . getDolGlobalString('MAIN_MAIL_EMAIL_FROM') . '>'; } - $liste[$typealias.'_'.$posalias] = array('label' => $listaliasval, 'data-html' => $listaliasval); + $liste['main_from'] = array('label' => $s, 'data-html' => $s); } } - } - // Using ajaxcombo here make the '' no more visible on list because is not a valid html tag, - // so we transform before each record into $liste to be printable with ajaxcombo by replacing <> into () - // $liste['senderprofile_0_0'] = array('label'=>'rrr', 'data-html'=>'rrr <aaaa>'); - foreach ($liste as $key => $val) { - if (!empty($liste[$key]['data-html'])) { - $liste[$key]['data-html'] = str_replace(array('<', '<', '>', '>'), array('__LTCHAR__', '__LTCHAR__', '__GTCHAR__', '__GTCHAR__'), $liste[$key]['data-html']); - $liste[$key]['data-html'] = str_replace(array('__LTCHAR__', '__GTCHAR__'), array('(', ')'), $liste[$key]['data-html']); + // Add also email aliases from the c_email_senderprofile table + $sql = "SELECT rowid, label, email FROM " . $this->db->prefix() . "c_email_senderprofile"; + $sql .= " WHERE active = 1 AND (private = 0 OR private = " . ((int)$user->id) . ")"; + $sql .= " ORDER BY position"; + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) { + $obj = $this->db->fetch_object($resql); + if ($obj) { + $listaliases['senderprofile_' . $obj->rowid] = $obj->label . ' <' . $obj->email . '>'; + } + $i++; + } + } else { + dol_print_error($this->db); } + + foreach ($listaliases as $typealias => $listalias) { + $posalias = 0; + $listaliasarray = explode(',', $listalias); + foreach ($listaliasarray as $listaliasval) { + $posalias++; + $listaliasval = trim($listaliasval); + if ($listaliasval) { + $listaliasval = preg_replace('//', '>', $listaliasval); + if (!preg_match('/</', $listaliasval)) { + $listaliasval = '<' . $listaliasval . '>'; + } + $liste[$typealias . '_' . $posalias] = array('label' => $listaliasval, 'data-html' => $listaliasval); + } + } + } + + // Using ajaxcombo here make the '' no more visible on list because is not a valid html tag, + // so we transform before each record into $liste to be printable with ajaxcombo by replacing <> into () + // $liste['senderprofile_0_0'] = array('label'=>'rrr', 'data-html'=>'rrr <aaaa>'); + foreach ($liste as $key => $val) { + if (!empty($liste[$key]['data-html'])) { + $liste[$key]['data-html'] = str_replace(array('<', '<', '>', '>'), array('__LTCHAR__', '__LTCHAR__', '__GTCHAR__', '__GTCHAR__'), $liste[$key]['data-html']); + $liste[$key]['data-html'] = str_replace(array('__LTCHAR__', '__GTCHAR__'), array('(', ')'), $liste[$key]['data-html']); + } + } + $out .= ' ' . $form->selectarray('fromtype', $liste, empty($arraydefaultmessage->email_from) ? $this->fromtype : 'from_template_' . GETPOST('modelmailselected'), 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 1, '', $disablebademails); } - $out .= ' '.$form->selectarray('fromtype', $liste, empty($arraydefaultmessage->email_from) ? $this->fromtype : 'from_template_'.GETPOST('modelmailselected'), 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 1, '', $disablebademails); - } - $out .= "
'.$langs->trans("MailFrom").""; - $out .= $langs->trans("Name").':'; - $out .= '    '; - $out .= $langs->trans("EMail").':<>'; - $out .= "
'; - $out .= $langs->trans("MailToUsers"); - $out .= ''; - - // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time - $tmparray = $this->withtouser; - foreach ($tmparray as $key => $val) { - $tmparray[$key] = dol_htmlentities($tmparray[$key], 0, 'UTF-8', true); - } - $withtoselected = GETPOST("receiveruser", 'array'); // Array of selected value - if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') { - $withtoselected = array_keys($tmparray); - } - $out .= $form->multiselectarray("receiveruser", $tmparray, $withtoselected, 0, 0, 'inline-block minwidth500', 0, ""); - $out .= "
'; - $out .= $langs->trans("GroupEmails"); - $out .= ''; - $out .= ' withoptiononeemailperrecipient > 0 ? ' checked="checked"' : '').'> '; - $out .= ''; - //$out .= ''; - //$out .= ' - '; - //$out .= $langs->trans("WarningIfYouCheckOneRecipientPerEmail"); - //$out .= ''; - if (getDolGlobalString('MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) { - if (!empty($this->withto) && !is_array($this->withto)) { - $out .= ' '.$langs->trans("or").' '; - } - } - $out .= '
'; - $out .= $langs->trans("MailToCCUsers"); - $out .= ''; - - // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time - $tmparray = $this->withtoccuser; - foreach ($tmparray as $key => $val) { - $tmparray[$key] = dol_htmlentities($tmparray[$key], 0, 'UTF-8', true); - } - $withtoselected = GETPOST("receiverccuser", 'array'); // Array of selected value - if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') { - $withtoselected = array_keys($tmparray); - } - $out .= $form->multiselectarray("receiverccuser", $tmparray, $withtoselected, 0, 0, 'inline-block minwidth500', 0, ""); - $out .= "
".$langs->trans("MailReply")."".$this->replytoname.($this->replytomail ? (" <".$this->replytomail.">") : ""); - $out .= "
'.$langs->trans("MailFile").''; - - if ($this->withmaindocfile) { - // withmaindocfile is set to 1 or -1 to show the checkbox (-1 = checked or 1 = not checked) - if (GETPOSTISSET('sendmail')) { - $this->withmaindocfile = (GETPOST('addmaindocfile', 'alpha') ? -1 : 1); - } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { - // If a template was selected, we use setup of template to define if join file checkbox is selected or not. - $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1); - } - } - - if (!empty($this->withmaindocfile)) { - if ($this->withmaindocfile == 1) { - $out .= ''; - } elseif ($this->withmaindocfile == -1) { - $out .= ''; - } - if (getDolGlobalString('MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND')) { - $out .= '
'; + $out .= "
' . $langs->trans("MailFrom") . ""; + $out .= $langs->trans("Name") . ':'; + $out .= '    '; + $out .= $langs->trans("EMail") . ':<>'; + $out .= "
'; + $out .= $langs->trans("MailToUsers"); + $out .= ''; + + // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time + $tmparray = $this->withtouser; + foreach ($tmparray as $key => $val) { + $tmparray[$key] = dol_htmlentities($tmparray[$key], 0, 'UTF-8', true); + } + $withtoselected = GETPOST("receiveruser", 'array'); // Array of selected value + if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') { + $withtoselected = array_keys($tmparray); + } + $out .= $form->multiselectarray("receiveruser", $tmparray, $withtoselected, 0, 0, 'inline-block minwidth500', 0, ""); + $out .= "
'; + $out .= $langs->trans("GroupEmails"); + $out .= ''; + $out .= ' withoptiononeemailperrecipient > 0 ? ' checked="checked"' : '') . '> '; + $out .= ''; + //$out .= ''; + //$out .= ' - '; + //$out .= $langs->trans("WarningIfYouCheckOneRecipientPerEmail"); + //$out .= ''; + if (getDolGlobalString('MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) { + if (!empty($this->withto) && !is_array($this->withto)) { + $out .= ' ' . $langs->trans("or") . ' '; } - // Try to extract data from full path - $formfile_params = array(); - preg_match('#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params); - - $out .= '
'; - // Preview of attachment - $out .= img_mime($listofnames[$key]).$listofnames[$key]; - - $out .= ' '.$formfile->showPreview(array(), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ? '' : 'entity='.((int) $entity))); - - if (!$this->withfilereadonly) { - $out .= ' '; - //$out.= ' '.img_delete($langs->trans("Remove"), 'id="removedfile_'.$key.'" name="removedfile_'.$key.'"', 'removedfile input-nobottom').''; - } - $out .= '
'; } - } /*elseif (empty($this->withmaindocfile)) { + $out .= '
'; + $out .= $langs->trans("MailToCCUsers"); + $out .= ''; + + // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time + $tmparray = $this->withtoccuser; + foreach ($tmparray as $key => $val) { + $tmparray[$key] = dol_htmlentities($tmparray[$key], 0, 'UTF-8', true); + } + $withtoselected = GETPOST("receiverccuser", 'array'); // Array of selected value + if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') { + $withtoselected = array_keys($tmparray); + } + $out .= $form->multiselectarray("receiverccuser", $tmparray, $withtoselected, 0, 0, 'inline-block minwidth500', 0, ""); + $out .= "
" . $langs->trans("MailReply") . "" . $this->replytoname . ($this->replytomail ? (" <" . $this->replytomail . ">") : ""); + $out .= "
' . $langs->trans("MailFile") . ''; + + if ($this->withmaindocfile) { + // withmaindocfile is set to 1 or -1 to show the checkbox (-1 = checked or 1 = not checked) + if (GETPOSTISSET('sendmail')) { + $this->withmaindocfile = (GETPOST('addmaindocfile', 'alpha') ? -1 : 1); + } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { + // If a template was selected, we use setup of template to define if join file checkbox is selected or not. + $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1); + } + } + + if (!empty($this->withmaindocfile)) { + if ($this->withmaindocfile == 1) { + $out .= ''; + } elseif ($this->withmaindocfile == -1) { + $out .= ''; + } + if (getDolGlobalString('MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND')) { + $out .= '
'; + } else { + $out .= '
'; + } + } + + if (is_numeric($this->withfile)) { + // TODO Trick to have param removedfile containing nb of file to delete. But this does not works without javascript + $out .= '' . "\n"; + $out .= '' . "\n"; + if (count($listofpaths)) { + foreach ($listofpaths as $key => $val) { + $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val))); + + $entity = (isset($this->param['object_entity']) ? $this->param['object_entity'] : $conf->entity); + if ($entity > 1) { + $relativepathtofile = str_replace('/' . $entity . '/', '/', $relativepathtofile); + } + // Try to extract data from full path + $formfile_params = array(); + preg_match('#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params); + + $out .= '
'; + // Preview of attachment + $out .= img_mime($listofnames[$key]) . $listofnames[$key]; + + $out .= ' ' . $formfile->showPreview(array(), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ? '' : 'entity=' . ((int)$entity))); + + if (!$this->withfilereadonly) { + $out .= ' '; + //$out.= ' '.img_delete($langs->trans("Remove"), 'id="removedfile_'.$key.'" name="removedfile_'.$key.'"', 'removedfile input-nobottom').''; + } + $out .= '
'; + } + } /*elseif (empty($this->withmaindocfile)) { //$out .= ''.$langs->trans("NoAttachedFiles").'
'; }*/ - if ($this->withfile == 2) { - $maxfilesizearray = getMaxFileSizeArray(); - $maxmin = $maxfilesizearray['maxmin']; - if ($maxmin > 0) { - $out .= ''; // MAX_FILE_SIZE must precede the field type=file + if ($this->withfile == 2) { + $maxfilesizearray = getMaxFileSizeArray(); + $maxmin = $maxfilesizearray['maxmin']; + if ($maxmin > 0) { + $out .= ''; // MAX_FILE_SIZE must precede the field type=file + } + // Can add other files + if (!getDolGlobalString('FROM_MAIL_DONT_USE_INPUT_FILE_MULTIPLE')) { + $out .= ''; + } else { + $out .= ''; + } + $out .= ' '; + $out .= ''; } - // Can add other files - if (!getDolGlobalString('FROM_MAIL_DONT_USE_INPUT_FILE_MULTIPLE')) { - $out .= ''; - } else { - $out .= ''; - } - $out .= ' '; - $out .= ''; + } else { + $out .= $this->withfile; } - } else { - $out .= $this->withfile; + + $out .= "
'; - $out .= $form->textwithpicto($langs->trans('MailText'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfrombody'); - $out .= ''; - - $formmail = $this; - $showlinktolayout = ($formmail->withfckeditor && getDolGlobalInt('MAIN_EMAIL_USE_LAYOUT')) ? $formmail->withlayout : ''; - $showlinktolayoutlabel = $langs->trans("FillMessageWithALayout"); - $showlinktoai = ($formmail->withaiprompt && isModEnabled('ai')) ? 'textgenerationemail' : ''; - $showlinktoailabel = $langs->trans("FillMessageWithAIContent"); - $formatforouput = ''; - $htmlname = 'message'; - - // Fill $out - include DOL_DOCUMENT_ROOT.'/core/tpl/formlayoutai.tpl.php'; - - $out .= '
'; - if ($this->withbodyreadonly) { - $out .= nl2br($defaultmessage); - $out .= ''; - } else { - if (!isset($this->ckeditortoolbar)) { - $this->ckeditortoolbar = 'dolibarr_mailings'; + if (empty($this->substit['__REF__'])) { // @phan-suppress-current-line PhanTypeMismatchProperty + $paymenturl = ''; + } else { + $langs->loadLangs(array('paypal', 'other')); + $typeforonlinepayment = 'free'; + if ($this->param["models"] == 'order' || $this->param["models"] == 'order_send') { + $typeforonlinepayment = 'order'; // TODO use detection on something else than template + } + if ($this->param["models"] == 'invoice' || $this->param["models"] == 'facture_send') { + $typeforonlinepayment = 'invoice'; // TODO use detection on something else than template + } + if ($this->param["models"] == 'member') { + $typeforonlinepayment = 'member'; // TODO use detection on something else than template + } + $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit['__REF__']); + $paymenturl = $url; } - // Editor wysiwyg - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - if ($this->withfckeditor == -1) { - if (getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) { - $this->withfckeditor = 1; - } else { - $this->withfckeditor = 0; + if (count($validpaymentmethod) > 0 && $paymenturl) { + $langs->load('other'); + $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace('\n', "\n", $langs->transnoentities("PredefinedMailContentLink", $paymenturl)); + $this->substit['__ONLINE_PAYMENT_URL__'] = $paymenturl; + } elseif (count($validpaymentmethod) > 0) { + $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = '__ONLINE_PAYMENT_TEXT_AND_URL__'; + $this->substit['__ONLINE_PAYMENT_URL__'] = '__ONLINE_PAYMENT_URL__'; + } else { + $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = ''; + $this->substit['__ONLINE_PAYMENT_URL__'] = ''; + } + + $this->substit['__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] = ''; + + // Generate the string with the template for lines repeated and filled for each line + $lines = ''; + $defaultlines = $arraydefaultmessage->content_lines; + if (isset($defaultlines)) { + foreach ($this->substit_lines as $lineid => $substit_line) { + $lines .= make_substitutions($defaultlines, $substit_line) . "\n"; + } + } + $this->substit['__LINES__'] = $lines; + + $defaultmessage = str_replace('\n', "\n", $defaultmessage); + + // Deal with format differences between message and some substitution variables (text / HTML) + $atleastonecomponentishtml = 0; + if (strpos($defaultmessage, '__USER_SIGNATURE__') !== false && dol_textishtml($this->substit['__USER_SIGNATURE__'])) { + $atleastonecomponentishtml++; + } + if (strpos($defaultmessage, '__SENDEREMAIL_SIGNATURE__') !== false && dol_textishtml($this->substit['__SENDEREMAIL_SIGNATURE__'])) { + $atleastonecomponentishtml++; + } + if (strpos($defaultmessage, '__ONLINE_PAYMENT_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) { + $atleastonecomponentishtml++; + } + if (strpos($defaultmessage, '__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) { + $atleastonecomponentishtml++; + } + if (dol_textishtml($defaultmessage)) { + $atleastonecomponentishtml++; + } + if ($atleastonecomponentishtml) { + if (!dol_textishtml($this->substit['__USER_SIGNATURE__'])) { + $this->substit['__USER_SIGNATURE__'] = dol_nl2br($this->substit['__USER_SIGNATURE__']); + } + if (!dol_textishtml($this->substit['__SENDEREMAIL_SIGNATURE__'])) { + $this->substit['__SENDEREMAIL_SIGNATURE__'] = dol_nl2br($this->substit['__SENDEREMAIL_SIGNATURE__']); + } + if (!dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) { + $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = dol_nl2br($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__']); + } + if (!dol_textishtml($defaultmessage)) { + $defaultmessage = dol_nl2br($defaultmessage); } } - $doleditor = new DolEditor('message', $defaultmessage, '', 280, $this->ckeditortoolbar, 'In', true, true, $this->withfckeditor, 8, '95%'); - $out .= $doleditor->Create(1); + if (GETPOSTISSET("message") && !GETPOST('modelselected')) { + $defaultmessage = GETPOST("message", "restricthtml"); + } else { + $defaultmessage = make_substitutions($defaultmessage, $this->substit); + // Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty) + $defaultmessage = preg_replace("/^(
)+/", "", $defaultmessage); + $defaultmessage = preg_replace("/^\n+/", "", $defaultmessage); + } + + $out .= '
'; + $out .= $form->textwithpicto($langs->trans('MailText'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfrombody'); + $out .= ''; + + $formmail = $this; + $showlinktolayout = ($formmail->withfckeditor && getDolGlobalInt('MAIN_EMAIL_USE_LAYOUT')) ? $formmail->withlayout : ''; + $showlinktolayoutlabel = $langs->trans("FillMessageWithALayout"); + $showlinktoai = ($formmail->withaiprompt && isModEnabled('ai')) ? 'textgenerationemail' : ''; + $showlinktoailabel = $langs->trans("FillMessageWithAIContent"); + $formatforouput = ''; + $htmlname = 'message'; + + // Fill $out + include DOL_DOCUMENT_ROOT . '/core/tpl/formlayoutai.tpl.php'; + + $out .= '
'; + if ($this->withbodyreadonly) { + $out .= nl2br($defaultmessage); + $out .= ''; + } else { + if (!isset($this->ckeditortoolbar)) { + $this->ckeditortoolbar = 'dolibarr_mailings'; + } + + // Editor wysiwyg + require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; + if ($this->withfckeditor == -1) { + if (getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) { + $this->withfckeditor = 1; + } else { + $this->withfckeditor = 0; + } + } + + $doleditor = new DolEditor('message', $defaultmessage, '', 280, $this->ckeditortoolbar, 'In', true, true, $this->withfckeditor, 8, '95%'); + $out .= $doleditor->Create(1); + } + $out .= "
'."\n"; + $out .= '
' . "\n"; - if ($this->withform == 1 || $this->withform == -1) { - $out .= '
'; - $out .= 'withfile == 2 && $conf->use_javascript_ajax) { - $out .= ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\''.dol_escape_js($langs->trans("FileWasNotUploaded")).'\'); return false; } else { return true; }"'; + if ($this->withform == 1 || $this->withform == -1) { + $out .= '
'; + $out .= 'withfile == 2 && $conf->use_javascript_ajax) { + $out .= ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\'' . dol_escape_js($langs->trans("FileWasNotUploaded")) . '\'); return false; } else { return true; }"'; + } + $out .= ' />'; + if ($this->withcancel) { + $out .= ''; + } + $out .= '
' . "\n"; } - $out .= ' />'; - if ($this->withcancel) { - $out .= ''; + + if ($this->withform == 1) { + $out .= '' . "\n"; } - $out .= '
'."\n"; - } - if ($this->withform == 1) { - $out .= ''."\n"; - } - - // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set - if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) { - $out .= ''; + $out .= ' })'; + $out .= ''; + } + + $out .= "\n"; + + return $out; } - - $out .= "\n"; - - return $out; } } - /** * get html For To * From c1058da4c5d2703cea4423bef97eb650ac72141d Mon Sep 17 00:00:00 2001 From: ATM-Lucas Date: Mon, 27 Jan 2025 10:15:56 +0100 Subject: [PATCH 6/9] Travis error --- htdocs/core/class/html.formmail.class.php | 1181 ++++++++++----------- 1 file changed, 589 insertions(+), 592 deletions(-) diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index a5881534518..21f064ba8ca 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -473,7 +473,7 @@ class FormMail extends Form global $conf, $langs, $user, $hookmanager, $form; // Required to show preview wof mail attachments - require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; $formfile = new FormFile($this->db); if (!is_object($form)) { @@ -532,632 +532,631 @@ class FormMail extends Form $listofpaths = array(); $listofnames = array(); $listofmimes = array(); - $keytoavoidconflict = empty($this->trackid) ? '' : '-' . $this->trackid; // this->trackid must be defined + $keytoavoidconflict = empty($this->trackid) ? '' : '-'.$this->trackid; // this->trackid must be defined if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) { - if (GETPOST('mode', 'alpha') == 'init' || (GETPOST('modelselected') && GETPOST('modelmailselected', 'alpha') && GETPOST('modelmailselected', 'alpha') != '-1')) { - if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param['fileinit']) && is_array($this->param['fileinit'])) { - foreach ($this->param['fileinit'] as $path) { - if (!empty($path)) { - $this->add_attached_files($path); - } + if (!empty($arraydefaultmessage->joinfiles) && !empty($this->param['fileinit']) && is_array($this->param['fileinit'])) { + foreach ($this->param['fileinit'] as $path) { + if (!empty($path)) { + $this->add_attached_files($path); } } } + } - if (!empty($_SESSION["listofpaths" . $keytoavoidconflict])) { - $listofpaths = explode(';', $_SESSION["listofpaths" . $keytoavoidconflict]); + if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) { + $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]); + } + if (!empty($_SESSION["listofnames".$keytoavoidconflict])) { + $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]); + } + if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) { + $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]); + } + + + $out .= "\n".'
'."\n"; + if ($this->withform == 1) { + $out .= '
'."\n"; + + $out .= ''; + $out .= ''; + $out .= ''; + $out .= ''; + $out .= ''; + } + if (!empty($this->withfrom)) { + if (!empty($this->withfromreadonly)) { + $out .= ''; + $out .= ''; } - if (!empty($_SESSION["listofnames" . $keytoavoidconflict])) { - $listofnames = explode(';', $_SESSION["listofnames" . $keytoavoidconflict]); - } - if (!empty($_SESSION["listofmimes" . $keytoavoidconflict])) { - $listofmimes = explode(';', $_SESSION["listofmimes" . $keytoavoidconflict]); - } - - - $out .= "\n" . '
' . "\n"; - if ($this->withform == 1) { - $out .= '' . "\n"; - - $out .= ''; - $out .= ''; - $out .= ''; - $out .= ''; - $out .= ''; - } - if (!empty($this->withfrom)) { - if (!empty($this->withfromreadonly)) { - $out .= ''; - $out .= ''; - } - } - foreach ($this->param as $key => $value) { - if (is_array($value)) { - $out .= "\n"; - } else { - $out .= '' . "\n"; - } - } - - $modelmail_array = array(); - if ($this->param['models'] != 'none') { - $result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs); - if ($result < 0) { - setEventMessages($this->error, $this->errors, 'errors'); - } - - foreach ($this->lines_model as $line) { - $reg = array(); - if (preg_match('/\((.*)\)/', $line->label, $reg)) { - $labeltouse = $langs->trans($reg[1]); // langs->trans when label is __(xxx)__ - } else { - $labeltouse = $line->label; - } - - // 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")) . ''; - } - } - } - - // Zone to select email template - if (count($modelmail_array) > 0) { - $model_mail_selected_id = GETPOSTISSET('modelmailselected') ? GETPOSTINT('modelmailselected') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0); - - // If list of template is filled - $out .= '
' . "\n"; - - $out .= $this->selectarray('modelmailselected', $modelmail_array, $model_mail_selected_id, $langs->trans('SelectMailModel'), 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 .= ''; - $out .= '   '; - $out .= '
'; - } elseif (!empty($this->param['models']) && in_array($this->param['models'], array( - 'propal_send', 'order_send', 'facture_send', - 'shipping_send', 'fichinter_send', 'supplier_proposal_send', 'order_supplier_send', - 'invoice_supplier_send', 'thirdparty', 'contract', 'user', 'recruitmentcandidature_send', 'product_send', 'all' - ))) { - // If list of template is empty - $out .= '
' . "\n"; - $out .= '' . $langs->trans('SelectMailModel') . ': '; - $out .= ''; // Do not put 'disabled' on 'option' tag, it is already on 'select' and it makes chrome crazy. - if ($user->admin) { - $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup') . ' - ' . $langs->transnoentitiesnoconv('EMails')), 1); - } - $out .= '   '; - $out .= ''; - $out .= '   '; - $out .= '
'; + } + foreach ($this->param as $key => $value) { + if (is_array($value)) { + $out .= "\n"; } else { - $out .= ''; + $out .= ''."\n"; + } + } + + $modelmail_array = array(); + if ($this->param['models'] != 'none') { + $result = $this->fetchAllEMailTemplate($this->param["models"], $user, $outputlangs); + if ($result < 0) { + setEventMessages($this->error, $this->errors, 'errors'); } - - $out .= '' . "\n"; - - // Substitution array/string - $helpforsubstitution = ''; - if (is_array($this->substit) && count($this->substit)) { - $helpforsubstitution .= $langs->trans('AvailableVariables') . ' :

' . "\n"; - } - foreach ($this->substit as $key => $val) { - // Do not show deprecated variables into the tooltip help of substitution variables - if (in_array($key, array('__NEWREF__', '__REFCLIENT__', '__REFSUPPLIER__', '__SUPPLIER_ORDER_DATE_DELIVERY__', '__SUPPLIER_ORDER_DELAY_DELIVERY__'))) { - continue; - } - $helpforsubstitution .= $key . ' -> ' . $langs->trans(dol_string_nohtmltag(dolGetFirstLineOfText($val))) . '
'; - } - if (is_array($this->substit) && count($this->substit)) { - $helpforsubstitution .= '
'; - } - - /* - if (!empty($this->withsubstit)) { // Unset or set ->withsubstit=0 to disable this. - $out .= '\n"; - }*/ - // From - if (!empty($this->withfrom)) { - if (!empty($this->withfromreadonly)) { - $out .= '
'; - if (is_numeric($this->withsubstit)) { - $out .= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // Old usage + foreach ($this->lines_model as $line) { + $reg = array(); + if (preg_match('/\((.*)\)/', $line->label, $reg)) { + $labeltouse = $langs->trans($reg[1]); // langs->trans when label is __(xxx)__ } else { - $out .= $form->textwithpicto($langs->trans('AvailableVariables'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // New usage + $labeltouse = $line->label; } - $out .= "
' . $langs->trans("MailFrom") . ''; + // 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")).''; + } + } + } - // $this->fromtype is the default value to use to select sender - if (!($this->fromtype === 'user' && $this->fromid > 0) - && !($this->fromtype === 'company') - && !($this->fromtype === 'robot') - && !preg_match('/user_aliases/', $this->fromtype) - && !preg_match('/global_aliases/', $this->fromtype) - && !preg_match('/senderprofile/', $this->fromtype) - ) { - // Use this->fromname and this->frommail or error if not defined - $out .= $this->fromname; - if ($this->frommail) { - $out .= ' <' . $this->frommail . '>'; - } else { - if ($this->fromtype) { - $langs->load('errors'); - $out .= ' <' . $langs->trans('ErrorNoMailDefinedForThisUser') . '> '; - } - } + // Zone to select email template + if (count($modelmail_array) > 0) { + $model_mail_selected_id = GETPOSTISSET('modelmailselected') ? GETPOSTINT('modelmailselected') : ($arraydefaultmessage->id > 0 ? $arraydefaultmessage->id : 0); + + // If list of template is filled + $out .= '
'."\n"; + + $out .= $this->selectarray('modelmailselected', $modelmail_array, $model_mail_selected_id, $langs->trans('SelectMailModel'), 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 .= ''; + $out .= '   '; + $out .= '
'; + } elseif (!empty($this->param['models']) && in_array($this->param['models'], array( + 'propal_send', 'order_send', 'facture_send', + 'shipping_send', 'fichinter_send', 'supplier_proposal_send', 'order_supplier_send', + 'invoice_supplier_send', 'thirdparty', 'contract', 'user', 'recruitmentcandidature_send', 'all' + ))) { + // If list of template is empty + $out .= '
'."\n"; + $out .= ''.$langs->trans('SelectMailModel').': '; + $out .= ''; // Do not put 'disabled' on 'option' tag, it is already on 'select' and it makes chrome crazy. + if ($user->admin) { + $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')), 1); + } + $out .= '   '; + $out .= ''; + $out .= '   '; + $out .= '
'; + } else { + $out .= ''; + } + + + $out .= ''."\n"; + + // Substitution array/string + $helpforsubstitution = ''; + if (is_array($this->substit) && count($this->substit)) { + $helpforsubstitution .= $langs->trans('AvailableVariables').' :

'."\n"; + } + foreach ($this->substit as $key => $val) { + // Do not show deprecated variables into the tooltip help of substitution variables + if (in_array($key, array('__NEWREF__', '__REFCLIENT__', '__REFSUPPLIER__', '__SUPPLIER_ORDER_DATE_DELIVERY__', '__SUPPLIER_ORDER_DELAY_DELIVERY__'))) { + continue; + } + $helpforsubstitution .= $key.' -> '.$langs->trans(dol_string_nohtmltag(dolGetFirstLineOfText($val))).'
'; + } + if (is_array($this->substit) && count($this->substit)) { + $helpforsubstitution .= '
'; + } + + /* + if (!empty($this->withsubstit)) { // Unset or set ->withsubstit=0 to disable this. + $out .= '\n"; + }*/ + + // From + if (!empty($this->withfrom)) { + if (!empty($this->withfromreadonly)) { + $out .= '\n"; } else { - $out .= '\n"; - } - } + $liste = array(); - // To - if (!empty($this->withto) || is_array($this->withto)) { - $out .= $this->getHtmlForTo(); - } - - // To User - if (!empty($this->withtouser) && is_array($this->withtouser) && getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) { - $out .= '\n"; - } - - // With option for one email per recipient - if (!empty($this->withoptiononeemailperrecipient)) { - if (abs($this->withoptiononeemailperrecipient) == 1) { - $out .= ''; - } else { - $out .= ''; - } - } - - // CC - if (!empty($this->withtocc) || is_array($this->withtocc)) { - $out .= $this->getHtmlForCc(); - } - - // To User cc - if (!empty($this->withtoccuser) && is_array($this->withtoccuser) && getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) { - $out .= '\n"; - } - - // CCC - if (!empty($this->withtoccc) || is_array($this->withtoccc)) { - $out .= $this->getHtmlForWithCcc(); - } - - // Replyto - if (!empty($this->withreplyto)) { - if ($this->withreplytoreadonly) { - $out .= ''; - $out .= ''; - $out .= "\n"; - } - } - - // Errorsto - if (!empty($this->witherrorsto)) { - $out .= $this->getHtmlForWithErrorsTo(); - } - - // Ask delivery receipt - if (!empty($this->withdeliveryreceipt) && getDolGlobalInt('MAIN_EMAIL_SUPPORT_ACK')) { - $out .= $this->getHtmlForDeliveryreceipt(); - } - - // Topic - if (!empty($this->withtopic)) { - $out .= $this->getHtmlForTopic($arraydefaultmessage, $helpforsubstitution); - } - - // Attached files - if (!empty($this->withfile)) { - $out .= ''; - $out .= ''; - - $out .= '\n"; + } else { + $out .= '\n"; + } + } - $entity = (isset($this->param['object_entity']) ? $this->param['object_entity'] : $conf->entity); - if ($entity > 1) { - $relativepathtofile = str_replace('/' . $entity . '/', '/', $relativepathtofile); - } - // Try to extract data from full path - $formfile_params = array(); - preg_match('#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params); + // To + if (!empty($this->withto) || is_array($this->withto)) { + $out .= $this->getHtmlForTo(); + } - $out .= '
'; - // Preview of attachment - $out .= img_mime($listofnames[$key]) . $listofnames[$key]; + // To User + if (!empty($this->withtouser) && is_array($this->withtouser) && getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) { + $out .= '
\n"; + } - if (!$this->withfilereadonly) { - $out .= ' '; - //$out.= ' '.img_delete($langs->trans("Remove"), 'id="removedfile_'.$key.'" name="removedfile_'.$key.'"', 'removedfile input-nobottom').''; - } - $out .= '
'; + // With option for one email per recipient + if (!empty($this->withoptiononeemailperrecipient)) { + if (abs($this->withoptiononeemailperrecipient) == 1) { + $out .= ''; + } else { + $out .= ''; + } + } + + // CC + if (!empty($this->withtocc) || is_array($this->withtocc)) { + $out .= $this->getHtmlForCc(); + } + + // To User cc + if (!empty($this->withtoccuser) && is_array($this->withtoccuser) && getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) { + $out .= '\n"; + } + + // CCC + if (!empty($this->withtoccc) || is_array($this->withtoccc)) { + $out .= $this->getHtmlForWithCcc(); + } + + // Replyto + if (!empty($this->withreplyto)) { + if ($this->withreplytoreadonly) { + $out .= ''; + $out .= ''; + $out .= "\n"; + } + } + + // Errorsto + if (!empty($this->witherrorsto)) { + $out .= $this->getHtmlForWithErrorsTo(); + } + + // Ask delivery receipt + if (!empty($this->withdeliveryreceipt) && getDolGlobalInt('MAIN_EMAIL_SUPPORT_ACK')) { + $out .= $this->getHtmlForDeliveryreceipt(); + } + + // Topic + if (!empty($this->withtopic)) { + $out .= $this->getHtmlForTopic($arraydefaultmessage, $helpforsubstitution); + } + + // Attached files + if (!empty($this->withfile)) { + $out .= ''; + $out .= ''; + + $out .= '\n"; + } else { + $out .= $this->withfile; } - // Message (+ Links to choose layout or ai prompt) - if (!empty($this->withbody)) { - $defaultmessage = GETPOST('message', 'restricthtml'); - if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') { - if ($arraydefaultmessage && $arraydefaultmessage->content) { - $defaultmessage = $arraydefaultmessage->content; - } elseif (!is_numeric($this->withbody)) { - $defaultmessage = $this->withbody; - } - } + $out .= "\n"; + } - // Complete substitution array with the url to make online payment + // Message (+ Links to choose layout or ai prompt) + if (!empty($this->withbody)) { + $defaultmessage = GETPOST('message', 'restricthtml'); + if (!GETPOST('modelselected', 'alpha') || GETPOST('modelmailselected') != '-1') { + if ($arraydefaultmessage && $arraydefaultmessage->content) { + $defaultmessage = $arraydefaultmessage->content; + } elseif (!is_numeric($this->withbody)) { + $defaultmessage = $this->withbody; + } + } + + // Complete substitution array with the url to make online payment + $paymenturl = ''; + // Set the online payment url link into __ONLINE_PAYMENT_URL__ key + require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; + $validpaymentmethod = getValidOnlinePaymentMethods(''); + + if (empty($this->substit['__REF__'])) { // @phan-suppress-current-line PhanTypeMismatchProperty $paymenturl = ''; - // Set the online payment url link into __ONLINE_PAYMENT_URL__ key - require_once DOL_DOCUMENT_ROOT . '/core/lib/payments.lib.php'; - $validpaymentmethod = getValidOnlinePaymentMethods(''); - - if (empty($this->substit['__REF__'])) { // @phan-suppress-current-line PhanTypeMismatchProperty - $paymenturl = ''; - } else { - $langs->loadLangs(array('paypal', 'other')); - $typeforonlinepayment = 'free'; - if ($this->param["models"] == 'order' || $this->param["models"] == 'order_send') { - $typeforonlinepayment = 'order'; // TODO use detection on something else than template - } - if ($this->param["models"] == 'invoice' || $this->param["models"] == 'facture_send') { - $typeforonlinepayment = 'invoice'; // TODO use detection on something else than template - } - if ($this->param["models"] == 'member') { - $typeforonlinepayment = 'member'; // TODO use detection on something else than template - } - $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit['__REF__']); - $paymenturl = $url; + } else { + $langs->loadLangs(array('paypal', 'other')); + $typeforonlinepayment = 'free'; + if ($this->param["models"] == 'order' || $this->param["models"] == 'order_send') { + $typeforonlinepayment = 'order'; // TODO use detection on something else than template } - - if (count($validpaymentmethod) > 0 && $paymenturl) { - $langs->load('other'); - $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace('\n', "\n", $langs->transnoentities("PredefinedMailContentLink", $paymenturl)); - $this->substit['__ONLINE_PAYMENT_URL__'] = $paymenturl; - } elseif (count($validpaymentmethod) > 0) { - $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = '__ONLINE_PAYMENT_TEXT_AND_URL__'; - $this->substit['__ONLINE_PAYMENT_URL__'] = '__ONLINE_PAYMENT_URL__'; - } else { - $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = ''; - $this->substit['__ONLINE_PAYMENT_URL__'] = ''; + if ($this->param["models"] == 'invoice' || $this->param["models"] == 'facture_send') { + $typeforonlinepayment = 'invoice'; // TODO use detection on something else than template } - - $this->substit['__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] = ''; - - // Generate the string with the template for lines repeated and filled for each line - $lines = ''; - $defaultlines = $arraydefaultmessage->content_lines; - if (isset($defaultlines)) { - foreach ($this->substit_lines as $lineid => $substit_line) { - $lines .= make_substitutions($defaultlines, $substit_line) . "\n"; - } + if ($this->param["models"] == 'member') { + $typeforonlinepayment = 'member'; // TODO use detection on something else than template } - $this->substit['__LINES__'] = $lines; - - $defaultmessage = str_replace('\n', "\n", $defaultmessage); - - // Deal with format differences between message and some substitution variables (text / HTML) - $atleastonecomponentishtml = 0; - if (strpos($defaultmessage, '__USER_SIGNATURE__') !== false && dol_textishtml($this->substit['__USER_SIGNATURE__'])) { - $atleastonecomponentishtml++; - } - if (strpos($defaultmessage, '__SENDEREMAIL_SIGNATURE__') !== false && dol_textishtml($this->substit['__SENDEREMAIL_SIGNATURE__'])) { - $atleastonecomponentishtml++; - } - if (strpos($defaultmessage, '__ONLINE_PAYMENT_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) { - $atleastonecomponentishtml++; - } - if (strpos($defaultmessage, '__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) { - $atleastonecomponentishtml++; - } - if (dol_textishtml($defaultmessage)) { - $atleastonecomponentishtml++; - } - if ($atleastonecomponentishtml) { - if (!dol_textishtml($this->substit['__USER_SIGNATURE__'])) { - $this->substit['__USER_SIGNATURE__'] = dol_nl2br($this->substit['__USER_SIGNATURE__']); - } - if (!dol_textishtml($this->substit['__SENDEREMAIL_SIGNATURE__'])) { - $this->substit['__SENDEREMAIL_SIGNATURE__'] = dol_nl2br($this->substit['__SENDEREMAIL_SIGNATURE__']); - } - if (!dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) { - $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = dol_nl2br($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__']); - } - if (!dol_textishtml($defaultmessage)) { - $defaultmessage = dol_nl2br($defaultmessage); - } - } - - if (GETPOSTISSET("message") && !GETPOST('modelselected')) { - $defaultmessage = GETPOST("message", "restricthtml"); - } else { - $defaultmessage = make_substitutions($defaultmessage, $this->substit); - // Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty) - $defaultmessage = preg_replace("/^(
)+/", "", $defaultmessage); - $defaultmessage = preg_replace("/^\n+/", "", $defaultmessage); - } - - $out .= ''; - $out .= ''; - $out .= ''; - $out .= ''; - - $out .= ''; - $out .= '\n"; + $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit['__REF__']); + $paymenturl = $url; } - $out .= '
'; + if (is_numeric($this->withsubstit)) { + $out .= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // Old usage + } else { + $out .= $form->textwithpicto($langs->trans('AvailableVariables'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip'); // New usage + } + $out .= "
'.$langs->trans("MailFrom").''; + + // $this->fromtype is the default value to use to select sender + if (!($this->fromtype === 'user' && $this->fromid > 0) + && !($this->fromtype === 'company') + && !($this->fromtype === 'robot') + && !preg_match('/user_aliases/', $this->fromtype) + && !preg_match('/global_aliases/', $this->fromtype) + && !preg_match('/senderprofile/', $this->fromtype) + ) { + // Use this->fromname and this->frommail or error if not defined + $out .= $this->fromname; + if ($this->frommail) { + $out .= ' <'.$this->frommail.'>'; } else { - $liste = array(); - - // Add user email - if (empty($user->email)) { + if ($this->fromtype) { $langs->load('errors'); - $s = $user->getFullName($langs) . ' <' . $langs->trans('ErrorNoMailDefinedForThisUser') . '>'; - } else { - $s = $user->getFullName($langs) . ' <' . $user->email . '>'; + $out .= ' <'.$langs->trans('ErrorNoMailDefinedForThisUser').'> '; } - $liste['user'] = array('label' => $s, 'data-html' => $s); - - // Add also company main email - if (getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')) { - $s = (!getDolGlobalString('MAIN_INFO_SOCIETE_NOM') ? $conf->global->MAIN_INFO_SOCIETE_EMAIL : $conf->global->MAIN_INFO_SOCIETE_NOM) . ' <' . getDolGlobalString('MAIN_INFO_SOCIETE_MAIL') . '>'; - $liste['company'] = array('label' => $s, 'data-html' => $s); - } - - // Add also email aliases if there is some - $listaliases = array( - 'user_aliases' => (empty($user->email_aliases) ? '' : $user->email_aliases), - 'global_aliases' => getDolGlobalString('MAIN_INFO_SOCIETE_MAIL_ALIASES'), - ); - - if (!empty($arraydefaultmessage->email_from)) { - $templatemailfrom = ' <' . $arraydefaultmessage->email_from . '>'; - $liste['from_template_' . GETPOST('modelmailselected')] = array('label' => $templatemailfrom, 'data-html' => $templatemailfrom); - } - - // Also add robot email - if (!empty($this->fromalsorobot)) { - if (getDolGlobalString('MAIN_MAIL_EMAIL_FROM') && getDolGlobalString('MAIN_MAIL_EMAIL_FROM') != getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')) { - $s = getDolGlobalString('MAIN_MAIL_EMAIL_FROM'); - if ($this->frommail) { - $s .= ' <' . getDolGlobalString('MAIN_MAIL_EMAIL_FROM') . '>'; - } - $liste['main_from'] = array('label' => $s, 'data-html' => $s); - } - } - - // Add also email aliases from the c_email_senderprofile table - $sql = "SELECT rowid, label, email FROM " . $this->db->prefix() . "c_email_senderprofile"; - $sql .= " WHERE active = 1 AND (private = 0 OR private = " . ((int)$user->id) . ")"; - $sql .= " ORDER BY position"; - $resql = $this->db->query($sql); - if ($resql) { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) { - $obj = $this->db->fetch_object($resql); - if ($obj) { - $listaliases['senderprofile_' . $obj->rowid] = $obj->label . ' <' . $obj->email . '>'; - } - $i++; - } - } else { - dol_print_error($this->db); - } - - foreach ($listaliases as $typealias => $listalias) { - $posalias = 0; - $listaliasarray = explode(',', $listalias); - foreach ($listaliasarray as $listaliasval) { - $posalias++; - $listaliasval = trim($listaliasval); - if ($listaliasval) { - $listaliasval = preg_replace('//', '>', $listaliasval); - if (!preg_match('/</', $listaliasval)) { - $listaliasval = '<' . $listaliasval . '>'; - } - $liste[$typealias . '_' . $posalias] = array('label' => $listaliasval, 'data-html' => $listaliasval); - } - } - } - - // Using ajaxcombo here make the '' no more visible on list because is not a valid html tag, - // so we transform before each record into $liste to be printable with ajaxcombo by replacing <> into () - // $liste['senderprofile_0_0'] = array('label'=>'rrr', 'data-html'=>'rrr <aaaa>'); - foreach ($liste as $key => $val) { - if (!empty($liste[$key]['data-html'])) { - $liste[$key]['data-html'] = str_replace(array('<', '<', '>', '>'), array('__LTCHAR__', '__LTCHAR__', '__GTCHAR__', '__GTCHAR__'), $liste[$key]['data-html']); - $liste[$key]['data-html'] = str_replace(array('__LTCHAR__', '__GTCHAR__'), array('(', ')'), $liste[$key]['data-html']); - } - } - $out .= ' ' . $form->selectarray('fromtype', $liste, empty($arraydefaultmessage->email_from) ? $this->fromtype : 'from_template_' . GETPOST('modelmailselected'), 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 1, '', $disablebademails); } - - $out .= "
' . $langs->trans("MailFrom") . ""; - $out .= $langs->trans("Name") . ':'; - $out .= '    '; - $out .= $langs->trans("EMail") . ':<>'; - $out .= "
'; - $out .= $langs->trans("MailToUsers"); - $out .= ''; - - // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time - $tmparray = $this->withtouser; - foreach ($tmparray as $key => $val) { - $tmparray[$key] = dol_htmlentities($tmparray[$key], 0, 'UTF-8', true); - } - $withtoselected = GETPOST("receiveruser", 'array'); // Array of selected value - if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') { - $withtoselected = array_keys($tmparray); - } - $out .= $form->multiselectarray("receiveruser", $tmparray, $withtoselected, 0, 0, 'inline-block minwidth500', 0, ""); - $out .= "
'; - $out .= $langs->trans("GroupEmails"); - $out .= ''; - $out .= ' withoptiononeemailperrecipient > 0 ? ' checked="checked"' : '') . '> '; - $out .= ''; - //$out .= ''; - //$out .= ' - '; - //$out .= $langs->trans("WarningIfYouCheckOneRecipientPerEmail"); - //$out .= ''; - if (getDolGlobalString('MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) { - if (!empty($this->withto) && !is_array($this->withto)) { - $out .= ' ' . $langs->trans("or") . ' '; - } - } - $out .= '
'; - $out .= $langs->trans("MailToCCUsers"); - $out .= ''; - - // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time - $tmparray = $this->withtoccuser; - foreach ($tmparray as $key => $val) { - $tmparray[$key] = dol_htmlentities($tmparray[$key], 0, 'UTF-8', true); - } - $withtoselected = GETPOST("receiverccuser", 'array'); // Array of selected value - if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') { - $withtoselected = array_keys($tmparray); - } - $out .= $form->multiselectarray("receiverccuser", $tmparray, $withtoselected, 0, 0, 'inline-block minwidth500', 0, ""); - $out .= "
" . $langs->trans("MailReply") . "" . $this->replytoname . ($this->replytomail ? (" <" . $this->replytomail . ">") : ""); - $out .= "
' . $langs->trans("MailFile") . ''; - - if ($this->withmaindocfile) { - // withmaindocfile is set to 1 or -1 to show the checkbox (-1 = checked or 1 = not checked) - if (GETPOSTISSET('sendmail')) { - $this->withmaindocfile = (GETPOST('addmaindocfile', 'alpha') ? -1 : 1); - } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { - // If a template was selected, we use setup of template to define if join file checkbox is selected or not. - $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1); - } - } - - if (!empty($this->withmaindocfile)) { - if ($this->withmaindocfile == 1) { - $out .= ''; - } elseif ($this->withmaindocfile == -1) { - $out .= ''; - } - if (getDolGlobalString('MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND')) { - $out .= '
'; + // Add user email + if (empty($user->email)) { + $langs->load('errors'); + $s = $user->getFullName($langs).' <'.$langs->trans('ErrorNoMailDefinedForThisUser').'>'; } else { - $out .= '
'; + $s = $user->getFullName($langs).' <'.$user->email.'>'; } + $liste['user'] = array('label' => $s, 'data-html' => $s); + + // Add also company main email + if (getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')) { + $s = (!getDolGlobalString('MAIN_INFO_SOCIETE_NOM') ? $conf->global->MAIN_INFO_SOCIETE_EMAIL : $conf->global->MAIN_INFO_SOCIETE_NOM).' <' . getDolGlobalString('MAIN_INFO_SOCIETE_MAIL').'>'; + $liste['company'] = array('label' => $s, 'data-html' => $s); + } + + // Add also email aliases if there is some + $listaliases = array( + 'user_aliases' => (empty($user->email_aliases) ? '' : $user->email_aliases), + 'global_aliases' => getDolGlobalString('MAIN_INFO_SOCIETE_MAIL_ALIASES'), + ); + + if (!empty($arraydefaultmessage->email_from)) { + $templatemailfrom = ' <'.$arraydefaultmessage->email_from.'>'; + $liste['from_template_'.GETPOST('modelmailselected')] = array('label' => $templatemailfrom, 'data-html' => $templatemailfrom); + } + + // Also add robot email + if (!empty($this->fromalsorobot)) { + if (getDolGlobalString('MAIN_MAIL_EMAIL_FROM') && getDolGlobalString('MAIN_MAIL_EMAIL_FROM') != getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')) { + $s = getDolGlobalString('MAIN_MAIL_EMAIL_FROM'); + if ($this->frommail) { + $s .= ' <' . getDolGlobalString('MAIN_MAIL_EMAIL_FROM').'>'; + } + $liste['main_from'] = array('label' => $s, 'data-html' => $s); + } + } + + // Add also email aliases from the c_email_senderprofile table + $sql = "SELECT rowid, label, email FROM ".$this->db->prefix()."c_email_senderprofile"; + $sql .= " WHERE active = 1 AND (private = 0 OR private = ".((int) $user->id).")"; + $sql .= " ORDER BY position"; + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) { + $obj = $this->db->fetch_object($resql); + if ($obj) { + $listaliases['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>'; + } + $i++; + } + } else { + dol_print_error($this->db); + } + + foreach ($listaliases as $typealias => $listalias) { + $posalias = 0; + $listaliasarray = explode(',', $listalias); + foreach ($listaliasarray as $listaliasval) { + $posalias++; + $listaliasval = trim($listaliasval); + if ($listaliasval) { + $listaliasval = preg_replace('//', '>', $listaliasval); + if (!preg_match('/</', $listaliasval)) { + $listaliasval = '<'.$listaliasval.'>'; + } + $liste[$typealias.'_'.$posalias] = array('label' => $listaliasval, 'data-html' => $listaliasval); + } + } + } + + // Using ajaxcombo here make the '' no more visible on list because is not a valid html tag, + // so we transform before each record into $liste to be printable with ajaxcombo by replacing <> into () + // $liste['senderprofile_0_0'] = array('label'=>'rrr', 'data-html'=>'rrr <aaaa>'); + foreach ($liste as $key => $val) { + if (!empty($liste[$key]['data-html'])) { + $liste[$key]['data-html'] = str_replace(array('<', '<', '>', '>'), array('__LTCHAR__', '__LTCHAR__', '__GTCHAR__', '__GTCHAR__'), $liste[$key]['data-html']); + $liste[$key]['data-html'] = str_replace(array('__LTCHAR__', '__GTCHAR__'), array('(', ')'), $liste[$key]['data-html']); + } + } + $out .= ' '.$form->selectarray('fromtype', $liste, empty($arraydefaultmessage->email_from) ? $this->fromtype : 'from_template_'.GETPOST('modelmailselected'), 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 1, '', $disablebademails); } - if (is_numeric($this->withfile)) { - // TODO Trick to have param removedfile containing nb of file to delete. But this does not works without javascript - $out .= '' . "\n"; - $out .= '' . "\n"; - if (count($listofpaths)) { - foreach ($listofpaths as $key => $val) { - $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val))); + $out .= "
'.$langs->trans("MailFrom").""; + $out .= $langs->trans("Name").':'; + $out .= '    '; + $out .= $langs->trans("EMail").':<>'; + $out .= "
'; + $out .= $langs->trans("MailToUsers"); + $out .= ''; - $out .= ' ' . $formfile->showPreview(array(), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ? '' : 'entity=' . ((int)$entity))); + // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time + $tmparray = $this->withtouser; + foreach ($tmparray as $key => $val) { + $tmparray[$key] = dol_htmlentities($tmparray[$key], 0, 'UTF-8', true); + } + $withtoselected = GETPOST("receiveruser", 'array'); // Array of selected value + if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') { + $withtoselected = array_keys($tmparray); + } + $out .= $form->multiselectarray("receiveruser", $tmparray, $withtoselected, 0, 0, 'inline-block minwidth500', 0, ""); + $out .= "
'; + $out .= $langs->trans("GroupEmails"); + $out .= ''; + $out .= ' withoptiononeemailperrecipient > 0 ? ' checked="checked"' : '').'> '; + $out .= ''; + //$out .= ''; + //$out .= ' - '; + //$out .= $langs->trans("WarningIfYouCheckOneRecipientPerEmail"); + //$out .= ''; + if (getDolGlobalString('MASS_ACTION_EMAIL_ON_DIFFERENT_THIRPARTIES_ADD_CUSTOM_EMAIL')) { + if (!empty($this->withto) && !is_array($this->withto)) { + $out .= ' '.$langs->trans("or").' '; + } + } + $out .= '
'; + $out .= $langs->trans("MailToCCUsers"); + $out .= ''; + + // multiselect array convert html entities into options tags, even if we don't want this, so we encode them a second time + $tmparray = $this->withtoccuser; + foreach ($tmparray as $key => $val) { + $tmparray[$key] = dol_htmlentities($tmparray[$key], 0, 'UTF-8', true); + } + $withtoselected = GETPOST("receiverccuser", 'array'); // Array of selected value + if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action', 'aZ09') == 'presend') { + $withtoselected = array_keys($tmparray); + } + $out .= $form->multiselectarray("receiverccuser", $tmparray, $withtoselected, 0, 0, 'inline-block minwidth500', 0, ""); + $out .= "
".$langs->trans("MailReply")."".$this->replytoname.($this->replytomail ? (" <".$this->replytomail.">") : ""); + $out .= "
'.$langs->trans("MailFile").''; + + if ($this->withmaindocfile) { + // withmaindocfile is set to 1 or -1 to show the checkbox (-1 = checked or 1 = not checked) + if (GETPOSTISSET('sendmail')) { + $this->withmaindocfile = (GETPOST('addmaindocfile', 'alpha') ? -1 : 1); + } elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { + // If a template was selected, we use setup of template to define if join file checkbox is selected or not. + $this->withmaindocfile = ($arraydefaultmessage->joinfiles ? -1 : 1); + } + } + + if (!empty($this->withmaindocfile)) { + if ($this->withmaindocfile == 1) { + $out .= ''; + } elseif ($this->withmaindocfile == -1) { + $out .= ''; + } + if (getDolGlobalString('MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND')) { + $out .= '
'; + } else { + $out .= '
'; + } + } + + if (is_numeric($this->withfile)) { + // TODO Trick to have param removedfile containing nb of file to delete. But this does not works without javascript + $out .= ''."\n"; + $out .= ''."\n"; + if (count($listofpaths)) { + foreach ($listofpaths as $key => $val) { + $relativepathtofile = substr($val, (strlen(DOL_DATA_ROOT) - strlen($val))); + + $entity = (isset($this->param['object_entity']) ? $this->param['object_entity'] : $conf->entity); + if ($entity > 1) { + $relativepathtofile = str_replace('/'.$entity.'/', '/', $relativepathtofile); } - } /*elseif (empty($this->withmaindocfile)) { + // Try to extract data from full path + $formfile_params = array(); + preg_match('#^(/)(\w+)(/)(.+)$#', $relativepathtofile, $formfile_params); + + $out .= '
'; + // Preview of attachment + $out .= img_mime($listofnames[$key]).$listofnames[$key]; + + $out .= ' '.$formfile->showPreview(array(), $formfile_params[2], $formfile_params[4], 0, ($entity == 1 ? '' : 'entity='.((int) $entity))); + + if (!$this->withfilereadonly) { + $out .= ' '; + //$out.= ' '.img_delete($langs->trans("Remove"), 'id="removedfile_'.$key.'" name="removedfile_'.$key.'"', 'removedfile input-nobottom').''; + } + $out .= '
'; + } + } /*elseif (empty($this->withmaindocfile)) { //$out .= ''.$langs->trans("NoAttachedFiles").'
'; }*/ - if ($this->withfile == 2) { - $maxfilesizearray = getMaxFileSizeArray(); - $maxmin = $maxfilesizearray['maxmin']; - if ($maxmin > 0) { - $out .= ''; // MAX_FILE_SIZE must precede the field type=file - } - // Can add other files - if (!getDolGlobalString('FROM_MAIL_DONT_USE_INPUT_FILE_MULTIPLE')) { - $out .= ''; - } else { - $out .= ''; - } - $out .= ' '; - $out .= ''; + if ($this->withfile == 2) { + $maxfilesizearray = getMaxFileSizeArray(); + $maxmin = $maxfilesizearray['maxmin']; + if ($maxmin > 0) { + $out .= ''; // MAX_FILE_SIZE must precede the field type=file } - } else { - $out .= $this->withfile; + // Can add other files + if (!getDolGlobalString('FROM_MAIL_DONT_USE_INPUT_FILE_MULTIPLE')) { + $out .= ''; + } else { + $out .= ''; + } + $out .= ' '; + $out .= ''; } - - $out .= "
'; - $out .= $form->textwithpicto($langs->trans('MailText'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfrombody'); - $out .= ''; - - $formmail = $this; - $showlinktolayout = ($formmail->withfckeditor && getDolGlobalInt('MAIN_EMAIL_USE_LAYOUT')) ? $formmail->withlayout : ''; - $showlinktolayoutlabel = $langs->trans("FillMessageWithALayout"); - $showlinktoai = ($formmail->withaiprompt && isModEnabled('ai')) ? 'textgenerationemail' : ''; - $showlinktoailabel = $langs->trans("FillMessageWithAIContent"); - $formatforouput = ''; - $htmlname = 'message'; - - // Fill $out - include DOL_DOCUMENT_ROOT . '/core/tpl/formlayoutai.tpl.php'; - - $out .= '
'; - if ($this->withbodyreadonly) { - $out .= nl2br($defaultmessage); - $out .= ''; - } else { - if (!isset($this->ckeditortoolbar)) { - $this->ckeditortoolbar = 'dolibarr_mailings'; - } - - // Editor wysiwyg - require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; - if ($this->withfckeditor == -1) { - if (getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) { - $this->withfckeditor = 1; - } else { - $this->withfckeditor = 0; - } - } - - $doleditor = new DolEditor('message', $defaultmessage, '', 280, $this->ckeditortoolbar, 'In', true, true, $this->withfckeditor, 8, '95%'); - $out .= $doleditor->Create(1); - } - $out .= "
' . "\n"; - - if ($this->withform == 1 || $this->withform == -1) { - $out .= '
'; - $out .= 'withfile == 2 && $conf->use_javascript_ajax) { - $out .= ' onClick="if (document.mailform.addedfile.value != \'\') { alert(\'' . dol_escape_js($langs->trans("FileWasNotUploaded")) . '\'); return false; } else { return true; }"'; - } - $out .= ' />'; - if ($this->withcancel) { - $out .= ''; - } - $out .= '
' . "\n"; + if (count($validpaymentmethod) > 0 && $paymenturl) { + $langs->load('other'); + $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = str_replace('\n', "\n", $langs->transnoentities("PredefinedMailContentLink", $paymenturl)); + $this->substit['__ONLINE_PAYMENT_URL__'] = $paymenturl; + } elseif (count($validpaymentmethod) > 0) { + $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = '__ONLINE_PAYMENT_TEXT_AND_URL__'; + $this->substit['__ONLINE_PAYMENT_URL__'] = '__ONLINE_PAYMENT_URL__'; + } else { + $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = ''; + $this->substit['__ONLINE_PAYMENT_URL__'] = ''; } - if ($this->withform == 1) { - $out .= '' . "\n"; + $this->substit['__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'] = ''; + + // Generate the string with the template for lines repeated and filled for each line + $lines = ''; + $defaultlines = $arraydefaultmessage->content_lines; + if (isset($defaultlines)) { + foreach ($this->substit_lines as $lineid => $substit_line) { + $lines .= make_substitutions($defaultlines, $substit_line)."\n"; + } + } + $this->substit['__LINES__'] = $lines; + + $defaultmessage = str_replace('\n', "\n", $defaultmessage); + + // Deal with format differences between message and some substitution variables (text / HTML) + $atleastonecomponentishtml = 0; + if (strpos($defaultmessage, '__USER_SIGNATURE__') !== false && dol_textishtml($this->substit['__USER_SIGNATURE__'])) { + $atleastonecomponentishtml++; + } + if (strpos($defaultmessage, '__SENDEREMAIL_SIGNATURE__') !== false && dol_textishtml($this->substit['__SENDEREMAIL_SIGNATURE__'])) { + $atleastonecomponentishtml++; + } + if (strpos($defaultmessage, '__ONLINE_PAYMENT_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) { + $atleastonecomponentishtml++; + } + if (strpos($defaultmessage, '__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__') !== false && dol_textishtml($this->substit['__ONLINE_INTERVIEW_SCHEDULER_TEXT_AND_URL__'])) { + $atleastonecomponentishtml++; + } + if (dol_textishtml($defaultmessage)) { + $atleastonecomponentishtml++; + } + if ($atleastonecomponentishtml) { + if (!dol_textishtml($this->substit['__USER_SIGNATURE__'])) { + $this->substit['__USER_SIGNATURE__'] = dol_nl2br($this->substit['__USER_SIGNATURE__']); + } + if (!dol_textishtml($this->substit['__SENDEREMAIL_SIGNATURE__'])) { + $this->substit['__SENDEREMAIL_SIGNATURE__'] = dol_nl2br($this->substit['__SENDEREMAIL_SIGNATURE__']); + } + if (!dol_textishtml($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'])) { + $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__'] = dol_nl2br($this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__']); + } + if (!dol_textishtml($defaultmessage)) { + $defaultmessage = dol_nl2br($defaultmessage); + } } - // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set - if (getDolGlobalString('MAIN_MAILFORM_DISABLE_ENTERKEY')) { - $out .= ''; - } - - $out .= "\n"; - - return $out; + $out .= ' })'; + $out .= ''; } + + $out .= "\n"; + + return $out; } } + /** * get html For To * @@ -1694,7 +1693,7 @@ class FormMail extends Form // Use the multiselect array function to create the dropdown $out .= ''; $out .= '