<?php
$configSectionNames = $model->getConfigSectionHumanReadableName();
$links = array();

foreach ($model->getConfigItemsArray() as $name => $configSection) {
    $links[] = array(
        'name' => $name,
        'label' => $configSectionNames[$name],
        'url' => $this->createUrl("section", array("section" => $name)),
        'active' => isset($_GET['section']) && $_GET['section'] == $name,
        'linkOptions' => array(
            'data-translation-id' => 'SYSTEM_GLOBAL_CONFIG_SECTION_TITLE_' . $name,
        ),
    );
}
$this->widget('ext.PlNavbar', array(
    'brand' => __('SYSTEM_GLOBAL_CONFIG_SECTION_TITLE'),
    'items' => array(
        array(
            'class' => 'bootstrap.widgets.TbMenu',
            'items' => $links,
        ),
    ),
    'helpBtnUrl' => 'systemGlobalConfig-section'. $this->getSectionName($links)
));

if (Yii::app()->user->translateMode) {
    ?>
    <span data-translation-id="SYSTEM_GLOBAL_CONFIG_MESSAGING_CHANGES_SAVED_SUCCESSFULLY">SYSTEM_GLOBAL_CONFIG_MESSAGING_CHANGES_SAVED_SUCCESSFULLY: <?php echo __('SYSTEM_GLOBAL_CONFIG_MESSAGING_CHANGES_SAVED_SUCCESSFULLY'); ?></span><br />
    <span data-translation-id="SYSTEM_GLOBAL_SEND_TEST_EMAIL_TO_CHECK_CONFIG">SYSTEM_GLOBAL_SEND_TEST_EMAIL_TO_CHECK_CONFIG: <?php echo __('SYSTEM_GLOBAL_SEND_TEST_EMAIL_TO_CHECK_CONFIG'); ?></span><br />
    <span data-translation-id="SYSTEM_GLOBAL_SENDING_TEST_EMAIL">SYSTEM_GLOBAL_SENDING_TEST_EMAIL: <?php echo __('SYSTEM_GLOBAL_SENDING_TEST_EMAIL'); ?></span><br />
    <h6>Email send messages</h6>
    <span data-translation-id="SYSTEM_GLOBAL_TEST_EMAIL_SENT_SUCCESSFULY">SYSTEM_GLOBAL_TEST_EMAIL_SENT_SUCCESSFULY: <?php echo __('SYSTEM_GLOBAL_TEST_EMAIL_SENT_SUCCESSFULY'); ?></span><br />
    <span data-translation-id="SYSTEM_GLOBAL_TEST_EMAIL_CHECK_YOUR_INBOX">SYSTEM_GLOBAL_TEST_EMAIL_CHECK_YOUR_INBOX: <?php echo __('SYSTEM_GLOBAL_TEST_EMAIL_CHECK_YOUR_INBOX'); ?></span><br />
    <span data-translation-id="SYSTEM_GLOBAL_TEST_EMAIL_SENT_FAILED">SYSTEM_GLOBAL_TEST_EMAIL_SENT_FAILED: <?php echo __('SYSTEM_GLOBAL_TEST_EMAIL_SENT_FAILED'); ?></span><br />
    <span data-translation-id="SYSTEM_GLOBAL_TEST_EMAIL_CHECK_YOUR_CONFIG">SYSTEM_GLOBAL_TEST_EMAIL_CHECK_YOUR_CONFIG: <?php echo __('SYSTEM_GLOBAL_TEST_EMAIL_CHECK_YOUR_CONFIG'); ?></span><br />
    <h6>Email states</h6>
    <span data-translation-id="EMAIL_STATE_PENDING">EMAIL_STATE_PENDING: <?php echo __('EMAIL_STATE_PENDING'); ?></span><br />
    <span data-translation-id="EMAIL_STATE_QUEUED">EMAIL_STATE_QUEUED: <?php echo __('EMAIL_STATE_QUEUED'); ?></span><br />
    <span data-translation-id="EMAIL_STATE_SENDING">EMAIL_STATE_SENDING: <?php echo __('EMAIL_STATE_SENDING'); ?></span><br />
    <span data-translation-id="EMAIL_STATE_SENT">EMAIL_STATE_SENT: <?php echo __('EMAIL_STATE_SENT'); ?></span><br />
    <span data-translation-id="EMAIL_STATE_FAILED">EMAIL_STATE_FAILED: <?php echo __('EMAIL_STATE_FAILED'); ?></span><br />
    <h6>Email content</h6>
    <span data-translation-id="TEST_EMAIL_SUBJECT">TEST_EMAIL_SUBJECT: <?php echo __('TEST_EMAIL_SUBJECT'); ?></span><br />
    <span data-translation-id="TEST_EMAIL_BODY">TEST_EMAIL_BODY: <?php echo __('TEST_EMAIL_BODY'); ?></span><br />
    <h6>Provisioning</h6>
    <span data-translation-id="DUMMY_PROFILE_EMPTY">DUMMY_PROFILE_EMPTY: <?php echo __('DUMMY_PROFILE_EMPTY'); ?></span><br />

    <i data-translation-id="SYSTEM_GLOBAL_CONFIG_DATE_FORMAT_Y_M_D" data-translation-target="SYSTEM_GLOBAL_CONFIG_TRANSLATION_TARGET_USER_DATE_FORMAT"></i>
    <i data-translation-id="SYSTEM_GLOBAL_CONFIG_DATE_FORMAT_D_M_Y"	data-translation-target="SYSTEM_GLOBAL_CONFIG_TRANSLATION_TARGET_USER_DATE_FORMAT"></i>
    <i data-translation-id="SYSTEM_GLOBAL_CONFIG_DATE_FORMAT_M_D_Y" data-translation-target="SYSTEM_GLOBAL_CONFIG_TRANSLATION_TARGET_USER_DATE_FORMAT"></i>
    <i data-translation-id="SYSTEM_GLOBAL_CONFIG_TIME_FORMAT_12H" data-translation-target="SYSTEM_GLOBAL_CONFIG_TRANSLATION_TARGET_USER_TIME_FORMAT"></i>
    <i data-translation-id="SYSTEM_GLOBAL_CONFIG_TIME_FORMAT_24H" data-translation-target="SYSTEM_GLOBAL_CONFIG_TRANSLATION_TARGET_USER_TIME_FORMAT"></i>
    <i data-translation-id="SYSTEM_GLOBAL_CONFIG_NAME_PATTERN_TITLE" data-translation-target="SYSTEM_GLOBAL_CONFIG_NAME_PATTERN"></i>
    <i data-translation-id="SYSTEM_GLOBAL_CONFIG_NAME_PATTERN_F" data-translation-target="SYSTEM_GLOBAL_CONFIG_NAME_PATTERN"></i>
    <i data-translation-id="SYSTEM_GLOBAL_CONFIG_NAME_PATTERN_FI" data-translation-target="SYSTEM_GLOBAL_CONFIG_NAME_PATTERN"></i>
    <i data-translation-id="SYSTEM_GLOBAL_CONFIG_NAME_PATTERN_FIRSTNAME" data-translation-target="SYSTEM_GLOBAL_CONFIG_NAME_PATTERN"></i>
    <i data-translation-id="SYSTEM_GLOBAL_CONFIG_NAME_PATTERN_LASTNAME" data-translation-target="SYSTEM_GLOBAL_CONFIG_NAME_PATTERN"></i>
    <i data-translation-id="SYSTEM_GLOBAL_CONFIG_NAME_PATTERN_COMPANY" data-translation-target="SYSTEM_GLOBAL_CONFIG_NAME_PATTERN"></i>
    <i data-translation-id="DUMMY_PROFILE_EMPTY" data-translation-target="DUMMY_PROFILE_EMPTY"></i>
    <i data-translation-id="SCRIPT_EXTENSION_EMPTY" data-translation-target="SCRIPT_EXTENSION_EMPTY">SCRIPT_EXTENSION_EMPTY: <?php echo __("SCRIPT_EXTENSION_EMPTY") ?></i>

    <h6>Password Security</h6>
    <span data-translation-id="PASSWORD_STRENGTH_NONE">PASSWORD_STRENGTH_NONE: <?php echo __('PASSWORD_STRENGTH_NONE'); ?></span><br />
    <span data-translation-id="PASSWORD_STRENGTH_MODERATE">PASSWORD_STRENGTH_MODERATE: <?php echo __('PASSWORD_STRENGTH_MODERATE'); ?></span><br />
    <span data-translation-id="PASSWORD_STRENGTH_STRONG">PASSWORD_STRENGTH_STRONG: <?php echo __('PASSWORD_STRENGTH_STRONG'); ?></span><br />
    <span data-translation-id="PASSWORD_STRENGTH_PARANOID">PASSWORD_STRENGTH_PARANOID: <?php echo __('PASSWORD_STRENGTH_PARANOID'); ?></span><br />

    
    <span data-translation-id="PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_TO_SHORT_3">PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_TO_SHORT_3: <?php echo __('PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_TO_SHORT_3'); ?></span><br />
    <span data-translation-id="PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_TO_SHORT_6">PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_TO_SHORT_6: <?php echo __('PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_TO_SHORT_6'); ?></span><br />
    <span data-translation-id="PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_TO_SHORT_8">PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_TO_SHORT_8: <?php echo __('PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_TO_SHORT_8'); ?></span><br />
    <span data-translation-id="PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_TO_SHORT_12">PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_TO_SHORT_12: <?php echo __('PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_TO_SHORT_12'); ?></span><br />

    <span data-translation-id="PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_NO_NUMBER">PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_NO_NUMBER: <?php echo __('PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_NO_NUMBER'); ?></span><br />
    <span data-translation-id="PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_NO_UPPERCASE_LETTER">PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_NO_UPPERCASE_LETTER: <?php echo __('PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_NO_UPPERCASE_LETTER'); ?></span><br />
    <span data-translation-id="PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_IS_USERNAME">PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_IS_USERNAME: <?php echo __('PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_IS_USERNAME'); ?></span><br />
    <span data-translation-id="PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_CONTAINS_USERNAME">PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_CONTAINS_USERNAME: <?php echo __('PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_CONTAINS_USERNAME'); ?></span><br />
    <span data-translation-id="PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_NO_SPECIAL_CHARACTER">PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_NO_SPECIAL_CHARACTER: <?php echo __('PHONALISA_PASSWORD_SECURITY_EXCEPTION_PASS_NO_SPECIAL_CHARACTER'); ?></span><br />



    <?php
}

