{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, acc) {
        rewrite = 1;
        if (group == 777 && acc != 0) {
            $('#href_' + type + '_' + cat).css('display', '');
            $('#span_' + type + '_' + cat).css('display', 'none');
        }
        else {
            $('#href_' + type + '_' + cat).css('display', 'none');
            $('#span_' + type + '_' + cat).css('display', '');
        }

        $.ajax({
            type: "POST",
            url: "edit_group.php",
            data: {
                save: '1',
                group: group,
                cat_item: type + cat,
                access: acc,
                csrf: '{$csrf}',
                rewrite: rewrite,
                cat: '{$cat_id}'
            },
            success: function (msg) {
                if (acc == 0 && type == 't') {
                    $('#href_' + type + '_' + cat).css('display', 'none');
                    $('#span_' + type + '_' + cat).css('display', '');
                    checked_cnt = checked_cnt - 1;
                }
                if (group == 777 && acc == 1) {
                    var spl = msg.split('&&');
                    del_cnt = spl[1];
                    checked_cnt = spl[0];
                    if (checked_cnt < 4) {
                        if (type == 't') {
                            $('#href_' + type + '_' + cat).css('display', '');
                            $('#span_' + type + '_' + cat).css('display', 'none');
                        }
                    }
                    else {
                        change_eye(obj);
                        if (acc == 1) change_eye(obj);
                    }
                    if (del_cnt) {
                        if (type == 't') {
                            $('#href_' + type + '_' + del_cnt).css('display', 'none');
                            $('#span_' + type + '_' + del_cnt).css('display', '');
                        }
                        change_eye($('#eye_' + type + '_' + del_cnt));
                        if (acc == 1) change_eye($('#eye_' + type + '_' + del_cnt));
                    }
                }
            }
        });
    }

    function send_cat_acc(group, cat, obj, type) {
        var rewrite = 0;
        acc_img = $(obj).attr("src");
        if (acc_img == "images/acc_allow.png") var acc = "2";
        else if (acc_img == "images/acc_invisibe.png") var acc = "0";
        else var acc = "1";

        //обработка смены зеленого глазика для отчетов, проставление доступа
        if (type == 'r' && group && cat && obj) {
            //загорелся зеленый глаз
            if (obj.src.indexOf('acc_close.png') >= 0) {
                $.ajax({
                    type: "POST",
                    url: "edit_group.php",
                    data: { green_eye: '1', g_id: group, r_id: cat, csrf: '{$csrf}' }
                });
            }
            //загорелся замочек
            if (obj.src.indexOf('acc_invisibe.png') >= 0) {
                $.ajax({
                    type: "POST",
                    url: "edit_group.php",
                    data: { green_eye: '0', g_id: group, r_id: cat, csrf: '{$csrf}' }
                });
            }
        }

        $(obj).parent().parent().css('backgroundColor', '#fff6ad');
        if ($('#eye_sub_' + cat)) $('#eye_sub_' + cat).css('backgroundColor', '#fff6ad');
        $(obj).parent().parent().attr('b_col', acc);

        if (group == 777 && checked_cnt > 2 && acc == 1) {
            jconfirm('{$lang.client_table_limit}', function () {
                send_cat_acc_client(group, cat, obj, type, acc);
            }, function () {
                change_eye(obj);
                change_eye(obj);
            });
            return;
        }
        if (group == 777 && acc != 0) {
            checked_cnt = checked_cnt + 1;
            $('#href_' + type + '_' + cat).css('display', '');
            $('#span_' + type + '_' + cat).css('display', 'none');
        }
        else if (group == 777) {
            checked_cnt = checked_cnt - 1;
            $('#href_' + type + '_' + cat).css('display', 'none');
            $('#span_' + type + '_' + cat).css('display', '');
        }

        $.ajax({
            type: "POST",
            url: "edit_group.php",
            data: { save: '1', group: group, cat_item: type + cat, access: acc, csrf: '{$csrf}', rewrite: rewrite },
            success: function (msg) {
                if (acc == 0 && type == 't' && group == 777) {
                    $('#href_' + type + '_' + cat).css('display', 'none');
                    $('#span_' + type + '_' + cat).css('display', '');
                    checked_cnt = checked_cnt - 1;
                }
                if (group == 777 && acc == 1) {
                    var spl = msg.split('&&');
                    del_cnt = spl[1];
                    checked_cnt = spl[0];
                    if (checked_cnt < 4) {
                        if (type == 't') {
                            $('#href_' + type + '_' + cat).css('display', '');
                            $('#span_' + type + '_' + cat).css('display', 'none');
                        }
                    }
                    else {
                        change_eye(obj);
                        if (acc == 1) change_eye(obj);
                    }
                    if (del_cnt) {
                        if (type == 't') {
                            $('#href_' + type + '_' + del_cnt).css('display', 'none');
                            $('#span_' + type + '_' + del_cnt).css('display', '');
                        }
                        change_eye($('#eye_' + type + '_' + del_cnt));
                        if (acc == 1) change_eye($('#eye_' + type + '_' + del_cnt));
                    }
                }

                if ($(obj).parent().parent().attr('b_col') == acc) {
                    $(obj).parent().parent().css('backgroundColor', 'transparent');
                    if ($('#eye_sub_' + cat)) $('#eye_sub_' + cat).css('backgroundColor', 'transparent');
                    $(obj).parent().parent().attr('b_col', '');
                }
            }
        });
    }
    function change_eye(obj) {
        acc = $(obj).attr("src");
        if (acc == "images/acc_allow.png") acc_img = "invisibe";
        else if (acc == "images/acc_invisibe.png") acc_img = "close";
        else acc_img = "allow";
        $(obj).attr("src", "images/acc_" + acc_img + ".png");
    }
