Fix category select fails server-side validation, probably related to 8ec106f22b

This commit is contained in:
nathan 2023-01-09 11:46:54 -07:00
parent 5a093813ac
commit 9722716d1a

View File

@ -669,24 +669,28 @@ class Select extends Etemplate\Widget
$no_lang = True; $no_lang = True;
break; break;
case 'select-cat': // !$type == globals cats too, $type2: extraStyleMultiselect, $type3: application, if not current-app, $type4: parent-id, $type5=owner (-1=global),$type6=show missing case 'select-cat':
if ((!$type3 || $type3 === $GLOBALS['egw']->categories->app_name) && // !$type == globals cats too, $type2: extraStyleMultiselect, $type3: application, if not current-app, $type4: parent-id, $type5=owner (-1=global),$type6=show missing
$application = self::expand_name($widget->attrs['application'], 0, 0, '', '', self::$cont) ?? $type3;
$globalCategories = self::expand_name($widget->attrs['globalCategories'], 0, 0, '', '', self::$cont) ?? $type;
if((!$application || $application === $GLOBALS['egw']->categories->app_name) &&
(!$type5 || $type5 == $GLOBALS['egw']->categories->account_id)) (!$type5 || $type5 == $GLOBALS['egw']->categories->account_id))
{ {
$categories = $GLOBALS['egw']->categories; $categories = $GLOBALS['egw']->categories;
} }
else // we need to instanciate a new cat object for the correct application else // we need to instanciate a new cat object for the correct application
{ {
$categories = new Api\Categories($type5,$type3); $categories = new Api\Categories($type5, $application);
} }
// Allow text for global // Allow text for global
$type = ($type && strlen($type) > 1 ? $type : !$type); $globalCategories = ($globalCategories && strlen($globalCategories) > 1 ? $globalCategories : !$globalCategories);
// we cast $type4 (parent) to int, to get default of 0 if omitted // we cast $type4 (parent) to int, to get default of 0 if omitted
foreach((array)$categories->return_sorted_array(0,False,'','','',$type,(int)$type4,true) as $cat) foreach((array)$categories->return_sorted_array(0, False, '', '', '', $globalCategories, (int)$type4, true) as $cat)
{ {
$s = str_repeat(' ',$cat['level']) . stripslashes($cat['name']); $s = str_repeat(' ', $cat['level']) . stripslashes($cat['name']);
if (Api\Categories::is_global($cat)) if(Api\Categories::is_global($cat))
{ {
$s .= Api\Categories::$global_marker; $s .= Api\Categories::$global_marker;
} }