{include file="./index_top.tpl"}

<style>
  input[id=font_size_fields], input[id=font_size_groups], input[id=font_size_title] {
    margin-right: 5px;
  }

  .form-settings__image-drop {
    cursor: pointer;
  }
</style>

<script type="text/javascript">
  var qst_id = {$qst.id};
    cpkNewCol = "{$lang.cp_new_color}";
    cpkCurCol = "{$lang.cp_cur_color}";
    allQstTableFields = JSON.parse('{$all_table_fields}');
</script>

<script>
    $(function(){
        $('[name*="qst_items["][name*="[def]"').change(function() {
            var pos = this.getAttribute('pos');
            var req = this.getAttribute('req');
            var dsc = this.getAttribute('dsc');
            if (req == '1' && !this.value && !$('[name="qst_items[' + pos + '][checked]"]').prop('checked')) {
                jalert('{$lang.Field} "' + dsc + '" {$lang.qst_required_field_alert}');
            }
        });
    });

    function check_values() {
      {if $sel_tab=="settings"}
        if (!document.getElementById('qst_name').value.replace(/ /g, '')) {
          jalert("{$lang.Enter_qst_name}");
          return false;
        }

        if ($('input:checked[type=checkbox][name^="qst_items["]').length > 50) {
          jalert(lang['You_can_add_50_fields_only']);
          return false;
        }
      {/if}
      return true;
    }

    function init_ac(user_data_autocomplete, is_edit) {
        if (user_data_autocomplete.length > 0) {
            var index = 0;
            user_data_autocomplete.each(function(i, item){
                var field_id = $(item).attr('field_id');
                var parent_link = $(item).attr('parent_link');
                var autocomplete = $(item).next().find('.autocomplete__input');
                var autocomplete_btn = autocomplete.next();
                var autocomplete_url = 'select_value.php?table=' + table_id + '&field=' + field_id;
                autocomplete.val($(item).attr('ac_value'));
                var timeout;

                autocomplete.on('keyup', function(e) { // Навешиваем keyup на автокомплит, чтобы формировалась ссылка на данные с введенными символами
                    var word = '&q=';
                    if (autocomplete.val() !== '') {
                        word += encodeURIComponent(autocomplete.val());
                    }
                    var autocomplete_url_by_word = 'select_value.php?table=' + table_id + '&field=' + field_id + word;
                    if (e.keyCode === 17 || e.keyCode === 18 || e.keyCode === 16 || e.keyCode === 27 || e.keyCode === 40 || e.keyCode === 37 ||
                        e.keyCode === 38 || e.keyCode === 39 || e.keyCode === 9 || e.keyCode === 20 || e.keyCode === 13) {
                        return;
                    }
                    clearTimeout(timeout);
                    timeout = setTimeout(function() {
                        autocomplete_ajax_request($(item), autocomplete_url_by_word, false, true, index);
                    }, 100);
                });
                var onAutocompleteClick = function () {

                };
                onAutocompleteClick = function () {
                    autocomplete_ajax_request($(item), autocomplete_url, false, true, index);
                    autocomplete_btn.off('click', onAutocompleteClick);
                };
                autocomplete.on('click', onAutocompleteClick);
                autocomplete_btn.on('click', onAutocompleteClick);
                index++;
            });
        }
    }

    function fix_name(obj) {
        var checked = obj.checked;
        var pos = obj.getAttribute('pos');
        var req = obj.getAttribute('req');
        var dsc = obj.getAttribute('dsc');
        if (checked) {
            if ($(obj).parent().parent().children().children(".field_radio").attr('allow_update') == '1') {
                $(obj).parent().parent().children().children(".field_radio").show();
            }
            document.getElementById('text_' + pos).value = document.getElementById('origname_' + pos).innerHTML;
        } else {
            if (req == '1' && !$('[name="qst_items[' + pos + '][def]"]').val()) {
                jalert('{$lang.Field} "' + dsc + '" {$lang.qst_required_field_alert}');
                obj.checked = true;
                return;
            }
            if ($(obj).parent().parent().children().children(".field_radio").attr('allow_update') == '1') {
                $(obj).parent().parent().children().children(".field_radio").hide();
            }
            document.getElementById('text_' + pos).value = "";
        }
        $('#text_' + pos).attr('name', checked ? 'qst_items[' + pos + '][text]' : null);
        $('#id_' + pos).attr('name', checked ? 'qst_items[' + pos + '][id]' : null);
        $('#item_type_' + pos).attr('name', checked ? 'qst_items[' + pos + '][item_type]' : null);
    }

    function select_clipboard_text() {
        $(document.getElementById('clipboard_text')).select();
    }

    function disable_update() {
        if ($('[name=maintable]').val()) {
            $('[name=allow_update]').attr('checked', false);
            $('[name=allow_update]').attr('disabled', true);
        } else {
            $('[name=allow_update]').attr('disabled', false);
        }
    }

    $(function () {
        $('.colorSelectorStyle').each(function (i, item)
        {
            colorpickerSetings.change = function(color) {
                var hex = color.toHexString();
                if (hex) {
                    $(item).css('background-color', hex);
                    $('#input_' + $(item).attr('id')).val(hex);
                    if (item.id == 'ft_font_color') {
                        $('#example_text1').css('color', hex);
                        set_css_val("k_field_name", 'color', hex);
                    };
                    if (item.id == 'ft_bg_color') {
                        $('#example_text1').css('background-color', hex);
                        set_css_val("k_field_name", 'background-color', hex);
                    }

                    if (item.id == 'gt_font_color') {
                        $('#example_text2').css('color', hex);
                        set_css_val("k_qst_group", 'color', hex);
                    }
                    if (item.id == 'gt_bg_color') {
                        $('#example_text2').css('background-color', hex);
                        set_css_val("k_qst_group", 'background-color', hex);
                    }

                    if (item.id == 'ht_font_color') {
                        $('#example_text3').css('color', hex);
                        set_css_val("form-basic__title", 'color', hex);
                    }
                    if (item.id == 'ht_bg_color') {
                        $('#example_text3').css('background-color', hex);
                        set_css_val("form-basic__title", 'background-color', hex);
                    }
                }
            };
            $(this).spectrum(colorpickerSetings);
        });
    });
    function set_css_val(cl_name, prop_name, value) {
        if(prop_name == 'color') prop_name = ' ' + prop_name;
        var css_text = document.getElementById('css_text').value;
        var p1, p2, p3, p4, p5;
        p1 = css_text.indexOf("." + cl_name);
        if (p1 == -1) return;
        p2 = css_text.indexOf(prop_name, p1);
        p3 = css_text.indexOf("}", p1);
        if (p3 == -1) return;
        if ((p2 != -1) && (p2 < p3)) { // Меняем поле
            if (value == "") {
                p4 = css_text.indexOf(";", p2);
                if (p4 == -1) return;
                css_text = css_text.substr(0, p2 - 1) + css_text.substr(p3);
            }
            else {
                p3 = css_text.indexOf(":", p2);
                if (p3 == -1) return;
                p4 = css_text.indexOf(";", p2);
                if (p4 == -1) return;
                css_text = css_text.substr(0, p3 + 1) + " " + value + css_text.substr(p4);
            }
        }
        else { // Не существует поля
            if (value != "")
                css_text = css_text.substr(0, p3 - 1) + "\n " + prop_name + ": " + value + ";\n" + css_text.substr(p3);
        }
        document.getElementById('css_text').value = css_text;
    }
    function refresh_font(sel) {
        var val = sel.value;
        if (sel.id == "font_name_fields") {
            $('#example_text1').css('font-family', val);
            set_css_val("k_field_name", 'font-family', val);

            set_css_val("k_savebutton", 'font-family', val);
            set_css_val("k_file_url", 'font-family', val);
        }
        if (sel.id == "font_name_groups") {
            $('#example_text2').css('font-family', val);
            set_css_val("k_qst_group", 'font-family', val);
        }
        if (sel.id == "font_name_titles") {
            $('#example_text3').css('font-family', val);
            set_css_val("form-basic__title", 'font-family', val);
        }
    }

    function refresh_font_size(inpt) {
        var val = inpt.value;
        if (val) val = val + "px";
        if (inpt.id == "font_size_fields") {
            $('#example_text1').css('font-size', val);
            set_css_val("k_field_name", 'font-size', val);
        }
        if (inpt.id == "font_size_groups") {
            $('#example_text2').css('font-size', val);
            set_css_val("k_qst_group", 'font-size', val);
        }
        if (inpt.id == "font_size_title") {
            $('#example_text3').css('font-size', val);
            set_css_val("form-basic__title", 'font-size', val);
        }
    }

    function change_button_type(def) {
        if (document.getElementById('def_button_type').checked) {
            // Стандартная кнопка
            document.getElementById('show_links').style.display = 'none';
        }
        else {
            // Ссылки на изображения
            document.getElementById('show_links').style.display = 'block';
        }

    }

    function refresh_img_url(inpt) {
        var val = inpt.value;
        if (inpt.id == 'img_url1') {
            document.getElementById('obj_img_url1').src = val;
            set_css_val("k_save_href", 'background', "url('" + val + "') repeat-x top left");
        }
        if (inpt.id == 'img_url2') {
            document.getElementById('obj_img_url2').src = val;
            set_css_val("k_save_href:hover", 'background', "url('" + val + "') repeat-x top left");
        }
    }

    function fix_img_button_size(img) {
        if (img.id == 'obj_img_url1') {
            set_css_val("k_save_href", 'width', img.width + "px");
            set_css_val("k_save_href", 'height', img.height + "px");
        }
        if (img.id == 'obj_img_url2') {
            set_css_val("k_save_href:hover", 'width', img.width + "px");
            set_css_val("k_save_href:hover", 'height', img.height + "px");
        }
    }

    var under_mouse_object = 0;
    var last_focus = 0;

    $().ready(function () {

        function formatItem(row) {
            return row[2];
        }

        function formatResult(row) {
            if (row[0] == "") return "";
            return row[1];
        }

        function fix_result(event, data, formatted) {
            var hidden = $(this).next().next();
            hidden.val(data[0]);
            hidden.change();
        }

        $(".datepicker").datepicker({
            showOn: "button",
            dateFormat: lang.date_js_format,
            buttonImage: "images/calbtn.png",
            buttonImageOnly: true,
            buttonText: lang.Calendar,
            showAnim: (('\v' == 'v') ? "" : "show"),  // в ie не включаем анимацию, тормозит
        }).attr('placeholder', lang.date_placeholder);
        $(".datetimepicker").datetimepicker({
            showOn: "button",
            dateFormat: lang.date_js_format,
            timeFormat: "HH:mm",
            buttonImage: "images/calbtn.png",
            buttonImageOnly: true,
            buttonText: lang.Calendar,
            showAnim: (('\v' == 'v') ? "" : "show"),  // в ie не включаем анимацию, тормозит
        }).attr('placeholder', lang.datetime_placeholder);
        $(".datepicker, .datetimepicker").css("width", "105px");
    });

    function allCheckbox(obj) {
        if (obj.checked) $(".field_checkbox").attr("checked", true);
        else $(".field_checkbox").attr("checked", false);

        $(".field_checkbox").each(function (indx) {
            fix_name(this);
        });
    }

    function show_hide_radio(obj) {
        if (obj.id == "allow_update_check" || obj.id == "allow_edit_check") {
            $(".field_checkbox:checked").parent().parent().children().children(".field_radio").show();
            $(".field_radio_th").show();
            $(".field_radio").attr("allow_update", '1');
            $(".reset_hash").show();
        }
        else {
            $(".field_radio").hide();
            $(".field_radio").attr("allow_update", '0');
            $(".reset_hash").hide();
        }
    }

    function insert_field(area) {
        message = document.getElementById(area);
        ins_field = document.getElementById('ins_field_' + area);
        if (document.selection) {
            message.focus();
            document.selection.createRange().text = ins_field.value;
        }
        else {
            message.value = message.value.substr(0, message.selectionStart) + ins_field.value + message.value.substr(message.selectionEnd);
        }
    }
