Formatting, replace gettype with is_???

This commit is contained in:
Miles Lott 2002-02-08 05:04:33 +00:00
parent 3e2136f1b8
commit 9dcc98b2d5
3 changed files with 356 additions and 308 deletions

View File

@ -170,14 +170,17 @@
/* send this the id and whatever fields you want to see */
function read_single_entry($id,$fields = '')
{
if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; }
if(!$fields || empty($fields))
{
$fields = $this->stock_contact_fields;
}
list($stock_fields,$stock_fieldnames,$extra_fields) =
$this->split_stock_and_extras($fields);
if (count($stock_fieldnames))
if(count($stock_fieldnames))
{
$t_fields = "," . implode(",",$stock_fieldnames);
if ($t_fields == ",")
if($t_fields == ",")
{
unset($t_fields);
}
@ -192,7 +195,7 @@
$return_fields[0]['owner'] = $ldap_fields[0]['phpgwcontactowner'][0];
$return_fields[0]['access'] = $ldap_fields[0]['phpgwcontactaccess'][0];
$return_fields[0]['cat_id'] = $ldap_fields[0]['phpgwcontactcatid'][0];
if (gettype($stock_fieldnames) == 'array')
if(is_array($stock_fieldnames))
{
while(list($name,$value)=each($stock_fieldnames))
{
@ -201,29 +204,29 @@
}
/* Setup address type fields */
if ($return_fields[0]['adr_one_type'])
if($return_fields[0]['adr_one_type'])
{
$one_type = $return_fields[0]['adr_one_type'];
reset($this->adr_types);
while (list($name,$val) = each($this->adr_types))
while(list($name,$val) = each($this->adr_types))
{
eval("if (strstr(\$one_type,\$name)) { \$return_fields[0][\"one_\$name\"] = \"on\"; }");
}
}
if ($return_fields[0]["adr_two_type"])
if($return_fields[0]["adr_two_type"])
{
$two_type = $return_fields[0]['adr_two_type'];
reset($this->adr_types);
while (list($name,$val) = each($this->adr_types))
while(list($name,$val) = each($this->adr_types))
{
eval("if (strstr(\$two_type,\$name)) { \$return_fields[0][\"two_\$name\"] = \"on\"; }");
}
}
$this->db->query("SELECT contact_name,contact_value FROM $this->ext_table WHERE contact_id='" . $id . "'",__LINE__,__FILE__);
while ($this->db->next_record())
while($this->db->next_record())
{
if ($extra_fields[$this->db->f('contact_name')])
if($extra_fields[$this->db->f('contact_name')])
{
$return_fields[0][$this->db->f('contact_name')] = $this->db->f('contact_value');
}
@ -233,21 +236,27 @@
function read_last_entry($fields = '')
{
if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; }
if(!$fields || empty($fields))
{
$fields = $this->stock_contact_fields;
}
list($stock_fields,$stock_fieldnames,$extra_fields) =
$this->split_stock_and_extras($fields);
if (count($stock_fieldnames))
if(count($stock_fieldnames))
{
$t_fields = "," . implode(",",$stock_fieldnames);
if ($t_fields == ",")
if($t_fields == ",")
{
unset($t_fields);
}
}
$id = $this->nextid;
if ($id == -1) { $id = 1; }
if($id == -1)
{
$id = 1;
}
$sri = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_contact_context'], 'uidnumber='.$id);
$ldap_fields = ldap_get_entries($this->ldap, $sri);
@ -259,7 +268,7 @@
$return_fields[0]['access'] = $ldap_fields[0]['phpgwcontactaccess'][0];
$return_fields[0]['cat_id'] = $ldap_fields[0]['phpgwcontactcatid'][0];
if (gettype($stock_fieldnames) == 'array')
if(is_array($stock_fieldnames))
{
while(list($name,$value)=each($stock_fieldnames))
{
@ -268,29 +277,29 @@
}
/* Setup address type fields */
if ($return_fields[0]['adr_one_type'])
if($return_fields[0]['adr_one_type'])
{
$one_type = $return_fields[0]['adr_one_type'];
reset($this->adr_types);
while (list($name,$val) = each($this->adr_types))
while(list($name,$val) = each($this->adr_types))
{
eval("if (strstr(\$one_type,\$name)) { \$return_fields[0][\"one_\$name\"] = \"on\"; }");
}
}
if ($return_fields[0]['adr_two_type'])
if($return_fields[0]['adr_two_type'])
{
$two_type = $return_fields[0]['adr_two_type'];
reset($this->adr_types);
while (list($name,$val) = each($this->adr_types))
while(list($name,$val) = each($this->adr_types))
{
eval("if (strstr(\$two_type,\$name)) { \$return_fields[0][\"two_\$name\"] = \"on\"; }");
}
}
$this->db->query("SELECT contact_name,contact_value FROM $this->ext_table WHERE contact_id='" . $id . "'",__LINE__,__FILE__);
while ($this->db->next_record())
while($this->db->next_record())
{
if ($extra_fields[$this->db->f('contact_name')])
if($extra_fields[$this->db->f('contact_name')])
{
$return_fields[0][$this->db->f('contact_name')] = $this->db->f('contact_value');
}
@ -301,30 +310,42 @@
/* 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='')
{
if(!$start) { $start = 0; }
if(!$limit) { $limit = 0; }
if(!$filter) { $filter = 'tid=n'; }
if(!$start)
{
$start = 0;
}
if(!$limit)
{
$limit = 0;
}
if(!$filter)
{
$filter = 'tid=n';
}
if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; }
if(!$fields || empty($fields))
{
$fields = $this->stock_contact_fields;
}
$DEBUG = 0;
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
$filterfields = array();
/* turn filter's a=b,c=d OR a=b into an array */
if ($filter)
if($filter)
{
if ($DEBUG) { echo 'DEBUG - Inbound filter is: #'.$filter.'#'; }
if($DEBUG) { echo 'DEBUG - Inbound filter is: #'.$filter.'#'; }
$filterarray = split(',',$filter);
if ($filterarray[1])
if($filterarray[1])
{
$i=0;
for ($i=0;$i<count($filterarray);$i++)
for($i=0;$i<count($filterarray);$i++)
{
list($name,$value) = split("=",$filterarray[$i]);
if ($name)
if($name)
{
if ($DEBUG) { echo '<br>DEBUG - Filter strings: #'.$this->non_contact_fields[$name].'# => #'.$value.'#'; }
if($DEBUG) { echo '<br>DEBUG - Filter strings: #'.$this->non_contact_fields[$name].'# => #'.$value.'#'; }
$filterfields[$this->non_contact_fields[$name]] = $value;
}
}
@ -332,7 +353,7 @@
else
{
list($name,$value) = split('=',$filter);
if ($DEBUG)
if($DEBUG)
{
echo '<br>DEBUG - Filter strings: #'.$this->non_contact_fields[$name].'# => #'.$value.'#';
}
@ -342,48 +363,52 @@
else
{
$filterfields += array('phpgwcontacttypeid' => 'n');
if ($DEBUG) { echo "<br>DEBUG - Filter strings: #phpgwcontacttypeid=n#"; }
if($DEBUG) { echo "<br>DEBUG - Filter strings: #phpgwcontacttypeid=n#"; }
}
if (is_array($this->grants))
if(is_array($this->grants))
{
/* this was not listing private entries when show all was selected */
/* $filterfields += array('phpgwcontactaccess' => 'public'); */
$grants = $this->grants;
while (list($user) = each($grants))
while(list($user) = each($grants))
{
if ($DEBUG) { echo '<br>DEBUG - Grant from owner: '.$user; }
if($DEBUG) { echo '<br>DEBUG - Grant from owner: '.$user; }
$filterfields += array('phpgwcontactowner' => $user);
}
}
/*
if ($DEBUG) {
if($DEBUG)
{
while(list($name,$value) = each($filterfields)) {
echo "<br>DEBUG - Filter strings: #".$name.",".$value."#";
}
}
*/
if (!$sort) { $sort = 'ASC'; }
if(!$sort)
{
$sort = 'ASC';
}
if (!$order)
if(!$order)
{
$order = 'n_family';
}
if ($DEBUG && $order)
if($DEBUG && $order)
{
echo "<br>DEBUG - ORDER by $order";
}
if ($query)
if($query)
{
$ldap_fields = array();
$total = 0;
reset($this->stock_contact_fields);
$lquery = '(&(|'; /* $lquery = '(|'; */
while (list($name,$value) = each($this->stock_contact_fields) )
while(list($name,$value) = each($this->stock_contact_fields) )
{
$lquery .= '(' . $value . '=*' . $query . '*)';
}
@ -399,7 +424,7 @@
$total = $total + ldap_count_entries($this->ldap, $sri);
/* _debug_array($ldap_fields);exit; */
if ($filterfields)
if($filterfields)
{
$ldap_fields = $this->filter_ldap($ldap_fields,$filterfields,$DEBUG);
}
@ -413,14 +438,14 @@
$ldap_fields = ldap_get_entries($this->ldap, $sri);
$this->total_records = ldap_count_entries($this->ldap, $sri);
if ($filterfields)
if($filterfields)
{
$ldap_fields = $this->filter_ldap($ldap_fields,$filterfields,$DEBUG);
}
}
/* Use shared sorting routines, based on sort and order */
if ($sort == 'ASC')
if($sort == 'ASC')
{
$ldap_fields = $this->asortbyindex($ldap_fields, $this->stock_contact_fields[$order]);
}
@ -434,11 +459,11 @@
The export feature, for example, does not limit rows.
This way, it can retrieve all rows at once.
*/
if ($start && $limit)
if($start && $limit)
{
$limit = $start + $limit;
}
elseif ($start && !$limit)
elseif($start && !$limit)
{
$limit = $start;
}
@ -455,9 +480,9 @@
@reset($ldap_fields);
$j=0;
for ($i=$start;$i<$limit;$i++)
for($i=$start;$i<$limit;$i++)
{
if ($i<$this->total_records && $ldap_fields[$i]['uid'][0])
if($i<$this->total_records && $ldap_fields[$i]['uid'][0])
{
$return_fields[$j]['id'] = $ldap_fields[$i]['uidnumber'][0];
$return_fields[$j]['lid'] = $ldap_fields[$i]['uid'][0];
@ -466,10 +491,10 @@
$return_fields[$j]['access'] = $ldap_fields[$i]['phpgwcontactaccess'][0];
$return_fields[$j]['cat_id'] = $ldap_fields[$i]['phpgwcontactcatId'][0];
if (gettype($stock_fieldnames) == 'array')
if(is_array($stock_fieldnames))
{
reset($stock_fieldnames);
while (list($f_name,$f_value) = each($stock_fieldnames))
while(list($f_name,$f_value) = each($stock_fieldnames))
{
$return_fields[$j][$f_name] = $ldap_fields[$i][$f_value][0];
}
@ -477,9 +502,9 @@
}
$this->db->query("SELECT contact_name,contact_value FROM $this->ext_table WHERE contact_id='"
. $ldap_fields[$i]['id'] . "'",__LINE__,__FILE__);
while ($this->db->next_record())
while($this->db->next_record())
{
if ($extra_fields[$this->db->f('contact_name')])
if($extra_fields[$this->db->f('contact_name')])
{
$return_fields[$j][$this->db->f('contact_name')] = $this->db->f('contact_value');
}
@ -509,12 +534,12 @@
$free = 0;
$this->nextid = $GLOBALS['phpgw']->common->last_id('contacts');
/* Loop until we find a free id */
while (!$free)
while(!$free)
{
$ldap_fields = '';
$sri = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_contact_context'], 'uidnumber='.$this->nextid);
$ldap_fields = ldap_get_entries($this->ldap, $sri);
if ($ldap_fields[0]['dn'][0])
if($ldap_fields[0]['dn'][0])
{
$this->nextid = $GLOBALS['phpgw']->common->next_id('contacts');
}
@ -525,11 +550,11 @@
}
$ldap_fields = '';
if (gettype($stock_fieldnames) == 'array')
if(is_array($stock_fieldnames))
{
while(list($name,$value)=each($stock_fieldnames))
{
if ($stock_fields[$name] != '')
if($stock_fields[$name] != '')
{
$ldap_fields[$value] = $stock_fields[$name];
}
@ -537,7 +562,7 @@
}
$time = gettimeofday();
$ldap_fields['uid'] = time().$time['usec'].':'.$ldap_fields['givenname'];
$ldap_fields['uid'] = time() . $time['usec'] . ':' . $ldap_fields['givenname'];
$dn = 'uid=' . $ldap_fields['uid'].',' . $GLOBALS['phpgw_info']['server']['ldap_contact_context'];
$ldap_fields['phpgwcontacttypeid'] = $tid;
@ -553,9 +578,9 @@
/* _debug_array($ldap_fields); */
$err = ldap_add($this->ldap, $dn, $ldap_fields);
if (count($extra_fields))
if(count($extra_fields))
{
while (list($name,$value) = each($extra_fields))
while(list($name,$value) = each($extra_fields))
{
$this->db->query("INSERT INTO $this->ext_table VALUES ('".$this->nextid."','" . $this->account_id . "','"
. addslashes($name) . "','" . addslashes($value) . "')",__LINE__,__FILE__);
@ -588,7 +613,7 @@
{
$nonfields = $this->non_contact_fields;
if (!$GLOBALS['phpgw_info']['server']['ldap_contact_context'])
if(!$GLOBALS['phpgw_info']['server']['ldap_contact_context'])
{
return False;
}
@ -597,11 +622,11 @@
$sri = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_contact_context'], 'uidnumber='.$id);
$ldap_fields = ldap_get_entries($this->ldap, $sri);
if ($ldap_fields[0]['dn'])
if($ldap_fields[0]['dn'])
{
$dn = $ldap_fields[0]['dn'];
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
if (gettype($stock_fieldnames) == 'array')
if(is_array($stock_fieldnames))
{
/*
Check each value, add our extra attributes if they are missing, and
@ -609,11 +634,11 @@
*/
/* Verify uidnumber */
$stock_fields['id'] = $id;
if (empty($ldap_fields[0]['uidnumber']))
if(empty($ldap_fields[0]['uidnumber']))
{
$err = ldap_modify($this->ldap,$dn,array('uidnumber' => $stock_fields['uidnumber']));
}
elseif (!$ldap_fields[0]['uidnumber'])
elseif(!$ldap_fields[0]['uidnumber'])
{
$err = ldap_mod_add($this->ldap,$dn,array('uidnumber' => $stock_fields['uidnumber']));
}
@ -621,17 +646,17 @@
/* Verify uid */
$uids = split(',',$dn);
$stock_fields['lid'] = $uids[0];
if (empty($ldap_fields[0]['uid']))
if(empty($ldap_fields[0]['uid']))
{
$err = ldap_modify($this->ldap,$dn,array('uid' => $stock_fields['lid']));
}
elseif (!$ldap_fields[0]['uid'])
elseif(!$ldap_fields[0]['uid'])
{
$err = ldap_mod_add($this->ldap,$dn,array('uid' => $stock_fields['lid']));
}
/* Verify objectclasses are there */
if (empty($ldap_fields[0]['objectclass']))
if(empty($ldap_fields[0]['objectclass']))
{
/* $stock_fields['objectclass'][0] = 'person'; */
$stock_fields['objectclass'][0] = 'organizationalPerson';
@ -639,7 +664,7 @@
$stock_fields['objectclass'][2] = 'phpgwContact';
$err = ldap_modify($this->ldap,$dn,array('objectclass' => $stock_fields['objectclass']));
}
elseif (!$ldap_fields[0]['objectclass'])
elseif(!$ldap_fields[0]['objectclass'])
{
/* $stock_fields['objectclass'][0] = 'person'; */
$stock_fields['objectclass'][0] = 'organizationalPerson';
@ -650,64 +675,64 @@
/* Verify owner */
$stock_fields['owner'] = $owner;
if (empty($ldap_fields[0]['phpgwcontactowner']))
if(empty($ldap_fields[0]['phpgwcontactowner']))
{
$err = ldap_modify($this->ldap,$dn,array('phpgwcontactowner' => $stock_fields['owner']));
}
elseif (!$ldap_fields[0]['phpgwcontactowner'])
elseif(!$ldap_fields[0]['phpgwcontactowner'])
{
$err = ldap_mod_add($this->ldap,$dn,array('phpgwcontactowner' => $stock_fields['owner']));
}
/* Verify access */
$stock_fields['access'] = $access;
if (empty($ldap_fields[0]['phpgwcontactaccess']))
if(empty($ldap_fields[0]['phpgwcontactaccess']))
{
$err = ldap_modify($this->ldap,$dn,array('phpgwcontactaccess' => $stock_fields['access']));
}
elseif (!$ldap_fields[0]['phpgwcontactaccess'])
elseif(!$ldap_fields[0]['phpgwcontactaccess'])
{
$err = ldap_mod_add($this->ldap,$dn,array('phpgwcontactaccess' => $stock_fields['access']));
}
/* Verify cat_id */
$stock_fields['cat_id'] = $cat_id ? $cat_id : ' ';
if (empty($ldap_fields[0]['phpgwcontactcatid']))
if(empty($ldap_fields[0]['phpgwcontactcatid']))
{
$err = ldap_modify($this->ldap,$dn,array('phpgwcontactcatid' => $stock_fields['cat_id']));
}
elseif (!$ldap_fields[0]['phpgwcontactcatid'])
elseif(!$ldap_fields[0]['phpgwcontactcatid'])
{
$err = ldap_mod_add($this->ldap,$dn,array('phpgwcontactcatid' => $stock_fields['cat_id']));
}
/* Verify tid */
$stock_fields['tid'] = $tid;
if (empty($ldap_fields[0]['phpgwcontacttypeid']))
if(empty($ldap_fields[0]['phpgwcontacttypeid']))
{
$err = ldap_modify($this->ldap,$dn,array('phpgwcontacttypeid' => $stock_fields['tid']));
}
elseif (!$ldap_fields[0]['phpgwcontacttypeid'])
elseif(!$ldap_fields[0]['phpgwcontacttypeid'])
{
$err = ldap_mod_add($this->ldap,$dn,array('phpgwcontacttypeid' => $stock_fields['tid']));
}
/* OK, just mod the data already */
$allfields = $stock_fieldnames + $nonfields;
while ( list($fname,$fvalue) = each($allfields) )
while(list($fname,$fvalue) = each($allfields))
{
/* if ($ldap_fields[0][$fvalue]) */
if ($ldap_fields[0][$fvalue] && $stock_fields[$fname] && $ldap_fields[0][$fvalue][0] != $stock_fields[$fname] )
if($ldap_fields[0][$fvalue] && $stock_fields[$fname] && $ldap_fields[0][$fvalue][0] != $stock_fields[$fname] )
{
/* echo "<br>".$fname." => ".$fvalue." was there"; */
$err = ldap_modify($this->ldap,$dn,array($fvalue => $stock_fields[$fname]));
}
elseif (!$ldap_fields[0][$fvalue] && $stock_fields[$fname])
elseif(!$ldap_fields[0][$fvalue] && $stock_fields[$fname])
{
/* echo "<br>".$fname." not there - '".$fvalue."'"; */
$err = ldap_mod_add($this->ldap,$dn,array($fvalue => $stock_fields[$fname]));
}
elseif ($ldap_fields[0][$fvalue] && !$stock_fields[$fname])
elseif($ldap_fields[0][$fvalue] && !$stock_fields[$fname])
{
/*
echo "<br>".$fname." gone... deleting - '".$fvalue."'";
@ -721,11 +746,11 @@
}
}
while (list($x_name,$x_value) = each($extra_fields))
while(list($x_name,$x_value) = each($extra_fields))
{
if ($this->field_exists($id,$x_name))
if($this->field_exists($id,$x_name))
{
if (! $x_value)
if(!$x_value)
{
$this->delete_single_extra_field($id,$x_name);
}
@ -751,7 +776,7 @@
/* Used by admin to change ownership on account delete */
function change_owner($old_owner='',$new_owner='')
{
if (!($new_owner && $old_owner))
if(!($new_owner && $old_owner))
{
return False;
}
@ -760,7 +785,7 @@
$ldap_fields = ldap_get_entries($this->ldap, $sri);
$entry = '';
while (list($null,$entry) = each($ldap_fields))
while(list($null,$entry) = each($ldap_fields))
{
$err = ldap_modify($this->ldap,$dn,array('phpgwcontactowner' => $new_owner));
}
@ -772,7 +797,7 @@
/* This is where the real work of delete() is done, shared class file contains calling function */
function delete_($id)
{
if (!$GLOBALS['phpgw_info']['server']['ldap_contact_context'])
if(!$GLOBALS['phpgw_info']['server']['ldap_contact_context'])
{
return False;
}
@ -780,7 +805,7 @@
$sri = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_contact_context'], 'uidnumber='.$id);
$ldap_fields = ldap_get_entries($this->ldap, $sri);
if ($ldap_fields[0]['dn'])
if($ldap_fields[0]['dn'])
{
$err = ldap_delete($this->ldap,$ldap_fields[0]['dn']);
@ -796,18 +821,18 @@
// This is for the admin script deleteaccount.php
function delete_all($owner=0)
{
if (!$GLOBALS['phpgw_info']['server']['ldap_contact_context'])
if(!$GLOBALS['phpgw_info']['server']['ldap_contact_context'])
{
return False;
}
if ($owner)
if($owner)
{
$sri = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_contact_context'], 'phpgwcontactowner='.$owner);
$ldap_fields = ldap_get_entries($this->ldap, $sri);
$entry = '';
while (list($null,$entry) = each($ldap_fields))
while(list($null,$entry) = each($ldap_fields))
{
$err = ldap_delete($this->ldap,$entry['dn']);
}

View File

@ -29,19 +29,19 @@
{
function check_perms($has, $needed)
{
return (!!($has & $needed) == True);
return(!!($has & $needed) == True);
}
function split_stock_and_extras($fields)
{
while (list($field,$value) = @each($fields))
while(list($field,$value) = @each($fields))
{
/* Depending on how the array was built, this is needed. */
if (gettype($value) == 'integer')
if(is_int($value))
{
$value = $field;
}
if ($this->stock_contact_fields[$field])
if($this->stock_contact_fields[$field])
{
$stock_fields[$field] = $value;
$stock_fieldnames[$field] = $this->stock_contact_fields[$field];
@ -57,7 +57,7 @@
function loop_addslashes($fields)
{
$absf = $this->stock_contact_fields;
while ($t = each($absf))
while($t = each($absf))
{
$ta[] = $this->db->db_addslashes($fields[$t[0]]);
}
@ -68,9 +68,9 @@
/* This will take an array or integer */
function delete($id)
{
if (gettype($id) == 'array')
if(is_array($id))
{
while (list($null,$t_id) = each($id))
while(list($null,$t_id) = each($id))
{
$this->delete_($t_id);
}
@ -83,23 +83,29 @@
function asc_sort($a,$b)
{
echo "<br>A:'".$a."' B:'".$b;
if($a[1]==$b[1]) return 0;
return ($a[1]>$b[1])?1:-1;
echo "<br>A:'" . $a . "' B:'" . $b;
if($a[1] == $b[1])
{
return 0;
}
return ($a[1]>$b[1]) ? 1 : -1;
}
function desc_sort($a,$b)
{
echo "<br>A:'".$a."' B:'".$b;
if($a[1]==$b[1]) return 0;
return ($a[1]<$b[1])?1:-1;
echo "<br>A:'" . $a . "' B:'" . $b;
if($a[1]==$b[1])
{
return 0;
}
return ($a[1]<$b[1]) ? 1 : -1;
}
/*
comesafter ($s1, $s2)
Returns 1 if $s1 comes after $s2 alphabetically, 0 if not.
*/
function comesafter ($s1, $s2)
function comesafter($s1, $s2)
{
/*
We don't want to overstep the bounds of one of the strings and segfault,
@ -107,17 +113,17 @@
*/
$order = 1;
if ( (strlen($s1) == 0) )
if( (strlen($s1) == 0) )
{
return 0;
}
if ( (strlen($s2) == 0) )
if( (strlen($s2) == 0) )
{
return 1;
}
if (strlen ($s1) > strlen ($s2))
if(strlen ($s1) > strlen ($s2))
{
$temp = $s1;
$s1 = $s2;
@ -125,17 +131,22 @@
$order = 0;
}
for ($index = 0; $index < strlen ($s1); $index++)
for($index = 0; $index < strlen ($s1); $index++)
{
/* $s1 comes after $s2 */
if (strtolower($s1[$index]) > strtolower($s2[$index])) { return ($order); }
if(strtolower($s1[$index]) > strtolower($s2[$index]))
{
return ($order);
}
/* $s1 comes before $s2 */
if (strtolower($s1[$index]) < strtolower($s2[$index])) { return (1 - $order); }
if(strtolower($s1[$index]) < strtolower($s2[$index]))
{
return (1 - $order);
}
}
/* Special case in which $s1 is a substring of $s2 */
return ($order);
return($order);
}
/*
@ -146,16 +157,16 @@
* case of a user array this is the username; with the group array it is the group name.
* asortby
*/
function asortbyindex ($sortarray, $index)
function asortbyindex($sortarray, $index)
{
$lastindex = count($sortarray) - 2;
for ($subindex = 0; $subindex < $lastindex; $subindex++)
for($subindex = 0; $subindex < $lastindex; $subindex++)
{
$lastiteration = $lastindex - $subindex;
for ($iteration = 0; $iteration < $lastiteration; $iteration++)
for($iteration = 0; $iteration < $lastiteration; $iteration++)
{
$nextchar = 0;
if ($this->comesafter($sortarray[$iteration][$index], $sortarray[$iteration + 1][$index]))
if($this->comesafter($sortarray[$iteration][$index], $sortarray[$iteration + 1][$index]))
{
$temp = $sortarray[$iteration];
$sortarray[$iteration] = $sortarray[$iteration + 1];
@ -166,16 +177,16 @@
return ($sortarray);
}
function arsortbyindex ($sortarray, $index)
function arsortbyindex($sortarray, $index)
{
$lastindex = count($sortarray) - 1;
for ($subindex = $lastindex; $subindex > 0; $subindex--)
for($subindex = $lastindex; $subindex > 0; $subindex--)
{
$lastiteration = $lastindex - $subindex;
for ($iteration = $lastiteration; $iteration > 0; $iteration--)
for($iteration = $lastiteration; $iteration > 0; $iteration--)
{
$nextchar = 0;
if ($this->comesafter($sortarray[$iteration][$index], $sortarray[$iteration - 1][$index]))
if($this->comesafter($sortarray[$iteration][$index], $sortarray[$iteration - 1][$index]))
{
$temp = $sortarray[$iteration];
$sortarray[$iteration] = $sortarray[$iteration - 1];
@ -186,7 +197,7 @@
return ($sortarray);
}
function filter_ldap ($ldap_fields,$filterfields,$DEBUG=0)
function filter_ldap($ldap_fields,$filterfields,$DEBUG=0)
{
$match = 0;
if($DEBUG) { echo '<br>'; }
@ -194,20 +205,20 @@
{
$yes = True;
if ($ldap_fields[$i]['uidnumber'][0])
if($ldap_fields[$i]['uidnumber'][0])
{
reset($filterfields);
while (list($col,$filt) = each($filterfields))
while(list($col,$filt) = each($filterfields))
{
if ($col == 'phpgwcontactcatid')
if($col == 'phpgwcontactcatid')
{
$colarray = explode(',',$ldap_fields[$i][$col][0]);
if ($colarray[1])
if($colarray[1])
{
while(list($key,$val) = each ($colarray))
{
if($DEBUG) { echo '&nbsp;&nbsp;Testing "'.$col.'" for "'.$val.'"'; }
if ($val == $filt)
if($val == $filt)
{
if($DEBUG) { echo ', and number '.$ldap_fields[$i]['uidnumber'][0].' matched.'.'&nbsp;&nbsp;'; }
$yes &= True;
@ -219,7 +230,7 @@
else
{
if($DEBUG) { echo '&nbsp;&nbsp;Testing "'.$col.'" for "'.$filt.'"'; }
if ($ldap_fields[$i][$col][0] == $filt)
if($ldap_fields[$i][$col][0] == $filt)
{
if($DEBUG) { echo ', and number '.$ldap_fields[$i]['uidnumber'][0].' matched.'.'&nbsp;&nbsp;'; }
$yes &= True;
@ -236,7 +247,7 @@
else
{
if($DEBUG) { echo '&nbsp;&nbsp;Testing "'.$col.'" for "'.$filt.'"'; }
if ($ldap_fields[$i][$col][0] == $filt)
if($ldap_fields[$i][$col][0] == $filt)
{
if($DEBUG) { echo ', and number '.$ldap_fields[$i]['uidnumber'][0].' matched.'.'&nbsp;&nbsp;'; }
$yes &= True;
@ -251,7 +262,7 @@
}
}
if ($yes)
if($yes)
{
if($DEBUG) { echo $ldap_fields[$i]['uidnumber'][0].' matched all!'.'<br>'; }
$new_ldap[] = $ldap_fields[$i];
@ -304,14 +315,14 @@
$address = $this->read_single_entry($id,$fields);
if ($address[0]['title'])
if($address[0]['title'])
{
$title = $address[0]['title'] . '&nbsp;';
}
if ($business)
if($business)
{
if ($address[0]['org_name'])
if($address[0]['org_name'])
{
$company = $address[0]['org_name'];
}
@ -336,12 +347,12 @@
$country = $address[0]['adr_two_countryname'];
}
if (! $country)
if(!$country)
{
$country = $GLOBALS['phpgw_info']['user']['preferences']['common']['country'];
}
if (file_exists(PHPGW_SERVER_ROOT . SEP . 'addressbook' . SEP . 'templates' . SEP .'default' . SEP . 'format_' . strtolower($country) . '.tpl'))
if(file_exists(PHPGW_SERVER_ROOT . SEP . 'addressbook' . SEP . 'templates' . SEP .'default' . SEP . 'format_' . strtolower($country) . '.tpl'))
{
$a = $t->set_file(array('address_format' => 'format_' . strtolower($country) . '.tpl'));
}
@ -350,7 +361,7 @@
$a = $t->set_file(array('address_format' => 'format_us.tpl'));
}
if (!$afont)
if(!$afont)
{
$afont = $GLOBALS['phpgw_info']['theme']['font'];
}
@ -364,7 +375,7 @@
$a .= $t->set_var('zip',$zip);
$a .= $t->set_var('state',$state);
if ($country != $GLOBALS['phpgw_info']['user']['preferences']['common']['country'])
if($country != $GLOBALS['phpgw_info']['user']['preferences']['common']['country'])
{
$countryname = $s->get_full_name($country);
$a .= $t->set_var('country',lang($countryname));
@ -406,14 +417,14 @@
$address = $this->read_single_entry($id,$fields);
if ($address[0]['title'])
if($address[0]['title'])
{
$title = $address[0]['title'] . '&nbsp;';
}
if ($business)
if($business)
{
if ($address[0]['org_name'])
if($address[0]['org_name'])
{
$company = $address[0]['org_name'];
}
@ -442,12 +453,12 @@
$email = $address[0]['email_home'];
}
if (! $country)
if(!$country)
{
$country = $GLOBALS['phpgw_info']['user']['preferences']['common']['country'];
}
if (file_exists(PHPGW_SERVER_ROOT . SEP . 'addressbook' . SEP . 'templates' . SEP .'default' . SEP . 'full_format_' . strtolower($country) . '.tpl'))
if(file_exists(PHPGW_SERVER_ROOT . SEP . 'addressbook' . SEP . 'templates' . SEP .'default' . SEP . 'full_format_' . strtolower($country) . '.tpl'))
{
$a = $t->set_file(array('address_format' => 'full_format_' . strtolower($country) . '.tpl'));
}
@ -456,7 +467,7 @@
$a = $t->set_file(array('address_format' => 'full_format_us.tpl'));
}
if (!$afont)
if(!$afont)
{
$afont = $GLOBALS['phpgw_info']['theme']['font'];
}
@ -478,7 +489,7 @@
$a .= $t->set_var('fax',$address[0]['tel_fax']);
$a .= $t->set_var('url',$address[0]['url']);
if ($country != $GLOBALS['phpgw_info']['user']['preferences']['common']['country'])
if($country != $GLOBALS['phpgw_info']['user']['preferences']['common']['country'])
{
$countryname = $s->get_full_name($country);
$a .= $t->set_var('country',lang($countryname));
@ -513,14 +524,14 @@
$address = $this->read_single_entry($id,$fields);
if ($address[0]['title'])
if($address[0]['title'])
{
$title = $address[0]['title'] . '&nbsp;';
}
if ($business)
if($business)
{
if ($address[0]['org_name'])
if($address[0]['org_name'])
{
$company = $address[0]['org_name'];
}
@ -545,12 +556,12 @@
$country = $address[0]['adr_two_countryname'];
}
if (! $country)
if(!$country)
{
$country = $GLOBALS['phpgw_info']['user']['preferences']['common']['country'];
}
if (file_exists(PHPGW_SERVER_ROOT . SEP . 'addressbook' . SEP . 'templates' . SEP .'default' . SEP . 'line_format_' . strtolower($country) . '.tpl'))
if(file_exists(PHPGW_SERVER_ROOT . SEP . 'addressbook' . SEP . 'templates' . SEP .'default' . SEP . 'line_format_' . strtolower($country) . '.tpl'))
{
$a = $t->set_file(array('address_format' => 'line_format_' . strtolower($country) . '.tpl'));
}
@ -559,7 +570,7 @@
$a = $t->set_file(array('address_format' => 'line_format_us.tpl'));
}
if (!$afont)
if(!$afont)
{
$afont = $GLOBALS['phpgw_info']['theme']['font'];
}
@ -572,7 +583,7 @@
$a .= $t->set_var('zip',$zip);
$a .= $t->set_var('state',$state);
if ($country != $GLOBALS['phpgw_info']['user']['preferences']['common']['country'])
if($country != $GLOBALS['phpgw_info']['user']['preferences']['common']['country'])
{
$countryname = $s->get_full_name($country);
$a .= $t->set_var('country','&nbsp;°&nbsp;' . lang($countryname));

View File

@ -163,14 +163,17 @@
/* send this the id and whatever fields you want to see */
function read_single_entry($id,$fields='')
{
if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; }
if(!$fields || empty($fields))
{
$fields = $this->stock_contact_fields;
}
list($stock_fields,$stock_fieldnames,$extra_fields) =
$this->split_stock_and_extras($fields);
if (count($stock_fieldnames))
if(count($stock_fieldnames))
{
$t_fields = ',' . implode(',',$stock_fieldnames);
if ($t_fields == ',')
if($t_fields == ',')
{
unset($t_fields);
}
@ -186,38 +189,38 @@
$return_fields[0]['access'] = $this->db->f('access');
$return_fields[0]['cat_id'] = $this->db->f('cat_id');
if (gettype($stock_fieldnames) == 'array')
if(is_array($stock_fieldnames))
{
while (list($f_name) = each($stock_fieldnames))
while(list($f_name) = each($stock_fieldnames))
{
$return_fields[0][$f_name] = $this->db->f($f_name);
}
}
/* Setup address type fields for ui forms display */
if ($this->db->f('adr_one_type'))
if($this->db->f('adr_one_type'))
{
$one_type = $this->db->f('adr_one_type');
reset($this->adr_types);
while (list($name,$val) = each($this->adr_types))
while(list($name,$val) = each($this->adr_types))
{
eval("if (strstr(\$one_type,\$name)) { \$return_fields[0][\"one_\$name\"] = \"on\"; }");
}
}
if ($this->db->f('adr_two_type'))
if($this->db->f('adr_two_type'))
{
$two_type = $this->db->f('adr_two_type');
reset($this->adr_types);
while (list($name,$val) = each($this->adr_types))
while(list($name,$val) = each($this->adr_types))
{
eval("if (strstr(\$two_type,\$name)) { \$return_fields[0][\"two_\$name\"] = \"on\"; }");
}
}
$this->db->query("SELECT contact_name,contact_value FROM $this->ext_table where contact_id='" . $this->db->f('id') . "'",__LINE__,__FILE__);
while ($this->db->next_record())
while($this->db->next_record())
{
if ($extra_fields[$this->db->f('contact_name')])
if($extra_fields[$this->db->f('contact_name')])
{
$return_fields[0][$this->db->f('contact_name')] = $this->db->f('contact_value');
}
@ -227,14 +230,17 @@
function read_last_entry($fields='')
{
if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; }
if(!$fields || empty($fields))
{
$fields = $this->stock_contact_fields;
}
list($stock_fields,$stock_fieldnames,$extra_fields) =
$this->split_stock_and_extras($fields);
if (count($stock_fieldnames))
if(count($stock_fieldnames))
{
$t_fields = ',' . implode(',',$stock_fieldnames);
if ($t_fields == ',')
if($t_fields == ',')
{
unset($t_fields);
}
@ -255,38 +261,38 @@
$return_fields[0]['access'] = $this->db->f('access');
$return_fields[0]['cat_id'] = $this->db->f('cat_id');
if (gettype($stock_fieldnames) == 'array')
if(is_array($stock_fieldnames))
{
while (list($f_name) = each($stock_fieldnames))
while(list($f_name) = each($stock_fieldnames))
{
$return_fields[0][$f_name] = $this->db->f($f_name);
}
}
/* Setup address type fields for ui forms display */
if ($this->db->f('adr_one_type'))
if($this->db->f('adr_one_type'))
{
$one_type = $this->db->f('adr_one_type');
reset($this->adr_types);
while (list($name,$val) = each($this->adr_types))
while(list($name,$val) = each($this->adr_types))
{
eval("if (strstr(\$one_type,\$name)) { \$return_fields[0][\"one_\$name\"] = \"on\"; }");
}
}
if ($this->db->f('adr_two_type'))
if($this->db->f('adr_two_type'))
{
$two_type = $this->db->f('adr_two_type');
reset($this->adr_types);
while (list($name,$val) = each($this->adr_types))
while(list($name,$val) = each($this->adr_types))
{
eval("if (strstr(\$two_type,\$name)) { \$return_fields[0][\"two_\$name\"] = \"on\"; }");
}
}
$this->db->query("SELECT contact_name,contact_value FROM $this->ext_table WHERE contact_id='" . $this->db->f('id') . "'",__LINE__,__FILE__);
while ($this->db->next_record())
while($this->db->next_record())
{
if ($extra_fields[$this->db->f('contact_name')])
if($extra_fields[$this->db->f('contact_name')])
{
$return_fields[0][$this->db->f('contact_name')] = $this->db->f('contact_value');
}
@ -301,35 +307,38 @@
if(!$limit) { $limit = 0; }
if(!$filter) { $filter = 'tid=n'; }
if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; }
if(!$fields || empty($fields))
{
$fields = $this->stock_contact_fields;
}
$DEBUG = 0;
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
if (count($stock_fieldnames))
if(count($stock_fieldnames))
{
$t_fields = ',' . implode(',',$stock_fieldnames);
if ($t_fields == ',')
if($t_fields == ',')
{
unset($t_fields);
}
}
/* turn filter's a=b,c=d OR a=b into an array */
if ($filter)
if($filter)
{
$check_stock = $this->stock_contact_fields + $this->non_contact_fields;
if ($DEBUG) { echo 'DEBUG - Inbound filter is: #'.$filter.'#'; }
if($DEBUG) { echo 'DEBUG - Inbound filter is: #'.$filter.'#'; }
$filterarray = split(',',$filter);
if ($filterarray[1])
if($filterarray[1])
{
$i=0;
for ($i=0;$i<count($filterarray);$i++)
for($i=0;$i<count($filterarray);$i++)
{
list($name,$value) = split('=',$filterarray[$i]);
if ($name)
if($name)
{
if ($DEBUG) { echo '<br>DEBUG - Filter intermediate strings 1: #'.$name.'# => #'.$value.'#'; }
if($DEBUG) { echo '<br>DEBUG - Filter intermediate strings 1: #'.$name.'# => #'.$value.'#'; }
$filterfields[$name] = $value;
}
}
@ -337,7 +346,7 @@
else
{
list($name,$value) = split('=',$filter);
if ($DEBUG)
if($DEBUG)
{
echo '<br>DEBUG - Filter intermediate strings 1: #'.$name.'# => #'.$value.'#';
}
@ -347,19 +356,19 @@
/* now check each element of the array and convert into SQL for queries below */
$i=0;
reset($filterfields);
while (list($name,$value) = each($filterfields))
while(list($name,$value) = each($filterfields))
{
if ($DEBUG) { echo '<br>DEBUG - Filter intermediate strings 2: #'.$name.'# => #'.$value.'#'; }
if($DEBUG) { echo '<br>DEBUG - Filter intermediate strings 2: #'.$name.'# => #'.$value.'#'; }
$isstd=0;
if ($name && empty($value))
if($name && empty($value))
{
if ($DEBUG) { echo '<br>DEBUG - filter field "'.$name.'" is empty (NULL)'; }
while (list($fname,$fvalue)=each($check_stock))
if($DEBUG) { echo '<br>DEBUG - filter field "'.$name.'" is empty (NULL)'; }
while(list($fname,$fvalue)=each($check_stock))
{
if ($fvalue==$name)
if($fvalue==$name)
{
$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'; }
break;
}
}
@ -367,17 +376,17 @@
elseif($name && $value)
{
reset($check_stock);
while (list($fname,$fvalue)=each($check_stock))
while(list($fname,$fvalue)=each($check_stock))
{
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 (gettype($value) == "integer")
elseif(is_int($value))
{
$filterlist .= $name."=".$value.";";
$filterlist .= $name.'='.$value.';';
}
else
{
@ -392,12 +401,12 @@
$filterlist = substr($filterlist,0,-1);
$filterlist = ereg_replace(';',' AND ',$filterlist);
if ($DEBUG)
if($DEBUG)
{
echo '<br>DEBUG - Filter output string: #'.$filterlist.'#';
}
if ($filterlist)
if($filterlist)
{
$filtermethod = '('.$filterlist.') ';
$fwhere = ' WHERE '; $fand = ' AND ';
@ -408,7 +417,7 @@
$filtermethod = " AND (tid='n' OR tid is null)";
}
if (!$filtermethod)
if(!$filtermethod)
{
if($this->account_id)
{
@ -431,10 +440,10 @@
}
}
if (is_array($this->grants))
if(is_array($this->grants))
{
$grants = $this->grants;
while (list($user) = each($grants))
while(list($user) = each($grants))
{
$public_user_list[] = $user;
}
@ -447,14 +456,17 @@
$fwhere .= ') '; $fand .= ') ';
}
if ($DEBUG && $filtermethod)
if($DEBUG && $filtermethod)
{
echo '<br>DEBUG - Filtering with: #' . $filtermethod . '#';
}
if (!$sort) { $sort = 'ASC'; }
if(!$sort)
{
$sort = 'ASC';
}
if ($order)
if($order)
{
$ordermethod = "ORDER BY $order $sort ";
}
@ -463,14 +475,14 @@
$ordermethod = "ORDER BY n_family,n_given,email $sort";
}
if ($DEBUG && $ordermethod)
if($DEBUG && $ordermethod)
{
echo "<br>DEBUG - $ordermethod";
}
$filtermethod = '';
if ($query)
if($query)
{
$query = ereg_replace("'",'',$query);
$query = ereg_replace('"','',$query);
@ -489,18 +501,18 @@
$sql = "SELECT id,lid,tid,owner,access,cat_id $t_fields FROM $this->std_table " . $fwhere
. $filtermethod . ' ' . $ordermethod;
}
if ($DEBUG) { echo '<br>' . $sql; }
if($DEBUG) { echo '<br>' . $sql; }
$db2 = $this->db;
$this->db->query($sql,__LINE__,__FILE__);
$this->total_records = $this->db->num_rows();
if ($start && $limit)
if($start && $limit)
{
$this->db->limit_query($sql,$start,__LINE__,__FILE__,$limit);
}
elseif (!$limit)
elseif(!$limit)
{
$this->db->query($sql,__LINE__,__FILE__);
}
@ -510,7 +522,7 @@
}
$i = 0;
while ($this->db->next_record())
while($this->db->next_record())
{
$return_fields[$i]['id'] = $this->db->f('id');
$return_fields[$i]['lid'] = $this->db->f('lid');
@ -519,9 +531,9 @@
$return_fields[$i]['access'] = $this->db->f('access');
$return_fields[$i]['cat_id'] = $this->db->f('cat_id');
if (gettype($stock_fieldnames) == 'array')
if(is_array($stock_fieldnames))
{
while (list($f_name) = each($stock_fieldnames))
while(list($f_name) = each($stock_fieldnames))
{
$return_fields[$i][$f_name] = $this->db->f($f_name);
}
@ -529,9 +541,9 @@
}
$db2->query("SELECT contact_name,contact_value FROM $this->ext_table WHERE contact_id='"
. $this->db->f('id') . "'" .$filterextra,__LINE__,__FILE__);
while ($db2->next_record())
while($db2->next_record())
{
if ($extra_fields[$db2->f('contact_name')])
if($extra_fields[$db2->f('contact_name')])
{
$return_fields[$i][$db2->f('contact_name')] = $db2->f('contact_value');
}
@ -550,7 +562,7 @@
$tid = 'n';
}
if ($fields['lid'])
if($fields['lid'])
{
$lid[0] = 'lid,';
$lid[1] = $fields['lid']."','";
@ -568,9 +580,9 @@
$this->db->next_record();
$id = $this->db->f(0);
if (count($extra_fields))
if(count($extra_fields))
{
while (list($name,$value) = each($extra_fields))
while(list($name,$value) = each($extra_fields))
{
$this->db->query("INSERT INTO $this->ext_table VALUES ('$id','" . $this->account_id . "','"
. $this->db->db_addslashes($name) . "','" . $this->db->db_addslashes($value) . "')",__LINE__,__FILE__);
@ -604,20 +616,20 @@
/* First make sure that id number exists */
$this->db->query("SELECT COUNT(*) FROM $this->std_table WHERE id='$id'",__LINE__,__FILE__);
$this->db->next_record();
if (!$this->db->f(0))
if(!$this->db->f(0))
{
return False;
}
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
if (count($stock_fields))
if(count($stock_fields))
{
while (list($stock_fieldname) = each($stock_fieldnames))
while(list($stock_fieldname) = each($stock_fieldnames))
{
$ta[] = $stock_fieldname . "='" . $this->db->db_addslashes($stock_fields[$stock_fieldname]) . "'";
}
$fields_s = ',' . implode(',',$ta);
if ($field_s == ',')
if($field_s == ',')
{
unset($field_s);
}
@ -625,11 +637,11 @@
. "id='$id'",__LINE__,__FILE__);
}
while (list($x_name,$x_value) = @each($extra_fields))
while(list($x_name,$x_value) = @each($extra_fields))
{
if ($this->field_exists($id,$x_name))
if($this->field_exists($id,$x_name))
{
if (!$x_value)
if(!$x_value)
{
$this->delete_single_extra_field($id,$x_name);
}
@ -650,7 +662,7 @@
/* Used by admin to change ownership on account delete */
function change_owner($old_owner='',$new_owner='')
{
if (!($new_owner && $old_owner))
if(!($new_owner && $old_owner))
{
return False;
}
@ -671,7 +683,7 @@
/* This is for the admin script deleteaccount.php */
function delete_all($owner=0)
{
if ($owner)
if($owner)
{
$this->db->query("DELETE FROM $this->std_table WHERE owner=$owner",__LINE__,__FILE__);
$this->db->query("DELETE FROM $this->ext_table WHERE contact_owner=$owner",__LINE__,__FILE__);