forked from extern/egroupware
* addressbook: enable Advanced Search for OrgView
This commit is contained in:
parent
4b23d7bca2
commit
b7304feca0
@ -91,6 +91,9 @@ class addressbook_sql extends so_sql_cf
|
||||
* @var string $param[searchletter] letter the org_name need to start with
|
||||
* @var array $param[col_filter] filter
|
||||
* @var string $param[search] or'ed search pattern
|
||||
* @var array $param[advanced_search] indicator that advanced search is active
|
||||
* @var string $param[op] (operator like AND or OR; will be passed when advanced search is active)
|
||||
* @var string $param[wildcard] (wildcard like % or empty or not set (for no wildcard); will be passed when advanced search is active)
|
||||
* @var int $param[start]
|
||||
* @var int $param[num_rows]
|
||||
* @var string $param[sort] ASC or DESC
|
||||
@ -99,6 +102,12 @@ class addressbook_sql extends so_sql_cf
|
||||
function organisations($param)
|
||||
{
|
||||
$filter = is_array($param['col_filter']) ? $param['col_filter'] : array();
|
||||
$op = 'OR';
|
||||
if (isset($param['op']) && !empty($param['op'])) $op = $param['op'];
|
||||
$advanced_search = false;
|
||||
if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true;
|
||||
$wildcard ='%';
|
||||
if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:'');
|
||||
|
||||
// fix cat_id filter to search in comma-separated multiple cats and return subcats
|
||||
if ((int)$filter['cat_id'])
|
||||
@ -164,7 +173,7 @@ class addressbook_sql extends so_sql_cf
|
||||
'COUNT(DISTINCT egw_addressbook.contact_id) AS org_count',
|
||||
"COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END) AS org_unit_count",
|
||||
"COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END) AS adr_one_locality_count",
|
||||
),'%',false,'OR','UNION',$filter);
|
||||
),$wildcard,false,$op/*'OR'*/,'UNION',$filter);
|
||||
// org by location
|
||||
$append = "GROUP BY org_name,$by ORDER BY org_name $sort,$by $sort";
|
||||
parent::search($param['search'],array('org_name'),$append,array(
|
||||
@ -173,10 +182,10 @@ class addressbook_sql extends so_sql_cf
|
||||
'COUNT(DISTINCT egw_addressbook.contact_id) AS org_count',
|
||||
"COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END) AS org_unit_count",
|
||||
"COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END) AS adr_one_locality_count",
|
||||
),'%',false,'OR','UNION',$filter);
|
||||
),$wildcard,false,$op/*'OR'*/,'UNION',$filter);
|
||||
$append = "ORDER BY org_name $sort,is_main DESC,$by $sort";
|
||||
}
|
||||
$rows = parent::search($param['search'],array('org_name'),$append,$extra,'%',false,'OR',
|
||||
$rows = parent::search($param['search'],array('org_name'),$append,$extra,$wildcard,false,$op/*'OR'*/,
|
||||
array($param['start'],$param['num_rows']),$filter);
|
||||
|
||||
if (!$rows) return false;
|
||||
@ -197,7 +206,7 @@ class addressbook_sql extends so_sql_cf
|
||||
if (count($filter['org_name']))
|
||||
{
|
||||
foreach((array) parent::search($criteria,array('org_name','org_unit','adr_one_locality'),'GROUP BY org_name,org_unit,adr_one_locality',
|
||||
'','%',false,'AND',false,$filter) as $row)
|
||||
'',$wildcard,false,$op/*'AND'*/,false,$filter) as $row)
|
||||
{
|
||||
$org_key = $row['org_name'].($by ? '|||'.$row[$by] : '');
|
||||
if ($orgs[$org_key]['org_unit_count'] == 1)
|
||||
|
@ -853,8 +853,9 @@ class addressbook_ui extends addressbook_bo
|
||||
{
|
||||
//_debug_array(array('Search'=>$query['search'],
|
||||
// 'AdvancedSearch'=>$query['advanced_search']));
|
||||
if (is_array($query['search'])) unset($query['search']);
|
||||
unset($query['advanced_search']);
|
||||
//if (is_array($query['search'])) unset($query['search']);
|
||||
//unset($query['advanced_search']);
|
||||
if(!$query['search'] && $old_state['advanced_search']) $query['advanced_search'] = $old_state['advanced_search'];
|
||||
}
|
||||
elseif(!$query['search'] && $old_state['advanced_search']) // eg. paging in an advanced search
|
||||
{
|
||||
@ -945,8 +946,23 @@ class addressbook_ui extends addressbook_bo
|
||||
$query['sort'] = 'ASC';
|
||||
$query['order'] = 'org_name';
|
||||
}
|
||||
$rows = parent::organisations($query);
|
||||
if ($query['advanced_search'])
|
||||
{
|
||||
$query['op'] = $query['advanced_search']['operator'];
|
||||
unset($query['advanced_search']['operator']);
|
||||
$query['wildcard'] = $query['advanced_search']['meth_select'];
|
||||
unset($query['advanced_search']['meth_select']);
|
||||
$original_search = $query['search'];
|
||||
$query['search'] = $query['advanced_search'];
|
||||
}
|
||||
|
||||
$rows = parent::organisations($query);
|
||||
if ($query['advanced_search'])
|
||||
{
|
||||
$query['search'] = $original_search;
|
||||
unset($query['wildcard']);
|
||||
unset($query['op']);
|
||||
}
|
||||
$GLOBALS['egw_info']['flags']['params']['manual'] = array('page' => 'ManualAddressbookIndexOrga');
|
||||
}
|
||||
else // contacts view
|
||||
@ -1211,7 +1227,7 @@ class addressbook_ui extends addressbook_bo
|
||||
$order = $order == 'n_given' ? lang('first name') : ($order == 'n_family' ? lang('last name') : lang('Organisation'));
|
||||
$GLOBALS['egw_info']['flags']['app_header'] .= ' - '.lang("%1 starts with '%2'",$order,$query['searchletter']);
|
||||
}
|
||||
if ($query['search'])
|
||||
if ($query['search'] && !$query['advanced_search']) // do not add that, if we have advanced search active
|
||||
{
|
||||
$GLOBALS['egw_info']['flags']['app_header'] .= ' - '.lang("Search for '%1'",$query['search']);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user