2
0
forked from Wavyzz/dolibarr

NEW: The notification module accept keyword __SUPERVISOR__ to send

notification to supervisor of user.
This commit is contained in:
Laurent Destailleur
2015-03-19 11:47:30 +01:00
parent 6ceda02eaa
commit f44d91e153
8 changed files with 152 additions and 131 deletions

View File

@@ -232,10 +232,10 @@ foreach($listofnotifiedevents as $notifiedevent)
foreach($arrayemail as $key=>$valuedet) foreach($arrayemail as $key=>$valuedet)
{ {
$valuedet=trim($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")); 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").'<br>'.$langs->trans("YouCanAlsoUseSupervisorKeyword"),1,'help','',0,2);
print '<br>'; print '<br>';
} }
// New entry input fields // New entry input fields

View File

@@ -85,8 +85,8 @@ class CMailFile
* CMailFile * CMailFile
* *
* @param string $subject Topic/Subject of mail * @param string $subject Topic/Subject of mail
* @param string $to Recipients emails (RFC 2822: "Nom firstname <email>[, ...]" ou "email[, ...]" ou "<email>[, ...]") * @param string $to Recipients emails (RFC 2822: "Name firstname <email>[, ...]" or "email[, ...]" or "<email>[, ...]"). Note: the keyword '__SUPERVISOREMAIL__' is not allowed here and must be replaced by caller.
* @param string $from Sender email (RFC 2822: "Nom firstname <email>[, ...]" ou "email[, ...]" ou "<email>[, ...]") * @param string $from Sender email (RFC 2822: "Name firstname <email>[, ...]" or "email[, ...]" or "<email>[, ...]")
* @param string $msg Message * @param string $msg Message
* @param array $filename_list List of files to attach (full path of filename on file system) * @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 * @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 $errors_to Email errors
* @param string $css Css option * @param string $css Css option
*/ */
function __construct($subject,$to,$from,$msg, 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='')
$filename_list=array(),$mimetype_list=array(),$mimefilename_list=array(),
$addr_cc="",$addr_bcc="",$deliveryreceipt=0,$msgishtml=0,$errors_to='',$css='')
{ {
global $conf; 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 <john@doe.com>' or 'john@doe.com' * @param string $address Example: 'John Doe <john@doe.com>, Alan Smith <alan@smith.com>' or 'john@doe.com, alan@smith.com'
* @param int $format 0=auto, 1=emails with <>, 2=emails without <>, 3=auto + label between " * @param int $format 0=auto, 1=emails with <>, 2=emails without <>, 3=auto + label between "
* @param int $encode 1=Encode name to RFC2822 * @param int $encode 1=Encode name to RFC2822
* @return string If format 0: '<john@doe.com>' or 'John Doe <john@doe.com>' or '=?UTF-8?B?Sm9obiBEb2U=?= <john@doe.com>' * @return string If format 0: '<john@doe.com>' or 'John Doe <john@doe.com>' or '=?UTF-8?B?Sm9obiBEb2U=?= <john@doe.com>'

View File

@@ -155,7 +155,7 @@ class Notify
*/ */
function send($notifcode, $object) 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'; include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@@ -373,120 +373,137 @@ class Notify
} }
$param='NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_'.$reg[1]; $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 = ''; $sendto = $conf->global->$param;
$link = ''; $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid');
$num++; if ($notifcodedefid <= 0) dol_print_error($this->db, 'Failed to get id from code');
switch ($notifcode) { $object_type = '';
case 'BILL_VALIDATE': $link = '';
$link='/compta/facture.php?facid='.$object->id; $num++;
$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;
}
$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"; $subject = '['.$application.'] '.$langs->transnoentitiesnoconv("DolibarrNotification");
$message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
$message.= "\n";
$message.= $mesg;
if ($link) $message=dol_concatdesc($message,$urlwithroot.$link);
$mailfile = new CMailFile( $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n";
$subject, $message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
$sendto, $message.= "\n";
$replyto, $message.= $mesg;
$message, if ($link) $message=dol_concatdesc($message,$urlwithroot.$link);
array($file),
array($mimefile),
array($filename[count($filename)-1]),
'',
'',
0,
-1
);
if ($mailfile->sendfile()) // Replace keyword __SUPERVISOREMAIL__
{ if (preg_match('/__SUPERVISOREMAIL__/', $sendto))
$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)."')"; $newval='';
if (! $this->db->query($sql)) if ($user->fk_user > 0)
{ {
dol_print_error($this->db); $supervisoruser=new User($this->db);
} $supervisoruser->fetch($user->fk_user);
} if ($supervisoruser->email) $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>');
else }
{ dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
$error++; $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto);
$this->errors[]=$mailfile->error; $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;
}
}
} }
} }

View File

