<?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
 */
?>
<?php 
$groupAttr = array('id' => $this->getID());
if (isset($this->groupAttr) && is_array($this->groupAttr)) {
	$groupAttr = $this->groupAttr;
}
$groupAttr['class'] = 'sly-select-' . $type . '-list sly-select-group' . (array_key_exists('class', $groupAttr) ? ' ' . $groupAttr['class'] : '');
if (array_key_exists('style', $groupAttr) && is_array($groupAttr['style'])) {
	$new_style = '';
	foreach ($groupAttr['style'] as $k => $v) {
		$new_style .= $k . ':' . $v . ';';
	}
	$groupAttr['style'] = $new_style;
}
?>
<span <?php echo sly_Util_HTML::buildAttributeString($groupAttr) ?>>
	<?php
	$selected  = sly_makeArray($this->getDisplayValue());
	$elementID = $this->getID();

	foreach ($this->values as $key => $value) {
		$checked  = in_array($key, $selected);
		$id       = 'sly_autogen_'.$elementID.'_'.$key.'_id';
		$attr     = array(
			'type'    => $type,
			'value'   => $key,
			'id'      => $id,
			'name'    => $this->attributes['name'].($type == 'radio' ? '' : '[]'),
			'checked' => $checked ? 'checked' : '',
			'class'   => 'sly-form-checkbox',
			'style'   => isset($this->attributes['style']) ? $this->attributes['style'] : ''
		);

		print '<span><input '.sly_Util_HTML::buildAttributeString($attr).' /> ';
		print '<label for="'.$id.'" class="sly-inline">'.sly_html($value).'</label></span>';
		print "\n";
	}
	?>
</span>

<?php if ($type === 'checkbox' && count($this->values) > 1): ?>
<span class="sly-select-checkbox-list sly-form-helptext">
	<a rel="all" href="#"><?php echo t('select_all') ?></a> |
	<a rel="none" href="#"><?php echo t('select_none') ?></a>
</span>
<?php endif ?>
