NEW : option to send email to salaries

This commit is contained in:
florian HENRY 2018-03-21 11:48:30 +01:00
parent d647bf23d6
commit dc6f4c1f4d
8 changed files with 214 additions and 4 deletions

View File

@ -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_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
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);
@ -271,6 +272,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 '</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
print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';
@ -541,6 +548,9 @@ else
if (! empty($conf->global->MAIN_MAIL_FORCE_SENDTO) && ! isValidEmail($conf->global->MAIN_MAIL_FORCE_SENDTO)) print img_warning($langs->trans("ErrorBadEMail"));
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
print '<tr class="oddeven"><td colspan="2">&nbsp;</td></tr>';

View File

@ -170,6 +170,9 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$sendtocc='';
$sendtobcc='';
$sendtoid = array();
if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) {
$sendtouserid=array();
}
// Define $sendto
$receiver=$_POST['receiver'];
@ -192,14 +195,25 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
if ($val == 'thirdparty') // Id of third party
{
$tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>';
}
elseif ($val) // Id du contact
} elseif ($val) // Id du contact
{
$tmparray[] = $thirdparty->contact_get_property((int) $val,'email');
$sendtoid[] = $val;
}
}
}
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);
// Define $sendtocc
@ -230,6 +244,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);
if (dol_strlen($sendto))

View File

@ -81,6 +81,9 @@ class FormMail extends Form
var $substit_lines=array();
var $param=array();
public $withtouser=array();
public $withtoccuser=array();
var $error;
public $lines_model;
@ -332,7 +335,7 @@ class FormMail extends Form
$out.= "\n".'<!-- Begin form mail type='.$this->param["models"].' --><div id="mailformdiv"></div>'."\n";
if ($this->withform == 1)
{
$out.= '<form method="POST" name="mailform" id="mailform" enctype="multipart/form-data" action="'.$this->param["returnurl"].'#formmail">'."\n";
$out.= '<form method="POST" name="mailform" id="mailform" action="'.$this->param["returnurl"].'#formmail">'."\n";
$out.= '<a id="formmail" name="formmail"></a>';
$out.= '<input style="display:none" type="submit" id="sendmail" name="sendmail">';
@ -623,6 +626,28 @@ class FormMail extends Form
$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
if (! empty($this->withoptiononeemailperrecipient))
{
@ -667,6 +692,28 @@ class FormMail extends Form
$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
if (! empty($this->withtoccc) || is_array($this->withtoccc))
{

View File

@ -147,6 +147,24 @@ if ($action == 'presend')
$liste[$key] = $value;
}
}
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->withtocc = $liste;

View File

@ -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_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_ENABLED_USER_DEST_SELECT=Add salaries users with email into allowed destinaries list
MAIN_MAIL_SENDMODE=Method to use to send EMails
MAIN_MAIL_SMTPS_ID=SMTP ID if authentication required
MAIN_MAIL_SMTPS_PW=SMTP Password if authentication required

View File

@ -11,7 +11,9 @@ MailFrom=Sender
MailErrorsTo=Errors to
MailReply=Reply to
MailTo=Receiver(s)
MailToSalaries=To salarie(s)
MailCC=Copy to
MailToCCSalaries=Copy to salarie(s)
MailCCC=Cached copy to
MailTopic=EMail topic
MailText=Message

View File

@ -202,6 +202,7 @@ $help_url='';
$title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("MyObjects"));
// TODO : move this SQL request into fetchAll class method
// Build and execute select
// --------------------------------------------------------------------
$sql = 'SELECT ';

View File

@ -1,4 +1,6 @@
<?php
use Splash\Tests\WsAdmin\A05SelfTestsTest;
/* Copyright (c) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (c) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (c) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
@ -115,7 +117,7 @@ class User extends CommonObject
public $lastsearch_values_tmp; // To store current 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.
private $cache_childids;
@ -135,6 +137,7 @@ class User extends CommonObject
public $default_c_exp_tax_cat;
public $default_range;
/**
* Constructor de la classe
*
@ -3011,5 +3014,106 @@ class User extends CommonObject
return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
/**
* Return property of contact from its id
*
* @param int $rowid id of contact
* @param string $mode 'email' or 'mobile'
* @return string Email of contact 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->lines
*
* @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;
}
}
}