From 715852569b94aaff981239c296131b5b9405af71 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 23 Mar 2018 10:42:36 +0100 Subject: [PATCH 1/4] NEW add printUserListWhere hook --- htdocs/user/class/user.class.php | 13 +++++++++++-- htdocs/user/home.php | 13 +++++++++++-- htdocs/user/index.php | 7 ++++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index f3c8f03329f..a32ec07b648 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2744,7 +2744,11 @@ class User extends CommonObject */ function get_full_tree($deleteafterid=0, $filter='') { - global $conf,$user; + global $conf, $user; + global $hookmanager; + + // Actions hooked (by external module) + $hookmanager->initHooks(array('userdao')); $this->users = array(); @@ -2754,7 +2758,11 @@ 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"; - // TODO add hook + // Add fields from hooks + $parameters=array(); + $reshook=$hookmanager->executeHooks('printUserListWhere',$parameters); // Note that $action and $object may have been modified by hook + $sql.=$hookmanager->resPrint; + /* if (! empty($conf->multicompany->enabled)) { if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { if (! empty($user->admin) && empty($user->entity)) { @@ -2774,6 +2782,7 @@ class User extends CommonObject } else { $sql.= " WHERE u.entity IN (".getEntity('user').")"; } + */ if ($filter) $sql.=" AND ".$filter; dol_syslog(get_class($this)."::get_full_tree get user list", LOG_DEBUG); diff --git a/htdocs/user/home.php b/htdocs/user/home.php index 0a4cb253c0f..d8659a5e93c 100644 --- a/htdocs/user/home.php +++ b/htdocs/user/home.php @@ -46,6 +46,10 @@ if ($user->societe_id > 0) $socid = $user->societe_id; $companystatic = new Societe($db); $fuserstatic = new User($db); +// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array +$contextpage=array('userhome'); +$hookmanager->initHooks($contextpage); + /* * View @@ -101,7 +105,11 @@ $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"; -// TODO add hook +// Add fields from hooks +$parameters=array(); +$reshook=$hookmanager->executeHooks('printUserListWhere',$parameters); // Note that $action and $object may have been modified by hook +$sql.=$hookmanager->resPrint; +/* if (! empty($conf->multicompany->enabled)) { if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { if (! empty($user->admin) && empty($user->entity)) { @@ -121,6 +129,7 @@ if (! empty($conf->multicompany->enabled)) { } else { $sql.= " WHERE u.entity IN (".getEntity('user').")"; } +*/ if (!empty($socid)) $sql.= " AND u.fk_soc = ".$socid; $sql.= $db->order("u.datec","DESC"); $sql.= $db->plimit($max); @@ -225,7 +234,7 @@ if ($canreadperms) $sql = "SELECT g.rowid, g.nom as name, g.note, g.entity, g.datec"; $sql.= " FROM ".MAIN_DB_PREFIX."usergroup as g"; - if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && ! $user->entity))) + if (! empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && ! $user->entity))) { $sql.= " WHERE g.entity IS NOT NULL"; } diff --git a/htdocs/user/index.php b/htdocs/user/index.php index 704c04d2593..4cf5969668e 100644 --- a/htdocs/user/index.php +++ b/htdocs/user/index.php @@ -191,7 +191,11 @@ $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"; -// TODO add hook +// Add fields from hooks +$parameters=array(); +$reshook=$hookmanager->executeHooks('printUserListWhere',$parameters); // Note that $action and $object may have been modified by hook +$sql.=$hookmanager->resPrint; +/* if (! empty($conf->multicompany->enabled)) { if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { if (! empty($user->admin) && empty($user->entity)) { @@ -211,6 +215,7 @@ if (! empty($conf->multicompany->enabled)) { } else { $sql.= " WHERE u.entity IN (".getEntity('user').")"; } +*/ if ($socid > 0) $sql.= " AND u.fk_soc = ".$socid; //if ($search_user != '') $sql.=natural_search(array('u.login', 'u.lastname', 'u.firstname'), $search_user); if ($search_supervisor > 0) $sql.= " AND u.fk_user IN (".$db->escape($search_supervisor).")"; From f330c5ad3263bb16094c9f3dc68a84e5c5517355 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 23 Mar 2018 10:52:10 +0100 Subject: [PATCH 2/4] Fix: better compatibility --- htdocs/user/class/user.class.php | 21 ++------------------- htdocs/user/home.php | 21 ++------------------- htdocs/user/index.php | 21 ++------------------- 3 files changed, 6 insertions(+), 57 deletions(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index a32ec07b648..bf9ff370e11 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2761,28 +2761,11 @@ class User extends CommonObject // Add fields from hooks $parameters=array(); $reshook=$hookmanager->executeHooks('printUserListWhere',$parameters); // Note that $action and $object may have been modified by hook - $sql.=$hookmanager->resPrint; - /* - 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').")"; - } + if ($reshook > 0) { + $sql.=$hookmanager->resPrint; } else { $sql.= " WHERE u.entity IN (".getEntity('user').")"; } - */ if ($filter) $sql.=" AND ".$filter; dol_syslog(get_class($this)."::get_full_tree get user list", LOG_DEBUG); diff --git a/htdocs/user/home.php b/htdocs/user/home.php index d8659a5e93c..ac14f6b0243 100644 --- a/htdocs/user/home.php +++ b/htdocs/user/home.php @@ -108,28 +108,11 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_soc = s.rowid"; // Add fields from hooks $parameters=array(); $reshook=$hookmanager->executeHooks('printUserListWhere',$parameters); // Note that $action and $object may have been modified by hook -$sql.=$hookmanager->resPrint; -/* -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').")"; - } +if ($reshook > 0) { + $sql.=$hookmanager->resPrint; } else { $sql.= " WHERE u.entity IN (".getEntity('user').")"; } -*/ if (!empty($socid)) $sql.= " AND u.fk_soc = ".$socid; $sql.= $db->order("u.datec","DESC"); $sql.= $db->plimit($max); diff --git a/htdocs/user/index.php b/htdocs/user/index.php index 4cf5969668e..4d83903d0aa 100644 --- a/htdocs/user/index.php +++ b/htdocs/user/index.php @@ -194,28 +194,11 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u2 ON u.fk_user = u2.rowid"; // Add fields from hooks $parameters=array(); $reshook=$hookmanager->executeHooks('printUserListWhere',$parameters); // Note that $action and $object may have been modified by hook -$sql.=$hookmanager->resPrint; -/* -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').")"; - } +if ($reshook > 0) { + $sql.=$hookmanager->resPrint; } else { $sql.= " WHERE u.entity IN (".getEntity('user').")"; } -*/ if ($socid > 0) $sql.= " AND u.fk_soc = ".$socid; //if ($search_user != '') $sql.=natural_search(array('u.login', 'u.lastname', 'u.firstname'), $search_user); if ($search_supervisor > 0) $sql.= " AND u.fk_user IN (".$db->escape($search_supervisor).")"; From 2fb0fc39a50b0243db5893f375ae1f97f4409b3e Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 23 Mar 2018 11:07:35 +0100 Subject: [PATCH 3/4] Fix: Parameter must be an array or an object that implements Countable --- htdocs/ticketsup/class/ticketsup.class.php | 6 +++--- htdocs/ticketsup/index.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/ticketsup/class/ticketsup.class.php b/htdocs/ticketsup/class/ticketsup.class.php index e201f1ab5bd..60edf6471ad 100644 --- a/htdocs/ticketsup/class/ticketsup.class.php +++ b/htdocs/ticketsup/class/ticketsup.class.php @@ -1038,7 +1038,7 @@ class Ticketsup extends CommonObject { global $langs; - if (count($this->cache_types_tickets)) { + if (! empty($this->cache_types_tickets) && count($this->cache_types_tickets)) { return 0; } // Cache deja charge @@ -1078,7 +1078,7 @@ class Ticketsup extends CommonObject { global $langs; - if (count($this->cache_category_tickets)) { + if (! empty($this->cache_types_tickets) && count($this->cache_category_tickets)) { return 0; } // Cache deja charge @@ -1118,7 +1118,7 @@ class Ticketsup extends CommonObject { global $langs; - if (count($this->cache_severity_tickets)) { + if (! empty($this->cache_types_tickets) && count($this->cache_severity_tickets)) { return 0; } // Cache deja charge diff --git a/htdocs/ticketsup/index.php b/htdocs/ticketsup/index.php index 8881b8c3ad2..b98a81f204e 100644 --- a/htdocs/ticketsup/index.php +++ b/htdocs/ticketsup/index.php @@ -215,7 +215,7 @@ print '' . $langs->trans("Statistics") . ' ' . img_ print ''; // don't display graph if no series -if (count($dataseries) >1) { +if (! empty($dataseries) && count($dataseries) > 1) { $data = array(); foreach ($dataseries as $key => $value) { $data[] = array($value['label'], $value['data']); From 47ea5a84fee484c3a6ccda0cd9a3f821f30dad3a Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 23 Mar 2018 11:11:14 +0100 Subject: [PATCH 4/4] Fix: wrong var name --- htdocs/ticketsup/class/ticketsup.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/ticketsup/class/ticketsup.class.php b/htdocs/ticketsup/class/ticketsup.class.php index 60edf6471ad..76902714a9e 100644 --- a/htdocs/ticketsup/class/ticketsup.class.php +++ b/htdocs/ticketsup/class/ticketsup.class.php @@ -1078,7 +1078,7 @@ class Ticketsup extends CommonObject { global $langs; - if (! empty($this->cache_types_tickets) && count($this->cache_category_tickets)) { + if (! empty($this->cache_category_ticket) && count($this->cache_category_tickets)) { return 0; } // Cache deja charge @@ -1118,7 +1118,7 @@ class Ticketsup extends CommonObject { global $langs; - if (! empty($this->cache_types_tickets) && count($this->cache_severity_tickets)) { + if (! empty($this->cache_severity_tickets) && count($this->cache_severity_tickets)) { return 0; } // Cache deja charge