<?php
/* Smarty version 4.3.1, created on 2023-11-29 02:21:06
  from '/Users/nikolaimv/Sites/it-academy.loc/admin/templates/views/telegrams/index.tpl' */

/* @var Smarty_Internal_Template $_smarty_tpl */
if ($_smarty_tpl->_decodeProperties($_smarty_tpl, array (
  'version' => '4.3.1',
  'unifunc' => 'content_656659c2e77e06_55463356',
  'has_nocache_code' => false,
  'file_dependency' => 
  array (
    '01c81ef1e801e7f9a281b2e1672764c715ffe15e' => 
    array (
      0 => '/Users/nikolaimv/Sites/it-academy.loc/admin/templates/views/telegrams/index.tpl',
      1 => 1701206408,
      2 => 'file',
    ),
  ),
  'includes' => 
  array (
    'file:components/page-header.tpl' => 1,
  ),
),false)) {
function content_656659c2e77e06_55463356 (Smarty_Internal_Template $_smarty_tpl) {
$_smarty_tpl->_checkPlugins(array(0=>array('file'=>'/Users/nikolaimv/Sites/it-academy.loc/includes/composer/vendor/smarty/smarty/libs/plugins/function.html_options.php','function'=>'smarty_function_html_options',),));
?>
<form action="<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['adminUrl']->value, ENT_QUOTES, 'UTF-8', true);?>
/telegrams" method="post" id="settings" autocomplete="off">

    <?php $_smarty_tpl->smarty->ext->_capture->open($_smarty_tpl, "buttons", null, null);?>
		<button class="btn btn-sm btn-primary" type="submit" name="action" value="save"><i class="ph-floppy-disk me-2"></i>Сохранить</button>
    <?php $_smarty_tpl->smarty->ext->_capture->close($_smarty_tpl);?>

    <?php $_smarty_tpl->smarty->ext->_capture->open($_smarty_tpl, "breadcrumb", null, null);?>
		<a href="<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['adminUrl']->value, ENT_QUOTES, 'UTF-8', true);?>
/telegrams" class="breadcrumb-item"><?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['title']->value, ENT_QUOTES, 'UTF-8', true);?>
</a>
    <?php $_smarty_tpl->smarty->ext->_capture->close($_smarty_tpl);?>

    <?php $_smarty_tpl->smarty->ext->_capture->open($_smarty_tpl, "showBy", null, null);?>
        		<button type="button" onclick="help('help_faq');" class="btn btn-sm link-danger border-danger"><i class="ph-question me-2"></i>Часто Задаваемые Вопросы</button>
    <?php $_smarty_tpl->smarty->ext->_capture->close($_smarty_tpl);?>

    <?php $_smarty_tpl->_subTemplateRender("file:components/page-header.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array('buttons'=>$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl, 'buttons'),'breadcrumb'=>$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl, 'breadcrumb'),'showBy'=>$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl, 'showBy')), 0, false);
?>

	<div class="content">

		<div class="card border shadow-sm">
			<div class="card-header d-flex justify-content-between m-0 p-0">
				<ul class="nav nav-tabs nav-tabs-overline nav-tabs-highlight fs-base border-top-0">

					<li class="nav-item">
						<a class="nav-link fs-sm active show" href="#general" data-bs-toggle="tab">
							<div class="d-flex align-items-center">
								<i class="ph-gear bg-primary text-primary bg-opacity-10 rounded p-1 me-2"></i>
								<span class="fw-semibold">Основные</span>
							</div>
						</a>
					</li>
					<li class="nav-item">
						<a class="nav-link fs-sm" href="#users" data-bs-toggle="tab">
							<div class="d-flex align-items-center">
								<i class="ph-shield-check bg-primary text-primary bg-opacity-10 rounded p-1 me-2"></i>
								<span class="fw-semibold"> Настройки пользователей</span>
							</div>
						</a>
					</li>
					<li class="nav-item">
						<a class="nav-link fs-sm" href="#contacts" data-bs-toggle="tab">
							<div class="d-flex align-items-center">
								<i class="ph-identification-card bg-primary text-primary bg-opacity-10 rounded p-1 me-2"></i>
								<span class="fw-semibold"> Шаблоны уведомлений</span>
							</div>
						</a>
					</li>
					<li class="nav-item">
						<a class="nav-link fs-sm" href="#logs" data-bs-toggle="tab">
							<div class="d-flex align-items-center">
								<i class="ph-identification-card bg-primary text-primary bg-opacity-10 rounded p-1 me-2"></i>
								<span class="fw-semibold">Логи</span>
							</div>
						</a>
					</li>
				</ul>
			</div>

			<div class="card-body m-0 p-0">
				<div class="tab-content mb-0 p-3">
					<div class="tab-pane fade show active" id="general">
						<fieldset class="">
							<div class="row mb-3">
								<label class="col-form-label col-lg-4">Статус</label>
								<div class="col-lg-4">
                                    <?php echo smarty_function_html_options(array('options'=>$_smarty_tpl->tpl_vars['statuses']->value,'name'=>"telegram[status]",'id'=>"status",'selected'=>(($tmp = $_smarty_tpl->tpl_vars['telegram']->value['status'] ?? null)===null||$tmp==='' ? 'V' ?? null : $tmp),'class'=>"form-control select"),$_smarty_tpl);?>

								</div>
								<div class="col-lg-4">
									<button type="button" onclick="help('help_module');" class="btn link-primary border-primary"><i class="ph-check-square-offset me-2"></i>Инструкция по настройке модуля</button>
								</div>
							</div>
							<div class="row mb-3">
								<label class="col-form-label col-lg-4">Telegram Bot Ключ (токен)<a href="javascript:void(0);" onclick="help('help_bot_telegram');" class="ms-1"><i class="ph-question"></i></a></label>
								<div class="col-lg-8">
									<div class="input-group">
										<input class="form-control" type="text" name="telegram[telegram_key]" value="<?php echo htmlspecialchars((string)(($tmp = $_smarty_tpl->tpl_vars['telegram']->value['telegram_key'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp), ENT_QUOTES, 'UTF-8', true);?>
" id="telegram_key">
										<button class="btn btn-<?php if ((isset($_smarty_tpl->tpl_vars['telegram']->value['webhook'])) && $_smarty_tpl->tpl_vars['telegram']->value['webhook'] != 'no') {?>success<?php } else { ?>primary<?php }?> set_webhook" type="button" onclick="webhook('telegram');"><i class="ph-check-circle me-2"></i> Проверить</button>
									</div>
									<input type="hidden" name="telegram[webhook]" value="<?php if ((isset($_smarty_tpl->tpl_vars['telegram']->value['webhook']))) {
echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['telegram']->value['webhook'], ENT_QUOTES, 'UTF-8', true);
} else { ?>no<?php }?>" />
								</div>
							</div>
							<div class="row mb-3">
								<label class="col-form-label col-lg-4">Длинное сообщение <a href="javascript:void(0);" onclick="help('help_trim_messages');" class="ms-1"><i class="ph-question"></i></a></label>
								<div class="col-lg-8">
									<div class="form-check form-check-inline mt-2">
										<input type="radio" class="form-check-input" name="telegram[trim_messages]" value="1" id="crop" <?php if ((isset($_smarty_tpl->tpl_vars['telegram']->value['trim_messages'])) && $_smarty_tpl->tpl_vars['telegram']->value['trim_messages'] == 1) {?>checked=""<?php }?>>
										<label class="form-check-label" for="crop">Обрезать</label>
									</div>
									<div class="form-check form-check-inline mt-2">
										<input type="radio" class="form-check-input" name="telegram[trim_messages]" value="0" id="smash" <?php if ((isset($_smarty_tpl->tpl_vars['telegram']->value['trim_messages'])) && $_smarty_tpl->tpl_vars['telegram']->value['trim_messages'] == 0) {?>checked=""<?php }?>>
										<label class="form-check-label" for="smash">Разбивать</label>
									</div>
								</div>
							</div>
							<div class="row mb-3">
								<label class="col-form-label col-lg-4">Таймаут соединения<a href="javascript:void(0);" onclick="help('help_timeout');" class="ms-1"><i class="ph-question"></i></a></label>
								<div class="col-lg-2">
									<input class="form-control" type="text" name="telegram[timeout]" value="<?php echo htmlspecialchars((string)(($tmp = $_smarty_tpl->tpl_vars['telegram']->value['timeout'] ?? null)===null||$tmp==='' ? 5 ?? null : $tmp), ENT_QUOTES, 'UTF-8', true);?>
" placeholder="5">
								</div>
							</div>
							<div class="row mb-3">
								<label class="col-form-label col-lg-4">Использовать прокси<a href="javascript:void(0);" onclick="help('help_proxy');" class="ms-1"><i class="ph-question"></i></a></label>
								<div class="col-lg-8">
									<div class="form-check form-check-inline mt-2">
										<input type="radio" class="form-check-input" name="telegram[proxy]" value="1" id="yes_proxy" <?php if ((isset($_smarty_tpl->tpl_vars['telegram']->value['proxy'])) && $_smarty_tpl->tpl_vars['telegram']->value['proxy'] == 1) {?>checked=""<?php }?> onclick="collapseProxy(this);">
										<label class="form-check-label" for="yes_proxy">Да</label>
									</div>
									<div class="form-check form-check-inline mt-2">
										<input type="radio" class="form-check-input" name="telegram[proxy]" value="0" id="not_proxy" <?php if ((isset($_smarty_tpl->tpl_vars['telegram']->value['proxy'])) && $_smarty_tpl->tpl_vars['telegram']->value['proxy'] == 0) {?>checked=""<?php }?> onclick="collapseProxy(this);">
										<label class="form-check-label" for="not_proxy">Нет</label>
									</div>
								</div>
							</div>
							<div class="row mb-3 collapse_proxy collapse <?php if ((isset($_smarty_tpl->tpl_vars['telegram']->value['proxy'])) && $_smarty_tpl->tpl_vars['telegram']->value['proxy'] == 1) {?>show<?php }?> ">
								<label class="col-form-label col-lg-4">Прокси (только Socks 5!)<br>
									<button type="button" class="btn btn-outline-primary my-2 add_proxy" onclick="addProxy();">Добавить прокси</button>
								</label>

								<div class="col-lg-8">
									<div class="table-responsive">
										<table class="table table_proxy" id="proxy_block">
											<thead id="header">
											<tr>
												<th width="30">Использовать</th>
												<th class="variant_name">IP-адрес</th>
												<th>Порт</th>
												<th>Логин</th>
												<th>Пароль</th>
												<th>Удалить</th>
											</tr>
											</thead>

											<tbody id="proxys" class="proxys">
                                            <?php $_smarty_tpl->_assignInScope('count_telegram_proxydata', 0);?>
                                            <?php if ((isset($_smarty_tpl->tpl_vars['telegram']->value['telegram_proxy_data']))) {?>
                                                <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['telegram']->value['telegram_proxy_data'], 'proxy_data');
$_smarty_tpl->tpl_vars['proxy_data']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['proxy_data']->value) {
$_smarty_tpl->tpl_vars['proxy_data']->do_else = false;
?>
													<tr id="proxy-<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['count_telegram_proxydata']->value, ENT_QUOTES, 'UTF-8', true);?>
">
														<td class="text-center">
															<div class="form-check mb-2">
																<input type="checkbox" class="form-check-input" name="telegram_proxy_data[<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['count_telegram_proxydata']->value, ENT_QUOTES, 'UTF-8', true);?>
][status]" <?php if ((isset($_smarty_tpl->tpl_vars['proxy_data']->value['status'])) && $_smarty_tpl->tpl_vars['proxy_data']->value['status'] == 'on') {?>checked<?php }?>>
															</div>
														</td>
														<td>
															<input type="text" name="telegram_proxy_data[<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['count_telegram_proxydata']->value, ENT_QUOTES, 'UTF-8', true);?>
][ip]" value="<?php echo htmlspecialchars((string)(($tmp = $_smarty_tpl->tpl_vars['proxy_data']->value['ip'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp), ENT_QUOTES, 'UTF-8', true);?>
" placeholder="IP-адрес"  class="form-control" />
														</td>
														<td><input type="text" name="telegram_proxy_data[<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['count_telegram_proxydata']->value, ENT_QUOTES, 'UTF-8', true);?>
][port]" value="<?php echo htmlspecialchars((string)(($tmp = $_smarty_tpl->tpl_vars['proxy_data']->value['port'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp), ENT_QUOTES, 'UTF-8', true);?>
" placeholder="Порт"  class="form-control" /></td>
														<td><input type="text" name="telegram_proxy_data[<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['count_telegram_proxydata']->value, ENT_QUOTES, 'UTF-8', true);?>
][login]" value="<?php echo htmlspecialchars((string)(($tmp = $_smarty_tpl->tpl_vars['proxy_data']->value['login'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp), ENT_QUOTES, 'UTF-8', true);?>
" placeholder="Логин"  class="form-control" /></td>
														<td><input type="text" name="telegram_proxy_data[<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['count_telegram_proxydata']->value, ENT_QUOTES, 'UTF-8', true);?>
][password]" value="<?php echo htmlspecialchars((string)(($tmp = $_smarty_tpl->tpl_vars['proxy_data']->value['password'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp), ENT_QUOTES, 'UTF-8', true);?>
" placeholder="Пароль"  class="form-control" /></td>
														<td class="text-center">
															<button type="button" class="btn btn-link text-danger del_proxy" onclick="confirm('Данное действие необратимо. Вы уверены?') ? $('#proxy-<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['count_telegram_proxydata']->value, ENT_QUOTES, 'UTF-8', true);?>
').remove() : false;"><i class="ph-trash"></i></button>
														</td>
													</tr>

                                                    <?php $_smarty_tpl->_assignInScope('count_telegram_proxydata', $_smarty_tpl->tpl_vars['count_telegram_proxydata']->value+1);?>
                                                <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                                            <?php }?>
											</tbody>

										</table>
									</div>
								</div>
							</div>

						</fieldset>
					</div>

					<div class="tab-pane fade" id="users">
						<div class="mb-3">
							<div class="table-responsive">
								<table class="table table_users" id="users_block">
									<thead id="header">
									<tr>
										<th class="text-start" width="40%">Администратор</th>
										<th class="text-start">telegram ID <a href="javascript:void(0);" onclick="help_id('help_id_telegram');" class="ms-1"><i class="ph-question"></i></a></th>
										<th class="text-center">Уведомлять</th>
										<th class="text-center" width="30">Удалить</th>
									</tr>
									</thead>

									<tbody id="users" class="variants sortable-table">
                                    <?php $_smarty_tpl->_assignInScope('groupdata_row', 0);?>
                                    <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['users']->value, 'user', false, 'key');
$_smarty_tpl->tpl_vars['user']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['key']->value => $_smarty_tpl->tpl_vars['user']->value) {
$_smarty_tpl->tpl_vars['user']->do_else = false;
?>
										<tr id="user-<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8', true);?>
">
											<td><?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['user']->value['loginName'], ENT_QUOTES, 'UTF-8', true);?>
</td>
											<td>
												<input type="text" name="telegram_user_data[<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8', true);?>
][id_telegram]" value="<?php echo htmlspecialchars((string)(($tmp = $_smarty_tpl->tpl_vars['telegram']->value['telegram_user_data'][$_smarty_tpl->tpl_vars['user']->value['userId']]['id_telegram'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp), ENT_QUOTES, 'UTF-8', true);?>
" placeholder="telegram ID"  class="form-control" />
											</td>
											<td>
												<div class="d-flex align-items-center justify-content-center">
													<div class="form-check">
														<input type="checkbox" class="form-check-input" name="telegram_user_data[<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8', true);?>
][checked]" <?php if ((isset($_smarty_tpl->tpl_vars['telegram']->value['telegram_user_data'][$_smarty_tpl->tpl_vars['user']->value['userId']]['checked']))) {?>checked<?php }?>>
													</div>
												</div>
											</td>
											<td class="text-center"></td>
										</tr>
                                    <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>

                                    <?php if (!empty($_smarty_tpl->tpl_vars['telegram']->value['telegram_user_groupdata'])) {?>

                                        <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['telegram']->value['telegram_user_groupdata'], 'user', false, 'key');
$_smarty_tpl->tpl_vars['user']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['key']->value => $_smarty_tpl->tpl_vars['user']->value) {
$_smarty_tpl->tpl_vars['user']->do_else = false;
?>
											<tr id="group-<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8', true);?>
">
												<td><input type="text" name="telegram_user_groupdata[<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8', true);?>
][name]" value="<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['user']->value['name'], ENT_QUOTES, 'UTF-8', true);?>
" placeholder="telegram ID"  class="form-control" /></td>
												<td><input type="text" name="telegram_user_groupdata[<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8', true);?>
][id_telegram]" value="<?php ob_start();
echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8', true);
$_prefixVariable1 = ob_get_clean();
echo htmlspecialchars((string)(($tmp = $_smarty_tpl->tpl_vars['telegram']->value['telegram_user_groupdata'][$_prefixVariable1]['id_telegram'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp), ENT_QUOTES, 'UTF-8', true);?>
" placeholder="telegram ID"  class="form-control" /></td>
												<td>
													<div class="d-flex align-items-center justify-content-center">
														<div class="form-check">
															<input type="checkbox" class="form-check-input" name="telegram_user_groupdata[<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8', true);?>
][checked]" <?php ob_start();
echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8', true);
$_prefixVariable2 = ob_get_clean();
if ((isset($_smarty_tpl->tpl_vars['telegram']->value['telegram_user_groupdata'][$_prefixVariable2]['checked']))) {?>checked<?php }?>>
														</div>
													</div>
												</td>
												<td class="text-center"><button type="button" class="btn btn-link text-danger del_proxy" onclick="confirm('Данное действие необратимо. Вы уверены?') ? $('#group-<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['key']->value, ENT_QUOTES, 'UTF-8', true);?>
').remove() : false;"><i class="ph-trash"></i></button></td>
											</tr>
                                            <?php $_smarty_tpl->_assignInScope('groupdata_row', $_smarty_tpl->tpl_vars['groupdata_row']->value+1);?>
                                        <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                                    <?php }?>

									</tbody>
									<tfoot>

									</tfoot>
								</table>
								<hr>
								<div class="text-start mt-2">
									<button type="button" class="btn btn-outline-primary add_user" onclick="addUser();">Добавить пользователя</button>
								</div>
							</div>


						</div>
					</div>

					<div class="tab-pane fade" id="contacts">
						<fieldset  class="mb-4">
							<legend class="fs-base fw-bold border-bottom pb-2 mb-3">Обратный звонок</legend>
							<div class="row mb-3">

								<div class="col-lg-7">
									<textarea rows="6" cols="3" class="form-control" name="telegram_langdata[call_me_telegram]" placeholder="#Обратный звонок {subject} от пользователя {name}, телефон {phone}."><?php echo htmlspecialchars((string)(($tmp = $_smarty_tpl->tpl_vars['telegram']->value['telegram_langdata']['call_me_telegram'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp), ENT_QUOTES, 'UTF-8', true);?>
</textarea>
								</div>
								<div class="col-lg-5">
									<button type="button" class="btn btn-primary collapsed mb-2" data-bs-toggle="collapse" data-bs-target="#callMeVars" aria-expanded="false">Список поддерживаемых переменных</button>
									<div class="collapse collapse" id="callMeVars">
										<div class="table-responsive">
											<table class="table table-bordered table-striped">
												<tbody>
                                                <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['callMeVars']->value, 'var', false, 'list');
$_smarty_tpl->tpl_vars['var']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['list']->value => $_smarty_tpl->tpl_vars['var']->value) {
$_smarty_tpl->tpl_vars['var']->do_else = false;
?>
													<tr>
														<td><?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['var']->value, ENT_QUOTES, 'UTF-8', true);?>
