{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
<!--// $Id$ //-->

<style>

    #general-settings {
        margin-bottom: 2em;
    }

    #userpanel-modules td {
        padding-top: 0.3em;
        padding-bottom: 0.3em;
    }

</style>

<H1>{$layout.pagetitle}</H1>

<form name="config" method="POST" action="?m=userpanel&f=submit_setup" id="general-settings-form">
</form>

<table class="lmsbox" id="general-settings">
    <colgroup>
        <col style="width: 1%;">
        <col style="width: 99%;">
    </colgroup>
    <thead>
        <tr>
            <td colspan="2" class="bold">
                {icon name="configuration"}
                {trans("Basic Configuration:")}
            </td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class="nobr">
                <label for="timeout">
                    {trans("Session timeout:")}
                </label>
            </td>
            <td>
                <input type="number" size="20" name="timeout" id="timeout" value="{$timeout}" form="general-settings-form">
            </td>
        </tr>
        <tr>
            <td class="nobr">
                <label for="page_header">
                    {trans("Page header")}:
                </label>
            </td>
            <td>
                <input type="text" size="50" name="page_header" id="page_header" value="{$page_header}" form="general-settings-form">
            </td>
        </tr>
        <tr>
            <td class="nobr">
                <label for="company_logo">
                    {trans("Company logo")}:
                </label>
            </td>
            <td>
                <input type="text" size="50" name="company_logo" id="company_logo" value="{$company_logo}"
                    placeholder="{trans("Enter path to your company logo")}" form="general-settings-form">
            </td>
        </tr>
        <tr>
            <td class="nobr">
                <label for="shortcut_icon">
                    {trans("Web browser icon")}:
                </label>
            </td>
            <td>
                <input type="text" size="50" name="shortcut_icon" id="shortcut_icon" value="{$shortcut_icon}" form="general-settings-form"
                    placeholder="{trans("Web browser icon")}" title="{trans("Enter full or relative URL address of web browser icon")}">
            </td>
        </tr>
        <tr>
            <td class="text-left nobr">
                {trans("Userpanel style:")}
            </td>
            <td>
                <select name="style" SIZE="1" {tip text="Userpanel design style" } form="general-settings-form">
                    {foreach $stylelist as $styleitem}
                        <option value="{$styleitem}"{if ($styleitem== $style) || ($styleitem=="default" && $style=="")} selected{/if}>{$styleitem}</option>
                    {/foreach}
                </select>
            </td>
        </tr>
        <tr>
            <td class="text-left nobr">
                <label for="extra_style">
                    {trans("Extra style sheet")}
                </label>
            </td>
            <td>
                <input type="text" size="50" name="extra_style" id="extra_style" value="{$extra_style}" form="general-settings-form"
                    placeholder="{trans("Enter full or relative URL address of extra style sheet file")}">
            </td>
        </tr>
        <tr>
            <td class="nobr">
                {trans("Hint style:")}
            </td>
            <td>
                <select name="hint" size="1"{tip text="Userpanel hints style. Chose modern for animated assistant, classic for tips in LMS style, or none to disable hints displaying"}
                    form="general-settings-form">
                    <option value="modern"{if $hint=='modern'} selected{/if}>{trans("modern")}</option>
                    <option value="classic"{if $hint=='classic'} selected{/if}>{trans("classic")}</option>
                    <option value="none"{if $hint=='none'} selected{/if}>{trans("none")}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td class="text-left nobr">
                {trans("Startup module:")}
            </td>
            <td>
                <select name="startupmodule" size="1" form="general-settings-form">
                    {$menu2 = $menu}
                    {array_multisort(Utils::array_column($menu2, 'name'), SORT_LOCALE_STRING, $menu2)}
                    {foreach $menu2 as $m}
                        {if $m.module !== "logout"}
                            <option value="{$m.module}" {if $startupmodule == $m.module}selected{/if}>{$m.name}</option>
                        {/if}
                    {/foreach}
                </select>
            </td>
        </tr>
        <tr>
            <td class="nobr">
                <label for="hide_nodes_modules">
                    {trans("Disabling modules:")}
                </label>
            </td>
            <td>
                <input type="checkbox" name="hide_nodes_modules" id="hide_nodes_modules" value="1" form="general-settings-form"
                    {if $hide_nodes_modules} checked{/if} {tip text="Hiding some modules useless when customer hasn't got any nodes"}>
            </td>
        </tr>
        <tr>
            <td class="nobr">
                <label for="mail_credential_reminders">
                    {trans("Mail credential reminders:")}
                </label>
            </td>
            <td>
                <input type="checkbox" id="mail_credential_reminders" name="mail_credential_reminders" {tip text="Mail credential reminders" }
                    form="general-settings-form" value="1"{if $mail_credential_reminders} checked{/if}>
            </td>
        </tr>
        <tr class="mail-credential-reminders">
            <td class="nobr">
                <label for="reminder_mail_sender">
                    {trans("Reminder mail sender:")}
                </label>
            </td>
            <td>
                <input type="text" size="50" name="reminder_mail_sender" id="reminder_mail_sender" form="general-settings-form"
                    value="{$reminder_mail_sender}" {tip text="Enter reminder mail sender" }>
            </td>
        </tr>
        <tr class="mail-credential-reminders">
            <td class="nobr">
                <label for="reminder_mail_subject">
                    {trans("Reminder mail subject:")}
                </label>
            </td>
            <td>
                <input type="text" size="50" name="reminder_mail_subject" id="reminder_mail_subject" form="general-settings-form"
                    value="{$reminder_mail_subject}" {tip text="Enter reminder mail subject" }>
            </td>
        </tr>
        <tr class="mail-credential-reminders">
            <td class="nobr">
                <label for="reminder_mail_body">
                    {trans("Reminder mail body:")}
                </label>
            </td>
            <td>
                <textarea name="reminder_mail_body" id="reminder_mail_body" cols="60" rows="7" {tip text="Enter reminder mail body" }
                    form="general-settings-form">{$reminder_mail_body}</textarea>
            </td>
        </tr>
        <tr>
            <td class="nobr">
                <label for="sms_credential_reminders">
                    {trans("SMS credential reminders:")}
                </label>
            </td>
            <td>
                <input type="checkbox" id="sms_credential_reminders" name="sms_credential_reminders" {tip text="SMS credential reminders"}
                    form="general-settings-form" value="1"{if $sms_credential_reminders} checked{/if}>
            </td>
        </tr>
        <tr class="sms-credential-reminders">
            <td class="nobr">
                <label for="reminder_sms_body">
                    {trans("Reminder sms body:")}
                </label>
            </td>
            <td>
                <textarea name="reminder_sms_body" id="reminder_sms_body" cols="60" rows="7" {tip text="Enter reminder sms body" }
                    form="general-settings-form">{$reminder_sms_body}</textarea>
            </td>
        </tr>
        <tr>
            <td class="nobr valign-top">
                <label for="reminder_type">{trans("Reminder type")}</label>
            </td>
            <td>
                <select id="reminder_type" name="reminder_type" {tip text="Userpanel reminder type"} form="general-settings-form">
                    {foreach $_USERPANEL_REMINDER_TYPES as $typeidx => $type}
                        <option value="{$typeidx}"{if $reminder_type == $typeidx} selected{/if}>{$type.selection}</option>
                        {if isset($type.options)}
                            {capture append="reminder_option_elements"}
                            <tr class="reminder-options" data-reminder-type="{$typeidx}">
                                <td></td>
                                <td>
                                    <fieldset>
                                        <legend class="bold">{$type['options-label']}</legend>
                                        <table>
                                            {foreach $type.options as $opt_idx => $opt}
                                                <tr>
                                                    <td>
                                                        <label for="reminder-option-{$typeidx}-{$opt_idx}">{$opt.label}</label>
                                                    </td>
                                                    <td>
                                                        {if $opt.type == 'single-select'}
                                                            {assign var=reminder_select_options value=call_user_func($opt.getter)}
                                                            <select id="reminder-option-{$typeidx}-{$opt_idx}"
                                                                name="{$opt.name}"
                                                                form="general-settings-form">
                                                                {foreach $reminder_select_options as $item}
                                                                    <option value="{$item.id}"
                                                                        {if $item.id == $reminder_options[$opt.name]} selected{/if}>
                                                                        {$item.label}
                                                                    </option>
                                                                {/foreach}
                                                            </select>
                                                        {/if}
                                                    </td>
                                                </tr>
                                            {/foreach}
                                        </table>
                                    </fieldset>
                                </td>
                            </tr>
                            {/capture}
                        {/if}
                    {/foreach}
                </select>
            </td>
        </tr>
        <tr>
            <td class="nobr valign-top">
                <label for="auth_type">{trans("Authentication type")}</label>
            </td>
            <td>
                <select id="auth_type" name="auth_type" {tip text="Userpanel authentication type"} form="general-settings-form">
                    {foreach $_USERPANEL_AUTH_TYPES as $typeidx => $type}
                        <option value="{$typeidx}"{if $auth_type == $typeidx} selected{/if}>{$type.selection}</option>
                        {if isset($type.options)}
                            {capture append="auth_option_elements"}
                              <tr class="auth-options" data-auth-type="{$typeidx}">
                                  <td></td>
                                  <td>
                                      <fieldset>
                                          <legend class="bold">{$type['options-label']}</legend>
                                          <table>
                                              {foreach $type.options as $opt_idx => $opt}
                                                  <tr>
                                                      <td>
                                                          <label for="auth-option-{$typeidx}-{$opt_idx}">{$opt.label}</label>
                                                      </td>
                                                      <td>
                                                          {if $opt.type == 'single-select'}
                                                              {assign var=auth_select_options value=call_user_func($opt.getter)}
                                                              <select id="auth-option-{$typeidx}-{$opt_idx}"
                                                                  name="{$opt.name}"
                                                                  form="general-settings-form">
                                                                  {foreach $auth_select_options as $item}
                                                                      <option value="{$item.id}"
                                                                          {if $item.id == $auth_options[$opt.name]} selected{/if}>
                                                                          {$item.label}
                                                                      </option>
                                                                  {/foreach}
                                                              </select>
                                                          {/if}
                                                      </td>
                                                  </tr>
                                              {/foreach}
                                          </table>
                                      </fieldset>
                                  </td>
                                </tr>
                            {/capture}
                        {/if}
                    {/foreach}
                </select>
            </td>
        </tr>
        {if !empty($auth_option_elements)}
            {foreach $auth_option_elements as $auth_option_element}
                {$auth_option_element}
            {/foreach}
        {/if}
        <tr>
            <td>
                <label for="twofactor_auth_type">
                    {trans("Two factor authentication")}
                </label>
            </td>
            <td>
                <select name="twofactor_auth_type" form="general-settings-form" id="twofactor_auth_type">
                    <option value="">{trans("<!twofactor-auth-type>— disabled —")}</option>
                    <option value="sms"{if $twofactor_auth_type == "sms"} selected{/if}>{trans("sms")}</option>
                    <option value="email"{if $twofactor_auth_type == "email"} selected{/if} disabled>{trans("email")}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td class="nobr">
                <label for="allowed_customer_status">
                    {trans("Allowed customer status")}
                </label>
            </td>
            <td>
                <select name="allowed_customer_status[]" class="lms-ui-multiselect" multiple
                    required data-default-value="{trans("— all —")}" form="general-settings-form">
                    {foreach Localisation::arraySort($_CSTATUSES, 'singularlabel') as $statusidx => $status}
                        <option value="{$statusidx}"
                            {if empty($allowed_customer_status) || in_array($statusidx, $allowed_customer_status)} selected{/if}
                        >{$status.singularlabel}</option>
                    {/foreach}
                </select>
            </td>
        </tr>
        <tr>
            <td class="nobr">
                <label for="pin_validation">
                    {trans("PIN validation")}
                </label>
            </td>
            <td>
                <input type="checkbox" name="pin_validation" id="pin_validation" form="general-settings-form"
                    {if !empty($pin_validation)} checked{/if}
                    {tip text="Userpanel PIN validation"}>
            </td>
        </tr>
        <tr>
            <td class="nobr">
                <label for="force_ssl">
                    {trans("Force SSL:")}
                </label>
            </td>
            <td>
                <input type="checkbox" name="force_ssl" id="force_ssl" value="1"{if $force_ssl} checked{/if}
                    form="general-settings-form"
                    {tip text="SSL Enforcing. Setting this option to 1 will effect with that LMS will enforce SSL connection with redirect to \'https://\'.$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI] at every request without SSL. Default: 0 (off)."}>
            </td>
        </tr>

        <tr>
            <td class="nobr">
                <label for="google_recaptcha_sitekey">
                    {trans("Google reCAPTCHA site key:")}
                </label>
            </td>
            <td>
                <input type="text" size="50" name="google_recaptcha_sitekey" id="google_recaptcha_sitekey"
                    form="general-settings-form" value="{$google_recaptcha_sitekey}" {tip text="Enter Google reCAPTCHA site key"}>
            </td>
        </tr>
        <tr>
            <td class="nobr">
                <label for="google_recaptcha_secret">
                    {trans("Google reCAPTCHA secret:")}
                </label>
            </td>
            <td>
                <input type="text" size="50" name="google_recaptcha_secret" id="google_recaptcha_secret"
                    form="general-settings-form" value="{$google_recaptcha_secret}" {tip text="Enter Google reCAPTCHA secret"}>
            </td>
        </tr>

        <tr>
            <td class="lms-ui-box-buttons" colspan="2">
                {button icon="save" label="Submit" onclick="document.config.submit();"}
            </td>
        </tr>
    </tbody>
