From 35703cff99ee56d82ee4d89e3fc86d8fcd470c7d Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 6 Mar 2018 13:23:00 +0100 Subject: [PATCH 1/8] Fix: wrong entity id, already value 1 ! --- htdocs/accountancy/class/bookkeeping.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index b59258f6cd7..83e7bd8ede3 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); @@ -486,7 +486,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(); From 1807bb36e254047b53e1fda168bf1686b1eec02e Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 6 Mar 2018 13:31:13 +0100 Subject: [PATCH 2/8] Fix: missing global $conf --- htdocs/accountancy/class/bookkeeping.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 83e7bd8ede3..16f40139a38 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -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; From d406b289111f57478e19db6dbcc2ea1392e117da Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 6 Mar 2018 19:08:39 +0100 Subject: [PATCH 3/8] Fix: problem to see users with transverse mode --- htdocs/user/class/user.class.php | 16 +++++++++++++--- htdocs/user/home.php | 18 ++++++++++++++---- htdocs/user/index.php | 16 +++++++++++++--- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 6a2a1b774e7..a54869afa18 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2744,13 +2744,23 @@ 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)))) + if (! empty($conf->multicompany->enabled)) { - $sql.= " WHERE u.entity IS NOT NULL"; + if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { + if ($conf->entity == 1 && ! empty($user->admin) && empty($user->entity)) { + $sql.= " WHERE u.entity IS NOT NULL"; + } 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').")"; + $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..fddb31653cf 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,23 @@ $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))) +if (! empty($conf->multicompany->enabled)) { - $sql.= " WHERE u.entity IS NOT NULL"; + if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { + if ($conf->entity == 1 && ! empty($user->admin) && empty($user->entity)) { + $sql.= " WHERE u.entity IS NOT NULL"; + } 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 (0,".$conf->entity.")"; + $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..52c38497cea 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,9 +191,19 @@ $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)))) +if (! empty($conf->multicompany->enabled)) { - $sql.= " WHERE u.entity IS NOT NULL"; + if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { + if ($conf->entity == 1 && ! empty($user->admin) && empty($user->entity)) { + $sql.= " WHERE u.entity IS NOT NULL"; + } 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 { From 175971bfc1bd3a7347cf3337aef88acb5c3d7c1f Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 6 Mar 2018 19:12:18 +0100 Subject: [PATCH 4/8] Fix: syntax error --- htdocs/user/class/user.class.php | 2 +- htdocs/user/home.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index a54869afa18..7cc6e673d37 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2760,7 +2760,7 @@ class User extends CommonObject } else { - $sql.= " WHERE u.entity = IN (".getEntity('user').")"; + $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 fddb31653cf..d2ec0ce4f36 100644 --- a/htdocs/user/home.php +++ b/htdocs/user/home.php @@ -117,7 +117,7 @@ if (! empty($conf->multicompany->enabled)) } else { - $sql.= " WHERE u.entity = IN (".getEntity('user').")"; + $sql.= " WHERE u.entity IN (".getEntity('user').")"; } if (!empty($socid)) $sql.= " AND u.fk_soc = ".$socid; $sql.= $db->order("u.datec","DESC"); From bf4402eb89efdd55dc0d00440350ec06f4debb29 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 6 Mar 2018 19:22:59 +0100 Subject: [PATCH 5/8] Fix: missing superadmin --- htdocs/user/class/user.class.php | 16 +++++++++------- htdocs/user/home.php | 16 +++++++++------- htdocs/user/index.php | 16 +++++++++------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 7cc6e673d37..3af25797113 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2744,11 +2744,15 @@ 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)) - { + // TODO add hook + if (! empty($conf->multicompany->enabled)) { if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { - if ($conf->entity == 1 && ! empty($user->admin) && empty($user->entity)) { - $sql.= " WHERE u.entity IS NOT NULL"; + 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"; @@ -2757,9 +2761,7 @@ class User extends CommonObject } else { $sql.= " WHERE u.entity IN (".getEntity('user').")"; } - } - else - { + } 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 d2ec0ce4f36..0a4cb253c0f 100644 --- a/htdocs/user/home.php +++ b/htdocs/user/home.php @@ -101,11 +101,15 @@ $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)) -{ +// TODO add hook +if (! empty($conf->multicompany->enabled)) { if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { - if ($conf->entity == 1 && ! empty($user->admin) && empty($user->entity)) { - $sql.= " WHERE u.entity IS NOT NULL"; + 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"; @@ -114,9 +118,7 @@ if (! empty($conf->multicompany->enabled)) } else { $sql.= " WHERE u.entity IN (".getEntity('user').")"; } -} -else -{ +} else { $sql.= " WHERE u.entity IN (".getEntity('user').")"; } if (!empty($socid)) $sql.= " AND u.fk_soc = ".$socid; diff --git a/htdocs/user/index.php b/htdocs/user/index.php index 52c38497cea..704c04d2593 100644 --- a/htdocs/user/index.php +++ b/htdocs/user/index.php @@ -191,11 +191,15 @@ $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)) -{ +// TODO add hook +if (! empty($conf->multicompany->enabled)) { if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { - if ($conf->entity == 1 && ! empty($user->admin) && empty($user->entity)) { - $sql.= " WHERE u.entity IS NOT NULL"; + 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"; @@ -204,9 +208,7 @@ if (! empty($conf->multicompany->enabled)) } else { $sql.= " WHERE u.entity IN (".getEntity('user').")"; } -} -else -{ +} else { $sql.= " WHERE u.entity IN (".getEntity('user').")"; } if ($socid > 0) $sql.= " AND u.fk_soc = ".$socid; From 03873038d5706f8ecd84c986c14bfe9b12e23957 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Wed, 7 Mar 2018 08:47:34 +0100 Subject: [PATCH 6/8] fix comment task --- htdocs/core/class/comment.class.php | 33 ++++++++++++++---------- htdocs/core/class/commonobject.class.php | 10 +++++-- htdocs/projet/tasks/comment.php | 6 ++++- 3 files changed, 33 insertions(+), 16 deletions(-) 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/projet/tasks/comment.php b/htdocs/projet/tasks/comment.php index 49072299ac4..de06eef9174 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){ + setEventMessage($object->errors,'errors'); + } + $result=$projectstatic->fetch($object->fk_project); if (! empty($projectstatic->socid)) $projectstatic->fetch_thirdparty(); From 6cb77577a634f2958e52ac3f2161c1789ed09636 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Wed, 7 Mar 2018 09:03:13 +0100 Subject: [PATCH 7/8] can use image --- htdocs/core/tpl/bloc_comment.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ''; From f7f9f0e605d19732bf88da06d637fe3b33e724de Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 7 Mar 2018 12:40:09 +0100 Subject: [PATCH 8/8] Update comment.php --- htdocs/projet/tasks/comment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/projet/tasks/comment.php b/htdocs/projet/tasks/comment.php index de06eef9174..3bf96d7d081 100644 --- a/htdocs/projet/tasks/comment.php +++ b/htdocs/projet/tasks/comment.php @@ -99,7 +99,7 @@ if ($id > 0 || ! empty($ref)) { $result=$object->fetchComments(); if ($result<0){ - setEventMessage($object->errors,'errors'); + setEventMessages($object->error,$object->errors,'errors'); }