diff --git a/htdocs/admin/notification.php b/htdocs/admin/notification.php index 58fd2442357..6de3cc09665 100644 --- a/htdocs/admin/notification.php +++ b/htdocs/admin/notification.php @@ -232,10 +232,10 @@ foreach($listofnotifiedevents as $notifiedevent) foreach($arrayemail as $key=>$valuedet) { $valuedet=trim($valuedet); - if (! empty($valuedet) && ! isValidEmail($valuedet)) $showwarning++; + if (! empty($valuedet) && ! isValidEmail($valuedet,1)) $showwarning++; } if ((! empty($conf->global->$param)) && $showwarning) $s.=' '.img_warning($langs->trans("ErrorBadEMail")); - print $form->textwithpicto($s,$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"),1,'help','',0,2); + print $form->textwithpicto($s,$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients").'
'.$langs->trans("YouCanAlsoUseSupervisorKeyword"),1,'help','',0,2); print '
'; } // New entry input fields diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index 573e768fb4b..61ea308df39 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -85,8 +85,8 @@ class CMailFile * CMailFile * * @param string $subject Topic/Subject of mail - * @param string $to Recipients emails (RFC 2822: "Nom firstname [, ...]" ou "email[, ...]" ou "[, ...]") - * @param string $from Sender email (RFC 2822: "Nom firstname [, ...]" ou "email[, ...]" ou "[, ...]") + * @param string $to Recipients emails (RFC 2822: "Name firstname [, ...]" or "email[, ...]" or "[, ...]"). Note: the keyword '__SUPERVISOREMAIL__' is not allowed here and must be replaced by caller. + * @param string $from Sender email (RFC 2822: "Name firstname [, ...]" or "email[, ...]" or "[, ...]") * @param string $msg Message * @param array $filename_list List of files to attach (full path of filename on file system) * @param array $mimetype_list List of MIME type of attached files @@ -98,9 +98,7 @@ class CMailFile * @param string $errors_to Email errors * @param string $css Css option */ - function __construct($subject,$to,$from,$msg, - $filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(), - $addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=0,$errors_to='',$css='') + function __construct($subject,$to,$from,$msg,$filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(),$addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=0,$errors_to='',$css='') { global $conf; @@ -1023,9 +1021,9 @@ class CMailFile } /** - * Return an address for SMTP protocol + * Return a formatted address string for SMTP protocol * - * @param string $address Example: 'John Doe ' or 'john@doe.com' + * @param string $address Example: 'John Doe , Alan Smith ' or 'john@doe.com, alan@smith.com' * @param int $format 0=auto, 1=emails with <>, 2=emails without <>, 3=auto + label between " * @param int $encode 1=Encode name to RFC2822 * @return string If format 0: '' or 'John Doe ' or '=?UTF-8?B?Sm9obiBEb2U=?= ' diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index 1a024c61552..aa92e6ee50f 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -155,7 +155,7 @@ class Notify */ function send($notifcode, $object) { - global $conf,$langs,$mysoc,$dolibarr_main_url_root; + global $user,$conf,$langs,$mysoc,$dolibarr_main_url_root; include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -373,120 +373,137 @@ class Notify } $param='NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_'.$reg[1]; - //if (! empty($conf->global->$param)) - //{ - $sendto = $conf->global->$param; - $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid'); - if ($notifcodedefid <= 0) dol_print_error($this->db, 'Failed to get id from code'); - $object_type = ''; - $link = ''; - $num++; + $sendto = $conf->global->$param; + $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid'); + if ($notifcodedefid <= 0) dol_print_error($this->db, 'Failed to get id from code'); - switch ($notifcode) { - case 'BILL_VALIDATE': - $link='/compta/facture.php?facid='.$object->id; - $dir_output = $conf->facture->dir_output; - $object_type = 'facture'; - $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$object->ref); - break; - case 'ORDER_VALIDATE': - $link='/commande/card.php?id='.$object->id; - $dir_output = $conf->commande->dir_output; - $object_type = 'order'; - $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$object->ref); - break; - case 'PROPAL_VALIDATE': - $link='/comm/propal.php?id='.$object->id; - $dir_output = $conf->propal->dir_output; - $object_type = 'propal'; - $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$object->ref); - break; - case 'FICHINTER_VALIDATE': - $link='/fichinter/card.php?id='.$object->id; - $dir_output = $conf->facture->dir_output; - $object_type = 'ficheinter'; - $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$object->ref); - break; - case 'ORDER_SUPPLIER_VALIDATE': - $link='/fourn/commande/card.php?id='.$object->id; - $dir_output = $conf->fournisseur->dir_output.'/commande/'; - $object_type = 'order_supplier'; - $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$object->ref,$user->getFullName($langs)); - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; - break; - case 'ORDER_SUPPLIER_APPROVE': - $link='/fourn/commande/card.php?id='.$object->id; - $dir_output = $conf->fournisseur->dir_output.'/commande/'; - $object_type = 'order_supplier'; - $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$object->ref,$user->getFullName($langs)); - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; - break; - case 'ORDER_SUPPLIER_REFUSE': - $link='/fourn/commande/card.php?id='.$object->id; - $dir_output = $conf->fournisseur->dir_output.'/commande/'; - $object_type = 'order_supplier'; - $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$object->ref,$user->getFullName($langs)); - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; - break; - case 'SHIPPING_VALIDATE': - $dir_output = $conf->expedition->dir_output.'/sending/'; - $object_type = 'order_supplier'; - $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$object->ref); - break; - } - $ref = dol_sanitizeFileName($object->ref); - $pdf_path = $dir_output."/".$ref."/".$ref.".pdf"; - if (! dol_is_file($pdf_path)) - { - // We can't add PDF as it is not generated yet. - $filepdf = ''; - } - else - { - $filepdf = $pdf_path; - } + $object_type = ''; + $link = ''; + $num++; - $subject = '['.$application.'] '.$langs->transnoentitiesnoconv("DolibarrNotification"); + switch ($notifcode) { + case 'BILL_VALIDATE': + $link='/compta/facture.php?facid='.$object->id; + $dir_output = $conf->facture->dir_output; + $object_type = 'facture'; + $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$object->ref); + break; + case 'ORDER_VALIDATE': + $link='/commande/card.php?id='.$object->id; + $dir_output = $conf->commande->dir_output; + $object_type = 'order'; + $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$object->ref); + break; + case 'PROPAL_VALIDATE': + $link='/comm/propal.php?id='.$object->id; + $dir_output = $conf->propal->dir_output; + $object_type = 'propal'; + $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$object->ref); + break; + case 'FICHINTER_VALIDATE': + $link='/fichinter/card.php?id='.$object->id; + $dir_output = $conf->facture->dir_output; + $object_type = 'ficheinter'; + $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$object->ref); + break; + case 'ORDER_SUPPLIER_VALIDATE': + $link='/fourn/commande/card.php?id='.$object->id; + $dir_output = $conf->fournisseur->dir_output.'/commande/'; + $object_type = 'order_supplier'; + $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; + $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$object->ref,$user->getFullName($langs)); + $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; + break; + case 'ORDER_SUPPLIER_APPROVE': + $link='/fourn/commande/card.php?id='.$object->id; + $dir_output = $conf->fournisseur->dir_output.'/commande/'; + $object_type = 'order_supplier'; + $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; + $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$object->ref,$user->getFullName($langs)); + $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; + break; + case 'ORDER_SUPPLIER_REFUSE': + $link='/fourn/commande/card.php?id='.$object->id; + $dir_output = $conf->fournisseur->dir_output.'/commande/'; + $object_type = 'order_supplier'; + $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; + $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$object->ref,$user->getFullName($langs)); + $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; + break; + case 'SHIPPING_VALIDATE': + $dir_output = $conf->expedition->dir_output.'/sending/'; + $object_type = 'order_supplier'; + $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$object->ref); + break; + } + $ref = dol_sanitizeFileName($object->ref); + $pdf_path = $dir_output."/".$ref."/".$ref.".pdf"; + if (! dol_is_file($pdf_path)) + { + // We can't add PDF as it is not generated yet. + $filepdf = ''; + } + else + { + $filepdf = $pdf_path; + } - $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n"; - $message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n"; - $message.= "\n"; - $message.= $mesg; - if ($link) $message=dol_concatdesc($message,$urlwithroot.$link); + $subject = '['.$application.'] '.$langs->transnoentitiesnoconv("DolibarrNotification"); - $mailfile = new CMailFile( - $subject, - $sendto, - $replyto, - $message, - array($file), - array($mimefile), - array($filename[count($filename)-1]), - '', - '', - 0, - -1 - ); + $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n"; + $message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n"; + $message.= "\n"; + $message.= $mesg; + if ($link) $message=dol_concatdesc($message,$urlwithroot.$link); - if ($mailfile->sendfile()) - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, objet_id, email)"; - $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".$object->socid.", null, 'email', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')"; - if (! $this->db->query($sql)) - { - dol_print_error($this->db); - } - } - else - { - $error++; - $this->errors[]=$mailfile->error; - } - //} + // Replace keyword __SUPERVISOREMAIL__ + if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) + { + $newval=''; + if ($user->fk_user > 0) + { + $supervisoruser=new User($this->db); + $supervisoruser->fetch($user->fk_user); + if ($supervisoruser->email) $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>'); + } + dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval); + $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto); + $sendto = preg_replace('/^[\s,]+/','',$sendto); // Clean start of string + $sendto = preg_replace('/[\s,]+$/','',$sendto); // Clean end of string + } + + if ($sendto) + { + $mailfile = new CMailFile( + $subject, + $sendto, + $replyto, + $message, + array($file), + array($mimefile), + array($filename[count($filename)-1]), + '', + '', + 0, + -1 + ); + + if ($mailfile->sendfile()) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, objet_id, email)"; + $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".$object->socid.", null, 'email', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')"; + if (! $this->db->query($sql)) + { + dol_print_error($this->db); + } + } + else + { + $error++; + $this->errors[]=$mailfile->error; + } + } } } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index d2ec84de96a..6ac8e92b229 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1633,14 +1633,14 @@ function dol_print_address($address, $htmlid, $mode, $id) /** * Return true if email syntax is ok * - * @param string $address email (Ex: "toto@titi.com", "John Do ") - * @return boolean true if email syntax is OK, false if KO or empty string + * @param string $address email (Ex: "toto@titi.com", "John Do ") + * @param int $acceptsupervisorkey If 1, the special string '__SUPERVISOREMAIL__' is also accepted as valid + * @return boolean true if email syntax is OK, false if KO or empty string */ -function isValidEmail($address) +function isValidEmail($address, $acceptsupervisorkey=0) { - if (filter_var($address, FILTER_VALIDATE_EMAIL)) { - return true; - } + if ($acceptsupervisorkey && $address == '__SUPERVISOREMAIL__') return true; + if (filter_var($address, FILTER_VALIDATE_EMAIL)) return true; return false; } diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 7bb08ba2c0f..2439066ad9c 100755 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1107,7 +1107,7 @@ ModuleCompanyCodeAquarium=Return an accountancy code built by:
%s followed by ModuleCompanyCodePanicum=Return an empty accountancy code. ModuleCompanyCodeDigitaria=Accountancy code depends on third party code. The code is composed of the character "C" in the first position followed by the first 5 characters of the third party code. UseNotifications=Use notifications -NotificationsDesc=EMails notifications feature allows you to silently send automatic mail, for some Dolibarr events. Targets of notifications can be defined:
* per third parties contacts (customers or suppliers), one contact at time.
* or by setting a global target email address on module setup page. +NotificationsDesc=EMails notifications feature allows you to silently send automatic mail, for some Dolibarr events. Targets of notifications can be defined:
* per third parties contacts (customers or suppliers), one contact at time.
* or by setting global target email addresses in module setup page. ModelModules=Documents templates DocumentModelOdt=Generate documents from OpenDocuments templates (.ODT or .ODS files for OpenOffice, KOffice, TextEdit,...) WatermarkOnDraft=Watermark on draft document @@ -1604,5 +1604,5 @@ NoModueToManageStockIncrease=No module able to manage automatic stock increase h YouMayFindNotificationsFeaturesIntoModuleNotification=You may find options for EMail notifications by enabling and configuring the module "Notification". ListOfNotificationsPerContact=List of notifications per contact* ListOfFixedNotifications=List of fixed notifications -GoOntoContactCardToAddMore=Go on the tab "Notifications" of a thirdparty contact to add or remove notifications for contact +GoOntoContactCardToAddMore=Go on the tab "Notifications" of a thirdparty contact to add or remove notifications for contacts/addresses Threshold=Threshold diff --git a/htdocs/langs/en_US/mails.lang b/htdocs/langs/en_US/mails.lang index 6fffc35bb08..37a50c14965 100644 --- a/htdocs/langs/en_US/mails.lang +++ b/htdocs/langs/en_US/mails.lang @@ -139,3 +139,5 @@ ListOfNotificationsDone=List all email notifications sent MailSendSetupIs=Configuration of email sending has been setup to '%s'. This mode can't be used to send mass emailing. MailSendSetupIs2=You must first go, with an admin account, into menu %sHome - Setup - EMails%s to change parameter '%s' to use mode '%s'. With this mode, you can enter setup of the SMTP server provided by your Internet Service Provider and use Mass emailing feature. MailSendSetupIs3=If you have any questions on how to setup your SMTP server, you can ask to %s. +YouCanAlsoUseSupervisorKeyword=You can also add the keyword __SUPERVISOREMAIL__ to have email being sent to the supervisor of user (works only if an email is defined for this supervisor) +NbOfTargetedContacts=Current number of targeted contact emails \ No newline at end of file diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index b1cf1d714af..e3de07b3d5d 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -48,7 +48,7 @@ Notify_PROJECT_CREATE=Project creation Notify_TASK_CREATE=Task created Notify_TASK_MODIFY=Task modified Notify_TASK_DELETE=Task deleted -SeeModuleSetup=See module setup +SeeModuleSetup=See setup of module %s NbOfAttachedFiles=Number of attached files/documents TotalSizeOfAttachedFiles=Total size of attached files/documents MaxSize=Maximum size diff --git a/htdocs/societe/notify/card.php b/htdocs/societe/notify/card.php index 69920a7e5ce..f8594a545ea 100644 --- a/htdocs/societe/notify/card.php +++ b/htdocs/societe/notify/card.php @@ -264,18 +264,22 @@ if ($result > 0) if (! preg_match('/^NOTIFICATION_FIXEDEMAIL_(.*)/', $key, $reg)) continue; print ''; $listtmp=explode(',',$val); + $first=1; foreach($listtmp as $keyemail => $valemail) { + if (! $first) print ', '; + $first=0; $valemail=trim($valemail); //print $keyemail.' - '.$valemail.' - '.$reg[1].'
'; - if (isValidEmail($valemail)) + if (isValidEmail($valemail, 1)) { - print ' <'.$valemail.'>'; + if ($valemail == '__SUPERVISOREMAIL__') print $valemail; + else print ' <'.$valemail.'>'; } else { $langs->load("errors"); - print '   '.img_warning().' '.$langs->trans("ErrorBadEMail",$valemail); + print ' '.img_warning().' '.$langs->trans("ErrorBadEMail",$valemail); } } print ''; @@ -286,7 +290,7 @@ if ($result > 0) print ''; print $langs->trans("Email"); print ''; - print ''.$langs->trans("SeeModuleSetup").''; + print ''.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).''; print ''; }