</td>
														<td><?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['list']->value, ENT_QUOTES, 'UTF-8', true);?>
</td>
													</tr>
                                                <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
												</tbody>
											</table>
										</div>
									</div>
								</div>
							</div>

							<legend class="fs-base fw-bold border-bottom pb-2 mb-3">Новое сообщение</legend>
							<div class="row mb-3">
								<div class="col-lg-7">
									<textarea rows="6" cols="3" class="form-control" name="telegram_langdata[feedback_telegram]" placeholder="Вы получили новый сообщение {subject} от пользователя {name}, телефон {phone}, email {email}. Сообщение: {message}"><?php echo htmlspecialchars((string)(($tmp = $_smarty_tpl->tpl_vars['telegram']->value['telegram_langdata']['feedback_telegram'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp), ENT_QUOTES, 'UTF-8', true);?>
</textarea>
								</div>
								<div class="col-lg-5">
									<button type="button" class="btn btn-primary collapsed mb-2" data-bs-toggle="collapse" data-bs-target="#feedbackVars" aria-expanded="false">Список поддерживаемых переменных</button>
									<div class="collapse collapse" id="feedbackVars">
										<div class="table-responsive">
											<table class="table table-bordered table-striped">
												<tbody>
                                                <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['feedbackVars']->value, 'var', false, 'list');
$_smarty_tpl->tpl_vars['var']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['list']->value => $_smarty_tpl->tpl_vars['var']->value) {
$_smarty_tpl->tpl_vars['var']->do_else = false;
?>
													<tr>
														<td><?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['var']->value, ENT_QUOTES, 'UTF-8', true);?>
