<?php

if ($model->typ == SysconfigValueType::MULTI) {
    $test = trim($model->value);
    if (empty($test)) {
        $toSearch = $model->defaultValue;
    } else {
        $toSearch = $model->value;
    }
    $mixedToOne = explode("\n", $toSearch);
    foreach ($mixedToOne as $index => $input) {
        $isDropdown = $index % 2 == 0;
        if ($isDropdown) {
            echo CHtml::dropDownList('Sysconfig[' . $model->key . '][]', $mixedToOne[$index], $model->getNamePattern(), array(
                'data-translation-target' => 'SYSTEM_GLOBAL_CONFIG_NAME_PATTERN',
                'style' => 'width: 94px'
                    )
            );
        } else {
            echo CHtml::textField('Sysconfig[' . $model->key . '][]', $mixedToOne[$index], array('style' => 'width: 15px'));
        }
    }
} else {
    $htmlOptions = array("disabled" => $model->readOnly);
    $chtmlType = $model->typ;
    $chtmlData = '';
    $chtmlValue = $model->value;
    $chtmlOptions = '';
    if ($model->typ == SysconfigValueType::INT) {
        $chtmlType = SysconfigValueType::TEXT;
        $chtmlValue = (int) $model->value;
        $chtmlData = $htmlOptions;
    } else if ($model->typ == SysconfigValueType::DROPDOWN) {
        $chtmlOptions = array('data-translation-target' => 'SYSTEM_GLOBAL_CONFIG_TRANSLATION_TARGET_' . strtoupper($model->key));
        $function = $model->optionValueCallback;
        if ($function != NULL) {
            $chtmlData = $model->$function();
        } else {
            $chtmlData = array();
        }
    } else if ($model->typ == SysconfigValueType::BOOL) {
        $chtmlData = array_merge($htmlOptions, array('name' => '.$value.', 'uncheckValue' => '0'));
    } else {
        $chtmlData = $htmlOptions;
    }
    echo CHtml::$chtmlType('Sysconfig[' . $model->key . ']', $chtmlValue, $chtmlData, $chtmlOptions);
}