forked from extern/egroupware
Import categories when each is in its own column
This commit is contained in:
parent
d966794b8d
commit
d67a265beb
@ -173,6 +173,25 @@ class addressbook_import_contacts_csv implements importexport_iface_import_plugi
|
||||
// Automatically handle text categories without explicit translation
|
||||
$record['cat_id'] = importexport_helper_functions::cat_name2id($record['cat_id']);
|
||||
|
||||
// Also handle categories in their own field
|
||||
$more_categories = array();
|
||||
foreach($_definition->plugin_options['field_mapping'] as $number => $field_name) {
|
||||
if(substr($field_name,0,3) != 'cat' || !$record[$field_name]) continue;
|
||||
list($cat, $cat_id) = explode('-', $field_name);
|
||||
if(is_numeric($record[$field_name]) && $record[$field_name] != 1) {
|
||||
// Column has a single category ID
|
||||
$more_categories[] = $record[$field_name];
|
||||
} elseif($record[$field_name] == '1' ||
|
||||
(!is_numeric($record[$field_name]) && strtolower($record[$field_name]) == strtolower(lang('Yes')))) {
|
||||
// Each category got its own column. '1' is the database value, lang('yes') is the human value
|
||||
$more_categories[] = $cat_id;
|
||||
} else {
|
||||
// Text categories
|
||||
$more_categories = array_merge($more_categories, importexport_helper_functions::cat_name2id(is_array($record[$field_name]) ? $record[$field_name] : explode(',',$record[$field_name])));
|
||||
}
|
||||
}
|
||||
if(count($more_categories) > 0) $record['cat_id'] = array_merge(is_array($record['cat_id']) ? $record['cat_id'] : explode(',',$record['cat_id']), $more_categories);
|
||||
|
||||
if ( $_definition->plugin_options['conditions'] ) {
|
||||
foreach ( $_definition->plugin_options['conditions'] as $condition ) {
|
||||
$contacts = array();
|
||||
|
@ -27,6 +27,26 @@ class addressbook_wizard_import_contacts_csv extends importexport_wizard_basic_i
|
||||
// Field mapping
|
||||
$bocontacts = new addressbook_bo();
|
||||
$this->mapping_fields = $bocontacts->contact_fields;
|
||||
|
||||
$categories = new categories('','addressbook');
|
||||
$cat_list = array();
|
||||
foreach((array)$categories->return_sorted_array(0,False,'','','',true,0,true) as $cat)
|
||||
{
|
||||
$s = str_repeat(' ',$cat['level']) . stripslashes($cat['name']);
|
||||
|
||||
if (categories::is_global($cat))
|
||||
{
|
||||
$s .= ' ♦';
|
||||
}
|
||||
$cat_list['cat-'.$cat['id']] = empty($cat['description']) ? $s : array(
|
||||
'label' => $s,
|
||||
'title' => $cat['description'],
|
||||
);
|
||||
}
|
||||
if(count($cat_list) > 0) {
|
||||
$this->mapping_fields[lang('Categories')] = $cat_list;
|
||||
}
|
||||
|
||||
foreach($bocontacts->customfields as $name => $data) {
|
||||
$this->mapping_fields['#'.$name] = $data['label'];
|
||||
}
|
||||
@ -48,6 +68,9 @@ class addressbook_wizard_import_contacts_csv extends importexport_wizard_basic_i
|
||||
|
||||
function wizard_step50(&$content, &$sel_options, &$readonlys, &$preserv)
|
||||
{
|
||||
if($content['field_mapping'][0] == lang('Categories')) {
|
||||
unset($content['field_mapping'][0]);
|
||||
}
|
||||
$result = parent::wizard_step50($content, $sel_options, $readonlys, $preserv);
|
||||
$content['msg'] .= "\n*" . lang('Contact ID cannot be changed by import');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user