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.

This commit is contained in:
Miles Lott 2004-01-17 03:21:21 +00:00
parent 65dd2fb78c
commit 63d80f2fcd
8 changed files with 240 additions and 69 deletions

View File

@ -84,6 +84,7 @@
/* Might change this to '' at the end---> */ /* Might change this to '' at the end---> */
$_start = get_var('start',array('POST','GET')); $_start = get_var('start',array('POST','GET'));
$_query = get_var('query',array('POST','GET')); $_query = get_var('query',array('POST','GET'));
$_cquery = get_var('cquery', array('GET'));
$_sort = get_var('sort',array('POST','GET')); $_sort = get_var('sort',array('POST','GET'));
$_order = get_var('order',array('POST','GET')); $_order = get_var('order',array('POST','GET'));
$_filter = get_var('filter',array('POST','GET')); $_filter = get_var('filter',array('POST','GET'));
@ -104,6 +105,13 @@
$this->query = $_query; $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'])) if(isset($_POST['fcat_id']) || isset($_POST['fcat_id']))
{ {
$this->cat_id = $_fcat_id; $this->cat_id = $_fcat_id;
@ -145,6 +153,7 @@
'start' => $this->start, 'start' => $this->start,
'limit' => $this->limit, 'limit' => $this->limit,
'query' => $this->query, 'query' => $this->query,
'cquery' => $this->cquery,
'sort' => $this->sort, 'sort' => $this->sort,
'order' => $this->order, 'order' => $this->order,
'filter' => $this->filter, 'filter' => $this->filter,
@ -228,6 +237,7 @@
$this->start = $data['start']; $this->start = $data['start'];
$this->limit = $data['limit']; $this->limit = $data['limit'];
$this->query = $data['query']; $this->query = $data['query'];
$this->cquery = $data['cquery'];
$this->sort = $data['sort']; $this->sort = $data['sort'];
$this->order = $data['order']; $this->order = $data['order'];
$this->filter = $data['filter']; $this->filter = $data['filter'];
@ -245,7 +255,7 @@
{ {
if(@is_array($dirty[$i])) 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]); $cleaned[$i][$name] = $GLOBALS['phpgw']->strip_html($dirty[$i][$name]);
} }
@ -348,7 +358,7 @@
} }
if(!@$fields['owner']) if(!@$fields['owner'])
{ {
$fields['owner'] = $GLOBALS['phpgw_info']['user']['account_id']; $fields['owner'] = (int)$GLOBALS['phpgw_info']['user']['account_id'];
} }
if(empty($fields['access'])) if(empty($fields['access']))
{ {

View File

@ -34,6 +34,8 @@
function read_entries($data) function read_entries($data)
{ {
// echo 'OK!';
// _debug_array($data);exit;
return $this->contacts->read( return $this->contacts->read(
$data['start'], $data['start'],
$data['limit'], $data['limit'],
@ -41,7 +43,9 @@
$data['query'], $data['query'],
$data['filter'], $data['filter'],
$data['sort'], $data['sort'],
$data['order'] $data['order'],
-1,
$data['cquery']
); );
} }

View File

@ -68,6 +68,7 @@
$this->start = $this->bo->start; $this->start = $this->bo->start;
$this->limit = $this->bo->limit; $this->limit = $this->bo->limit;
$this->query = $this->bo->query; $this->query = $this->bo->query;
$this->cquery = $this->bo->cquery;
$this->sort = $this->bo->sort; $this->sort = $this->bo->sort;
$this->order = $this->bo->order; $this->order = $this->bo->order;
$this->filter = $this->bo->filter; $this->filter = $this->bo->filter;
@ -81,6 +82,7 @@
'start' => $this->start, 'start' => $this->start,
'limit' => $this->limit, 'limit' => $this->limit,
'query' => $this->query, 'query' => $this->query,
'cquery' => $this->cquery,
'sort' => $this->sort, 'sort' => $this->sort,
'order' => $this->order, 'order' => $this->order,
'filter' => $this->filter, 'filter' => $this->filter,
@ -97,6 +99,7 @@
'start' => $this->start, 'start' => $this->start,
'limit' => $this->limit, 'limit' => $this->limit,
'query' => $this->query, 'query' => $this->query,
'cquery' => $this->cquery,
'sort' => $this->sort, 'sort' => $this->sort,
'order' => $this->order, 'order' => $this->order,
'filter' => $this->filter, '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','row','row');
$GLOBALS['phpgw']->template->set_block('addressbook_list_t','delete_block','delete_block'); $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_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(); $custom = $this->fields->read_custom_fields();
$customfields = array(); $customfields = array();
@ -402,6 +445,7 @@
'fields' => $columns_to_display, 'fields' => $columns_to_display,
'filter' => $qfilter, 'filter' => $qfilter,
'query' => $this->query, 'query' => $this->query,
'cquery' => $this->cquery,
'sort' => $this->sort, 'sort' => $this->sort,
'order' => $this->order 'order' => $this->order
)); ));
@ -641,9 +685,14 @@
unset($fields['referer']); unset($fields['referer']);
$fields['owner'] = $GLOBALS['phpgw_info']['user']['account_id']; $fields['owner'] = $GLOBALS['phpgw_info']['user']['account_id'];
$this->bo->add_entry($fields); $ab_id = $this->bo->add_entry($fields);
if(@is_array($ab_id) || !$ab_id)
$ab_id = $this->bo->get_lastid(); {
/* Errors encountered during validation */
$errors = $ab_id;
break;
}
// $ab_id = $this->bo->get_lastid();
Header('Location: ' Header('Location: '
. $GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uiaddressbook.view&ab_id=' . $ab_id . '&referer=' . $referer)); . $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); $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_save',lang('Save'));
$GLOBALS['phpgw']->template->set_var('lang_cancel',lang('Cancel')); $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')); $GLOBALS['phpgw']->template->set_var('cancel_url',$GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uiaddressbook.index'));

