* * View and manipulate contact records * * Copyright (C) 2001 Joseph Engo * * -------------------------------------------------------------------------* * This library is part of the phpGroupWare API * * http://www.phpgroupware.org/api * * ------------------------------------------------------------------------ * * This library is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published by * * the Free Software Foundation; either version 2.1 of the License, * * or any later version. * * This library is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * * along with this library; if not, write to the Free Software Foundation, * * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * \**************************************************************************/ /* $Id$ */ class contacts extends contacts_ { function check_perms($has, $needed) { return (!!($has & $needed) == True); } function split_stock_and_extras($fields) { while (list($field,$value) = each($fields)) { // Depending on how the array was build, this is needed. // Yet, I can't figure out why .... if (gettype($value) == "integer") { $value = $field; } if ($this->stock_contact_fields[$field]) { $stock_fields[$field] = $value; $stock_fieldnames[$field] = $this->stock_contact_fields[$field]; } else { $extra_fields[$field] = $value; } } return array($stock_fields,$stock_fieldnames,$extra_fields); } function loop_addslashes($fields) { $absf = $this->stock_contact_fields; while ($t = each($absf)) { $ta[] = addslashes($fields[$t[0]]); } reset($absf); // Is this needed ? return $ta; } // This will take an array or integer function delete($id) { if (gettype($id) == "array") { while (list($null,$t_id) = each($id)) { $this->delete_($t_id); } } else { $this->delete_($id); } } function asc_sort($a,$b) { echo "
A:'".$a."' B:'".$b; if($a[1]==$b[1]) return 0; return ($a[1]>$b[1])?1:-1; } function desc_sort($a,$b) { echo "
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) { /** ** We don't want to overstep the bounds of one of the strings and segfault, ** so let's see which one is shorter. **/ $order = 1; if ( (strlen($s1) == 0) ) { return 0; } if ( (strlen($s2) == 0) ) { return 1; } if (strlen ($s1) > strlen ($s2)) { $temp = $s1; $s1 = $s2; $s2 = $temp; $order = 0; } for ($index = 0; $index < strlen ($s1); $index++) { /* $s1 comes after $s2 */ if (strtolower($s1[$index]) > strtolower($s2[$index])) { return ($order); } /* $s1 comes before $s2 */ if (strtolower($s1[$index]) < strtolower($s2[$index])) { return (1 - $order); } } /* Special case in which $s1 is a substring of $s2 */ return ($order); } /* * asortbyindex ($sortarray, $index) * * Sort a multi-dimensional array by a second-degree index. For instance, the 0th index * of the Ith member of both the group and user arrays is a string identifier. In the * case of a user array this is the username; with the group array it is the group name. * asortby */ function asortbyindex ($sortarray, $index) { $lastindex = count($sortarray) - 2; for ($subindex = 0; $subindex < $lastindex; $subindex++) { $lastiteration = $lastindex - $subindex; for ($iteration = 0; $iteration < $lastiteration; $iteration++) { $nextchar = 0; if ($this->comesafter($sortarray[$iteration][$index], $sortarray[$iteration + 1][$index])) { $temp = $sortarray[$iteration]; $sortarray[$iteration] = $sortarray[$iteration + 1]; $sortarray[$iteration + 1] = $temp; } } } return ($sortarray); } function arsortbyindex ($sortarray, $index) { $lastindex = count($sortarray) - 1; for ($subindex = $lastindex; $subindex > 0; $subindex--) { $lastiteration = $lastindex - $subindex; for ($iteration = $lastiteration; $iteration > 0; $iteration--) { $nextchar = 0; if ($this->comesafter($sortarray[$iteration][$index], $sortarray[$iteration - 1][$index])) { $temp = $sortarray[$iteration]; $sortarray[$iteration] = $sortarray[$iteration - 1]; $sortarray[$iteration - 1] = $temp; } } } return ($sortarray); } function filter_ldap ($ldap_fields,$filterfields,$DEBUG=0) { $match = 0; if($DEBUG) { echo "
"; } for($i=0;$i"; } $new_ldap[] = $ldap_fields[$i]; } else { if($DEBUG) { echo $ldap_fields[$i]["uidnumber"][0].' did not match all.'."
"; } } } } if($DEBUG) { if($match) { echo '
'.$match.' total matches.'."\n"; } else { echo '
No matches :('."\n"; } } $this->total_records = count($new_ldap); return $new_ldap; } function formatted_address($id = '',$fields = '',$business = True) { global $phpgw,$phpgw_info; $font = $phpgw_info['theme']['font']; $t = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('addressbook')); $s = CreateObject('phpgwapi.sbox'); $address = $this->read_single_entry($id,$fields); if ($address[0]['title']) { $title = $address[0]['title'] . ' '; } if ($business) { $street = $address[0]['adr_one_street']; $city = $address[0]['adr_one_locality']; $zip = $address[0]['adr_one_postalcode']; $state = $address[0]['adr_one_region']; $country = $address[0]['adr_one_countryname']; } else { $street = $address[0]['adr_two_street']; $city = $address[0]['adr_two_locality']; $zip = $address[0]['adr_two_postalcode']; $state = $address[0]['adr_two_region']; $country = $address[0]['adr_two_countryname']; } if (! $country) { $country = $phpgw_info['user']['preferences']['common']['country']; } // echo 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')); } else { $a = $t->set_file(array('address_format' => 'format_us.tpl')); } $a .= $t->set_var('font',$font); $a .= $t->set_var('title',$title); $a .= $t->set_var('firstname',$address[0]['n_given']); $a .= $t->set_var('lastname',$address[0]['n_family']); $a .= $t->set_var('company',$address[0]['org_name']); $a .= $t->set_var('department',$address[0]['org_unit']); $a .= $t->set_var('street',$street); $a .= $t->set_var('city',$city); $a .= $t->set_var('zip',$zip); $a .= $t->set_var('state',$state); $countryname = $s->get_full_name($country); $a .= $t->set_var('country',lang($countryname)); $a .= $t->fp('out','address_format'); return $a; } } ?>