{include file="./index_top.tpl"}
{include file="./acc_top.tpl"}
<script>
    {if $checked_cnt}var checked_cnt ={$checked_cnt};
    {else}var checked_cnt = 0;{/if}

    function send_cat_acc_client(group, cat, obj, type) {
        var acc_img = $(obj).attr("src");
        var acc_type = $(obj).attr("data-type");
        if (acc_img == "images/acc_invisibe.png") var acc = (acc_type == "1" ? "1" : "0");
        else var acc = (acc_type == "1" ? "2" : "3");

        $.ajax({
            type: "POST",
            url: "edit_group.php",
            data: {
                save: '1',
                group: group,
                cat_item: type + cat,
                access: acc,
                csrf: '{$csrf}',
                rewrite: 0
            },
            success: function (msg) {
                change_eye(obj);
            }
        });
    }

    function change_eye(obj) {
        var acc_img = $(obj).attr("src");
        var acc_type = $(obj).attr("data-type");
        if (acc_img == "images/acc_invisibe.png") acc_img = (acc_type == "1" ? "allow" : "close");
        else acc_img = "invisibe";
        $(obj).attr("src", "images/acc_" + acc_img + ".png");
    }

    function set_client_group() {
        document.getElementById('reboot').value = 1;
        document.getElementById('group_form').submit();
    }

    $(function () {
        $('input[name=are_fields_editable]').click(function (e) {
            $('.editable_fields_list_tr').toggle();
        });
        if ($('input[name=are_fields_editable]').is(':checked')) {
            $('.editable_fields_list_tr').show();
        }
    });
    $(document).ready(function() {
            $('.chosen-select').chosen({
                allow_single_deselect: true,
            });
        });

</script>