View File

@ -22,6 +22,10 @@ function check_all(which)
{lang_showing} {lang_showing}
<br>{searchreturn} <br>{searchreturn}
{search_filter} {search_filter}
<table width="95%" border="1" cellspacing="1" cellpadding="3">
<tr>{alphalinks}
</tr>
</table>
<table width="95%" border="0" cellspacing="1" cellpadding="3"> <table width="95%" border="0" cellspacing="1" cellpadding="3">
<form name="addr_index" action="{action_url}" method="POST"> <form name="addr_index" action="{action_url}" method="POST">
<tr bgcolor="{th_bg}">{cols} <tr bgcolor="{th_bg}">{cols}
@ -65,3 +69,6 @@ function check_all(which)
</table> </table>
</div> </div>
<!-- END addressbook_footer --> <!-- END addressbook_footer -->
<!-- BEGIN addressbook_alpha --><td bgcolor="{charbgcolor}" align="center"><a href="{charlink}"><font color="{charcolor}">{char}</a></font></td>
<!-- END addressbook_alpha -->

View File

@ -116,25 +116,26 @@
@param $order string sort-order DESC=descending, ASC=ascending @param $order string sort-order DESC=descending, ASC=ascending
@param $lastmod integer get only fields modified since, -1=for all @param $lastmod integer get only fields modified since, -1=for all
*/ */
function read($start=0,$limit=0,$fields='',$query='',$filter='',$sort='',$order='', $lastmod=-1) function read($start=0,$limit=0,$fields='',$query='',$filter='',$sort='',$order='', $lastmod=-1,$cquery='')
{ {
if(@is_array($fields)) if(@is_array($fields))
{ {
$fields['owner'] = 'owner'; // we need the owner to set the rights $fields['owner'] = 'owner'; // we need the owner to set the rights
} }
if ($entrys = contacts_::read($start,$limit,$fields,$query,$filter,$sort,$order, $lastmod)) if($entries = contacts_::read($start,$limit,$fields,$query,$filter,$sort,$order,$lastmod,$cquery))
{ {
foreach($entrys as $nr => $entry) foreach($entries as $nr => $entry)
{ {
$entrys[$nr]['rights'] = (int)$this->grants[$entry['owner']]; $entries[$nr]['rights'] = (int)$this->grants[$entry['owner']];
} }
} }
return $entrys; return $entries;
} }
function split_stock_and_extras($fields) function split_stock_and_extras($fields)
{ {
while (list($field,$value) = @each($fields)) settype($fields, 'array');
foreach($fields as $field => $value)
{ {
/* Depending on how the array was built, this is needed. */ /* Depending on how the array was built, this is needed. */
if(@is_int($value)) if(@is_int($value))
@ -157,11 +158,10 @@
function loop_addslashes($fields) function loop_addslashes($fields)
{ {
$absf = $this->stock_contact_fields; $absf = $this->stock_contact_fields;
while ($t = each($absf)) foreach($absf as $t => $nul)
{ {
$ta[] = $this->db->db_addslashes($fields[$t[0]]); $ta[] = $this->db->db_addslashes($fields[$t]);
} }
reset($absf);
return $ta; return $ta;
} }
@ -170,7 +170,7 @@
{ {
if(@is_array($id)) if(@is_array($id))
{ {
while (list($null,$t_id) = each($id)) foreach($id as $nul => $t_id)
{ {
$this->delete_($t_id); $this->delete_($t_id);
} }
@ -184,14 +184,20 @@
function asc_sort($a,$b) function asc_sort($a,$b)
{ {
echo "<br>A:'".$a."' B:'".$b; echo "<br>A:'".$a."' B:'".$b;
if($a[1]==$b[1]) return 0; if($a[1] == $b[1])
{
return 0;
}
return ($a[1]>$b[1])?1:-1; return ($a[1]>$b[1])?1:-1;
} }
function desc_sort($a,$b) function desc_sort($a,$b)
{ {
echo "<br>A:'".$a."' B:'".$b; echo "<br>A:'".$a."' B:'".$b;
if($a[1]==$b[1]) return 0; if($a[1]==$b[1])
{
return 0;
}
return ($a[1]<$b[1])?1:-1; return ($a[1]<$b[1])?1:-1;
} }

View File

@ -299,7 +299,7 @@
} }
/* send this the range, query, sort, order and whatever fields you want to see */ /* send this the range, query, sort, order and whatever fields you want to see */
function read($start=0,$limit=0,$fields='',$query='',$filter='',$sort='',$order='', $lastmod=-1) function read($start=0,$limit=0,$fields='',$query='',$filter='',$sort='',$order='', $lastmod=-1,$cquery='')
{ {
if(!$start) { $start = 0; } if(!$start) { $start = 0; }
if(!$limit) { $limit = 0; } if(!$limit) { $limit = 0; }
@ -394,7 +394,16 @@
$ldap_fields = array(); $ldap_fields = array();
$myfilter = ''; $myfilter = '';
if($query) if($cquery)
{
$search_filter = array(
'fn' => 'cn',
'n_family' => 'sn',
'org_name' => 'o'
);
$myfilter = $this->makefilter($filterfields,$search_filter,"$cquery*",$DEBUG);
}
elseif($query)
{ {
// the old code was searching about all fields // the old code was searching about all fields
// this was very slow // this was very slow
@ -671,21 +680,19 @@
$ldap_fields['objectclass'][2] = 'phpgwContact'; $ldap_fields['objectclass'][2] = 'phpgwContact';
//$ldap_fields['last_mod'] = $GLOBALS['phpgw']->datetime->gmtnow; //$ldap_fields['last_mod'] = $GLOBALS['phpgw']->datetime->gmtnow;
// a hack!! $err = $this->validate($ldap_fields);
// there should be some validate function in this class if(@is_array($err) && @isset($err[0]))
if(empty($ldap_fields['sn']))
{ {
$ldap_fields['sn'] = $ldap_fields['cn']; return $err;
} }
if(empty($ldap_fields['cn']))
{
$ldap_fields['cn'] = $ldap_fields['sn'];
}
// _debug_array($ldap_fields); exit; // _debug_array($ldap_fields); exit;
$err = ldap_add($this->ldap, $dn, $ldap_fields); $err = ldap_add($this->ldap, $dn, $ldap_fields);
if(!$err)
{
return False;
}
if (count($extra_fields)) if(count($extra_fields))
{ {
while (list($name,$value) = each($extra_fields)) while (list($name,$value) = each($extra_fields))
{ {
@ -696,6 +703,58 @@
return $this->nextid; return $this->nextid;
} }
/* LDAP syntaxes require some testing prior to add */
function validate(&$entry)
{
$errors = array();
foreach($entry as $field => $value)
{
if(strstr($field,'phone'))
{
/* Regex for testing valid international phone number entries.
* LDAP may reject bad values here, such as an email address in a phone number.
* This format is somewhat loose, allowing for optional parenthesis, + sign,
* and 0-7 numbers between separators.
*/
$regex = "/^[\s]*[\(]?[\+]?\d{0,7}[\s]?[\(]?[0-9]{0,7}[ ]?[\)]?[-]{0,7}[ ]?[0-9]{0,7}[ ]*[-]{0,7}[ ]*[0-9]{0,7}[ ]*$/x";
if(!preg_match($regex,$value))
{
$errors[] = array($field => $value);
}
}
elseif(strstr($field,'mailtype') || strstr($field,'mailhometype'))
{
/* Check for valid mail type */
if(!@isset($this->email_types[$value]))
{
$errors[] = array($field => $value);
}
}
elseif(strstr($field,'mail'))
{
/* Check for valid email address - TODO - should depend on mail type */
$regex = "/[ |\t|\r|\n]*\"?([^\"]+\"?@[^ <>\t]+\.[^ <>\t][^ <>\t]+)[ |\t|\r|\n]*/x";
if(!preg_match($regex,$value))
{
$errors[] = array($field => $value);
}
}
}
/* Verify sn/cn attrs set */
if(empty($entry['sn']) && !empty($entry['cn']))
{
$entry['sn'] = $entry['cn'];
}
if(empty($entry['cn']) && !empty($entry['sn']))
{
$entry['cn'] = $entry['sn'];
}
$entry['cn'] = $entry['cn'] ? $entry['cn'] : '-';
$entry['sn'] = $entry['sn'] ? $entry['sn'] : '-';
return $errors;
}
function field_exists($id,$field_name) function field_exists($id,$field_name)
{ {
$this->db->query("select count(*) from $this->ext_table where contact_id='$id' and contact_name='" $this->db->query("select count(*) from $this->ext_table where contact_id='$id' and contact_name='"

View File

@ -189,7 +189,8 @@
if(@is_array($stock_fieldnames)) if(@is_array($stock_fieldnames))
{ {
while (list($f_name) = each($stock_fieldnames)) // while (list($f_name) = each($stock_fieldnames))
foreach($stock_fieldnames as $f_name)
{ {
$return_fields[0][$f_name] = $this->db->f($f_name); $return_fields[0][$f_name] = $this->db->f($f_name);
} }
@ -199,8 +200,9 @@
if ($this->db->f('adr_one_type')) if ($this->db->f('adr_one_type'))
{ {
$one_type = $this->db->f('adr_one_type'); $one_type = $this->db->f('adr_one_type');
reset($this->adr_types); // reset($this->adr_types);
while (list($name,$val) = each($this->adr_types)) // while (list($name,$val) = each($this->adr_types))
foreach($this->adr_types as $name => $val)
{ {
eval("if (strstr(\$one_type,\$name)) { \$return_fields[0][\"one_\$name\"] = \"on\"; }"); eval("if (strstr(\$one_type,\$name)) { \$return_fields[0][\"one_\$name\"] = \"on\"; }");
} }
@ -208,8 +210,9 @@
if ($this->db->f('adr_two_type')) if ($this->db->f('adr_two_type'))
{ {
$two_type = $this->db->f('adr_two_type'); $two_type = $this->db->f('adr_two_type');
reset($this->adr_types); // reset($this->adr_types);
while (list($name,$val) = each($this->adr_types)) // while (list($name,$val) = each($this->adr_types))
foreach($this->adr_types as $name => $val)
{ {
eval("if (strstr(\$two_type,\$name)) { \$return_fields[0][\"two_\$name\"] = \"on\"; }"); eval("if (strstr(\$two_type,\$name)) { \$return_fields[0][\"two_\$name\"] = \"on\"; }");
} }
@ -258,7 +261,8 @@
if (@is_array($stock_fieldnames)) if (@is_array($stock_fieldnames))
{ {
while (list($f_name) = each($stock_fieldnames)) // while (list($f_name) = each($stock_fieldnames))
foreach($stock_fieldnames as $f_name)
{ {
$return_fields[0][$f_name] = $this->db->f($f_name); $return_fields[0][$f_name] = $this->db->f($f_name);
} }
@ -268,8 +272,9 @@
if ($this->db->f('adr_one_type')) if ($this->db->f('adr_one_type'))
{ {
$one_type = $this->db->f('adr_one_type'); $one_type = $this->db->f('adr_one_type');
reset($this->adr_types); // reset($this->adr_types);
while (list($name,$val) = each($this->adr_types)) // while (list($name,$val) = each($this->adr_types))
foreach($this->adr_types as $name => $val)
{ {
eval("if (strstr(\$one_type,\$name)) { \$return_fields[0][\"one_\$name\"] = \"on\"; }"); eval("if (strstr(\$one_type,\$name)) { \$return_fields[0][\"one_\$name\"] = \"on\"; }");
} }
@ -277,8 +282,9 @@
if ($this->db->f('adr_two_type')) if ($this->db->f('adr_two_type'))
{ {
$two_type = $this->db->f('adr_two_type'); $two_type = $this->db->f('adr_two_type');
reset($this->adr_types); // reset($this->adr_types);
while (list($name,$val) = each($this->adr_types)) // while (list($name,$val) = each($this->adr_types))
foreach($this->adr_types as $name => $val)
{ {
eval("if (strstr(\$two_type,\$name)) { \$return_fields[0][\"two_\$name\"] = \"on\"; }"); eval("if (strstr(\$two_type,\$name)) { \$return_fields[0][\"two_\$name\"] = \"on\"; }");
} }
@ -296,7 +302,7 @@
} }
/* send this the range, query, sort, order and whatever fields you want to see */ /* send this the range, query, sort, order and whatever fields you want to see */
function read($start=0,$limit=0,$fields='',$query='',$filter='',$sort='',$order='', $lastmod=-1) function read($start=0,$limit=0,$fields='',$query='',$filter='',$sort='',$order='', $lastmod=-1,$cquery='')
{ {
if(!$start) { $start = 0; } if(!$start) { $start = 0; }
if(!$limit) { $limit = 0; } if(!$limit) { $limit = 0; }
@ -346,18 +352,20 @@
} }
/* now check each element of the array and convert into SQL for queries below */ /* now check each element of the array and convert into SQL for queries below */
$i=0; $i = 0;
reset($filterfields); // reset($filterfields);
while (list($name,$value) = each($filterfields)) // while (list($name,$value) = each($filterfields))
foreach($filterfields as $name => $value)
{ {
if ($DEBUG) { echo '<br>DEBUG - Filter intermediate strings 2: #'.$name.'# => #'.$value.'#'; } if ($DEBUG) { echo '<br>DEBUG - Filter intermediate strings 2: #'.$name.'# => #'.$value.'#'; }
$isstd=0; $isstd=0;
if ($name && empty($value)) if ($name && empty($value))
{ {
if ($DEBUG) { echo '<br>DEBUG - filter field "'.$name.'" is empty (NULL)'; } if ($DEBUG) { echo '<br>DEBUG - filter field "'.$name.'" is empty (NULL)'; }
while (list($fname,$fvalue)=each($check_stock)) // while (list($fname,$fvalue)=each($check_stock))
foreach($check_stock as $fname => $fvalue)
{ {
if ($fvalue==$name) if($fvalue == $name)
{ {
$filterlist .= $name.' is NULL,'; $filterlist .= $name.' is NULL,';
if ($DEBUG) { echo '<br>DEBUG - filter field "'.$name.'" is a stock field'; } if ($DEBUG) { echo '<br>DEBUG - filter field "'.$name.'" is a stock field'; }
@ -367,26 +375,27 @@
} }
elseif($name && $value) elseif($name && $value)
{ {
reset($check_stock); // reset($check_stock);
while (list($fname,$fvalue)=each($check_stock)) // while (list($fname,$fvalue)=each($check_stock))
foreach($check_stock as $fname => $fvalue)
{ {
if ($fvalue==$name) if($fvalue == $name)
{ {
if ($name == 'cat_id') if($name == 'cat_id')
{ {
$filterlist .= "(" . $name . " LIKE '%," . $value . ",%' OR " . $name."='".$value."');"; $filterlist .= "(" . $name . " LIKE '%," . $value . ",%' OR " . $name."='".$value."');";
} }
elseif(@is_int($value)) elseif(@is_int($value))
{ {
$filterlist .= $name."=".$value.";"; $filterlist .= $name . '=' . $value . ';';
} }
elseif ($value == "!''") // check for not empty elseif ($value == "!''") // check for not empty
{ {
$filterlist .= $name."!='';"; $filterlist .= $name . "!='';";
} }
else else
{ {
$filterlist .= $name."='".$value."';"; $filterlist .= $name . "='" . $value . "';";
} }
break; break;
} }
@ -439,7 +448,8 @@
if(@is_array($this->grants)) if(@is_array($this->grants))
{ {
$grants = $this->grants; $grants = $this->grants;
while (list($user) = each($grants)) // while (list($user) = each($grants))
foreach($grants as $user)
{ {
$public_user_list[] = $user; $public_user_list[] = $user;
} }
@ -477,7 +487,7 @@
{ {
$fwhere .= " AND last_mod > $lastmod "; $fwhere .= " AND last_mod > $lastmod ";
} }
else if($lastmod >= 0) elseif($lastmod >= 0)
{ {
$fwhere = " WHERE last_mod > $lastmod "; $fwhere = " WHERE last_mod > $lastmod ";
} }
@ -489,15 +499,32 @@
$filtermethod = ''; $filtermethod = '';
if($query) if($cquery)
{
$cfields = array(
'fn' => 'cn',
'n_family' => 'sn',
'org_name' => 'o'
);
$sql = 'SELECT * FROM ' . $this->std_table . ' WHERE (';
$sqlcount = 'SELECT COUNT(id) FROM ' . $this->std_table . ' WHERE (';
while(list($f,$x) = each($cfields))
{
$sql .= " UPPER($f) LIKE UPPER('$cquery%') OR ";
$sqlcount .= " UPPER($f) LIKE UPPER('$cquery%') OR ";
}
$sql = substr($sql,0,-3) . ') ' . $fand . $filtermethod . $ordermethod;
$sqlcount = substr($sqlcount,0,-3) . ') ' . $fand . $filtermethod;
unset($f); unset($x);
}
elseif($query)
{ {
$query = str_replace("'",'',$query); $query = str_replace("'",'',$query);
$query = str_replace('"','',$query); $query = str_replace('"','',$query);
$sql = "SELECT * FROM $this->std_table WHERE ("; $sql = "SELECT * FROM $this->std_table WHERE (";
$sqlcount = "SELECT COUNT(id) FROM $this->std_table WHERE ("; $sqlcount = "SELECT COUNT(id) FROM $this->std_table WHERE (";
reset($this->stock_contact_fields); foreach($this->stock_contact_fields as $f => $x)
while(list($f,$x) = each($this->stock_contact_fields))
{ {
$sql .= " UPPER($f) LIKE UPPER('%$query%') OR "; $sql .= " UPPER($f) LIKE UPPER('%$query%') OR ";
$sqlcount .= " UPPER($f) LIKE UPPER('%$query%') OR "; $sqlcount .= " UPPER($f) LIKE UPPER('%$query%') OR ";
@ -561,7 +588,8 @@
if(@is_array($stock_fieldnames)) if(@is_array($stock_fieldnames))
{ {
while(list($f_name) = each($stock_fieldnames)) // while(list($f_name) = each($stock_fieldnames))
foreach($stock_fieldnames as $f_name)
{ {
$return_fields[$i][$f_name] = $this->db->f($f_name); $return_fields[$i][$f_name] = $this->db->f($f_name);
} }
@ -618,15 +646,16 @@
$id = $this->db->get_last_insert_id($this->std_table, 'id'); $id = $this->db->get_last_insert_id($this->std_table, 'id');
if (count($extra_fields)) if(count($extra_fields))
{ {
while (list($name,$value) = each($extra_fields)) // while (list($name,$value) = each($extra_fields))
foreach($extra_fields as $name => $value)
{ {
$this->db->query("INSERT INTO $this->ext_table VALUES ('$id','" . $owner . "','" $this->db->query("INSERT INTO $this->ext_table VALUES ('$id','" . $owner . "','"
. $this->db->db_addslashes($name) . "','" . $this->db->db_addslashes($value) . "')",__LINE__,__FILE__); . $this->db->db_addslashes($name) . "','" . $this->db->db_addslashes($value) . "')",__LINE__,__FILE__);
} }
} }
return $id; return ($id ? $id : False);
} }
function field_exists($id,$field_name) function field_exists($id,$field_name)
@ -690,7 +719,8 @@
$this->db->query($sql="UPDATE $this->std_table SET $fields_s WHERE " $this->db->query($sql="UPDATE $this->std_table SET $fields_s WHERE "
. "id=$id",__LINE__,__FILE__); . "id=$id",__LINE__,__FILE__);
} }
while (list($x_name,$x_value) = @each($extra_fields)) // while (list($x_name,$x_value) = @each($extra_fields))
foreach($extra_fields as $x_name => $x_value)
{ {
if ($this->field_exists($id,$x_name)) if ($this->field_exists($id,$x_name))
{ {

View File

@ -34,6 +34,7 @@ afghanistan common en AFGHANISTAN
albania common en ALBANIA albania common en ALBANIA
algeria common en ALGERIA algeria common en ALGERIA
all common en All all common en All
alphabet common en 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
american samoa common en AMERICAN SAMOA american samoa common en AMERICAN SAMOA
andorra common en ANDORRA andorra common en ANDORRA
angola common en ANGOLA angola common en ANGOLA