From ace91371c8c9ee58e3c6256eab63560ca1f7022e Mon Sep 17 00:00:00 2001 From: Miles Lott Date: Sun, 8 Jul 2001 13:54:40 +0000 Subject: [PATCH] Starting to commit mostly working redesign using 3layer --- addressbook/inc/class.boXport.inc.php | 309 +++++ addressbook/inc/class.boaddressbook.inc.php | 404 ++++++ addressbook/inc/class.soaddressbook.inc.php | 87 ++ addressbook/inc/class.uiXport.inc.php | 246 ++++ addressbook/inc/class.uiaddressbook.inc.php | 1300 +++++++++++++++++++ addressbook/inc/class.uivcard.inc.php | 197 +++ addressbook/inc/contacts.readme.txt | 244 ---- addressbook/inc/functions.inc.php | 969 +------------- 8 files changed, 2562 insertions(+), 1194 deletions(-) create mode 100644 addressbook/inc/class.boXport.inc.php create mode 100644 addressbook/inc/class.boaddressbook.inc.php create mode 100644 addressbook/inc/class.soaddressbook.inc.php create mode 100644 addressbook/inc/class.uiXport.inc.php create mode 100644 addressbook/inc/class.uiaddressbook.inc.php create mode 100644 addressbook/inc/class.uivcard.inc.php delete mode 100644 addressbook/inc/contacts.readme.txt diff --git a/addressbook/inc/class.boXport.inc.php b/addressbook/inc/class.boXport.inc.php new file mode 100644 index 0000000000..5029e64d7d --- /dev/null +++ b/addressbook/inc/class.boXport.inc.php @@ -0,0 +1,309 @@ + * + * -------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 2 of the License, or (at your * + * option) any later version. * + \**************************************************************************/ + + /* $Id$ */ + + class boXport + { + var $public_functions = array( + 'import' => True, + 'export' => True + ); + + var $so; + var $contacts; + + var $start; + var $limit; + var $query; + var $sort; + var $order; + var $filter; + var $cat_id; + + var $use_session = False; + + function boXport ($session=False) + { + global $phpgw; + + $this->contacts = &$phpgw->contacts; + $this->so = CreateObject('addressbook.soaddressbook'); + if($session) + { + $this->read_sessiondata(); + $this->use_session = True; + } + global $start,$limit,$query,$sort,$order,$filter,$cat_id; + + if($start || $start == 0) { $this->start = $start; } + if($limit) { $this->limit = $limit; } + if($query) { $this->query = $query; } + if($sort) { $this->sort = $sort; } + if($order) { $this->order = $order; } + if($filter) { $this->filter = $filter; } + $this->cat_id = $cat_id; + } + + function save_sessiondata() + { + global $phpgw,$start,$limit,$query,$sort,$order,$filter,$cat_id; + + if ($this->use_session) + { + $data = array( + 'start' => $start, + 'limit' => $limit, + 'query' => $query, + 'sort' => $sort, + 'order' => $order, + 'filter' => $filter, + 'cat_id' => $cat_id + ); + if($this->debug) { echo '
Save:'; _debug_array($data); } + $phpgw->session->appsession('session_data','addressbook',$data); + } + } + + function read_sessiondata() + { + global $phpgw; + + $data = $phpgw->session->appsession('session_data','addressbook'); + if($this->debug) { echo '
Read:'; _debug_array($data); } + + $this->start = $data['start']; + $this->limit = $data['limit']; + $this->query = $data['query']; + $this->sort = $data['sort']; + $this->order = $data['order']; + $this->filter = $data['filter']; + $this->cat_id = $data['cat_id']; + } + + function import() + { + global $tsvfile,$private; + + include (PHPGW_APP_INC . '/import/' . $conv_type); + + if ($private == '') { $private = 'public'; } + $row = 0; + $buffer = array(); + $contacts = new import_conv; + + $buffer = $contacts->import_start_file($buffer); + $fp = fopen($tsvfile,'r'); + if ($contacts->type == 'csv') + { + while ($data = fgetcsv($fp,8000,',')) + { + $num = count($data); + $row++; + if ($row == 1) + { + $header = $data; + /* Changed here to ignore the header, set to our array + while(list($lhs,$rhs) = each($contacts->import)) + { + $header[] = $lhs; + } + */ + } + else + { + $buffer = $contacts->import_start_record($buffer); + for ($c=0; $c<$num; $c++ ) + { + //Send name/value pairs along with the buffer + if ($contacts->import[$header[$c]] != '' && $data[$c] != '') + { + $buffer = $contacts->import_new_attrib($buffer, $contacts->import[$header[$c]],$data[$c]); + } + } + $buffer = $contacts->import_end_record($buffer,$private); + } + } + } + elseif ($contacts->type == 'ldif') + { + while ($data = fgets($fp,8000)) + { + $url = ""; + list($name,$value,$extra) = split(':', $data); + if (substr($name,0,2) == 'dn') + { + $buffer = $contacts->import_start_record($buffer); + } + + $test = trim($value); + if ($name && !empty($test) && $extra) + { + // Probable url string + $url = $test; + $value = $extra; + } + elseif ($name && empty($test) && $extra) + { + // Probable multiline encoding + $newval = base64_decode(trim($extra)); + $value = $newval; + //echo $name.':'.$value; + } + + if ($name && $value) + { + $test = split(',mail=',$value); + if ($test[1]) + { + $name = "mail"; + $value = $test[1]; + } + if ($url) + { + $name = "homeurl"; + $value = $url. ':' . $value; + } + //echo '
'.$j.': '.$name.' => '.$value; + if ($contacts->import[$name] != '' && $value != '') + { + $buffer = $contacts->import_new_attrib($buffer, $contacts->import[$name],$value); + } + } + else + { + $buffer = $contacts->import_end_record($buffer,$private); + } + } + } + else + { + while ($data = fgets($fp,8000)) + { + $data = trim($data); // RB 2001/05/07 added for Lotus Organizer + while (substr($data,-1) == '=') { // '=' at end-of-line --> line to be continued with next line + $data = substr($data,0,-1) . trim(fgets($fp,8000)); + } + if (strstr($data,';ENCODING=QUOTED-PRINTABLE')) { // RB 2001/05/07 added for Lotus Organizer + $data = quoted_printable_decode(str_replace(';ENCODING=QUOTED-PRINTABLE','',$data)); + } + list($name,$value) = explode(':', $data,2); // RB 2001/05/09 to allow ':' in Values (not only in URL's) + + if (strtolower(substr($name,0,5)) == 'begin') + { + $buffer = $contacts->import_start_record($buffer); + } + if ($name && $value) + { + reset($contacts->import); + while ( list($fname,$fvalue) = each($contacts->import) ) + { + if ( strstr(strtolower($name), $contacts->import[$fname]) ) + { + $buffer = $contacts->import_new_attrib($buffer,$name,$value); + } + } + } + else + { + $buffer = $contacts->import_end_record($buffer); + } + } + } + + fclose($fp); + $buffer = $contacts->import_end_file($buffer,$private,$cat_id); + + if ($download == '') + { + if($conv_type == 'Debug LDAP' || $conv_type == 'Debug SQL' ) + { + // filename, default application/octet-stream, length of file, default nocache True + $phpgw->browser->content_header($tsvfilename,'',strlen($buffer)); + echo $buffer; + } + else + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + echo "
$buffer
"; + echo ''.lang("OK").''; + $phpgw->common->phpgw_footer(); + } + } + else + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + echo "
$buffer
"; + echo ''.lang("OK").''; + $phpgw->common->phpgw_footer(); + } + } + + function export() + { + global $phpgw_info; + + include (PHPGW_APP_INC . '/export/' . $conv_type); + $buffer=array(); + $contacts = new export_conv; + + // Read in user custom fields, if any + $customfields = array(); + while (list($col,$descr) = @each($phpgw_info['user']['preferences']['addressbook'])) + { + if ( substr($col,0,6) == 'extra_' ) + { + $field = ereg_replace('extra_','',$col); + $field = ereg_replace(' ','_',$field); + $customfields[$field] = ucfirst($field); + } + } + $extrafields = array( + 'ophone' => 'ophone', + 'address2' => 'address2', + 'address3' => 'address3' + ); + if ($contacts->type != 'vcard') + { + $contacts->qfields = $contacts->stock_contact_fields;# + $extrafields;# + $customfields; + } + + if (!empty($cat_id)) + { + $buffer = $contacts->export_start_file($buffer,$cat_id); + } + else + { + $buffer = $contacts->export_start_file($buffer); + } + + for ($i=0;$iids);$i++) + { + $buffer = $contacts->export_start_record($buffer); + while( list($name,$value) = each($contacts->currentrecord) ) + { + $buffer = $contacts->export_new_attrib($buffer,$name,$value); + } + $buffer = $contacts->export_end_record($buffer); + } + + // Here, buffer becomes a string suitable for printing + $buffer = $contacts->export_end_file($buffer); + + $tsvfilename = $phpgw_info['server']['temp_dir'] . SEP . $tsvfilename; + + return $buffer; + } + } +?> diff --git a/addressbook/inc/class.boaddressbook.inc.php b/addressbook/inc/class.boaddressbook.inc.php new file mode 100644 index 0000000000..1932a5ca21 --- /dev/null +++ b/addressbook/inc/class.boaddressbook.inc.php @@ -0,0 +1,404 @@ + * + * -------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 2 of the License, or (at your * + * option) any later version. * + \**************************************************************************/ + + /* $Id$ */ + + class boaddressbook + { + var $public_functions = array( + 'read_entries' => True, + 'read_entry' => True, + 'read_last_entry' => True, + 'add_entry' => True, + 'add_vcard' => True, + 'add_email' => True, + 'copy_entry' => True, + 'update_entry' => True + ); + + var $debug = False; + + var $so; + var $start; + var $limit; + var $query; + var $sort; + var $order; + var $filter; + var $cat_id; + + var $use_session = False; + + function boaddressbook($session=False) + { + global $phpgw; + + $this->so = CreateObject('addressbook.soaddressbook'); + + if($session) + { + $this->read_sessiondata(); + $this->use_session = True; + } + global $start,$limit,$query,$sort,$order,$filter,$cat_id; + + if($start || $start == 0) { $this->start = $start; } + if($limit) { $this->limit = $limit; } + if(!empty($query)) { $this->query = $query; } + if(!empty($sort)) { $this->sort = $sort; } + if(!empty($order)) { $this->order = $order; } + if(!empty($filter)) { $this->filter = $filter; } + $this->cat_id = $cat_id; + } + + function save_sessiondata() + { + global $phpgw,$start,$limit,$query,$sort,$order,$filter,$cat_id; + + if ($this->use_session) + { + $data = array( + 'start' => $start, + 'limit' => $limit, + 'query' => $query, + 'sort' => $sort, + 'order' => $order, + 'filter' => $filter, + 'cat_id' => $cat_id + ); + if($this->debug) { echo '
Save:'; _debug_array($data); } + $phpgw->session->appsession('session_data','addressbook',$data); + } + } + + function read_sessiondata() + { + global $phpgw; + + $data = $phpgw->session->appsession('session_data','addressbook'); + if($this->debug) { echo '
Read:'; _debug_array($data); } + + $this->start = $data['start']; + $this->limit = $data['limit']; + $this->query = $data['query']; + $this->sort = $data['sort']; + $this->order = $data['order']; + $this->filter = $data['filter']; + $this->cat_id = $data['cat_id']; + } + + function strip_html($dirty = '') + { + global $phpgw; + + if ($dirty == ''){$dirty = array();} + for($i=0;$istrip_html($dirty[$i][$name]); + } + } + return $cleaned; + } + + function read_entries($start,$limit,$qcols,$qfilter,$userid='') + { + $entries = $this->so->read_entries($start,$limit,$qcols,$this->query,$qfilter,$this->sort,$this->order,$userid); + return $this->strip_html($entries); + } + + function read_entry($id,$fields,$userid='') + { + $entry = $this->so->read_entry($id,$fields,$userid); + return $this->strip_html($entry); + } + + function read_last_entry($fields) + { + $entry = $this->so->read_last_entry($fields); + return $this->strip_html($entry); + } + + function add_vcard() + { + global $phpgw,$phpgw_info,$uploadedfile; + + if($uploadedfile == 'none' || $uploadedfile == '') + { + Header('Location: ' . $phpgw->link('/addressbook/main.php','menuaction=addressbook.uivcard.in&action=GetFile')); + } + else + { + $uploaddir = $phpgw_info['server']['temp_dir'] . SEP; + + srand((double)microtime()*1000000); + $random_number = rand(100000000,999999999); + $newfilename = md5("$uploadedfile, $uploadedfile_name, " + . time() . getenv("REMOTE_ADDR") . $random_number ); + + copy($uploadedfile, $uploaddir . $newfilename); + $ftp = fopen($uploaddir . $newfilename . '.info','w'); + fputs($ftp,"$uploadedfile_type\n$uploadedfile_name\n"); + fclose($ftp); + + $filename = $uploaddir . $newfilename; + + $vcard = CreateObject('phpgwapi.vcard'); + $entry = $vcard->in_file($filename); + /* _debug_array($entry);exit; */ + $this->so->add_entry($phpgw_info['user']['account_id'],$entry,'private','','n'); + $ab_id = $this->get_lastid(); + + /* Delete the temp file. */ + unlink($filename); + unlink($filename . '.info'); + Header('Location: ' . $phpgw->link('/addressbook/main.php','menuaction=addressbook.uiaddressbook.view&ab_id=' . $ab_id)); + } + } + + function add_email() + { + global $phpgw_info,$name,$referer; + + $named = explode(' ', $name); + for ($i=count($named);$i>=0;$i--) { $names[$i] = $named[$i]; } + if ($names[2]) + { + $fields['n_given'] = $names[0]; + $fields['n_middle'] = $names[1]; + $fields['n_family'] = $names[2]; + } + else + { + $fields['n_given'] = $names[0]; + $fields['n_family'] = $names[1]; + } + $fields['email'] = $add_email; + $referer = urlencode($referer); + + $this->so->add_entry($phpgw_info['user']['account_id'],$fields,'private','','n'); + $ab_id = $this->get_lastid(); + + Header('Location: ' + . $phpgw->link('/addressbook/main.php',"menuaction=addressbook.uiaddressbook.view&ab_id=$ab_id&referer=$referer")); + } + + function copy_entry() + { + global $phpgw,$phpgw_info,$ab_id; + + $addnew = $this->read_entry($ab_id,$this->so->contacts->stock_contact_fields,$phpgw_info['user']['account_id']); + + $addnew[0]['note'] .= "\nCopied from ".$phpgw->accounts->id2name($addnew[0]['owner']).", record #".$addnew[0]['id']."."; + $addnew[0]['owner'] = $phpgw_info['user']['account_id']; + $addnew[0]['id'] = ''; + $fields = $addnew[0]; + + if ($addnew['tid']) + { + $this->so->add_entry($fields['owner'],$fields,$fields['access'],$fields['cat_id'],$fields['tid']); + } + else + { + $this->so->add_entry($fields['owner'],$fields,$fields['access'],$fields['cat_id']); + } + + $ab_id = $this->get_lastid(); + Header("Location: " . $phpgw->link('/addressbook/main.php',"menuaction=addressbook.uiaddressbook.edit&ab_id=$ab_id")); + } + + function add_entry() + { + global $phpgw,$phpgw_info; + + $fields = $this->get_form(); + + $referer = urlencode($fields['referer']); + unset($fields['referer']); + + $this->so->add_entry($phpgw_info['user']['account_id'],$fields,$fields['access'],$fields['cat_id'],$fields['tid']); + + $ab_id = $this->get_lastid(); + + Header('Location: ' + . $phpgw->link('/addressbook/main.php',"menuaction=addressbook.uiaddressbook.view&ab_id=$ab_id&referer=$referer")); + $phpgw->common->phpgw_exit(); + } + + function get_lastid() + { + return $this->so->get_lastid(); + } + + function update_entry() + { + global $phpgw,$phpgw_info; + + $fields = $this->get_form(); + $check = $this->read_entry($fields['ab_id'],array('owner' => 'owner')); + + if (($this->contacts->grants[$check[0]['owner']] & PHPGW_ACL_EDIT) && $check[0]['owner'] != $phpgw_info['user']['account_id']) + { + $userid = $check[0]['owner']; + } + else + { + $userid = $phpgw_info['user']['account_id']; + } + $referer = urlencode($fields['referer']); + unset($fields['referer']); + + $this->so->update_entry($fields['ab_id'],$fields['userid'],$fields,$fields['access'],$fields['cat_id'],$fields['tid']); + + Header("Location: " + . $phpgw->link('/addressbook/main.php',"menuaction=addressbook.uiaddressbook.view&ab_id=" . $fields['ab_id'] . "&referer=$referer")); + $phpgw->common->phpgw_exit(); + } + + function get_form() + { + global $entry; + /* _debug_array($entry); */ + + if (!$entry['bday_month'] && !$entry['bday_day'] && !$entry['bday_year']) + { + $fields['bday'] = ''; + } + else + { + $bday_day = $entry['bday_day']; + if (strlen($bday_day) == 1) + { + $bday_day = '0' . $entry['bday_day']; + } + $fields['bday'] = $entry['bday_month'] . '/' . $bday_day . '/' . $entry['bday_year']; + } + + if ($entry['url'] == 'http://') + { + $fields['url'] = ''; + } + + $fields['org_name'] = $entry['company']; + $fields['org_unit'] = $entry['department']; + $fields['n_given'] = $entry['firstname']; + $fields['n_family'] = $entry['lastname']; + $fields['n_middle'] = $entry['middle']; + $fields['n_prefix'] = $entry['prefix']; + $fields['n_suffix'] = $entry['suffix']; + if ($entry['prefix']) { $pspc = ' '; } + if ($entry['middle']) { $mspc = ' '; } else { $nspc = ' '; } + if ($entry['suffix']) { $sspc = ' '; } + $fields['fn'] = $entry['prefix'].$pspc.$entry['firstname'].$nspc.$mspc.$entry['middle'].$mspc.$entry['lastname'].$sspc.$entry['suffix']; + $fields['email'] = $entry['email']; + $fields['email_type'] = $entry['email_type']; + $fields['email_home'] = $entry['hemail']; + $fields['email_home_type'] = $entry['hemail_type']; + $fields['title'] = $entry['title']; + $fields['tel_work'] = $entry['wphone']; + $fields['tel_home'] = $entry['hphone']; + $fields['tel_fax'] = $entry['fax']; + $fields['tel_pager'] = $entry['pager']; + $fields['tel_cell'] = $entry['mphone']; + $fields['tel_msg'] = $entry['msgphone']; + $fields['tel_car'] = $entry['carphone']; + $fields['tel_video'] = $entry['vidphone']; + $fields['tel_isdn'] = $entry['isdnphone']; + $fields['adr_one_street'] = $entry['bstreet']; + $fields['adr_one_locality'] = $entry['bcity']; + $fields['adr_one_region'] = $entry['bstate']; + $fields['adr_one_postalcode'] = $entry['bzip']; + $fields['adr_one_countryname'] = $entry['bcountry']; + + if($entry['one_dom']) + { + $typea .= 'dom;'; + } + if($entry['one_intl']) + { + $typea .= 'intl;'; + } + if($entry['one_parcel']) + { + $typea .= 'parcel;'; + } + if($entry['one_postal']) + { + $typea .= 'postal;'; + } + $fields['adr_one_type'] = substr($typea,0,-1); + + $fields['address2'] = $entry['address2']; + $fields['address3'] = $entry['address3']; + + $fields['adr_two_street'] = $entry['hstreet']; + $fields['adr_two_locality'] = $entry['hcity']; + $fields['adr_two_region'] = $entry['hstate']; + $fields['adr_two_postalcode'] = $entry['hzip']; + $fields['adr_two_countryname'] = $entry['hcountry']; + + if($entry['two_dom']) + { + $typeb .= 'dom;'; + } + if($entry['two_intl']) + { + $typeb .= 'intl;'; + } + if($entry['two_parcel']) + { + $typeb .= 'parcel;'; + } + if($entry['two_postal']) + { + $typeb .= 'postal;'; + } + $fields['adr_two_type'] = substr($typeb,0,-1); + + while (list($name,$val) = @each($entry['customfields'])) + { + $fields[$name] = $val; + } + + $fields['ophone'] = $entry['ophone']; + $fields['tz'] = $entry['timezone']; + $fields['pubkey'] = $entry['pubkey']; + $fields['note'] = $entry['notes']; + $fields['label'] = $entry['label']; + + if ($entry['access'] == True) + { + $fields['access'] = 'private'; + } + else + { + $fields['access'] = 'public'; + } + + if (is_array($entry['cat_id'])) + { + $fields['cat_id'] = count($entry['cat_id']) > 1 ? ','.implode(',',$entry['cat_id']).',' : $entry['cat_id'][0]; + } + else + { + $fields['cat_id'] = $entry['cat_id']; + } + + $fields['ab_id'] = $entry['ab_id']; + $fields['tid'] = $entry['tid']; + $fields['referer'] = $entry['referer']; + /* _debug_array($fields);exit; */ + return $fields; + } /* end get_form() */ + } +?> diff --git a/addressbook/inc/class.soaddressbook.inc.php b/addressbook/inc/class.soaddressbook.inc.php new file mode 100644 index 0000000000..ceb7c661d0 --- /dev/null +++ b/addressbook/inc/class.soaddressbook.inc.php @@ -0,0 +1,87 @@ + * + * -------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 2 of the License, or (at your * + * option) any later version. * + \**************************************************************************/ + + /* $Id$ */ + + class soaddressbook + { + var $contacts; + var $rights; + + function soaddressbook() + { + global $phpgw,$rights; + + $phpgw->contacts = CreateObject('phpgwapi.contacts'); + + $this->contacts = &$phpgw->contacts; + $this->rights = $rights; + } + + function read_entries($start,$offset,$qcols,$query,$qfilter,$sort,$order) + { + $readrights = $this->rights & PHPGW_ACL_READ; + return $this->contacts->read($start,$offset,$qcols,$query,$qfilter,$sort,$order,$readrights); + } + + function read_entry($id,$fields) + { + if ($this->rights & PHPGW_ACL_READ) + { + return $this->contacts->read_single_entry($id,$fields); + } + else + { + $rtrn = array('No access' => 'No access'); + return $rtrn; + } + } + + function read_last_entry($fields) + { + if ($this->rights & PHPGW_ACL_READ) + { + return $this->contacts->read_last_entry($fields); + } + else + { + $rtrn = array('No access' => 'No access'); + return $rtrn; + } + } + + function add_entry($userid,$fields,$access='',$cat_id='',$tid='n') + { + if ($this->rights & PHPGW_ACL_ADD) + { + $this->contacts->add($userid,$fields,$access,$cat_id,$tid); + } + return; + } + + function get_lastid() + { + $entry = $this->contacts->read_last_entry(); + $ab_id = $entry[0]['id']; + return $ab_id; + } + + function update_entry($id,$userid,$fields,$access,$cat_id) + { + if ($this->rights & PHPGW_ACL_EDIT) + { + $this->contacts->update($id,$userid,$fields,$access,$cat_id); + } + return; + } + } +?> diff --git a/addressbook/inc/class.uiXport.inc.php b/addressbook/inc/class.uiXport.inc.php new file mode 100644 index 0000000000..f3d3a4880c --- /dev/null +++ b/addressbook/inc/class.uiXport.inc.php @@ -0,0 +1,246 @@ + * + * -------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 2 of the License, or (at your * + * option) any later version. * + \**************************************************************************/ + + /* $Id$ */ + + class uiXport + { + var $template; + var $public_functions = array( + 'import' => True, + 'export' => True + ); + var $bo; + var $cat; + + var $start; + var $limit; + var $query; + var $sort; + var $order; + var $filter; + var $cat_id; + + function uiXport() + { + global $phpgw; + + $this->template = &$phpgw->template; + $this->cat = CreateObject('phpgwapi.categories'); + $this->bo = CreateObject('addressbook.boXport',True); + + $this->start = &$this->bo->start; + $this->limit = &$this->bo->limit; + $this->query = &$this->bo->query; + $this->sort = &$this->bo->sort; + $this->order = &$this->bo->order; + $this->filter = &$this->bo->filter; + $this->cat_id = &$this->bo->cat_id; + } + + /* Return a select form element with the categories option dialog in it */ + function cat_option($cat_id='',$notall=False,$java=True,$multiple=False) + { + if ($java) + { + $jselect = ' onChange="this.form.submit();"'; + } + /* Setup all and none first */ + $cats_link = "\n" .''."\n"; + return $cats_link; + } + + function import() + { + global $phpgw,$convert,$download,$tsvfilename; + + if ($convert) + { + $buffer = $this->bo->import(); + print_r($buffer); + + if ($download == '') + { + if($conv_type == 'Debug LDAP' || $conv_type == 'Debug SQL' ) + { + // filename, default application/octet-stream, length of file, default nocache True + $phpgw->browser->content_header($tsvfilename,'',strlen($buffer)); + echo $buffer; + } + else + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + echo "
$buffer
"; + echo ''.lang("OK").''; + $phpgw->common->phpgw_footer(); + } + } + else + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + echo "
$buffer
"; + echo ''.lang("OK").''; + $phpgw->common->phpgw_footer(); + } + + } + else + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + $this->template->set_file(array('import' => 'import.tpl')); + + $dir_handle = opendir(PHPGW_APP_INC . SEP . 'import'); + $i=0; $myfilearray = ''; + while ($file = readdir($dir_handle)) + { + //echo ""; + if ((substr($file, 0, 1) != '.') && is_file(PHPGW_APP_INC . SEP . 'import' . SEP . $file) ) + { + $myfilearray[$i] = $file; + $i++; + } + } + closedir($dir_handle); + sort($myfilearray); + for ($i=0;$i' . $fname . ''; + } + + $this->template->set_var('lang_cancel',lang('Cancel')); + $this->template->set_var('lang_cat',lang('Select Category')); + $this->template->set_var('cancel_url',$phpgw->link('/addressbook/main.php','menuaction=addressbook.uiaddressbook.get_list')); + $this->template->set_var('navbar_bg',$phpgw_info['theme']['navbar_bg']); + $this->template->set_var('navbar_text',$phpgw_info['theme']['navbar_text']); + $this->template->set_var('import_text',lang('Import from LDIF, CSV, or VCard')); + $this->template->set_var('action_url',$phpgw->link('/addressbook/main.php','menuaction=addressbook.boXport.import')); + $this->template->set_var('cat_link',$this->cat_option($this->cat_id,True,False)); + $this->template->set_var('tsvfilename',''); + $this->template->set_var('conv',$conv); + $this->template->set_var('debug',lang('Debug output in browser')); + $this->template->set_var('filetype',lang('LDIF')); + $this->template->set_var('download',lang('Submit')); + $this->template->set_var('start',$this->start); + $this->template->set_var('sort',$this->sort); + $this->template->set_var('order',$this->order); + $this->template->set_var('filter',$this->filter); + $this->template->set_var('query',$this->query); + $this->template->set_var('cat_id',$this->cat_id); + $this->template->pparse('out','import'); + } + $phpgw->common->phpgw_footer(); + } + + function export() + { + global $phpgw,$phpgw_info,$convert,$tsvfilename; + + if ($convert) + { + $buffer = $this->bo->export(); + + if ($conv_type == 'none') + { + $phpgw_info['flags']['noheader'] = False; + $phpgw_info['flags']['noheader'] = True; + $phpgw->common->phpgw_header(); + echo parse_navbar(); + echo lang('No conversion type <none> could be located. Please choose a conversion type from the list'); + echo ' '.lang('OK').''; + $phpgw->common->phpgw_footer(); + $phpgw->common->phpgw_exit(); + } + + if ( ($download == 'on') || ($o->type == 'pdb') ) + { + // filename, default application/octet-stream, length of file, default nocache True + $phpgw->browser->content_header($tsvfilename,'application/octet-stream',strlen($buffer)); + echo $buffer; + } + else + { + echo "
\n";
+					echo $buffer;
+					echo "\n
\n"; + echo ''.lang('OK').''; + $phpgw->common->phpgw_footer(); + } + } + else + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + $this->template->set_file(array('export' => 'export.tpl')); + + $dir_handle = opendir(PHPGW_APP_INC. SEP . 'export'); + $i=0; $myfilearray = ''; + while ($file = readdir($dir_handle)) + { + #echo ""; + if ((substr($file, 0, 1) != '.') && is_file(PHPGW_APP_INC . SEP . 'export' . SEP . $file) ) + { + $myfilearray[$i] = $file; + $i++; + } + } + closedir($dir_handle); + sort($myfilearray); + for ($i=0;$i'.$fname.''."\n"; + } + + $this->template->set_var('lang_cancel',lang('Cancel')); + $this->template->set_var('lang_cat',lang('Select Category')); + $this->template->set_var('cat_link',$this->cat_option($this->cat_id,False,False)); + $this->template->set_var('cancel_url',$phpgw->link('/addressbook/index.php')); + $this->template->set_var('navbar_bg',$phpgw_info['theme']['navbar_bg']); + $this->template->set_var('navbar_text',$phpgw_info['theme']['navbar_text']); + $this->template->set_var('export_text',lang('Export from Addressbook')); + $this->template->set_var('action_url',$phpgw->link('/addressbook/export.php')); + $this->template->set_var('filename',lang('Export file name')); + $this->template->set_var('conv',$conv); + $this->template->set_var('debug',lang('')); + $this->template->set_var('download',lang('Submit')); + $this->template->set_var('start',$this->start); + $this->template->set_var('sort',$this->sort); + $this->template->set_var('order',$this->order); + $this->template->set_var('filter',$this->filter); + $this->template->set_var('query',$this->query); + $this->template->set_var('cat_id',$this->cat_id); + $this->template->pparse('out','export'); + + $phpgw->common->phpgw_footer(); + } + } + } +?> diff --git a/addressbook/inc/class.uiaddressbook.inc.php b/addressbook/inc/class.uiaddressbook.inc.php new file mode 100644 index 0000000000..ff0ad0fd9e --- /dev/null +++ b/addressbook/inc/class.uiaddressbook.inc.php @@ -0,0 +1,1300 @@ + and * + * Miles Lott * + * -------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 2 of the License, or (at your * + * option) any later version. * + \**************************************************************************/ + + /* $Id$ */ + + class uiaddressbook + { + var $template; + var $contacts; + var $bo; + var $cat; + var $company; + var $prefs; + + var $debug = False; + + var $start; + var $limit; + var $query; + var $sort; + var $order; + var $filter; + var $cat_id; + + var $template; + var $public_functions = array( + 'get_list' => True, + 'view' => True, + 'add' => True, + 'edit' => True + ); + + var $extrafields = array( + 'ophone' => 'ophone', + 'address2' => 'address2', + 'address3' => 'address3' + ); + + function uiaddressbook() + { + global $phpgw,$phpgw_info; + + $phpgw->country = CreateObject('phpgwapi.country'); + $phpgw->browser = CreateObject('phpgwapi.browser'); + $phpgw->nextmatchs = CreateObject('phpgwapi.nextmatchs'); + + $this->bo = CreateObject('addressbook.boaddressbook',True); + $this->template = &$phpgw->template; + $this->contacts = &$phpgw->contacts; + $this->cat = CreateObject('phpgwapi.categories'); + $this->company = CreateObject('phpgwapi.categories','addressbook_company'); + $this->prefs = &$phpgw_info['user']['preferences']['addressbook']; + + $this->start = &$this->bo->start; + $this->limit = &$this->bo->limit; + $this->query = &$this->bo->query; + $this->sort = &$this->bo->sort; + $this->order = &$this->bo->order; + $this->filter = &$this->bo->filter; + $this->cat_id = &$this->bo->cat_id; + if($this->debug) { $this->_debug_sqsof(); } +/* _debug_array($this); */ + } + + function _debug_sqsof() + { + $data = array( + 'start' => $this->start, + 'limit' => $this->limit, + 'query' => $this->query, + 'sort' => $this->sort, + 'order' => $this->order, + 'filter' => $this->filter, + 'cat_id' => $this->cat_id + ); + echo '
UI:'; + _debug_array($data); + } + + /* Called only by get_list(), just prior to page footer. */ + function save_sessiondata() + { + $this->bo->save_sessiondata(); + } + + function formatted_list($name,$list,$id='',$default=False,$java=False) + { + if ($java) + { + $jselect = ' onChange="this.form.submit();"'; + } + + $select = "\n" .''."\n"; + $select .= '' . "\n"; + + return $select; + } + + function read_custom_fields() + { + $i = 0; $j = 0; + $fields = array(); + @reset($this->prefs); + while (list($col,$descr) = @each($this->prefs)) + { + if ( substr($col,0,6) == 'extra_' ) + { + $fields[$j]['name'] = ereg_replace('extra_','',$col); + $fields[$j]['name'] = ereg_replace(' ','_',$fields[$j]['name']); + $fields[$j]['id'] = $i; + + if ($query && ($fields[$j]['name'] != $query)) + { + unset($fields[$j]['name']); + unset($fields[$j]['id']); + } + else + { + /* echo "
".$j.": '".$fields[$j]['name']."'"; */ + $j++; + } + } + $i++; + } + @reset($fields); + return $fields; + } + + function save_custom_field($old='',$new='') + { + global $phpgw,$phpgw_info; + + $phpgw->preferences->read_repository($phpgw_info['user']['account_id']); + if ($old) + { + $phpgw->preferences->delete("addressbook","extra_".$old); + } + if($new) + { + $phpgw->preferences->add("addressbook","extra_".$new); + } + $phpgw->preferences->save_repository(1); + } + + /* Return a select form element with the categories option dialog in it */ + function cat_option($cat_id='',$notall=False,$java=True,$multiple=False) + { + if ($java) + { + $jselect = ' onChange="this.form.submit();"'; + } + /* Setup all and none first */ + $cats_link = "\n" .''."\n"; + return $cats_link; + } + + /* this cleans up the fieldnames for display */ + function display_name($column) + { + $abc = array( + 'fn' => 'full name', + 'sound' => 'Sound', + 'org_name' => 'company name', + 'org_unit' => 'department', + 'title' => 'title', + 'n_prefix' => 'prefix', + 'n_given' => 'first name', + 'n_middle' => 'middle name', + 'n_family' => 'last name', + 'n_suffix' => 'suffix', + 'label' => 'label', + 'adr_one_street' => 'business street', + 'adr_one_locality' => 'business city', + 'adr_one_region' => 'business state', + 'adr_one_postalcode' => 'business zip code', + 'adr_one_countryname' => 'business country', + 'adr_one_type' => 'business address type', + 'adr_two_street' => 'home street', + 'adr_two_locality' => 'home city', + 'adr_two_region' => 'home state', + 'adr_two_postalcode' => 'home zip code', + 'adr_two_countryname' => 'home country', + 'adr_two_type' => 'home address type', + 'tz' => 'time zone', + 'geo' => 'geo', + 'tel_work' => 'business phone', + 'tel_home' => 'home phone', + 'tel_voice' => 'voice phone', + 'tel_msg' => 'message phone', + 'tel_fax' => 'fax', + 'tel_pager' => 'pager', + 'tel_cell' => 'mobile phone', + 'tel_bbs' => 'bbs phone', + 'tel_modem' => 'modem phone', + 'tel_isdn' => 'isdn phone', + 'tel_car' => 'car phone', + 'tel_video' => 'video phone', + 'tel_prefer' => 'preferred phone', + 'email' => 'business email', + 'email_type' => 'business email type', + 'email_home' => 'home email', + 'email_home_type' => 'home email type', + 'address2' => 'address line 2', + 'address3' => 'address line 3', + 'ophone' => 'Other Phone', + 'bday' => 'birthday', + 'url' => 'url', + 'pubkey' => 'public key', + 'note' => 'notes' + ); + + if ($abc[$column]) + { + return lang($abc[$column]); + } + else + { + return; + } + } + + /* + Former index.php + */ + function get_list() + { + global $phpgw,$phpgw_info; + + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + $this->template->set_file(array('addressbook_list_t' => 'index.tpl')); + $this->template->set_block('addressbook_list_t','addressbook_header','addressbook_header'); + $this->template->set_block('addressbook_list_t','column','column'); + $this->template->set_block('addressbook_list_t','row','row'); + $this->template->set_block('addressbook_list_t','addressbook_footer','addressbook_footer'); + + $customfields = $this->read_custom_fields(); + + if (!isset($this->cat_id)) + { + $this->cat_id = $this->prefs['default_category']; + } + if ($this->prefs['autosave_category']) + { + $phpgw->preferences->read_repository(); + $phpgw->preferences->delete('addressbook','default_category'); + $phpgw->preferences->add('addressbook','default_category',$this->cat_id); + $phpgw->preferences->save_repository(); + } + + /* $qfields = $contacts->stock_contact_fields + $extrafields + $customfields; */ + /* create column list and the top row of the table based on user prefs */ + while ($column = each($this->contacts->stock_contact_fields)) + { + $test = strtolower($column[0]); + if (isset($this->prefs[$test]) && $this->prefs[$test]) + { + $showcol = $this->display_name($column[0]); + $cols .= ' ' . "\n"; + $cols .= ' '; + $cols .= $phpgw->nextmatchs->show_sort_order($this->sort, + $column[0],$this->order,"/addressbook/main.php",$showcol,'&menuaction=addressbook.uiaddressbook.get_list'); + $cols .= "\n "; + $cols .= "\n"; + + /* To be used when displaying the rows */ + $columns_to_display[$column[0]] = True; + } + } + /* Setup the columns for non-standard fields, since we don't allow sorting */ + $nonstd = $this->extrafields + $customfields; + while ($column = each($nonstd)) + { + $test = strtolower($column[1]); + if (isset($this->prefs[$test]) && $this->prefs[$test]) + { + $showcol = $this->display_name($column[0]); + /* This must be a custom field */ + if (!$showcol) { $showcol = $column[1]; } + $cols .= ' ' . "\n"; + $cols .= ' '; + $cols .= $showcol; + $cols .= "\n "; + $cols .= "\n"; + + /* To be used when displaying the rows */ + $columns_to_display[$column[0]] = True; + } + } + /* Check if prefs were set, if not, create some defaults */ + if (!$columns_to_display ) + { + $columns_to_display = array( + 'n_given' => 'n_given', + 'n_family' => 'n_family', + 'org_name' => 'org_name' + ); + $columns_to_display = $columns_to_display + $customfields; + /* No prefs,. so cols above may have been set to "" or a bunch of */ + $cols=''; + while ($column = each($columns_to_display)) + { + $showcol = $this->display_name($column[0]); + if (!$showcol) { $showcol = $column[1]; } + $cols .= ' ' . "\n"; + $cols .= ' '; + $cols .= $phpgw->nextmatchs->show_sort_order($this->sort, + $column[0],$this->order,"/addressbook/main.php",$showcol,'menuaction=addressbook.uiaddressbook.get_list&cat_id='.$this->cat_id); + $cols .= "\n "; + $cols .= "\n"; + } + $noprefs=lang('Please set your preferences for this app'); + } + + if (!$this->start) + { + $this->start = 0; + } + + if($phpgw_info['user']['preferences']['common']['maxmatchs'] && + $phpgw_info['user']['preferences']['common']['maxmatchs'] > 0) + { + $this->limit = $phpgw_info['user']['preferences']['common']['maxmatchs']; + } + else + { + $this->limit = 30; + } + + global $filter; + if (empty($filter) || !isset($filter)) + { + if($this->prefs['default_filter']) + { + $this->filter = $this->prefs['default_filter']; + $this->query = ''; + } + else + { + $this->filter = 'none'; + } + } + + /* + Set qfilter to display entries where tid=n (normal contact entry), + else they may be accounts, etc. + */ + $qfilter = 'tid=n'; + switch ($this->filter) + { + case 'blank': + $nosearch = True; + break; + case 'none': + break; + case 'private': + $qfilter .= ',access=private'; /* fall through */ + case 'yours': + $qfilter .= ',owner='.$phpgw_info['user']['account_id']; + break; + default: + $qfilter .= ',owner='.$this->filter; + } + if ($this->cat_id) + { + $qfilter .= ',cat_id='.$this->cat_id; + } + + if (!$userid) { $userid = $phpgw_info['user']['account_id']; } + + if ($nosearch && !$this->query) + { + $entries = array(); + $this->contacts->total_records = 0; + } + else + { + /* read the entry list */ + $entries = $this->bo->read_entries($this->start,$this->limit,$columns_to_display,$qfilter,$userid); + } + + /* global here so nextmatchs accepts our setting of $query */ + global $query; + + $query = $this->query; + $search_filter = $phpgw->nextmatchs->show_tpl('/addressbook/main.php', + $this->start, $this->contacts->total_records,'&menuaction=addressbook.uiaddressbook.get_list',"75%", + $phpgw_info["theme"]["th_bg"],1,1,1,1); + + $lang_showing = $phpgw->nextmatchs->show_hits($this->contacts->total_records,$this->start); + + /* set basic vars and parse the header */ + $this->template->set_var('font',$phpgw_info['theme']['font']); + $this->template->set_var('lang_view',lang('View')); + $this->template->set_var('lang_vcard',lang('VCard')); + $this->template->set_var('lang_edit',lang('Edit')); + $this->template->set_var('lang_owner',lang('Owner')); + + $this->template->set_var('searchreturn',$noprefs . ' ' . $searchreturn); + $this->template->set_var('lang_showing',$lang_showing); + $this->template->set_var('search_filter',$search_filter); + $this->template->set_var('cats',lang('Category')); + $this->template->set_var('cats_url',$phpgw->link('/addressbook/main.php','menuaction=addressbook.uiaddressbook.get_list')); + $this->template->set_var('cats_link',$this->cat_option($this->cat_id)); + $this->template->set_var('lang_cats',lang('Select')); + $this->template->set_var('lang_addressbook',lang('Address book')); + $this->template->set_var('th_bg',$phpgw_info['theme']['th_bg']); + $this->template->set_var('th_font',$phpgw_info['theme']['font']); + $this->template->set_var('th_text',$phpgw_info['theme']['th_text']); + $this->template->set_var('lang_add',lang('Add')); + $this->template->set_var('add_url',$phpgw->link('/addressbook/main.php','menuaction=addressbook.uiaddressbook.add')); + $this->template->set_var('lang_addvcard',lang('AddVCard')); + $this->template->set_var('vcard_url',$phpgw->link('/addressbook/main.php','menuaction=addressbook.uivcard.in')); + $this->template->set_var('lang_import',lang('Import Contacts')); + $this->template->set_var('import_url',$phpgw->link('/addressbook/main.php','menuaction=addressbook.uiXport.import')); + $this->template->set_var('lang_import_alt',lang('Alt. CSV Import')); + $this->template->set_var('import_alt_url',$phpgw->link('/addressbook/csv_import.php')); + $this->template->set_var('lang_export',lang('Export Contacts')); + $this->template->set_var('export_url',$phpgw->link('/addressbook/main.php','menuaction=addressbook.uiXport.export')); + + $this->template->set_var('start',$this->start); + $this->template->set_var('sort',$this->sort); + $this->template->set_var('order',$this->order); + $this->template->set_var('filter',$this->filter); + $this->template->set_var('query',$this->query); + $this->template->set_var('cat_id',$this->cat_id); + + $this->template->set_var('qfield',$qfield); + $this->template->set_var('cols',$cols); + + $this->template->pparse('out','addressbook_header'); + + /* Show the entries */ + /* each entry */ + for ($i=0;$itemplate->set_var('columns',''); + $tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color); + $this->template->set_var('row_tr_color',$tr_color); + $myid = $entries[$i]['id']; + $myowner = $entries[$i]['owner']; + + /* each entry column */ + while ($column = each($columns_to_display)) + { + $ref = $data=''; + $coldata = $entries[$i][$column[0]]; + /* Some fields require special formatting. */ + if ($column[0] == 'url') + { + if ( !empty($coldata) && (substr($coldata,0,7) != 'http://') ) { $coldata = 'http://' . $coldata; } + $ref=''; + $data=$coldata.''; + } + elseif ( ($column[0] == 'email') || ($column[0] == 'email_home') ) + { + if ($phpgw_info['user']['apps']['email']) + { + $ref=''; + } + else + { + $ref=''; + } + $data=$coldata . ''; + } + else /* But these do not */ + { + $ref = ''; $data = $coldata; + } + $this->template->set_var('col_data',$ref.$data); + $this->template->parse('columns','column',True); + } + + if (1) + { + $this->template->set_var('row_view_link',$phpgw->link('/addressbook/main.php', + 'menuaction=addressbook.uiaddressbook.view&ab_id='.$entries[$i]['id'])); + } + else + { + $this->template->set_var('row_view_link',''); + $this->template->set_var('lang_view',lang('Private')); + } + + $this->template->set_var('row_vcard_link',$phpgw->link('/addressbook/main.php', + 'menuaction=addressbook.uivcard.out&ab_id='.$entries[$i]['id'])); + /* echo '
: ' . $contacts->grants[$myowner] . ' - ' . $myowner; */ + if ($this->contacts->check_perms($this->contacts->grants[$myowner],PHPGW_ACL_EDIT) || $myowner == $phpgw_info['user']['account_id']) + { + $this->template->set_var('row_edit','' . lang('Edit') . ''); + } + else + { + $this->template->set_var('row_edit',' '); + } + + $this->template->set_var('row_owner',$phpgw->accounts->id2name($myowner)); + + $this->template->parse('rows','row',True); + $this->template->pparse('out','row'); + reset($columns_to_display); + } + + $this->template->pparse('out','addressbook_footer'); + $this->save_sessiondata(); + $phpgw->common->phpgw_footer(); + } + + /* Following used for add/edit */ + function addressbook_form($format,$action,$title='',$fields='',$customfields='',$cat_id='') + { + global $phpgw,$phpgw_info,$referer; + + $this->template->set_file(array('form' => 'form.tpl')); + + if ( ($phpgw_info['server']['countrylist'] == 'user_choice' && + $phpgw_info['user']['preferences']['common']['countrylist'] == 'use_select') || + ($phpgw_info['server']['countrylist'] == 'force_select')) + { + $countrylist = True; + } + + $email = $fields['email']; + $emailtype = $fields['email_type']; + $hemail = $fields['email_home']; + $hemailtype = $fields['email_home_type']; + $firstname = $fields['n_given']; + $middle = $fields['n_middle']; + $prefix = $fields['n_prefix']; + $suffix = $fields['n_suffix']; + $lastname = $fields['n_family']; + $title = $fields['title']; + $wphone = $fields['tel_work']; + $hphone = $fields['tel_home']; + $fax = $fields['tel_fax']; + $pager = $fields['tel_pager']; + $mphone = $fields['tel_cell']; + $ophone = $fields['ophone']; + $msgphone = $fields['tel_msg']; + $isdnphone = $fields['tel_isdn']; + $carphone = $fields['tel_car']; + $vidphone = $fields['tel_video']; + $preferred = $fields['tel_prefer']; + + $bstreet = $fields['adr_one_street']; + $address2 = $fields['address2']; + $address3 = $fields['address3']; + $bcity = $fields['adr_one_locality']; + $bstate = $fields['adr_one_region']; + $bzip = $fields['adr_one_postalcode']; + $bcountry = $fields['adr_one_countryname']; + $one_dom = $fields['one_dom']; + $one_intl = $fields['one_intl']; + $one_parcel = $fields['one_parcel']; + $one_postal = $fields['one_postal']; + + $hstreet = $fields['adr_two_street']; + $hcity = $fields['adr_two_locality']; + $hstate = $fields['adr_two_region']; + $hzip = $fields['adr_two_postalcode']; + $hcountry = $fields['adr_two_countryname']; + $btype = $fields['adr_two_type']; + $two_dom = $fields['two_dom']; + $two_intl = $fields['two_intl']; + $two_parcel = $fields['two_parcel']; + $two_postal = $fields['two_postal']; + + $timezone = $fields['tz']; + $bday = $fields['bday']; + $notes = stripslashes($fields['note']); + $label = stripslashes($fields['label']); + $company = $fields['org_name']; + $department = $fields['org_unit']; + $url = $fields['url']; + $pubkey = $fields['pubkey']; + $access = $fields['access']; + if(!$cat_id) + { + $cat_id = $fields['cat_id']; + } + /* allow multiple categories on sql */ + $cats_link = $this->cat_option( + $cat_id, + True, + False, + !$phpgw_info['server']['contact_repository'] || $phpgw_info['server']['contact_repository'] == 'sql' + ); + + if ($access == 'private') + { + $access_check = ' checked'; + } + else + { + $access_check = ''; + } + + if ($customfields) + { + while(list($name,$value) = each($customfields)) + { + $value = ereg_replace('_',' ',$value); + $custom .= ' + +   + '.$value.': + + +'; + } + } + + if ($format != "view") + { + // Preferred phone number radio buttons + $pref[0] = ''; + $pref[1] = '(' . lang('pref') . ')'; + while (list($name,$val) = each($this->contacts->tel_types)) + { + $str[$name] = "\n".' template->set_var("pref_".$name,$str[$name]); + } + + if (strlen($bday) > 2) + { + list( $month, $day, $year ) = split( '/', $bday ); + $temp_month[$month] = ' selected'; + $bday_month = ''; + $bday_day = ''; + $bday_year = ''; + } + else + { + $bday_month = ''; + $bday_day = ''; + $bday_year = ''; + } + + $time_zone = '"; + + reset($this->contacts->email_types); + $hemail_type = '"; + + reset($this->contacts->adr_types); + while (list($type,$val) = each($this->contacts->adr_types)) + { + $badrtype .= "\n".'contacts->adr_types); + while (list($type,$val) = each($this->contacts->adr_types)) + { + $hadrtype .= "\n".''; + $label = ''; + $pubkey = ''; + } + else + { + $notes = '
'; + if ($bday == "//") + { + $bday = ""; + } + } + + if ($action) + { + echo '
'; + } + + if (!ereg("^http://",$url)) + { + $url = "http://". $url; + } + + $birthday = $phpgw->common->dateformatorder($bday_year,$bday_month,$bday_day) + . '(e.g. 1969)'; + if ($format == 'edit') + { + $create .= '' . lang("Created by") . ':' + . '' + . $phpgw->common->grab_owner_name($fields["owner"]); + } + else + { + $create .= ''; + } + + $this->template->set_var('lang_home',lang('Home')); + $this->template->set_var('lang_business',lang('Business')); + $this->template->set_var('lang_personal',lang('Personal')); + + $this->template->set_var('lang_lastname',lang('Last Name')); + $this->template->set_var('lastname',$lastname); + $this->template->set_var('lang_firstname',lang('First Name')); + $this->template->set_var('firstname',$firstname); + $this->template->set_var('lang_middle',lang('Middle Name')); + $this->template->set_var('middle',$middle); + $this->template->set_var('lang_prefix',lang('Prefix')); + $this->template->set_var('prefix',$prefix); + $this->template->set_var('lang_suffix',lang('Suffix')); + $this->template->set_var('suffix',$suffix); + $this->template->set_var('lang_birthday',lang('Birthday')); + $this->template->set_var('birthday',$birthday); + + $this->template->set_var('lang_company',lang('Company Name')); + $this->template->set_var('company',$company); + $this->template->set_var('lang_department',lang('Department')); + $this->template->set_var('department',$department); + $this->template->set_var('lang_title',lang('Title')); + $this->template->set_var('title',$title); + $this->template->set_var('lang_email',lang('Business Email')); + $this->template->set_var('email',$email); + $this->template->set_var('lang_email_type',lang('Business EMail Type')); + $this->template->set_var('email_type',$email_type); + $this->template->set_var('lang_url',lang('URL')); + $this->template->set_var('url',$url); + $this->template->set_var('lang_timezone',lang('time zone offset')); + $this->template->set_var('timezone',$time_zone); + $this->template->set_var('lang_fax',lang('Business Fax')); + $this->template->set_var('fax',$fax); + $this->template->set_var('lang_wphone',lang('Business Phone')); + $this->template->set_var('wphone',$wphone); + $this->template->set_var('lang_pager',lang('Pager')); + $this->template->set_var('pager',$pager); + $this->template->set_var('lang_mphone',lang('Cell Phone')); + $this->template->set_var('mphone',$mphone); + $this->template->set_var('lang_msgphone',lang('Message Phone')); + $this->template->set_var('msgphone',$msgphone); + $this->template->set_var('lang_isdnphone',lang('ISDN Phone')); + $this->template->set_var('isdnphone',$isdnphone); + $this->template->set_var('lang_carphone',lang('Car Phone')); + $this->template->set_var('carphone',$carphone); + $this->template->set_var('lang_vidphone',lang('Video Phone')); + $this->template->set_var('vidphone',$vidphone); + + $this->template->set_var('lang_ophone',lang('Other Number')); + $this->template->set_var('ophone',$ophone); + $this->template->set_var('lang_bstreet',lang('Business Street')); + $this->template->set_var('bstreet',$bstreet); + $this->template->set_var('lang_address2',lang('Address Line 2')); + $this->template->set_var('address2',$address2); + $this->template->set_var('lang_address3',lang('Address Line 3')); + $this->template->set_var('address3',$address3); + $this->template->set_var('lang_bcity',lang('Business City')); + $this->template->set_var('bcity',$bcity); + $this->template->set_var('lang_bstate',lang('Business State')); + $this->template->set_var('bstate',$bstate); + $this->template->set_var('lang_bzip',lang('Business Zip Code')); + $this->template->set_var('bzip',$bzip); + $this->template->set_var('lang_bcountry',lang('Business Country')); + $this->template->set_var('bcountry',$bcountry); + if ($countrylist) + { + $this->template->set_var('bcountry',$phpgw->country->form_select($bcountry,'entry[bcountry]')); + } + else + { + $this->template->set_var('bcountry',''); + } + $this->template->set_var('lang_badrtype',lang('Address Type')); + $this->template->set_var('badrtype',$badrtype); + + $this->template->set_var('lang_hphone',lang('Home Phone')); + $this->template->set_var('hphone',$hphone); + $this->template->set_var('lang_hemail',lang('Home Email')); + $this->template->set_var('hemail',$hemail); + $this->template->set_var('lang_hemail_type',lang('Home EMail Type')); + $this->template->set_var('hemail_type',$hemail_type); + $this->template->set_var('lang_hstreet',lang('Home Street')); + $this->template->set_var('hstreet',$hstreet); + $this->template->set_var('lang_hcity',lang('Home City')); + $this->template->set_var('hcity',$hcity); + $this->template->set_var('lang_hstate',lang('Home State')); + $this->template->set_var('hstate',$hstate); + $this->template->set_var('lang_hzip',lang('Home Zip Code')); + $this->template->set_var('hzip',$hzip); + $this->template->set_var('lang_hcountry',lang('Home Country')); + if ($countrylist) + { + $this->template->set_var('hcountry',$phpgw->country->form_select($hcountry,'entry[hcountry]')); + } + else + { + $this->template->set_var('hcountry',''); + } + $this->template->set_var('lang_hadrtype',lang('Address Type')); + $this->template->set_var('hadrtype',$hadrtype); + + $this->template->set_var('create',$create); + $this->template->set_var('lang_notes',lang('notes')); + $this->template->set_var('notes',$notes); + $this->template->set_var('lang_label',lang('label')); + $this->template->set_var('label',$label); + $this->template->set_var('lang_pubkey',lang('Public Key')); + $this->template->set_var('pubkey',$pubkey); + $this->template->set_var('access_check',$access_check); + + $this->template->set_var('lang_private',lang('Private')); + + $this->template->set_var('lang_cats',lang('Category')); + $this->template->set_var('cats_link',$cats_link); + if ($customfields) + { + $this->template->set_var('lang_custom',lang('Custom Fields').':'); + $this->template->set_var('custom',$custom); + } + else + { + $this->template->set_var('lang_custom',''); + $this->template->set_var('custom',''); + } + $this->template->set_var('th_bg',$phpgw_info['theme']['th_bg']); + $this->template->set_var('th_text',$phpgw_info['theme']['th_text']); + $this->template->set_var('row_on',$phpgw_info['theme']['row_on']); + $this->template->set_var('row_off',$phpgw_info['theme']['row_off']); + $this->template->set_var('row_text',$phpgw_info['theme']['row_text']); + + $this->template->pfp('out','form'); + } //end form function + + function add() + { + global $phpgw,$phpgw_info,$referer; + + $this->template->set_file(array('add' => 'add.tpl')); + + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + $this->addressbook_form('','menuaction=addressbook.boaddressbook.add_entry','Add','',$customfields,$this->cat_id); + + $this->template->set_var('lang_ok',lang('ok')); + $this->template->set_var('lang_clear',lang('clear')); + $this->template->set_var('lang_cancel',lang('cancel')); + $this->template->set_var('cancel_url',$phpgw->link('/addressbook/main.php','menuaction=addressbook.uiaddressbook.get_list')); + $this->template->parse('out','add'); + $this->template->pparse('out','add'); + + $phpgw->common->phpgw_footer(); + } + + function edit() + { + global $phpgw,$phpgw_info,$ab_id,$referer; + + /* First, make sure they have permission to this entry */ + $check = $this->bo->read_entry($ab_id,array('owner' => 'owner', 'tid' => 'tid')); + + if ( !$this->contacts->check_perms($this->contacts->grants[$check[0]['owner']],PHPGW_ACL_EDIT) && ($check[0]['owner'] != $phpgw_info['user']['account_id']) ) + { + Header("Location: " . $phpgw->link('/addressbook/main.php','menuaction=addressbook.uiaddressbook.get_list')); + $phpgw->common->phpgw_exit(); + } + + if (!$ab_id) + { + Header("Location: " . $phpgw->link('/addressbook/main.php','menuaction=addressbook.uiaddressbook.get_list')); + $phpgw->common->phpgw_exit(); + } + + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + /* Read in user custom fields, if any */ + $customfields = $this->read_custom_fields(); + + /* merge in extra fields */ + $qfields = $this->contacts->stock_contact_fields + $this->extrafields + $customfields; + $fields = $this->bo->read_entry($ab_id,$qfields); + $this->addressbook_form('edit','menuaction=addressbook.boaddressbook.update_entry',lang('Edit'),$fields[0],$customfields); + + $this->template->set_file(array('edit' => 'edit.tpl')); + + $this->template->set_var('th_bg',$phpgw_info['theme']['th_bg']); + $this->template->set_var('ab_id',$ab_id); + $this->template->set_var('tid',$check[0]['tid']); + $this->template->set_var('referer',$referer); + $this->template->set_var('lang_ok',lang('ok')); + $this->template->set_var('lang_clear',lang('clear')); + $this->template->set_var('lang_cancel',lang('cancel')); + $this->template->set_var('lang_submit',lang('submit')); + $this->template->set_var('cancel_link',''); + + if (($this->contacts->grants[$check[0]['owner']] & PHPGW_ACL_DELETE) || $check[0]['owner'] == $phpgw_info['user']['account_id']) + { + $this->template->set_var('delete_link',''); + $this->template->set_var('delete_button',''); + } + + $this->template->pfp('out','edit'); + $phpgw->common->phpgw_footer(); + } + + function view() + { + global $phpgw,$phpgw_info,$ab_id,$submit,$referer; + + // First, make sure they have permission to this entry + $check = $this->bo->read_entry($ab_id,array('owner' => 'owner')); + $perms = $this->contacts->check_perms($this->contacts->grants[$check[0]['owner']],PHPGW_ACL_READ); + + if ( (!$perms) && ($check[0]['owner'] != $phpgw_info['user']['account_id']) ) + { + Header("Location: " . $phpgw->link('/addressbook/main.php','menuaction=addressbook.uiaddressbook.get_list')); + $phpgw->common->phpgw_exit(); + } + + if (!$ab_id) + { + Header("Location: " . $phpgw->link('/addressbook/main.php','menuaction=addressbook.uiaddressbook.get_list')); + $phpgw->common->phpgw_exit(); + } + elseif (!$submit && $ab_id) + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + } + + $this->template->set_file(array('view_t' => 'view.tpl')); + $this->template->set_block('view_t','view_header','view_header'); + $this->template->set_block('view_t','view_row','view_row'); + $this->template->set_block('view_t','view_footer','view_footer'); + $this->template->set_block('view_t','view_buttons','view_buttons'); + + $customfields = $this->read_custom_fields(); + + while ($column = each($this->contacts->stock_contact_fields)) + { + if (isset($this->prefs[$column[0]]) && $this->prefs[$column[0]]) + { + $columns_to_display[$column[0]] = True; + $colname[$column[0]] = $column[0]; + } + } + + // No prefs? + if (!$columns_to_display ) + { + $columns_to_display = array( + 'n_given' => 'n_given', + 'n_family' => 'n_family', + 'org_name' => 'org_name', + 'tel_work' => 'tel_work', + 'tel_home' => 'tel_home', + 'email' => 'email', + 'email_home' => 'email_home' + ); + while ($column = each($columns_to_display)) + { + $colname[$column[0]] = $column[1]; + } + $noprefs = " - " . lang('Please set your preferences for this app'); + } + + /* merge in extra fields */ + $qfields = $this->contacts->stock_contact_fields + $this->extrafields + $customfields; + + $fields = $this->bo->read_entry($ab_id,$qfields); + + $record_owner = $fields[0]['owner']; + + if ($fields[0]["access"] == 'private') + { + $access_check = lang('private'); + } + else + { + $access_check = lang('public'); + } + + $this->template->set_var('lang_viewpref',lang("Address book - view") . $noprefs); + + @reset($qfields); + while (list($column,$null) = @each($qfields)) + { + if($this->display_name($colname[$column])) + { + $this->template->set_var('display_col',$this->display_name($colname[$column])); + } + elseif($this->display_name($column)) + { + $this->template->set_var('display_col',$this->display_name($column)); + } + else + { + $this->template->set_var('display_col',ucfirst($column)); + } + $ref = $data = ""; + if ($fields[0][$column]) + { + $tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color); + $this->template->set_var('th_bg',$tr_color); + $coldata = $fields[0][$column]; + /* Some fields require special formatting. */ + if ( ($column == 'note' || $column == 'pubkey') && $coldata ) + { + $datarray = explode ("\n",$coldata); + if ($datarray[1]) + { + while (list($key,$info) = each ($datarray)) + { + if ($key) + { + $data .= ' ' .$info; + } + else + { + /* First row, don't close td/tr */ + $data .= $info; + } + } + $data .= ""; + } + else + { + $data = $coldata; + } + } + elseif($column == 'label' && $coldata) + { + $data .= $this->contacts->formatted_address($fields[0]['id'],'',False); + } + elseif ($column == "url" && $coldata) + { + $ref = ''; + $data = $coldata . ''; + } + elseif ( (($column == "email") || ($column == "email_home")) && $coldata) + { + if ($phpgw_info["user"]["apps"]["email"]) + { + $ref=''; + } + else + { + $ref = ''; + } + $data = $coldata.""; + } + else + { + /* But these do not */ + $ref = ""; $data = $coldata; + } + + if (!$data) + { + $this->template->set_var('ref_data'," "); + } + else + { + $this->template->set_var('ref_data',$ref . $data); + } + $this->template->parse('cols','view_row',True); + } + } + /* Following cleans up view_row, since we were only using it to fill {cols} */ + $this->template->set_var('view_row',''); + + $fields['cat_id'] = is_array($this->cat_id) ? implode(',',$this->cat_id) : $this->cat_id; + + $cats = explode(',',$fields[0]['cat_id']); + if ($cats[1]) + { + while (list($key,$contactscat) = each($cats)) + { + if ($contactscat) + { + $catinfo = $this->cat->return_single($contactscat); + $catname .= $catinfo[0]['name'] . '; '; + } + } + if (!$this->cat_id) + { + $this->cat_id = $cats[0]; + } + } + else + { + $fields[0]['cat_id'] = ereg_replace(',','',$fields[0]['cat_id']); + $catinfo = $this->cat->return_single($fields[0]['cat_id']); + $catname = $catinfo[0]['name']; + if (!$this->cat_id) + { + $this->cat_id = $fields[0]['cat_id']; + } + } + + if (!$catname) { $catname = lang('none'); } + + // These are in the footer + $this->template->set_var('lang_owner',lang('Record owner')); + $this->template->set_var('owner',$phpgw->common->grab_owner_name($record_owner)); + $this->template->set_var('lang_access',lang("Record access")); + $this->template->set_var('access',$access_check); + $this->template->set_var('lang_category',lang('Category')); + $this->template->set_var('catname',$catname); + + if (($this->contacts->grants[$record_owner] & PHPGW_ACL_EDIT) || ($record_owner == $phpgw_info['user']['account_id'])) + { + $extra_vars = array('cd' => 16,'query' => $this->query,'cat_id' => $this->cat_id); + + if ($referer) $extra_vars += array( 'referer' => urlencode($referer)); + + $this->template->set_var('edit_button',$this->html_1button_form('edit','Edit',array(),'/addressbook/main.php','menuaction=addressbook.uiaddressbook.edit&ab_id=' .$ab_id)); + } + $this->template->set_var('copy_button',$this->html_1button_form('submit','copy',array(), + '/addressbook/main.php','menuaction=addressbook.boaddressbook.copy_entry&ab_id=' . $fields[0]['id'])); + + if ($fields[0]['n_family'] && $fields[0]['n_given']) + { + $this->template->set_var('vcard_button',$this->html_1button_form('VCardForm','VCard',array(),'/addressbook/main.php','menuaction=addressbook.uivcard.out&ab_id=' .$ab_id)); + } + else + { + $this->template->set_var('vcard_button',lang('no vcard')); + } + + $this->template->set_var('done_button',$this->html_1button_form('DoneForm','Done',array(), + $referer ? ereg_replace('/phpgroupware','',$referer) : '/addressbook/main.php','menuaction=addressbook.uiaddressbook.get_list')); + $this->template->set_var('access_link',$access_link); + + $this->template->pfp('out','view_t'); + + $phpgw->common->phpgw_footer(); + } + + function html_input_hidden($vars) + { + if (!is_array($vars)) { return ''; } + while (list($name,$value) = each($vars)) + { + if ($value != '') // dont need to send all the empty vars + { + $html .= '' . "\n"; + } + } + return $html; + } + + function html_submit_button($name,$lang) + { + return '' . "\n"; + } + + function phpgw_link($url,$vars='') + { + global $phpgw; + if (is_array( $vars )) + { + while(list($name,$value) = each($vars)) + { + if ($value != '') // dont need to send all the empty vars + { + $v[] = "$name=$value"; + } + } + $vars = implode('&',$v); + } + return $phpgw->link($url,$vars); + } + + function html_1button_form($name,$lang,$hidden_vars,$url,$url_vars='',$method='POST') + { + $html = "phpgw_link($url,$url_vars)."\">\n"; + $html .= $this->html_input_hidden($hidden_vars); + $html .= $this->html_submit_button($name,$lang); + $html .= "\n"; + return $html; + } + } +?> diff --git a/addressbook/inc/class.uivcard.inc.php b/addressbook/inc/class.uivcard.inc.php new file mode 100644 index 0000000000..0e01acc57b --- /dev/null +++ b/addressbook/inc/class.uivcard.inc.php @@ -0,0 +1,197 @@ + and * + * Miles Lott * + * -------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 2 of the License, or (at your * + * option) any later version. * + \**************************************************************************/ + + /* $Id$ */ + + class uivcard + { + var $template; + var $contacts; + var $browser; + var $vcard; + var $bo; + + var $public_functions = array( + 'in' => True, + 'out' => True + ); + + var $extrafields = array( + 'ophone' => 'ophone', + 'address2' => 'address2', + 'address3' => 'address3' + ); + + function uivcard() + { + global $phpgw; + $this->template = &$phpgw->template; + $this->contacts = &$phpgw->contacts; + $this->browser = CreateObject('phpgwapi.browser'); + $this->vcard = CreateObject('phpgwapi.vcard'); + $this->bo = CreateObject('addressbook.boaddressbook',True); + } + + function in() + { + global $phpgw,$phpgw_info,$action; + + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + echo ''; + + if ($action == 'GetFile') + { + echo '
' . lang('You must select a vcard. (*.vcf)') . '


