* * -------------------------------------------- * * 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' => 'calendar', 'noappheader' => True, 'noappfooter' => True ); include('../header.inc.php'); $GLOBALS['phpgw']->contacts = createobject('phpgwapi.contacts'); $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); // $t->unknows = 'keep'; $t->debug = 1; $t->set_file(array('import' => 'csv_import.tpl')); $t->set_block('import','filename','filenamehandle'); $t->set_block('import','fheader','fheaderhandle'); $t->set_block('import','fields','fieldshandle'); $t->set_block('import','ffooter','ffooterhandle'); $t->set_block('import','imported','importedhandle'); // $t->set_var("navbar_bg",$phpgw_info["theme"]["navbar_bg"]); // $t->set_var("navbar_text",$phpgw_info["theme"]["navbar_next"]); if ($action == 'download' && (!$fieldsep || !$csvfile || !($fp=fopen($csvfile,'r')))) { $action = ''; } $t->set_var('action_url',$GLOBALS['phpgw']->link('/calendar/csv_import.php')); $t->set_var('lang_cal_action',lang('Import CSV-File into Calendar')); $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'\n"; } return $ret.')'; } function index( $value,$arr ) { while (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 ) { $addrs = $GLOBALS['phpgw']->contacts->read( 0,0,array('id'),'',"n_family=$n_family,n_given=$n_given,org_name=$org_name" ); if (!count($addrs)) { $addrs = $GLOBALS['phpgw']->contacts->read( 0,0,array('id'),'',"n_family=$n_family,n_given=$n_given" ); } if (!count($addrs)) { $addrs = $GLOBALS['phpgw']->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) { $id_str = ','.$id_str.','; } return $id_str; } switch ($action) { case '': // Start, ask Filename $t->set_var('lang_csvfile',lang('CSV-Filename')); $t->set_var('lang_fieldsep',lang('Fieldseparator')); $t->set_var('fieldsep',$fieldsep ? $fieldsep : ','); $t->set_var('submit',lang('Download')); $t->set_var('csvfile',$csvfile); $t->set_var('enctype','ENCTYPE="multipart/form-data"'); $hiddenvars .= ''."\n"; $t->parse('filenamehandle','filename'); break; case 'download': $GLOBALS['phpgw']->preferences->read_repository(); $defaults = $GLOBALS['phpgw_info']['user']['preferences']['calendar']['csv_import']; if (!is_array($defaults)) { $defaults = array(); } $t->set_var('lang_csv_fieldname',lang('CSV-Fieldname')); $t->set_var('lang_cal_fieldname',lang('Calendar-Fieldname')); $t->set_var('lang_translation',lang("Translation").' '.lang('help').''); $t->set_var('submit',lang('Import')); $t->set_var('lang_debug',lang('Test Import (show importable records only in browser)')); $t->parse('fheaderhandle','fheader'); $hiddenvars .= ''."\n" . '\n"; $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)"; $defaults = array ( 'VERTRAULICH' => "is_public${PSep}0${ASep}1${PSep}0", 'VONDATUM' => 'datetime'.$mktime_lotus, 'BISDATUM' => 'edatetime'.$mktime_lotus, 'SCHLUSSELID' => "category$PSep@cat_id(${CPre}SCHLUSSELID$CPos)", 'NOTIZEN' => 'title', ); $cal_names = array( 'owner' => 'Owner of the calendar-entry', 'category' => 'Category: @cat_id(CatName)', 'groups' => 'Groups (dont know what this field is for)', 'datetime' => 'Startdate: @mktime( )', 'mdatetime' => 'Modification date', 'edatetime' => 'Enddate of the entry', 'priority' => 'Priority: 1=Low, 2=Normal, 3=High', 'cal_type' => 'cal_type: single_event=E else M', 'is_public' => 'Access: 1=public, 0=private', 'title' => 'Title varchar(80)', 'description' => 'Description text' ); $cal_name_options = "