diff -Nru egroupware-1.4.004-2.dfsg/about.php /tmp/zYV1ViGWhF/egroupware-1.6.001+dfsg/about.php --- egroupware-1.4.004-2.dfsg/about.php 2008-04-15 14:57:39.000000000 +0100 +++ egroupware-1.6.001+dfsg/about.php 2008-11-24 11:42:31.000000000 +0000 @@ -17,7 +17,7 @@ * @author Ralf Becker * @license http://www.gnu.org/copyleft/gpl.html * @link http://www.egroupware.org - * @version SVN: $Id: about.php 23959 2007-05-27 07:50:57Z lkneschke $ + * @version SVN: $Id: about.php 23950 2007-05-26 19:06:12Z ralfbecker $ */ $GLOBALS['egw_info'] = array( diff -Nru /tmp/IEcAucsswJ/egroupware-1.4.004-2.dfsg/addressbook/csv_import.php /tmp/zYV1ViGWhF/egroupware-1.6.001+dfsg/addressbook/csv_import.php --- egroupware-1.4.004-2.dfsg/addressbook/csv_import.php 2008-04-15 14:59:26.000000000 +0100 +++ egroupware-1.6.001+dfsg/addressbook/csv_import.php 2008-11-24 11:43:09.000000000 +0000 @@ -1,440 +1,435 @@ * - * -------------------------------------------- * - * 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. * - \**************************************************************************/ +/** + * Addressbook - CSV Import + * + * @link http://www.egroupware.org + * @author Ralf Becker + * @package addressbook + * @copyright (c) 2003-8 by Ralf Becker + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id: csv_import.php 26318 2008-11-07 09:59:49Z ralfbecker $ + */ - /* $Id: csv_import.php 21465 2006-04-26 21:23:38Z ralfbecker $ */ - - $GLOBALS['egw_info']['flags'] = array( +$GLOBALS['egw_info'] = array( + 'flags' => array( 'currentapp' => 'addressbook', 'noheader' => True, - 'enable_contacts_class' => True, - ); - include('../header.inc.php'); - - if (isset($_FILES['csvfile']['tmp_name'])) + ), +); +include('../header.inc.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('/addressbook/index.php'); +} +$GLOBALS['egw_info']['flags']['app_header'] = lang('Import CSV-File into Addressbook'); +$GLOBALS['egw']->common->egw_header(); + +$GLOBALS['egw']->contacts = new contacts(); + +//$GLOBALS['egw']->template->set_unknowns('keep'); +$GLOBALS['egw']->template->set_file(array('import' => 'csv_import.tpl')); +$GLOBALS['egw']->template->set_block('import','filename','filenamehandle'); +$GLOBALS['egw']->template->set_block('import','fheader','fheaderhandle'); +$GLOBALS['egw']->template->set_block('import','fields','fieldshandle'); +$GLOBALS['egw']->template->set_block('import','ffooter','ffooterhandle'); +$GLOBALS['egw']->template->set_block('import','imported','importedhandle'); + +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('/addressbook/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 + +// 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['egw']->contacts->search(array('n_family'=>$n_family,'n_given'=>$n_given,'org_name'=>$org_name)); + if(!count($addrs)) { - $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' : ''; + $addrs = $GLOBALS['egw']->contacts->search(array('n_family'=>$n_family,'n_given'=>$n_given)); } - else + if(!count($addrs)) { - $csvfile = $GLOBALS['egw']->session->appsession('csvfile'); + $addrs = $GLOBALS['egw']->contacts->search(array('n_family'=>$n_family,'org_name'=>$org_name)); } - if ($_POST['cancel']) + + if(count($addrs)) { - @unlink($csvfile); - $GLOBALS['egw']->redirect_link('/addressbook/index.php'); + return $addrs[0]['id']; } - $GLOBALS['egw_info']['flags']['app_header'] = lang('Import CSV-File into Addressbook'); - $GLOBALS['egw']->common->egw_header(); - $GLOBALS['egw']->contacts = createobject('phpgwapi.contacts'); + return False; +} - //$GLOBALS['egw']->template->set_unknowns('keep'); - $GLOBALS['egw']->template->set_file(array('import' => 'csv_import.tpl')); - $GLOBALS['egw']->template->set_block('import','filename','filenamehandle'); - $GLOBALS['egw']->template->set_block('import','fheader','fheaderhandle'); - $GLOBALS['egw']->template->set_block('import','fields','fieldshandle'); - $GLOBALS['egw']->template->set_block('import','ffooter','ffooterhandle'); - $GLOBALS['egw']->template->set_block('import','imported','importedhandle'); - - if(($_POST['action'] == 'download' || $_POST['action'] == 'continue') && (!$_POST['fieldsep'] || !$csvfile || !($fp=fopen($csvfile,'rb')))) +function cat_id($cats) +{ + if(!$cats) { - $_POST['action'] = ''; + return ''; } - $GLOBALS['egw']->template->set_var('action_url',$GLOBALS['egw']->link('/addressbook/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 - - // 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) + $ids = array(); + foreach(split(' *[,;] *',$cats) as $cat) { - $addrs = $GLOBALS['egw']->contacts->search(array('n_family'=>$n_family,'n_given'=>$n_given,'org_name'=>$org_name)); - if(!count($addrs)) + if (is_numeric($cat) && $GLOBALS['egw']->categories->id2name($cat) != '--') { - $addrs = $GLOBALS['egw']->contacts->search(array('n_family'=>$n_family,'n_given'=>$n_given)); + $id = (int) $cat; } - if(!count($addrs)) + elseif ($id = $GLOBALS['egw']->categories->name2id(addslashes($cat))) { - $addrs = $GLOBALS['egw']->contacts->search(array('n_family'=>$n_family,'org_name'=>$org_name)); + // cat exists } + else + { // create new cat + $id = $GLOBALS['egw']->categories->add(array('name' => $cat,'descr' => $cat)); + } + $ids[$id] = $id; // we use the $id as index to not ass a cat twice + } + return implode(',',$ids); +} - if(count($addrs)) +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('csvfile',$csvfile); + $GLOBALS['egw']->template->set_var('enctype','ENCTYPE="multipart/form-data"'); + + $GLOBALS['egw']->template->parse('filenamehandle','filename'); + break; + + case 'continue': + case 'download': + $defaults = $GLOBALS['egw_info']['user']['preferences']['addressbook']['cvs_import']; + if(!is_array($defaults)) { - return $addrs[0]['id']; + $defaults = array(); } + $GLOBALS['egw']->template->set_var('lang_csv_fieldname',lang('CSV-Fieldname')); + $GLOBALS['egw']->template->set_var('lang_addr_fieldname',lang('Addressbook-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('fheaderhandle','fheader'); + + $addr_names = $GLOBALS['egw']->contacts->contact_fields; + $addr_names['cat_id'] .= ': id or name, comma separated list'; + $addr_names['private'] .= ': 0 = public, 1 = private'; + $addr_names['owner'] .= ': id or account name of user or group, defaults to importing user'; + $addr_names['bday'] .= ': YYYY-mm-dd'; + unset($addr_names['jpegphoto']); // cant cvs import that - return False; - } - - function cat_id($cats) - { - if(!$cats) + foreach($GLOBALS['egw']->contacts->customfields as $name => $data) { - return ''; + $addr_names['#'.$name] = $data['label']; } - if(!is_object($GLOBALS['egw']->categories)) + $addr_name_options = "