* * -------------------------------------------- * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * \**************************************************************************/ /* $Id$ */ $GLOBALS['phpgw_info']['flags'] = array( 'currentapp' => 'infolog', 'noheader' => True, 'nonavbar' => True, 'enable_contacts_class' => True ); include("../header.inc.php"); if (!isset($GLOBALS['phpgw_info']['user']['apps']['admin']) || !$GLOBALS['phpgw_info']['user']['apps']['admin']) // no admin { Header('Location: ' . $GLOBALS['phpgw']->link('/home.php')); $GLOBALS['phpgw']->common->phpgw_exit(); } $GLOBALS['phpgw']->common->phpgw_header(); $infolog = createobject('infolog.uiinfolog'); $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_var("navbar_bg",$GLOBALS['phpgw_info']["theme"]["navbar_bg"]); // $GLOBALS['phpgw']->template->set_var("navbar_text",$GLOBALS['phpgw_info']["theme"]["navbar_text"]); if ($action == 'download' && (!$fieldsep || !$csvfile || !($fp=fopen($csvfile,"r")))) { $action = ''; } $GLOBALS['phpgw']->template->set_var("action_url",$GLOBALS['phpgw']->link("/infolog/csv_import.php")); $GLOBALS['phpgw']->template->set_var( $infolog->setStyleSheet( )); $GLOBALS['phpgw']->template->set_var("lang_info_action",lang("InfoLog - Import CSV-File")); $PSep = '||'; // Pattern-Separator, separats the pattern-replacement-pairs in trans $ASep = '|>'; // Assignment-Separator, separats pattern and replacesment $VPre = '|#'; // Value-Prefix, is expanded to \ for ereg_replace $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 (list($key,$val) = each($arr)) $ret .= ($ret ? ',' : '(') . "'$key' => '$val'"; return $ret.')'; } function index( $value,$arr ) { while (list ($key,$val) = each($arr)) if ($value == $val) return $key; return False; } 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'); $addrs = $contacts->read( 0,0,array('id'),'',"n_family=$n_family,n_given=$n_given,org_name=$org_name" ); if (!count($addrs)) $addrs = $contacts->read( 0,0,array('id'),'',"n_family=$n_family,n_given=$n_given" ); if (!count($addrs)) $addrs = $contacts->read( 0,0,array('id'),'',"n_family=$n_family,org_name=$org_name" ); if (count($addrs)) return $addrs[0]['id']; return False; } $cat2id = array( ); function cat_id($cats) { if (!$cats) { return ''; } $cats = split('[,;]',$cats); while (list($k,$cat) = each($cats)) { if (isset($cat2id[$cat])) { $ids[$cat] = $cat2id[$cat]; // cat is in cache } else { if (!is_object($GLOBALS['phpgw']->categories)) { $GLOBALS['phpgw']->categories = createobject('phpgwapi.categories'); } if ($id = $GLOBALS['phpgw']->categories->name2id( addslashes($cat) )) { // cat exists $cat2id[$cat] = $ids[$cat] = $id; } else { // create new cat $GLOBALS['phpgw']->categories->add( array('name' => $cat,'descr' => $cat )); $cat2id[$cat] = $ids[$cat] = $GLOBALS['phpgw']->categories->name2id( addslashes($cat) ); } } } $id_str = implode( ',',$ids ); if (count($ids) > 1) // multiple cats need to be in ',' { $id_str = ",$id_str,"; } return $id_str; } switch ($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('fieldsep',$fieldsep ? $fieldsep : ','); $GLOBALS['phpgw']->template->set_var('submit',lang('Download')); $GLOBALS['phpgw']->template->set_var('csvfile',$csvfile); $GLOBALS['phpgw']->template->set_var('enctype','ENCTYPE="multipart/form-data"'); $hiddenvars .= ''."\n"; $GLOBALS['phpgw']->template->parse('rows','filename'); break; case 'download': $GLOBALS['phpgw']->preferences->read_repository(); $defaults = $GLOBALS['phpgw_info']['user']['preferences']['infolog']['cvs_import']; if (!is_array($defaults)) { $defaults = array(); } $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('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', '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', 'access' => 'Access: public,private', 'cat' => 'Cathegory: int(11) cathegory-id', 'datecreated' => 'Date Created: DateTime if empty = Start Date or now', 'startdate' => 'Start Date: DateTime', 'enddate' => 'End Date: DateTime', 'pri' => 'Priority: urgent,high,normal,low', '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)' ); // the next line is used in the help-text too $mktime_lotus = "${PSep}0?([0-9]+)[ .:-]+0?([0-9]*)[ .:-]+0?([0-9]*)[ .:-]+0?([0-9]*)[ .:-]+0?([0-9]*)[ .:-]+0?([0-9]*).*$ASep@mktime(${VPre}4,${VPre}5,${VPre}6,${VPre}2,${VPre}3,${VPre}1)"; /* this are settings to import from Lotus Organizer $defaults += array( 'Land' => "addr$PSep.*[(]+([0-9]+)[)]+$ASep+${VPre}1 (${CPre}Ortsvorwahl$CPos) ${CPre}Telefon$CPos$PSep${CPre}Telefon$CPos", 'Notiz' => 'des', 'Privat' => "access${PSep}1${ASep}private${PSep}public", 'Startdatum' => 'startdate'.$mktime_lotus, 'Enddatum' => 'enddate'.$mktime_lotus, 'Erledigt' => "status${PSep}1${ASep}done${PSep}call", 'Nachname' => "addr_id${PSep}@addr_id(${CPre}Nachname$CPos,${CPre}Vorname$CPos,${CPre}Firma$CPos)", 'Firma' => "from${PSep}.+$ASep${CPre}Firma$CPos: ${CPre}Nachname$CPos, ${CPre}Vorname$CPos". "${PSep}${CPre}Nachname$CPos, ${CPre}Vorname$CPos", 'no CSV 1' => "type${PSep}phone", 'no CSV 2' => "subject${PSep}@substr(${CPre}Notiz$CPos,0,60).' ...'" ); */ $info_name_options = "