<?php
/*
 * Copyright (c) 2013, webvariants GbR, http://www.webvariants.de
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

$name     = $this->getName();
$selected = sly_makeArray($this->getDisplayValue()); // list of selected keys

if ($this->getAttribute('multiple') == 'multiple') {
	$this->setAttribute('name', $name.'[]');
}

print '<select '.$this->getAttributeString('value').'>';

foreach ($this->values as $key => $value) {
	$sel   = in_array($key, $selected) ? ' selected="selected"' : '';
	$value = sly_html($value);

	if (preg_match('#^( *)#', $value, $matches)) {
		$value = preg_replace('#^( *)#', str_repeat('&nbsp;', strlen($matches[1])), $value);
	}

	print '<option value="'.sly_html($key).'"'.$sel.'>'.$value.'</option>';
}

print '</select>';
