{include file="left.tpl"}

<script src="../modules/editors/tinymce/tinymce.min.js"></script>
<script>
	jQuery(document).ready(function($)
	{
		<? if('{status}' == '1') { ?>
			init_tinymce('text', 'lite', '{file_manager_theme}', '{file_manager}', '<? echo md5($conf->code); ?>');

			$('#msgsmile').popover({html: true, animation: true, trigger: 'click'});
			$('#msgsmile').on('show.bs.popover', function()
			{
				$(document).mouseup(function(e)
				{
					var container = $('.popover-content');

					if(container.has(e.target).length === 0)
					{
						$('#msgsmile').popover('hide');

						selected = 'gcms_smiles';
					}
				});
			});

			get_smiles('#msgsmile', 1);
		<? } ?>

		load_ticket_answers('{id}');
	});

	function set_smile(elem)
	{
		var smile = '<img src="'+$(elem).attr('src')+'" class="g_smile" height="20px" width="20px"> ';

		tinymce.activeEditor.insertContent(smile);

		selected = 'gcms_smiles';
	}

	function close_ticket(id)
	{
		if(confirm('Вы уверены?'))
		{
			NProgress.start();

			$.ajax({
				type: 'POST',
				url: '../ajax/actions_a.php',
				data: 'phpaction=1&close_ticket=1&token='+$("#token").val()+'&id='+id,
				dataType: 'json',
				success: function(result)
				{
					NProgress.done();

					if (result.status == 1)
					{
						setTimeout(show_ok, 500);

						$('#status').html('Закрыт');
						$('#add_answer').hide();
					}else
						setTimeout(show_error, 500);
				}
			});
		}
	}
</script>

<div class="content float-right">
	<div class="block">
		<div class="header">Информация</div>
		<div class="block-content">
			<table class="table-list">
				<tbody>
					<tr class="bh">
						<td width="1%" align="center"><i class="fa fa-file-text-o" aria-hidden="true"></i></td>
						<td width="20%">Тема:</td>
						<td>{name}</td>
					</tr>
					<tr class="bh">
						<td align="center"><i class="fa fa-user-circle-o" aria-hidden="true"></i></td>
						<td>Автор:</td>
						<td><a target="_blank" href="../profile?id={author_id}"><u>{author_login}</u></a></td>
					</tr>
					<tr class="bh">
						<td align="center"><i class="fa fa-heartbeat" aria-hidden="true"></i></td>
						<td>Статус:</td>
						<td>
							<span id="status" class="text-<? if('{status}' == '1') { ?>info">Открыт<? } else { ?>success">Закрыт<? } ?></span>
						</td>
					</tr>
					<? if('{files}' != 'none'){ ?> 
						<tr class="bh">
							<td align="center"><i class="fa fa-file" aria-hidden="true"></i></td>
							<td>Файл:</td>
							<td>
								<a target="_blank" href="../<? echo $ticket->files ?>">Скачать файл</a>
							</td>
						</tr>
					<? } ?>
					<tr>
						<td align="center"><i class="fa fa-clock-o" aria-hidden="true"></i></td>
						<td>Дата создания:</td>
						<td>{date}</td>
					</tr>
				</tbody>
			</table>
			<? if(('{status}' == '1') || (strripos($users_groups[$sessionrights]['rights'], "p") !== false)) { ?>
				<div class="form-input">
					<label>Операции</label>
				</div>
				<? if('{status}' == '1') { ?>
					<div class="btn green float-left m-r-5" onclick="close_ticket('{id}')">Закрыть тикет</div>
				<? } ?>
				<? if(strripos($users_groups[$sessionrights]['rights'], "p") !== false){ ?>
					<div class="btn red float-left" onclick="dell_ticket('{id}')">Удалить тикет</div>
				<? } ?>
				<div class="clear"></div>
			<? } ?>
		</div>
	</div>
	<div class="block">
		<div class="header">Вопрос</div>
		<div class="block-content">
			<p>{text}</p>
		</div>
	</div>

	<? if('{status}' == '1') { ?>
		<link href="{site_host}templates/SquareLine/css/_small.css" rel="stylesheet">

		<div id="add_answer">
			<div class="space"></div>

			<div class="block">
				<div class="header">Оставить комментарий</div>
				<div class="block-content">
					<textarea id="text" maxlenght="1000"></textarea>

					<div class="message-send">
						<i class="fa fa-smile-o" data-container="body" data-content="empty" data-placement="top" data-toggle="popover" id="msgsmile"></i>

						<div class="btn float-right" onclick="send_ticket_answer('{id}')">Отправить</div>
					</div>
				</div>
			</div>
			<div class="clear"></div>
		</div>
	<? } ?>

	<div class="block">
		<div class="header">Комментарии</div>
		<div class="block-content">
			<div id="answers"></div>
		</div>
	</div>
</div>