$this->widget('bootstrap.widgets.TbAlert', array(
    'block' => true, // display a larger alert block?
    'fade' => true, // use transitions?
    'closeText' => '&times;', // close link text - if set to false, no close link is displayed
));
?>

<div class="form">

    <?php
    echo CHtml::beginForm();
    $this->widget('bootstrap.widgets.TbGridView', array(
        'id' => 'sysconfig-grid',
        'type' => 'striped bordered condensed',
        'itemsCssClass' => 'plTable',
        'dataProvider' => $model->getSectionItems($section),
        'summaryText' => false,
        'hideHeader' => false,
        'htmlOptions' => array(
            'class' => 'plTable'
        ),
        'columns' => array(
            array(
                'name' => 'short',
                'type' => 'raw',
                'header' => $model->getAttributeLabel('short'),
                'header' => __('SYSTEM_GLOBAL_CONFIG_HEADER_SHORT'),
                'headerHtmlOptions' => array(
                    'data-translation-id' => 'SYSTEM_GLOBAL_CONFIG_HEADER_SHORT',
                ),
            ),
            array(
                'name' => 'value',
                'type' => 'raw',
                'value' => 'app()->controller->renderValue($data, $row)',
                'header' => __('SYSTEM_GLOBAL_CONFIG_HEADER_VALUE'),
                'headerHtmlOptions' => array(
                    'data-translation-id' => 'SYSTEM_GLOBAL_CONFIG_HEADER_VALUE',
                ),
            ),
            array(
                'name' => 'defaultValue',
                'type' => 'raw',
                'value' => 'app()->controller->renderDefaultValue($data, $row)',
                'header' => __('SYSTEM_GLOBAL_CONFIG_HEADER_DEFAULT_VALUE'),
                'headerHtmlOptions' => array(
                    'data-translation-id' => 'SYSTEM_GLOBAL_CONFIG_HEADER_DEFAULT_VALUE',
                ),
            ),
            array(
                'name' => 'descr',
                'type' => 'raw',
                'header' => __('SYSTEM_GLOBAL_CONFIG_HEADER_FULL'),
                'headerHtmlOptions' => array(
                    'data-translation-id' => 'SYSTEM_GLOBAL_CONFIG_HEADER_FULL',
                ),
            ),
        ),
    ));

    echo CHtml::hiddenField('action', 'save');
    echo CHtml::submitButton('save', array('id' => 'saveSysconfigSectionAction', 'style' => 'display:none'));

    $this->widget('bootstrap.widgets.TbButton', array(
        'buttonType' => 'button',
        'type' => 'primary',
        'label' => __('GLOBAL_SAVE_BUTTON'),
        'loadingText' => 'loading...',
        'htmlOptions' => array(
            'id' => 'saveSysconfigSectionButton',
            'data-translation-id' => 'GLOBAL_SAVE_BUTTON',
        ),
    ));
    echo CHtml::endForm();
    ?>