</td>
														<td><?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['list']->value, ENT_QUOTES, 'UTF-8', true);?>
</td>
													</tr>
                                                <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
												</tbody>
											</table>
										</div>
									</div>
								</div>
							</div>

							<legend class="fs-base fw-bold border-bottom pb-2 mb-3">Заявка на курс</legend>
							<div class="row mb-3">
								<div class="col-lg-7">
									<textarea rows="6" cols="3" class="form-control" name="telegram_langdata[service_telegram]" placeholder="Вы получили новый сообщение {subject} от пользователя {name}, телефон {phone}, email {email}. Сообщение: {message}"><?php echo htmlspecialchars((string)(($tmp = $_smarty_tpl->tpl_vars['telegram']->value['telegram_langdata']['service_telegram'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp), ENT_QUOTES, 'UTF-8', true);?>
</textarea>
								</div>
								<div class="col-lg-5">
									<button type="button" class="btn btn-primary collapsed mb-2" data-bs-toggle="collapse" data-bs-target="#serviceVars" aria-expanded="false">Список поддерживаемых переменных</button>
									<div class="collapse collapse" id="serviceVars">
										<div class="table-responsive">
											<table class="table table-bordered table-striped">
												<tbody>
                                                <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['serviceVars']->value, 'var', false, 'list');
$_smarty_tpl->tpl_vars['var']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['list']->value => $_smarty_tpl->tpl_vars['var']->value) {
$_smarty_tpl->tpl_vars['var']->do_else = false;
?>
													<tr>
														<td><?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['var']->value, ENT_QUOTES, 'UTF-8', true);?>
