From 8d7650092dc4de9dc82161acea3f03b51ca38cba Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 14 Feb 2002 18:42:19 +0000 Subject: [PATCH] fix for multiple cats separated by ';' and containing " ' " in the cat-names --- addressbook/csv_import.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/addressbook/csv_import.php b/addressbook/csv_import.php index ca82861b77..e48a334caf 100644 --- a/addressbook/csv_import.php +++ b/addressbook/csv_import.php @@ -90,7 +90,7 @@ return ''; } - $cats = explode(',',$cats); + $cats = split('[,;]',$cats); while (list($k,$cat) = each($cats)) { @@ -104,18 +104,24 @@ { $GLOBALS['phpgw']->categories = createobject('phpgwapi.categories'); } - if ($id = $GLOBALS['phpgw']->categories->name2id( $cat )) + if ($id = $GLOBALS['phpgw']->categories->name2id( addslashes($cat) )) { // cat exists $cat2id[$cat] = $ids[$cat] = $id; } else { // create new cat - $GLOBALS['phpgw']->categories->add( $cat,0,$cat,'','public',0); - $cat2id[$cat] = $ids[$cat] = $GLOBALS['phpgw']->categories->name2id( $cat ); + $GLOBALS['phpgw']->categories->add( array('name' => $cat,'descr' => $cat )); + $cat2id[$cat] = $ids[$cat] = $GLOBALS['phpgw']->categories->name2id( addslashes($cat) ); } } } - return implode( ',',$ids ); + $id_str = implode( ',',$ids ); + + if (count($ids) > 1) // multiple cats need to be in ',' + { + $id_str = ",$id_str,"; + } + return $id_str; } switch ($action) @@ -308,12 +314,10 @@ $val = ereg_replace((string) $pattern,str_replace($VPre,'\\',$replace),(string) $val); // echo "'$val'

"; - $quote = $val[0] == '@' ? "'" : ''; - $reg = $CPreReg.'([a-zA-Z_0-9]+)'.$CPosReg; while (ereg($reg,$val,$vars)) { // expand all CSV fields - $val = str_replace($CPre.$vars[1].$CPos,$quote.$fields[index($vars[1],$csv_fields)].$quote,$val); + $val = str_replace($CPre.$vars[1].$CPos,$val[0] == '@' ? "'".addslashes($fields[index($vars[1],$csv_fields)])."'" : $fields[index($vars[1],$csv_fields)],$val); } if ($val[0] == '@') {