fix for multiple cats separated by ';' and containing " ' " in the cat-names

This commit is contained in:
Ralf Becker 2002-02-14 18:42:19 +00:00
parent 4746eac65d
commit 8d7650092d

View File

@ -90,7 +90,7 @@
return ''; return '';
} }
$cats = explode(',',$cats); $cats = split('[,;]',$cats);
while (list($k,$cat) = each($cats)) while (list($k,$cat) = each($cats))
{ {
@ -104,18 +104,24 @@
{ {
$GLOBALS['phpgw']->categories = createobject('phpgwapi.categories'); $GLOBALS['phpgw']->categories = createobject('phpgwapi.categories');
} }
if ($id = $GLOBALS['phpgw']->categories->name2id( $cat )) if ($id = $GLOBALS['phpgw']->categories->name2id( addslashes($cat) ))
{ // cat exists { // cat exists
$cat2id[$cat] = $ids[$cat] = $id; $cat2id[$cat] = $ids[$cat] = $id;
} }
else else
{ // create new cat { // create new cat
$GLOBALS['phpgw']->categories->add( $cat,0,$cat,'','public',0); $GLOBALS['phpgw']->categories->add( array('name' => $cat,'descr' => $cat ));
$cat2id[$cat] = $ids[$cat] = $GLOBALS['phpgw']->categories->name2id( $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) switch ($action)
@ -308,12 +314,10 @@
$val = ereg_replace((string) $pattern,str_replace($VPre,'\\',$replace),(string) $val); $val = ereg_replace((string) $pattern,str_replace($VPre,'\\',$replace),(string) $val);
// echo "'$val'</p>"; // echo "'$val'</p>";
$quote = $val[0] == '@' ? "'" : '';
$reg = $CPreReg.'([a-zA-Z_0-9]+)'.$CPosReg; $reg = $CPreReg.'([a-zA-Z_0-9]+)'.$CPosReg;
while (ereg($reg,$val,$vars)) while (ereg($reg,$val,$vars))
{ // expand all CSV fields { // 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] == '@') if ($val[0] == '@')
{ {