From 9763f202b5354a774b665e0e08f45480c34fb71a Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 7 Jul 2008 06:09:32 +0000 Subject: [PATCH] "use static method of link class" --- infolog/csv_import.php | 876 ++++++++++++++++++++--------------------- 1 file changed, 438 insertions(+), 438 deletions(-) diff --git a/infolog/csv_import.php b/infolog/csv_import.php index e854769c94..165a4d8c29 100644 --- a/infolog/csv_import.php +++ b/infolog/csv_import.php @@ -5,64 +5,64 @@ * @link http://www.egroupware.org * @author Ralf Becker * @package infolog - * @copyright (c) 2003-6 by Ralf Becker + * @copyright (c) 2003-8 by Ralf Becker * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @version $Id$ */ - $GLOBALS['egw_info']['flags'] = array( - 'currentapp' => 'infolog', - 'noheader' => True, - 'enable_contacts_class' => True, - ); - include('../header.inc.php'); +$GLOBALS['egw_info']['flags'] = array( + 'currentapp' => 'infolog', + 'noheader' => True, + 'enable_contacts_class' => True, +); +include('../header.inc.php'); - if (!isset($GLOBALS['egw_info']['user']['apps']['admin']) || - !$GLOBALS['egw_info']['user']['apps']['admin']) // no admin - { - $GLOBALS['egw']->redirect_link('/home.php'); - } - if (isset($_FILES['csvfile']['tmp_name'])) - { - $csvfile = tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_"); - $GLOBALS['egw']->session->appsession('csvfile','',$csvfile); - $_POST['action'] = move_uploaded_file($_FILES['csvfile']['tmp_name'],$csvfile) ? - 'download' : ''; - } - else - { - $csvfile = $GLOBALS['egw']->session->appsession('csvfile'); - } - if ($_POST['cancel']) - { - @unlink($csvfile); - $GLOBALS['egw']->redirect_link('/admin/index.php'); - } - $GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog - Import CSV-File'); - $GLOBALS['egw']->common->egw_header(); +if (!isset($GLOBALS['egw_info']['user']['apps']['admin']) || + !$GLOBALS['egw_info']['user']['apps']['admin']) // no admin +{ + $GLOBALS['egw']->redirect_link('/home.php'); +} +if (isset($_FILES['csvfile']['tmp_name'])) +{ + $csvfile = tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_"); + $GLOBALS['egw']->session->appsession('csvfile','',$csvfile); + $_POST['action'] = move_uploaded_file($_FILES['csvfile']['tmp_name'],$csvfile) ? + 'download' : ''; +} +else +{ + $csvfile = $GLOBALS['egw']->session->appsession('csvfile'); +} +if ($_POST['cancel']) +{ + @unlink($csvfile); + $GLOBALS['egw']->redirect_link('/admin/index.php'); +} +$GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog - Import CSV-File'); +$GLOBALS['egw']->common->egw_header(); - $boinfolog = createobject('infolog.boinfolog'); +$boinfolog = createobject('infolog.boinfolog'); - $GLOBALS['egw']->template->set_file(array('import_t' => 'csv_import.tpl')); - $GLOBALS['egw']->template->set_block('import_t','filename','filenamehandle'); - $GLOBALS['egw']->template->set_block('import_t','fheader','fheaderhandle'); - $GLOBALS['egw']->template->set_block('import_t','fields','fieldshandle'); - $GLOBALS['egw']->template->set_block('import_t','ffooter','ffooterhandle'); - $GLOBALS['egw']->template->set_block('import_t','imported','importedhandle'); - $GLOBALS['egw']->template->set_block('import_t','import','importhandle'); +$GLOBALS['egw']->template->set_file(array('import_t' => 'csv_import.tpl')); +$GLOBALS['egw']->template->set_block('import_t','filename','filenamehandle'); +$GLOBALS['egw']->template->set_block('import_t','fheader','fheaderhandle'); +$GLOBALS['egw']->template->set_block('import_t','fields','fieldshandle'); +$GLOBALS['egw']->template->set_block('import_t','ffooter','ffooterhandle'); +$GLOBALS['egw']->template->set_block('import_t','imported','importedhandle'); +$GLOBALS['egw']->template->set_block('import_t','import','importhandle'); - if(($_POST['action'] == 'download' || $_POST['action'] == 'continue') && (!$_POST['fieldsep'] || !$csvfile || !($fp=fopen($csvfile,'rb')))) - { - $_POST['action'] = ''; - } - $GLOBALS['egw']->template->set_var("action_url",$GLOBALS['egw']->link("/infolog/csv_import.php")); +if(($_POST['action'] == 'download' || $_POST['action'] == 'continue') && (!$_POST['fieldsep'] || !$csvfile || !($fp=fopen($csvfile,'rb')))) +{ + $_POST['action'] = ''; +} +$GLOBALS['egw']->template->set_var("action_url",$GLOBALS['egw']->link("/infolog/csv_import.php")); - $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 +$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 addr_id( $n_family,$n_given=null,$org_name=null ) { // find in Addressbook, at least n_family AND (n_given OR org_name) have to match @@ -137,7 +137,7 @@ function cat_id($cats) if (is_numeric($cat) && $GLOBALS['egw']->categories->id2name($cat) != '--') { $cat2id[$cat] = $ids[$cat] = $cat; - } + } elseif (($id = $GLOBALS['egw']->categories->name2id( addslashes($cat) ))) { // cat exists $cat2id[$cat] = $ids[$cat] = $id; @@ -158,395 +158,395 @@ function cat_id($cats) return $id_str; } - if ($_POST['next']) $_POST['action'] = 'next'; - switch ($_POST['action']) +if ($_POST['next']) $_POST['action'] = 'next'; +switch ($_POST['action']) +{ +case '': // Start, ask Filename + $GLOBALS['egw']->template->set_var('lang_csvfile',lang('CSV-Filename')); + $GLOBALS['egw']->template->set_var('lang_fieldsep',lang('Fieldseparator')); + $GLOBALS['egw']->template->set_var('lang_charset',lang('Charset of file')); + $GLOBALS['egw']->template->set_var('select_charset', + html::select('charset','', + $GLOBALS['egw']->translation->get_installed_charsets()+ + array('utf-8' => 'utf-8 (Unicode)'),True)); + $GLOBALS['egw']->template->set_var('fieldsep',$_POST['fieldsep'] ? $_POST['fieldsep'] : ';'); + $GLOBALS['egw']->template->set_var('submit',lang('Import')); + $GLOBALS['egw']->template->set_var('enctype','ENCTYPE="multipart/form-data"'); + + $GLOBALS['egw']->template->parse('rows','filename'); + break; + +case 'continue': +case 'download': + $GLOBALS['egw']->preferences->read_repository(); + $defaults = $GLOBALS['egw_info']['user']['preferences']['infolog']['cvs_import']; + if (!is_array($defaults)) { - case '': // Start, ask Filename - $GLOBALS['egw']->template->set_var('lang_csvfile',lang('CSV-Filename')); - $GLOBALS['egw']->template->set_var('lang_fieldsep',lang('Fieldseparator')); - $GLOBALS['egw']->template->set_var('lang_charset',lang('Charset of file')); - $GLOBALS['egw']->template->set_var('select_charset', - html::select('charset','', - $GLOBALS['egw']->translation->get_installed_charsets()+ - array('utf-8' => 'utf-8 (Unicode)'),True)); - $GLOBALS['egw']->template->set_var('fieldsep',$_POST['fieldsep'] ? $_POST['fieldsep'] : ';'); - $GLOBALS['egw']->template->set_var('submit',lang('Import')); - $GLOBALS['egw']->template->set_var('enctype','ENCTYPE="multipart/form-data"'); - - $GLOBALS['egw']->template->parse('rows','filename'); - break; - - case 'continue': - case 'download': - $GLOBALS['egw']->preferences->read_repository(); - $defaults = $GLOBALS['egw_info']['user']['preferences']['infolog']['cvs_import']; - if (!is_array($defaults)) - { - $defaults = array(); - } - $GLOBALS['egw']->template->set_var('lang_csv_fieldname',lang('CSV-Fieldname')); - $GLOBALS['egw']->template->set_var('lang_info_fieldname',lang('InfoLog-Fieldname')); - $GLOBALS['egw']->template->set_var('lang_translation',lang("Translation").' '.lang('help').''); - $GLOBALS['egw']->template->set_var('submit', - html::submit_button('convert','Import') . ' '. - html::submit_button('cancel','Cancel')); - $GLOBALS['egw']->template->set_var('lang_debug',lang('Test Import (show importable records only in browser)')); - $GLOBALS['egw']->template->parse('rows','fheader'); - - $info_names = array( - 'type' => 'Type: char(10) task,phone,note', - 'from' => 'From: text(255) free text if no Addressbook-entry assigned', - 'addr' => 'Addr: text(255) phone-nr/email-address', - 'subject' => 'Subject: text(255)', - 'des' => 'Description: text long free text', - 'location' => 'Location: text(255)', - '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' => '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', - 'datecompleted'=> 'Date completed: DateTime', - 'datemodified'=> 'Date Last Modified: DateTime, if empty = Date Created', - 'modifier' => 'Modifier: int(11) user-id, if empty current user', - 'priority' => 'Priority: 3=urgent, 2=high, 1=normal, 0=low', - 'planned_time'=> 'planned Time: int(11) time used in min', - 'used_time' => 'used Time: int(11) time used in min', - 'status' => 'Status: char(10) offer,not-started,ongoing,call,will-call,done,billed,cancelled', - 'percent' => 'Percent completed: int', -// 'confirm' => 'Confirmation: char(10) not,accept,finish,both when to confirm', - 'project_id' => 'Link to Projectmanager, use Project-ID, Title or @project_id(id_or_title)', - 'addr_id' => 'Link to Addressbook, use nlast,nfirst[,org] or @addr_id(nlast,nfirst,org)', - 'link_1' => '1. link: appname:appid the entry should be linked to, eg.: addressbook:123', - 'link_2' => '2. link: appname:appid the entry should be linked to, eg.: addressbook:123', - 'link_3' => '3. link: appname:appid the entry should be linked to, eg.: addressbook:123', - ); - // add custom fields - if ($boinfolog->customfields) - { - foreach($boinfolog->customfields as $name => $field) - { - if ($field['type'] == 'label' || !count($field['values']) && $field['rows'] <= 1 && $field['len'] <= 0) continue; - - $info_names['#'.$name] = lang('custom fields').': '.$field['label']; - } - } - - // 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 = "