{* Check templates access *}
{$templates_access_script}
<script>
    var sel_records = document.getElementById('sel_records');
    var global_cur_index = new Array();
    function show_template_preview(form_id, mode) {
        var newWindow = window.open("", "_blank");
        newWindow.blur();
        var checkValues = $("input[name='sel[]']:checked").map(function () {
            return $(this).val();
        }).get();
        if (checkValues == '') {
//      checkValues = $("input[name='sel[]']").map(function(){
//        return $(this).val();
//      }).get();
            checkValues = -{$current_status};
        }
        if (document.getElementById('view_line_id')) {
            checkValues = new Array();
            checkValues[0] = document.getElementById('view_line_id').value;
        }

        if (document.getElementById('array_status'))
            var array_status = document.getElementById('array_status').value;
        else
            var array_status = '';

        $.ajax({
            url: 'forms.php?ajax_sel_store&table_id={$table_id}',
            type: 'post',
            data: {
                sel: checkValues,
                array_status: array_status,
                csrf: '{$csrf}'
            },
            success: function () {
                newWindow.focus();
                newWindow.location.href = 'forms.php?table={$table_id}&mode=' + mode + '&form=' + form_id + '&view';
            }
        });
    }
    function remove_view_form(form_id, mode) {
    }

    function switch_form(cur_index, mode) {

    }
</script>

{* print *}
<div id="dialog_print" class="dialog1" style="display:none;">
    <div class="hr1"></div>
    {if $dialog_button.print}
        <div id="form_print_wrapper">
            <div class="form-print__wrapper cb-scroll">
                {foreach from=$dialog_button.print item=form name=buttons}
                    <p class="print_btn" id="d_button_print_{$smarty.foreach.buttons.iteration}">
                        <button class="d_button form-print__btn form-print__btn_{if $form.type_form < 3 }printer{else}download{/if}"
                            onclick="dial_form('print',{$form.id},{$form.type_form},'');">{$form.name_form|escape:'html'}</button>
                    </p>
                {/foreach}
            </div>
        </div>
    {else}
        <p class="add1">{$lang.Templates_not_found}<a
                    href={if $cur_page!='fields'}"view_line2.php?table={$table_id}{if $rel_table}&rel_table={$rel_table}&rel_line={$rel_line}&rel_field={$rel_field}{/if}{if $all_filters_on}&all_filters_on{elseif $filter_id}&filter={$filter_id}{/if}{if $archive}&archive{/if}{if $deleted}&deleted{/if}{if $all_records}&all{/if}{if $page}&page={$page}{/if}&line={$line_id}&op=print&back_url={$base64_current_url}"{else}"" onclick="document.getElementById('sel_records').submit(); return false;"{/if}
            >{$lang.additionally}</a></p>
    {/if}
</div>

{* scheduled date *}


<div id="dialog_date" class="dialog1" style="display:none;">
    <div class="hr1"></div>
    <p style="padding-left: 3px;" align="left"><label><input type="radio" name="group1" value="0">{$lang.start_now}
        </label></p>
    <p style="padding-left: 3px;" align="left"><label><input type="radio" name="group1" value="1"
                                                             checked>{$lang.delayed}</label>
        &nbsp;&nbsp;<span id="schedule_span_wrapper"><input id="schedule_send_span" type="text" size="19" maxlength="19"
                                                            class="datetimepicker form-control" tabindex="800" value=""
                                                            style="width: 120px; font-family: Arial,Verdana,sans-serif; font-size: 13px; padding: 5px;">
    </p>
    </span>
    <p>
        <button class="d_button" style="width: 120px;"
                onclick="dial_form('','','','', '', document.getElementById('schedule_send_span').value);">Отправить
        </button>
    </p>
</div>