</td>
														<td><?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['list']->value, ENT_QUOTES, 'UTF-8', true);?>
</td>
													</tr>
                                                <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
												</tbody>
											</table>
										</div>
									</div>
								</div>
							</div>

						</fieldset>
					</div>

					<div class="tab-pane fade" id="logs">
						<fieldset class="">
							<div class="mb-3">
								<p class="fw-semibold">Уровни логирования:</p>
								<ol class="fs-sm">
									<li>Выключены - логи не пишутся<span class="text-success"> - рекомендуемый режим!</span></li>
									<li>Только ошибки - в логи пишутся только ошибки соединения (ошибки cURL или ответ с ошибкой от сервера месседжера)</li>
									<li>Полные - в логи пишутся все запросы: успешные и ошибочные, также пишется тест уведомлений.<span class="text-danger"> Не рекомендуется использовать, только в режиме отладки!</span></li>
								</ol>
							</div>
							<div class="row mb-3">
								<label class="col-form-label col-lg-2">Статус <a href="javascript:void(0);" onclick="help('help_log');" class="ms-1"><i class="ph-question"></i></a></label>
								<div class="col-lg-6">
									<div class="input-group">
                                        <?php echo smarty_function_html_options(array('options'=>$_smarty_tpl->tpl_vars['logs']->value,'name'=>"telegram[logs]",'id'=>"logs",'selected'=>(($tmp = $_smarty_tpl->tpl_vars['telegram']->value['logs'] ?? null)===null||$tmp==='' ? '0' ?? null : $tmp),'class'=>"form-control select"),$_smarty_tpl);?>

									</div>
								</div>
								<div class="col-lg-4">
									<div class="input-group">
										<button class="btn btn-danger" type="button" onclick="clearLog('telegram');"><i class="ph-download me-2"></i> Удалить</button>
										<button class="btn btn-primary" type="button" onclick="downloadLog('telegram');"><i class="ph-download me-2"></i> Скачать</button>
									</div>
								</div>
							</div>
							<div class="mb-3">
								<textarea id="log_telegram" rows="6" cols="3" class="form-control form-control-sm" disabled><?php echo $_smarty_tpl->tpl_vars['logs_file']->value;?>