</div>

<script>
    $('#saveSysconfigSectionButton').click(function () {
        var btn = $(this);
        btn.button('loading'); // call the loading function
        $("#saveSysconfigSectionAction").click();
    });

    $(function () {
        // Handler for .ready() called.
        $('#Sysconfig_UI_THEME').change(function () {
            var val = $(this).val();
            var cssUrl = '<?php echo Yii::app()->request->baseUrl; ?>/css/theme_';

            cssUrl += val + '.css';
            $('link[rel=stylesheet]:last').attr('href', cssUrl);
        });

        $('#Sysconfig_EMAIL_USER').prop('disabled', !$('#Sysconfig_EMAIL_AUTH_ON').is(':checked'));
        $('#Sysconfig_EMAIL_PASS').prop('disabled', !$('#Sysconfig_EMAIL_AUTH_ON').is(':checked'));
        $('#Sysconfig_EMAIL_TLS_CHECKCERT_ON').prop('disabled', !$('#Sysconfig_EMAIL_TLS_ON').is(':checked'));

        $('#Sysconfig_EMAIL_AUTH_ON').on('change', function () {
            $('#Sysconfig_EMAIL_USER').prop('disabled', !$(this).is(':checked'));
            $('#Sysconfig_EMAIL_PASS').prop('disabled', !$(this).is(':checked'));
        });

        $('#Sysconfig_EMAIL_TLS_ON').on('change', function () {
            $('#Sysconfig_EMAIL_TLS_CHECKCERT_ON').prop('disabled', !$(this).is(':checked'));
        });

        $('#EMail_recipient').on('input', function () {
            $('#sendMailBtn').prop('disabled', !document.getElementById('EMail_recipient').validity.valid);
        });
    });
</script>
