<div class="page-title">
    <h1><?php echo $this->settingName;?></h1>
    <p class="alert-content"><?php echo $this->settingDescription;?></p>
</div>

<?php if ($this->description != "") { ?>
    <div class="alert alert-warning" style="width: 560px;"><?php echo $this->description;?></div>
<?php } ?>

<div class="cm-holder settings-wrapper">
    <form id="sitesettings" name="settings" method="post" action="index.php?fuse=admin&controller=settings&action=update" autocomplete="off">
        <input type="hidden" name="settingType" value="<?php echo $this->settingType;?>" />
        <input type="hidden" name="pluginName" value="<?php echo $this->selectedPlugin; ?>" />

        <?php
            $languages = CE_Lib::getEnabledLanguages(true);
            if ($this->settingIsLanguages && count($languages) > 1) {
                $active = true;
        ?>
            <ul class="nav nav-tabs">
            <?php foreach($languages as $languageKey => $language){ ?>
                <li class="nav-item">
                    <a class="nav-link <?php if ($active) { echo 'active'; $active = false; } ?>"  href="javascript:void(0)" onclick="settingsObject.filterBy(this,'<?php echo $languageKey; ?>')"><?php echo $language; ?></a>
                </li>
            <?php } ?>
            </ul>
        <?php } ?>
        <?php echo $this->settingsfields($this->settings);?>

        <div class="sec-box">
            <div class="texting">
                <input id="updatesettingbtn" data-loading-text="<?php echo $this->user->lang("Saving");?>..." type="submit" value="<?php echo $this->user->lang("Update Settings");?>" class="cm-btns orange lg">
                <?php if ($this->settingsGroup == 'admin_email') { ?>
                <button  id="testmailsettings" class="cm-btns dark lg" data-loading-text="<?php echo $this->user->lang("Testing");?>..."><span><?php echo $this->user->lang("Test Configuration");?></span></button>
                <?php } ?>
             </div>
         </div>
    </form>
</div>



<script data-cfasync="false" type="text/javascript">
    $(function() {

        <?php if ($this->settingsGroup == 'admin_email') { ?>

        $('#testmailsettings').click(function(e) {
            RichHTML.mask();
            e.preventDefault();
            <?php foreach ($this->settings as $key => $settings) { ?>
                <?php if ($settings['settingName'] == $this->user->lang('Mail Type')) { ?>
            var mail<?php echo $key; ?> = $('select[name=value_<?php echo $settings['settingId']; ?>]').val();
            <?php } else if ($settings['settingName'] == $this->user->lang('Ignore Invalid Mail Server SSL')) { ?>
            var mail<?php echo $key; ?> = $('input[name=value_<?php echo $settings['settingId']; ?>]:checked').val();
            <?php } else { ?>
            var mail<?php echo $key; ?> = $('input[name=value_<?php echo $settings['settingId']; ?>]').val();
                <?php } ?>
            <?php } ?>

            $('#testmailsettings').button('loading');
            $.ajax({
                url: 'index.php?fuse=admin&controller=settings&action=emailtest',
                type: 'POST',
                data: {
                    type: mail0,
                    host: mail1,
                    username: mail2,
                    password: mail3,
                    port: mail4,
                    overrideFrom: mail5,
                    ignoreSSL: mail6
                },
                success: function (json) {
                    $('#testmailsettings').button('reset');
                    if (json.error == true) {
                        RichHTML.error(json.message);
                    } else {
                        RichHTML.info(clientexec.lang('Test email sent successfully.'));
                    }
                }
            });
        });
        <?php } ?>

        $("#updatesettingbtn").click(function(e) {
            e.preventDefault();
            $('#updatesettingbtn').button('loading');
            var contactForm = $("#sitesettings");
            $.ajax({
                url: contactForm.attr( 'action' ),
                type: contactForm.attr( 'method' ),
                data: contactForm.serialize(),
                success: function (){
                    $('#updatesettingbtn').button('reset');
                    $.notify("Settings Updated");
                    <?php if ($this->settingsGroup == 'admin_localization' || $this->settingsGroup == 'admin_general') { ?>
                    location.reload();
                    <?php } ?>
                }
            });
            return false;
        });
    });

    settingsObject = {};
    settingsObject.filterBy = function(el, filter) {
        $(el).closest('.nav-tabs').find('li').find('a').removeClass('active')
        $(el).closest('li a').addClass('active');

        $('.language').hide();
        $('.'+filter).show();
    }
</script>