diff --git a/class/actions_sendrecurringinvoicebymail.class.php b/class/actions_sendrecurringinvoicebymail.class.php index 2f0c15c..ccc9813 100644 --- a/class/actions_sendrecurringinvoicebymail.class.php +++ b/class/actions_sendrecurringinvoicebymail.class.php @@ -115,7 +115,8 @@ class Actionssendrecurringinvoicebymail 'errorsTo' => $conf->global->MAIN_MAIL_ERRORS_TO, 'replyTo' => $conf->global->MAIN_MAIL_ERRORS_TO, 'subject' => $mailObject->subject, - 'message' => $mailObject->body_plaintext, + 'message' => $mailObject->body, + 'ishtml' => $mailObject->body_ishtml, ); // Check that we have a recipient, to avoid some frequent error... @@ -154,7 +155,7 @@ class Actionssendrecurringinvoicebymail $mail_data['cc'], // CC $mail_data['bcc'], // BCC 0, //deliveryreceipt - 0, //msgishtml + $mail_data['ishtml'], //msgishtml $mail_data['errorsTo'], '', // css '', // trackid diff --git a/class/sribmcustommailinfo.class.php b/class/sribmcustommailinfo.class.php index 6559134..7f68e19 100644 --- a/class/sribmcustommailinfo.class.php +++ b/class/sribmcustommailinfo.class.php @@ -109,12 +109,12 @@ class SRIBMCustomMailInfo extends CommonObject /** * @var string */ - public $body_plaintext; + public $body; /** - * @var string (not used at the moment) + * @var int 0: plain text, 1: html, -1: auto (see CMailFile and dol_ishtml()) */ - public $body_html; + public $body_ishtml = 0; // End of database fields @@ -228,7 +228,7 @@ class SRIBMCustomMailInfo extends CommonObject $sql .= " SET "; $sql .= " fk_facture_rec = " . (int)$this->fk_facture_rec; $sql .= ", active = " . (int)$this->active; - $sql .= ", addmaindocfile = '" . (int)$this->addmaindocfile . "'"; + $sql .= ", addmaindocfile = " . (int)$this->addmaindocfile; $sql .= ", fromtype = '" . $this->db->escape($this->fromtype) . "'"; $sql .= ", frommail = '" . $this->db->escape($this->frommail) . "'"; $sql .= ", sendto_thirdparty = " . (int)$this->db->escape($this->sendto_thirdparty); @@ -238,8 +238,8 @@ class SRIBMCustomMailInfo extends CommonObject $sql .= ", sendbcc_thirdparty = " . (int)$this->db->escape($this->sendbcc_thirdparty); $sql .= ", sendbcc_free = '" . $this->db->escape($this->sendbcc_free) . "'"; $sql .= ", subject = '" . $this->db->escape($this->subject) . "'"; - $sql .= ", body_plaintext = '" . $this->db->escape($this->body_plaintext) . "'"; - $sql .= ", body_html = '" . $this->db->escape($this->body_html) . "'"; + $sql .= ", body = '" . $this->db->escape($this->body) . "'"; + $sql .= ", body_ishtml = " . (int)$this->body_ishtml; $sql .= " WHERE rowid = " . (int)$this->id; $result = $this->db->query($sql); @@ -281,7 +281,7 @@ class SRIBMCustomMailInfo extends CommonObject { global $conf; - $sql = "SELECT rowid, fk_facture_rec, active, addmaindocfile, fromtype, frommail, sendto_thirdparty, sendto_free, sendcc_thirdparty, sendcc_free, sendbcc_thirdparty, sendbcc_free, subject, body_plaintext, body_html"; + $sql = "SELECT rowid, fk_facture_rec, active, addmaindocfile, fromtype, frommail, sendto_thirdparty, sendto_free, sendcc_thirdparty, sendcc_free, sendbcc_thirdparty, sendbcc_free, subject, body, body_ishtml"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE " . (isset($ref) ? 'fk_facture_rec = ' . (int)$ref : "rowid = " . (int)$rowid); @@ -309,8 +309,8 @@ class SRIBMCustomMailInfo extends CommonObject $this->sendbcc_thirdparty = $obj->sendbcc_thirdparty; $this->sendbcc_free = $obj->sendbcc_free; $this->subject = $obj->subject; - $this->body_plaintext = $obj->body_plaintext; - $this->body_html = $obj->body_html; + $this->body = $obj->body; + $this->body_ishtml = $obj->body_ishtml; $ref = $obj->fk_facture_rec; } elseif (!$fill_defaults_from_template) { $this->error = "SRIBMCustomMailInfo not found (id: " . var_export($rowid, true) . ", ref: " . var_export($ref, true); @@ -366,7 +366,7 @@ class SRIBMCustomMailInfo extends CommonObject } $this->subject = $template->topic; - $this->body_plaintext = $template->content; + $this->body = $template->content; $this->addmaindocfile = $template->joinfiles; } diff --git a/core/modules/modsendrecurringinvoicebymail.class.php b/core/modules/modsendrecurringinvoicebymail.class.php index 0ce3334..3369880 100644 --- a/core/modules/modsendrecurringinvoicebymail.class.php +++ b/core/modules/modsendrecurringinvoicebymail.class.php @@ -357,7 +357,7 @@ class modsendrecurringinvoicebymail extends DolibarrModules $this->db->query("INSERT INTO " . MAIN_DB_PREFIX . "sribm_custom_mail_info (fk_facture_rec, fromtype, frommail) VALUES (" . (int)$row->rid . ", 'robot', '" . $this->db->escape($conf->global->MAIN_MAIL_EMAIL_FROM) . "')"); $sid = $this->db->last_insert_id(MAIN_DB_PREFIX . 'sribm_custom_mail_info'); } - foreach (array('subject' => 'subject', 'body' => 'body_plaintext', 'sendto' => 'sendto_free') as $key => $item) { + foreach (array('subject' => 'subject', 'body' => 'body', 'sendto' => 'sendto_free') as $key => $item) { if (! empty($mail_data[$key])) { // We loop on each field. // Not optimized, I know. diff --git a/fiche-rec-tab1.php b/fiche-rec-tab1.php index b787ffd..f78fb3e 100644 --- a/fiche-rec-tab1.php +++ b/fiche-rec-tab1.php @@ -132,6 +132,10 @@ do { setEventMessages("In some configuration, CMailFile doesn't allow empty subject. You should set one.", null, 'warnings'); //break; } + if (! in_array(GETPOST('body_ishtml', 'int'), array('-1', '0', '1'), true)) { + setEventMessages("Unexpected body_ishtml value", null, 'errors'); + break; + } // Feed the input data to the model $mailObject->active = GETPOST('active', 'int') ? 1 : 0; @@ -147,7 +151,8 @@ do { $mailObject->sendcc_thirdparty = in_array('thirdparty', GETPOST('sendcc_socpeople', 'array')); $mailObject->subject = GETPOST('subject', 'alpha'); - $mailObject->body_plaintext = GETPOST('body_plaintext', 'alpha'); + $mailObject->body = GETPOST('body', 'alpha'); + $mailObject->body_ishtml = (int)GETPOST('body_ishtml', 'int'); // Save into database if ($mailObject->id) { @@ -295,7 +300,7 @@ do { $output .= ' ' . $langs->trans("JoinMainDoc") . "\n"; - // body_plaintext + // body $output .= ''; $output .= $form->textwithpicto($langs->trans("MailText"), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltipfrombody'); $output .= "\n"; @@ -306,11 +311,24 @@ do { $doleditor = new DolEditor('body_plaintext', (GETPOST('body_plaintext', 'alpha') ? GETPOST('body_plaintext', 'alpha') : $mailObject->body_plaintext), '', 280); $output .= $doleditor->Create(1); */ - $output .= '\n"; $output .= "\n"; + // body_ishtml + $output .= '' . $langs->trans('MailBodyFormat') . "\n"; + $tmp_ishtml = (int)(GETPOSTISSET('body_ishtml') ? GETPOST('body_ishtml', 'int') : $mailObject->body_ishtml); + // selectarray() does funny things with -1 key, so we build it manually. + //$output .= $form->selectarray('body_ishtml', $listBodyIsHtml, $mailObject->body_ishtml); + $output .= '\n\n"; + $output .= "\n"; $output .= '
'; diff --git a/langs/en_US/sendrecurringinvoicebymail.lang b/langs/en_US/sendrecurringinvoicebymail.lang index 92ea605..2e0ef64 100644 --- a/langs/en_US/sendrecurringinvoicebymail.lang +++ b/langs/en_US/sendrecurringinvoicebymail.lang @@ -41,10 +41,16 @@ About = About sendrecurringinvoicebymailAbout = About sendrecurringinvoicebymail sendrecurringinvoicebymailAboutPage = sendrecurringinvoicebymail about page +# # Tab title on the fiche-rec page +# CustomizationTitle = Customization CustomizationIntro = Below, you can override the global email template for this particular recurring invoice. To remove all customization, click on the %s button. CustomizationLinkToGlobalTemplate = As a note, the global email template can be configured here, and the default sender address can be configured there. +MailBodyFormat = Message format +MailBodyFormatAutoDetect = Auto-detect +MailBodyFormatPlainText = Plain text +MailBodyFormatHtml = HTML OptionEnable = Send mail when generating via cron (cf. module "Scheduled Jobs") Reset = Reset ResetDone = Reset done : customization deleted diff --git a/langs/fr_FR/sendrecurringinvoicebymail.lang b/langs/fr_FR/sendrecurringinvoicebymail.lang index 47a29da..787adbf 100644 --- a/langs/fr_FR/sendrecurringinvoicebymail.lang +++ b/langs/fr_FR/sendrecurringinvoicebymail.lang @@ -29,6 +29,11 @@ sendrecurringinvoicebymailSetup = Configuration du module sendrecurringinvoiceby Settings = Réglages sendrecurringinvoicebymailSetupPage = Page de configuration du module sendrecurringinvoicebymail + + + + + # # Page À propos # @@ -42,6 +47,10 @@ sendrecurringinvoicebymailAboutPage = Page à propos de sendrecurringinvoicebyma CustomizationTitle = Personnalisation CustomizationIntro = Ci-dessous, vous pouvez personnaliser les emails pour cette facture-modèle. Pour annuler toute personnalisation, cliquez sur le bouton '%s'. CustomizationLinkToGlobalTemplate = Pour mémoire, le template global est configurable par ici, et l'adresse de l'émetteur par défaut est configurable par là. +MailBodyFormat = Format du message +MailBodyFormatAutoDetect = Auto-detect +MailBodyFormatPlainText = Texte pur +MailBodyFormatHtml = HTML OptionEnable = Envoyer par email lors d'une génération automatique via le module "Travaux planifiés" Reset = Réinitialiser ResetDone = Réinitialisation effectuée : personnalisation supprimée. diff --git a/sql/update_0.3.1-0.3.2.sql b/sql/update_0.3.1-0.3.2.sql new file mode 100644 index 0000000..388337c --- /dev/null +++ b/sql/update_0.3.1-0.3.2.sql @@ -0,0 +1,21 @@ +-- Copyright (C) 2021 Chl +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see http://www.gnu.org/licenses/. + + +-- We designed the schema too quickly : CMailFile doesn't let us manage +-- independently the text and html parts. All we can do is set the mode. +ALTER TABLE llx_sribm_custom_mail_info CHANGE COLUMN body_plaintext body mediumtext; +ALTER TABLE llx_sribm_custom_mail_info DROP COLUMN body_html; +ALTER TABLE llx_sribm_custom_mail_info ADD COLUMN body_ishtml smallint DEFAULT 0 NOT NULL;