</script>
<br>
<table border=0 cellpadding=3>
    {foreach from=$tables item=one_table}
        {if $user.group_id == 1 || $user.sub_admin_rights.set_rights.tables[$one_table.id]}
        <tr>
            <td>{if $one_table.blocked}<img src="images/lock.svg" style="width:13px">{/if}</td>
            <td style="width:196px">
                <div style="width:19px;float:left;height:13px;margin-right:5px;text-align:center">
                    <img id="eye_t_{$one_table.id}"
                         src='images/acc_{if $one_table.acc==1}allow{elseif $one_table.acc==2}invisibe{else}close{/if}.png'
                         {if $one_table.blocked == 2}
                            onclick="jalert('{$lang.Blocked_table_alert_1} &quot;{$one_table.addon}&quot;<br>{$lang.Blocked_table_alert_2}'); return false;"
                         {elseif !$one_table.blocked}
                            onclick="send_cat_acc({$group_id}, {$one_table.id}, this, 't'); change_eye(this);"
                         {/if}
                         style='text-decoration:none;background-color:transparent;margin-top:2px;{if !$one_table.blocked}cursor:pointer{/if}'>
                </div>
                <div style="float:left;width:150px">
                    {if $user.group_id == 1 || $user.sub_admin_rights.set_rights.tables[$one_table.id] == 2}
                    <a id="href_t_{$one_table.id}"
                       {if $group_id==777 && !$one_table.client_tbl}style="display:none"{/if}
                       {if $one_table.blocked == 2}
                            class="gray_link" onclick="jalert('{$lang.Blocked_table_alert_1} &quot;{$one_table.addon}&quot;<br>{$lang.Blocked_table_alert_2}'); return false;"
                       {/if}
                       href="edit_group.php?group={$group_id}&cat={$cat_id}&cat_item=t{$one_table.id}">
                    {/if}
                        {$one_table.name_table}
                    </a>
                    <span id="span_t_{$one_table.id}"
                          {if $group_id!=777 || $one_table.client_tbl}style="display:none"{/if}>{$one_table.name_table}</span>
                </div>
                <div style="float:left;width:16px;font-style: italic;color:gray;"><span id="eye_sub_{$one_table.id}"
                                                                                        style="padding-top:3px;padding-bottom:3px;"><span
                                style="{if !$one_table.subtable}visibility:hidden;{/if}">{$lang.subtable}</span></span>
                    <div>

            </td>
        </tr>
        {/if}
    {/foreach}
    {foreach from=$reports item=one_report}
        {if $user.group_id == 1 || $user.sub_admin_rights.set_rights.reports[$one_report.id]}
        <tr>
            <td>{if $one_report.blocked}<img src="images/lock.svg" style="width:13px">{/if}</td>
            <td>
                <div style="width:19px;float:left;height:13px;margin-right:5px;text-align:center">
                    <img id="eye_r_{$one_report.id}"
                         src='images/acc_{if $one_report.acc==1}allow{elseif $one_report.acc==2}invisibe{else}close{/if}.png'
                         {if $one_report.blocked == 2}
                            onclick="jalert('{$lang.Blocked_report_alert_1} &quot;{$one_report.addon}&quot;<br>{$lang.Blocked_report_alert_2}'); return false;"
                         {elseif !$one_report.blocked}
                            onclick="send_cat_acc({$group_id}, {$one_report.id}, this, 'r'); change_eye(this);"
                         {/if}
                         style='text-decoration:none;background-color:transparent;margin-top:2px;{if !$one_report.blocked}cursor:pointer{/if}'>
                </div>
                <div style="float:left;width:150px">
                    {if ($user.group_id == 1 || $user.sub_admin_rights.set_rights.reports[$one_report.id] == 2) && $one_report.blocked != 2}
                    <a id="href_t_{$one_report.id}"
                       {if $group_id==777 && !$one_report.client_tbl}style="display:none"{/if}
                       href="edit_group.php?group={$group_id}&cat={$cat_id}&cat_item=r{$one_report.id}">
                    {/if}
                        {$one_report.name}
                    </a>
                    <span id="span_t_{$one_report.id}"
                          {if $group_id!=777 || $one_report.client_tbl}style="display:none"{/if}>{$one_report.name}</span>
                </div>
                <div style="float:left;width:16px;font-style: italic;color:gray;"><span id="eye_sub_{$one_report.id}"
                                                                                        style="padding-top:3px;padding-bottom:3px;"><span
                                style="visibility:hidden;">{$lang.subtable}</span></span>
                    <div>
            </td>
        </tr>
        {/if}
    {/foreach}
    {foreach from=$calendars item=one_calendar}
        {if $user.group_id == 1 || $user.sub_admin_rights.set_rights.calendars[$one_calendar.id]}
        <tr>
            <td>{if $one_calendar.blocked}<img src="images/lock.svg" style="width:13px">{/if}</td>
            <td>
                <div style="width:19px;float:left;height:13px;margin-right:5px;text-align:center">
                    <img id="eye_c_{$one_calendar.id}"
                         src='images/acc_{if $one_calendar.acc==1}allow{elseif $one_calendar.acc==2}invisibe{else}close{/if}.png'
                         {if $one_calendar.blocked == 2}
                            onclick="jalert('{$lang.Blocked_calend_alert_1} &quot;{$one_calendar.addon}&quot;<br>{$lang.Blocked_calend_alert_2}'); return false;"
                         {elseif !$one_calendar.blocked}
                            onclick="send_cat_acc({$group_id}, {$one_calendar.id}, this, 'c'); change_eye(this);"
                         {/if}
                         style='text-decoration:none;background-color:transparent;margin-top:2px;{if !$one_calendar.blocked}cursor:pointer{/if}'>
                </div>
                {$one_calendar.name}
            </td>
        </tr>
        {/if}
    {/foreach}
    {if $nothing==1}
        <tr>
        <td>{$lang.no_tables}</td></tr>{/if}
</table>
<br>
<a href="edit_group.php?group={$group_id}">{$lang.return_to_cat_list}</a>
<br/><br/>