Merge pull request #8430 from atm-florian/dev_mailtouser
NEW : Can select from the user list into send form email (For field to and CC)
This commit is contained in:
commit
698f5c165a
@ -71,6 +71,7 @@ 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);
|
||||||
dolibarr_set_const($db, "MAIN_MAIL_FORCE_SENDTO", GETPOST("MAIN_MAIL_FORCE_SENDTO"),'chaine',0,'',$conf->entity);
|
dolibarr_set_const($db, "MAIN_MAIL_FORCE_SENDTO", GETPOST("MAIN_MAIL_FORCE_SENDTO"),'chaine',0,'',$conf->entity);
|
||||||
|
dolibarr_set_const($db, "MAIN_MAIL_ENABLED_USER_DEST_SELECT", GETPOST("MAIN_MAIL_ENABLED_USER_DEST_SELECT"),'chaine',0,'',$conf->entity);
|
||||||
// Send mode parameters
|
// Send mode parameters
|
||||||
dolibarr_set_const($db, "MAIN_MAIL_SENDMODE", GETPOST("MAIN_MAIL_SENDMODE"),'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_PORT", GETPOST("MAIN_MAIL_SMTP_PORT"),'chaine',0,'',$conf->entity);
|
||||||
@ -275,6 +276,12 @@ if ($action == 'edit')
|
|||||||
print '<input class="flat" name="MAIN_MAIL_FORCE_SENDTO" size="32" value="' . (! empty($conf->global->MAIN_MAIL_FORCE_SENDTO)?$conf->global->MAIN_MAIL_FORCE_SENDTO:'') . '" />';
|
print '<input class="flat" name="MAIN_MAIL_FORCE_SENDTO" size="32" value="' . (! empty($conf->global->MAIN_MAIL_FORCE_SENDTO)?$conf->global->MAIN_MAIL_FORCE_SENDTO:'') . '" />';
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
|
|
||||||
|
//Add user to select destinaries list
|
||||||
|
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ENABLED_USER_DEST_SELECT").'</td><td>';
|
||||||
|
print $form->selectyesno('MAIN_MAIL_ENABLED_USER_DEST_SELECT',$conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT,1);
|
||||||
|
print '</td></tr>';
|
||||||
|
|
||||||
// Separator
|
// Separator
|
||||||
|
|
||||||
print '<tr class="oddeven"><td colspan="2"> </td></tr>';
|
print '<tr class="oddeven"><td colspan="2"> </td></tr>';
|
||||||
@ -544,6 +551,9 @@ else
|
|||||||
if (! empty($conf->global->MAIN_MAIL_FORCE_SENDTO) && ! isValidEmail($conf->global->MAIN_MAIL_FORCE_SENDTO)) print img_warning($langs->trans("ErrorBadEMail"));
|
if (! empty($conf->global->MAIN_MAIL_FORCE_SENDTO) && ! isValidEmail($conf->global->MAIN_MAIL_FORCE_SENDTO)) print img_warning($langs->trans("ErrorBadEMail"));
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
|
//Add user to select destinaries list
|
||||||
|
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_ENABLED_USER_DEST_SELECT").'</td><td>'.yn($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT).'</td></tr>';
|
||||||
|
|
||||||
// Separator
|
// Separator
|
||||||
|
|
||||||
print '<tr class="oddeven"><td colspan="2"> </td></tr>';
|
print '<tr class="oddeven"><td colspan="2"> </td></tr>';
|
||||||
|
|||||||
@ -170,6 +170,9 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
$sendtocc='';
|
$sendtocc='';
|
||||||
$sendtobcc='';
|
$sendtobcc='';
|
||||||
$sendtoid = array();
|
$sendtoid = array();
|
||||||
|
if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
|
||||||
|
$sendtouserid=array();
|
||||||
|
}
|
||||||
|
|
||||||
// Define $sendto
|
// Define $sendto
|
||||||
$receiver=$_POST['receiver'];
|
$receiver=$_POST['receiver'];
|
||||||
@ -200,6 +203,18 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
|
||||||
|
$receiveruser=$_POST['receiveruser'];
|
||||||
|
if (is_array($receiveruser) && count($receiveruser)>0)
|
||||||
|
{
|
||||||
|
$fuserdest = new User($db);
|
||||||
|
foreach($receiveruser as $key=>$val)
|
||||||
|
{
|
||||||
|
$tmparray[] = $fuserdest->user_get_property($key,'email');
|
||||||
|
$sendtouserid[] = $key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
$sendto=implode(',',$tmparray);
|
$sendto=implode(',',$tmparray);
|
||||||
|
|
||||||
// Define $sendtocc
|
// Define $sendtocc
|
||||||
@ -230,6 +245,19 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
|
||||||
|
$receiveruser=$_POST['receiveccruser'];
|
||||||
|
|
||||||
|
if (is_array($receiveruser) && count($receiveruser)>0)
|
||||||
|
{
|
||||||
|
$fuserdest = new User($db);
|
||||||
|
foreach($receiveruser as $key=>$val)
|
||||||
|
{
|
||||||
|
$tmparray[] = $fuserdest->user_get_property($key,'email');
|
||||||
|
$sendtouserid[] = $key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
$sendtocc=implode(',',$tmparray);
|
$sendtocc=implode(',',$tmparray);
|
||||||
|
|
||||||
if (dol_strlen($sendto))
|
if (dol_strlen($sendto))
|
||||||
@ -430,6 +458,9 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
|
|||||||
if (is_array($attachedfiles) && count($attachedfiles)>0) {
|
if (is_array($attachedfiles) && count($attachedfiles)>0) {
|
||||||
$object->attachedfiles = $attachedfiles;
|
$object->attachedfiles = $attachedfiles;
|
||||||
}
|
}
|
||||||
|
if (is_array($sendtouserid) && count($sendtouserid)>0 && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
|
||||||
|
$object->sendtouserid = $sendtouserid;
|
||||||
|
}
|
||||||
|
|
||||||
// Call of triggers
|
// Call of triggers
|
||||||
if (! empty($trigger_name))
|
if (! empty($trigger_name))
|
||||||
|
|||||||
@ -81,6 +81,9 @@ class FormMail extends Form
|
|||||||
var $substit_lines=array();
|
var $substit_lines=array();
|
||||||
var $param=array();
|
var $param=array();
|
||||||
|
|
||||||
|
public $withtouser=array();
|
||||||
|
public $withtoccuser=array();
|
||||||
|
|
||||||
var $error;
|
var $error;
|
||||||
|
|
||||||
public $lines_model;
|
public $lines_model;
|
||||||
@ -624,6 +627,28 @@ class FormMail extends Form
|
|||||||
$out.= "</td></tr>\n";
|
$out.= "</td></tr>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To User
|
||||||
|
if (! empty($this->withtouser) && is_array($this->withtouser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT))
|
||||||
|
{
|
||||||
|
$out.= '<tr><td>';
|
||||||
|
$out.= $langs->trans("MailToSalaries");
|
||||||
|
$out.= '</td><td>';
|
||||||
|
|
||||||
|
// multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
|
||||||
|
$tmparray = $this->withtouser;
|
||||||
|
foreach($tmparray as $key => $val)
|
||||||
|
{
|
||||||
|
$tmparray[$key]=dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
|
||||||
|
}
|
||||||
|
$withtoselected=GETPOST("receiveruser",'none'); // Array of selected value
|
||||||
|
if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action','aZ09') == 'presend')
|
||||||
|
{
|
||||||
|
$withtoselected = array_keys($tmparray);
|
||||||
|
}
|
||||||
|
$out.= $form->multiselectarray("receiveruser", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, "");
|
||||||
|
$out.= "</td></tr>\n";
|
||||||
|
}
|
||||||
|
|
||||||
// withoptiononeemailperrecipient
|
// withoptiononeemailperrecipient
|
||||||
if (! empty($this->withoptiononeemailperrecipient))
|
if (! empty($this->withoptiononeemailperrecipient))
|
||||||
{
|
{
|
||||||
@ -668,6 +693,28 @@ class FormMail extends Form
|
|||||||
$out.= "</td></tr>\n";
|
$out.= "</td></tr>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To User cc
|
||||||
|
if (! empty($this->withtoccuser) && is_array($this->withtoccuser) && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT))
|
||||||
|
{
|
||||||
|
$out.= '<tr><td>';
|
||||||
|
$out.= $langs->trans("MailToCCSalaries");
|
||||||
|
$out.= '</td><td>';
|
||||||
|
|
||||||
|
// multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
|
||||||
|
$tmparray = $this->withtoccuser;
|
||||||
|
foreach($tmparray as $key => $val)
|
||||||
|
{
|
||||||
|
$tmparray[$key]=dol_htmlentities($tmparray[$key], null, 'UTF-8', true);
|
||||||
|
}
|
||||||
|
$withtoselected=GETPOST("receiverccuser",'none'); // Array of selected value
|
||||||
|
if (empty($withtoselected) && count($tmparray) == 1 && GETPOST('action','aZ09') == 'presend')
|
||||||
|
{
|
||||||
|
$withtoselected = array_keys($tmparray);
|
||||||
|
}
|
||||||
|
$out.= $form->multiselectarray("receiverccuser", $tmparray, $withtoselected, null, null, 'inline-block minwidth500', null, "");
|
||||||
|
$out.= "</td></tr>\n";
|
||||||
|
}
|
||||||
|
|
||||||
// CCC
|
// CCC
|
||||||
if (! empty($this->withtoccc) || is_array($this->withtoccc))
|
if (! empty($this->withtoccc) || is_array($this->withtoccc))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -152,6 +152,24 @@ if ($action == 'presend')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
|
||||||
|
$listeuser=array();
|
||||||
|
$fuserdest = new User($db);
|
||||||
|
|
||||||
|
$result= $fuserdest->fetchAll('ASC', 't.lastname', 0, 0, array('customsql'=>'t.statut=1 AND t.employee=1 AND t.email IS NOT NULL AND t.email<>\'\''));
|
||||||
|
if ($result>0 && is_array($fuserdest->users) && count($fuserdest->users)>0) {
|
||||||
|
foreach($fuserdest->users as $uuserdest) {
|
||||||
|
$listeuser[$uuserdest->id] = $uuserdest->user_get_property($uuserdest->id,'email');
|
||||||
|
}
|
||||||
|
} elseif ($result<0) {
|
||||||
|
setEventMessages(null, $fuserdest->errors,'errors');
|
||||||
|
}
|
||||||
|
if (count($listeuser)>0) {
|
||||||
|
$formmail->withtouser = $listeuser;
|
||||||
|
$formmail->withtoccuser = $listeuser;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$formmail->withto = GETPOST('sendto') ? GETPOST('sendto') : $liste;
|
$formmail->withto = GETPOST('sendto') ? GETPOST('sendto') : $liste;
|
||||||
$formmail->withtocc = $liste;
|
$formmail->withtocc = $liste;
|
||||||
|
|||||||
@ -889,6 +889,10 @@ class InterfaceActionsAuto extends DolibarrTriggers
|
|||||||
$actioncomm->fk_element = $elementid;
|
$actioncomm->fk_element = $elementid;
|
||||||
$actioncomm->elementtype = $elementtype;
|
$actioncomm->elementtype = $elementtype;
|
||||||
|
|
||||||
|
if (property_exists($object,'sendtouserid') && is_array($object->sendtouserid) && count($object->sendtouserid)>0) {
|
||||||
|
$actioncomm->userassigned=$object->sendtouserid;
|
||||||
|
}
|
||||||
|
|
||||||
$ret=$actioncomm->create($user); // User creating action
|
$ret=$actioncomm->create($user); // User creating action
|
||||||
|
|
||||||
if ($ret > 0 && $conf->global->MAIN_COPY_FILE_IN_EVENT_AUTO)
|
if ($ret > 0 && $conf->global->MAIN_COPY_FILE_IN_EVENT_AUTO)
|
||||||
|
|||||||
@ -273,6 +273,7 @@ MAIN_MAIL_ERRORS_TO=Email used as 'Errors-To' field in emails sent
|
|||||||
MAIN_MAIL_AUTOCOPY_TO= Send systematically a hidden carbon-copy of all sent emails to
|
MAIN_MAIL_AUTOCOPY_TO= Send systematically a hidden carbon-copy of all sent emails to
|
||||||
MAIN_DISABLE_ALL_MAILS=Disable all emails sendings (for test purposes or demos)
|
MAIN_DISABLE_ALL_MAILS=Disable all emails sendings (for test purposes or demos)
|
||||||
MAIN_MAIL_FORCE_SENDTO=Send all emails to (instead of real recipients, for test purposes)
|
MAIN_MAIL_FORCE_SENDTO=Send all emails to (instead of real recipients, for test purposes)
|
||||||
|
MAIN_MAIL_ENABLED_USER_DEST_SELECT=Add salaries users with email into allowed destinaries list
|
||||||
MAIN_MAIL_SENDMODE=Method to use to send EMails
|
MAIN_MAIL_SENDMODE=Method to use to send EMails
|
||||||
MAIN_MAIL_SMTPS_ID=SMTP ID if authentication required
|
MAIN_MAIL_SMTPS_ID=SMTP ID if authentication required
|
||||||
MAIN_MAIL_SMTPS_PW=SMTP Password if authentication required
|
MAIN_MAIL_SMTPS_PW=SMTP Password if authentication required
|
||||||
|
|||||||
@ -11,7 +11,9 @@ MailFrom=Sender
|
|||||||
MailErrorsTo=Errors to
|
MailErrorsTo=Errors to
|
||||||
MailReply=Reply to
|
MailReply=Reply to
|
||||||
MailTo=Receiver(s)
|
MailTo=Receiver(s)
|
||||||
|
MailToSalaries=To salarie(s)
|
||||||
MailCC=Copy to
|
MailCC=Copy to
|
||||||
|
MailToCCSalaries=Copy to salarie(s)
|
||||||
MailCCC=Cached copy to
|
MailCCC=Cached copy to
|
||||||
MailTopic=EMail topic
|
MailTopic=EMail topic
|
||||||
MailText=Message
|
MailText=Message
|
||||||
|
|||||||
@ -205,6 +205,7 @@ $help_url='';
|
|||||||
$title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("MyObjects"));
|
$title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("MyObjects"));
|
||||||
|
|
||||||
|
|
||||||
|
// TODO : move this SQL request into fetchAll class method
|
||||||
// Build and execute select
|
// Build and execute select
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
$sql = 'SELECT ';
|
$sql = 'SELECT ';
|
||||||
|
|||||||
@ -115,7 +115,7 @@ class User extends CommonObject
|
|||||||
public $lastsearch_values_tmp; // To store current search criterias for user
|
public $lastsearch_values_tmp; // To store current search criterias for user
|
||||||
public $lastsearch_values; // To store last saved search criterias for user
|
public $lastsearch_values; // To store last saved search criterias for user
|
||||||
|
|
||||||
public $users; // To store all tree of users hierarchy
|
public $users = array(); // To store all tree of users hierarchy
|
||||||
public $parentof; // To store an array of all parents for all ids.
|
public $parentof; // To store an array of all parents for all ids.
|
||||||
private $cache_childids;
|
private $cache_childids;
|
||||||
|
|
||||||
@ -3003,5 +3003,105 @@ class User extends CommonObject
|
|||||||
return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return property of user from its id
|
||||||
|
*
|
||||||
|
* @param int $rowid id of contact
|
||||||
|
* @param string $mode 'email' or 'mobile'
|
||||||
|
* @return string Email of user with format: "Full name <email>"
|
||||||
|
*/
|
||||||
|
function user_get_property($rowid,$mode)
|
||||||
|
{
|
||||||
|
$user_property='';
|
||||||
|
|
||||||
|
if (empty($rowid)) return '';
|
||||||
|
|
||||||
|
$sql = "SELECT rowid, email, user_mobile, civility, lastname, firstname";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."user";
|
||||||
|
$sql.= " WHERE rowid = '".$rowid."'";
|
||||||
|
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$nump = $this->db->num_rows($resql);
|
||||||
|
|
||||||
|
if ($nump)
|
||||||
|
{
|
||||||
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
|
||||||
|
if ($mode == 'email') $user_property = dolGetFirstLastname($obj->firstname, $obj->lastname)." <".$obj->email.">";
|
||||||
|
else if ($mode == 'mobile') $user_property = $obj->user_mobile;
|
||||||
|
}
|
||||||
|
return $user_property;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dol_print_error($this->db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load all objects into $this->users
|
||||||
|
*
|
||||||
|
* @param string $sortorder sort order
|
||||||
|
* @param string $sortfield sort field
|
||||||
|
* @param int $limit limit page
|
||||||
|
* @param int $offset page
|
||||||
|
* @param array $filter filter output
|
||||||
|
* @return int <0 if KO, >0 if OK
|
||||||
|
*/
|
||||||
|
function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter=array())
|
||||||
|
{
|
||||||
|
global $conf;
|
||||||
|
|
||||||
|
$sql="SELECT t.rowid";
|
||||||
|
$sql.= ' FROM '.MAIN_DB_PREFIX .$this->table_element.' as t ';
|
||||||
|
$sql.= " WHERE 1";
|
||||||
|
|
||||||
|
//Manage filter
|
||||||
|
if (!empty($filter)){
|
||||||
|
foreach($filter as $key => $value) {
|
||||||
|
if (strpos($key,'date')) {
|
||||||
|
$sql.= ' AND '.$key.' = \''.$this->db->idate($value).'\'';
|
||||||
|
}
|
||||||
|
elseif ($key=='customsql') {
|
||||||
|
$sql.= ' AND '.$value;
|
||||||
|
} else {
|
||||||
|
$sql.= ' AND '.$key.' LIKE \'%'.$value.'%\'';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$sql.= $this->db->order($sortfield,$sortorder);
|
||||||
|
if ($limit) $sql.= $this->db->plimit($limit+1,$offset);
|
||||||
|
|
||||||
|
dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG);
|
||||||
|
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$this->users=array();
|
||||||
|
$num = $this->db->num_rows($resql);
|
||||||
|
if ($num)
|
||||||
|
{
|
||||||
|
while ($obj = $this->db->fetch_object($resql))
|
||||||
|
{
|
||||||
|
$line = new self($this->db);
|
||||||
|
$result = $line->fetch($obj->rowid);
|
||||||
|
if ($result>0 && !empty($line->id)) {
|
||||||
|
$this->users[$obj->rowid] = clone $line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->db->free($resql);
|
||||||
|
}
|
||||||
|
return $num;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->errors[] = $this->db->lasterror();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user