cats may now be separated by ',' or ';'

This commit is contained in:
Ralf Becker 2002-02-14 19:56:06 +00:00
parent 3bfa6c85d3
commit ca22fe93e1

View File

@ -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);
$cats = split('[,;]',$cats);
while (list($k,$cat) = each($cats)) {
if (isset($cat2id[$cat])) {
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)) {
}
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'</p>";
$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).';';