<div align=center>
    <script>
        function change_select(obj) {
            if (obj.value == 0)
                obj.style.color = '#8b8b8b';
            else
                obj.style.color = '#000000';

            if (obj.value == 777) {
                document.getElementById('cat_item_select').selectedIndex = 0;
                document.getElementById('cat_item_select').style.color = '#8b8b8b';
                document.getElementById('cat_item_select').disabled = 'disabled';
            }
            document.getElementById('select_from').submit();
        }
        function obnul_cat_item(i, obj) {
            if (obj.selectedIndex == 0 || i == 2) {
                document.getElementById('cat_item_select').selectedIndex = 0;
                document.getElementById('cat_item_select').style.color = '#8B8B8B';
                if (i == 1) {
                    document.getElementById('cat_select').selectedIndex = 0;
                    document.getElementById('cat_select').style.color = '#8B8B8B';
                }
            }
            else if (obj.value == 777) {
                document.getElementById('cat_item_select').selectedIndex = 0;
                document.getElementById('cat_item_select').style.color = '#8B8B8B';
                document.getElementById('cat_select').selectedIndex = 0;
                document.getElementById('cat_select').style.color = '#8B8B8B';
            }
        }

        function send_cat_acc2(group, cat, obj, type) {
            var rewrite = 0;
            var checked_cnt = cat;
            acc_img = $(obj).attr("src");
            if (acc_img == "images/acc_big_allow.png") {
                var acc = "2";
                if (type == 't' && document.getElementById("table_visacc_vis")) {
                    document.getElementById("table_visacc_vis").value = 0;
                    document.getElementById("table_visacc_acc").value = 1;
                }
                if (type == 'r' && document.getElementById("report_visacc_acc")) {
                    document.getElementById("report_visacc_acc").value = 2;
                }
            }
            else if (acc_img == "images/acc_big_invisibe.png" && group != 777) {
                var acc = "0";
                if (type == 't' && document.getElementById("table_visacc_vis")) {
                    document.getElementById("table_visacc_vis").value = 0;
                    document.getElementById("table_visacc_acc").value = 0;
                }
                if (type == 'r' && document.getElementById("report_visacc_acc")) {
                    document.getElementById("report_visacc_acc").value = 0;
                }
            }
            else {
                var acc = "1";
                if (type == 't' && document.getElementById("table_visacc_vis")) {
                    document.getElementById("table_visacc_vis").value = 1;
                    document.getElementById("table_visacc_acc").value = 1;
                }
                if (type == 'r' && document.getElementById("report_visacc_acc")) {
                    document.getElementById("report_visacc_acc").value = 1;
                }
            }

            $(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_eye2(obj);
            //         change_eye2(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_eye2(obj);
                    //         if (acc == 1) change_eye2(obj);
                    //     }
                    //     if (del_cnt) {
                    //         if (type == 't') {
                    //             $('#href_' + type + '_' + del_cnt).css('display', 'none');
                    //             $('#span_' + type + '_' + del_cnt).css('display', '');
                    //         }
                    //         change_eye2($('#eye_' + type + '_' + del_cnt));
                    //         if (acc == 1) change_eye2($('#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_eye2(obj, group) {
            acc = $(obj).attr("src");
            if (acc == "images/acc_big_allow.png") acc_img = "invisibe";
            else if (acc == "images/acc_big_invisibe.png" && group != 777) acc_img = "close";
            else acc_img = "allow";
            $(obj).attr("src", "images/acc_big_" + acc_img + ".png");

            // загорелся зеленый глаз
            if (acc_img == "allow") {
                $.ajax({
                    type: "POST",
                    url: "edit_group.php",
                    data: { green_eye: '1', g_id: '{$group_id}', r_id: '{$report_vis_acc.id}', csrf: '{$csrf}' },
                    success: function(data) {
                        if (data == 'changed') {
                            $('.user_acc_img').prop('src', 'images/check_on_m.png');
                            $('.user_acc_img').attr('o_value', 1);
                            $('.user_acc_input').prop('value', 1);
                            $('.user_acc_input').attr('o_value', 1);
                        }
                    }
                });
            }
            // загорелся замочек
            if (acc_img == "close") {
                $.ajax({
                    type: "POST",
                    url: "edit_group.php",
                    data: { green_eye: '0', g_id: '{$group_id}', r_id: '{$report_vis_acc.id}', csrf: '{$csrf}' },
                    success: function(data) {
                        if (data == 'changed') {
                            $('.user_acc_img').prop('src', 'images/check_off_m.png');
                            $('.user_acc_img').attr('o_value', 0);
                            $('.user_acc_input').prop('value', 0);
                            $('.user_acc_input').attr('o_value', 0);
                        }
                    }
                });
            }
        }
    </script>
    <br>{$title_text}<span class='help_bt' h_id='Groups_access'></span><br><br>
    <form id='select_from' action='' method='GET'>
        {if $edit_group}<input type="hidden" name="edit" value="{$edit_group}"/>{/if}
        <div class="search_bar" style="line-height:35px; border-bottom:1px solid #eaeaea;width:930px;">
          <table>
            <tr>
              <td style="color: #8B8B8B;padding: 0 15px;line-height: 12px;"></td>
              <td style="color: #8B8B8B;padding: 0 27px;line-height: 12px;"><b>{$lang.User_group}</b></td>
              <td style="color: #8B8B8B;padding: 0 15px;line-height: 12px;"><b>{$lang.Category}</b></td>
              <td style="color: #8B8B8B;padding: 0 15px;line-height: 12px;"><b>{$lang.Table}</b></td>
            </tr>

            <tr>
              <td>
                <a href="edit_group.php"><img style="float:left;margin-top:-2px;" src="images/dom.png"/></a>
              </td>

              <td>
                <div class="flex-row">
                  <span class='grey_next'>></span>
                  <select
                    name='group'
                    class='form-control form-control-160 acc_sel_item dont_use_chosen'
                    onchange='obnul_cat_item(1, this);change_select(this);'
                    {if $group_id}style='color:black;'{/if}
                  >
                    <option style='color: #8b8b8b;' value='0'> - {$lang.User_group} -</option>{$group_sel}
                  </select>
                  <span class='grey_next'>></span>
                </div>
              </td>

              <td>
                <div class="flex-row">
                  <select
                    name='cat'
                    id="cat_select"
                    class='form-control form-control-160 acc_sel_item dont_use_chosen'
                    {if $group_id==777}disabled{/if}
                    onchange='obnul_cat_item(2, this);change_select(this);'
                    {if $cat_id}style = 'color:black;'{/if}
                  >{$cat_sel}</select>
                  <span class='grey_next'>></span>
                </div>
              </td>

              <td>
                <div class="flex-row">
                  <select
                    name='cat_item'
                    id="cat_item_select"
                    class='form-control form-control-160 acc_sel_item dont_use_chosen'
                    {if $group_id==777}disabled{/if}
                    onchange='change_select(this);' {if $cat_item}style = 'color:black;'{/if}
                  >{$cat_item_sel}</select>
                </div>
              </td>

              <td width="20%" class="conf_navigation_access_cell">
                <div class="flex-row flex-jc-left">
                  <span>
                    <a href="{if $cat_item}{if $table_vis_acc.id}{if $menu=='filters'}edit_filter{elseif $menu=='tips'}edit_tip{elseif $menu=='buttons'}edit_button{elseif $menu=='subtables'}edit_subtable{elseif $menu=='addittables'}edit_addittable{elseif $menu=='templates'}forms{else}edit_field{/if}.php?table={$table_vis_acc.id}{if $menu=='templates'}&mode={$template_type}&admin{/if}{elseif $report_vis_acc.id}edit_report.php?report={$report_vis_acc.id}{else}edit_tabrep.php?calendar={$cat_item|replace:'c':''}{/if}{elseif $cat_id}edit_tabrep.php?cat={$cat_id}{else}edit_cat.php{/if}{$back_url_prm}" class="conf_navigation_href_top_menu">{$lang.Configuration}</a>
                  </span>
                </div>
              </td>
            </tr>
          </table>
        </div>
        {if $menu || $cats || $reports }
            <style>
                .href_top_menu:hover {
                    background-color: transparent;
                }

                div.bubble {
                    position: relative;
                    background-color: #fff;
                    border-bottom: 1px solid #DDDDDD;
                }

                div.bubble:before, div.bubble:after {
                    content: ' ';
                    position: absolute;
                    width: 0;
                    height: 0;
                }

                {if !$reports}
                div.speech:after {
                    left: {if $menu=='common'}218{elseif $menu=='rules' || !$menu}168{elseif $menu=='filters'}288{elseif $menu=='tips' && $rules_id>0}258{elseif $menu=='tips' && !$rules_id}389{elseif $menu=='tips'}533{elseif $menu=='templates' && $rules_id>0}438{elseif $menu=='templates' && !$rules_id}569{elseif $menu=='templates'}635{elseif $menu=='buttons' && $rules_id>0}622{elseif $menu=='buttons'}761{elseif $menu=='subtables' && $rules_id>0}722{elseif $menu=='subtables'}866{/if}px;
                    top: {if $menu=='rules' || $menu=='tips' && $rules_id || $menu=='templates' && $rules_id || $menu=='buttons' && $rules_id || $menu=='subtables' && $rules_id }47{else}53{/if}px;
                    border: 10px solid;
                    border-color: #fff transparent transparent transparent;
                }

                div.speech:before {
                    left: {if $menu=='common'}218{elseif $menu=='rules' || !$menu}168{elseif $menu=='filters'}288{elseif $menu=='tips' && $rules_id>0}258{elseif $menu=='tips' && !$rules_id}389{elseif $menu=='tips'}533{elseif $menu=='templates' && $rules_id>0}438{elseif $menu=='templates' && !$rules_id}569{elseif $menu=='templates'}635{elseif $menu=='buttons' && $rules_id>0}622{elseif $menu=='buttons'}761{elseif $menu=='subtables' && $rules_id>0}722{elseif $menu=='subtables'}866{/if}px;
                    top: {if $menu=='rules' || $menu=='tips' && $rules_id || $menu=='templates' && $rules_id || $menu=='buttons' && $rules_id || $menu=='subtables' && $rules_id }48{else}54{/if}px;
                    border: 10px solid;
                    border-color: #DDDDDD transparent transparent transparent;
                }

                div.speech_top:after {
                    left: {if $menu!='common' && $rules_id>0}{10 + (mb_strlen($rule_info.name)/2-1)*7 + 395}{elseif $menu!='common' && $rules_id<0}{10 + (mb_strlen($lang.This_new_rule)/2-1)*7 + 395}{elseif $menu=='rules' && !$rules_id}430{else}328{/if}px;
                    top: 41px;
                    border: 10px solid;
                    border-color: #fff transparent transparent transparent;
                }

                div.speech_top:before {
                    left: {if $menu!='common' && $rules_id>0}{10 + (mb_strlen($rule_info.name)/2-1)*7 + 395}{elseif $menu!='common' && $rules_id<0}{10 + (mb_strlen($lang.This_new_rule)/2-1)*7 + 395}{elseif $menu=='rules' && !$rules_id}430{else}328{/if}px;
                    top: 42px;
                    border: 10px solid;
                    border-color: #DDDDDD transparent transparent transparent;
                }

                {/if}

                @-moz-document url-prefix() {
                    div.speech:before {
                        left: 0px;
                        top: 0px;
                        border: 0px solid;
                        border-color: transparent transparent transparent transparent;
                    }
                }
            </style>
        {/if}
        {if $blocked}
            <div style="color:red; margin:20px;">
                {$lang.Blocked_table_alert_1} "{$addon.name}".<br>{$lang.Blocked_table_alert_2}
            </div>
        {else}
            {if !$reports && $menu}
                <div class="search_bar bubble speech_top"
                     style="line-height:25px;background-color:#ffffff;border-top:none;width:930px;padding-bottom:4px;z-index: 100;margin-bottom:15px;">
                    <table width="891">
                        <tr>
                            <td align="left" style="width: 255px;">
                                <div style="height: 30px;margin-left: 50px;">
                                    <div style="padding-top: 2px;">{$lang.This_now_rule}: &nbsp;</div>
                                </div>
                            </td>
                            <td align="left">
                                <span style="margin-right:25px">{if $menu == 'rules' || $rules_id || $subtable_id}<a
                                        class="href_top_menu" style="color:gray"
                                        href="edit_group.php?group={if $to_back}{$to_back}{else}{$group_id}{/if}&cat={$cat_id}&cat_item={$cat_item}&menu=common">{$lang.Default}</a>{else}
                                        <b>{$lang.Default}</b>{/if} </span>
                                {if $rules_id || $subtable_id}
                                <span style="margin-right:25px">
                                        <b>{if $rules_id>0}{$rule_info.name}{elseif $subtable_id}{$rule_name}{elseif $rules_id==-1}
                                            <i>{$lang.This_new_rule}</i>{/if}</b> </span>
                                {/if}
                                <span style="margin-right:25px">{if $menu != 'rules' || $rules_id || $subtable_id}<a
                                        class="href_top_menu"
                                        style="{if $menu!='rules' || $rules_id>0 || $rules_id==-1 || $subtable_id}color:gray{if $rules_count==0};text-decoration:none{/if}{else}color:black;text-decoration:none;{/if}"
                                        href="edit_group.php?group={if $to_back}{$to_back}{else}{$group_id}{/if}&cat={$cat_id}&cat_item={$cat_item}&menu=rules">{$lang.Rules}
                                        ({$rules_count})</a>{else}<b>{$lang.Rules} ({$rules_count})</b>{/if} </span>
                            </td>
                        </tr>
                    </table>
                </div>
                {if !$rules_id && $menu != 'rules'}
                    {include file="./acc_menu.tpl"}
                {/if}
            {/if}
            {if $reports && $cat_item}
                <div class="search_bar bubble speech"
                     style="line-height:25px;background-color:#ffffff;border-top:none;width:930px;padding-bottom:4px;">
                    <table>
                        <tr>
                            <td colspan="4" align="left" style="width: 232px;">
                                <div>
                                    <div style="float:left;padding-top: 2px;">{$lang.Visibility} {$lang.reports}:
                                        &nbsp;</div>
                                    <img id="eye_t_{$report_vis_acc.id}"
                                         style="float:left;text-decoration:none;background-color:transparent;{if !$report_acc_blocked}cursor:pointer;{/if}"
                                         src='images/acc_big_{if $report_vis_acc.acc==1}allow{elseif $report_vis_acc.acc==2}invisibe{else}close{/if}.png'
                                         {if !$report_acc_blocked}onclick='send_cat_acc2({$group_id}, {$report_vis_acc.id}, this, "r");change_eye2(this, {$group_id});'{/if}/>
                                    {if $report_acc_blocked}<img src="images/lock.svg" style="width:20px; padding-right:5px;">{/if}
                                </div>
                            </td>
                            <td colspan="4" align="left" width="550px"></td>
                        </tr>
                    </table>
                </div>
            {/if}
            <input type="hidden" name="menu" value="{$menu}"/>
            {if $template_type}<input type="hidden" name="type" value="{$template_type}"/>{/if}
            {if $subtable_id}<input type="hidden" name="subtable_id" value="{$subtable_id}"/>{/if}
        {/if}
    </form>
    <script>
        //$('#to_hidden').ready(function(){
        //  if ($.browser.webkit) $('#to_hidden').attr('hidden','hidden');
        //});
    </script>
