diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 74595267a7c..0742e3d4851 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -5451,8 +5451,6 @@ class Facture extends CommonInvoice dol_syslog(__METHOD__, LOG_DEBUG); - $this->db->begin(); - // Select all action comm reminder $sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."facture as f"; if (!empty($paymentmode) && $paymentmode != 'all') { @@ -5541,20 +5539,92 @@ class Facture extends CommonInvoice } if (!$error && $to) { + $this->db->begin(); + // Errors Recipient $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO; $trackid = 'inv'.$tmpinvoice->id; + $sendcontext = 'standard'; + // Mail Creation - $cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', $trackid, '', '', ''); + $cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', $trackid, '', $sendcontext, ''); // Sending Mail if ($cMailFile->sendfile()) { $nbMailSend++; + + // Add a line into event table + require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; + + // Insert record of emails sent + $actioncomm = new ActionComm($this->db); + + $actioncomm->type_code = 'AC_OTH_AUTO'; // Event insert into agenda automatically + $actioncomm->socid = $tmpinvoice->thirdparty->id; // To link to a company + $actioncomm->contact_id = 0; + + $actioncomm->code = 'AC_EMAIL'; + $actioncomm->label = 'sendEmailsRemindersOnInvoiceDueDateOK'; + $actioncomm->note_private = $sendContent; + $actioncomm->fk_project = $tmpinvoice->fk_project; + $actioncomm->datep = dol_now(); + $actioncomm->datef = $actioncomm->datep; + $actioncomm->percentage = -1; // Not applicable + $actioncomm->authorid = $user->id; // User saving action + $actioncomm->userownerid = $user->id; // Owner of action + // Fields when action is an email (content should be added into note) + $actioncomm->email_msgid = $cMailFile->msgid; + $actioncomm->email_from = $from; + $actioncomm->email_sender = ''; + $actioncomm->email_to = $to; + //$actioncomm->email_tocc = $sendtocc; + //$actioncomm->email_tobcc = $sendtobcc; + //$actioncomm->email_subject = $subject; + $actioncomm->errors_to = $errors_to; + + //$actioncomm->extraparams = $extraparams; + + $actioncomm->create($user); } else { $errormesg = $cMailFile->error.' : '.$to; $error++; + + // Add a line into event table + require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; + + // Insert record of emails sent + $actioncomm = new ActionComm($this->db); + + $actioncomm->type_code = 'AC_OTH_AUTO'; // Event insert into agenda automatically + $actioncomm->socid = $tmpinvoice->thirdparty->id; // To link to a company + $actioncomm->contact_id = 0; + + $actioncomm->code = 'AC_EMAIL'; + $actioncomm->label = 'sendEmailsRemindersOnInvoiceDueDateKO'; + $actioncomm->note_private = $errormesg; + $actioncomm->fk_project = $tmpinvoice->fk_project; + $actioncomm->datep = dol_now(); + $actioncomm->datef = $actioncomm->datep; + $actioncomm->percentage = -1; // Not applicable + $actioncomm->authorid = $user->id; // User saving action + $actioncomm->userownerid = $user->id; // Owner of action + // Fields when action is an email (content should be added into note) + $actioncomm->email_msgid = $cMailFile->msgid; + $actioncomm->email_from = $from; + $actioncomm->email_sender = ''; + $actioncomm->email_to = $to; + //$actioncomm->email_tocc = $sendtocc; + //$actioncomm->email_tobcc = $sendtobcc; + //$actioncomm->email_subject = $subject; + $actioncomm->errors_to = $errors_to; + + //$actioncomm->extraparams = $extraparams; + + $actioncomm->create($user); } + + $this->db->commit(); // We always commit } if ($errormesg) { @@ -5572,10 +5642,8 @@ class Facture extends CommonInvoice if (!$error) { $this->output .= 'Nb of emails sent : '.$nbMailSend; - $this->db->commit(); return 0; } else { - $this->db->commit(); // We commit also on error, to have the error message recorded. $this->error = 'Nb of emails sent : '.$nbMailSend.', '.(!empty($errorsMsg)) ? join(', ', $errorsMsg) : $error; return $error; } @@ -5583,8 +5651,9 @@ class Facture extends CommonInvoice /** * See if current invoice date is posterior to the last invoice date among validated invoices of same type. + * * @param boolean $allow_validated_drafts return true if the invoice has been validated before returning to DRAFT state. - * @return boolean + * @return array return array */ public function willBeLastOfSameType($allow_validated_drafts = false) { @@ -5608,10 +5677,10 @@ class Facture extends CommonInvoice $is_last_of_same_type = $is_last_of_same_type || (!strpos($this->ref, 'PROV') && $this->status == self::STATUS_DRAFT); } - return [$is_last_of_same_type, $last_date]; + return array($is_last_of_same_type, $last_date); } else { // element is first of type to be validated - return [true]; + return array(true); } } else { dol_print_error($this->db); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index df4fe39bcfd..6d87116fd6b 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7167,6 +7167,8 @@ function dol_textishtml($msg, $option = 0) } return false; } else { + // Remove all urls because 'http://aa?param1=abc&param2=def' must not be used inside detection + $msg = preg_replace('/https?:\/\/[^"\'\s]+/i', '', $msg); if (preg_match('//i', $msg)) { return true; } elseif (preg_match('/&[A-Z0-9]{1,6};/i', $msg)) { + // TODO If content is 'A link https://aaa?param=abc&param2=def', it return true but must be false return true; // Html entities names (http://www.w3schools.com/tags/ref_entities.asp) } elseif (preg_match('/&#[0-9]{2,3};/i', $msg)) { return true; // Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp) @@ -7829,6 +7832,7 @@ function make_substitutions($text, $substitutionarray, $outputlangs = null, $con } else { if (! $msgishtml) { $valueishtml = dol_textishtml($value, 1); + var_dump("valueishtml=".$valueishtml); if ($valueishtml) { $text = dol_htmlentitiesbr($text); diff --git a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql index 286d28ac1a6..c090c55dee7 100644 --- a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql +++ b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql @@ -630,10 +630,11 @@ ALTER TABLE llx_eventorganization_conferenceorboothattendee ADD COLUMN lastname ALTER TABLE llx_eventorganization_conferenceorboothattendee ADD COLUMN email_company varchar(128) after email; -ALTER TABLE llx_c_email_template ADD COLUMN email_from varchar(255); -ALTER TABLE llx_c_email_template ADD COLUMN email_to varchar(255); -ALTER TABLE llx_c_email_template ADD COLUMN email_tocc varchar(255); -ALTER TABLE llx_c_email_template ADD COLUMN email_tobcc varchar(255); +ALTER TABLE llx_c_email_templates ADD COLUMN joinfiles text; +ALTER TABLE llx_c_email_templates ADD COLUMN email_from varchar(255); +ALTER TABLE llx_c_email_templates ADD COLUMN email_to varchar(255); +ALTER TABLE llx_c_email_templates ADD COLUMN email_tocc varchar(255); +ALTER TABLE llx_c_email_templates ADD COLUMN email_tobcc varchar(255); ALTER TABLE llx_fichinter ADD COLUMN ref_client varchar(255) after ref_ext; diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 82205369c86..47de2cbebcc 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -166,6 +166,7 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase print __METHOD__."\n"; } + /** * testNum2Alpha * @@ -535,6 +536,10 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase $input='This is a text with html comments '; // we suppose this is not enough to be html content $after=dol_textishtml($input); $this->assertFalse($after); + + $input="A text\nwith a link https://aaa?param=abc&param2=def"; + $after=dol_textishtml($input); + $this->assertFalse($after); }