diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index ef579fea64..4fda5a8c89 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -1906,19 +1906,25 @@ class addressbook_ui extends addressbook_bo unset($query['advanced_search']['meth_select']); } + $columsel = $this->prefs['nextmatch-addressbook.index.rows']; + $columselection = $columsel ? explode(',',$columsel) : array(); + $extracols = []; + if (in_array('owner_shared_with', $columselection)) + { + $extracols[] = 'shared_with'; + } + $rows = parent::search($query['advanced_search'] ? $query['advanced_search'] : $query['search'],$id_only, - $order,'',$wildcard,false,$op,array((int)$query['start'],(int) $query['num_rows']),$query['col_filter']); + $order, $extracols, $wildcard,false, $op,[(int)$query['start'], (int)$query['num_rows']], $query['col_filter']); // do we need to read the custom fields, depends on the column is enabled and customfields - $columsel = $this->prefs['nextmatch-addressbook.index.rows']; - $available_distib_lists=$this->get_lists(Acl::READ); - $columselection = $columsel ? explode(',',$columsel) : array(); $ids = $calendar_participants = array(); if (!$id_only && $rows) { $show_custom_fields = (in_array('customfields',$columselection) || $this->config['index_load_cfs']) && $this->customfields; $show_calendar = $this->config['disable_event_column'] != 'True' && in_array('calendar_calendar',$columselection); - $show_distributionlist = in_array('distrib_lists',$columselection) || count($available_distib_lists); + $show_distributionlist = in_array('distrib_lists', $columselection) || + is_array($available_distib_lists) && count($available_distib_lists); if ($show_calendar || $show_custom_fields || $show_distributionlist) { foreach($rows as $val) diff --git a/addressbook/templates/default/index.xet b/addressbook/templates/default/index.xet index 5abe754f7c..3ee795b54b 100644 --- a/addressbook/templates/default/index.xet +++ b/addressbook/templates/default/index.xet @@ -85,7 +85,10 @@ - + + + + @@ -154,7 +157,10 @@ - + + + + diff --git a/api/src/Contacts/Sql.php b/api/src/Contacts/Sql.php index 3509c31004..04f7ae2d03 100644 --- a/api/src/Contacts/Sql.php +++ b/api/src/Contacts/Sql.php @@ -510,7 +510,7 @@ class Sql extends Api\Storage else { // SQL to get all shared contacts to be OR-ed into ACL filter - $shared_sql = 'contact_id IN (SELECT contact_id FROM '.self::SHARED_TABLE.' WHERE '. + $shared_sql = $this->table_name.'.contact_id IN (SELECT contact_id FROM '.self::SHARED_TABLE.' WHERE '. // $filter[tid] === null is used by sync-collection report, in which case we need to return deleted shares, to remove them from devices (array_key_exists('tid', $filter) && !isset($filter['tid']) ? '' : 'shared_deleted IS NULL AND '). $this->db->expression(self::SHARED_TABLE, ['shared_with' => $filter['owner'] ?? array_keys($this->grants)]).')'; @@ -668,6 +668,20 @@ class Sql extends Api\Storage } } } + if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); + if (($key = array_search('shared_with', $extra_cols)) !== false) + { + $extra_cols[$key] = '(SELECT '.$this->db->group_concat('DISTINCT shared_with').' FROM '.self::SHARED_TABLE. + ' WHERE '.self::SHARED_TABLE.'.contact_id='.$this->table_name.'.contact_id) AS shared_with'; + } + if (!empty($filter['shared_with'])) + { + $join .= ' JOIN '.self::SHARED_TABLE.' sw ON '.$this->table_name.'.contact_id=sw.contact_id AND sw.'. + $this->db->expression(self::SHARED_TABLE, ['shared_with' => $filter['shared_with']]). + ' AND sw.shared_deleted IS NULL'; + } + unset($filter['shared_with']); + $rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false!