From 63d80f2fcd21cfd682b4bd1f558eea88d2f7c9f0 Mon Sep 17 00:00:00 2001 From: Miles Lott Date: Sat, 17 Jan 2004 03:21:21 +0000 Subject: [PATCH] Add the search for 1st character of certain fields, showing alphabet at the top. This feature was lost for 2 years(!), so hopefully it works for you. --- addressbook/inc/class.boaddressbook.inc.php | 14 ++- addressbook/inc/class.soaddressbook.inc.php | 6 +- addressbook/inc/class.uiaddressbook.inc.php | 70 +++++++++++++-- addressbook/templates/default/index.tpl | 7 ++ phpgwapi/inc/class.contacts.inc.php | 30 ++++--- phpgwapi/inc/class.contacts_ldap.inc.php | 85 +++++++++++++++--- phpgwapi/inc/class.contacts_sql.inc.php | 96 ++++++++++++++------- phpgwapi/setup/phpgw_en.lang | 1 + 8 files changed, 240 insertions(+), 69 deletions(-) diff --git a/addressbook/inc/class.boaddressbook.inc.php b/addressbook/inc/class.boaddressbook.inc.php index bb134b8239..3a86528050 100644 --- a/addressbook/inc/class.boaddressbook.inc.php +++ b/addressbook/inc/class.boaddressbook.inc.php @@ -84,6 +84,7 @@ /* Might change this to '' at the end---> */ $_start = get_var('start',array('POST','GET')); $_query = get_var('query',array('POST','GET')); + $_cquery = get_var('cquery', array('GET')); $_sort = get_var('sort',array('POST','GET')); $_order = get_var('order',array('POST','GET')); $_filter = get_var('filter',array('POST','GET')); @@ -104,6 +105,13 @@ $this->query = $_query; } + if((empty($_cquery) && !empty($this->cquery)) || !empty($_cquery)) + { + $this->cquery = $_cquery; + } + +// $this->cquery = ((empty($_cquery) && !empty($this->cquery)) || !empty($_cquery)) ? $_cquery : $this->cquery; + if(isset($_POST['fcat_id']) || isset($_POST['fcat_id'])) { $this->cat_id = $_fcat_id; @@ -145,6 +153,7 @@ 'start' => $this->start, 'limit' => $this->limit, 'query' => $this->query, + 'cquery' => $this->cquery, 'sort' => $this->sort, 'order' => $this->order, 'filter' => $this->filter, @@ -228,6 +237,7 @@ $this->start = $data['start']; $this->limit = $data['limit']; $this->query = $data['query']; + $this->cquery = $data['cquery']; $this->sort = $data['sort']; $this->order = $data['order']; $this->filter = $data['filter']; @@ -245,7 +255,7 @@ { if(@is_array($dirty[$i])) { - while(list($name,$value) = @each($dirty[$i])) + foreach($dirty[$i] as $name => $value) { $cleaned[$i][$name] = $GLOBALS['phpgw']->strip_html($dirty[$i][$name]); } @@ -348,7 +358,7 @@ } if(!@$fields['owner']) { - $fields['owner'] = $GLOBALS['phpgw_info']['user']['account_id']; + $fields['owner'] = (int)$GLOBALS['phpgw_info']['user']['account_id']; } if(empty($fields['access'])) { diff --git a/addressbook/inc/class.soaddressbook.inc.php b/addressbook/inc/class.soaddressbook.inc.php index 17633e66cb..5c42a20645 100644 --- a/addressbook/inc/class.soaddressbook.inc.php +++ b/addressbook/inc/class.soaddressbook.inc.php @@ -34,6 +34,8 @@ function read_entries($data) { +// echo 'OK!'; +// _debug_array($data);exit; return $this->contacts->read( $data['start'], $data['limit'], @@ -41,7 +43,9 @@ $data['query'], $data['filter'], $data['sort'], - $data['order'] + $data['order'], + -1, + $data['cquery'] ); } diff --git a/addressbook/inc/class.uiaddressbook.inc.php b/addressbook/inc/class.uiaddressbook.inc.php index 10d3719829..ae79787418 100644 --- a/addressbook/inc/class.uiaddressbook.inc.php +++ b/addressbook/inc/class.uiaddressbook.inc.php @@ -68,6 +68,7 @@ $this->start = $this->bo->start; $this->limit = $this->bo->limit; $this->query = $this->bo->query; + $this->cquery = $this->bo->cquery; $this->sort = $this->bo->sort; $this->order = $this->bo->order; $this->filter = $this->bo->filter; @@ -81,6 +82,7 @@ 'start' => $this->start, 'limit' => $this->limit, 'query' => $this->query, + 'cquery' => $this->cquery, 'sort' => $this->sort, 'order' => $this->order, 'filter' => $this->filter, @@ -97,6 +99,7 @@ 'start' => $this->start, 'limit' => $this->limit, 'query' => $this->query, + 'cquery' => $this->cquery, 'sort' => $this->sort, 'order' => $this->order, 'filter' => $this->filter, @@ -232,6 +235,46 @@ $GLOBALS['phpgw']->template->set_block('addressbook_list_t','row','row'); $GLOBALS['phpgw']->template->set_block('addressbook_list_t','delete_block','delete_block'); $GLOBALS['phpgw']->template->set_block('addressbook_list_t','addressbook_footer','addressbook_footer'); + $GLOBALS['phpgw']->template->set_block('addressbook_list_t','addressbook_alpha','addressbook_alpha'); + + /* Setup query for 1st char of fullname, company, lastname using user lang */ + if(lang('alphabet') == 'alphabet*') + { + $aar = array('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z'); + } + else + { + $aar = explode(',',lang('alphabet')); + } + $aar[] = 'all'; + foreach($aar as $char) + { + if($this->cquery == $char || + ($char == 'all' && !$this->cquery)) + { + $GLOBALS['phpgw']->template->set_var('charbgcolor','#000000'); + $GLOBALS['phpgw']->template->set_var('charcolor','#FFFFFF'); + } + else + { + $GLOBALS['phpgw']->template->set_var('charbgcolor',$GLOBALS['phpgw_info']['theme']['th_bg']); + $GLOBALS['phpgw']->template->set_var('charcolor',$GLOBALS['phpgw_info']['theme']['th_text']); + } + if($char == 'all') + { + $GLOBALS['phpgw']->template->set_var('charlink', + $GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uiaddressbook.index&cquery=') + ); + } + else + { + $GLOBALS['phpgw']->template->set_var('charlink', + $GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uiaddressbook.index&cquery=' . $char) + ); + } + $GLOBALS['phpgw']->template->set_var('char',$char != 'all' ? strtoupper($char) : lang('all')); + $GLOBALS['phpgw']->template->fp('alphalinks','addressbook_alpha',True); + } $custom = $this->fields->read_custom_fields(); $customfields = array(); @@ -402,6 +445,7 @@ 'fields' => $columns_to_display, 'filter' => $qfilter, 'query' => $this->query, + 'cquery' => $this->cquery, 'sort' => $this->sort, 'order' => $this->order )); @@ -641,9 +685,14 @@ unset($fields['referer']); $fields['owner'] = $GLOBALS['phpgw_info']['user']['account_id']; - $this->bo->add_entry($fields); - - $ab_id = $this->bo->get_lastid(); + $ab_id = $this->bo->add_entry($fields); + if(@is_array($ab_id) || !$ab_id) + { + /* Errors encountered during validation */ + $errors = $ab_id; + break; + } +// $ab_id = $this->bo->get_lastid(); Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uiaddressbook.view&ab_id=' . $ab_id . '&referer=' . $referer)); @@ -665,6 +714,11 @@ $this->addressbook_form('','menuaction=addressbook.uiaddressbook.add','Add','',$customfields,$this->cat_id); + $GLOBALS['phpgw']->template->set_var('errors',''); + if(@is_array($errors)) + { + $GLOBALS['phpgw']->template->set_var('errors',implode(',',$errors)); + } $GLOBALS['phpgw']->template->set_var('lang_save',lang('Save')); $GLOBALS['phpgw']->template->set_var('lang_cancel',lang('Cancel')); $GLOBALS['phpgw']->template->set_var('cancel_url',$GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uiaddressbook.index')); @@ -1199,7 +1253,7 @@ . strtolower($cf) . ']"' . ($this->prefs[$cf] ? ' checked' : '') . '>' . str_replace('_',' ',$cf) . '' . "\n"; - + if(!(++$i % 6)) { echo "\n"; @@ -1540,12 +1594,12 @@ $temp_month[$month] = ' selected'; $bday_month = '