diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index b59258f6cd7..16f40139a38 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -48,7 +48,7 @@ class BookKeeping extends CommonObject */ public $table_element = 'accounting_bookkeeping'; - public $entity = 1; + public $entity; /** * @var BookKeepingLine[] Lines @@ -295,7 +295,7 @@ class BookKeeping extends CommonObject $sql .= ",'" . $this->db->escape($this->code_journal) . "'"; $sql .= ",'" . $this->db->escape($this->journal_label) . "'"; $sql .= "," . $this->db->escape($this->piece_num); - $sql .= ", " . (! isset($this->entity) ? '1' : $this->entity); + $sql .= ", " . (! isset($this->entity) ? $conf->entity : $this->entity); $sql .= ")"; dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG); @@ -363,6 +363,8 @@ class BookKeeping extends CommonObject * @return int <0 if KO, Id of created object if OK */ public function createStd(User $user, $notrigger = false, $mode='') { + global $conf; + dol_syslog(__METHOD__, LOG_DEBUG); $error = 0; @@ -486,7 +488,7 @@ class BookKeeping extends CommonObject $sql .= ' ' . (empty($this->code_journal) ? 'NULL' : "'" . $this->db->escape($this->code_journal) . "'") . ','; $sql .= ' ' . (empty($this->journal_label) ? 'NULL' : "'" . $this->db->escape($this->journal_label) . "'") . ','; $sql .= ' ' . (empty($this->piece_num) ? 'NULL' : $this->db->escape($this->piece_num)).','; - $sql .= ' ' . (! isset($this->entity) ? '1' : $this->entity); + $sql .= ' ' . (! isset($this->entity) ? $conf->entity : $this->entity); $sql .= ')'; $this->db->begin(); diff --git a/htdocs/core/class/comment.class.php b/htdocs/core/class/comment.class.php index a21057662f2..9aeebd575bf 100644 --- a/htdocs/core/class/comment.class.php +++ b/htdocs/core/class/comment.class.php @@ -7,20 +7,22 @@ class Comment extends CommonObject public $element='comment'; //!< Id that identify managed objects public $table_element='comment'; //!< Name of table without prefix where object is stored - var $fk_element; - var $element_type; + public $fk_element; + public $element_type; - var $description; + public $description; - var $tms; + public $tms; - var $datec; + public $datec; - var $fk_user_author; + public $fk_user_author; - var $entity; + public $entity; - var $import_key; + public $import_key; + + public $comments = array(); public $oldcopy; @@ -289,10 +291,10 @@ class Comment extends CommonObject * @param int $fk_element Id of element * @return array Comment array */ - public static function fetchAllFor($element_type, $fk_element) + public function fetchAllFor($element_type, $fk_element) { global $db,$conf; - $TComments = array(); + $this->comments = array(); if(!empty($element_type) && !empty($fk_element)) { $sql = "SELECT"; $sql.= " c.rowid"; @@ -302,7 +304,7 @@ class Comment extends CommonObject $sql.= " AND c.entity = ".$conf->entity; $sql.= " ORDER BY c.tms DESC"; - dol_syslog("Comment::fetchAllFor", LOG_DEBUG); + dol_syslog(get_class($this).'::'.__METHOD__, LOG_DEBUG); $resql=$db->query($sql); if ($resql) { @@ -313,12 +315,17 @@ class Comment extends CommonObject { $comment = new self($db); $comment->fetch($obj->rowid); - $TComments[] = $comment; + $this->comments[] = $comment; } } $db->free($resql); + } else { + $error++; $this->errors[]="Error ".$this->db->lasterror(); + return -1; } + } - return $TComments; + + return count($this->comments); } } \ No newline at end of file diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 504d03e6c7e..54eeffdc4b6 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6528,8 +6528,14 @@ abstract class CommonObject require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php'; $comment = new Comment($this->db); - $this->comments = Comment::fetchAllFor($this->element, $this->id); - return 1; + $result=$comment->fetchAllFor($this->element, $this->id); + if ($result<0) { + $this->errors=array_merge($this->errors,$comment->errors); + return -1; + } else { + $this->comments = $comment->comments; + } + return count($this->comments); } /** diff --git a/htdocs/core/tpl/bloc_comment.tpl.php b/htdocs/core/tpl/bloc_comment.tpl.php index 473c42eb42f..b7e5e732c3a 100644 --- a/htdocs/core/tpl/bloc_comment.tpl.php +++ b/htdocs/core/tpl/bloc_comment.tpl.php @@ -43,7 +43,7 @@ print ''; $desc = GETPOST('comment_description'); -$doleditor = new DolEditor('comment_description', $desc, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '100%'); +$doleditor = new DolEditor('comment_description', $desc, '', 80, 'dolibarr_notes', 'In', 0, true, true, ROWS_3, '100%'); print $doleditor->Create(1); print ''; diff --git a/htdocs/projet/tasks/comment.php b/htdocs/projet/tasks/comment.php index 49072299ac4..3bf96d7d081 100644 --- a/htdocs/projet/tasks/comment.php +++ b/htdocs/projet/tasks/comment.php @@ -97,7 +97,11 @@ if ($id > 0 || ! empty($ref)) { if ($object->fetch($id,$ref) > 0) { - $res=$object->fetch_optionals($object->id,$extralabels); + $result=$object->fetchComments(); + if ($result<0){ + setEventMessages($object->error,$object->errors,'errors'); + } + $result=$projectstatic->fetch($object->fk_project); if (! empty($projectstatic->socid)) $projectstatic->fetch_thirdparty(); diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 386b814da6f..0f2de0aea1e 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2744,12 +2744,24 @@ class User extends CommonObject // Init $this->users array $sql = "SELECT DISTINCT u.rowid, u.firstname, u.lastname, u.fk_user, u.fk_soc, u.login, u.email, u.gender, u.admin, u.statut, u.photo, u.entity"; // Distinct reduce pb with old tables with duplicates $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; - if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) || (! empty($user->admin) && empty($user->entity)))) - { - $sql.= " WHERE u.entity IS NOT NULL"; - } - else - { + // TODO add hook + if (! empty($conf->multicompany->enabled)) { + if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { + if (! empty($user->admin) && empty($user->entity)) { + if ($conf->entity == 1) { + $sql.= " WHERE u.entity IS NOT NULL"; + } else { + $sql.= " WHERE u.entity IN (".getEntity('user').")"; + } + } else { + $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql.= " WHERE ug.fk_user = u.rowid"; + $sql.= " AND ug.entity IN (".getEntity('user').")"; + } + } else { + $sql.= " WHERE u.entity IN (".getEntity('user').")"; + } + } else { $sql.= " WHERE u.entity IN (".getEntity('user').")"; } if ($filter) $sql.=" AND ".$filter; diff --git a/htdocs/user/home.php b/htdocs/user/home.php index 6600d262002..0a4cb253c0f 100644 --- a/htdocs/user/home.php +++ b/htdocs/user/home.php @@ -89,7 +89,7 @@ print '
'; */ $max=10; -$sql = "SELECT u.rowid, u.lastname, u.firstname, u.admin, u.login, u.fk_soc, u.datec, u.statut"; +$sql = "SELECT DISTINCT u.rowid, u.lastname, u.firstname, u.admin, u.login, u.fk_soc, u.datec, u.statut"; $sql.= ", u.entity"; $sql.= ", u.ldap_sid"; $sql.= ", u.photo"; @@ -101,13 +101,25 @@ $sql.= ", s.code_client"; $sql.= ", s.canvas"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_soc = s.rowid"; -if (! empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && ! $user->entity))) -{ - $sql.= " WHERE u.entity IS NOT NULL"; -} -else -{ - $sql.= " WHERE u.entity IN (0,".$conf->entity.")"; +// TODO add hook +if (! empty($conf->multicompany->enabled)) { + if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { + if (! empty($user->admin) && empty($user->entity)) { + if ($conf->entity == 1) { + $sql.= " WHERE u.entity IS NOT NULL"; + } else { + $sql.= " WHERE u.entity IN (".getEntity('user').")"; + } + } else { + $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql.= " WHERE ug.fk_user = u.rowid"; + $sql.= " AND ug.entity IN (".getEntity('user').")"; + } + } else { + $sql.= " WHERE u.entity IN (".getEntity('user').")"; + } +} else { + $sql.= " WHERE u.entity IN (".getEntity('user').")"; } if (!empty($socid)) $sql.= " AND u.fk_soc = ".$socid; $sql.= $db->order("u.datec","DESC"); diff --git a/htdocs/user/index.php b/htdocs/user/index.php index b5edbafa89e..704c04d2593 100644 --- a/htdocs/user/index.php +++ b/htdocs/user/index.php @@ -175,7 +175,7 @@ $user2=new User($db); $buttonviewhierarchy='
'; -$sql = "SELECT u.rowid, u.lastname, u.firstname, u.admin, u.fk_soc, u.login, u.email, u.accountancy_code, u.gender, u.employee, u.photo,"; +$sql = "SELECT DISTINCT u.rowid, u.lastname, u.firstname, u.admin, u.fk_soc, u.login, u.email, u.accountancy_code, u.gender, u.employee, u.photo,"; $sql.= " u.datelastlogin, u.datepreviouslogin,"; $sql.= " u.ldap_sid, u.statut, u.entity,"; $sql.= " u.tms as date_update, u.datec as date_creation,"; @@ -191,12 +191,24 @@ $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user_extrafields as ef on (u.rowid = ef.fk_object)"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_soc = s.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u2 ON u.fk_user = u2.rowid"; -if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) || (! empty($user->admin) && empty($user->entity)))) -{ - $sql.= " WHERE u.entity IS NOT NULL"; -} -else -{ +// TODO add hook +if (! empty($conf->multicompany->enabled)) { + if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { + if (! empty($user->admin) && empty($user->entity)) { + if ($conf->entity == 1) { + $sql.= " WHERE u.entity IS NOT NULL"; + } else { + $sql.= " WHERE u.entity IN (".getEntity('user').")"; + } + } else { + $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql.= " WHERE ug.fk_user = u.rowid"; + $sql.= " AND ug.entity IN (".getEntity('user').")"; + } + } else { + $sql.= " WHERE u.entity IN (".getEntity('user').")"; + } +} else { $sql.= " WHERE u.entity IN (".getEntity('user').")"; } if ($socid > 0) $sql.= " AND u.fk_soc = ".$socid;