diff --git a/api/src/Etemplate/Widget/Select.php b/api/src/Etemplate/Widget/Select.php index 0f29227445..d3a7f13115 100644 --- a/api/src/Etemplate/Widget/Select.php +++ b/api/src/Etemplate/Widget/Select.php @@ -515,6 +515,22 @@ class Select extends Etemplate\Widget //error_log(__METHOD__."('$name', TRUE) options=".array2string($options).' --> values='.array2string($values)); $options = $values; } + else if (end($options) && is_array(end($options)) && isset(end($options)['value'])) + { + $values = array(); + foreach($options as $index => $option) + { + if(is_array($option) && isset($option['value'])) + { + $values[$option['value']] = $option['label']; + } + else + { + $values[$index] = $option; + } + } + $options = $values; + } //error_log(__METHOD__."('$name') returning ".array2string($options)); return $options; } diff --git a/api/src/Etemplate/Widget/Taglist.php b/api/src/Etemplate/Widget/Taglist.php index e34a489e5e..24102f9854 100644 --- a/api/src/Etemplate/Widget/Taglist.php +++ b/api/src/Etemplate/Widget/Taglist.php @@ -88,7 +88,7 @@ class Taglist extends Etemplate\Widget { $results[] = array('id' => $id, 'label' => $name); } - + usort($results, function ($a, $b) use ($query) { $a_label = is_array($a["label"]) ? $a["label"]["label"] : $a["label"]; $b_label = is_array($b["label"]) ? $b["label"]["label"] : $b["label"]; @@ -97,7 +97,7 @@ class Taglist extends Etemplate\Widget similar_text($query, $b_label, $percent_b); return $percent_a === $percent_b ? 0 : ($percent_a > $percent_b ? -1 : 1); }); - + // switch regular JSON response handling off Api\Json\Request::isJSONRequest(false); @@ -144,6 +144,28 @@ class Taglist extends Etemplate\Widget foreach((array) $value as $key => $val) { + if($this->type == 'taglist-account') + { + // If in allowed options, skip account check to support app-specific options + if(count($allowed) > 0 && in_array($val, $allowed)) continue; + // validate accounts independent of options know to server + $account_type = $this->attrs['account_type'] ? $this->attrs['account_type'] : 'accounts'; + $type = $GLOBALS['egw']->accounts->exists($val); + //error_log(__METHOD__."($cname,...) form_name=$form_name, widget_type=$widget_type, account_type=$account_type, type=$type"); + if (!$type || $type == 1 && in_array($account_type, array('groups', 'owngroups', 'memberships')) || + $type == 2 && $account_type == 'users' || + in_array($account_type, array('owngroups', 'memberships')) && + !in_array($val, $GLOBALS['egw']->accounts->memberships( + $GLOBALS['egw_info']['user']['account_id'], true)) + ) + { + self::set_validation_error($form_name, lang("'%1' is NOT allowed ('%2')!", $val, + !$type?'not found' : ($type == 1 ? 'user' : 'group')),''); + $value = ''; + break; + } + continue; + } if(count($allowed) && !$this->attrs['allowFreeEntries'] && !array_key_exists($val,$allowed)) { self::set_validation_error($form_name,lang("'%1' is NOT allowed ('%2')!",$val,implode("','",array_keys($allowed))),'');