</textarea>
							</div>
						</fieldset>
					</div>

				</div>
			</div>
		</div>


		<div class="col-md-12 main main_buttons text-center">
            <?php echo $_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl, 'buttons');?>

		</div>

	</div>

</form>

<div id="ModalBox" class="modal fade">
	<div class="modal-dialog modal-full">
		<div class="modal-content">
			<div class="modal-header">
				<h5 class="modal-title"></h5>
				<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
			</div>
			<div class="modal-body"></div>
			<div class="modal-footer">
				<button type="button" class="btn btn-link" data-bs-dismiss="modal">Закрыть</button>
			</div>
		</div>
	</div>
</div>

<?php echo '<script'; ?>
>
    $(document).ready(function() {
        <?php if ((isset($_smarty_tpl->tpl_vars['errors']->value['htaccess']))) {?> new Noty({ text: 'Невозможно сохранить файл ".htaccess".', type: 'error' }).show(); <?php }?>
        <?php if ((isset($_smarty_tpl->tpl_vars['errors']->value['serializations']))) {?> new Noty({ text: 'Невозможно сохранить сериализационный файл.', type: 'error' }).show(); <?php }?>
        <?php if ((isset($_smarty_tpl->tpl_vars['messages']->value['saved']))) {?> new Noty({ text: 'Настройки сохранены.', type: 'success' }).show(); <?php }?>

    });

    function collapseProxy(element) {
        const collapse_proxy = document.querySelector('.collapse_proxy');
        const currentProxy = element.value;
        if (currentProxy == 1) {
            collapse_proxy.classList.add('show');
        } else {
            collapse_proxy.classList.remove('show');
        }
    }

    var proxy_row = <?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['count_telegram_proxydata']->value, ENT_QUOTES, 'UTF-8', true);?>