{* send *}
<div id="dialog_send" class="dialog1" style="display:none; padding-left: 0px; overflow: visible !important;">
    <div id="dialog_left_arrow_send" class="dialog_left_arrow" style="display:none"></div>
    <div id="dialog_right_arrow_send" class="dialog_right_arrow" style="display:none"></div>
    <div class="hr1"></div>
    <div id="form_send_wrapper">
        {if $can_free_send}
            <p class="send_btn" id="d_button_send_0">
                <button class="d_button"
                        onclick="
                        {if $free_send_addr}
                            {if $config.confirm_dispatch == 1}
                                jconfirm('{$lang.confirm_text}', function() { $('#jalert_ok').click(dial_form('send',-2, 2,'','',''));  });
                            {else}
                                dial_form('send',-2, 2,'','','');
                            {/if}
                        {else}
                            jalert('{$lang.No_free_addr}<br><br><a href=\'forms.php?table={$table_id}&mode=send&form=-2&edit\' >Настройки свободного шаблона</a>');
                        {/if}">
                    {$lang.free_mail_template}<img style="margin-top:8px; margin-left:5px;" src="images/free_template_icon.png"/>
                </button>
            </p>
        {/if}
        {if $dialog_button.send}

        {foreach from=$dialog_button.send item=form name=send_buttons}
            <p class="send_btn" id="d_button_send_{$smarty.foreach.send_buttons.iteration}" name="form_{$form.id}"
               onmouseout="$('#lupa_send_{$smarty.foreach.send_buttons.iteration}').css('display', 'none')"
               onmouseover="$('#lupa_send_{$smarty.foreach.send_buttons.iteration}').css('display', 'inline-block')">
                <button class="d_button"
                        onclick="{if $form.paused}jconfirm('{$lang.Mailer_paused_warning}', function() { dial_form('send', {$form.id}, {$form.type_form}, '{$form.warning}', '', {$form.scheduled}) } ) {elseif $config.confirm_dispatch == 1}jconfirm('{$lang.confirm_text}', function() { $('#jalert_ok').click(dial_form('send', {$form.id}, {$form.type_form}, '{$form.warning}', '', {$form.scheduled}));  } ) {else} dial_form('send', {$form.id}, {$form.type_form}, '{$form.warning}', '', {$form.scheduled}){/if};">{$form.name_form|escape:'html'}</button>
                <button id="lupa_send_{$smarty.foreach.send_buttons.iteration}" class="form_lupa"
                        onmouseover="this.style.backgroundPosition = 'left';"
                        onmouseout="this.style.backgroundPosition = 'right';"
                        onclick="show_template_preview({$form.id},'send')"
                ></button>
            </p>
        {/foreach}
    </div>
    <script>
        global_cur_index['send'] = 0;
    </script>
    {if $smarty.foreach.send_buttons.total+$can_free_send > 8}
        <div id="form_switcher_wrapper_send">
            {for $i=0 to $smarty.foreach.send_buttons.total step 8}
                <button id="form_send_switcher_{$i}" class="form_send_switcher form_switcher"
                        onclick="switch_form({$i}, 'send')"></button>
            {/for}
        </div>
        <script>switch_form(0, 'send');</script>
    {/if}
    {else}
    {if $can_free_send}{else}
        <p class="add1">{$lang.Templates_not_found}<a
                    href={if $cur_page!='fields'}"view_line2.php?table={$table_id}{if $rel_table}&rel_table={$rel_table}&rel_line={$rel_line}&rel_field={$rel_field}{/if}{if $all_filters_on}&all_filters_on{elseif $filter_id}&filter={$filter_id}{/if}{if $archive}&archive{/if}{if $deleted}&deleted{/if}{if $all_records}&all{/if}{if $page}&page={$page}{/if}&line={$line_id}&op=send&back_url={$base64_current_url}"{else}"" onclick="document.getElementById('sel_records').submit(); return false;"{/if}
            >{$lang.additionally}</a></p>
    {/if}
    {/if}
</div>