'; + } + + $this->template->set_file(array('vcardin' => 'vcardin.tpl')); + + $this->template->set_var('vcard_header','

 ' . lang('Address book - VCard in') . '


'); + $this->template->set_var('action_url',$phpgw->link('/addressbook/main.php','menuaction=addressbook.boaddressbook.add_vcard')); + $this->template->set_var('lang_access',lang('Access')); + $this->template->set_var('lang_groups',lang('Which groups')); + $this->template->set_var('access_option',$access_option); + $this->template->set_var('group_option',$group_option); + + $this->template->pparse('out','vcardin'); + + $phpgw->common->phpgw_footer(); + } + + function out() + { + global $phpgw,$phpgw_info,$ab_id; + + if ($nolname || $nofname) + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + } + + if (!$ab_id) + { + Header('Location: ' . $phpgw->link('/addressbook/index.php')); + $phpgw->common->phpgw_exit(); + } + + // First, make sure they have permission to this entry + $check = $this->bo->read_entry($ab_id,array('owner' => 'owner')); + $perms = $this->contacts->check_perms($this->contacts->grants[$check[0]['owner']],PHPGW_ACL_READ); + + if ( (!$perms) && ($check[0]['owner'] != $phpgw_info['user']['account_id']) ) + { + Header("Location: " . $phpgw->link('/addressbook/main.php','menuaction=addressbook.uiaddressbook.get_list')); + $phpgw->common->phpgw_exit(); + } + + $extrafields = array('address2' => 'address2'); + $qfields = $this->contacts->stock_contact_fields + $extrafields; + + $fieldlist = $this->bo->read_entry($ab_id,$qfields); + $fields = $fieldlist[0]; + + $email = $fields['email']; + $emailtype = $fields['email_type']; + if (!$emailtype) + { + $fields['email_type'] = 'INTERNET'; + } + $hemail = $fields['email_home']; + $hemailtype = $fields['email_home_type']; + if (!$hemailtype) + { + $fields['email_home_type'] = 'INTERNET'; + } + $firstname = $fields['n_given']; + $lastname = $fields['n_family']; + + if(!$nolname && !$nofname) + { + /* First name and last must be in the vcard. */ + if($lastname == '') + { + /* Run away here. */ + Header('Location: ' . $phpgw->link('/addressbook/main.php',"menuaction=addressbook.uivcard.out&nolname=1&ab_id=$ab_id")); + } + if($firstname == '') + { + Header('Location: ' . $phpgw->link('/addressbook/main.php',"menuaction=addressbook.uivcard.out&nofname=1&ab_id=$ab_id")); + } + + if ($email) + { + $fn = explode('@',$email); + $filename = sprintf("%s.vcf", $fn[0]); + } + elseif ($hemail) + { + $fn = explode('@',$hemail); + $filename = sprintf("%s.vcf", $fn[0]); + } + else + { + $fn = strtolower($firstname); + $filename = sprintf("%s.vcf", $fn); + } + + // set translation variable + $myexport = $this->vcard->export; + // check that each $fields exists in the export array and + // set a new array to equal the translation and original value + while( list($name,$value) = each($fields) ) + { + if ($myexport[$name] && ($value != "") ) + { + //echo '
'.$name."=".$fields[$name]."\n"; + $buffer[$myexport[$name]] = $value; + } + } + + // create a vcard from this translated array + $entry = $this->vcard->out($buffer); + // print it using browser class for headers + // filename, mimetype, no length, default nocache True + $this->browser->content_header($filename,'text/x-vcard'); + echo $entry; + $phpgw->common->exit; + } /* !nolname && !nofname */ + + if($nofname) + { + echo '