</table>

<table id="userpanel-modules" class="lmsbox lms-ui-background-cycle">
    <thead>
        <tr>
            <td class="text-center bold">{trans("Module")}</td>
            <td class="text-center bold">{trans("Display name")}</td>
            <td class="text-center bold">{trans("Database version")}</td>
            <td class="text-center bold">{trans("Tip")}</td>
            <td class="text-center bold">{trans("Description")}</td>
            <td class="text-center bold">{trans("Enabled")}</td>
        </tr>
    </thead>
    <tbody>
        {foreach $menu as $menuitem}
            <tr class="highlight{if !in_array($menuitem.module, $enabled_modules)} blend{/if}"
                data-module="{$menuitem.module}">
                <td data-target-url="?m=userpanel&module={$menuitem.module}">
                    {if empty($menuitem.icon)}
                        <img src="img/recover.gif" class="module-icon">
                    {else}
                        <i class="{$menuitem.icon} fa-fw module-icon"></i>
                    {/if}
                    {$menuitem.module}
                </td>
                <td data-target-url="?m=userpanel&module={$menuitem.module}">
                    {$menuitem.name}
                </td>
                <td data-target-url="?m=userpanel&module={$menuitem.module}" class="text-center">
                    {if $menuitem.dbver>0}{$menuitem.dbver}{else}{trans("-")}{/if}
                </td>
                <td data-target-url="?m=userpanel&module={$menuitem.module}">
                    {t}{$menuitem.tip}{/t}
                </td>
                <td data-target-url="?m=userpanel&module={$menuitem.module}">
                    {t}{$menuitem.description}{/t}
                </td>
                <td class="text-center">
                    <input type="checkbox" name="enabled_modules[{$menuitem.module}]" value="1" form="general-settings-form"
                        {if in_array($menuitem.module, $enabled_modules)} checked{/if}>
                </td>
            </tr>
        {/foreach}
    </tbody>
    <tfoot>
        <tr class="dark">
            <td colspan="5" class="ftop bold text-center">
                {trans("Total:")} {$total}
            </td>
            <td class="ftop buttons nobr">
                {button icon="save" label="Submit" onclick="document.config.submit();"}
            </td>
        </tr>
    </tfoot>