</script>

<div align=center>
    <br>
    {if $no_save_mode}<img src="images/lock.svg" style="width:20px; padding-right:5px;" title="{$lang.Element_no_edit_msg}">{/if}
    {if $qst_id == -1}{$lang.Add_qst}{else}{$lang.Edit_questionare}: {$qst.name}{/if}
    {if $qst_id != -1 && !$blocked}
        <div style="left: 10px; top: 2px; float: none;"
            onclick="switchOnObject('{$qst_id}')"
            class="switch-btn {if !$disabled}switch-on{/if}"
            id="switch-on-btn_{$qst_id}"></div>
        <script>
            let ajaxObj = new XMLHTTP("edit_questionare.php");
            ajaxObj.format = 0;
            ajaxObj.method = "POST";
            function switchOnObject(qst_id) {
                $('#switch-on-btn_'+qst_id).toggleClass('switch-on');
                $('#switch-on-btn_'+qst_id).trigger('on.switch');
                ajaxObj.call('qst_id='+qst_id+'&sel=disable&enbl='+($('#switch-on-btn_'+qst_id).hasClass('switch-on')?1:0)+'&csrf={$csrf}',()=>{});
            }
        </script>
    {/if}
    <br><br>
    {if $sel_tab=="display"}<span class="select_tab">{$lang.Qst_display}</span>{else}<a
        href="edit_questionare.php?qst_id={$qst_id}&sel_tab=display&table={$qst.table_id}" class="select_tab"
        {if $qst_id==-1}onclick="jalert('{$lang.Qst_save_at_first}');return false;"{/if}>{$lang.Qst_display}</a>{/if} /
    {if $sel_tab=="settings"}<span class="select_tab">{$lang.Settings}</span>{else}<a
        href="edit_questionare.php?qst_id={$qst_id}&sel_tab=settings&table={$qst.table_id}"
        class="select_tab">{$lang.Settings}</a>{/if} /
    {if $sel_tab=="style_editor"}<span class="select_tab">{$lang.Style_editor}</span>{else}<a
        href="edit_questionare.php?qst_id={$qst_id}&sel_tab=style_editor&table={$qst.table_id}" class="select_tab"
        {if $qst_id==-1}onclick="jalert('{$lang.Qst_save_at_first}');return false;"{/if}>{$lang.Style_editor}</a>{/if}{if $user.group_id==1} /
        {if $sel_tab=="calc"}<span class="select_tab">{$lang.Qst_calc}</span>{else}<a
            href="edit_questionare.php?qst_id={$qst_id}&sel_tab=calc&table={$qst.table_id}" class="select_tab"
            {if $qst_id==-1}onclick="jalert('{$lang.Qst_save_at_first}');return false;"{/if}>{$lang.Qst_calc}</a>{/if}{/if}
    <br>
    <br>

    {if $error}
        <div style="color:red; font-size:13px;">{$error}</div>
        <br>
    {/if}

    {if $blocked}
        <div style="text-align:center;font-size: 13px;">
            <a href="edit_questionare.php?table={$table_id}">{$lang.Return}</a>
        </div>
    {else}
    <form action="edit_questionare.php" name="user_data" id="edit_quastionary" method="post" enctype="multipart/form-data">
        <input type="hidden" name="sel" value="save">
        <input type="hidden" name="table" value="{$qst.table_id}">
        <input type="hidden" name="qst_id" value="{$qst_id}">
        <input type="hidden" name="sel_tab" value="{$sel_tab}">
        <input type=hidden name=csrf value='{$csrf}'>
        <Table border=0 cellpadding=3 cellspacing=0>
            {if $message}
                <tr>
                    <td colspan=3 align=center>
                        <span id="edit_config__info-maessage" style="color:green">{$message}</span><br><br>
                    </td>
                </tr>
            {/if}
            {if $sel_tab=="settings"}
                <tr>
                    <td width="150" align="right">{$lang.Qst_name}</td>
                    <td width="24" style="position: relative; right: -2px; left: 0; margin-left: 0; padding-left: 0;">
                        <span class='help_bt' h_id='Qst_name'></span>:
                    </td>
                    <td align="left">
                        <input class="form-control form-control-250" style="margin-left: 0px;" type=text name="name" id="qst_name" size="40"
                               value="{$qst.name}">
                    </td>
                </tr>
                <tr>
                    <td width="150" align="right">{$lang.Qst_title}</td>
                    <td width="24" style="position: relative; right: -2px; left: 0; margin-left: 0; padding-left: 0;">
                        <span class='help_bt' h_id='h1_name'></span>:
                    </td>
                    <td align="left">
                        <input class="form-control form-control-250" style="margin-left: 0px;" type=text name="h1_name" id="h1_name" size="40"
                               value="{$qst.h1_name}">
                    </td>
                </tr>
                <tr>
                    <td width="150" align="right">{$lang.Qst_description}</td>
                    <td width="24" style="position: relative; right: -2px; left: 0; margin-left: 0; padding-left: 0;">
                        <span class='help_bt' h_id='Qst_description'></span>:
                    </td>
                    <td align="left">
                        <textarea
                          class="form-control"
                          style="margin-left: 0px; min-width: 260px; width: 260px; height: 100px;"
                          type=text
                          name="description"
                          id="description"
                        >{$qst.description}</textarea>
                    </td>
                </tr>

                <!-- Блок с режимом цвета -->
                <tr>
                  <td colspan="3" style="padding: 0;">
                    <input id="qst_design_input" name="qst_design_input" class="hidden" type="text" style="width: 850px;">
                  </td>
                </tr>

                <tr>{* mode - Режим цвета *}
                  <td align=right>{$lang.Color_mode}</td>
                  <td
                    width="24"
                    style="position: relative; right: -2px; left: 0; margin-left: 0; padding-left: 0;"
                  >
                    <span class='help_bt' h_id='Qst_color_mode'></span>:
                  </td>

                  <td>
                    <table>
                      <tr>
                        <td>
                          <label class="radio-inline">
                            <input
                              type="radio"
                              onchange="changeColorMode();"
                              name="color_mode"
                              value="standart"
                              {if $color_schema.color_mode == 'standart'}checked{/if}
                            >{$lang.Standart}
                          </label>

                          <label class="radio-inline">
                            <input
                              type="radio"
                              onchange="changeColorMode();"
                              name="color_mode"
                              value="palette"
                              {if $color_schema.color_mode == 'palette'}checked{/if}
                            >{$lang.Paint}
                          </label>
                        </td>
                      </tr>
                    </table>
                  </td>
                </tr>

                {* standart_block - Цветовая схема *}
                <tr
                  class="informer-bg-color"
                  id="standart_block"
                  {if $color_schema.color_mode != 'standart'}style='display:none;'{/if}
                >
                  <td align="right">{$lang.Color_scheme}</td>

                  <td
                    width="24"
                    style="position: relative; right: -2px; left: 0; margin-left: 0; padding-left: 0;"
                  >
                    <span class="help_bt" h_id="Qst_color_set"></span>:
                  </td>

                  <td>
                    <table>
                      <tr>
                        <td>
                          <select
                            class="form-control form-control-160"
                            name="standart_color_scheme"
                            onchange="changeStandartСolor();"
                          >
                            {$color_options}
                          </select>
                        </td>

                        <td class="informer__color-example--row"></td>
                      </tr>
                    </table>
                  </td>
                </tr>

                {* palette_block - Выбор цвета с помощью колопикеров *}
                <tr
                  class='informer-colors'
                  id="palette_block"
                  {if $color_schema.color_mode != 'palette'}style='display:none;'{/if}
                >
                  <td align="right">{$lang.BackgroundColor}</td>
                  <td
                    width="24"
                    style="position: relative; right: -2px; left: 0; margin-left: 0; padding-left: 0;"
                  >
                    <span class='help_bt' h_id='Qst_bg_color'></span>:
                  </td>

                  <td>
                    <table>
                      <tr>
                        <td class="informer__txt-settings">
                          <input
                            type="text"
                            class="colorSelector"
                            name="palette_background_color"
                            value="{$color_schema.palette_background_color}"
                            data-css-style-attr="background-color"
                          />
                        </td>

                        <td align="right">
                          {$lang.DecorColor}
                          <span class="help_bt" h_id="Qst_txt_color"></span>:
                        </td>

                        <td class="informer__txt-settings">
                          <input
                            type="text"
                            class="colorSelector"
                            name="palette_design_color"
                            value="{$color_schema.palette_design_color}"
                            data-css-style-attr="color"
                          />
                        </td>

                        <td class="informer__color-example--row"></td>
                      </tr>
                    </table>
                  </td>
                </tr>

                <tr> {* Прозрачные блоки формы *}
                  <td align=right>{$lang.removeGroundBlock}</td>
                  <td
                    width="24"
                    style="position: relative; right: -2px; left: 0; margin-left: 0; padding-left: 0;"
                  >
                    <span class='help_bt' h_id='Qst_transp_mode'></span>:
                  </td>

                  <td>
                    <input
                      name="transparent_shape_blocks"
                      type="checkbox"
                      {if $color_schema.transparent_shape_blocks}checked{/if}
                    >
                  </td>
                </tr>
                <!-- Конец Блок с режимом цвета -->

                <tr>
                    <td align=right>{$lang.insert_image}</td>
                    <td width="24" style="position: relative; right: -2px; left: 0; margin-left: 0; padding-left: 0;">
                        <span class='help_bt' h_id='Qst_insert_image'></span>:
                    </td>
                    <td>

                        {if $sel_image}
                            <select class="form-control" id="ins_image" style="width:500px">{$sel_image}</select>
                            <input type=button class="btn btn-default btn-sm" value="OK" onclick="insert_var('ins_image')">
                            <a href="" class="red_link"
                               onclick="return jconfirm('{$lang.Delete_file} '+document.getElementById(document.getElementById('ins_image').value).innerHTML+'?', function () { document.getElementById('del_image').value=document.getElementById(document.getElementById('ins_image').value).innerHTML; document.getElementById('edit_form').submit(); });">{$lang.delete}</a>
                            <br>
                        {/if}

                        {if $qst.header_image}
                          <img id="form_settings_image" src="images/questionare/{$qst.header_image}" data-name="{$qst.header_image}" style="max-height: 90px; margin-bottom: 10px;">
                          <span class="form-settings__image-drop" onclick="dropHeaderImg()" title="Удалить">
                            <img alt="удалить" title="Удалить категорию" src="images/b_drop.png" border="0">
                          </span>
                        {/if}

                        <input type="file" name="header_image" id="header_image" accept="image/png, image/jpeg">

                        {* <input type="submit" name='add_image' value="{$lang.Upload}"
                               onClick="if (!document.getElementById('att_image').value) { jalert('{$lang.select_file}');return false; } "> *}
                        {* <input type='hidden' name='del_image' id='del_image'> *}
                    </td>
                </tr>

                <script>
                  function dropHeaderImg(dropBtn) {

                    let formData = new FormData();
                    formData.append('csrf', csrf);
                    formData.append('remove', 'header_image');
                    formData.append('qst_id', qst_id);
                    formData.append('header_image', $('#form_settings_image').attr('data-name'));

                    fetch('edit_questionare.php', {
                      method: 'POST',
                      credentials: 'include',
                      redirect: 'follow',
                      body: formData
                    })
                    .then(response => response.status)
                    .then(result => {
                      if (result == 200) {
                        window.location.reload();
                      } else {
                        jalert('Не удалось удалить изображение');
                      }
                    })
                  };
                </script>

                <tr>
                    <td colspan="3">
                        <table>
                            <tr>
                                <td width="150" align="right">{$lang.Qst_allow_update}</td>
                                <td width="24" style="position: relative; right: -2px; padding-left: 0;">
                                    <span class='help_bt' h_id='Qst_ability'></span>:
                                </td>
                                <td>
                                    <p style="padding: 0 0 0 5px; margin:5px 0px;"><input type="radio"
                                                                                            id="deny_update_check"
                                                                                            {if !$qst.allow_update}checked{/if}
                                                                                            onchange="show_hide_radio(this)"
                                                                                            name="allow_update"
                                                                                            value="0">&nbsp; {$lang.Qst_just_add}
                                    </p>
                                    <p style="padding: 0 0 0 5px; margin:5px 0px;"><input type="radio"
                                                                                            id="allow_edit_check"
                                                                                            {if $qst.allow_update eq 2}checked{/if}
                                                                                            onchange="show_hide_radio(this)"
                                                                                            name="allow_update"
                                                                                            value="2">&nbsp; {$lang.Qst_can_edit}
                                    </p>
                                    <p style="padding: 0 0 0 5px; margin:5px 0px;"><input type="radio"
                                                                                            id="allow_update_check"
                                                                                            {if $qst.allow_update eq 1}checked{/if}
                                                                                            onchange="show_hide_radio(this)"
                                                                                            name="allow_update"
                                                                                            value="1">&nbsp; {$lang.Qst_can_update}
                                    </p></td>
                            </tr>
                            {*<input type=checkbox id="allow_update_check" name=allow_update {if $qst.allow_update}checked{/if} value=1 onclick="show_hide_radio(this)"></td><td></td></tr>*}
                            <tr>
                                <td colspan="2"></td>
                                <td align="left"><p style="padding: 0px 0px 0px; margin:5px 0px 5px 1px;"><span
                                                {if !$qst.allow_update}style="display: none"{/if}
                                                class="reset_hash"><input type="checkbox" id="reset_hash"
                                                                          name="reset_hash"
                                                                          {if $qst.reset_hash}checked{/if}
                                                                          value=1></span>&nbsp;
                                        <span style="{if !$qst.allow_update}display: none;{/if}"
                                              class="reset_hash">{$lang.Qst_reset_hash}</span></p></td>
                            </tr>
                        </table>
                    </td>
                </tr>

                <tr>
                  <td colspan="3">
                    <input type="hidden" name="qst_table" value="{$table_select}"/>
                  </td>
                </tr>

                <tr>
                  <td colspan=3>
                    <table>
                      <tr>
                        <th></th>
                        <th width=100px style="text-align:left; padding-left: 2px;">
                          {$lang.Display_in_form}&nbsp;<span class='help_bt' h_id='Display_in_form'></span>
                        </th>
                        <th align=left>{$lang.Field}<span class='help_bt' h_id='Field'></span><br>&nbsp;</th>
                        <th align=left>{$lang.Name_in_form}<span class='help_bt' h_id='Name_in_form'></span><br>&nbsp;</th>
                        <th align=left>{$lang.Default_value}<span class='help_bt' h_id='Default_value'></span><br>&nbsp;</th>
                        <th width=200px style="text-align: center">
                          <span class="field_radio field_radio_th" {if !$qst.allow_update}style="display: none"{/if}>
                            {$lang.Show_edit_db_values}&nbsp;<span class='help_bt' h_id='Show_edit_db_values'></span>
                          </span>
                        </th>
                      </tr>

                      <tr><td style="height:20px" colspan="6"></td></tr>

                      <tr>
                        <td rowspan="{count($items)+1}" width="178" align="right">
                          {$lang.Fields} <span class='help_bt' h_id='Name_in_form'></span>&nbsp;:
                        </td>
                        <td style="font-weight: bold; text-align: center; padding: 10px 0px">
                          <input type=checkbox name="all_checkbox" onclick="allCheckbox(this)" {if $qst_id==-1}checked{/if} />
                        </td>
                        <td colspan="3">&nbsp;</td>
                        <td></td>
                      </tr>

                      {foreach from=$items item=one_item key=item_pos}
                        <tr>
                          <td align=center>
                            <input
                              class="field_checkbox"
                              type=checkbox
                              name="qst_items[{$item_pos}][checked]"
                              {if $one_item.text OR $qst_id==-1}checked{/if}
                              onclick="fix_name(this)"
                              pos="{$item_pos}"
                              req="{$one_item.required}"
                              dsc="{$one_item.name}"
                            />
                          </td>

                          <td width=200px {if $one_item.item_type=="group"}style="font-weight: bold;"{/if}>
                            <span id="origname_{$item_pos}">{$one_item.name}</span>
                            {if $one_item.required}<span style="color:red">*</span>{/if}
                          </td>

                          <td>
                            <input
                              class="form-control form-control-250"
                              type=text
                              size=22
                              id='text_{$item_pos}'
                              {if $one_item.text OR $qst_id==-1}name="qst_items[{$item_pos}][text]"{/if}
                              value="{if $qst_id==-1}{$one_item.name}{else}{$one_item.text}{/if}"
                            />
                            <input type=hidden {if $one_item.text OR $qst_id==-1}name="qst_items[{$item_pos}][id]"{/if} id="id_{$item_pos}" value="{$one_item.id}"/>
                            <input type=hidden {if $one_item.text OR $qst_id==-1}name="qst_items[{$item_pos}][item_type]"{/if} id="item_type_{$item_pos}" value="{$one_item.item_type}"/>
                          </td>

                          {* ------------------------------- DEFALUT VALUE ------------------------- *}
                          <td>
                            {if $one_item.item_type=='field'}
                              {assign var="field" value=$one_item}

                              {if $field.type_field eq 1}
                                <input
                                  class="form-control form-control-250"
                                  type=text
                                  name="qst_items[{$item_pos}][def]"
                                  pos="{$item_pos}"
                                  req="{$one_item.required}"
                                  dsc="{$one_item.name}"
                                  value="{$field.def}"
                                  size="15"
                                />

                              {elseif $field.type_field eq 2 or $field.type_field eq 12}
                                <input
                                  type=radio
                                  name="qst_items[{$item_pos}][def]"
                                  pos="{$item_pos}"
                                  req="{$one_item.required}"
                                  dsc="{$one_item.name}"
                                  id="default_value1_{$field.id}"
                                  value="{if $field.def ne '[cur.date]' and $field.def ne '[cur.time]'}{$field.def}{/if}"
                                  {if $field.def ne '[cur.date]' and $field.def ne '[cur.time]'}checked{/if}
                                />

                                <input
                                  type=text
                                  value="{if $field.def ne '[cur.date]' and $field.def ne '[cur.time]'}{$field.def}{/if}"
                                  size="15"
                                  onclick="document.getElementById('default_value1_{$field.id}').checked = true"
                                  onchange="document.getElementById('default_value1_{$field.id}').checked = true; document.getElementById('default_value1_{$field.id}').value = this.value"
                                  class="form-control form-control-250 {if $field.type_value}datetimepicker{else}datepicker{/if}"
                                />
                                <br>

                                <input
                                  type=radio
                                  name="qst_items[{$item_pos}][def]"
                                  pos="{$item_pos}"
                                  req="{$one_item.required}"
                                  dsc="{$one_item.name}"
                                  id="default_value2_{$field.id}"
                                  value="{ldelim}cur.date{rdelim}"
                                  {if $field.def eq "[cur.date]"}checked{/if}
                                />

                                <label for="default_value2_{$field.id}">{$lang.add_record_date}</label><br>

                                {if $field.type_value}
                                  <input
                                    type=radio
                                    name="qst_items[{$item_pos}][def]"
                                    pos="{$item_pos}"
                                    req="{$one_item.required}"
                                    dsc="{$one_item.name}"
                                    id="default_value3_{$field.id}"
                                    value="{ldelim}cur.time{rdelim}"
                                    {if $field.def eq "[cur.time]"}checked{/if}
                                  />
                                  <label for="default_value3_{$field.id}">{$lang.add_record_time}</label>
                                {/if}

                              {elseif $field.type_field eq 3}
                                {if !$field.type_value}
                                  <input
                                    class="form-control form-control-250"
                                    type=text
                                    name="qst_items[{$item_pos}][def]"
                                    pos="{$item_pos}"
                                    req="{$one_item.required}"
                                    dsc="{$one_item.name}"
                                    value="{$field.def}"
                                    size="22"
                                  />
                                {else}
                                  <textarea
                                    class="form-control form-control-250"
                                    name="qst_items[{$item_pos}][def]"
                                    pos="{$item_pos}"
                                    req="{$one_item.required}"
                                    dsc="{$one_item.name}"
                                    rows=1
                                    cols=26
                                  >{$field.def}</textarea>
                                {/if}

                              {elseif $field.type_field eq 4 or $field.type_field eq 13}
                                {if !$field.mult_value}
                                  <select
                                    class="form-control form-control-250"
                                    name="qst_items[{$item_pos}][def]"
                                    pos="{$item_pos}"
                                    req="{$one_item.required}"
                                    dsc="{$one_item.name}"
                                  >{$field.def_select}</select>
                                {else}
                                  {foreach from=$field.def_select item=one_value}
                                    <input
                                      type=checkbox
                                      name="qst_items[{$item_pos}][def][]"
                                      value="{$one_value.list_value}"
                                      {if $one_value.checked}checked{/if}
                                    />{$one_value.display_value}
                                    <br>
                                  {/foreach}
                                {/if}

                                {elseif $field.type_field eq 5 && $field.mult_value == '1'}
                                  {$field.def}
                                  <select
                                    multiple
                                    class="questionare select2-plugin dont_use_chosen"
                                    id="value{$field.id}"
                                    data-field-id="{$field.id}"
                                    data-table-id="{$field['table_id']}"
                                    data-line-id=""
                                    data-mode="questionare"
                                    data-previously-value="{$field.display_edit|htmlspecialchars}"
                                    req="{$one_item.required}"
                                    style="width: 100%;"
                                    name="qst_items[{$item_pos}][def][]"
                                  >
                                    {if !empty($field.display_edit_def)}
                                      {foreach from=$field.display_edit_def item=option}
                                        {if $option.id > 0}
                                          <option selected value="{$option.id}">{$option.text}</option>
                                        {/if}
                                      {/foreach}
                                    {/if}
                                  </select>
                                {elseif $field.type_field eq 5}
                                  <select
                                    class="combobox combobox--view-line"
                                    ac_id="edit_value{$field.id}"
                                    ac_value="{$field.display_edit|htmlspecialchars}"
                                    name="qst_items[{$item_pos}][def]"
                                    pos="{$item_pos}"
                                    req="{$one_item.required}"
                                    dsc="{$one_item.name}"
                                    ac_hidden_val="{$field.value.raw}"
                                    field_id="{$field.id}"
                                    parent_link="{$field.parent_link_field}"
                                    value="{$field.value.raw}"
                                    id="value{$field.id}"
                                  >
                                    <option value="{$field.def}"></option>
                                  </select>

                              {elseif $field.type_field eq 7 or $field.type_field eq 11 or $field.type_field eq 14}
                                {if !$field.mult_value}
                                  <select
                                    name="qst_items[{$item_pos}][def]"
                                    pos="{$item_pos}"
                                    req="{$one_item.required}"
                                    dsc="{$one_item.name}"
                                  >
                                    <option value=""></option>
                                    {foreach from=$field.options item=one_user}
                                      <option value="{$one_user.id}" {if $one_user.chosen}selected{/if}>{$one_user.name}</option>
                                    {/foreach}
                                  </select>
                                {else}
                                  {foreach from=$field.options item=one_user}
                                    <input
                                      type="checkbox"
                                      name="qst_items[{$item_pos}][def][]"
                                      pos="{$item_pos}"
                                      req="{$one_item.required}"
                                      dsc="{$one_item.name}"
                                      value="{$one_user.id}"
                                      {if $one_user.chosen}checked{/if}
                                    >{$one_user.name}
                                    <br>
                                  {/foreach}
                                {/if}

                              {elseif $field.type_field eq 8 or $field.type_field eq 10}
                                <input
                                  type=radio
                                  name="qst_items[{$item_pos}][def]"
                                  pos="{$item_pos}"
                                  req="{$one_item.required}"
                                  dsc="{$one_item.name}"
                                  id="default_value1_{$field.id}"
                                  value="{if $field.def ne '[autonumber]'}{$field.def}{/if}"
                                  {if $field.def ne "[autonumber]"}checked{/if}
                                />

                                <input
                                  type=text
                                  value="{if $field.def ne "[autonumber]"}{$field.def}{/if}"
                                  size="15"
                                  onclick="document.getElementById('default_value1_{$field.id}').checked = true"
                                  onchange="document.getElementById('default_value1_{$field.id}').value = this.value"
                                />
                                <br>
                                <input
                                  type=radio
                                  name="qst_items[{$item_pos}][def]"
                                  pos="{$item_pos}"
                                  req="{$one_item.required}"
                                  dsc="{$one_item.name}"
                                  id="default_value2_{$field.id}"
                                  value="{ldelim}autonumber{rdelim}"
                                  {if $field.def eq "[autonumber]"}checked{/if}
                                />
                                <label for="default_value2_{$field.id}">{$lang.auto_numbering}</label>
                              {/if}
                            {/if}
                          </td>
                          {* ================================ DEFALUT VALUE ========================= *}

                          <td align=center>
                            <input
                              class="field_radio"
                              allow_update="{$qst.allow_update}"
                              type=radio
                              {if ($one_item.text OR $qst_id==-1) AND $qst.allow_update}{else}style="display: none;"{/if}
                              name="qst_items[{$item_pos}][readonly]" {if $one_item.readonly eq 1}checked{/if}
                              value="1"
                            />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                            <input
                              class="field_radio"
                              allow_update="{$qst.allow_update}"
                              type=radio
                              {if ($one_item.text OR $qst_id==-1) AND $qst.allow_update}{else}style="display: none;"{/if}
                              name="qst_items[{$item_pos}][readonly]" {if $one_item.readonly neq 1 OR $qst_id==-1 }checked{/if}
                              value="0"
                            />
                          </td>
                        </tr>
                      {/foreach}

                        {if $required_exists}
                        <tr>
                            <td colspan="2"></td>
                            <td colspan="4" style="padding-top: 15px;"><span style="color:red">*</span> - обязательное для заполнения</td>
                        </tr>
                        {/if}
                        <tr>
                            <td colspan="6"><p style="padding-top: 20px;"></p></td>
                        </tr>
                        {if $table.user_table_link}
                            <tr>
                                <td align="right">{$lang.qst_reg_group} <span class='help_bt' h_id='qst_reg_group'></span>:</td>
                                <td style="padding-left: 2px;" colspan=3><select name="reg_group">{$sel_reg_group}</select></td>
                            </tr>
                        {/if}
                        <tr>
                            <td align="right">{$lang.qst_res_text} <span class='help_bt' h_id='qst_res_text'></span>:</td>
                            <td style="padding-left: 4px;" colspan=3>
                                <textarea class="form-control" id=message name=res_text style="width: 320px;height: 125px;">{$qst.res_text}</textarea>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">{$lang.Insert_field_template} <span class='help_bt'  h_id='Insert_field_template'></span>:</td>
                            <td style="padding-left: 4px;" colspan=3>
                                <select class="form-control form-control-250" id="ins_field_message">{$sel_ins_field}</select>
                                <input class="btn btn-default btn-sm" type=button value=OK onclick="insert_field('message');">
                            </td>
                        </tr>
                        <tr>
                            <td align="right">{$lang.Qst_button_text} <span class='help_bt' h_id='Qst_button_text'></span>:</td>
                            <td style="padding-left: 4px;" colspan=3>
                                <input class="form-control form-control-250" type=text name=button_text value='{$qst.button_text}' size=30>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">{$lang.Qst_charset} <span class='help_bt' h_id='Qst_charset'></span>:</td>
                            <td style="padding-left: 4px;" colspan=3>
                                <select class="form-control form-control-250" name="charset">{$charset_select}</select>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">{$lang.Alternative_site} <span class='help_bt' h_id='Alternative_site'></span>:</td>
                            <td style="padding-left: 4px;" colspan=3>
                                <input class="form-control form-control-250" type=text name=alternative_site value='{$qst.alternative_site}' size=30>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">{$lang.Security} <span class='help_bt' h_id='Qst_security'></span>:</td>
                            <td style="padding-left: 4px;" colspan=3>
                                <select class="form-control form-control-250" name="secure">
                                    <option value="0"{if !$qst.secure} selected{/if}>http</option>
                                    <option value="1"{if $qst.secure} selected{/if}>https</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">{$lang.Qst_lang} <span class='help_bt' h_id='Qst_lang'></span>:</td>
                            <td style="padding-left: 4px;" colspan=3>
                                <select class="form-control form-control-250" name="lang">
                                    {foreach from=$langs_list item=lang_name key=sname}
                                        <option value="{$sname}" {if $sname==$qst.lang}selected{/if}>{$lang_name}</option>
                                    {/foreach}
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td align="right" nowrap>{$lang.Qst_add_limit} <span class='help_bt' h_id='Qst_add_limit'></span>:</td>
                            <td style="padding-left: 4px;" colspan=3>
                                <select class="form-control form-control-250" name="add_limit" onchange="$('#limit_count').toggle(this.value != 0)">
                                    <option value=0 {if $qst.add_limit == 0}selected{/if}>{$lang.no}</option>
                                    <option value=1 {if $qst.add_limit == 1}selected{/if}>{$lang.from_IP}</option>
                                    <option value=2 {if $qst.add_limit == 2}selected{/if}>{$lang.from_net}</option>
                                </select>
                                <span id="limit_count" style="margin-left: 3px;{if !$qst.add_limit} display:none;{/if}">
                                    {$lang.no_more_than}
                                    <input class="form-control form-control-20" type=text name="limit_count" value="{$qst.limit_count}" placeholder=1>
                                    {$lang.records_per_day}
                                </span>
                            </td>
                        </tr>
                        <tr>
                        </tr>
                        <tr>
                          <td align="right">{$lang.captcha} <span class='help_bt' h_id='captcha'></span>:</td>
                          <td style="padding-left: 4px;" colspan=3>
                              <select name="captcha">
                                  <option value="NULL">Нет</option>
                                  {foreach from=$all_captcha item=$captcha}
                                  <option value="{$captcha}" {if $qst.captcha == $captcha} selected {/if}>{$lang.$captcha}</option>
                                  {/foreach}
                              </select>
                          </td>
                        </tr>
                        <tr>
                            <td align="right">{$lang.UTM_tag} <span class='help_bt' h_id='UTM_tag'></span>:</td>
                            <td style="padding-left: 4px;" colspan=3>
                                <input type=checkbox name="UTM_tag"
                                        onclick="use_tag(this.checked)"
                                        {if $qst.UTM_tag}checked {/if}>
                            </td>
                        </tr>
                        <tbody id="UTM_tag" {if !$qst.UTM_tag}style="display:none"{/if}>
                        <tr>
                            <td align=right>{$lang.chose_field_utm}<span class="help_bt"
                                                                          h_id="chose_field_utm"></span>:
                            </td>
                            <td align=center width="300px"><input type="radio" {if !$qst.UTM_tag}checked{/if} class="field_radio"
                                                              onchange="tag_fields(this.value)"
                                                              name="choose_field_utm" value="auto"> {$lang.auto}
                                <input style="margin-left:40px" type="radio" class="field_radio" {if $qst.UTM_tag}checked{/if} onchange="tag_fields(this.value)"
                                                  name="choose_field_utm" value="manual"> {$lang.manual}</td>
                        </tr>
                        </tbody>
                        <tbody id="UTM_fields" {if !$qst.UTM_tag}style="display:none"{/if}>
                        <tr>
                            <td align="right" width="250px">{$lang.select_utm_source}<span class="help_bt"
                                                                                            h_id="select_utm_source"></span>:
                            </td>
                            <td>
                                <select class="form-control form-control-250"
                                        name="utm_source">
                                    <option></option>
                                    {foreach from=$option_utm item=$row}
                                        <option value="{$row.id}" {if $row.id == $qst.tags.utm_source} selected {/if}>{$row.name_field}</option>
                                    {/foreach}
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td align="right" width="250px">{$lang.select_utm_medium}<span class="help_bt"
                                                                                            h_id="select_utm_medium"></span>:
                            </td>
                            <td>
                                <select class="form-control form-control-250"
                                        name="utm_medium">
                                    <option></option>
                                    {foreach from=$option_utm item=$row}
                                        <option value="{$row.id}" {if $row.id == $qst.tags.utm_medium} selected {/if}>{$row.name_field}</option>
                                    {/foreach}
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td align="right" width="250px">{$lang.select_utm_campaign}<span class="help_bt"
                                                                                              h_id="select_utm_campaign"></span>:
                            </td>
                            <td>
                                <select class="form-control form-control-250"
                                        name="utm_campaign">
                                    <option></option>
                                    {foreach from=$option_utm item=$row}
                                        <option value="{$row.id}" {if $row.id == $qst.tags.utm_campaign} selected {/if}>{$row.name_field}</option>
                                    {/foreach}
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td align="right" width="250px">{$lang.select_utm_content}<span class="help_bt"
                                                                                            h_id="select_utm_content"></span>:
                            </td>
                            <td>
                                <select class="form-control form-control-250"
                                        name="utm_content">
                                    <option></option>
                                    {foreach from=$option_utm item=$row}
                                        <option value="{$row.id}" {if $row.id == $qst.tags.utm_content} selected {/if}>{$row.name_field}</option>
                                    {/foreach}
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td align="right" width="250px">{$lang.select_utm_term}<span class="help_bt"
                                                                                          h_id="select_utm_term"></span>:
                            </td>
                            <td>
                                <select class="form-control form-control-250" name="utm_term">
                                    <option></option>
                                    {foreach from=$option_utm item=$row}
                                        <option value="{$row.id}" {if $row.id == $qst.tags.utm_term} selected {/if}>{$row.name_field}</option>
                                    {/foreach}
                                </select>
                            </td>
                        </tr>
                        </tbody>
                        <tr>
                            <td align="right" nowrap>{$lang.User_agreement} <span class='help_bt' h_id='User_agreement'></span>:</td>
                            <td style="padding-left: 4px;" colspan=4>
                                <input type=checkbox name="user_agreement"
                                        {if $qst.user_agreement}checked{/if}
                                        onclick="$('#user_agreement_more').toggle(this.checked)"> {$lang.Qst_agr_checkbox1}
                            </td>
                        </tr>
                        <tbody id="user_agreement_more" {if !$qst.user_agreement}style="display:none"{/if}>
                        <tr>
                            <td></td>
                            <td style="padding-left: 4px;" colspan=4>
                                <input type=checkbox name="user_agreement_auto"
                                        {if $qst.user_agreement_auto}checked{/if}> {$lang.Qst_agr_checkbox2}
                            </td>
                        </tr>
                        <tr>
                            <td align="right">{$lang.Agreement_header} <span class='help_bt' h_id='User_agreement_header'></span>:</td>
                            <td style="padding-left: 4px;" colspan=4>
                                <textarea class="form-control qst__agreement-header" name="user_agreement_header">{$qst.user_agreement_header}</textarea>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">{$lang.Agreement_text} <span class='help_bt' h_id='User_agreement_text'></span>:</td>
                            <td style="padding-left: 4px;" colspan=4>
                                <textarea class="form-control qst__agreement-text" name="user_agreement_text"
                                          style="width:700px; height:200px;">{$qst.user_agreement_text}</textarea>
                            </td>
                        </tr>
                        </tbody>
                        <tr>
                            <td></td>
                            <td>
                                {if $config.protect_of_elements && $user.id == 1}<a href="" id="protect_switch" style="width: 60px;display: inline-block">{$lang.Protect}</a>{/if}
                                <a href="edit_log.php?st_date=00&f_text=edit_questionare.php?table%3D{$qst.table_id}%26qst_id%3D{$qst_id}>" target="_blank">{$lang.Log}</a>
                            </td>
                        </tr>
                        {if $config.protect_of_elements && $user.id == 1}
                        <tbody id="protect_block" style="display:none">
                            <tr>
                                <td align="right">{$lang.Protected}<span class='help_bt' h_id='Protect_of_element'></span>:</td>
                                <td>
                                    <input type="checkbox" name="protected" {if $protected}checked{/if} onclick="$('[id^=pr_]').prop('disabled', !this.checked)">
                                    <span class="access_param_wrapper">{$lang.View2}<span class='help_bt' h_id='protect_of_view'></span></span>
                                    <span class="access_param_wrapper">{$lang.Edit3}<span class='help_bt' h_id='protect_of_edit'></span></span>
                                </td>
                            </tr>
                            <tr>
                                <td align="right"></td>
                                <td>
                                    <div style="float: left; margin:0 34px; width: 60px; padding: 8px 0 6px 15px; text-align: center;">
                                        <input type="checkbox" id="pr_view_all" {if !$protected}disabled{/if}
                                               onclick="$('[id^=pr_view]').prop('checked', this.checked); if (!this.checked) $('[id^=pr_edit]').prop('checked', 0);">
                                    </div>
                                    <div style="float: left; margin:0 34px; width: 60px; padding: 8px 0 6px 0; text-align: center;">
                                        <input type="checkbox" id="pr_edit_all" {if !$protected}disabled{/if}
                                               onclick="$('[id^=pr_edit]').prop('checked', this.checked); if ( this.checked) $('[id^=pr_view]').prop('checked', 1);">
                                    </div>
                                </td>
                            </tr>
                            {foreach from=$protect key=gid item=acc}
                                <tr>
                                    <td align="right" style="padding-top: 11px;">{$acc.name}:</td>
                                    <td style="display: flex; flex-wrap: nowrap;">
                                        <div style="float: left; margin:0 34px; width: 60px; padding: 8px 0 6px 15px; text-align: center;">
                                            <input type="checkbox" name="protect_rights[{$gid}][view]" id="pr_view{$gid}" value="1"
                                                   {if $acc.view}checked{/if} {if !$protected}disabled{/if}
                                                   onclick="if (!this.checked) $('#pr_edit{$gid}').prop('checked', 0)">
                                        </div>
                                        <div style="float: left; margin:0 34px; width: 60px; padding: 8px 0 6px 0; text-align: center;">
                                            <input type="checkbox" name="protect_rights[{$gid}][edit]" id="pr_edit{$gid}" value="1"
                                                   {if $acc.edit}checked{/if} {if !$protected}disabled{/if}
                                                   onclick="if ( this.checked) $('#pr_view{$gid}').prop('checked', 1)">
                                        </div>
                                    </td>
                                </tr>
                            {/foreach}
                            <tr><td></td></tr>
                            <tr>
                                <td align=right>{$lang.Comment}<span class='help_bt' h_id='protect_comment'></span>:</td>
                                <td><textarea class="form-control form-control-250" name="protect_comment" rows=5>{$protect_comment}</textarea></td>
                            </tr>
                        </tbody>
                        {/if}
                    </table>
                  </td>
                </tr>
                
            {elseif $sel_tab=="style_editor"}
                <TR>
                    <TD>
                        <!--h4>{$lang.Colors}</h4-->
                        <br>{$lang.Qst_fields_displ} <span class='help_bt' h_id='Qst_fields_displ'></span><br>
                        <table>
                            <tr>
                                <td>{$lang.Qst_font_name}:</td>
                                <td width=50px><select class="form-control form-control-160" id=font_name_fields onchange='refresh_font(this);'>
                                        <option {if $qst.ft_name=='Arial,Arial,Helvetica,sans-serif'}selected{/if}
                                                value='Arial,Arial,Helvetica,sans-serif'>Arial
                                        </option>
                                        <option {if $qst.ft_name=='Arial Black,Arial Black,Gadget,sans-serif'}selected{/if}
                                                value='Arial Black,Arial Black,Gadget,sans-serif'>Arial Black
                                        </option>
                                        <option {if $qst.ft_name=='Comic Sans MS,Comic Sans MS,cursive'}selected{/if}
                                                value='Comic Sans MS,Comic Sans MS,cursive'>Comic Sans MS
                                        </option>
                                        <option {if $qst.ft_name=='Courier New,Courier New,Courier,monospace'}selected{/if}
                                                value='Courier New,Courier New,Courier,monospace'>Courier New
                                        </option>
                                        <option {if $qst.ft_name=='Georgia,Georgia,serif'}selected{/if}
                                                value='Georgia,Georgia,serif'>Georgia
                                        </option>
                                        <option {if $qst.ft_name=='Impact,Charcoal,sans-serif'}selected{/if}
                                                value='Impact,Charcoal,sans-serif'>Impact
                                        </option>
                                        <option {if $qst.ft_name=='Lucida Console,Monaco,monospace'}selected{/if}
                                                value='Lucida Console,Monaco,monospace'>Lucida Console
                                        </option>
                                        <option {if $qst.ft_name=='Lucida Sans Unicode,Lucida Grande,sans-serif'}selected{/if}
                                                value='Lucida Sans Unicode,Lucida Grande,sans-serif'>Lucida Sans Unicode
                                        </option>
                                        <option {if $qst.ft_name=='Palatino Linotype,Book Antiqua,Palatino,serif'}selected{/if}
                                                value='Palatino Linotype,Book Antiqua,Palatino,serif'>Palatino
                                        </option>
                                        <option {if $qst.ft_name=='Tahoma,Geneva,sans-serif'}selected{/if}
                                                value='Tahoma,Geneva,sans-serif'>Tahoma
                                        </option>
                                        <option {if $qst.ft_name=='Times New Roman,Times,serif'}selected{/if}
                                                value='Times New Roman,Times,serif'>Times New Roman
                                        </option>
                                        <option {if $qst.ft_name=='Trebuchet MS,Helvetica,sans-serif'}selected{/if}
                                                value='Trebuchet MS,Helvetica,sans-serif'>Trebuchet MS
                                        </option>
                                        <option {if $qst.ft_name=='Verdana,Geneva,sans-serif'}selected{/if}
                                                value='Verdana,Geneva,sans-serif'>Verdana
                                        </option>
                                    </select></td>
                                <td>{$lang.Qst_font_size}:</td>
                                <td width=70px>
                                    <input class="form-control form-control-25" type=text value="{$qst.ft_size_int}"
                                           id=font_size_fields onchange='refresh_font_size(this)'
                                           onkeyup='refresh_font_size(this)'>px
                                </td>
                                <td>{$lang.Font_color}:</td>
                                <td>
                                    <input type="text" id="ft_font_color" class="colorSelector colorSelectorStyle" value="{if $qst.ft_color}{$qst.ft_color}{else}#000000{/if}">
                                </td>
                                <td>{$lang.Background_color}:</td>
                                <td >
                                    <input type="text" id="ft_bg_color" class="colorSelector colorSelectorStyle" value="{if $qst.ft_bg_color}{$qst.ft_bg_color}{else}#000000{/if}">
                                </td>
                                <td>{$lang.Sample}:</td>
                                <td>
                                    <div id="example_text1"
                                         style="padding:5px; border:1px solid #bbb; color:{$qst.ft_color}; background-color:{$qst.ft_bg_color}; font-family: {$qst.ft_name}; font-size: {$qst.ft_size};">
                                        {$lang.Sample}
                                    </div>
                                </td>
                            </tr>
                        </table>
                        <br>
                        {$lang.Qst_groups_displ} <span class='help_bt' h_id='Qst_groups_displ'></span><br>
                        <table>
                            <tr>
                                <td>{$lang.Qst_font_name}:</td>
                                <td width=50px><select class="form-control form-control-160" id=font_name_groups onchange='refresh_font(this);'>
                                        <option {if $qst.gt_name=='Arial,Arial,Helvetica,sans-serif'}selected{/if}
                                                value='Arial,Arial,Helvetica,sans-serif'>Arial
                                        </option>
                                        <option {if $qst.gt_name=='Arial Black,Arial Black,Gadget,sans-serif'}selected{/if}
                                                value='Arial Black,Arial Black,Gadget,sans-serif'>Arial Black
                                        </option>
                                        <option {if $qst.gt_name=='Comic Sans MS,Comic Sans MS,cursive'}selected{/if}
                                                value='Comic Sans MS,Comic Sans MS,cursive'>Comic Sans MS
                                        </option>
                                        <option {if $qst.gt_name=='Courier New,Courier New,Courier,monospace'}selected{/if}
                                                value='Courier New,Courier New,Courier,monospace'>Courier New
                                        </option>
                                        <option {if $qst.gt_name=='Georgia,Georgia,serif'}selected{/if}
                                                value='Georgia,Georgia,serif'>Georgia
                                        </option>
                                        <option {if $qst.gt_name=='Impact,Charcoal,sans-serif'}selected{/if}
                                                value='Impact,Charcoal,sans-serif'>Impact
                                        </option>
                                        <option {if $qst.gt_name=='Lucida Console,Monaco,monospace'}selected{/if}
                                                value='Lucida Console,Monaco,monospace'>Lucida Console
                                        </option>
                                        <option {if $qst.gt_name=='Lucida Sans Unicode,Lucida Grande,sans-serif'}selected{/if}
                                                value='Lucida Sans Unicode,Lucida Grande,sans-serif'>Lucida Sans Unicode
                                        </option>
                                        <option {if $qst.gt_name=='Palatino Linotype,Book Antiqua,Palatino,serif'}selected{/if}
                                                value='Palatino Linotype,Book Antiqua,Palatino,serif'>Palatino
                                        </option>
                                        <option {if $qst.gt_name=='Tahoma,Geneva,sans-serif'}selected{/if}
                                                value='Tahoma,Geneva,sans-serif'>Tahoma
                                        </option>
                                        <option {if $qst.gt_name=='Times New Roman,Times,serif'}selected{/if}
                                                value='Times New Roman,Times,serif'>Times New Roman
                                        </option>
                                        <option {if $qst.gt_name=='Trebuchet MS,Helvetica,sans-serif'}selected{/if}
                                                value='Trebuchet MS,Helvetica,sans-serif'>Trebuchet MS
                                        </option>
                                        <option {if $qst.gt_name=='Verdana,Geneva,sans-serif'}selected{/if}
                                                value='Verdana,Geneva,sans-serif'>Verdana
                                        </option>
                                    </select></td>
                                <td>{$lang.Qst_font_size}:</td>
                                <td width=70px><input class="form-control form-control-25" type=text value="{$qst.gt_size_int}"
                                                      id=font_size_groups onchange='refresh_font_size(this)'
                                                      onkeyup='refresh_font_size(this)'>px
                                </td>
                                <td>{$lang.Font_color}:</td>
                                <td>
                                    <input type="text" id="gt_font_color" class="colorSelector colorSelectorStyle" value="{if $qst.gt_color}{$qst.gt_color}{else}#000000{/if}">
                                </td>
                                <td>{$lang.Background_color}:</td>
                                <td>
                                    <input type="text" id="gt_bg_color" class="colorSelector colorSelectorStyle" value="{if $qst.gt_bg_color}{$qst.gt_bg_color}{else}#000000{/if}">
                                </td>
                                <td>{$lang.Sample}:</td>
                                <td>
                                    <div id="example_text2"
                                         style="padding:5px; border:1px solid #bbb; color:{$qst.gt_color}; background-color:{$qst.gt_bg_color}; font-family: {$qst.gt_name}; font-size: {$qst.gt_size};">
                                        {$lang.Sample}
                                    </div>
                                </td>
                            </tr>
                        </table>
                        <br>
                        <!-- #95240 -->
                        {$lang.Qst_title_displ} <span class='help_bt' h_id='Qst_title_displ'></span><br>
                        <table>
                            <tr>
                                <td>{$lang.Qst_font_name}:</td>
                                <td width=50px><select class="form-control form-control-160" id=font_name_titles onchange='refresh_font(this);'>
                                        <option {if $qst.ht_name=='Arial,Arial,Helvetica,sans-serif'}selected{/if}
                                                value='Arial,Arial,Helvetica,sans-serif'>Arial
                                        </option>
                                        <option {if $qst.ht_name=='Arial Black,Arial Black,Gadget,sans-serif'}selected{/if}
                                                value='Arial Black,Arial Black,Gadget,sans-serif'>Arial Black
                                        </option>
                                        <option {if $qst.ht_name=='Comic Sans MS,Comic Sans MS,cursive'}selected{/if}
                                                value='Comic Sans MS,Comic Sans MS,cursive'>Comic Sans MS
                                        </option>
                                        <option {if $qst.ht_name=='Courier New,Courier New,Courier,monospace'}selected{/if}
                                                value='Courier New,Courier New,Courier,monospace'>Courier New
                                        </option>
                                        <option {if $qst.ht_name=='Georgia,Georgia,serif'}selected{/if}
                                                value='Georgia,Georgia,serif'>Georgia
                                        </option>
                                        <option {if $qst.ht_name=='Impact,Charcoal,sans-serif'}selected{/if}
                                                value='Impact,Charcoal,sans-serif'>Impact
                                        </option>
                                        <option {if $qst.ht_name=='Lucida Console,Monaco,monospace'}selected{/if}
                                                value='Lucida Console,Monaco,monospace'>Lucida Console
                                        </option>
                                        <option {if $qst.ht_name=='Lucida Sans Unicode,Lucida Grande,sans-serif'}selected{/if}
                                                value='Lucida Sans Unicode,Lucida Grande,sans-serif'>Lucida Sans Unicode
                                        </option>
                                        <option {if $qst.ht_name=='Palatino Linotype,Book Antiqua,Palatino,serif'}selected{/if}
                                                value='Palatino Linotype,Book Antiqua,Palatino,serif'>Palatino
                                        </option>
                                        <option {if $qst.ht_name=='Tahoma,Geneva,sans-serif'}selected{/if}
                                                value='Tahoma,Geneva,sans-serif'>Tahoma
                                        </option>
                                        <option {if $qst.ht_name=='Times New Roman,Times,serif'}selected{/if}
                                                value='Times New Roman,Times,serif'>Times New Roman
                                        </option>
                                        <option {if $qst.ht_name=='Trebuchet MS,Helvetica,sans-serif'}selected{/if}
                                                value='Trebuchet MS,Helvetica,sans-serif'>Trebuchet MS
                                        </option>
                                        <option {if $qst.ht_name=='Verdana,Geneva,sans-serif'}selected{/if}
                                                value='Verdana,Geneva,sans-serif'>Verdana
                                        </option>
                                    </select></td>
                                <td>{$lang.Qst_font_size}:</td>
                                <td width=70px><input class="form-control form-control-25" type=text value="{$qst.ht_size_int}"
                                                      id=font_size_title onchange='refresh_font_size(this)'
                                                      onkeyup='refresh_font_size(this)'>px
                                </td>
                                <td>{$lang.Font_color}:</td>
                                <td>
                                    <input type="text" id="ht_font_color" class="colorSelector colorSelectorStyle" value="{if $qst.ht_color}{$qst.ht_color}{else}#000000{/if}">
                                </td>
                                <td>{$lang.Background_color}:</td>
                                <td>
                                    <input type="text" id="ht_bg_color" class="colorSelector colorSelectorStyle" value="{if $qst.ht_bg_color}{$qst.ht_bg_color}{else}#000000{/if}">
                                </td>
                                <td>{$lang.Sample}:</td>
                                <td>
                                    <div id="example_text3"
                                         style="padding:5px; border:1px solid #bbb; color:{$qst.ht_color}; background-color:{$qst.ht_bg_color}; font-family: {$qst.ht_name}; font-size: {$qst.ht_size};">
                                        {$lang.Sample}
                                    </div>
                                </td>
                            </tr>
                        </table>
                        <!-- #95240 end -->
                    </TD>
                </TR>
                <!--TR>
                    <TD>
                        <h4>{$lang.Qst_save_button_type} <span class='help_bt' h_id='Qst_save_button_type'></span></h4>
                        <input type=radio name='button_type' id='def_button_type' value='0'
                               {if !$qst.button_type}checked{/if}
                               onchange='change_button_type();'>{$lang.Qst_save_button_type1}<br>
                        <input type=radio name='button_type' value='1' {if $qst.button_type}checked{/if}
                               onchange='change_button_type();'>{$lang.Qst_save_button_type2}<br>
                        <div id='show_links'>
                            <p>{$lang.Qst_save_button_url}: <input type=text size=40 id='img_url1'
                                                                   onchange='refresh_img_url(this)'
                                                                   value="{$qst.img_url1}"> <img src='{$qst.img_url1}'
                                                                                                 id='obj_img_url1'
                                                                                                 style="vertical-align:middle;"
                                                                                                 onload="fix_img_button_size(this);">
                            </p>
                            {$lang.Qst_save_button_url2}: <input type=text size=40 id='img_url2'
                                                                 onchange='refresh_img_url(this)'
                                                                 value="{$qst.img_url2}"> <img src='{$qst.img_url2}'
                                                                                               id='obj_img_url2'
                                                                                               style="vertical-align:middle;"
                                                                                               onload="fix_img_button_size(this);"><br>
                        </div>
                        {if !$qst.button_type}
                            <script>
                                document.getElementById('show_links').style.display = 'none';
                            </script>
                        {/if}
                    </TD>
                </TR-->
                <TR style="display:none">
                    <TD>
                        <h4>CSS <span class='help_bt' h_id='CSS'></span></h4>
                        <textarea class="form-control" class="form-control" style="width:700px;height:250px;" id=css_text name='css'>{$qst.css}
                        </textarea>
                    </TD>
                </TR>
            {elseif $sel_tab=="display"}
                <!--tr>
                    <td>
                        {$qst.html_code}
                    </td>
                </tr-->
                <tr>
                    <td align=center>
                        <h4>{$lang.Link_form} <span class='help_bt' h_id='Link_form'></span></h4>
                    </td>
                </tr>
                <tr>
                    <td align=center>
                        <a href="{$qst.link}"
                           onclick="window.open('{$qst.link}', 'form{$qst.id}'); return false">{$qst.link}</a>
                    </td>
                </tr>
                <tr>
                    <td align=center>
                        <h4>{$lang.qst_html_src} <span class='help_bt' h_id='qst_html_src'></span></h4>
                    </td>
                </tr>
                <tr>
                    <td align=center>
                        <textarea class="form-control" style="width:500px;height:100px;" readonly id="clipboard_text"
                                  onmouseup="setTimeout(select_clipboard_text);">{$qst.html_code|escape:'html'}
                        </textarea>
                        <br><br>
                        {$lang.qst_src_explain}
                    </td>
                </tr>
            {elseif $sel_tab=="calc"}
                <tr>
                    <td align=right>{$lang.Computation} <span class='help_bt' h_id='Calcs'></span>:</td>
                    <td align=left>
                        {if $qst.calc_id}
                            <a href="#"
                               onclick="open_calc('calc_id={$qst.calc_id}',{$qst.calculate|strlen});return false;">{$lang.Edit}</a>
                        {else}
                            <textarea class="form-control" cols="38" rows="5" name="calc"></textarea>
                        {/if}
                    </td>
                <tr>
                    <td align=right>JavaScript <span class='help_bt' h_id='JavaScript'></span>:</td>
                    <td>
                        {if $qst.javascript}
                            <a href="#"
                               onclick="open_calc('qst_id={$qst.id}&part=qst_javas',{$qst.javascript|strlen});return false;">{$lang.Edit}</a>
                        {else}
                            <textarea class="form-control" cols="38" rows="5" name="javascript"></textarea>
                        {/if}
                    </td>
                </tr>
            {/if}
        </Table>
        <br>
        <input type="hidden" id="reopen" name="reopen" value="">
        {if $sel_tab=="settings" || $sel_tab=="style_editor" || ($sel_tab=="calc" && (!$qst.calc_id || !$qst.javascript))}
            <input class="btn btn-default btn-sm" type="submit" value="{$lang.Save}"
                   onclick="if (!check_values()) return false; document.getElementById('reopen').value=1;"
                   {if $no_save_mode}disabled title="{$lang.Element_no_edit_msg}"{/if}>
            <br>
            <br>
            <a href="edit_questionare.php?table={$qst.table_id}">{$lang.Return}</a>
        {else}
            <input class="btn btn-default btn-sm" type="button" onclick="location.href='edit_questionare.php?table={$qst.table_id}'"
                   value="{$lang.Qst_return_to_list}">
            <br/>
            <br/>
        {/if}
    </form>
    {/if}

    <br>
    <script>
        var internal_qst = 1;
        $(document).ready(function () {
            init_ac($('.combobox'), true);
        });

        function use_tag(check) {
            tag = document.getElementById('UTM_tag');
            fields = document.getElementById('UTM_fields');
            if (check) {
                tag.style.display = 'table-row-group';
            } else {
                tag.style.display = 'none';
                fields.style.display = 'none';
            }
        }
        function tag_fields(value) {
            fields = document.getElementById('UTM_fields');
            if (value === 'manual') {
                fields.style.display = 'table-row-group';
            } else {
                fields.style.display = 'none';
            }
        }

        init_chosen();
    </script>