;

    function addProxy() {
        html = '    <tr id="proxy-' + proxy_row + '">';
        html += '       <td class="text-center"><div class="form-check mb-2"><input type="checkbox" class="form-check-input" name="telegram_proxy_data[' + proxy_row + '][status]"></div></td>';
        html += '       <td><input type="text" name="telegram_proxy_data[' + proxy_row + '][ip]" value="" placeholder="IP-адрес"  class="form-control" /></td>';
        html += '       <td><input type="text" name="telegram_proxy_data[' + proxy_row + '][port]" value="" placeholder="Порт"  class="form-control" /></td>';
        html += '       <td><input type="text" name="telegram_proxy_data[' + proxy_row + '][login]" value="" placeholder="Логин"  class="form-control" /></td>';
        html += '       <td><input type="text" name="telegram_proxy_data[' + proxy_row + '][password]" value="" placeholder="Пароль"  class="form-control" /></td>';
        html += '       <td class="text-center"><button type="button" class="btn btn-link text-danger del_proxy" onclick="confirm(\'Данное действие необратимо. Вы уверены?\') ? $(\'#proxy-' + proxy_row + '\').remove() : false;"><i class="ph-trash"></i></button></td>';
        html += '   </tr>';

        $('.table_proxy tbody').append(html);
        proxy_row++;
    }

    var group_row = <?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['groupdata_row']->value, ENT_QUOTES, 'UTF-8', true);?>