'; + echo lang("This person's first name was not in the address book.") .'
'; + echo lang('Vcards require a first name entry.') . '

'; + echo '' . lang('OK') . ''; + echo '
'; + } + + if($nolname) + { + echo '

'; + echo lang("This person's last name was not in the address book.") . '
'; + echo lang('Vcards require a last name entry.') . '

'; + echo '' . lang('OK') . ''; + echo '
'; + } + + if($nolname || $nofname) + { + $phpgw->common->phpgw_footer(); + } + } + } +?> diff --git a/addressbook/inc/contacts.readme.txt b/addressbook/inc/contacts.readme.txt deleted file mode 100644 index 92ec92020a..0000000000 --- a/addressbook/inc/contacts.readme.txt +++ /dev/null @@ -1,244 +0,0 @@ - /**************************************************************************\ - * phpGroupWare API - Contacts class documentation * - * This file written by Miles Lott * - * -------------------------------------------------------------------------* - * 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$ */ - - -Starting with the most cumbersome function: - -function read($start,$offset,$fields,$query="",$filter="",$sort="",$order="") - - Purpose: - Returns a list of contacts based on limits, query, and filter, - in an array of name/values, e.g.: - - $fields[0]["id"] => "354", - $fields[0]["email"] => "name@domain.com", ... - - $fields[1]["id"] => "355", - $fields[1]["email"] => "othername@otherdomain.com", ... - - Inputs: - - $start = start of list, e.g. 1,16,31 - $offset = numrows, e.g. 15,30,etc. from nextmatchs, usually - $fields = simple array of fields to return: - - $qfields = array( - 'id' => 'id', - 'n_given' => 'n_given - ); - - $query = simple string to search for, e.g. "milosch" or "555" - - $filter = for 'accounting' fields other than id (use read_single_entry for - that): - - owner = account_id of record owner - access = public/private - cat_id = category id for the record - lid = account_lid for account records stored here, if any - tid = type id: - n = normal contact - almost always use this - p = profiles for hr, tied to account records - u = user account, if stored in contacts class - g = group account, "" - - Filters should be in the format: - - example 1: 'tid=n' filter for normal contacts - example 2: 'tid=u,lid=milosch' filter user accounts for lid - 'milosch' - etc... - - $sort = ASC, DESC, or "" (defaults to ASC) - - $order = sort on this field, e.g. n_given - - -function read_single_entry($id,$fields) - - Purpose: - returns a single array of name/value based on id - and field selection, e.g.: - - $fields[0]["email"] => "name@domain.com" - $fields[0]["n_given"] => "Bob" - - Inputs: - - $id = id of entry you want to return - - $fields = simple array of fields to return - - $qfields = array( - 'id' => 'id', - 'n_given' => 'n_given - ); - - -function add($owner,$fields,$access='',$cat_id='',$tid='n') - - Purpose: - - Add a new contact record of the type, category and access sent - with a field list. - - Inputs: - - $owner = id of user adding this data - - $fields = simple array of fields to write into the new record - - $access = public/private - - $cat_id = category id for the record, if desired - - $tid = type id ( see read() above ), defaults to 'n' - - -function update($id,$owner,$fields,$access='',$cat_id='',$tid='') - - Purpose: - - Update an entry already in the contacts list - - Inputs: - - $id = id of entry you want to update - - $owner = id of user modifying this data - - $fields = simple array of fields to update in the record - (see examples above) - - $access = public/private - - $cat_id = category id for the record, if desired - - - $tid = type id ( see read() above ), defaults to 'n' - - -function delete_($id) - - Purpose: - - Delete an entry already in the contacts list - - Inputs: - - $id = id of entry you want to delete - - -Stock contact fields, other than accounting fields mentioned above: - - $this->stock_contact_fields = array( - "fn" => "fn", // 'prefix given middle family suffix' - "n_given" => "n_given", // firstname - "n_family" => "n_family", // lastname - "n_middle" => "n_middle", - "n_prefix" => "n_prefix", - "n_suffix" => "n_suffix", - "sound" => "sound", - "bday" => "bday", // Birthday (12/31/1969) - "note" => "note", // Note, description, etc. - "tz" => "tz", // Hours offset from phpgw install - "geo" => "geo", // Not used - "url" => "url", - "pubkey" => "pubkey", // Similar to note, but for public encryption key - - "org_name" => "org_name", // company - "org_unit" => "org_unit", // division - "title" => "title", - - "adr_one_street" => "adr_one_street", // Business address entry - "adr_one_locality" => "adr_one_locality", - "adr_one_region" => "adr_one_region", - "adr_one_postalcode" => "adr_one_postalcode", - "adr_one_countryname" => "adr_one_countryname", - "adr_one_type" => "adr_one_type", // address is domestic/intl/postal/parcel/work/home - "label" => "label", // address label - - "adr_two_street" => "adr_two_street", // Home address entry - "adr_two_locality" => "adr_two_locality", - "adr_two_region" => "adr_two_region", - "adr_two_postalcode" => "adr_two_postalcode", - "adr_two_countryname" => "adr_two_countryname", - "adr_two_type" => "adr_two_type", // address is domestic/intl/postal/parcel/work/home - - "tel_work" => "tel_work", - "tel_home" => "tel_home", - "tel_voice" => "tel_voice", - "tel_fax" => "tel_fax", - "tel_msg" => "tel_msg", - "tel_cell" => "tel_cell", - "tel_pager" => "tel_pager", - "tel_bbs" => "tel_bbs", - "tel_modem" => "tel_modem", - "tel_car" => "tel_car", - "tel_isdn" => "tel_isdn", - "tel_video" => "tel_video", - "tel_prefer" => "tel_prefer", // home;work;voice - "email" => "email", - "email_type" => "email_type", //'INTERNET','CompuServe',etc... - "email_home" => "email_home", - "email_home_type" => "email_home_type" //'INTERNET','CompuServe',etc... - ); - -Other useful arrays for setting option dialogs, etc. - - // Used to set adr_one_type/adr_two_type, e.g. 'intl;work' - $this->adr_types = array( - "dom" => lang("Domestic"), - "intl" => lang("International"), - "parcel" => lang("Parcel"), - "postal" => lang("Postal") - ); - - // Used to set preferred number field, e.g. 'cell' or 'work' - $this->tel_types = array( - "work" => "work", - "home" => "home", - "voice" => "voice", - "fax" => "fax", - "msg" => "msg", - "cell" => "cell", - "pager" => "pager", - "bbs" => "bbs", - "modem" => "modem", - "car" => "car", - "isdn" => "isdn", - "video" => "video" - ); - - $this->email_types = array( - "INTERNET" => "INTERNET", - "CompuServe" => "CompuServe", - "AOL" => "AOL", - "Prodigy" => "Prodigy", - "eWorld" => "eWorld", - "AppleLink" => "AppleLink", - "AppleTalk" => "AppleTalk", - "PowerShare" => "PowerShare", - "IBMMail" => "IBMMail", - "ATTMail" => "ATTMail", - "MCIMail" => "MCIMail", - "X.400" => "X.400", - "TLX" => "TLX" - ); - diff --git a/addressbook/inc/functions.inc.php b/addressbook/inc/functions.inc.php index bfef191b8f..1bd3cd5cb4 100755 --- a/addressbook/inc/functions.inc.php +++ b/addressbook/inc/functions.inc.php @@ -1,21 +1,19 @@ * -* -------------------------------------------- * -* This program is free software; you can redistribute it and/or modify it * -* under the terms of the GNU General Public License as published by the * -* Free Software Foundation; either version 2 of the License, or (at your * -* option) any later version. * -\**************************************************************************/ + /**************************************************************************\ + * phpGroupWare - addressbook * + * http://www.phpgroupware.org * + * Written by Joseph Engo * + * -------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 2 of the License, or (at your * + * option) any later version. * + \**************************************************************************/ -/* $Id$ */ - - // I don't think this is needed anymore - - // Perform acl check, set $rights + /* $Id$ */ + /* I don't think this is needed anymore */ + /* Perform acl check, set $rights */ if(!isset($owner)) { $owner = 0; } $grants = $phpgw->acl->get_grants('addressbook'); @@ -38,7 +36,6 @@ } } - /* Generic formatted list function */ function formatted_list($name,$list,$id='',$default=False,$java=False) { if ($java) @@ -67,61 +64,16 @@ return $select; } - function read_custom_fields($start='',$limit='',$query='',$sort='ASC') - { - global $phpgw,$phpgw_info; - $phpgw->preferences->read_repository($phpgw_info['user']['account_id']); - - $i=0;$j=0; - while (list($col,$descr) = @each($phpgw_info["user"]["preferences"]["addressbook"])) - { - if ( substr($col,0,6) == 'extra_' ) - { - $fields[$j]['name'] = ereg_replace('extra_','',$col); - $fields[$j]['name'] = ereg_replace(' ','_',$fields[$j]['name']); - $fields[$j]['id'] = $i; - - if ($query && ($fields[$j]['name'] != $query)) - { - unset($fields[$j]['name']); - unset($fields[$j]['id']); - } - else - { - //echo "
".$j.": '".$fields[$j]['name']."'"; - $j++; - } - } - $i++; - } - return $fields; - } - - function save_custom_field($old='',$new='') - { - global $phpgw,$phpgw_info; - - $phpgw->preferences->read_repository($phpgw_info['user']['account_id']); - if ($old) - { - $phpgw->preferences->delete("addressbook","extra_".$old); - } - if($new) - { - $phpgw->preferences->add("addressbook","extra_".$new); - } - $phpgw->preferences->save_repository(1); - } - /* Return a select form element with the categories option dialog in it */ function cat_option($cat_id='',$notall=False,$java=True,$multiple=False) { - global $phpgw_info; + global $phpgw; + if ($java) { $jselect = ' onChange="this.form.submit();"'; } - // Setup all and none first + /* Setup all and none first */ $cats_link = "\n" .''."\n"; return $cats_link; } - /* SET THE FONT TO DEFAULT IF IT DOESNT EXISTS */ - function set_font() - { - if($phpgw_info['user']['preferences']['notes']['notes_font'] == '') - { - $font = "Arial"; - return $font; - } - else - { - $font = $phpgw_info['user']['preferences']['notes']['notes_font']; - return $font; - } - } - - /* SET FONT SIZE */ - function set_font_size() - { - if($phpgw_info['user']['preferences']['notes']['notes_font_size'] == '') - { - $font_size = "3"; - return $font_size; - } - else - { - $font_size = $phpgw_info['user']['preferences']['notes']['notes_font_size']; - return $font_size; - } - } - - // this cleans up the fieldnames for display + /* this cleans up the fieldnames for preferences */ function display_name($column) { $abc = array( @@ -211,7 +132,6 @@ 'tel_isdn' => 'isdn phone', 'tel_car' => 'car phone', 'tel_video' => 'video phone', - 'tel_prefer' => 'preferred phone', 'email' => 'business email', 'email_type' => 'business email type', @@ -225,7 +145,7 @@ 'pubkey' => 'public key', 'note' => 'notes' ); - + if ($abc[$column]) { return lang($abc[$column]); @@ -236,855 +156,4 @@ } } - function addressbook_strip_html($dirty = '') - { - global $phpgw; - if ($dirty == ""){$dirty = array();} - for($i=0;$istrip_html($dirty[$i][$name]); - } - } - return $cleaned; - } - - function addressbook_read_entries($start,$offset,$qcols,$query,$qfilter,$sort,$order,$userid='') - { - global $contacts,$rights; - $readrights = $rights & PHPGW_ACL_READ; - $entries = $contacts->read($start,$offset,$qcols,$query,$qfilter,$sort,$order,$readrights); - $cleaned = addressbook_strip_html($entries); - return $cleaned; - } - - function addressbook_read_entry($id,$fields,$userid='') - { - global $contacts,$rights; - if ($rights & PHPGW_ACL_READ) - { - $entry = $contacts->read_single_entry($id,$fields); - $cleaned = addressbook_strip_html($entry); - return $cleaned; - } - else - { - $rtrn = array('No access' => 'No access'); - return $rtrn; - } - } - - function addressbook_read_last_entry($fields) - { - global $contacts,$rights; - if ($rights & PHPGW_ACL_READ) - { - $entry = $contacts->read_last_entry($fields); - $cleaned = addressbook_strip_html($entry); - return $cleaned; - } - else - { - $rtrn = array('No access' => 'No access'); - return $rtrn; - } - } - - function addressbook_add_entry($userid,$fields,$access='',$cat_id='',$tid='n') - { - global $contacts,$rights; - if ($rights & PHPGW_ACL_ADD) - { - $contacts->add($userid,$fields,$access,$cat_id,$tid); - } - return; - } - - function addressbook_get_lastid() - { - global $contacts; - $entry = $contacts->read_last_entry(); - $ab_id = $entry[0]['id']; - return $ab_id; - } - - function addressbook_update_entry($id,$userid,$fields,$access,$cat_id) - { - global $contacts,$rights; - if ($rights & PHPGW_ACL_EDIT) - { - $contacts->update($id,$userid,$fields,$access,$cat_id); - } - return; - } - - // Folowing used for add/edit - function addressbook_form($format,$action,$title='',$fields='',$customfields='',$cat_id='') - { - global $phpgw,$phpgw_info,$referer; - - $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); - $t->set_file(array('form' => 'form.tpl')); - //$t->set_block('form','add','add'); - //$t->set_block('form','edit','edit'); - - if ( ($phpgw_info['server']['countrylist'] == 'user_choice' && - $phpgw_info['user']['preferences']['common']['countrylist'] == 'use_select') || - ($phpgw_info['server']['countrylist'] == 'force_select')) - { - $countrylist = True; - } - - $email = $fields['email']; - $emailtype = $fields['email_type']; - $hemail = $fields['email_home']; - $hemailtype = $fields['email_home_type']; - $firstname = $fields['n_given']; - $middle = $fields['n_middle']; - $prefix = $fields['n_prefix']; - $suffix = $fields['n_suffix']; - $lastname = $fields['n_family']; - $title = $fields['title']; - $wphone = $fields['tel_work']; - $hphone = $fields['tel_home']; - $fax = $fields['tel_fax']; - $pager = $fields['tel_pager']; - $mphone = $fields['tel_cell']; - $ophone = $fields['ophone']; - $msgphone = $fields['tel_msg']; - $isdnphone = $fields['tel_isdn']; - $carphone = $fields['tel_car']; - $vidphone = $fields['tel_video']; - $preferred = $fields['tel_prefer']; - - $bstreet = $fields['adr_one_street']; - $address2 = $fields['address2']; - $address3 = $fields['address3']; - $bcity = $fields['adr_one_locality']; - $bstate = $fields['adr_one_region']; - $bzip = $fields['adr_one_postalcode']; - $bcountry = $fields['adr_one_countryname']; - $one_dom = $fields['one_dom']; - $one_intl = $fields['one_intl']; - $one_parcel = $fields['one_parcel']; - $one_postal = $fields['one_postal']; - - $hstreet = $fields['adr_two_street']; - $hcity = $fields['adr_two_locality']; - $hstate = $fields['adr_two_region']; - $hzip = $fields['adr_two_postalcode']; - $hcountry = $fields['adr_two_countryname']; - $btype = $fields['adr_two_type']; - $two_dom = $fields['two_dom']; - $two_intl = $fields['two_intl']; - $two_parcel = $fields['two_parcel']; - $two_postal = $fields['two_postal']; - - $timezone = $fields['tz']; - $bday = $fields['bday']; - $notes = stripslashes($fields['note']); - $label = stripslashes($fields['label']); - $company = $fields['org_name']; - $department = $fields['org_unit']; - $url = $fields['url']; - $pubkey = $fields['pubkey']; - $access = $fields['access']; - if(!$cat_id) { - $cat_id = $fields['cat_id']; - } - /* allow multiple categories on sql */ - $cats_link = cat_option( - $cat_id, - True, - False, - !$phpgw_info['server']['contact_repository'] || $phpgw_info['server']['contact_repository'] == 'sql' - ); - - if ($access == 'private') - { - $access_check = ' checked'; - } - else - { - $access_check = ''; - } - - if ($customfields) - { - while(list($name,$value) = each($customfields)) - { - $value = ereg_replace('_',' ',$value); - $custom .= ' - -   - '.$value.': - - -'; - } - } - - $c = CreateObject("phpgwapi.contacts"); - - if ($format != "view") - { - // Preferred phone number radio buttons - $pref[0] = ""; - $pref[1] = "(".lang('pref').")"; - while (list($name,$val) = each($c->tel_types)) - { - $str[$name] = "\n".' set_var("pref_".$name,$str[$name]); - } - - if (strlen($bday) > 2) - { - list( $month, $day, $year ) = split( '/', $bday ); - $temp_month[$month] = "SELECTED"; - $bday_month = ""; - $bday_day = ''; - $bday_year = ''; - } - else - { - $bday_month = ""; - $bday_day = ''; - $bday_year = ''; - } - - $time_zone = ""; - - reset($c->email_types); - $hemail_type = '"; - - reset($c->adr_types); - while (list($type,$val) = each($c->adr_types)) - { - $badrtype .= "\n".'adr_types); - while (list($type,$val) = each($c->adr_types)) - { - $hadrtype .= "\n".''; - $label = ''; - $pubkey = ''; - } - else - { - $notes = "
"; - if ($bday == "//") - { - $bday = ""; - } - } - - if ($action) - { - echo '
'; - } - - if (!ereg("^http://",$url)) - { - $url = "http://". $url; - } - - $birthday = $phpgw->common->dateformatorder($bday_year,$bday_month,$bday_day) - . '(e.g. 1969)'; - if ($format == 'edit') - { - $create .= '' . lang("Created by") . ':' - . '' - . $phpgw->common->grab_owner_name($fields["owner"]); - } - else - { - $create .= ''; - } - - $t->set_var('lang_home',lang('Home')); - $t->set_var('lang_business',lang('Business')); - $t->set_var('lang_personal',lang('Personal')); - - $t->set_var('lang_lastname',lang('Last Name')); - $t->set_var('lastname',$lastname); - $t->set_var('lang_firstname',lang('First Name')); - $t->set_var('firstname',$firstname); - $t->set_var('lang_middle',lang('Middle Name')); - $t->set_var('middle',$middle); - $t->set_var('lang_prefix',lang('Prefix')); - $t->set_var('prefix',$prefix); - $t->set_var('lang_suffix',lang('Suffix')); - $t->set_var('suffix',$suffix); - $t->set_var('lang_birthday',lang('Birthday')); - $t->set_var('birthday',$birthday); - - $t->set_var('lang_company',lang('Company Name')); - $t->set_var('company',$company); - $t->set_var('lang_department',lang('Department')); - $t->set_var('department',$department); - $t->set_var('lang_title',lang('Title')); - $t->set_var('title',$title); - $t->set_var('lang_email',lang('Business Email')); - $t->set_var('email',$email); - $t->set_var('lang_email_type',lang('Business EMail Type')); - $t->set_var('email_type',$email_type); - $t->set_var('lang_url',lang('URL')); - $t->set_var('url',$url); - $t->set_var('lang_timezone',lang('time zone offset')); - $t->set_var('timezone',$time_zone); - $t->set_var('lang_fax',lang('Business Fax')); - $t->set_var('fax',$fax); - $t->set_var('lang_wphone',lang('Business Phone')); - $t->set_var('wphone',$wphone); - $t->set_var('lang_pager',lang('Pager')); - $t->set_var('pager',$pager); - $t->set_var('lang_mphone',lang('Cell Phone')); - $t->set_var('mphone',$mphone); - $t->set_var('lang_msgphone',lang('Message Phone')); - $t->set_var('msgphone',$msgphone); - $t->set_var('lang_isdnphone',lang('ISDN Phone')); - $t->set_var('isdnphone',$isdnphone); - $t->set_var('lang_carphone',lang('Car Phone')); - $t->set_var('carphone',$carphone); - $t->set_var('lang_vidphone',lang('Video Phone')); - $t->set_var('vidphone',$vidphone); - - $t->set_var('lang_ophone',lang('Other Number')); - $t->set_var('ophone',$ophone); - $t->set_var('lang_bstreet',lang('Business Street')); - $t->set_var('bstreet',$bstreet); - $t->set_var('lang_address2',lang('Address Line 2')); - $t->set_var('address2',$address2); - $t->set_var('lang_address3',lang('Address Line 3')); - $t->set_var('address3',$address3); - $t->set_var('lang_bcity',lang('Business City')); - $t->set_var('bcity',$bcity); - $t->set_var('lang_bstate',lang('Business State')); - $t->set_var('bstate',$bstate); - $t->set_var('lang_bzip',lang('Business Zip Code')); - $t->set_var('bzip',$bzip); - $t->set_var('lang_bcountry',lang('Business Country')); - $t->set_var('bcountry',$bcountry); - if ($countrylist) - { - $t->set_var('bcountry',$phpgw->country->form_select($bcountry,'bcountry')); - } - else - { - $t->set_var('bcountry',''); - } - $t->set_var('lang_badrtype',lang('Address Type')); - $t->set_var('badrtype',$badrtype); - - $t->set_var('lang_hphone',lang('Home Phone')); - $t->set_var('hphone',$hphone); - $t->set_var('lang_hemail',lang('Home Email')); - $t->set_var('hemail',$hemail); - $t->set_var('lang_hemail_type',lang('Home EMail Type')); - $t->set_var('hemail_type',$hemail_type); - $t->set_var('lang_hstreet',lang('Home Street')); - $t->set_var('hstreet',$hstreet); - $t->set_var('lang_hcity',lang('Home City')); - $t->set_var('hcity',$hcity); - $t->set_var('lang_hstate',lang('Home State')); - $t->set_var('hstate',$hstate); - $t->set_var('lang_hzip',lang('Home Zip Code')); - $t->set_var('hzip',$hzip); - $t->set_var('lang_hcountry',lang('Home Country')); - if ($countrylist) - { - $t->set_var('hcountry',$phpgw->country->form_select($hcountry,'hcountry')); - } - else - { - $t->set_var('hcountry',''); - } - $t->set_var('lang_hadrtype',lang('Address Type')); - $t->set_var('hadrtype',$hadrtype); - - $t->set_var('create',$create); - $t->set_var('lang_notes',lang('notes')); - $t->set_var('notes',$notes); - $t->set_var('lang_label',lang('label')); - $t->set_var('label',$label); - $t->set_var('lang_pubkey',lang('Public Key')); - $t->set_var('pubkey',$pubkey); - $t->set_var('access_check',$access_check); - - $t->set_var('lang_private',lang('Private')); - - $t->set_var('lang_cats',lang('Category')); - $t->set_var('cats_link',$cats_link); - if ($customfields) - { - $t->set_var('lang_custom',lang('Custom Fields').':'); - $t->set_var('custom',$custom); - } - else - { - $t->set_var('lang_custom',''); - $t->set_var('custom',''); - } - $t->set_var('th_bg',$phpgw_info['theme']['th_bg']); - $t->set_var('th_text',$phpgw_info['theme']['th_text']); - $t->set_var('row_on',$phpgw_info['theme']['row_on']); - $t->set_var('row_off',$phpgw_info['theme']['row_off']); - $t->set_var('row_text',$phpgw_info['theme']['row_text']); - - $t->pfp('out','form'); - } //end form function - - function OLDparsevcard($filename,$access='') - { - global $phpgw; - global $phpgw_info; - - $vcard = fopen($filename, 'r'); - // Make sure we have a file to read. - if (!$vcard) { - fclose($vcard); - return FALSE; - } - - // Keep running through this to support vcards - // with multiple entries. - while (!feof($vcard)) { - if(!empty($varray)) - unset($varray); - - // Make sure our file is a vcard. - // I should deal with empty line at the - // begining of the file. Those will fail here. - $vline = fgets($vcard,20); - $vline = strtolower($vline); - if(strcmp("begin:vcard", substr($vline, 0, strlen("begin:vcard")) ) != 0) { - fclose($vcard); - return FALSE; - } - - // Write the vcard into an array. - // You can have multiple vcards in one file. - // I only deal with halve of that. :) - // It will only return values from the 1st vcard. - $varray[0] = "begin"; - $varray[1] = "vcard"; - $i=2; - while(!feof($vcard) && strcmp("end:vcard", strtolower(substr($vline, 0, strlen("end:vcard"))) ) !=0 ) { - $vline = fgets($vcard,4096); - // Check for folded lines and escaped colons '\:' - $la = explode(":", $vline); - - if (count($la) > 1) { - $varray[$i] = strtolower($la[0]); - $i++; - - for($j=1;$j<=count($la);$j++) { - $varray[$i] .= $la[$j]; - } - $i++; - } else { // This is the continuation of a folded line. - $varray[$i-1] .= $la[0]; - } - } - - // Add this entry to the addressbook before moving on to the next one. - fillab($varray); - } // while(!feof($vcard)) - - fclose($vcard); - return TRUE; - } - - - function fillab($varray,$access='') { - global $phpgw; - global $phpgw_info; - - $i=0; - -// while($i < count($varray)) { -// echo '
'.$varray[$i].' %% '.$varray[$i+1]; -// $i++;$i++; -// } -// exit; - // incremented by 2 - while($i < count($varray)) { - $k = explode(";",$varray[$i]); // Key - $v = explode(";",$varray[$i+1]); // Values - for($h=0;$hkh="'.$k[$h].'",v0="'.$v[0].'",v1="'.$v[1].'",v2="'.$v[2].'",v3="'.$v[3].'",v4="'.$v[4].'",v5="'.$v[5].'",v6="'.$v[6].'",v7="'.$v[7].'"'; - switch($k[$h]) { - case "fn": - $fn = $v[0]; - break; - case "n": - $lastname = $v[0]; - $firstname = $v[1]; - break; - case "bday": - $bday = $v[0]; - break; - case "url": - $url = $v[0]; - // Fix the result of exploding on ':' above - if (substr($url,0,5) == 'http/') { - $url = ereg_replace('http//','http://',$url); - } elseif (substr($url,0,6) == 'https/') { - $url = ereg_replace('https//','https://',$url); - } elseif (substr($url,0,7) != 'http://') { - $url = 'http://' . $url; - } - break; - case "label": - $label = $v[0]; - break; - case "adr": // This one is real ugly. Still! :( - if(!$street) { - $street = $v[2]; - $address2 = $v[1] . " " . $v[0]; - $city = $v[3]; - $state = $v[4]; - $zip = $v[5]; - $country = $v[6]; - if (strstr($k[$h+1],"intl")) { $adronetype .= "INTL;"; } - if (strstr($k[$h+1],"dom")) { $adronetype .= "DOM;"; } - } else { - $hstreet = $v[2]; - $hcity = $v[3]; - $hstate = $v[4]; - $hzip = $v[5]; - $hcountry = $v[6]; - if (strstr($k[$h+1],"intl")) { $adrtwotype .= "INTL;"; } - if (strstr($k[$h+1],"dom")) { $adrtwotype .= "DOM;"; } - } - break; - case "tel": - switch ($k[$h+1]) { - case "work": - $wphone = $v[0]; - break; - case "home": - $hphone = $v[0]; - break; - case "cell": - $mphone = $v[0]; - break; - case "pager": - $pager = $v[0]; - break; - case "fax": - $fax = $v[0]; - break; - case "msg": - $msgphone = $v[0]; - break; - case "bbs": - $bbsphone = $v[0]; - break; - case "modem": - $modem = $v[0]; - break; - case "car": - $carphone = $v[0]; - break; - case "isdn": - $isdn = $v[0]; - break; - case "video": - $vidphone = $v[0]; - break; - case "pref": - switch ($k[$h+2]) { - case "work": - $tel_prefer .= "work;"; - $wphone = $v[0]; - break; - case "home": - $tel_prefer .= "home;"; - $hphone = $v[0]; - break; - case "cell": - $tel_prefer .= "cell;"; - $mphone = $v[0]; - break; - case "pager": - $tel_prefer .= "pager;"; - $pager = $v[0]; - break; - case "fax": - $tel_prefer .= "fax;"; - $fax = $v[0]; - break; - case "msg": - $tel_prefer .= "msg;"; - $msgphone = $v[0]; - break; - case "bbs": - $tel_prefer .= "bbs;"; - $bbsphone = $v[0]; - break; - case "modem": - $tel_prefer .= "modem;"; - $modem = $v[0]; - break; - case "car": - $tel_prefer .= "car;"; - $carphone = $v[0]; - break; - case "isdn": - $tel_prefer .= "isdn;"; - $isdn = $v[0]; - break; - case "video": - $tel_prefer .= "video;"; - $vidphone = $v[0]; - break; - } - default: - $whphone = $v[0]; - break; - } - break; - case "email": - if (empty($email)) { $email = $v[0]; } - else { $hemail = $v[0]; } - switch ($k[$h+1]) { - case "compuserve": - if (!$adronetype) { $emailtype="CompuServe"; } - else { $hemailtype="CompuServe"; } - break; - case "aol": - if (!$adronetype) { $emailtype="AOL"; } - else { $hemailtype="AOL"; } - break; - case "prodigy": - if (!$adronetype) { $emailtype="Prodigy"; } - else { $hemailtype="Prodigy"; } - break; - case "eworld": - if (!$adronetype) { $emailtype="eWorld"; } - else { $hemailtype="eWorld"; } - break; - case "applelink": - if (!$adronetype) { $emailtype="AppleLink"; } - else { $hemailtype="AppleLink"; } - break; - case "appletalk": - if (!$adronetype) { $emailtype="AppleTalk"; } - else { $hemailtype="AppleTalk"; } - break; - case "powershare": - if (!$adronetype) { $emailtype="PowerShare"; } - else { $hemailtype="PowerShare"; } - break; - case "ibmmail": - if (!$adronetype) { $emailtype="IBMMail"; } - else { $hemailtype="IBMMail"; } - break; - case "attmail": - if (!$adronetype) { $emailtype="ATTMail"; } - else { $hemailtype="ATTMail"; } - break; - case "mcimail": - if (!$adronetype) { $emailtype="MCIMail"; } - else { $hemailtype="MCIMail"; } - break; - case "x.400": - if (!$adronetype) { $emailtype="X.400"; } - else { $hemailtype="X.400"; } - break; - case "tlx": - if (!$adronetype) { $emailtype="TLX"; } - else { $hemailtype="TLX"; } - break; - default: - if (!$adronetype) { $emailtype="INTERNET"; } - else { $hemailtype="INTERNET"; } - break; - } - break; - case "title": - $title = $v[0]; - break; - case "org": - $company = $v[0]; - if(count($v) > 1) { - $notes .= $v[0] . "\n"; - for($j=1;$jtel_prefer: '.$fields["tel_prefer"]; - echo '
owner: '.$fields["owner"]; - echo '
firstname: '.$fields["n_given"]; - echo '
lastname: '.$fields["n_family"]; - echo '
full name: '.$fields["fn"]; - echo '
title: '.$fields["title"]; - echo '
email: '.$fields["email"]; - echo '
work#: '.$fields["tel_work"]; - echo '
home#: '.$fields["tel_home"]; - echo '
fax#: '.$fields["tel_fax"]; - echo '
pager#: '.$fields["tel_pager"]; - echo '
cell#: '.$fields["tel_cell"]; - echo '
msg#: '.$fields["tel_msg"]; - echo '
car#: '.$fields["tel_car"]; - echo '
modem# '.$fields["tel_modem"]; - echo '
bbs#: '.$fields["tel_bbs"]; - echo '
isdn#: '.$fields["tel_isdn"]; - echo '
video#: '.$fields["tel_video"]; - echo '
street: '.$fields["adr_one_street"]; - echo '
addr2: '.$fields["address2"]; - echo '
city: '.$fields["adr_one_locality"]; - echo '
state: '.$fields["adr_one_region"]; - echo '
zip: '.$fields["adr_one_postalcode"]; - echo '
adronetype: '.$fields["adr_one_type"]; - echo '
bday: '.$fields["bday"]; - echo '
url: '.$fields["url"]; - echo '
note: '.$fields["note"]; - echo '
company: '.$fields["org_name"]; - exit; - */ - $c = CreateObject("phpgwapi.contacts"); - $c->add($phpgw_info["user"]["account_id"],$fields); - } - ?>