<?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
 */

$attrs    = $this->attrs;
$classes  = isset($attrs['class']) ? trim($attrs['class']).' ' : '';
$classes .= sprintf('sly-form-col-%d sly-num%d', $this->columns, $this->num-1);

$attrs['class'] = $classes;

$attrs  = sly_Util_HTML::buildAttributeString($attrs);
$legend = sly_translate($this->legend);

?>

<fieldset <?php echo $attrs ?>>
	<?php if (mb_strlen($legend) > 0): ?><legend><?php echo sly_html($legend) ?></legend><?php endif ?>
	<div class="sly-form-wrapper">
		<?php

		$rowCount = count($this->rows);
		$columns  = $this->columns;

		foreach ($this->rows as $rowNum => $elements) {
			if (count($elements) == 1 && reset($elements) instanceof sly_Form_Fragment) {
				print reset($elements)->render();
			}
			else {
				if ($this->isMultilingual($elements)) {
					print $this->renderView('row_i18n.phtml', compact('rowNum', 'elements', 'columns', 'request'));
				}
				else {
					print $this->renderView('row.phtml', compact('rowNum', 'elements', 'columns', 'request'));
				}
			}
		}

		$registry = sly_Core::getTempRegistry();

		if ($this->isMultilingual() && sly_Util_Language::isMultilingual() && !$registry->has('sly.form.i18n.checkimg')) {
			sly_Core::getLayout()->addJavaScriptFile('assets/js/jquery.imgcheckbox.min.js');
			$registry->set('sly.form.i18n.checkimg', true);
		}

		?>
	</div>
</fieldset>
