diff --git a/htdocs/admin/mails.php b/htdocs/admin/mails.php
index aa859b18a7e..961491cce2e 100644
--- a/htdocs/admin/mails.php
+++ b/htdocs/admin/mails.php
@@ -69,20 +69,20 @@ complete_substitutions_array($substitutionarrayfortest, $langs);
if ($action == 'update' && empty($_POST["cancel"]))
{
- dolibarr_set_const($db, "MAIN_DISABLE_ALL_MAILS", GETPOST("MAIN_DISABLE_ALL_MAILS"),'chaine',0,'',$conf->entity);
+ dolibarr_set_const($db, "MAIN_DISABLE_ALL_MAILS", GETPOST("MAIN_DISABLE_ALL_MAILS"),'chaine',0,'',$conf->entity);
// Send mode parameters
- dolibarr_set_const($db, "MAIN_MAIL_SENDMODE", GETPOST("MAIN_MAIL_SENDMODE"),'chaine',0,'',$conf->entity);
- dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT", GETPOST("MAIN_MAIL_SMTP_PORT"),'chaine',0,'',$conf->entity);
- dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER", GETPOST("MAIN_MAIL_SMTP_SERVER"),'chaine',0,'',$conf->entity);
- dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID", GETPOST("MAIN_MAIL_SMTPS_ID"), 'chaine',0,'',$conf->entity);
- dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW", GETPOST("MAIN_MAIL_SMTPS_PW"), 'chaine',0,'',$conf->entity);
- dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS", GETPOST("MAIN_MAIL_EMAIL_TLS"),'chaine',0,'',$conf->entity);
- dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS", GETPOST("MAIN_MAIL_EMAIL_STARTTLS"),'chaine',0,'',$conf->entity);
+ dolibarr_set_const($db, "MAIN_MAIL_SENDMODE", GETPOST("MAIN_MAIL_SENDMODE"),'chaine',0,'',$conf->entity);
+ dolibarr_set_const($db, "MAIN_MAIL_SMTP_PORT", GETPOST("MAIN_MAIL_SMTP_PORT"),'chaine',0,'',$conf->entity);
+ dolibarr_set_const($db, "MAIN_MAIL_SMTP_SERVER", GETPOST("MAIN_MAIL_SMTP_SERVER"),'chaine',0,'',$conf->entity);
+ dolibarr_set_const($db, "MAIN_MAIL_SMTPS_ID", GETPOST("MAIN_MAIL_SMTPS_ID"), 'chaine',0,'',$conf->entity);
+ dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW", GETPOST("MAIN_MAIL_SMTPS_PW"), 'chaine',0,'',$conf->entity);
+ dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS", GETPOST("MAIN_MAIL_EMAIL_TLS"),'chaine',0,'',$conf->entity);
+ dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS", GETPOST("MAIN_MAIL_EMAIL_STARTTLS"),'chaine',0,'',$conf->entity);
// Content parameters
- dolibarr_set_const($db, "MAIN_MAIL_EMAIL_FROM", GETPOST("MAIN_MAIL_EMAIL_FROM"), 'chaine',0,'',$conf->entity);
- dolibarr_set_const($db, "MAIN_MAIL_ERRORS_TO", GETPOST("MAIN_MAIL_ERRORS_TO"), 'chaine',0,'',$conf->entity);
- dolibarr_set_const($db, "MAIN_MAIL_AUTOCOPY_TO", GETPOST("MAIN_MAIL_AUTOCOPY_TO"),'chaine',0,'',$conf->entity);
- dolibarr_set_const($db, 'MAIN_MAIL_DEFAULT_FROMTYPE',GETPOST('MAIN_MAIL_DEFAULT_FROMTYPE'),'chaine',0,'',$conf->entity);
+ dolibarr_set_const($db, "MAIN_MAIL_EMAIL_FROM", GETPOST("MAIN_MAIL_EMAIL_FROM"), 'chaine',0,'',$conf->entity);
+ dolibarr_set_const($db, "MAIN_MAIL_ERRORS_TO", GETPOST("MAIN_MAIL_ERRORS_TO"), 'chaine',0,'',$conf->entity);
+ dolibarr_set_const($db, "MAIN_MAIL_AUTOCOPY_TO", GETPOST("MAIN_MAIL_AUTOCOPY_TO"),'chaine',0,'',$conf->entity);
+ dolibarr_set_const($db, 'MAIN_MAIL_DEFAULT_FROMTYPE', GETPOST('MAIN_MAIL_DEFAULT_FROMTYPE'),'chaine',0,'',$conf->entity);
header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
exit;
@@ -427,13 +427,30 @@ if ($action == 'edit')
print '">';
// Default from type
-
- $liste = array();
- $liste['user'] = $langs->trans('UserEmail');
- $liste['company'] = $langs->trans('CompanyEmail').' ('.(empty($conf->global->MAIN_INFO_SOCIETE_MAIL)?$langs->trans("NotDefined"):$conf->global->MAIN_INFO_SOCIETE_MAIL).')';
+ $liste = array();
+ $liste['user'] = $langs->trans('UserEmail');
+ $liste['company'] = $langs->trans('CompanyEmail').' ('.(empty($conf->global->MAIN_INFO_SOCIETE_MAIL)?$langs->trans("NotDefined"):$conf->global->MAIN_INFO_SOCIETE_MAIL).')';
+ /*
+ $sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE active = 1';
+ $resql = $db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ $i=0;
+ while($i < $num)
+ {
+ $obj = $db->fetch_object($resql);
+ if ($obj)
+ {
+ $liste['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>';
+ }
+ $i++;
+ }
+ }
+ else dol_print_error($db);*/
print '
| '.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').' | ';
- print $form->selectarray('MAIN_MAIL_DEFAULT_FROMTYPE',$liste,$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE,0);
+ print $form->selectarray('MAIN_MAIL_DEFAULT_FROMTYPE', $liste, $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE, 0);
print ' |
';
// Separator
@@ -569,13 +586,46 @@ else
print '';
// Default from type
+ $liste = array();
+ $liste['user'] = $langs->trans('UserEmail');
+ $liste['company'] = $langs->trans('CompanyEmail').' ('.(empty($conf->global->MAIN_INFO_SOCIETE_MAIL)?$langs->trans("NotDefined"):$conf->global->MAIN_INFO_SOCIETE_MAIL).')';
+ $sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE active = 1';
+ $resql = $db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ $i=0;
+ while($i < $num)
+ {
+ $obj = $db->fetch_object($resql);
+ if ($obj)
+ {
+ $liste['senderprofile_'.$obj->rowid] = $obj->label.' <'.$obj->email.'>';
+ }
+ $i++;
+ }
+ }
+ else dol_print_error($db);
print '| '.$langs->trans('MAIN_MAIL_DEFAULT_FROMTYPE').' | ';
print '';
- if($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE === 'user'){
+ if ($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE === 'user')
+ {
print $langs->trans('UserEmail');
- } else {
- print $langs->trans('CompanyEmail');
+ }
+ else if ($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE === 'company')
+ {
+ print $langs->trans('CompanyEmail').' '.dol_escape_htmltag('<'.$mysoc->email.'>');
+ }
+ else {
+ $id = preg_replace('/senderprofile_/', '', $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE);
+ if ($id > 0)
+ {
+ include_once DOL_DOCUMENT_ROOT.'/core/class/emailsenderprofile.class.php';
+ $emailsenderprofile = new EmailSenderProfile($db);
+ $emailsenderprofile->fetch($id);
+ print $emailsenderprofile->label.' '.dol_escape_htmltag('<'.$emailsenderprofile->email.'>');
+ }
}
print ' |
';
diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php
index 67fde5dbd48..76534211481 100644
--- a/htdocs/core/actions_massactions.inc.php
+++ b/htdocs/core/actions_massactions.inc.php
@@ -306,6 +306,15 @@ if (! $error && $massaction == 'confirm_presend')
$tmp=explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
$from = trim($tmp[($reg[1] - 1)]);
}
+ elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
+ $sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE rowid = '.(int) $reg[1];
+ $resql = $db->query($sql);
+ $obj = $db->fetch_object($resql);
+ if ($obj)
+ {
+ $from = $obj->label.' <'.$obj->email.'>';
+ }
+ }
else {
$from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
}
diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php
index 7b1db834d22..57b6ae80b6c 100644
--- a/htdocs/core/actions_sendmails.inc.php
+++ b/htdocs/core/actions_sendmails.inc.php
@@ -258,6 +258,15 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$tmp=explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
$from = trim($tmp[($reg[1] - 1)]);
}
+ elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
+ $sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE rowid = '.(int) $reg[1];
+ $resql = $db->query($sql);
+ $obj = $db->fetch_object($resql);
+ if ($obj)
+ {
+ $from = $obj->label.' <'.$obj->email.'>';
+ }
+ }
else {
$from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
}
diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php
index 788fa723cdb..77f3d30c93b 100644
--- a/htdocs/core/class/html.formmail.class.php
+++ b/htdocs/core/class/html.formmail.class.php
@@ -444,6 +444,8 @@ class FormMail extends Form
}
} else {
$liste = array();
+
+ // Add user email
if (empty($user->email))
{
$langs->load('errors');
@@ -453,9 +455,32 @@ class FormMail extends Form
{
$liste['user'] = $user->getFullName($langs) .' <'.$user->email.'>';
}
+
+ // Add also company main email
$liste['company'] = $conf->global->MAIN_INFO_SOCIETE_NOM .' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>';
- // Add also email aliases if there is one
+
+ // Add also email aliases if there is some
$listaliases=array('user_aliases'=>$user->email_aliases, 'global_aliases'=>$conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
+
+ // Add also email aliases from the c_email_senderprofile table
+ $sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE active = 1 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($db);
+
foreach($listaliases as $typealias => $listalias)
{
$posalias=0;
diff --git a/htdocs/install/mysql/migration/6.0.0-7.0.0.sql b/htdocs/install/mysql/migration/6.0.0-7.0.0.sql
index 3ecf4b405c8..b5e274c9d90 100644
--- a/htdocs/install/mysql/migration/6.0.0-7.0.0.sql
+++ b/htdocs/install/mysql/migration/6.0.0-7.0.0.sql
@@ -364,3 +364,20 @@ ALTER TABLE llx_c_paiement ADD UNIQUE INDEX uk_c_paiement(id, entity, code);
ALTER TABLE llx_c_payment_term DROP PRIMARY KEY;
ALTER TABLE llx_c_payment_term ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER rowid;
ALTER TABLE llx_c_payment_term ADD UNIQUE INDEX uk_c_payment_term(rowid, entity, code);
+
+
+create table llx_c_email_senderprofile
+(
+ rowid integer AUTO_INCREMENT PRIMARY KEY,
+ entity integer DEFAULT 1 NOT NULL, -- multi company id
+ private smallint DEFAULT 0 NOT NULL, -- Template public or private
+ date_creation datetime,
+ tms timestamp,
+ label varchar(255), -- Label of predefined email
+ email varchar(255), -- Email
+ signature text -- Predefined signature
+ position smallint, -- Position
+ active tinyint DEFAULT 1 NOT NULL,
+)ENGINE=innodb;
+
+ALTER TABLE llx_c_email_senderprofile ADD UNIQUE INDEX uk_c_email_senderprofile(entity, label, email);
diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php
index efd0404ee72..40a69851a0e 100644
--- a/htdocs/modulebuilder/index.php
+++ b/htdocs/modulebuilder/index.php
@@ -86,7 +86,7 @@ if (empty($newmask)) // This should no happen
if ($dirins && $action == 'initmodule' && $modulename)
{
- if (preg_match('/\s/', $modulename))
+ if (preg_match('/[^a-z0-9_]/i', $modulename))
{
$error++;
setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
@@ -174,7 +174,7 @@ if ($dirins && $action == 'initmodule' && $modulename)
if ($dirins && $action == 'initobject' && $module && $objectname)
{
- if (preg_match('/\s/', $objectname))
+ if (preg_match('/[^a-z0-9_]/i', $objectname))
{
$error++;
setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
@@ -183,6 +183,14 @@ if ($dirins && $action == 'initobject' && $module && $objectname)
$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
$destdir = $dirins.'/'.strtolower($module);
+ // The dir was not created by init
+ dol_mkdir($destdir.'/class');
+ dol_mkdir($destdir.'/img');
+ dol_mkdir($destdir.'/lib');
+ dol_mkdir($destdir.'/scripts');
+ dol_mkdir($destdir.'/sql');
+ dol_mkdir($destdir.'/test/phpunit');
+
// Scan dir class to find if an object with same name already exists.
if (! $error)
{
@@ -443,7 +451,7 @@ if ($dirins && $action == 'confirm_deleteproperty' && $propertykey)
if ($dirins && $action == 'confirm_delete')
{
- if (preg_match('/\s/', $module))
+ if (preg_match('/[^a-z0-9_]/i', $module))
{
$error++;
setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');
@@ -476,7 +484,7 @@ if ($dirins && $action == 'confirm_delete')
if ($dirins && $action == 'confirm_deleteobject' && $objectname)
{
- if (preg_match('/[^a-z0-9]/i', $objectname))
+ if (preg_match('/[^a-z0-9_]/i', $objectname))
{
$error++;
setEventMessages($langs->trans("SpaceOrSpecialCharAreNotAllowed"), null, 'errors');