diff options
author | Bart Visscher <bartv@thisnet.nl> | 2011-11-05 20:33:42 +0100 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2011-11-09 22:19:52 +0100 |
commit | ef124c3e21ceae49f0f704589a833d1208d99c65 (patch) | |
tree | 896f352cd5abd17fee6c300f4c389883ebd3320a /lib/template.php | |
parent | 938c5ef21ce2870befcc16335998d48ad773433a (diff) | |
download | nextcloud-server-ef124c3e21ceae49f0f704589a833d1208d99c65.tar.gz nextcloud-server-ef124c3e21ceae49f0f704589a833d1208d99c65.zip |
Use a function to generate select options
Diffstat (limited to 'lib/template.php')
-rw-r--r-- | lib/template.php | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/template.php b/lib/template.php index 440b62003e7..d1439199e1e 100644 --- a/lib/template.php +++ b/lib/template.php @@ -98,6 +98,33 @@ function relative_modified_date($timestamp) { else { return $l->t('years ago'); } } +function html_select_options($options, $selected, $params=array()) { + if (!is_array($selected)){ + $selected=array($selected); + } + if (isset($params['combine']) && $params['combine']){ + $options = array_combine($options, $options); + } + $value_name = $label_name = false; + if (isset($params['value'])){ + $value_name = $params['value']; + } + if (isset($params['label'])){ + $label_name = $params['label']; + } + $html = ''; + foreach($options as $value => $label){ + if ($value_name && is_array($label)){ + $value = $label[$value_name]; + } + if ($label_name && is_array($label)){ + $label = $label[$label_name]; + } + $select = in_array($value, $selected) ? ' selected="selected"' : ''; + $html .= '<option value="' . $value . '"' . $select . '>' . $label . '</option>'; + } + return $html; +} /** * This class provides the templates for owncloud. |