';
diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php
index b5e8cd33517..3d247bfd5ca 100644
--- a/htdocs/contact/class/contact.class.php
+++ b/htdocs/contact/class/contact.class.php
@@ -87,17 +87,17 @@ class Contact extends CommonObject
/**
* @deprecated
- * @see state_id
+ * @see $state_id
*/
public $fk_departement;
/**
* @deprecated
- * @see state_code
+ * @see $state_code
*/
public $departement_code;
/**
* @deprecated
- * @see state
+ * @see $state
*/
public $departement;
public $state_id; // Id of department
@@ -682,12 +682,13 @@ class Contact extends CommonObject
/**
* Load object contact
*
- * @param int $id id du contact
- * @param User $user Utilisateur (abonnes aux alertes) qui veut les alertes de ce contact
- * @param string $ref_ext External reference, not given by Dolibarr
- * @return int -1 if KO, 0 if OK but not found, 1 if OK
+ * @param int $id id du contact
+ * @param User $user Utilisateur (abonnes aux alertes) qui veut les alertes de ce contact
+ * @param string $ref_ext External reference, not given by Dolibarr
+ * @param string $email Email
+ * @return int -1 if KO, 0 if OK but not found, 1 if OK
*/
- function fetch($id, $user=0, $ref_ext='')
+ function fetch($id, $user=null, $ref_ext='', $email='')
{
global $langs;
@@ -721,9 +722,15 @@ class Contact extends CommonObject
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
if ($id) $sql.= " WHERE c.rowid = ". $id;
- elseif ($ref_ext) {
+ else
+ {
$sql .= " WHERE c.entity IN (".getEntity($this->element).")";
- $sql .= " AND c.ref_ext = '".$this->db->escape($ref_ext)."'";
+ if ($ref_ext) {
+ $sql .= " AND c.ref_ext = '".$this->db->escape($ref_ext)."'";
+ }
+ if ($email) {
+ $sql .= " AND c.email = '".$this->db->escape($email)."'";
+ }
}
$resql=$this->db->query($sql);
diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php
index 61c4b636758..9ffaceadb26 100644
--- a/htdocs/core/actions_sendmails.inc.php
+++ b/htdocs/core/actions_sendmails.inc.php
@@ -427,8 +427,9 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$object->socid = $sendtosocid; // To link to a company
$object->sendtoid = $sendtoid; // To link to contact addresses. This is an array.
$object->actiontypecode = $actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
- $object->actionmsg = $actionmsg; // Long text
- $object->actionmsg2 = $actionmsg2; // Short text
+ $object->actionmsg = $actionmsg; // Long text (@TODO Replace this with $message, we already have details of email in dedicated properties)
+ $object->actionmsg2 = $actionmsg2; // Short text ($langs->transnoentities('MailSentBy')...);
+
$object->trackid = $trackid;
$object->fk_element = $object->id;
$object->elementtype = $object->element;
@@ -439,9 +440,14 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
$object->sendtouserid = $sendtouserid;
}
- // TODO Set object->email_xxx properties
+ $object->email_msgid = $mailfile->msgid; // @TODO Set msgid into $mailfile after sending
+ $object->email_from = $from;
+ $object->email_subject = $subject;
+ $object->email_to = $sendto;
+ $object->email_tocc = $sendtocc;
+ $object->email_tobcc = $sendtobcc;
+ $object->email_subject = $subject;
$object->email_msgid = $mailfile->msgid;
- //...
// Call of triggers
if (! empty($trigger_name))
diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php
index 0c9a43d5ca9..9d3bc24bd76 100644
--- a/htdocs/core/lib/admin.lib.php
+++ b/htdocs/core/lib/admin.lib.php
@@ -1731,7 +1731,7 @@ function email_admin_prepare_head()
$h = 0;
$head = array();
- if ($user->admin && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates'))
+ if (! empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates'))
{
$head[$h][0] = DOL_URL_ROOT."/admin/mails.php";
$head[$h][1] = $langs->trans("OutGoingEmailSetup");
@@ -1752,7 +1752,7 @@ function email_admin_prepare_head()
$head[$h][2] = 'templates';
$h++;
- if ($conf->global->MAIN_FEATURES_LEVEL >= 1)
+ if ($conf->global->MAIN_FEATURES_LEVEL >= 1 && ! empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates'))
{
$head[$h][0] = DOL_URL_ROOT."/admin/mails_senderprofile_list.php";
$head[$h][1] = $langs->trans("EmailSenderProfiles");
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 5ec9e40518f..7bb634cde2a 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -2837,35 +2837,50 @@ function isValidPhone($phone)
* @param string $stringencoding Encoding of string
* @return int Length of string
*/
-function dol_strlen($string,$stringencoding='UTF-8')
+function dol_strlen($string, $stringencoding='UTF-8')
{
if (function_exists('mb_strlen')) return mb_strlen($string,$stringencoding);
else return strlen($string);
}
/**
- * Make a substring. Works even in mbstring module is not enabled.
+ * Make a substring. Works even if mbstring module is not enabled for better compatibility.
*
* @param string $string String to scan
* @param string $start Start position
- * @param int $length Length
+ * @param int $length Length (in nb of characters or nb of bytes depending on trunconbytes param)
* @param string $stringencoding Page code used for input string encoding
+ * @param int $trunconbytes 1=Length is max of bytes instead of max of characters
* @return string substring
*/
-function dol_substr($string,$start,$length,$stringencoding='')
+function dol_substr($string, $start, $length, $stringencoding='', $trunconbytes=0)
{
global $langs;
if (empty($stringencoding)) $stringencoding=$langs->charset_output;
$ret='';
- if (function_exists('mb_substr'))
+ if (empty($trunconbytes))
{
- $ret=mb_substr($string,$start,$length,$stringencoding);
+ if (function_exists('mb_substr'))
+ {
+ $ret=mb_substr($string, $start, $length, $stringencoding);
+ }
+ else
+ {
+ $ret=substr($string, $start, $length);
+ }
}
else
{
- $ret=substr($string,$start,$length);
+ if (function_exists('mb_strcut'))
+ {
+ $ret=mb_strcut($string, $start, $length, $stringencoding);
+ }
+ else
+ {
+ $ret=substr($string, $start, $length);
+ }
}
return $ret;
}
@@ -3063,7 +3078,7 @@ function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',
* @param string $trunc Where to trunc: right, left, middle (size must be a 2 power), wrap
* @param string $stringencoding Tell what is source string encoding
* @param int $nodot Truncation do not add ... after truncation. So it's an exact truncation.
- * @param int $display Trunc is use to display and can be changed for small screen. TODO Remove this param (must be dealt with CSS)
+ * @param int $display Trunc is used to display data and can be changed for small screen. TODO Remove this param (must be dealt with CSS)
* @return string Truncated string. WARNING: length is never higher than $size if $nodot is set, but can be 3 chars higher otherwise.
*/
function dol_trunc($string,$size=40,$trunc='right',$stringencoding='UTF-8',$nodot=0, $display=0)
@@ -6782,26 +6797,27 @@ function dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id
if ($key == '') return '';
// Check in cache
- if (isset($cache_codes[$tablename][$key])) // Can be defined to 0 or ''
+ if (isset($cache_codes[$tablename][$key][$fieldid])) // Can be defined to 0 or ''
{
- return $cache_codes[$tablename][$key]; // Found in cache
+ return $cache_codes[$tablename][$key][$fieldid]; // Found in cache
}
+ dol_syslog('dol_getIdFromCode (value not found into cache)', LOG_DEBUG);
+
$sql = "SELECT ".$fieldid." as valuetoget";
$sql.= " FROM ".MAIN_DB_PREFIX.$tablename;
$sql.= " WHERE ".$fieldkey." = '".$db->escape($key)."'";
if (! empty($entityfilter))
$sql.= " AND entity IN (" . getEntity($tablename) . ")";
- dol_syslog('dol_getIdFromCode', LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
- if ($obj) $cache_codes[$tablename][$key]=$obj->valuetoget;
- else $cache_codes[$tablename][$key]='';
+ if ($obj) $cache_codes[$tablename][$key][$fieldid]=$obj->valuetoget;
+ else $cache_codes[$tablename][$key][$fieldid]='';
$db->free($resql);
- return $cache_codes[$tablename][$key];
+ return $cache_codes[$tablename][$key][$fieldid];
}
else
{
@@ -6889,8 +6905,6 @@ function picto_from_langcode($codelang, $moreatt = '')
if (empty($codelang)) return '';
- if (empty($codelang)) return '';
-
if ($codelang == 'auto')
{
return '';
@@ -7061,6 +7075,7 @@ function printCommonFooter($zone='private')
if (! empty($conf->use_javascript_ajax))
{
print '