;

    function addUser() {
        html = '    <tr id="group-' + group_row + '">';
        html += '       <td><input type="text" name="telegram_user_groupdata[' + group_row + '][name]" value="" placeholder="Имя получателя"  class="form-control" /></td>';
        html += '       <td><input type="text" name="telegram_user_groupdata[' + group_row + '][id_telegram]" value="" placeholder="telegram ID"  class="form-control" /></td>';
        html += '       <td class="text-center"><div class="d-flex align-items-center justify-content-center"><div class="form-check mb-2"><input type="checkbox" class="form-check-input" name="telegram_user_data[' + group_row + '][checked]"></div></div></td>';
        html += '       <td class="text-center"><button type="button" class="btn btn-link text-danger del_proxy" onclick="confirm(\'Данное действие необратимо. Вы уверены?\') ? $(\'#group-' + group_row + '\').remove() : false;"><i class="ph-trash"></i></button></td>';
        html += '   </tr>';

        $('.table_users tbody').append(html);
        group_row++;
    }

    function webhook(key) {

        var bot_key = $('#' + key + '_key').val(), proxy = $("input[name='telegram[proxy]']:checked").val(),
            timeout = $('input[name="telegram[timeout]"]').val(), proxydata = '';

        if (proxy == '1') {
            for (var i=0; i< proxy_row; i++) {
                if (($('input[name="telegram_proxy_data[' + i + '][status]"]').is(':checked')) && ($('input[name="telegram_proxy_data[' + i + '][ip]"]').val() !== '') && ($('input[name="telegram_proxy_data[' + i + '][port]"]').val() !== '')) {
                    proxydata += $('input[name="telegram_proxy_data[' + i + '][ip]"]').val() + ':' + $('input[name="telegram_proxy_data[' + i + '][port]"]').val();

                    if (($('input[name="telegram_proxy_data[' + i + '][login]"]').val() !== '') || ($('input[name="telegram_proxy_data[' + i + '][password]"]').val() !== '')) {
                        proxydata += '@' + $('input[name="telegram_proxy_data[' + i + '][login]"]').val() + ':' + $('input[name="telegram_proxy_data[' + i + '][password]"]').val();
                    }

                    proxydata += ';';
                }
            }
        }

        $.ajax({
            url: '<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['adminUrl']->value, ENT_QUOTES, 'UTF-8', true);?>
/telegrams?action=set_webhook',
            type: 'post',
            dataType: 'json',
            data: { "telegram[key]": key, "telegram[telegram_key]": bot_key, "telegram[timeout]": timeout, "telegram[proxy]": proxy, "telegram[proxydata]": proxydata },
            success: function(response) {

                new Noty({ text: response.message, type: response.type }).show();

                if (response.webhook) {
                    $('input[name="telegram[webhook]"]').val(response.webhook);
                    if (response.webhook == 'no') {
                        $('.set_webhook').removeClass('btn-success').addClass('btn-primary')
                    } else {
                        $('.set_webhook').removeClass('btn-primary').addClass('btn-success')
                    }
                }
            },
            error: function(xhr, ajaxOptions, thrownError) {
                // new Noty({ text: xhr.statusText, type: 'error' }).show();
                console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                // alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
            }
        });
    }


    function help(key) {
        $("#ModalBox").modal('show');
        $.ajax({
            url: '<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['adminUrl']->value, ENT_QUOTES, 'UTF-8', true);?>
/telegrams?action=help&key=' + key,
            type: 'post',
            dataType: 'json',
            success: function(json) {
                if (json['error']) {
                    $(".modal-title").html('Error!');
                    $(".modal-body").html('<div class="h4" style="color:red;text-align:center;">' + json['error'] + '</div>');
                }

                if (json['success']) {
                    $(".modal-title").html(json['header']);
                    $(".modal-body").html(json['success']);
                }
            },
            error: function(xhr, ajaxOptions, thrownError) {
                $("#ModalBox").modal('hide');
                alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
            }
        });
    }

    function help_id(key) {
        $(".modal-body").html('');
        $(".modal-title").html('');
        $("#ModalBox").modal('show');
        webhook = $('input[name="telegram[webhook]"]').val();
        $.ajax({
            url: '<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['adminUrl']->value, ENT_QUOTES, 'UTF-8', true);?>
/telegrams?action=help&key=' + key + '&webhook=' + webhook,
            type: 'post',
            dataType: 'json',
            success: function(json) {
                if (json['error']) {
                    $(".modal-title").html('Error!');
                    $(".modal-body").html('<div class="h4" style="color:red;text-align:center;">' + json['error'] + '</div>');
                }

                if (json['success']) {
                    $(".modal-title").html(json['header']);
                    $(".modal-body").html(json['success']);
                }
            }    ,
            error: function(xhr, ajaxOptions, thrownError) {
                $("#ModalBox").modal('hide');
                alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
            }
        });
    }

    function clearLog(key) {
        $(".modal-body").html('');

        $.ajax({
            url: '<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['adminUrl']->value, ENT_QUOTES, 'UTF-8', true);?>
/telegrams?action=clear_log',
            type: 'post',
            dataType: 'json',
            data: 'key=' + key,
            success: function(response) {
                new Noty({ text: response.message, type: response.type }).show();

                if (response.status == 200) {
                    $('#log_' + key).val('');

                }
            },
            error: function(xhr, ajaxOptions, thrownError) {
                alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
            }
        });
    }

    function downloadLog(key) {
        $(".modal-body").html('');
        $.ajax({
            url: '<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['adminUrl']->value, ENT_QUOTES, 'UTF-8', true);?>
/telegrams?action=download_log' + '&key=' + key,
            type: 'GET',
            success: function(json) {
                if (json['error']) {
                    $("#ModalBox").modal('show');
                    $(".modal-title").html('Error!');
                    $(".modal-body").html('<div class="h4" style="color:red;text-align:center;">' + json['error'] + '</div>');
                } else {
                    $("#ModalBox").modal('hide');
                    window.location = '<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['adminUrl']->value, ENT_QUOTES, 'UTF-8', true);?>
/telegrams?action=download_log' + '&key=' + key;
                }
            },
            error: function(xhr, ajaxOptions, thrownError) {
                alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
            }
        });
    }

<?php echo '</script'; ?>
><?php }
}
