From 4c5a90726eeb943264aa6fe9b4f154634a7855b2 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Thu, 23 Sep 2010 19:51:51 +0000 Subject: [PATCH] Backport 32261 - Add option to change addressbook for record on a per-record basis, with fallback to owner - Add option to not change the addressbook a record is in when updating it --- ...lass.addressbook_import_contacts_csv.inc.php | 17 ++++++++++++++++- ...dressbook_wizard_import_contacts_csv.inc.php | 13 +++++++++++-- addressbook/setup/etemplates.inc.php | 4 ++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/addressbook/inc/class.addressbook_import_contacts_csv.inc.php b/addressbook/inc/class.addressbook_import_contacts_csv.inc.php index 525af0f60d..dbbf75d448 100644 --- a/addressbook/inc/class.addressbook_import_contacts_csv.inc.php +++ b/addressbook/inc/class.addressbook_import_contacts_csv.inc.php @@ -150,7 +150,19 @@ class addressbook_import_contacts_csv implements importexport_iface_import_plugi // don't import empty contacts if( count( array_unique( $record ) ) < 2 ) continue; - $record['owner'] = $_definition->plugin_options['contact_owner']; + // Set owner, unless it's supposed to come from CSV file + if($_definition->plugin_options['owner_from_csv']) { + if(!is_numeric($record['owner'])) { + $this->errors[$import_csv->get_current_position()] = lang( + 'Invalid addressbook ID: %1. Might be a bad field translation. Used %2 instead.', + $record['owner'], + $_definition->plugin_options['contact_owner'] + ); + $record['owner'] = $_definition->plugin_options['contact_owner']; + } + } else { + $record['owner'] = $_definition->plugin_options['contact_owner']; + } if ( $_definition->plugin_options['conditions'] ) { foreach ( $_definition->plugin_options['conditions'] as $condition ) { @@ -217,6 +229,9 @@ class addressbook_import_contacts_csv implements importexport_iface_import_plugi // Don't change a user account into a contact if($old['owner'] == 0) { unset($_data['owner']); + } elseif(!$this->definition->plugin_options['change_owner']) { + // Don't change addressbook of an existing contact + unset($_data['owner']); } // Merge to deal with fields not in import record diff --git a/addressbook/inc/class.addressbook_wizard_import_contacts_csv.inc.php b/addressbook/inc/class.addressbook_wizard_import_contacts_csv.inc.php index 4349eab699..1bb688d0f1 100644 --- a/addressbook/inc/class.addressbook_wizard_import_contacts_csv.inc.php +++ b/addressbook/inc/class.addressbook_wizard_import_contacts_csv.inc.php @@ -57,6 +57,7 @@ class addressbook_wizard_import_contacts_csv extends importexport_wizard_basic_i function wizard_step60(&$content, &$sel_options, &$readonlys, &$preserv) { if($this->debug) error_log('addressbook.importexport.addressbook_csv_import::wizard_step60->$content '.print_r($content,true)); + unset($content['no_owner_map']); // return from step60 if ($content['step'] == 'wizard_step60') { @@ -77,13 +78,21 @@ class addressbook_wizard_import_contacts_csv extends importexport_wizard_basic_i { $content['msg'] = $this->steps['wizard_step60']; $content['step'] = 'wizard_step60'; - - if(!$content['contact_owner'] && $content['plugin_options']) { + if(!array_key_exists($content['contact_owner']) && $content['plugin_options']) { $content['contact_owner'] = $content['plugin_options']['contact_owner']; } + if(!array_key_exists($content['owner_from_csv']) && $content['plugin_options']) { + $content['owner_from_csv'] = $content['plugin_options']['owner_from_csv']; + } + if(!array_key_exists($content['change_owner']) && $content['plugin_options']) { + $content['change_owner'] = $content['plugin_options']['change_owner']; + } $bocontacts = new addressbook_bo(); $sel_options['contact_owner'] = $bocontacts->get_addressbooks(EGW_ACL_ADD); + if(!in_array('owner', $content['field_mapping'])) { + $content['no_owner_map'] = true; + } $preserv = $content; unset ($preserv['button']); diff --git a/addressbook/setup/etemplates.inc.php b/addressbook/setup/etemplates.inc.php index 82e33568e2..0c26fc19a9 100755 --- a/addressbook/setup/etemplates.inc.php +++ b/addressbook/setup/etemplates.inc.php @@ -2,7 +2,7 @@ /** * eGroupWare - eTemplates for Application addressbook * http://www.egroupware.org - * generated by soetemplate::dump4setup() 2010-09-16 15:01 + * generated by soetemplate::dump4setup() 2010-09-23 13:34 * * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @package addressbook @@ -68,7 +68,7 @@ $templ_data[] = array('name' => 'addressbook.export_csv_options','template' => ' $templ_data[] = array('name' => 'addressbook.export_csv_selectors','template' => '','lang' => '','group' => '0','version' => '','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:3:{i:0;a:0:{}i:1;a:1:{s:1:"A";a:4:{s:4:"type";s:5:"radio";s:5:"label";s:7:"Use all";s:4:"size";s:12:"all_contacts";s:4:"name";s:9:"selection";}}i:2;a:1:{s:1:"A";a:4:{s:4:"type";s:5:"radio";s:5:"label";s:18:"Use search results";s:4:"name";s:9:"selection";s:4:"size";s:7:"use_all";}}}s:4:"rows";i:2;s:4:"cols";i:1;}}','size' => '','style' => '','modified' => '1268429802',); -$templ_data[] = array('name' => 'addressbook.importexport_wizard_chooseowner','template' => '','lang' => '','group' => '0','version' => '0.0.1','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:3:{i:0;a:0:{}i:1;a:1:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"name";s:3:"msg";s:7:"no_lang";s:1:"1";}}i:2;a:1:{s:1:"A";a:3:{s:4:"type";s:6:"select";s:4:"name";s:13:"contact_owner";s:4:"size";s:4:"None";}}}s:4:"rows";i:2;s:4:"cols";i:1;}}','size' => '','style' => '','modified' => '1268327427',); +$templ_data[] = array('name' => 'addressbook.importexport_wizard_chooseowner','template' => '','lang' => '','group' => '0','version' => '0.0.1','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:6:{i:0;a:1:{s:2:"h2";s:14:",@no_owner_map";}i:1;a:1:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"name";s:3:"msg";s:7:"no_lang";s:1:"1";}}i:2;a:1:{s:1:"A";a:3:{s:4:"type";s:8:"checkbox";s:5:"label";s:30:"Use field from CSV if possible";s:4:"name";s:14:"owner_from_csv";}}i:3;a:1:{s:1:"A";a:3:{s:4:"type";s:6:"select";s:4:"name";s:13:"contact_owner";s:4:"size";s:4:"None";}}i:4;a:1:{s:1:"A";a:1:{s:4:"type";s:5:"label";}}i:5;a:1:{s:1:"A";a:3:{s:4:"type";s:11:"select-bool";s:5:"label";s:32:"Change addressbook when updating";s:4:"name";s:12:"change_owner";}}}s:4:"rows";i:5;s:4:"cols";i:1;}}','size' => '','style' => '','modified' => '1268327427',); $templ_data[] = array('name' => 'addressbook.index','template' => '','lang' => '','group' => '0','version' => '1.7.001','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:5:{i:0;a:3:{s:2:"h1";s:6:",!@msg";s:2:"h2";s:2:",1";s:2:"c4";s:7:"noPrint";}i:1;a:2:{s:1:"A";a:5:{s:4:"type";s:5:"label";s:4:"span";s:13:"all,redItalic";s:5:"align";s:6:"center";s:4:"name";s:3:"msg";s:7:"no_lang";s:1:"1";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:2;a:2:{s:1:"A";a:2:{s:4:"type";s:8:"template";s:4:"name";s:22:"addressbook.index.left";}s:1:"B";a:3:{s:4:"type";s:8:"template";s:5:"align";s:5:"right";s:4:"name";s:27:"addressbook.index.right_add";}}i:3;a:2:{s:1:"A";a:4:{s:4:"type";s:9:"nextmatch";s:4:"size";s:22:"addressbook.index.rows";s:4:"name";s:2:"nm";s:4:"span";s:3:"all";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:4;a:2:{s:1:"A";a:5:{s:4:"type";s:6:"button";s:4:"name";s:3:"add";s:5:"label";s:3:"Add";s:4:"help";s:17:"Add a new contact";s:7:"onclick";s:168:"window.open(egw::link(\'/index.php\',\'menuaction=addressbook.addressbook_ui.edit\'),\'_blank\',\'dependent=yes,width=850,height=440,scrollbars=yes,status=yes\'); return false;";}s:1:"B";a:6:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"3";s:5:"align";s:5:"right";i:1;a:5:{s:4:"type";s:8:"checkbox";s:4:"name";s:7:"use_all";s:5:"label";s:11:"whole query";s:8:"onchange";s:126:"if (this.checked==true && !confirm(\'Apply the action on the whole query, NOT only the shown contacts!!!\')) this.checked=false;";s:4:"help";s:67:"Apply the action on the whole query, NOT only the shown contacts!!!";}i:2;a:6:{s:4:"type";s:6:"select";s:8:"onchange";s:16:"do_action(this);";s:4:"size";s:45:"Select an action or addressbook to move to...";s:7:"no_lang";s:1:"1";s:4:"name";s:6:"action";s:4:"help";s:42:"Select an action or addressbook to move to";}i:3;a:8:{s:4:"type";s:6:"button";s:4:"size";s:9:"arrow_ltr";s:5:"label";s:9:"Check all";s:4:"name";s:9:"check_all";s:4:"help";s:9:"Check all";s:7:"onclick";s:70:"toggle_all(this.form,form::name(\'nm[rows][checked][]\')); return false;";s:6:"needed";s:1:"1";s:4:"span";s:14:",checkAllArrow";}}}}s:4:"rows";i:4;s:4:"cols";i:2;s:4:"size";s:4:"100%";s:7:"options";a:1:{i:0;s:4:"100%";}}}','size' => '100%','style' => '','modified' => '1243585623',);