@@ -1633,14 +1633,14 @@ function dol_print_address($address, $htmlid, $mode, $id)
/** /**
* Return true if email syntax is ok * Return true if email syntax is ok
* *
* @param string $address email (Ex: "toto@titi.com", "John Do <johndo@titi.com>") * @param string $address email (Ex: "toto@titi.com", "John Do <johndo@titi.com>")
* @return boolean true if email syntax is OK, false if KO or empty string * @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)) { if ($acceptsupervisorkey && $address == '__SUPERVISOREMAIL__') return true;
return true; if (filter_var($address, FILTER_VALIDATE_EMAIL)) return true;
}
return false; return false;
} }

View File

@@ -1107,7 +1107,7 @@ ModuleCompanyCodeAquarium=Return an accountancy code built by:<br>%s followed by
ModuleCompanyCodePanicum=Return an empty accountancy code. 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. 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 UseNotifications=Use notifications
NotificationsDesc=EMails notifications feature allows you to silently send automatic mail, for some Dolibarr events. Targets of notifications can be defined:<br>* per third parties contacts (customers or suppliers), one contact at time.<br>* 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:<br>* per third parties contacts (customers or suppliers), one contact at time.<br>* or by setting global target email addresses in module setup page.
ModelModules=Documents templates ModelModules=Documents templates
DocumentModelOdt=Generate documents from OpenDocuments templates (.ODT or .ODS files for OpenOffice, KOffice, TextEdit,...) DocumentModelOdt=Generate documents from OpenDocuments templates (.ODT or .ODS files for OpenOffice, KOffice, TextEdit,...)
WatermarkOnDraft=Watermark on draft document 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". YouMayFindNotificationsFeaturesIntoModuleNotification=You may find options for EMail notifications by enabling and configuring the module "Notification".
ListOfNotificationsPerContact=List of notifications per contact* ListOfNotificationsPerContact=List of notifications per contact*
ListOfFixedNotifications=List of fixed notifications 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 Threshold=Threshold

View File

@@ -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. 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 <strong>'%s'</strong> 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. MailSendSetupIs2=You must first go, with an admin account, into menu %sHome - Setup - EMails%s to change parameter <strong>'%s'</strong> 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. 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 <strong>__SUPERVISOREMAIL__</strong> 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

View File

@@ -48,7 +48,7 @@ Notify_PROJECT_CREATE=Project creation
Notify_TASK_CREATE=Task created Notify_TASK_CREATE=Task created
Notify_TASK_MODIFY=Task modified Notify_TASK_MODIFY=Task modified
Notify_TASK_DELETE=Task deleted Notify_TASK_DELETE=Task deleted
SeeModuleSetup=See module setup SeeModuleSetup=See setup of module %s
NbOfAttachedFiles=Number of attached files/documents NbOfAttachedFiles=Number of attached files/documents
TotalSizeOfAttachedFiles=Total size of attached files/documents TotalSizeOfAttachedFiles=Total size of attached files/documents
MaxSize=Maximum size MaxSize=Maximum size

View File

@@ -264,18 +264,22 @@ if ($result > 0)
if (! preg_match('/^NOTIFICATION_FIXEDEMAIL_(.*)/', $key, $reg)) continue; if (! preg_match('/^NOTIFICATION_FIXEDEMAIL_(.*)/', $key, $reg)) continue;
print '<tr '.$bc[$var].'><td>'; print '<tr '.$bc[$var].'><td>';
$listtmp=explode(',',$val); $listtmp=explode(',',$val);
$first=1;
foreach($listtmp as $keyemail => $valemail) foreach($listtmp as $keyemail => $valemail)
{ {
if (! $first) print ', ';
$first=0;
$valemail=trim($valemail); $valemail=trim($valemail);
//print $keyemail.' - '.$valemail.' - '.$reg[1].'<br>'; //print $keyemail.' - '.$valemail.' - '.$reg[1].'<br>';
if (isValidEmail($valemail)) if (isValidEmail($valemail, 1))
{ {
print ' &lt;'.$valemail.'&gt;'; if ($valemail == '__SUPERVISOREMAIL__') print $valemail;
else print ' &lt;'.$valemail.'&gt;';
} }
else else
{ {
$langs->load("errors"); $langs->load("errors");
print ' &nbsp; '.img_warning().' '.$langs->trans("ErrorBadEMail",$valemail); print ' '.img_warning().' '.$langs->trans("ErrorBadEMail",$valemail);
} }
} }
print '</td>'; print '</td>';
@@ -286,7 +290,7 @@ if ($result > 0)
print '<td>'; print '<td>';
print $langs->trans("Email"); print $langs->trans("Email");
print '</td>'; print '</td>';
print '<td align="right">'.$langs->trans("SeeModuleSetup").'</td>'; print '<td align="right">'.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).'</td>';
print '</tr>'; print '</tr>';
} }