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

View File

@ -29,19 +29,19 @@
{ {
function check_perms($has, $needed) function check_perms($has, $needed)
{ {
return (!!($has & $needed) == True); return(!!($has & $needed) == True);
} }
function split_stock_and_extras($fields) 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. */ /* Depending on how the array was built, this is needed. */
if (gettype($value) == 'integer') if(is_int($value))
{ {
$value = $field; $value = $field;
} }
if ($this->stock_contact_fields[$field]) if($this->stock_contact_fields[$field])
{ {
$stock_fields[$field] = $value; $stock_fields[$field] = $value;
$stock_fieldnames[$field] = $this->stock_contact_fields[$field]; $stock_fieldnames[$field] = $this->stock_contact_fields[$field];
@ -57,7 +57,7 @@
function loop_addslashes($fields) function loop_addslashes($fields)
{ {
$absf = $this->stock_contact_fields; $absf = $this->stock_contact_fields;
while ($t = each($absf)) while($t = each($absf))
{ {
$ta[] = $this->db->db_addslashes($fields[$t[0]]); $ta[] = $this->db->db_addslashes($fields[$t[0]]);
} }
@ -68,9 +68,9 @@
/* This will take an array or integer */ /* This will take an array or integer */
function delete($id) 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); $this->delete_($t_id);
} }
@ -83,23 +83,29 @@
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 ($a[1]>$b[1])?1:-1; {
return 0;
}
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 ($a[1]<$b[1])?1:-1; {
return 0;
}
return ($a[1]<$b[1]) ? 1 : -1;
} }
/* /*
comesafter ($s1, $s2) comesafter ($s1, $s2)
Returns 1 if $s1 comes after $s2 alphabetically, 0 if not. 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, We don't want to overstep the bounds of one of the strings and segfault,
@ -107,17 +113,17 @@
*/ */
$order = 1; $order = 1;
if ( (strlen($s1) == 0) ) if( (strlen($s1) == 0) )
{ {
return 0; return 0;
} }
if ( (strlen($s2) == 0) ) if( (strlen($s2) == 0) )
{ {
return 1; return 1;
} }
if (strlen ($s1) > strlen ($s2)) if(strlen ($s1) > strlen ($s2))
{ {
$temp = $s1; $temp = $s1;
$s1 = $s2; $s1 = $s2;
@ -125,17 +131,22 @@
$order = 0; $order = 0;
} }
for ($index = 0; $index < strlen ($s1); $index++) for($index = 0; $index < strlen ($s1); $index++)
{ {
/* $s1 comes after $s2 */ /* $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 */ /* $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 */ /* 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. * case of a user array this is the username; with the group array it is the group name.
* asortby * asortby
*/ */
function asortbyindex ($sortarray, $index) function asortbyindex($sortarray, $index)
{ {
$lastindex = count($sortarray) - 2; $lastindex = count($sortarray) - 2;
for ($subindex = 0; $subindex < $lastindex; $subindex++) for($subindex = 0; $subindex < $lastindex; $subindex++)
{ {
$lastiteration = $lastindex - $subindex; $lastiteration = $lastindex - $subindex;
for ($iteration = 0; $iteration < $lastiteration; $iteration++) for($iteration = 0; $iteration < $lastiteration; $iteration++)
{ {
$nextchar = 0; $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]; $temp = $sortarray[$iteration];
$sortarray[$iteration] = $sortarray[$iteration + 1]; $sortarray[$iteration] = $sortarray[$iteration + 1];
@ -166,16 +177,16 @@
return ($sortarray); return ($sortarray);
} }
function arsortbyindex ($sortarray, $index) function arsortbyindex($sortarray, $index)
{ {
$lastindex = count($sortarray) - 1; $lastindex = count($sortarray) - 1;
for ($subindex = $lastindex; $subindex > 0; $subindex--) for($subindex = $lastindex; $subindex > 0; $subindex--)
{ {
$lastiteration = $lastindex - $subindex; $lastiteration = $lastindex - $subindex;
for ($iteration = $lastiteration; $iteration > 0; $iteration--) for($iteration = $lastiteration; $iteration > 0; $iteration--)
{ {
$nextchar = 0; $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]; $temp = $sortarray[$iteration];
$sortarray[$iteration] = $sortarray[$iteration - 1]; $sortarray[$iteration] = $sortarray[$iteration - 1];
@ -186,7 +197,7 @@
return ($sortarray); return ($sortarray);
} }
function filter_ldap ($ldap_fields,$filterfields,$DEBUG=0) function filter_ldap($ldap_fields,$filterfields,$DEBUG=0)
{ {
$match = 0; $match = 0;
if($DEBUG) { echo '<br>'; } if($DEBUG) { echo '<br>'; }
@ -194,20 +205,20 @@
{ {
$yes = True; $yes = True;
if ($ldap_fields[$i]['uidnumber'][0]) if($ldap_fields[$i]['uidnumber'][0])
{ {
reset($filterfields); 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]); $colarray = explode(',',$ldap_fields[$i][$col][0]);
if ($colarray[1]) if($colarray[1])
{ {
while(list($key,$val) = each ($colarray)) while(list($key,$val) = each ($colarray))
{ {
if($DEBUG) { echo '&nbsp;&nbsp;Testing "'.$col.'" for "'.$val.'"'; } 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;'; } if($DEBUG) { echo ', and number '.$ldap_fields[$i]['uidnumber'][0].' matched.'.'&nbsp;&nbsp;'; }
$yes &= True; $yes &= True;
@ -219,7 +230,7 @@
else else
{ {
if($DEBUG) { echo '&nbsp;&nbsp;Testing "'.$col.'" for "'.$filt.'"'; } 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;'; } if($DEBUG) { echo ', and number '.$ldap_fields[$i]['uidnumber'][0].' matched.'.'&nbsp;&nbsp;'; }
$yes &= True; $yes &= True;
@ -230,13 +241,13 @@
if($DEBUG) { echo ', but number '.$ldap_fields[$i]['uidnumber'][0].' did not match.'.'&nbsp;&nbsp;'; } if($DEBUG) { echo ', but number '.$ldap_fields[$i]['uidnumber'][0].' did not match.'.'&nbsp;&nbsp;'; }
$yes &= False; $yes &= False;
$match--; $match--;
} }
} }
} }
else else
{ {
if($DEBUG) { echo '&nbsp;&nbsp;Testing "'.$col.'" for "'.$filt.'"'; } 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;'; } if($DEBUG) { echo ', and number '.$ldap_fields[$i]['uidnumber'][0].' matched.'.'&nbsp;&nbsp;'; }
$yes &= True; $yes &= True;
@ -251,7 +262,7 @@
} }
} }
if ($yes) if($yes)
{ {
if($DEBUG) { echo $ldap_fields[$i]['uidnumber'][0].' matched all!'.'<br>'; } if($DEBUG) { echo $ldap_fields[$i]['uidnumber'][0].' matched all!'.'<br>'; }
$new_ldap[] = $ldap_fields[$i]; $new_ldap[] = $ldap_fields[$i];
@ -285,33 +296,33 @@
$fields = array $fields = array
( (
'n_given' => 'n_given', 'n_given' => 'n_given',
'n_family' => 'n_family', 'n_family' => 'n_family',
'title' => 'title', 'title' => 'title',
'org_name' => 'org_name', 'org_name' => 'org_name',
'org_unit' => 'org_unit', 'org_unit' => 'org_unit',
'adr_one_street' => 'adr_one_street', 'adr_one_street' => 'adr_one_street',
'adr_one_locality' => 'adr_one_locality', 'adr_one_locality' => 'adr_one_locality',
'adr_one_postalcode' => 'adr_one_postalcode', 'adr_one_postalcode' => 'adr_one_postalcode',
'adr_one_region' => 'adr_one_region', 'adr_one_region' => 'adr_one_region',
'adr_one_countryname' => 'adr_one_countryname', 'adr_one_countryname' => 'adr_one_countryname',
'adr_two_street' => 'adr_two_street', 'adr_two_street' => 'adr_two_street',
'adr_two_locality' => 'adr_two_locality', 'adr_two_locality' => 'adr_two_locality',
'adr_two_postalcode' => 'adr_two_postalcode', 'adr_two_postalcode' => 'adr_two_postalcode',
'adr_two_region' => 'adr_two_region', 'adr_two_region' => 'adr_two_region',
'adr_two_countryname' => 'adr_two_countryname' 'adr_two_countryname' => 'adr_two_countryname'
); );
$address = $this->read_single_entry($id,$fields); $address = $this->read_single_entry($id,$fields);
if ($address[0]['title']) if($address[0]['title'])
{ {
$title = $address[0]['title'] . '&nbsp;'; $title = $address[0]['title'] . '&nbsp;';
} }
if ($business) if($business)
{ {
if ($address[0]['org_name']) if($address[0]['org_name'])
{ {
$company = $address[0]['org_name']; $company = $address[0]['org_name'];
} }
@ -336,12 +347,12 @@
$country = $address[0]['adr_two_countryname']; $country = $address[0]['adr_two_countryname'];
} }
if (! $country) if(!$country)
{ {
$country = $GLOBALS['phpgw_info']['user']['preferences']['common']['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')); $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')); $a = $t->set_file(array('address_format' => 'format_us.tpl'));
} }
if (!$afont) if(!$afont)
{ {
$afont = $GLOBALS['phpgw_info']['theme']['font']; $afont = $GLOBALS['phpgw_info']['theme']['font'];
} }
@ -364,7 +375,7 @@
$a .= $t->set_var('zip',$zip); $a .= $t->set_var('zip',$zip);
$a .= $t->set_var('state',$state); $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); $countryname = $s->get_full_name($country);
$a .= $t->set_var('country',lang($countryname)); $a .= $t->set_var('country',lang($countryname));
@ -381,39 +392,39 @@
$fields = array $fields = array
( (
'n_given' => 'n_given', 'n_given' => 'n_given',
'n_family' => 'n_family', 'n_family' => 'n_family',
'title' => 'title', 'title' => 'title',
'org_name' => 'org_name', 'org_name' => 'org_name',
'org_unit' => 'org_unit', 'org_unit' => 'org_unit',
'adr_one_street' => 'adr_one_street', 'adr_one_street' => 'adr_one_street',
'adr_one_locality' => 'adr_one_locality', 'adr_one_locality' => 'adr_one_locality',
'adr_one_postalcode' => 'adr_one_postalcode', 'adr_one_postalcode' => 'adr_one_postalcode',
'adr_one_region' => 'adr_one_region', 'adr_one_region' => 'adr_one_region',
'tel_work' => 'tel_work', 'tel_work' => 'tel_work',
'tel_fax' => 'tel_fax', 'tel_fax' => 'tel_fax',
'email' => 'email', 'email' => 'email',
'url' => 'url', 'url' => 'url',
'adr_one_countryname' => 'adr_one_countryname', 'adr_one_countryname' => 'adr_one_countryname',
'adr_two_street' => 'adr_two_street', 'adr_two_street' => 'adr_two_street',
'adr_two_locality' => 'adr_two_locality', 'adr_two_locality' => 'adr_two_locality',
'adr_two_postalcode' => 'adr_two_postalcode', 'adr_two_postalcode' => 'adr_two_postalcode',
'adr_two_region' => 'adr_two_region', 'adr_two_region' => 'adr_two_region',
'adr_two_countryname' => 'adr_two_countryname', 'adr_two_countryname' => 'adr_two_countryname',
'tel_home' => 'tel_home', 'tel_home' => 'tel_home',
'email_home' => 'email_home' 'email_home' => 'email_home'
); );
$address = $this->read_single_entry($id,$fields); $address = $this->read_single_entry($id,$fields);
if ($address[0]['title']) if($address[0]['title'])
{ {
$title = $address[0]['title'] . '&nbsp;'; $title = $address[0]['title'] . '&nbsp;';
} }
if ($business) if($business)
{ {
if ($address[0]['org_name']) if($address[0]['org_name'])
{ {
$company = $address[0]['org_name']; $company = $address[0]['org_name'];
} }
@ -422,32 +433,32 @@
$company = $title . $address[0]['n_given'] . '&nbsp;' . $address[0]['n_family']; $company = $title . $address[0]['n_given'] . '&nbsp;' . $address[0]['n_family'];
} }
$street = $address[0]['adr_one_street']; $street = $address[0]['adr_one_street'];
$city = $address[0]['adr_one_locality']; $city = $address[0]['adr_one_locality'];
$zip = $address[0]['adr_one_postalcode']; $zip = $address[0]['adr_one_postalcode'];
$state = $address[0]['adr_one_region']; $state = $address[0]['adr_one_region'];
$country = $address[0]['adr_one_countryname']; $country = $address[0]['adr_one_countryname'];
$tel = $address[0]['tel_work']; $tel = $address[0]['tel_work'];
$email = $address[0]['email']; $email = $address[0]['email'];
} }
else else
{ {
$company = $title . $address[0]['n_given'] . '&nbsp;' . $address[0]['n_family']; $company = $title . $address[0]['n_given'] . '&nbsp;' . $address[0]['n_family'];
$street = $address[0]['adr_two_street']; $street = $address[0]['adr_two_street'];
$city = $address[0]['adr_two_locality']; $city = $address[0]['adr_two_locality'];
$zip = $address[0]['adr_two_postalcode']; $zip = $address[0]['adr_two_postalcode'];
$state = $address[0]['adr_two_region']; $state = $address[0]['adr_two_region'];
$country = $address[0]['adr_two_countryname']; $country = $address[0]['adr_two_countryname'];
$tel = $address[0]['tel_home']; $tel = $address[0]['tel_home'];
$email = $address[0]['email_home']; $email = $address[0]['email_home'];
} }
if (! $country) if(!$country)
{ {
$country = $GLOBALS['phpgw_info']['user']['preferences']['common']['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')); $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')); $a = $t->set_file(array('address_format' => 'full_format_us.tpl'));
} }
if (!$afont) if(!$afont)
{ {
$afont = $GLOBALS['phpgw_info']['theme']['font']; $afont = $GLOBALS['phpgw_info']['theme']['font'];
} }
@ -478,7 +489,7 @@
$a .= $t->set_var('fax',$address[0]['tel_fax']); $a .= $t->set_var('fax',$address[0]['tel_fax']);
$a .= $t->set_var('url',$address[0]['url']); $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); $countryname = $s->get_full_name($country);
$a .= $t->set_var('country',lang($countryname)); $a .= $t->set_var('country',lang($countryname));
@ -495,32 +506,32 @@
$fields = array $fields = array
( (
'n_given' => 'n_given', 'n_given' => 'n_given',
'n_family' => 'n_family', 'n_family' => 'n_family',
'title' => 'title', 'title' => 'title',
'org_name' => 'org_name', 'org_name' => 'org_name',
'adr_one_street' => 'adr_one_street', 'adr_one_street' => 'adr_one_street',
'adr_one_locality' => 'adr_one_locality', 'adr_one_locality' => 'adr_one_locality',
'adr_one_postalcode' => 'adr_one_postalcode', 'adr_one_postalcode' => 'adr_one_postalcode',
'adr_one_region' => 'adr_one_region', 'adr_one_region' => 'adr_one_region',
'adr_one_countryname' => 'adr_one_countryname', 'adr_one_countryname' => 'adr_one_countryname',
'adr_two_street' => 'adr_two_street', 'adr_two_street' => 'adr_two_street',
'adr_two_locality' => 'adr_two_locality', 'adr_two_locality' => 'adr_two_locality',
'adr_two_postalcode' => 'adr_two_postalcode', 'adr_two_postalcode' => 'adr_two_postalcode',
'adr_two_region' => 'adr_two_region', 'adr_two_region' => 'adr_two_region',
'adr_two_countryname' => 'adr_two_countryname' 'adr_two_countryname' => 'adr_two_countryname'
); );
$address = $this->read_single_entry($id,$fields); $address = $this->read_single_entry($id,$fields);
if ($address[0]['title']) if($address[0]['title'])
{ {
$title = $address[0]['title'] . '&nbsp;'; $title = $address[0]['title'] . '&nbsp;';
} }
if ($business) if($business)
{ {
if ($address[0]['org_name']) if($address[0]['org_name'])
{ {
$company = $address[0]['org_name']; $company = $address[0]['org_name'];
} }
@ -545,12 +556,12 @@
$country = $address[0]['adr_two_countryname']; $country = $address[0]['adr_two_countryname'];
} }
if (! $country) if(!$country)
{ {
$country = $GLOBALS['phpgw_info']['user']['preferences']['common']['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')); $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')); $a = $t->set_file(array('address_format' => 'line_format_us.tpl'));
} }
if (!$afont) if(!$afont)
{ {
$afont = $GLOBALS['phpgw_info']['theme']['font']; $afont = $GLOBALS['phpgw_info']['theme']['font'];
} }
@ -572,7 +583,7 @@
$a .= $t->set_var('zip',$zip); $a .= $t->set_var('zip',$zip);
$a .= $t->set_var('state',$state); $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); $countryname = $s->get_full_name($country);
$a .= $t->set_var('country','&nbsp;°&nbsp;' . lang($countryname)); $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 */ /* send this the id and whatever fields you want to see */
function read_single_entry($id,$fields='') 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) = list($stock_fields,$stock_fieldnames,$extra_fields) =
$this->split_stock_and_extras($fields); $this->split_stock_and_extras($fields);
if (count($stock_fieldnames)) if(count($stock_fieldnames))
{ {
$t_fields = ',' . implode(',',$stock_fieldnames); $t_fields = ',' . implode(',',$stock_fieldnames);
if ($t_fields == ',') if($t_fields == ',')
{ {
unset($t_fields); unset($t_fields);
} }
@ -186,38 +189,38 @@
$return_fields[0]['access'] = $this->db->f('access'); $return_fields[0]['access'] = $this->db->f('access');
$return_fields[0]['cat_id'] = $this->db->f('cat_id'); $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); $return_fields[0][$f_name] = $this->db->f($f_name);
} }
} }
/* Setup address type fields for ui forms display */ /* 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'); $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))
{ {
eval("if (strstr(\$one_type,\$name)) { \$return_fields[0][\"one_\$name\"] = \"on\"; }"); 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'); $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))
{ {
eval("if (strstr(\$two_type,\$name)) { \$return_fields[0][\"two_\$name\"] = \"on\"; }"); 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__); $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'); $return_fields[0][$this->db->f('contact_name')] = $this->db->f('contact_value');
} }
@ -227,14 +230,17 @@
function read_last_entry($fields='') 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) = list($stock_fields,$stock_fieldnames,$extra_fields) =
$this->split_stock_and_extras($fields); $this->split_stock_and_extras($fields);
if (count($stock_fieldnames)) if(count($stock_fieldnames))
{ {
$t_fields = ',' . implode(',',$stock_fieldnames); $t_fields = ',' . implode(',',$stock_fieldnames);
if ($t_fields == ',') if($t_fields == ',')
{ {
unset($t_fields); unset($t_fields);
} }
@ -255,38 +261,38 @@
$return_fields[0]['access'] = $this->db->f('access'); $return_fields[0]['access'] = $this->db->f('access');
$return_fields[0]['cat_id'] = $this->db->f('cat_id'); $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); $return_fields[0][$f_name] = $this->db->f($f_name);
} }
} }
/* Setup address type fields for ui forms display */ /* 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'); $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))
{ {
eval("if (strstr(\$one_type,\$name)) { \$return_fields[0][\"one_\$name\"] = \"on\"; }"); 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'); $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))
{ {
eval("if (strstr(\$two_type,\$name)) { \$return_fields[0][\"two_\$name\"] = \"on\"; }"); 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__); $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'); $return_fields[0][$this->db->f('contact_name')] = $this->db->f('contact_value');
} }
@ -301,35 +307,38 @@
if(!$limit) { $limit = 0; } if(!$limit) { $limit = 0; }
if(!$filter) { $filter = 'tid=n'; } 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; $DEBUG = 0;
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($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); $t_fields = ',' . implode(',',$stock_fieldnames);
if ($t_fields == ',') if($t_fields == ',')
{ {
unset($t_fields); unset($t_fields);
} }
} }
/* turn filter's a=b,c=d OR a=b into an array */ /* 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; $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); $filterarray = split(',',$filter);
if ($filterarray[1]) if($filterarray[1])
{ {
$i=0; $i=0;
for ($i=0;$i<count($filterarray);$i++) for($i=0;$i<count($filterarray);$i++)
{ {
list($name,$value) = split('=',$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; $filterfields[$name] = $value;
} }
} }
@ -337,7 +346,7 @@
else else
{ {
list($name,$value) = split('=',$filter); list($name,$value) = split('=',$filter);
if ($DEBUG) if($DEBUG)
{ {
echo '<br>DEBUG - Filter intermediate strings 1: #'.$name.'# => #'.$value.'#'; 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 */ /* 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))
{ {
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))
{ {
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'; }
break; break;
} }
} }
@ -367,17 +376,17 @@
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))
{ {
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 else
{ {
@ -392,12 +401,12 @@
$filterlist = substr($filterlist,0,-1); $filterlist = substr($filterlist,0,-1);
$filterlist = ereg_replace(';',' AND ',$filterlist); $filterlist = ereg_replace(';',' AND ',$filterlist);
if ($DEBUG) if($DEBUG)
{ {
echo '<br>DEBUG - Filter output string: #'.$filterlist.'#'; echo '<br>DEBUG - Filter output string: #'.$filterlist.'#';
} }
if ($filterlist) if($filterlist)
{ {
$filtermethod = '('.$filterlist.') '; $filtermethod = '('.$filterlist.') ';
$fwhere = ' WHERE '; $fand = ' AND '; $fwhere = ' WHERE '; $fand = ' AND ';
@ -408,7 +417,7 @@
$filtermethod = " AND (tid='n' OR tid is null)"; $filtermethod = " AND (tid='n' OR tid is null)";
} }
if (!$filtermethod) if(!$filtermethod)
{ {
if($this->account_id) if($this->account_id)
{ {
@ -431,10 +440,10 @@
} }
} }
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))
{ {
$public_user_list[] = $user; $public_user_list[] = $user;
} }
@ -447,14 +456,17 @@
$fwhere .= ') '; $fand .= ') '; $fwhere .= ') '; $fand .= ') ';
} }
if ($DEBUG && $filtermethod) if($DEBUG && $filtermethod)
{ {
echo '<br>DEBUG - Filtering with: #' . $filtermethod . '#'; echo '<br>DEBUG - Filtering with: #' . $filtermethod . '#';
} }
if (!$sort) { $sort = 'ASC'; } if(!$sort)
{
$sort = 'ASC';
}
if ($order) if($order)
{ {
$ordermethod = "ORDER BY $order $sort "; $ordermethod = "ORDER BY $order $sort ";
} }
@ -463,14 +475,14 @@
$ordermethod = "ORDER BY n_family,n_given,email $sort"; $ordermethod = "ORDER BY n_family,n_given,email $sort";
} }
if ($DEBUG && $ordermethod) if($DEBUG && $ordermethod)
{ {
echo "<br>DEBUG - $ordermethod"; echo "<br>DEBUG - $ordermethod";
} }
$filtermethod = ''; $filtermethod = '';
if ($query) if($query)
{ {
$query = ereg_replace("'",'',$query); $query = ereg_replace("'",'',$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 $sql = "SELECT id,lid,tid,owner,access,cat_id $t_fields FROM $this->std_table " . $fwhere
. $filtermethod . ' ' . $ordermethod; . $filtermethod . ' ' . $ordermethod;
} }
if ($DEBUG) { echo '<br>' . $sql; } if($DEBUG) { echo '<br>' . $sql; }
$db2 = $this->db; $db2 = $this->db;
$this->db->query($sql,__LINE__,__FILE__); $this->db->query($sql,__LINE__,__FILE__);
$this->total_records = $this->db->num_rows(); $this->total_records = $this->db->num_rows();
if ($start && $limit) if($start && $limit)
{ {
$this->db->limit_query($sql,$start,__LINE__,__FILE__,$limit); $this->db->limit_query($sql,$start,__LINE__,__FILE__,$limit);
} }
elseif (!$limit) elseif(!$limit)
{ {
$this->db->query($sql,__LINE__,__FILE__); $this->db->query($sql,__LINE__,__FILE__);
} }
@ -510,7 +522,7 @@
} }
$i = 0; $i = 0;
while ($this->db->next_record()) while($this->db->next_record())
{ {
$return_fields[$i]['id'] = $this->db->f('id'); $return_fields[$i]['id'] = $this->db->f('id');
$return_fields[$i]['lid'] = $this->db->f('lid'); $return_fields[$i]['lid'] = $this->db->f('lid');
@ -519,9 +531,9 @@
$return_fields[$i]['access'] = $this->db->f('access'); $return_fields[$i]['access'] = $this->db->f('access');
$return_fields[$i]['cat_id'] = $this->db->f('cat_id'); $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); $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='" $db2->query("SELECT contact_name,contact_value FROM $this->ext_table WHERE contact_id='"
. $this->db->f('id') . "'" .$filterextra,__LINE__,__FILE__); . $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'); $return_fields[$i][$db2->f('contact_name')] = $db2->f('contact_value');
} }
@ -550,7 +562,7 @@
$tid = 'n'; $tid = 'n';
} }
if ($fields['lid']) if($fields['lid'])
{ {
$lid[0] = 'lid,'; $lid[0] = 'lid,';
$lid[1] = $fields['lid']."','"; $lid[1] = $fields['lid']."','";
@ -568,9 +580,9 @@
$this->db->next_record(); $this->db->next_record();
$id = $this->db->f(0); $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->query("INSERT INTO $this->ext_table VALUES ('$id','" . $this->account_id . "','"
. $this->db->db_addslashes($name) . "','" . $this->db->db_addslashes($value) . "')",__LINE__,__FILE__); . $this->db->db_addslashes($name) . "','" . $this->db->db_addslashes($value) . "')",__LINE__,__FILE__);
@ -604,20 +616,20 @@
/* First make sure that id number exists */ /* First make sure that id number exists */
$this->db->query("SELECT COUNT(*) FROM $this->std_table WHERE id='$id'",__LINE__,__FILE__); $this->db->query("SELECT COUNT(*) FROM $this->std_table WHERE id='$id'",__LINE__,__FILE__);
$this->db->next_record(); $this->db->next_record();
if (!$this->db->f(0)) if(!$this->db->f(0))
{ {
return False; return False;
} }
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields); 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]) . "'"; $ta[] = $stock_fieldname . "='" . $this->db->db_addslashes($stock_fields[$stock_fieldname]) . "'";
} }
$fields_s = ',' . implode(',',$ta); $fields_s = ',' . implode(',',$ta);
if ($field_s == ',') if($field_s == ',')
{ {
unset($field_s); unset($field_s);
} }
@ -625,11 +637,11 @@
. "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))
{ {
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); $this->delete_single_extra_field($id,$x_name);
} }
@ -650,7 +662,7 @@
/* Used by admin to change ownership on account delete */ /* Used by admin to change ownership on account delete */
function change_owner($old_owner='',$new_owner='') function change_owner($old_owner='',$new_owner='')
{ {
if (!($new_owner && $old_owner)) if(!($new_owner && $old_owner))
{ {
return False; return False;
} }
@ -671,7 +683,7 @@
/* This is for the admin script deleteaccount.php */ /* This is for the admin script deleteaccount.php */
function delete_all($owner=0) 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->std_table WHERE owner=$owner",__LINE__,__FILE__);
$this->db->query("DELETE FROM $this->ext_table WHERE contact_owner=$owner",__LINE__,__FILE__); $this->db->query("DELETE FROM $this->ext_table WHERE contact_owner=$owner",__LINE__,__FILE__);