diff --git a/infolog/csv_import.php b/infolog/csv_import.php index 821925f883..b49e0c6ff2 100644 --- a/infolog/csv_import.php +++ b/infolog/csv_import.php @@ -85,29 +85,45 @@ function addr_id( $n_family,$n_given,$org_name ) { // find in Addressbook, at l $cat2id = array( ); -function cat_id( $cats ) +function cat_id($cats) { if (!$cats) + { return ''; - - $cats = explode(',',$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)) { + } + + $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( $cat )) { // cat exists + } + 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 ); + } + else + { // create new 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) { @@ -296,11 +312,9 @@ function cat_id( $cats ) $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] == '@') { $val = 'return '.substr($val,1).';';