diff --git a/addressbook/csv_import.php b/addressbook/csv_import.php index 01cacefa28..19f3544bac 100644 --- a/addressbook/csv_import.php +++ b/addressbook/csv_import.php @@ -19,11 +19,16 @@ ); include('../header.inc.php'); + if ($_POST['cancel']) + { + $GLOBALS['phpgw']->redirect_link('/addressbook/index.php'); + } $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Import CSV-File into Addressbook'); $GLOBALS['phpgw']->common->phpgw_header(); $GLOBALS['phpgw']->contacts = createobject('phpgwapi.contacts'); + //$GLOBALS['phpgw']->template->set_unknowns('keep'); $GLOBALS['phpgw']->template->set_file(array('import' => 'csv_import.tpl')); $GLOBALS['phpgw']->template->set_block('import','filename','filenamehandle'); $GLOBALS['phpgw']->template->set_block('import','fheader','fheaderhandle'); @@ -33,7 +38,7 @@ $csvfile = isset($_POST['csvfile']) ? $_POST['csvfile'] : $_FILES['csvfile']['tmp_name']; - if($_POST['action'] == 'download' && (!$_POST['fieldsep'] || !$csvfile || !($fp=fopen($csvfile,'rb')))) + if(($_POST['action'] == 'download' || $_POST['action'] == 'continue') && (!$_POST['fieldsep'] || !$csvfile || !($fp=fopen($csvfile,'rb')))) { $_POST['action'] = ''; } @@ -45,27 +50,6 @@ $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 - function dump_array($arr) - { - while(is_array($arr) && (list($key,$val) = each($arr))) - { - $ret .= ($ret ? ',' : '(') . "'$key' => '$val'\n"; - } - return $ret.')'; - } - - function index($value,$arr) - { - while(is_array($arr) && (list($key,$val) = each($arr))) - { - if($value == $val) - { - return $key; - } - } - return False; - } - // find in Addressbook, at least n_family AND (n_given OR org_name) have to match function addr_id($n_family,$n_given,$org_name) { @@ -129,14 +113,25 @@ } return $id_str; } + if (!is_object($GLOBALS['phpgw']->html)) + { + $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html'); + } + + if ($_POST['next']) $_POST['action'] = 'next'; switch($_POST['action']) { case '': // Start, ask Filename $GLOBALS['phpgw']->template->set_var('lang_csvfile',lang('CSV-Filename')); $GLOBALS['phpgw']->template->set_var('lang_fieldsep',lang('Fieldseparator')); + $GLOBALS['phpgw']->template->set_var('lang_charset',lang('Charset of file')); + $GLOBALS['phpgw']->template->set_var('select_charset', + $GLOBALS['phpgw']->html->select('charset','', + $GLOBALS['phpgw']->translation->get_installed_charsets()+ + array('utf-8' => 'utf-8 (Unicode)'),True)); $GLOBALS['phpgw']->template->set_var('fieldsep',$_POST['fieldsep'] ? $_POST['fieldsep'] : ','); - $GLOBALS['phpgw']->template->set_var('submit',lang('Download')); + $GLOBALS['phpgw']->template->set_var('submit',lang('Import')); $GLOBALS['phpgw']->template->set_var('csvfile',$csvfile); $GLOBALS['phpgw']->template->set_var('enctype','ENCTYPE="multipart/form-data"'); $hiddenvars .= ''."\n"; @@ -144,8 +139,8 @@ $GLOBALS['phpgw']->template->parse('filenamehandle','filename'); break; + case 'continue': case 'download': - $GLOBALS['phpgw']->preferences->read_repository(); $defaults = $GLOBALS['phpgw_info']['user']['preferences']['addressbook']['cvs_import']; if(!is_array($defaults)) { @@ -154,11 +149,11 @@ $GLOBALS['phpgw']->template->set_var('lang_csv_fieldname',lang('CSV-Fieldname')); $GLOBALS['phpgw']->template->set_var('lang_addr_fieldname',lang('Addressbook-Fieldname')); $GLOBALS['phpgw']->template->set_var('lang_translation',lang("Translation").' '.lang('help').''); - $GLOBALS['phpgw']->template->set_var('submit',lang('Import')); + $GLOBALS['phpgw']->template->set_var('submit', + $GLOBALS['phpgw']->html->submit_button('convert','Import') . ' '. + $GLOBALS['phpgw']->html->submit_button('cancel','Cancel')); $GLOBALS['phpgw']->template->set_var('lang_debug',lang('Test Import (show importable records only in browser)')); $GLOBALS['phpgw']->template->parse('fheaderhandle','fheader'); - $hiddenvars .= ''."\n" - . '\n"; $addr_names = $GLOBALS['phpgw']->contacts->stock_contact_fields + array( 'cat_id' => 'Categories: @cat_id(Cat1,Cat2)', @@ -189,6 +184,7 @@ $addr_name_options .= "