diff --git a/addressbook/inc/class.egw_addressbook_record.inc.php b/addressbook/importexport/class.egw_addressbook_record.inc.php similarity index 96% rename from addressbook/inc/class.egw_addressbook_record.inc.php rename to addressbook/importexport/class.egw_addressbook_record.inc.php index 2e2800ab5f..7a81f46afb 100644 --- a/addressbook/inc/class.egw_addressbook_record.inc.php +++ b/addressbook/importexport/class.egw_addressbook_record.inc.php @@ -8,7 +8,7 @@ * @link http://www.egroupware.org * @author Cornelius Weiss * @copyright Cornelius Weiss - * @version $Id$ + * @version $Id: class.egw_addressbook_record.inc.php 22827 2006-11-10 15:35:35Z nelius_weiss $ */ require_once(EGW_INCLUDE_ROOT. '/importexport/inc/class.iface_egw_record.inc.php'); diff --git a/addressbook/inc/class.export_contacts_csv.inc.php b/addressbook/importexport/class.export_contacts_csv.inc.php similarity index 91% rename from addressbook/inc/class.export_contacts_csv.inc.php rename to addressbook/importexport/class.export_contacts_csv.inc.php index a574169899..d3928b97b7 100644 --- a/addressbook/inc/class.export_contacts_csv.inc.php +++ b/addressbook/importexport/class.export_contacts_csv.inc.php @@ -8,13 +8,13 @@ * @link http://www.egroupware.org * @author Cornelius Weiss * @copyright Cornelius Weiss - * @version $Id$ + * @version $Id: $ */ require_once(EGW_INCLUDE_ROOT. '/etemplate/inc/class.etemplate.inc.php'); require_once(EGW_INCLUDE_ROOT. '/importexport/inc/class.export_csv.inc.php'); require_once(EGW_INCLUDE_ROOT. '/importexport/inc/class.iface_export_plugin.inc.php'); -require_once(EGW_INCLUDE_ROOT. '/addressbook/inc/class.egw_addressbook_record.inc.php'); +require_once(EGW_INCLUDE_ROOT. '/addressbook/importexport/class.egw_addressbook_record.inc.php'); require_once(EGW_INCLUDE_ROOT. '/addressbook/inc/class.uicontacts.inc.php'); /** @@ -42,7 +42,8 @@ class export_contacts_csv implements iface_export_plugin { } $options['begin_with_fieldnames'] = true; - $export_object = new export_csv($_stream, $charset, (array)$options); + $export_object = new export_csv($_stream, $_charset, (array)$options); + $export_object->set_mapping($options['mapping']); // $options['selection'] is array of identifiers as this plugin doesn't // support other selectors atm. @@ -97,4 +98,4 @@ class export_contacts_csv implements iface_export_plugin { public static function get_selectors_etpl() { return 'Selectors:'; } -} \ No newline at end of file +} diff --git a/addressbook/importexport/class.import_contacts_csv.inc.php b/addressbook/importexport/class.import_contacts_csv.inc.php new file mode 100644 index 0000000000..a915cf2f50 --- /dev/null +++ b/addressbook/importexport/class.import_contacts_csv.inc.php @@ -0,0 +1,216 @@ + + * @copyright Cornelius Weiss + * @version $Id: $ + */ + +require_once(EGW_INCLUDE_ROOT. '/importexport/inc/class.iface_import_plugin.inc.php'); +require_once(EGW_INCLUDE_ROOT.'/importexport/inc/class.import_csv.inc.php'); + + +/** + * class import_csv for addressbook + */ +class import_contacts_csv implements iface_import_plugin { + + private static $plugin_options = array( + 'fieldsep', //char + 'charset', //string + 'addressbook', //char + 'owner', // comma seperated list of int + 'csv_fields', // array( $csv_col_num => csv_field_name) + 'field_mapping', // array( $csv_col_num => adb_filed) + 'field_translation', // array( $csv_col_num => translation) + 'has_header_line', //bool + 'max', // int + 'conditions', /* => array containing condition arrays: + 'type' => 0, // exists + 'string' => '#kundennummer', + 'true' => array( + 'action' => update, + 'last' => true, + ), + 'false' => array( + 'action' => insert, + 'last' => true, + ),*/ + + ); + + /** + * actions wich could be done to data entries + */ + private static $actions = array( 'none', 'update', 'insert', 'delte', ); + + /** + * conditions for actions + * + * @var array + */ + private static $conditions = array( 'exists', 'greater', 'greater or equal', ); + + /** + * @var bocontacts + */ + private $bocontacts; + + /** + * constructor of import_contacts_csv + * + public function __construct() { + $this->bocontacts = CreateObject('addressbook.bocontacts'); + }*/ + + /** + * imports entries according to given definition object. + * @param resource $_stream + * @param string $_charset + * @param definition $_definition + */ + public function import( $_stream, $_charset, definition $_definition ) { + $import_csv = new import_csv( $_stream, array( + 'fieldsep' => $_definition->plugin_options['fieldsep'], + 'charset' => $_definition->plugin_options['charset'], + )); + + // fetch the addressbook bo + $this->bocontacts = CreateObject('addressbook.bocontacts'); + + // set FieldMapping. Throw away empty / not assigned entrys + $import_csv->mapping = array_diff($_definition->plugin_options['field_mapping'],array('')); + + // renamed from translation to conversion + $import_csv->conversion = $_definition->plugin_options['field_conversion'] ? + $_definition->plugin_options['field_conversion'] : + $_definition->plugin_options['field_translation']; + + //check if file has a header line + if ($_definition->plugin_options['has_header_line']) { + $record = $import_csv->get_record(); + } + + // TODO: Throw away spechial chars ? + // TODO: check conversion: + // - is not existing cat created? + // - usermapping? + + while ( $record = $import_csv->get_record() ) { + + // don't import empty contacts + if( count( array_unique( $record ) ) < 2 ) continue; + + if ( $_definition->plugin_options['conditions'] ) { + foreach ( $_definition->plugin_options['conditions'] as $condition ) { + switch ( $condition['type'] ) { + // exists + case 'exists' : + $contacts = $this->bocontacts->search(array( + $condition['string'] => $record[$condition['string']], + ),true); + + if ( is_array( $contacts ) && count( array_keys( $contacts ) >= 1 ) ) { + // apply action to all contacts matching this exists condition + $action = $condition['true']; + foreach ( (array)$contacts as $contact ) { + $record['id'] = $contact['id']; + $this->action( $action['action'], $record ); + } + } else { + $action = $condition['true']; + $this->action( $action['action'], $record ); + } + break; + + // not supported action + default : + die('condition / action not supported!!!'); + break; + } + if ($action['last']) break; + } + } else { + // unconditional insert + $this->action( 'insert', $values ); + } + } + } + + /** + * perform the required action + * + * @param int $_action one of $this->actions + * @param array $_data contact data for the action + * @return bool success or not + */ + private function action ( $_action, $_data ) { + print_r($_data); + switch ($_action) { + case 'none' : + return true; + case 'update' : + case 'insert' : + return $this->bocontacts->save( $_data ); + case 'delete' : + } + } + + /** + * returns translated name of plugin + * + * @return string name + */ + public static function get_name() { + return lang('Addressbook CSV export'); + } + + /** + * returns translated (user) description of plugin + * + * @return string descriprion + */ + public static function get_description() { + return lang("Imports contacts into your Addressbook from a CSV File. CSV means 'Comma Seperated Values'. However in the options Tab you can also choose other seperators."); + } + + /** + * retruns file suffix(s) plugin can handle (e.g. csv) + * + * @return string suffix (comma seperated) + */ + public static function get_filesuffix() { + return 'csv'; + } + + /** + * return etemplate components for options. + * @abstract We can't deal with etemplate objects here, as an uietemplate + * objects itself are scipt orientated and not "dialog objects" + * + * @return array ( + * name => string, + * content => array, + * sel_options => array, + * preserv => array, + * ) + */ + public function get_options_etpl() { + // lets do it! + } + + /** + * returns etemplate name for slectors of this plugin + * + * @return string etemplate name + */ + public function get_selectors_etpl() { + // lets do it! + } + +} // end of iface_export_plugin +?> diff --git a/addressbook/importexport/class.wizzard_addressbook_csv_import.inc.php b/addressbook/importexport/class.wizzard_addressbook_csv_import.inc.php new file mode 100644 index 0000000000..c84db13863 --- /dev/null +++ b/addressbook/importexport/class.wizzard_addressbook_csv_import.inc.php @@ -0,0 +1,192 @@ + + * @version $Id: $ + */ + +require_once(EGW_INCLUDE_ROOT.'/addressbook/inc/class.addressbook_csv_import.inc.php'); + +class wizzard_addressbook_csv_import extends addressbook_csv_import +{ + + var $steps; + + /** + * constructor + */ + function wizzard_addressbook_csv_import() + { + $this->steps = array( + 'wizzard_step30' => lang('Load Sample file'), + 'wizzard_step40' => lang('Choose seperator and charset'), + 'wizzard_step50' => lang('Manage mapping'), + 'wizzard_step60' => lang('Choose owner of imported data'), + ); + $this->__construct(); + } + + function wizzard_step30(&$content, &$sel_options, &$readonlys, &$preserv) + { + if($this->debug) error_log('addressbook.importexport.addressbook_csv_import::wizzard_step30->$content '.print_r($content,true)); + // return from step30 + if ($content['step'] == 'wizzard_step30') + { + switch (array_search('pressed', $content['button'])) + { + case 'next': + error_log(print_r($content,true)); + $file = fopen ($content['file']['tmp_name'],'rb'); + + return $GLOBALS['egw']->uidefinitions->get_step($content['step'],1); + case 'previous' : + return $GLOBALS['egw']->uidefinitions->get_step($content['step'],-1); + case 'finish': + return 'wizzard_finish'; + default : + return $this->wizzard_step30($content,$sel_options,$readonlys,$preserv); + } + } + // init step30 + else + { + $content['msg'] = $this->steps['wizzard_step30']; + $content['step'] = 'wizzard_step30'; + $preserv = $content; + unset ($preserv['button']); + $GLOBALS['egw']->js->set_onload("var btn = document.getElementById('exec[button][next]'); btn.attributes.removeNamedItem('onclick');"); + return 'addressbook.importexport_wizzard_samplefile'; + } + + } + + /** + * choose fieldseperator, charset and headerline + * + * @param array $content + * @param array $sel_options + * @param array $readonlys + * @param array $preserv + * @return string template name + */ + function wizzard_step40(&$content, &$sel_options, &$readonlys, &$preserv) + { + if($this->debug) error_log('addressbook.importexport.addressbook_csv_import::wizzard_step40->$content '.print_r($content,true)); + // return from step40 + if ($content['step'] == 'wizzard_step40') + {//error_log(serialize($GLOBALS['egw']->uidefinitions)); + switch (array_search('pressed', $content['button'])) + { + case 'next': + return $GLOBALS['egw']->uidefinitions->get_step($content['step'],1); + case 'previous' : + return $GLOBALS['egw']->uidefinitions->get_step($content['step'],-1); + case 'finish': + return 'wizzard_finish'; + default : + return $this->wizzard_step40($content,$sel_options,$readonlys,$preserv); + } + } + // init step40 + else + { + $content['msg'] = $this->steps['wizzard_step40']; + $content['step'] = 'wizzard_step40'; + $sel_options['charset'] = $GLOBALS['egw']->translation->get_installed_charsets()+ + array('utf-8' => 'utf-8 (Unicode)'); + $preserv = $content; + unset ($preserv['button']); + return 'addressbook.importexport_wizzard_choosesepncharset'; + } + + } + + function wizzard_step50(&$content, &$sel_options, &$readonlys, &$preserv) + { + if($this->debug) error_log('addressbook.importexport.addressbook_csv_import::wizzard_step50->$content '.print_r($content,true)); + // return from step50 + if ($content['step'] == 'wizzard_step50') + { + array_shift($content['csv_fields']); + //$content['csv_fields'] = array('csv_01','csv_02','csv_03','csv_04','csv_05','csv_06','csv_07','csv_08','csv_09','csv_10','csv_11','csv_12'); + array_shift($content['field_mapping']); + array_shift($content['field_translation']); + + switch (array_search('pressed', $content['button'])) + { + case 'next': + return $GLOBALS['egw']->uidefinitions->get_step($content['step'],1); + case 'previous' : + return $GLOBALS['egw']->uidefinitions->get_step($content['step'],-1); + case 'finish': + return 'wizzard_finish'; + default : + return $this->wizzard_step50($content,$sel_options,$readonlys,$preserv); + } + } + // init step50 + else + { + $content['msg'] = $this->steps['wizzard_step50']; + $content['step'] = 'wizzard_step50'; + + array_unshift($content['csv_fields'],array('row0')); + array_unshift($content['field_mapping'],array('row0')); + array_unshift($content['field_translation'],array('row0')); + + $j = 0; + foreach ($content['csv_fields'] as $field) + { + if(strstr($field,'no_csv_')) $j++; + } + while ($j <= 3) + { + $content['csv_fields'][] = 'no_csv_'.$j; + $content['field_mapping'][] = $content['field_translation'][] = ''; + $j++; + } + $contact_fields = $this->bocontacts->get_contact_columns(); + $sel_options['field_mapping'] = array('' => lang('none')) + array_combine($contact_fields,$contact_fields); + error_log(print_r($sel_options['field_mapping'],true)); + $preserv = $content; + unset ($preserv['button']); + return 'addressbook.importexport_wizzard_fieldmaping'; + } + + } + + function wizzard_step60(&$content, &$sel_options, &$readonlys, &$preserv) + { + if($this->debug) error_log('addressbook.importexport.addressbook_csv_import::wizzard_step60->$content '.print_r($content,true)); + // return from step60 + if ($content['step'] == 'wizzard_step60') + { + switch (array_search('pressed', $content['button'])) + { + case 'next': + return $GLOBALS['egw']->uidefinitions->get_step($content['step'],1); + case 'previous' : + return $GLOBALS['egw']->uidefinitions->get_step($content['step'],-1); + case 'finish': + return 'wizzard_finish'; + default : + return $this->wizzard_step60($content,$sel_options,$readonlys,$preserv); + } + } + // init step60 + else + { + $content['msg'] = $this->steps['wizzard_step60']; + $content['step'] = 'wizzard_step60'; + + $preserv = $content; + unset ($preserv['button']); + return 'addressbook.importexport_wizzard_chooseowner'; + } + + } +} diff --git a/addressbook/importexport/definitions/outlook_csv_english.xml b/addressbook/importexport/definitions/outlook_csv_english.xml new file mode 100644 index 0000000000..8ea1389eb7 --- /dev/null +++ b/addressbook/importexport/definitions/outlook_csv_english.xml @@ -0,0 +1,59 @@ + + + + importexport definitions + utf-8 + 1 + + + + outlook_csv_english + addressbook + export_contacts_csv + export + + -1 + + + + Title + First Name + Middle Name + Last Name + Suffix + Company + Department + Job Title + Business Street + Business Street 2 + Business Street 3 + Business City + Business State + Business Postal Code + Business Country + Home Street + Home City + Home State + Home Postal Code + Home Country + Business Fax + Business Phone + Assistant's Phone + Car Phone + ISDN + Home Phone + Mobile Phone + Pager + Business Phone 2 + Birthday + E-mail Address + E-mail Address 2 + Web Page + Notes + + + 0 + Exports selected contacts for english version of MS Outlook + + + diff --git a/addressbook/importexport/definitions/outlook_csv_finish.xml b/addressbook/importexport/definitions/outlook_csv_finish.xml new file mode 100644 index 0000000000..63e56b4038 --- /dev/null +++ b/addressbook/importexport/definitions/outlook_csv_finish.xml @@ -0,0 +1,58 @@ + + + + importexport definitions + utf-8 + 1 + + + + outlook_csv_finish + addressbook + export_contacts_csv + export + + -1 + + + + Tehtävänimike + Etunimi + Toinen nimi + Sukunimi + Jälkiliite + Yritys + Osasto + Lähiosoite (työ) + Lähiosoite (työ) 2 + Lähiosoite (työ) 3 + Postitoimipaikka (työ) + Sijaintitiedot (työ) + Postinumero (työ) + Maa (työ) + Lähiosoite (koti) + Postitoimipaikka (koti) + Sijaintitiedot (koti) + Postinumero (koti) + Maa (koti) + Työfaksi + Työpuhelin + Avustajan puhelinnumero + Autopuhelin + ISDN + Kotipuhelin + Matkapuhelin + Hakulaite + Työpuhelin 2 + Syntymäpäivä + Sähköpostiosoite + Säköpostiosoite 2 + Web-sivu + Muistilaput + + + 0 + + + + diff --git a/addressbook/importexport/definitions/outlook_csv_french.xml b/addressbook/importexport/definitions/outlook_csv_french.xml new file mode 100644 index 0000000000..ee2bcf96ef --- /dev/null +++ b/addressbook/importexport/definitions/outlook_csv_french.xml @@ -0,0 +1,58 @@ + + + + importexport definitions + utf-8 + 1 + + + + outlook_csv_french + addressbook + export_contacts_csv + export + + -1 + + + + Fonction + Prénom + Deuxième prénom + Nom + Suffixe + Société + Service + Rue (bureau) + Rue (bureau) 2 + Rue (bureau) 3 + Ville (bureau) + État/Prov (bureau) + Code postal (bureau) + Pays (bureau) + Rue (domicile) + Ville (domicile) + État/Prov (domicile) + Code postal (domicile) + Pays (domicile) + Télécopie (bureau) + Téléphone (bureau) + Téléphone de l'assistant(e) + Téléphone (voiture) + RNIS + Téléphone (domicile) + Tél. mobile + Récepteur de radiomessagerie + Téléphone 2 (bureau) + Anniversaire + Adresse e-mail + Adresse e-mail 2 + Page Web + Notes + + + 0 + + + + diff --git a/addressbook/importexport/definitions/outlook_csv_german.xml b/addressbook/importexport/definitions/outlook_csv_german.xml new file mode 100644 index 0000000000..400cad3455 --- /dev/null +++ b/addressbook/importexport/definitions/outlook_csv_german.xml @@ -0,0 +1,59 @@ + + + + importexport definitions + utf-8 + 1 + + + + outlook_csv_german + addressbook + export_contacts_csv + export + + -1 + + + + Anrede + Vorname + Weitere Vornamen + Nachname + Suffix + Firma + Abteilung + Position + Straße geschäftlich + Straße geschäftlich 2 + Straße geschäftlich 3 + Ort geschäftlich + Region geschäftlich + Postleitzahl geschäftlich + Land geschäftlich + Straße privat + Ort privat + Region privat + Postleitzahl privat + Land privat + Fax geschäftlich + Telefon geschäftlich + Telefon Assistent + Autotelefon + ISDN + Telefon privat + Mobiltelefon + Pager + Telefon geschäftlich 2 + Geburtstag + E-Mail-Adresse + E-Mail 2: Adresse + Webseite + Notizen + + + 0 + Exportiert ausgewählte Kontakte zur Datenübernahme in die deutsche Version von MS Outlook + + + diff --git a/addressbook/importexport/definitions/outlook_csv_italian.xml b/addressbook/importexport/definitions/outlook_csv_italian.xml new file mode 100644 index 0000000000..706ef67438 --- /dev/null +++ b/addressbook/importexport/definitions/outlook_csv_italian.xml @@ -0,0 +1,59 @@ + + + + importexport definitions + utf-8 + 1 + + + + outlook_csv_italien + addressbook + export_contacts_csv + export + + -1 + + + + Posizione + Titolo + Nome + Secondo nome + Cognome + Titolo straniero + Società + Reparto + Via (uff.) + Via (uff.) 2 + Via (uff.) 3 + Città (uff.) + Provincia (uff.) + CAP (uff.) + Paese (uff.) + Via (ab.) + Città (ab.) + Provincia (ab.) + CAP (ab.) + Paese (ab.) + Fax (uff.) + Ufficio + Telefono assistente + Telefono auto + ISDN + Abitazione + Cellulare + Pager + Business Phone 2 + Compleanno + Indirizzo posta elettronica + Indirizzo posta elettronica 2 + Pagina Web + Notes + + + 0 + + + +