Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2023-10-11 12:04:37 +02:00
commit cc552a498c
6 changed files with 51 additions and 41 deletions

View file

@ -900,22 +900,26 @@ while ($currentdaytoshow < $lastdaytoshow) {
}
} else {
/* Use this list to have for all users */
$sql = "SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity";
$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
if (isModEnabled('multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
$sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
$sql = "SELECT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity";
$sql .= " FROM ".$db->prefix()."user as u";
if (isModEnabled('multicompany') && getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
$sql .= " WHERE u.rowid IN (";
$sql .= " SELECT ug.fk_user FROM ".$db->prefix()."usergroup_user as ug";
$sql .= " WHERE ug.entity IN (".getEntity('usergroup').")";
$sql .= " AND ug.fk_user = u.rowid ";
if ($usergroup > 0) {
$sql .= " AND ug.fk_usergroup = ".((int) $usergroup);
}
$sql .= ")";
} else {
if ($usergroup > 0) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ug ON u.rowid = ug.fk_user";
$sql .= " LEFT JOIN ".$db->prefix()."usergroup_user as ug ON u.rowid = ug.fk_user";
}
$sql .= " WHERE u.entity IN (".getEntity('user').")";
if ($usergroup > 0) {
$sql .= " AND ug.fk_usergroup = ".((int) $usergroup);
}
}
$sql .= " AND u.statut = 1";
if ($usergroup > 0) {
$sql .= " AND ug.fk_usergroup = ".((int) $usergroup);
}
if ($user->socid > 0) {
// External users should see only contacts of their company
$sql .= " AND u.fk_soc = ".((int) $user->socid);

View file

@ -2136,9 +2136,6 @@ abstract class CommonObject
$restrictiononfksoc = empty($this->restrictiononfksoc) ? 0 : $this->restrictiononfksoc;
$sql = "SELECT MAX(te.".$fieldid.")";
$sql .= " FROM ".(empty($nodbprefix) ?$this->db->prefix():'').$this->table_element." as te";
if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
$sql .= ",".$this->db->prefix()."usergroup_user as ug";
}
if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
$tmparray = explode('@', $this->ismultientitymanaged);
$sql .= ", ".$this->db->prefix().$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity
@ -2174,12 +2171,11 @@ abstract class CommonObject
$sql .= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid
}
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
if ($this->element == 'user' && getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
$sql .= " AND te.entity IS NOT NULL"; // Show all users
} else {
$sql .= " AND ug.fk_user = te.rowid";
$sql .= " AND ug.entity IN (".getEntity('usergroup').")";
$sql .= " AND te.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix()."usergroup_user as ug WHERE ug.entity IN (".getEntity('usergroup')."))";
}
} else {
$sql .= ' AND te.entity IN ('.getEntity($this->element).')';
@ -2210,9 +2206,6 @@ abstract class CommonObject
$sql = "SELECT MIN(te.".$fieldid.")";
$sql .= " FROM ".(empty($nodbprefix) ?$this->db->prefix():'').$this->table_element." as te";
if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
$sql .= ",".$this->db->prefix()."usergroup_user as ug";
}
if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
$tmparray = explode('@', $this->ismultientitymanaged);
$sql .= ", ".$this->db->prefix().$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity
@ -2248,12 +2241,11 @@ abstract class CommonObject
$sql .= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid
}
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
if ($this->element == 'user' && getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
$sql .= " AND te.entity IS NOT NULL"; // Show all users
} else {
$sql .= " AND ug.fk_user = te.rowid";
$sql .= " AND ug.entity IN (".getEntity('usergroup').")";
$sql .= " AND te.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix()."usergroup_user as ug WHERE ug.entity IN (".getEntity('usergroup')."))";
}
} else {
$sql .= ' AND te.entity IN ('.getEntity($this->element).')';

View file

@ -2009,7 +2009,7 @@ class Form
* @return array|string HTML select string
* @see select_dolgroups()
*/
public function select_dolusers($selected = '', $htmlname = 'userid', $show_empty = 0, $exclude = null, $disabled = 0, $include = '', $enableonly = '', $force_entity = '0', $maxlength = 0, $showstatus = 0, $morefilter = '', $show_every = 0, $enableonlytext = '', $morecss = '', $notdisabled = 0, $outputmode = 0, $multiple = false, $forcecombo = 0)
public function select_dolusers($selected = '', $htmlname = 'userid', $show_empty = 0, $exclude = null, $disabled = 0, $include = '', $enableonly = '', $force_entity = 0, $maxlength = 0, $showstatus = 0, $morefilter = '', $show_every = 0, $enableonlytext = '', $morecss = '', $notdisabled = 0, $outputmode = 0, $multiple = false, $forcecombo = 0)
{
// phpcs:enable
global $conf, $user, $langs, $hookmanager;
@ -2056,18 +2056,16 @@ class Form
$sql .= " FROM " . $this->db->prefix() . "user as u";
if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
$sql .= " LEFT JOIN " . $this->db->prefix() . "entity as e ON e.rowid = u.entity";
if ($force_entity) {
if (!empty($force_entity)) {
$sql .= " WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) . ")";
} else {
$sql .= " WHERE u.entity IS NOT NULL";
}
} else {
if (isModEnabled('multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
$sql .= " LEFT JOIN " . $this->db->prefix() . "usergroup_user as ug";
$sql .= " ON ug.fk_user = u.rowid";
$sql .= " WHERE ug.entity = " . (int) $conf->entity;
if (isModEnabled('multicompany') && getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
$sql .= " WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix()."usergroup_user as ug WHERE ug.entity IN (".getEntity('usergroup')."))";
} else {
$sql .= " WHERE u.entity IN (0, " . ((int) $conf->entity) . ")";
$sql .= " WHERE u.entity IN (" . getEntity('user') . ")";
}
}
if (!empty($user->socid)) {
@ -2173,8 +2171,8 @@ class Form
$moreinfohtml .= ($moreinfohtml ? ' - ' : ' <span class="opacitymedium">(') . $langs->trans('Disabled');
}
}
if (isModEnabled('multicompany') && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && !$user->entity) {
if (!$obj->entity) {
if (isModEnabled('multicompany') && !getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1 && !empty($user->admin) && empty($user->entity)) {
if (empty($obj->entity)) {
$moreinfo .= ($moreinfo ? ' - ' : ' (') . $langs->trans("AllEntities");
$moreinfohtml .= ($moreinfohtml ? ' - ' : ' <span class="opacitymedium">(') . $langs->trans("AllEntities");
} else {
@ -2184,9 +2182,9 @@ class Form
}
}
}
$moreinfo .= ($moreinfo ? ')' : '');
$moreinfohtml .= ($moreinfohtml ? ')</span>' : '');
if ($disableline && $disableline != '1') {
$moreinfo .= (!empty($moreinfo) ? ')' : '');
$moreinfohtml .= (!empty($moreinfohtml) ? ')</span>' : '');
if (!empty($disableline) && $disableline != '1') {
// Add text from $enableonlytext parameter
$moreinfo .= ' - ' . $disableline;
$moreinfohtml .= ' - ' . $disableline;
@ -2195,7 +2193,7 @@ class Form
$labeltoshowhtml .= $moreinfohtml;
$out .= '<option value="' . $obj->rowid . '"';
if ($disableline) {
if (!empty($disableline)) {
$out .= ' disabled';
}
if ((is_object($selected) && $selected->id == $obj->rowid) || (!is_object($selected) && in_array($obj->rowid, $selected))) {
@ -9938,7 +9936,7 @@ class Form
$out .= '>';
$out .= $obj->name;
if (isModEnabled('multicompany') && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1) {
if (isModEnabled('multicompany') && !getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1) {
$out .= " (" . $obj->label . ")";
}

View file

@ -504,7 +504,7 @@ class FormOther
$sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut as status, u.login, u.photo, u.gender, u.entity, u.admin";
$sql_usr .= " FROM ".$this->db->prefix()."user as u";
if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
$sql_usr .= " WHERE u.entity IS NOT NULL"; // Show all users
} else {
@ -533,7 +533,7 @@ class FormOther
$sql_usr .= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut as status, u2.login, u2.photo, u2.gender, u2.entity, u2.admin";
$sql_usr .= " FROM ".$this->db->prefix()."user as u2, ".$this->db->prefix()."societe_commerciaux as sc";
if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
$sql_usr .= " WHERE u2.entity IS NOT NULL"; // Show all users
} else {

View file

@ -528,7 +528,7 @@ class Ldap
*/
public function add($dn, $info, $user)
{
dol_syslog(get_class($this)."::add dn=".$dn." info=".json_encode($info));
dol_syslog(get_class($this)."::add dn=".$dn." info=".print_r($info, true));
// Check parameters
if (!$this->connection) {
@ -576,7 +576,7 @@ class Ldap
*/
public function modify($dn, $info, $user)
{
dol_syslog(get_class($this)."::modify dn=".$dn." info=".join(',', $info));
dol_syslog(get_class($this)."::modify dn=".$dn." info=".print_r($info, true));
// Check parameters
if (!$this->connection) {

View file

@ -4,6 +4,7 @@
* Copyright (C) 2019-2023 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2020 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2023 Charlene Benke <charlene@patas-monkey.com>
* Copyright (C) 2023 Benjamin Falière <benjamin.faliere@altairis.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -1713,9 +1714,10 @@ class Ticket extends CommonObject
* @param array $mimetype_list List of MIME type of attached files
* @param array $mimefilename_list List of attached file name in message
* @param boolean $send_email Whether the message is sent by email
* @param boolean $public_area 1=Is the public area
* @return int <0 if KO, >0 if OK
*/
public function createTicketMessage($user, $notrigger = 0, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $send_email = false)
public function createTicketMessage($user, $notrigger = 0, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $send_email = false, $public_area = false)
{
global $conf, $langs;
$error = 0;
@ -1758,6 +1760,20 @@ class Ticket extends CommonObject
$actioncomm->fk_element = $this->id;
$actioncomm->fk_project = $this->fk_project;
// add contact id from author email on public interface
if ($public_area && !empty($this->origin_email) && !empty($conf->global->TICKET_ASSIGN_CONTACT_TO_MESSAGE)) {
$contacts = $this->searchContactByEmail($this->origin_email);
if (!empty($contacts)) {
// Ensure that contact is active and select first active contact
foreach ($contacts as $contact) {
if ((int) $contact->statut == 1) {
$actioncomm->contact_id = $contact->id;
break;
}
}
}
}
$attachedfiles = array();
$attachedfiles['paths'] = $filename_list;
$attachedfiles['names'] = $mimefilename_list;
@ -2560,7 +2576,7 @@ class Ticket extends CommonObject
$listofnames = $resarray['listofnames'];
$listofmimes = $resarray['listofmimes'];
$id = $object->createTicketMessage($user, 0, $listofpaths, $listofmimes, $listofnames, $send_email);
$id = $object->createTicketMessage($user, 0, $listofpaths, $listofmimes, $listofnames, $send_email, $public_area);
if ($id <= 0) {
$error++;
$this->error = $object->error;