diff --git a/importexport/inc/class.importexport_basic_import_csv.inc.php b/importexport/inc/class.importexport_basic_import_csv.inc.php
index 78abab4ff4..05f83cdc55 100644
--- a/importexport/inc/class.importexport_basic_import_csv.inc.php
+++ b/importexport/inc/class.importexport_basic_import_csv.inc.php
@@ -77,6 +77,11 @@ abstract class importexport_basic_import_csv implements importexport_iface_impor
*/
protected $is_admin = false;
+ /**
+ * Select box values for human conversion
+ */
+ protected $lookups = array();
+
/**
* @var int
*/
diff --git a/importexport/inc/class.importexport_export_csv.inc.php b/importexport/inc/class.importexport_export_csv.inc.php
index f2d32c4ca1..922ed1680b 100644
--- a/importexport/inc/class.importexport_export_csv.inc.php
+++ b/importexport/inc/class.importexport_export_csv.inc.php
@@ -282,6 +282,16 @@ class importexport_export_csv implements importexport_iface_export_record
if($appname) {
if(!self::$cf_parse_cache[$appname]) {
$c_fields = self::convert_parse_custom_fields($appname, $selects, $links, $methods);
+
+ // Add in any fields that are keys to another app
+ foreach((array)$fields['links'] as $link_field => $app)
+ {
+ if(is_numeric($link_field)) continue;
+ $links[$link_field] = $app;
+ // Set it as a normal link field
+ $fields['links'][] = $link_field;
+ unset($fields['links'][$link_field]);
+ }
self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods);
}
list($c_fields, $c_selects, $links, $methods) = self::$cf_parse_cache[$appname];
@@ -294,6 +304,7 @@ class importexport_export_csv implements importexport_iface_export_record
}
$fields += $c_fields;
$selects += $c_selects;
+
}
foreach((array)$fields['select'] as $name) {
if($record->$name != null && is_array($selects) && $selects[$name]) {
diff --git a/importexport/inc/class.importexport_import_csv.inc.php b/importexport/inc/class.importexport_import_csv.inc.php
index 85589aadf5..7c7851bc73 100755
--- a/importexport/inc/class.importexport_import_csv.inc.php
+++ b/importexport/inc/class.importexport_import_csv.inc.php
@@ -272,13 +272,23 @@ class importexport_import_csv implements importexport_iface_import_record { //,
if(!self::$cf_parse_cache[$appname]) {
$c_fields = importexport_export_csv::convert_parse_custom_fields($appname, $selects, $links, $methods);
+ // Add in any fields that are keys to another app
+ foreach((array)$fields['links'] as $link_field => $app)
+ {
+ if(is_numeric($link_field)) continue;
+ $links[$link_field] = $app;
+ // Set it as a normal link field
+ $fields['links'][] = $link_field;
+ unset($fields['links'][$link_field]);
+ }
self::$cf_parse_cache[$appname] = array($c_fields, $selects, $links, $methods);
}
list($c_fields, $c_selects, $links, $methods) = self::$cf_parse_cache[$appname];
// Not quite a recursive merge, since only one level
- foreach($fields as $type => &$list) {
+ foreach($fields as $type => &$list)
+ {
if($c_fields[$type]) {
- $list = array_merge($c_fields[$type], $list);;
+ $list = array_merge($c_fields[$type], $list);
unset($c_fields[$type]);
}
}
@@ -301,8 +311,46 @@ class importexport_import_csv implements importexport_iface_import_record { //,
}
}
foreach((array)$fields['links'] as $name) {
- if($record[$name]) {
- // TODO
+ if($record[$name] && $links[$name])
+ {
+ // Primary key to another app, not a link
+ // Text - search for a matching record
+ if(!is_numeric($record[$name]))
+ {
+ $results = egw_link::query($links[$name], $record[$name]);
+ if(count($results) > 1)
+ {
+ // More than 1 result. Check for exact match
+ $exact_count = 0;
+ foreach($results as $id => $title)
+ {
+ if($title == $record[$name])
+ {
+ $exact_count++;
+ $app_id = $id;
+ }
+ }
+ if($exact_count != 1)
+ {
+ $warnings[] = lang('Unable to link to %1 "%2"',
+ lang($links[$name]), $record[$name]).
+ ' - ' .lang('too many matches');
+ $record[$name] = null;
+ continue;
+ }
+ $record[$name] = $app_id;
+ }
+ else if (count($results) == 0)
+ {
+ $warnings[] = lang('Unable to link to %1 "%2"',
+ lang($links[$name]), $record[$name]).
+ ' - ' . lang('no matches');
+ $record[$name] = null;
+ continue;
+ } else {
+ $record[$name] = key($results);
+ }
+ }
}
}
foreach((array)$fields['select-account'] as $name) {
diff --git a/importexport/inc/class.importexport_import_ui.inc.php b/importexport/inc/class.importexport_import_ui.inc.php
index 4c8fed1414..04c45aba92 100644
--- a/importexport/inc/class.importexport_import_ui.inc.php
+++ b/importexport/inc/class.importexport_import_ui.inc.php
@@ -296,6 +296,21 @@
$preview = html::table($rows);
rewind($stream);
}
+ if(count($plugin->get_warnings())) {
+ $this->message .= "
\n".lang('Warnings').':';
+ foreach($plugin->get_warnings() as $record => $message) {
+ $this->message .= "\n$record: $message";
+ }
+ $this->message .= "
\n";
+ };
+ if(count($plugin->get_errors())) {
+ $this->message .= "
\n".lang('Problems during import:');
+ foreach($plugin->get_errors() as $record => $message) {
+ $this->message .= "
\n$record: $message";
+ }
+ if($count != $total_processed) $this->message .= "
\n".lang('Some records may not have been imported');
+ $this->message .= "
\n";
+ }
return '