{* free send template *}
{if $can_free_send}
    <div id="dialog_free_send" class="dialog1" style="display:none;">

        <p style="text-align: left; padding-left: 8px;">
            <span style="color: #999">Тема письма:</span>
            <input type=text id="free_subj_send" name=subj_mail value='{$form_free_send.subj_mail}'
                   style="margin-top:5px; width: 400px;"></p>

        <p style="text-align: left; padding-left: 8px;">
            <span style="color: #999">Текст:</span>
            <textarea name="body_form" id="free_text_send"
                      style="margin-top:5px; height: 130px; width: 400px; resize: none">{$form_free_send.body_form}</textarea>
        </p>
        <p>
            <button class="d_button" style="width: 120px;" onclick="{if $config.confirm_dispatch == 1}jconfirm('{$lang.confirm_text}', function() { $('#jalert_ok').click(dial_form('send',-3,1,'','',''));  } ) {else}dial_form('send',-3,1,'','',''){/if};">Отправить</button>
        </p>

    </div>
{/if}

{* sms *}
<div id="dialog_sms" class="dialog1" style="display:none; padding-left: 0px; overflow: visible !important;">
    <div id="dialog_left_arrow_sms" class="dialog_left_arrow" style="display:none"></div>
    <div id="dialog_right_arrow_sms" class="dialog_right_arrow" style="display:none"></div>
    <div class="hr1"></div>
    <div id="form_sms_wrapper">
        {if $can_free_sms}
            <p class="sms_btn" id="d_button_sms_0">
                <button class="d_button"
                        onclick="
                        {if $free_sms_addr}
                            {if $config.confirm_dispatch == 1}
                                jconfirm('{$lang.confirm_text}', function () { $('#jalert_ok').click(dial_form('sms',-2,1,'', '', '')} );
                            {else}
                                dial_form('sms',-2, 2,'','','');
                            {/if}
                        {else}
                            jalert('{$lang.No_free_addr}<br><br><a href=\'forms.php?table={$table_id}&mode=sms&form=-2&edit\' >Настройки свободного шаблона</a>');
                        {/if}
                                ">
                    {$lang.free_sms_template}<img style="margin-top:8px; margin-left:5px;" src="images/free_template_icon.png"/>
                </button>
            </p>
        {/if}
        {if $dialog_button.sms}

        {foreach from=$dialog_button.sms item=form name=sms_buttons}
            <p class="sms_btn dialog_sms_button" id="d_button_sms_{$smarty.foreach.sms_buttons.iteration}" name="form_{$form.id}"
               >
                <button class="d_button"
                        onclick="{if $config.confirm_dispatch == 1}jconfirm('{$lang.confirm_text}', function () { $('#jalert_ok').click(dial_form('sms',{$form.id},{$form.type_form},'', '', {$form.scheduled}));  });{else}dial_form('sms',{$form.id},{$form.type_form},'', '', {$form.scheduled}){/if}">{$form.name_form}</button>
                <button id="lupa_sms_{$smarty.foreach.sms_buttons.iteration}" class="form_lupa"
                        onclick="show_template_preview({$form.id},'sms')"
                ></button>
            </p>
        {/foreach}
    </div>
    <script>
        global_cur_index['sms'] = 0;
    </script>
    {if $smarty.foreach.sms_buttons.total + $can_free_sms > 8}
        <div id="form_switcher_wrapper_sms">
            {for $i=0 to $smarty.foreach.sms_buttons.total step 8}
                <button id="form_sms_switcher_{$i}" class="form_sms_switcher form_switcher"
                    onclick="switch_form({$i}, 'sms')"></button>
            {/for}
        </div>
        <script>switch_form(0, 'sms');</script>
    {/if}
    {else}
    {if $can_free_sms}{else}
        <p class="add1">{$lang.Templates_not_found}<a
                href={if $cur_page!='fields'}"view_line2.php?table={$table_id}{if $rel_table}&rel_table={$rel_table}&rel_line={$rel_line}&rel_field={$rel_field}{/if}{if $all_filters_on}&all_filters_on{elseif $filter_id}&filter={$filter_id}{/if}{if $archive}&archive{/if}{if $deleted}&deleted{/if}{if $all_records}&all{/if}{if $page}&page={$page}{/if}&line={$line_id}&op=sms&back_url={$base64_current_url}"{else}"" onclick="document.getElementById('sel_records').submit(); return false;"{/if}
            >{$lang.additionally}</a></p>
    {/if}
    {/if}
</div>

{* free sms template *}
<div id="dialog_free_sms" class="dialog1" style="display:none;">
    <p style="text-align: left; padding-left: 8px;">
        <span style="color: #999">Текст:</span>
        <textarea name="body_form" id="free_text_sms"
                  style="margin-top:5px; height: 130px; width: 400px; resize: none">{$form_free_sms.body_form}</textarea>
    </p>
    <p>
        <button class="d_button" style="width: 120px;" onclick="{if $config.confirm_dispatch == 1}jconfirm('{$lang.confirm_text}', function() { $('#jalert_ok').click(dial_form('sms',-3,1,'', '', ''));  });{else}dial_form('sms',-3,1,'', '', ''){/if}">Отправить</button>
</div>

{* search *}
<div id="dialog_search" class="dialog1" style="display:none;">
    <div class="hr1"></div>
    {if $dialog_button.search}
        <div id="form_search_wrapper">
        {foreach from=$dialog_button.search item=form name=buttons}
                <p class="search_btn" id="d_button_print_{$smarty.foreach.buttons.iteration}">
                    <button class="d_button" onclick="dial_form('search',{$form.id},'');">{$form.name_form}</button>
                </p>
        {/foreach}
        </div>
        {foreach from=$dialog_button.search item=form name=buttons}
            {if $smarty.foreach.buttons.total > 8}
                <div id="form_switcher_wrapper_search">
                    {for $i=0 to $smarty.foreach.buttons.total step 8}
                        <button id="form_search_switcher_{$i}" class="form_search_switcher form_switcher"
                                onclick="switch_form({$i}, 'search')"></button>
                    {/for}
                </div>
            {/if}
        {/foreach}
    {else}
        <p class="add1">{$lang.No_templates}</p>
    {/if}
    <script>
        switch_form(0, 'search');
    </script>
</div>


{* autocall *}
<div id="dialog_autocall" class="dialog1" style="display:none;">
    <div class="hr1"></div>
    {if $dialog_button.autocall}
        {foreach from=$dialog_button.autocall item=form name=buttons}
            <p>
                <button class="d_button" onclick="dial_form('autocall',{$form.id},'','','',1);">{$form.name_form}</button>
            </p>
        {/foreach}
    {else}
        <p class="add1">{$lang.No_templates}</p>
    {/if}
</div>

{* один из авариантов реализации *}
{* rel_tables
<div id="dialog_rel_tab_list" class="dialog1" style="display:none;">
    <div class="hr1"></div>
    {if ($all_reltables or $all_reltables_act) and $line_id!="new" and $line_id!="array" and $line_status neq 3}
		<div class="connected-tables__frame">
			<div class="connected-tables__dropdown-menu ">
				{foreach from=$all_reltables_act item=one_reltable}
                    <div class="connected-tables-frame__item">
						<a href="fields.php?table={$one_reltable.id}&rel_search&rel_table={$one_reltable.rel_table}&rel_line={$one_reltable.rel_line}&rel_field={$one_reltable.rel_field} "
						      class="connected-tables__link" target="_blank">
						    <span>{if $lang.conf.{$one_reltable.name_table}}{$lang.conf.{$one_reltable.name_table}}{else}{$one_reltable.name_table}{/if} {if $count_rel_fields[$one_reltable.id]>1}({if $lang.conf.{$one_reltable.rel_fname}}{$lang.conf.{$one_reltable.rel_fname}}{else}{$one_reltable.rel_fname}{/if}){/if}</span>
						</a>
					</div>
                {/foreach}
				{if $all_reltables}
                    <ul class="connected-tables__dropdown-menu-all" id="rel_tables_sublist" {if $all_reltables_act}style="display: none;"{/if}>
						{foreach from=$all_reltables item=one_reltable}
                            <li class="connected-tables-frame__item">
								<a href="fields.php?table={$one_reltable.id}&rel_search&rel_table={$one_reltable.rel_table}&rel_line={$one_reltable.rel_line}&rel_field={$one_reltable.rel_field} "
									    class="connected-tables__link" target="_blank">
									<span>{if $lang.conf.{$one_reltable.name_table}}{$lang.conf.{$one_reltable.name_table}}{else}{$one_reltable.name_table}{/if} {if $count_rel_fields[$one_reltable.id]>1}({if $lang.conf.{$one_reltable.rel_fname}}{$lang.conf.{$one_reltable.rel_fname}}{else}{$one_reltable.rel_fname}{/if}){/if}</span>
								</a>
							</li>
                        {/foreach}
					</ul>
                    {if $all_reltables_act}
                        <button type="button" class="connected-tables-frame__show-more" id="rel_tables_show">{$lang.Show_more}</button>
                    {/if}
				{/if}
			</div>
	    </div>
    {/if}
</div> *}

{* rel_tables *}
<div id="dialog_rel_tab_list" class="dialog1" style="display:none;">
    <div class="hr1"></div>
    {if $all_rel_tabs }
		    <div id="form_rel_tab_list_wrapper">
				{foreach from=$all_rel_tabs item=one_reltable name=rel_tab_list}
                    {if $form.id == 100500 || $form.id == 100501}
                        <p class="connected-tables-frame__item rel_tab_list_btn">
                            <a href="fields.php?table={$one_reltable.id}&rel_search&rel_table={$one_reltable.rel_table}&rel_line={$one_reltable.rel_line}&rel_field={$one_reltable.rel_field}"
                                class="connected-tables__link" target="_blank">
                                <button class="d_button">
                                    <span>{if $lang.conf.{$one_reltable.name_table}}{$lang.conf.{$one_reltable.name_table}}{else}{$one_reltable.name_table}{/if} {if $count_rel_fields[$one_reltable.id]>1}({if $lang.conf.{$one_reltable.rel_fname}}{$lang.conf.{$one_reltable.rel_fname}}{else}{$one_reltable.rel_fname}{/if}){/if}</span>
                                </button>
                            </a>
                        </p>
                    {else}
                        <p class="rel_tab_list_btn" id="d_button_rel_tab_list_{$smarty.foreach.rel_tab_list.iteration}">
                            <a href="fields.php?table={$one_reltable.id}&rel_search&rel_table={$one_reltable.rel_table}&rel_line={$one_reltable.rel_line}&rel_field={$one_reltable.rel_field}"
                                class="connected-tables__link" target="_blank">
                                <button class="d_button">
                                    <span>{if $lang.conf.{$one_reltable.name_table}}{$lang.conf.{$one_reltable.name_table}}{else}{$one_reltable.name_table}{/if} {if $count_rel_fields[$one_reltable.id]>1}({if $lang.conf.{$one_reltable.rel_fname}}{$lang.conf.{$one_reltable.rel_fname}}{else}{$one_reltable.rel_fname}{/if}){/if}</span>
                                </button>
                            </a>
                        </p>
                    {/if}
                {/foreach}
        	</div>

            {if $smarty.foreach.rel_tab_list.total > 8}
                <div id="form_switcher_wrapper_rel_tab_list">
                    {for $i=0 to $smarty.foreach.rel_tab_list.total step 8}
                        <button id="form_rel_tab_list_switcher_{$i}" class="form_rel_tab_list_switcher form_switcher"
                                onclick="switch_form({$i}, 'rel_tab_list')">
                        </button>
                    {/for}
                </div>
            {/if}
    {else}
        <p class="add1">Связанные тацблицы отсутствуют</p>
    {/if}
    <script>
        switch_form(0, 'rel_tab_list');
    </script>
</div>

{* syncron *}
<div id="dialog_sync_list" class="dialog1" style="display:none;">
    <div class="hr1"></div>
    {if $sync_list }
        <div id="form_sync_list_wrapper">
            {foreach from=$sync_list item=one_sync name=sync_list}
                <p class="sync_list_btn" id="d_button_sync_list_{$smarty.foreach.sync_list.iteration}">
                    <a href="{$one_sync.host}/sync.php?field={$one_sync.field}&view_line={$one_sync.line}"
                        class="connected-tables__link" target="_blank">
                        <button class="d_button">
                            <span>{if $lang.conf.{$one_sync.name}}{$lang.conf.{$one_sync.name}}{else}{$one_sync.name}{/if}</span>
                        </button>
                    </a>
                </p>
            {/foreach}
        </div>

        {if $smarty.foreach.sync_list.total > 8}
            <div id="form_switcher_wrapper_sync_list">
                {for $i=0 to $smarty.foreach.sync_list.total step 8}
                    <button id="form_sync_list_switcher_{$i}" class="form_sync_list_switcher form_switcher"
                            onclick="switch_form({$i}, 'sync_list')">
                    </button>
                {/for}
            </div>
        {/if}
    {/if}
    <script>
        switch_form(0, 'sync_list');
    </script>
</div>

{* Месенджеры *}
<div id="dialog_msg" class="dialog1" style="display:none; padding-left: 0px; overflow: visible !important;">
    <div id="dialog_left_arrow_msg" class="dialog_left_arrow" style="display:none"></div>
    <div id="dialog_right_arrow_msg" class="dialog_right_arrow" style="display:none"></div>
    <div class="hr1"></div>
    <div id="form_msg_wrapper">
    {if $dialog_button.msg}
        {foreach from=$dialog_button.msg item=form name=msg_buttons}
            <p class="msg_btn" id="d_button_msg_{$smarty.foreach.msg_buttons.iteration}" name="form_{$form.id}"
               onmouseout="$('#lupa_msg_{$smarty.foreach.msg_buttons.iteration}').css('display', 'none')"
               onmouseover="$('#lupa_msg_{$smarty.foreach.msg_buttons.iteration}').css('display', 'inline-block')">
                <button class="d_button"
                        onclick="{if $config.confirm_dispatch == 1}jconfirm('{$lang.confirm_text}', function () { $('#jalert_ok').click(dial_form('msg',{$form.id},{$form.type_form},'', '', {$form.scheduled}));  });{else}dial_form('msg',{$form.id},{$form.type_form},'', '', {$form.scheduled}){/if}">{$form.name_form}</button>
                <button id="lupa_msg_{$smarty.foreach.msg_buttons.iteration}" class="form_lupa"
                        onmouseover="this.style.backgroundPosition = 'left';"
                        onmouseout="this.style.backgroundPosition = 'right';"
                        onclick="show_template_preview({$form.id},'msg')"
                ></button>
            </p>
        {/foreach}
        <script>
            global_cur_index['msg'] = 0;
        </script>
        {if $smarty.foreach.msg_buttons.total > 8}
            <div id="form_switcher_wrapper_msg">
                {for $i=0 to $smarty.foreach.msg_buttons.total step 8}
                    <button id="form_msg_switcher_{$i}" class="form_msg_switcher form_switcher"
                            onclick="switch_form({$i}, 'msg')"></button>
                {/for}
            </div>
            <script>switch_form(0, 'msg');</script>
        {/if}
    {else}
        <p class="add1">{$lang.Templates_not_found}<a
                    href={if $cur_page!='fields'}"view_line2.php?table={$table_id}{if $rel_table}&rel_table={$rel_table}&rel_line={$rel_line}&rel_field={$rel_field}{/if}{if $all_filters_on}&all_filters_on{elseif $filter_id}&filter={$filter_id}{/if}{if $archive}&archive{/if}{if $deleted}&deleted{/if}{if $all_records}&all{/if}{if $page}&page={$page}{/if}&line={$line_id}&op=msg&back_url={$base64_current_url}"{else}"" onclick="document.getElementById('sel_records').submit(); return false;"{/if}
            >{$lang.additionally}</a></p>
    {/if}
    </div>
</div>