</div>

<script async>
  function setColorPickerValue(event, color) {
    const input = $(event.target);
    const attr  = input.attr('data-css-style-attr') || '';

    const new_value = color.toHexString();
    input.val(new_value);
  }

  // Изменение режима цветов
  async function changeColorMode() {
    const value = $('input[name="color_mode"]:checked').val();
    const paletteBlock  = $('#palette_block');
    const standartBlock = $('#standart_block');

    if (value == 'standart') {
      paletteBlock.css('display', 'none');
      standartBlock.css('display', '');
      await setNewPalette();
    } else {
      standartBlock.css('display', 'none');
      paletteBlock.css('display', '');
    }

    await changeStandartСolor();
    await changePaletteСolor();
    await setNewPalette();
  }

  // Изменение цветовой схемы
  async function changeStandartСolor() {
    const select = $('select[name="standart_color_scheme"]');
    const option = $('select[name="standart_color_scheme"] option:selected');
    const value  = select.val();
    const txt_color = option.attr('txt_col') || '';

    changePaletteСolor();
  }

  // Изменение цветовой схемы
  async function changePaletteСolor() {
    const select = $('select[name="standart_color_scheme"]');
    const option = $('select[name="standart_color_scheme"] option:selected');
    const value  = select.val();
    const txt_color = option.attr('txt_col') || '';

    $('input[name="palette_background_color"]').val(all_colors[value] || '');
    $('input[name="palette_design_color"]').val(txt_color);
  }

  async function setNewPalette() {
    for (let element of [
      $('input[name="palette_background_color"]'), // Цвет фона
      $('input[name="palette_design_color"]')  // Цвет оформления
    ]) {
      element.spectrum({
        clearText:  lang.Reset,
        allowEmpty: true,
        color:      element.val(),
        ...colorpickerSetings
      });
      element.on('move.spectrum', setColorPickerValue);
    }
  }

  //пременные цветов кнопок
  let all_colors = {
    'grey':            '#969696',
    'success':         'rgb(106, 168, 79)',
    'primary':         'rgb(61, 133, 198)',
    'info':            'rgb(69, 129, 142)',
    'warning':         'rgb(230, 145, 56)',
    'danger':          'rgb(204, 0, 0)',
    'bd_group_yellow': 'rgb(241, 194, 50)',
    'bd_group_maroon': 'rgb(166, 28, 0)',
    'bd_group_cyan':   'rgb(60, 120, 216)',
    'bd_group_violet': 'rgb(103, 78, 167)',
    'bd_group_purple': 'rgb(166, 77, 121)',
    'light_grey':      '#ededed',
    'light_green':     'rgb(217, 234, 211)',
    'light_blue':      'rgb(207, 226, 243)',
    'light_turquoise': 'rgb(208, 224, 227)',
    'light_orange':    'rgb(252, 229, 205)',
    'light_red':       'rgb(244, 204, 204)',
    'light_maroon':    'rgb(230, 184, 175)',
    'light_yellow':    'rgb(255, 242, 204)',
    'light_cyan':      'rgb(201, 218, 248)',
    'light_violet':    'rgb(217, 210, 233)',
    'light_purple':    'rgb(234, 209, 220)',
  };

  {if $color_schema.color_mode == 'standart'}changeStandartСolor();{/if}
  setNewPalette();
</script>
<script src="include/js/configuration.js?{$revision}"></script>