From 6596f08060a82272f3d9ee543591d01d4bf79c38 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 7 Oct 2003 23:58:48 +0000 Subject: [PATCH] updated cvs-import with charset-conversation and automatialy run some string to id conversations --- infolog/csv_import.php | 217 ++++++++++++++++------- infolog/inc/class.boinfolog.inc.php | 13 +- infolog/setup/phpgw_de.lang | 8 +- infolog/setup/phpgw_en.lang | 8 +- infolog/templates/default/csv_import.tpl | 14 +- 5 files changed, 179 insertions(+), 81 deletions(-) diff --git a/infolog/csv_import.php b/infolog/csv_import.php index c83f6a667c..991573dbb9 100644 --- a/infolog/csv_import.php +++ b/infolog/csv_import.php @@ -24,18 +24,22 @@ { $GLOBALS['phpgw']->redirect_link('/home.php'); } + if ($_POST['cancel']) + { + $GLOBALS['phpgw']->redirect_link('/admin/index.php'); + } $GLOBALS['phpgw_info']['flags']['app_header'] = lang('InfoLog - Import CSV-File'); $GLOBALS['phpgw']->common->phpgw_header(); $boinfolog = createobject('infolog.boinfolog'); $GLOBALS['phpgw']->template->set_file(array('import_t' => 'csv_import.tpl')); - $GLOBALS['phpgw']->template->set_block('import_t','filename'); - $GLOBALS['phpgw']->template->set_block('import_t','fheader'); - $GLOBALS['phpgw']->template->set_block('import_t','fields'); - $GLOBALS['phpgw']->template->set_block('import_t','ffooter'); - $GLOBALS['phpgw']->template->set_block('import_t','imported'); - $GLOBALS['phpgw']->template->set_block('import_t','import'); + $GLOBALS['phpgw']->template->set_block('import_t','filename','filenamehandle'); + $GLOBALS['phpgw']->template->set_block('import_t','fheader','fheaderhandle'); + $GLOBALS['phpgw']->template->set_block('import_t','fields','fieldshandle'); + $GLOBALS['phpgw']->template->set_block('import_t','ffooter','ffooterhandle'); + $GLOBALS['phpgw']->template->set_block('import_t','imported','importedhandle'); + $GLOBALS['phpgw']->template->set_block('import_t','import','importhandle'); // $GLOBALS['phpgw']->template->set_var("navbar_bg",$GLOBALS['phpgw_info']["theme"]["navbar_bg"]); @@ -43,7 +47,7 @@ $csvfile = isset($_POST['csvfile']) ? $_POST['csvfile'] : $_FILES['csvfile']['tmp_name']; - if ($_POST['action'] == 'download' && (!$_POST['fieldsep'] || !$csvfile || !($fp=fopen($csvfile,"r")))) + if(($_POST['action'] == 'download' || $_POST['action'] == 'continue') && (!$_POST['fieldsep'] || !$csvfile || !($fp=fopen($csvfile,'rb')))) { $_POST['action'] = ''; } @@ -55,26 +59,7 @@ $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 ) -{ - foreach($arr as $key => $val) - { - $ret .= ($ret ? ',' : '(') . "'$key' => '$val'"; - } - return $ret.')'; -} - -function index( $value,$arr ) -{ - foreach($arr as $key => $val) - { - if ($value == $val) - return $key; - } - return False; -} - -function addr_id( $n_family,$n_given,$org_name ) +function addr_id( $n_family,$n_given,$org_name ) { // find in Addressbook, at least n_family AND (n_given OR org_name) have to match $contacts = createobject('phpgwapi.contacts'); @@ -99,7 +84,8 @@ function cat_id($cats) return ''; } - $cats = split('[,;]',$cats); + // no multiple cat's in InfoLog atm. + $cats = array($cats); //split('[,;]',$cats); foreach($cats as $k => $cat) { @@ -133,13 +119,24 @@ function cat_id($cats) return $id_str; } - switch ($_POST['action']) + 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"; @@ -147,6 +144,7 @@ function cat_id($cats) $GLOBALS['phpgw']->template->parse('rows','filename'); break; + case 'continue': case 'download': $GLOBALS['phpgw']->preferences->read_repository(); $defaults = $GLOBALS['phpgw_info']['user']['preferences']['infolog']['cvs_import']; @@ -157,32 +155,33 @@ function cat_id($cats) $GLOBALS['phpgw']->template->set_var('lang_csv_fieldname',lang('CSV-Fieldname')); $GLOBALS['phpgw']->template->set_var('lang_info_fieldname',lang('InfoLog-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('rows','fheader'); - $hiddenvars .= ''."\n". - '\n"; $info_names = array( - 'type' => 'Type: task,phone,note,confirm,reject,email,fax', + 'type' => 'Type: char(10) task,phone,note,confirm,reject,email,fax', 'from' => 'From: text(64) free text if no Addressbook-entry assigned', 'addr' => 'Addr: text(64) phone-nr/email-address', 'subject' => 'Subject: text(64)', 'des' => 'Description: text long free text', - 'owner' => 'Owner: int(11) user-id of owner, if empty current user', - 'responsible' => 'Responsible: int(11) user-id of resp. person', + 'responsible' => 'Responsible: int(11) user-id or user-name', + 'owner' => 'Owner: int(11) user-id/-name of owner, if empty current user', 'access' => 'Access: public,private', - 'cat' => 'Cathegory: int(11) cathegory-id', - 'datecreated' => 'Date Created: DateTime if empty = Start Date or now', - 'startdate' => 'Start Date: DateTime', + 'cat' => 'Category: int(11) category-id or -name (new ones got created)', + 'startdate' => 'Start Date: DateTime: Timestamp or eg. YYYY-MM-DD hh:mm', 'enddate' => 'End Date: DateTime', + 'datecreated' => 'Date Created: DateTime, if empty = Start Date or now', + 'datemodified'=> 'Date Last Modified: DateTime, if empty = Date Created', + 'modifier' => 'Modifier: int(11) user-id, if empty current user', 'pri' => 'Priority: urgent,high,normal,low', - //'time' => 'Time: int(11) time used in min', + 'time' => 'Time: int(11) time used in min', //'bill_cat' => 'Billing Cathegory: int(11)', - 'status' => 'Status: offer,ongoing,call,will-call,done,billed', - 'confirm' => 'Confirmation: not,accept,finish,both when to confirm', - 'cat_id' => 'Categorie id(s), to set use @cat_id(Cat1,Cat2)', - 'addr_id' => 'Addressbook id, to set use @addr_id(nlast,nfirst,org)' + 'status' => 'Status: char(10) offer,ongoing,call,will-call,done,billed,xx%', + 'confirm' => 'Confirmation: char(10) not,accept,finish,both when to confirm', + 'addr_id' => 'Addressbook id, to set use @addr_id(nlast,nfirst,org)' ); // the next line is used in the help-text too @@ -207,6 +206,7 @@ function cat_id($cats) $info_name_options .= "