diff --git a/addressbook/csv_import.php b/addressbook/csv_import.php index 4091409d94..c80c1dd77f 100644 --- a/addressbook/csv_import.php +++ b/addressbook/csv_import.php @@ -42,7 +42,7 @@ if (isset($_POST['charset'])) $GLOBALS['egw_info']['flags']['app_header'] = lang('Import CSV-File into Addressbook'); $GLOBALS['egw']->common->egw_header(); -$GLOBALS['egw']->contacts = new contacts(); +$bocontacts = new addressbook_bo(); //$GLOBALS['egw']->template->set_unknowns('keep'); $GLOBALS['egw']->template->set_file(array('import' => 'csv_import.tpl')); @@ -64,24 +64,30 @@ $VPre = '|#'; // Value-Prefix, is expanded to \ for ereg_replace $CPre = '|['; $CPreReg = '\|\['; // |{csv-fieldname} is expanded to the value of the csv-field $CPos = ']'; $CPosReg = '\]'; // if used together with @ (replacement is eval-ed) value gets autom. quoted -// find in Addressbook, at least n_family AND (n_given OR org_name) have to match +/** + * Find contact with at least n_family AND (n_given OR org_name) have to match + * + * @param string $n_family + * @param string $n_given + * @param string $org_name + * @return int|boolean contact id or false if no match + */ function addr_id($n_family,$n_given,$org_name) { - $addrs = $GLOBALS['egw']->contacts->search(array('n_family'=>$n_family,'n_given'=>$n_given,'org_name'=>$org_name)); + global $bocontacts; + $addrs = $bocontacts->search(array('n_family'=>$n_family,'n_given'=>$n_given,'org_name'=>$org_name)); if(!count($addrs)) { - $addrs = $GLOBALS['egw']->contacts->search(array('n_family'=>$n_family,'n_given'=>$n_given)); + $addrs = $bocontacts->search(array('n_family'=>$n_family,'n_given'=>$n_given)); } if(!count($addrs)) { - $addrs = $GLOBALS['egw']->contacts->search(array('n_family'=>$n_family,'org_name'=>$org_name)); + $addrs = $bocontacts->search(array('n_family'=>$n_family,'org_name'=>$org_name)); } - if(count($addrs)) { return $addrs[0]['id']; } - return False; } @@ -131,6 +137,8 @@ switch($_POST['action']) case 'continue': case 'download': $defaults = $GLOBALS['egw_info']['user']['preferences']['addressbook']['cvs_import']; + if (!($unique_id = $GLOBALS['egw_info']['user']['preferences']['addressbook']['cvs_import_unique_id'])) $unique_id = 'id'; + if (!($unique_id2 = $GLOBALS['egw_info']['user']['preferences']['addressbook']['cvs_import_unique_id2'])) $unique_id2 = 'uid'; if(!is_array($defaults)) { $defaults = array(); @@ -144,16 +152,17 @@ switch($_POST['action']) $GLOBALS['egw']->template->set_var('lang_debug',lang('Test Import (show importable records only in browser)')); $GLOBALS['egw']->template->parse('fheaderhandle','fheader'); - $addr_names = $GLOBALS['egw']->contacts->contact_fields; + $addr_names = $bocontacts->contact_fields; $addr_names['cat_id'] .= ': id or name, comma separated list'; $addr_names['private'] .= ': 0 = public, 1 = private'; $addr_names['owner'] .= ': id or account name of user or group, defaults to importing user'; $addr_names['bday'] .= ': YYYY-mm-dd'; + $addr_names['uid'] = lang('Unique ID (UID)'); unset($addr_names['jpegphoto']); // cant cvs import that - foreach($GLOBALS['egw']->contacts->customfields as $name => $data) + foreach($bocontacts->customfields as $name => $data) { - $addr_names['#'.$name] = $data['label']; + $cfs['#'.$name] = $addr_names['#'.$name] = $data['label']; } $addr_name_options = "