mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-06-25 12:21:26 +02:00
fixed csv import:
- no more caching in the cat_id function, as it's done in the categories class in the API no - categories::name2id no longer caches not found entries, as they might be added in this request - contacts_sql::add set's all unset telefon numbers to '', to avoid the stupid db-default '+1 (000) 000-0000', which I dont want to change in the stable release
This commit is contained in:
parent
bba94d054e
commit
dc68edab46
@ -36,7 +36,7 @@
|
|||||||
$GLOBALS['egw']->redirect_link('/addressbook/index.php');
|
$GLOBALS['egw']->redirect_link('/addressbook/index.php');
|
||||||
}
|
}
|
||||||
$GLOBALS['egw_info']['flags']['app_header'] = lang('Import CSV-File into Addressbook');
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('Import CSV-File into Addressbook');
|
||||||
$GLOBALS['egw']->common->phpgw_header();
|
$GLOBALS['egw']->common->egw_header();
|
||||||
|
|
||||||
$GLOBALS['egw']->contacts = createobject('phpgwapi.contacts');
|
$GLOBALS['egw']->contacts = createobject('phpgwapi.contacts');
|
||||||
|
|
||||||
@ -81,51 +81,36 @@
|
|||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cat2id = array();
|
|
||||||
|
|
||||||
function cat_id($cats)
|
function cat_id($cats)
|
||||||
{
|
{
|
||||||
if(!$cats)
|
if(!$cats)
|
||||||
{
|
{
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
if(!is_object($GLOBALS['egw']->categories))
|
||||||
|
{
|
||||||
|
$GLOBALS['egw']->categories =& CreateObject('phpgwapi.categories');
|
||||||
|
}
|
||||||
$ids = array();
|
$ids = array();
|
||||||
foreach(split(' *[,;] *',$cats) as $cat)
|
foreach(split(' *[,;] *',$cats) as $cat)
|
||||||
{
|
{
|
||||||
if(isset($cat2id[$cat]))
|
if (is_numeric($cat) && $GLOBALS['egw']->categories->id2name($cat) != '--')
|
||||||
{
|
{
|
||||||
$ids[$cat] = $cat2id[$cat]; // cat is in cache
|
$id = (int) $cat;
|
||||||
|
}
|
||||||
|
elseif ($id = $GLOBALS['egw']->categories->name2id(addslashes($cat)))
|
||||||
|
{
|
||||||
|
// cat exists
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{ // create new cat
|
||||||
if(!is_object($GLOBALS['egw']->categories))
|
$id = $GLOBALS['egw']->categories->add(array('name' => $cat,'descr' => $cat));
|
||||||
{
|
|
||||||
$GLOBALS['egw']->categories = createobject('phpgwapi.categories');
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // create new cat
|
|
||||||
$GLOBALS['egw']->categories->add(array('name' => $cat,'descr' => $cat));
|
|
||||||
$cat2id[$cat] = $ids[$cat] = $GLOBALS['egw']->categories->name2id(addslashes($cat));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$ids[$id] = $id; // we use the $id as index to not ass a cat twice
|
||||||
}
|
}
|
||||||
$id_str = implode(',',$ids);
|
return implode(',',$ids);
|
||||||
|
|
||||||
if(count($ids) > 1) // multiple cats need to be in ','
|
|
||||||
{
|
|
||||||
$id_str = ",$id_str,";
|
|
||||||
}
|
|
||||||
return $id_str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_object($GLOBALS['egw']->html))
|
if (!is_object($GLOBALS['egw']->html))
|
||||||
{
|
{
|
||||||
$GLOBALS['egw']->html = CreateObject('phpgwapi.html');
|
$GLOBALS['egw']->html = CreateObject('phpgwapi.html');
|
||||||
@ -410,7 +395,7 @@
|
|||||||
$empty = !count($values);
|
$empty = !count($values);
|
||||||
|
|
||||||
// convert the category name to an id
|
// convert the category name to an id
|
||||||
if ($values['cat_id'] && !is_numeric($values['cat_id']) && $values['cat_id'][0] != ',')
|
if ($values['cat_id'])
|
||||||
{
|
{
|
||||||
$values['cat_id'] = cat_id($values['cat_id']);
|
$values['cat_id'] = cat_id($values['cat_id']);
|
||||||
}
|
}
|
||||||
@ -438,9 +423,8 @@
|
|||||||
}
|
}
|
||||||
if(!$_POST['debug'] && !$empty) // dont import empty contacts
|
if(!$_POST['debug'] && !$empty) // dont import empty contacts
|
||||||
{
|
{
|
||||||
$GLOBALS['egw']->contacts->add( $values['owner'] ? $values['owner'] : $GLOBALS['egw_info']['user']['account_id'],
|
$GLOBALS['egw']->contacts->add( $values['owner'] ? $values['owner'] : $GLOBALS['egw_info']['user']['account_id'],$values);
|
||||||
$values);
|
//echo "<p>adding: ".print_r($values,true)."</p>\n";
|
||||||
// echo "<p>adding: ".print_r($values)."</p>\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$log .= "\t</tr>\n</table>\n";
|
$log .= "\t</tr>\n</table>\n";
|
||||||
@ -459,5 +443,5 @@
|
|||||||
|
|
||||||
$GLOBALS['egw']->template->set_var('hiddenvars',str_replace('{','{',$hiddenvars));
|
$GLOBALS['egw']->template->set_var('hiddenvars',str_replace('{','{',$hiddenvars));
|
||||||
$GLOBALS['egw']->template->pfp('out','import',True);
|
$GLOBALS['egw']->template->pfp('out','import',True);
|
||||||
$GLOBALS['egw']->common->phpgw_footer();
|
$GLOBALS['egw']->common->egw_footer();
|
||||||
?>
|
?>
|
||||||
|
@ -607,7 +607,9 @@
|
|||||||
'(cat_owner = '.(int)$this->account_id.' OR cat_owner = -1)',
|
'(cat_owner = '.(int)$this->account_id.' OR cat_owner = -1)',
|
||||||
),__LINE__,__FILE__);
|
),__LINE__,__FILE__);
|
||||||
|
|
||||||
return $cache[$cat_name] = $this->db->next_record() ? $this->db->f('cat_id') : 0;
|
if (!$this->db->next_record()) return 0; // cat not found, dont cache it, as it might be created in this request
|
||||||
|
|
||||||
|
return $cache[$cat_name] = (int) $this->db->f('cat_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -610,10 +610,11 @@
|
|||||||
{
|
{
|
||||||
$fields['tid'] = 'n';
|
$fields['tid'] = 'n';
|
||||||
}
|
}
|
||||||
// setting the following fields to empty if unset, as the addressbook does not seem to set them anymore and I dont want to change the db-default atm.
|
// setting the telephone numbers to empty if unset, as otherwise the db-default adds '+1 (000) 000-0000'
|
||||||
foreach(array('tel_voice','tel_bbs','tel_modem') as $name)
|
// I dont want to change the default in the stable release
|
||||||
|
foreach($this->stock_contact_fields as $name)
|
||||||
{
|
{
|
||||||
if (!isset($fields[$name])) $fields[$name] = '';
|
if (substr($name,0,4) == 'tel_' && !isset($fields[$name])) $fields[$name] = '';
|
||||||
}
|
}
|
||||||
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
|
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user