{if $edit_group==1}
    <div style="font-size:14px; padding-top:10px;">
        <form action="" method="post">
            <input type="hidden" name="save_group_settings" value="1"/>
            <input type="hidden" name="group" value="777"/>
            <input type="hidden" name="csrf" value="{$csrf}"/>
            <table border=0 cellpadding=3>
                <tr>
                    <td align=right>{$lang.Group_name}<span class="help_bt" h_id="acc_Group_name"></span>:</td>
                    <td><input class="form-control" name="group_name" value="{$group.name}" size=30/></td>
                </tr>
                <tr>
                    <td align="right">{$lang.default_page}<span class="help_bt" h_id="default_page"></span>:
                    </td>
                    <td colspan=2 width="50%">
                        <select class="form-control" name="default_page">
                            <option value=" ">{$lang.absent_page}</option>
                            {foreach from=$dp_list item=dp_gr key=dp_gr_key}
                                <optgroup label="{$dp_gr.name}">
                                    {foreach from=$dp_gr.contents item=dp_item key=dp_item_key}
                                        <option value="{$dp_item.id}"
                                                {if $dp_item.id==$group.default_page}selected{/if}>{$dp_item.name}
                                            {if $dp_item.type=='r'} {$lang.report_page} {/if}
                                            {if $dp_item.type=='c'} {$lang.calendar_page} {/if}
                                        </option>
                                    {/foreach}
                                </optgroup>
                            {/foreach}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align=right nowrap>{$lang.Are_fields_editable}<span class="help_bt" h_id="Are_fields_editable"></span>:</td>
                    <td>
                        <input type="checkbox" name="are_fields_editable" {if $group.editable_fields}checked{/if}>
                        <input class="btn btn-default btn-sm" type="submit" onclick="return confirm('{$lang.confirm_apply_editable_to_all}');"
                               name="apply_editable_to_all" value="{$lang.apply_editable_to_all}">
                    </td>
                </tr>
                <tr class="editable_fields_list_tr" style="display:none;">
                    <td align="center" colspan="2">
                        <hr/>
                    </td>
                </tr>
                <tr class="editable_fields_list_tr" style="display:none;">
                    <td align="center" colspan="2"><b> {$lang.Editable_fields_list} </b></td>
                </tr>
                <tr class="editable_fields_list_tr" style="display:none">
                    <td align="right" style="width:183px;">{$lang.Login}:</td>
                    <td><input type="checkbox" name="editable[login]"
                               {if strpos($group.editable_fields, 'login')}checked{/if}></td>
                </tr>
                <tr class="editable_fields_list_tr" style="display:none;">
                    <td align="right" style="width:183px;">{$lang.Password}:</td>
                    <td><input type="checkbox" name="editable[password]"
                               {if strpos($group.editable_fields, 'password')}checked{/if}></td>
                </tr>
                <tr class="editable_fields_list_tr" style="display:none;">
                    <td align="right" style="width:183px;">{$lang.Fillot}:</td>
                    <td><input type="checkbox" name="editable[fio]"
                               {if strpos($group.editable_fields, 'fio')}checked{/if}></td>
                </tr>
                <tr class="editable_fields_list_tr" style="display:none;">
                    <td align="right" style="width:183px;">{$lang.e_mail}:</td>
                    <td><input type="checkbox" name="editable[e_mail]"
                               {if strpos($group.editable_fields, 'e_mail')}checked{/if}></td>
                </tr>
                <tr class="editable_fields_list_tr" style="display:none;">
                    <td align="right" style="width:183px;">{$lang.Phone}:</td>
                    <td><input type="checkbox" name="editable[phone]"
                               {if strpos($group.editable_fields, 'phone')}checked{/if}></td>
                </tr>
                {if $all_modules.telegram_notify}
                <tr class="editable_fields_list_tr" style="display:none;">
                    <td align="right" style="width:183px;">{$lang.Telegram_notify}:</td>
                    <td><input type="checkbox" name="editable[telegram]"
                               {if strpos($group.editable_fields, 'telegram')}checked{/if}></td>
                </tr>
                {/if}
                <tr class="editable_fields_list_tr" style="display:none;">
                    <td align="right" style="width:183px;">{$lang.system_lang}:</td>
                    <td><input type="checkbox" name="editable[lang]"
                               {if strpos($group.editable_fields, 'lang')}checked{/if}></td>
                </tr>
                <tr class="editable_fields_list_tr" style="display:none;">
                    <td align="right" style="width:183px;">{$lang.time_zone}:</td>
                    <td><input type="checkbox" name="editable[time_zone]"
                               {if strpos($group.editable_fields, 'time_zone')}checked{/if}></td>
                </tr>
                <!--tr class="editable_fields_list_tr" style="display:none;">
                    <td align="right" style="width:183px;">{$lang.window_scroll}:</td>
                    <td><input type="checkbox" name="editable[window_scroll]"
                               {if strpos($group.editable_fields, 'window_scroll')}checked{/if}></td>
                </tr-->
                <!--tr class="editable_fields_list_tr" style="display:none;">
                    <td align="right" style="width:183px;">{$lang.api_on}:</td>
                    <td><input type="checkbox" name="editable[api_on]"
                               {if strpos($group.editable_fields, 'api_on')}checked{/if}></td>
                </tr-->
                <tr class="editable_fields_list_tr" style="display:none;">
                    <td align="right" style="width:183px;">{$lang.sound_notify}:</td>
                    <td><input type="checkbox" name="editable[sound_on]"
                               {if strpos($group.editable_fields, 'sound_on')}checked{/if}></td>
                </tr>
                <tr class="editable_fields_list_tr" style="display:none;">
                    <td align="right" style="width:183px;">{$lang.cut_notify_text}:</td>
                    <td><input type="checkbox" name="editable[cut_notify_text]"
                               {if strpos($group.editable_fields, 'cut_notify_text')}checked{/if}></td>
                </tr>
                <tr class="editable_fields_list_tr" style="display:none;">
                    <td align="right" style="width:183px;">{$lang.display_notification_on}:</td>
                    <td><input type="checkbox" name="editable[display_notification_on]"
                               {if strpos($group.editable_fields, 'display_notification_on')}checked{/if}></td>
                </tr>
                <tr class="editable_fields_list_tr" style="display:none;">
                    <td align="right" style="width:183px;">{$lang.user_avatar}:</td>
                    <td><input type="checkbox" name="editable[user_avatar]"
                               {if strpos($group.editable_fields, 'user_avatar')}checked{/if}></td>
                </tr>
                <tr class="editable_fields_list_tr" style="display:none;">
                    <td align="right" style="width:183px;">{$lang.default_page}:</td>
                    <td><input type="checkbox" name="editable[default_page]"
                               {if strpos($group.editable_fields, 'default_page')}checked{/if}></td>
                </tr>
                <tr class="editable_fields_list_tr" style="display:none;">
                    <td align="right" style="width:183px;">{$lang.default_channel}:</td>
                    <td><input type="checkbox" name="editable[default_channel]"
                               {if strpos($group.editable_fields, 'default_channel')}checked{/if}></td>
                </tr>
                <tr class="editable_fields_list_tr" style="display:none;">
                    <td align="center" colspan="2">
                        <hr/>
                    </td>
                </tr>
            </table>
            <br/>
            <input class="btn btn-default btn-sm" type="submit" value="{$lang.Save}"/>
        </form>
    </div>
    <br/>
{else}
    <form action="edit_group.php?group={$group.id}" method="post" name="group_data" id="group_form">
        <table border=0 cellpadding=3>
            <tr>
                <td align="center">{$lang.allowed_tables}:</td>
            </tr>
            <tr>
                <td align="center">
                    {$client_sels}
                </td>
            </tr>
        </table>

        <table border=0 cellpadding=3>
            {foreach from=$client_sub item=one_table}
                <tr>
                    <td style="width:196px">
                        <div style="float:left;width:150px">
                            {if $one_table.name_table}
                                <div style="width:19px;float:left;height:13px;margin-right:5px;text-align:center">
                                    <img src='images/acc_{if $one_table.acc && $one_table.vis_acc}allow{elseif $one_table.acc}invisibe{else}close{/if}.png'
                                         data-type="{if $one_table.main_table}1{else}0{/if}"
                                         style='text-decoration:none;background-color:white;margin-top:2px;cursor:pointer'
                                         onclick="send_cat_acc_client({$group_id}, {$one_table.id}, this, 't')">
                                </div>
                                <a id="href_t_{$one_table.id}"
                                   href="edit_group.php?group={$group_id}&cat={$cat_id}&cat_item=t{$one_table.id}">{$one_table.name_table}</a>
                            {elseif $one_table.cron_id}
                                <a id="href_t_{$one_table.id}"
                                   href="edit_group.php?group={$group_id}&cat={$cat_id}&cat_item=r{$one_table.id}">{$one_table.name}</a>
                            {elseif $one_table.name}
                                <div style="width:19px;float:left;height:13px;margin-right:5px;text-align:center">
                                    <img src='images/acc_{if $one_table.access==1}allow{else}invisibe{/if}.png'
                                         style='text-decoration:none;background-color:white;margin-top:2px;'>
                                </div>
                                <a id="href_t_{$one_table.id}"
                                   href="edit_group.php?group={$group_id}&cat={$cat_id}&cat_item=r{$one_table.id}&rep_menu=rules">{$one_table.name}</a>
                            {/if}
                        </div>
                        {if $one_table.subtable}
                        <div style="float:left;width:16px;font-style: italic;color:gray;">{$lang.subtable}
                            <div>
                                {/if}
                    </td>
                </tr>
            {/foreach}
            {foreach from=$client_sub2 item=one_table}
                <tr>
                    <td style="width:196px">
                        <div style="float:left;width:150px">
                            {if $one_table.name_table}
                                <div style="width:19px;float:left;height:13px;margin-right:5px;text-align:center">
                                    <img src='images/acc_{if $one_table.acc==1 && $one_table.vis_acc==1}allow{else}invisibe{/if}.png'
                                         style='text-decoration:none;background-color:white;margin-top:2px;'>
                                </div>
                                <a id="href_t_{$one_table.id}"
                                   href="edit_group.php?group={$group_id}&cat={$cat_id}&cat_item=t{$one_table.id}">{$one_table.name_table}</a>
                            {elseif $one_table.cron_id}
                                <a id="href_t_{$one_table.id}"
                                   href="edit_group.php?group={$group_id}&cat={$cat_id}&cat_item=r{$one_table.id}">{$one_table.name}</a>
                            {elseif $one_table.name}
                                <div style="width:19px;float:left;height:13px;margin-right:5px;text-align:center">
                                    <img src='images/acc_{if $one_table.access==1}allow{else}invisibe{/if}.png'
                                         style='text-decoration:none;background-color:white;margin-top:2px;'>
                                </div>
                                <a id="href_t_{$one_table.id}"
                                   href="edit_group.php?group={$group_id}&cat={$cat_id}&cat_item=r{$one_table.id}&rep_menu=rules">{$one_table.name}</a>
                            {/if}
                        </div>
                        {if $one_table.subtable}
                        <div style="float:left;width:16px;font-style: italic;color:gray;">{$lang.subtable}
                            <div>
                                {/if}
                    </td>
                </tr>
            {/foreach}
            {foreach from=$client_sub3 item=one_table}
                <tr>
                    <td style="width:196px">
                        <div style="float:left;width:150px">
                            {if $one_table.name_table}
                                <div style="width:19px;float:left;height:13px;margin-right:5px;text-align:center">
                                    <img src='images/acc_{if $one_table.acc==1 && $one_table.vis_acc==1}allow{else}invisibe{/if}.png'
                                         style='text-decoration:none;background-color:white;margin-top:2px;'>
                                </div>
                                <a id="href_t_{$one_table.id}"
                                   href="edit_group.php?group={$group_id}&cat={$cat_id}&cat_item=t{$one_table.id}">{$one_table.name_table}</a>
                            {elseif $one_table.cron_id}
                                <a id="href_t_{$one_table.id}"
                                   href="edit_group.php?group={$group_id}&cat={$cat_id}&cat_item=r{$one_table.id}">{$one_table.name}</a>
                            {elseif $one_table.name}
                                <div style="width:19px;float:left;height:13px;margin-right:5px;text-align:center">
                                    <img src='images/acc_allow.png'
                                         style='text-decoration:none;background-color:white;margin-top:2px;'>
                                </div>
                                {$one_table.name}
                            {/if}
                        </div>
                        {if $one_table.subtable}
                        <div style="float:left;width:16px;font-style: italic;color:gray;">{$lang.subtable}
                            <div>
                                {/if}
                    </td>
                </tr>
            {/foreach}

        </table>

        <input type=hidden name='csrf' value='{$csrf}'>
        <input type="hidden" name="reboot" id="reboot" value=0>
        <input type="hidden" name="save_client_acc" value=1>
    </form>
    <br>
{/if}
<a href="edit_group.php">{$lang.Return_to_group}</a>
<br/><br/>
<script>
$(document).on('change', 'select[name^="allowed_tables_"]', function() {
    $(this).chosen({
        allow_single_deselect: true,
    });
});
</script>
<style>
    .chosen-container-single .chosen-single abbr {
        display: none;
    }

    #group_form .chosen-container {
      margin-bottom: 5px;
    }
</style>
