From 25055b8603ab31709849a13efb1c9111002d8780 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 31 Oct 2006 07:56:34 +0000 Subject: [PATCH] improved advanced search: - fixed not working paging (lost advanced search) - uses now a named window and gives it focus - disabled for org-views - can be unset via clicking on the addressbook icon (index.php) - last search can always be restored from session --- .../inc/class.contacts_admin_prefs.inc.php | 2 +- addressbook/inc/class.uicontacts.inc.php | 75 +++++++++++-------- addressbook/index.php | 11 ++- addressbook/templates/default/edit.xet | 18 ++--- 4 files changed, 62 insertions(+), 44 deletions(-) diff --git a/addressbook/inc/class.contacts_admin_prefs.inc.php b/addressbook/inc/class.contacts_admin_prefs.inc.php index f0984ae2da..40aabcf0b6 100644 --- a/addressbook/inc/class.contacts_admin_prefs.inc.php +++ b/addressbook/inc/class.contacts_admin_prefs.inc.php @@ -54,7 +54,7 @@ class contacts_admin_prefs array( 'text' => ''.lang('Advanced search').'', 'no_lang' => true, 'link' => false diff --git a/addressbook/inc/class.uicontacts.inc.php b/addressbook/inc/class.uicontacts.inc.php index f6a03d1590..9e0569c118 100644 --- a/addressbook/inc/class.uicontacts.inc.php +++ b/addressbook/inc/class.uicontacts.inc.php @@ -489,6 +489,28 @@ class uicontacts extends bocontacts */ function get_rows(&$query,&$rows,&$readonlys,$id_only=false) { + $old_state = $GLOBALS['egw']->session->appsession('index','addressbook'); + if (isset($this->org_views[(string) $query['org_view']])) // we have an org view, reset the advanced search + { + if (is_array($query['search'])) unset($query['search']); + unset($query['advanced_search']); + } + elseif (is_array($query['search'])) // new advanced search, store it in the session + { + $query['advanced_search'] = array_intersect_key($query['search'],array_flip(array_merge($this->get_contact_columns(),array('operator','meth_select')))); + foreach ($query['advanced_search'] as $key => $value) + { + if(!$value) unset($query['advanced_search'][$key]); + } + $query['start'] = 0; + $query['search'] = ''; + // store the advanced search in the session to call it again + $GLOBALS['egw']->session->appsession('advanced_search','addressbook',$query['advanced_search']); + } + elseif(!$query['search'] && $old_state['advanced_search']) // eg. paging in an advanced search + { + $query['advanced_search'] = $old_state['advanced_search']; + } if (($do_email=$query['do_email']) && $GLOBALS['egw_info']['etemplate']['loop'] && is_object($GLOBALS['egw']->js)) { // remove previous addEmail() calls, otherwise they will be run again $GLOBALS['egw']->js->body['onLoad'] = preg_replace('/addEmail\([^)]+\);/','',$GLOBALS['egw']->js->body['onLoad']); @@ -496,7 +518,6 @@ class uicontacts extends bocontacts //echo "

uicontacts::get_rows(".print_r($query,true).")

\n"; if (!$id_only) { - $old_state = $GLOBALS['egw']->session->appsession('index','addressbook'); // check if accounts are stored in ldap, which does NOT yet support the org-views if ($this->so_accounts && $query['filter'] === '0' && $query['org_view']) { @@ -513,7 +534,6 @@ class uicontacts extends bocontacts { $query['searchletter'] = ''; // reset lettersearch if viewing the contacts of one organisation } - unset($old_state); $GLOBALS['egw']->session->appsession($do_email ? 'email' : 'index','addressbook',$query); // save the state of the index in the user prefs $state = serialize(array( @@ -531,6 +551,8 @@ class uicontacts extends bocontacts $GLOBALS['egw']->preferences->save_repository(false,'user',false); } } + unset($old_state); + if ((string)$query['cat_id'] != '') { $query['col_filter']['cat_id'] = $query['cat_id'] ? $query['cat_id'] : null; @@ -596,25 +618,17 @@ class uicontacts extends bocontacts } $wildcard = '%'; $op = 'OR'; - if (is_array($query['search'])) // Advanced Search + if ($query['advanced_search']) { - $op = $query['search']['operator']; - $wildcard = $query['search']['meth_select']; - $advanced_search = $query['search']; - $query['search'] = array_intersect_key($query['search'],array_flip($this->get_contact_columns())); - foreach ($query['search'] as $key => $value) { - if(!$value) unset($query['search'][$key]); - } - if (empty($query['search'])) { - $query['search'] = ''; - unset($advanced_search); - } + $op = $query['advanced_search']['operator']; + unset($query['advanced_search']['operator']); + $wildcard = $query['advanced_search']['meth_select']; + unset($query['advanced_search']['meth_select']); } - $rows = parent::search($query['search'],$id_only ? array('id','org_name','n_family','n_given','n_fileas') : false, + $rows = parent::search($query['advanced_search'] ? $query['advanced_search'] : $query['search'], + $id_only ? array('id','org_name','n_family','n_given','n_fileas') : false, $order,'',$wildcard,false,$op,array((int)$query['start'],(int) $query['num_rows']),$query['col_filter']); - if( is_array($advanced_search) ) { - $query['search'] = ''; - } + // do we need the custom fields if (!$id_only && $this->prefs['custom_colum'] != 'never' && $rows && $this->customfields) { @@ -749,6 +763,10 @@ class uicontacts extends bocontacts { $GLOBALS['egw_info']['flags']['app_header'] .= ': '.$query['org_view_label']; } + if($query['advanced_search']) + { + $GLOBALS['egw_info']['flags']['app_header'] .= ': '.lang('Advanced search'); + } if ($query['cat_id']) { if (!is_object($GLOBALS['egw']->categories)) @@ -757,19 +775,16 @@ class uicontacts extends bocontacts } $GLOBALS['egw_info']['flags']['app_header'] .= ': '.lang('Category').' '.$GLOBALS['egw']->categories->id2name($query['cat_id']); } - if ($query['searchletter']) + if ($query['searchletter']) { $order = $order == 'org_name' ? lang('company name') : ($order == 'n_given' ? lang('first name') : lang('last name')); $GLOBALS['egw_info']['flags']['app_header'] .= ' - '.lang("%1 starts with '%2'",$order,$query['searchletter']); } - if ($query['search']) + if ($query['search']) { $GLOBALS['egw_info']['flags']['app_header'] .= ' - '.lang("Search for '%1'",$query['search']); } - if(is_array($advanced_search)) { - $GLOBALS['egw_info']['flags']['app_header'] .= ' - '.lang("Advanced search"); - } - return $this->total; + return $this->total; } /** @@ -1295,10 +1310,12 @@ $readonlys['button[vcard]'] = true; } $GLOBALS['egw_info']['flags']['include_xajax'] = true; $GLOBALS['egw_info']['flags']['java_script'] .= $this->js(); + $GLOBALS['egw_info']['flags']['java_script'] .= ""; $GLOBALS['egw_info']['etemplate']['advanced_search'] = true; // initialize etemplate arrays - $content = $sel_options = $readonlys = $preserv = array(); + $sel_options = $readonlys = $preserv = array(); + $content = $GLOBALS['egw']->session->appsession('advanced_search','addressbook'); for($i = -23; $i<=23; $i++) $tz[$i] = ($i > 0 ? '+' : '').$i; $sel_options['tz'] = $tz + array('' => lang('doesn\'t matter')); @@ -1315,11 +1332,6 @@ $readonlys['button[vcard]'] = true; '%' => lang('contains'), false => lang('exact'), ); - - $index_nm = $GLOBALS['egw']->session->appsession($do_email ? 'email' : 'index','addressbook'); - if (array_key_exists('meth_select',$index_nm['search'])) { - $content = $index_nm['search']; - } // configure edit template as search dialog $readonlys['change_photo'] = true; $readonlys['fileas_type'] = true; @@ -1328,7 +1340,8 @@ $readonlys['button[vcard]'] = true; $readonlys['personal|organisation|home|details|links']['links'] = true; $content['hidebuttons'] = true; $content['no_tid'] = true; - + $content['disable_change_org'] = true; + $this->tmpl->read('addressbook.search'); return $this->tmpl->exec('addressbook.uicontacts.search',$content,$sel_options,$readonlys,$preserv,2); } diff --git a/addressbook/index.php b/addressbook/index.php index eba975c305..91f8113c1a 100755 --- a/addressbook/index.php +++ b/addressbook/index.php @@ -19,6 +19,11 @@ )); include('../header.inc.php'); - ExecMethod('addressbook.uicontacts.index'); - - $GLOBALS['egw']->common->egw_footer(); + // check if we have an advanced search and reset it in case + $old_state = $GLOBALS['egw']->session->appsession('index','addressbook'); + if ($old_state['advanced_search']) + { + unset($old_state['advanced_search']); + $GLOBALS['egw']->session->appsession('index','addressbook',$old_state); + } + $GLOBALS['egw']->redirect_link('/index.php','menuaction=addressbook.uicontacts.index'); diff --git a/addressbook/templates/default/edit.xet b/addressbook/templates/default/edit.xet index 41b391a5c3..4fee8eaa49 100644 --- a/addressbook/templates/default/edit.xet +++ b/addressbook/templates/default/edit.xet @@ -58,7 +58,7 @@ - + @@ -83,7 +83,7 @@ - + @@ -128,7 +128,7 @@ - + @@ -177,14 +177,14 @@ - + - + @@ -340,7 +340,7 @@ - + @@ -350,7 +350,7 @@ - + @@ -449,8 +449,8 @@ - - + +