From c8369f9b3998826dd7fc61bf5f894a3c46c0c203 Mon Sep 17 00:00:00 2001 From: nathangray Date: Wed, 15 Nov 2017 11:29:10 -0700 Subject: [PATCH] Addressbook - fix hide accounts preference did not work for duplicate & organisation views - Added a new preference option to hide only deactivated accounts --- .../inc/class.addressbook_hooks.inc.php | 3 +- addressbook/inc/class.addressbook_ui.inc.php | 7 ++- addressbook/lang/egw_en.lang | 3 ++ api/src/Contacts/Sql.php | 46 ++++++++++++++++--- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/addressbook/inc/class.addressbook_hooks.inc.php b/addressbook/inc/class.addressbook_hooks.inc.php index 786b331342..0d0ce68b95 100644 --- a/addressbook/inc/class.addressbook_hooks.inc.php +++ b/addressbook/inc/class.addressbook_hooks.inc.php @@ -141,7 +141,8 @@ class addressbook_hooks ); } $settings['hide_accounts'] = array( - 'type' => 'check', + 'type' => 'select', + 'values' => array('1' => lang('Hide all accounts'), 'deactivated' => lang('Show active accounts'), '0' => lang('Show all accounts')), 'label' => 'Hide accounts from addressbook', 'name' => 'hide_accounts', 'help' => 'Hides accounts completly from the adressbook.', diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index 655a6d3347..240010c77c 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -1633,10 +1633,15 @@ window.egw_LAB.wait(function() { { unset($query['col_filter']['list']); } - if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) + if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '1') { $query['col_filter']['account_id'] = null; } + else + { + unset($query['col_filter']['account_id']); + } + // all backends allow now at least to use groups as distribution lists $query['no_filter2'] = false; diff --git a/addressbook/lang/egw_en.lang b/addressbook/lang/egw_en.lang index 8c7b16a37f..6b825c9c44 100644 --- a/addressbook/lang/egw_en.lang +++ b/addressbook/lang/egw_en.lang @@ -274,6 +274,7 @@ grant addressbook access common en Grant address book access group %1 addressbook en Group %1 h addressbook en h hide accounts from addressbook addressbook en Hide user accounts +hide all accounts addressbook en Hide all accounts hides accounts completly from the adressbook. addressbook en Hide user accounts completely from the address book. history logging admin en History logging home address addressbook en Home address @@ -441,6 +442,8 @@ set full name and file as field in contacts of all users (either all or only emp set only full name addressbook en Set only full name should the columns photo and home address always be displayed, even if they are empty. addressbook en Are photo and home address always displayed, even if columns are empty. show addressbook en Show +show active accounts addressbook en Show active accounts +show all accounts addressbook en Show all accounts show birthday reminders on main screen addressbook en Birthday reminders show infolog entries for this organisation addressbook en Show InfoLog entries for this organisation show the contacts of this organisation addressbook en Show contacts of this organisation diff --git a/api/src/Contacts/Sql.php b/api/src/Contacts/Sql.php index 0ac5eb0d13..c107e1cd3d 100644 --- a/api/src/Contacts/Sql.php +++ b/api/src/Contacts/Sql.php @@ -32,7 +32,7 @@ class Sql extends Api\Storage /** * join to show only active account (and not already expired ones) */ - const ACCOUNT_ACTIVE_JOIN = ' LEFT JOIN egw_accounts ON egw_addressbook.account_id=egw_accounts.account_id'; + const ACCOUNT_ACTIVE_JOIN = ' LEFT JOIN egw_accounts ON egw_addressbook.account_id=egw_accounts.account_id '; /** * filter to show only active account (and not already expired or deactived ones) * UNIX_TIMESTAMP(NOW()) gets replaced with value of time() in the code! @@ -110,6 +110,7 @@ class Sql extends Api\Storage function organisations($param) { $filter = is_array($param['col_filter']) ? $param['col_filter'] : array(); + $join = ''; $op = 'OR'; if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; $advanced_search = false; @@ -148,6 +149,18 @@ class Sql extends Api\Storage " OR contact_private=0 AND ".$this->table_name.".contact_owner IN (". implode(',',array_keys($this->grants))."))"; } + if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) + { + $join .= self::ACCOUNT_ACTIVE_JOIN; + if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === 'deactivated') + { + $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); + } + else + { + $filter[] = 'egw_accounts.account_id IS NULL'; + } + } } if ($param['searchletter']) { @@ -194,7 +207,7 @@ class Sql extends Api\Storage $append = "ORDER BY org_name $sort,is_main DESC,$by $sort"; } $rows = parent::search($param['search'],array('org_name'),$append,$extra,$wildcard,false,$op/*'OR'*/, - array($param['start'],$param['num_rows']),$filter); + array($param['start'],$param['num_rows']),$filter,$join); if (!$rows) return false; @@ -216,7 +229,7 @@ class Sql extends Api\Storage { foreach((array) parent::search(null, array('org_name','org_unit','adr_one_locality'), 'GROUP BY org_name,org_unit,adr_one_locality', - '',$wildcard,false,$op/*'AND'*/,false,$filter) as $row) + '',$wildcard,false,$op/*'AND'*/,false,$filter,$join) as $row) { $org_key = $row['org_name'].($by ? '|||'.$row[$by] : ''); if ($orgs[$org_key]['org_unit_count'] == 1) @@ -351,7 +364,20 @@ class Sql extends Api\Storage implode('+', $extra) . ' AS match_count' ); $join .= $this->db->column_data_implode(' OR ',$join_fields) . ')'; - + if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) + { + if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === 'deactivated') + { + $join .=' LEFT JOIN egw_accounts AS account_1 ON egw_addressbook.account_id=account_1.account_id '; + $join .=' LEFT JOIN egw_accounts AS account_2 ON egw_addressbook.account_id=account_2.account_id '; + $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'),array(time(),'account_1.account_'),self::ACOUNT_ACTIVE_FILTER); + $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'),array(time(),'account_2.account_'),self::ACOUNT_ACTIVE_FILTER); + } + else + { + $filter[] = 'egw_addressbook.account_id IS NULL and a2.account_id IS NULL'; + } + } $append = " HAVING match_count >= $match_count ORDER BY {$order} $sort, $this->table_name.contact_id"; $columns[] = $this->table_name.'.contact_id AS contact_id'; @@ -526,10 +552,18 @@ class Sql extends Api\Storage } // add join to show only active accounts (only if accounts are shown and in sql and we not already join the accounts table, eg. used by admin) if ((is_array($owner) ? in_array(0, $owner) : !$owner) && substr($this->account_repository,0,3) == 'sql' && - strpos($join,$GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id',$filter)) + strpos($join,$GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id',$filter) && + $GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) { $join .= self::ACCOUNT_ACTIVE_JOIN; - $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); + if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === 'deactivated') + { + $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); + } + else + { + $filter[] = 'egw_accounts.account_id IS NULL'; + } } if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) // search also adds a join for custom fields! {