</table>

<script>

	$(function() {
		$('#userpanel-modules').sortable({
			items: 'tbody > tr[data-module]',
			handle: '.module-icon',
			opacity: 0.9,
			axis: 'y',
			placeholder: 'light',
			update: function (event, ui) {
				var modules = [];
				ui.item.parent().children('tr[data-module]').each(function (index, value) {
					modules.push($(this).attr('data-module'));
				});
				$.ajax('?m=userpanel&f=save_module_order', {
					method: "POST",
					data: {
						modules: modules
					},
					dataType: "json",
					success: function (data, textStatus, qXHR) {
						if (data.result === undefined || data.result != 'OK') {
							$('#userpanel-modules').sortable('cancel');
							alert('{trans("LMS: operation failed!")}');
						}
					},
					error: function (jqXHR, textStatus, errorThrown) {
						$('#userpanel-modules').sortable('cancel');
						alert('{trans("AJAX: Invalid result - status:")}' + textStatus + '!');
					}
				});
			}
		});

        $('#mail_credential_reminders').change(function () {
            $('.mail-credential-reminders').toggle($(this).prop('checked'));
        }).trigger('change');

        $('#sms_credential_reminders').change(function () {
            $('.sms-credential-reminders').toggle($(this).prop('checked'));
        }).trigger('change');

        $('[name="auth_type"]').change(function () {
            $(".auth-options").find('fieldset').addClass('lms-ui-disabled').find("[form]").prop('disabled', true).addClass('lms-ui-disabled');
            $('.auth-options[data-auth-type="' + $(this).val() + '"]').find('fieldset').removeClass('lms-ui-disabled').find("[form]").prop('disabled', false).removeClass('lms-ui-disabled');
        }).change();
        $('[name="reminder_type"]').change(function () {
            $(".reminder-options").find('fieldset').addClass('lms-ui-disabled').find("[form]").prop('disabled', true).addClass('lms-ui-disabled');
            $('.reminder-options[data-reminder-type="' + $(this).val() + '"]').find('fieldset').removeClass('lms-ui-disabled').find("[form]").prop('disabled', false).removeClass('lms-ui-disabled');
        }).change();
	});

</script>
{/block}
