<?php
require_once('../wu-engine/wu_init.php');
if(isset($_GET['ticket'])) {
$ticket = intval($_GET['ticket']);
$now_ticket = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT id,usr,th,log,av FROM `".DB_PREFIX."_tickets_main` INNER JOIN ".DB_PREFIX."_users ON ".DB_PREFIX."_tickets_main.usr = ".DB_PREFIX."_users.uid WHERE id='$ticket' LIMIT 1"));
if (empty($now_ticket['id'])) {
header ("Location: /".ADMINPATH."/support"); exit;
}
$page_name = 'Просмотр тикета';
$page_keys = 'поддержка, тикет';
$page_desc = 'Просмотр тикета';
$prevurl_1 = '/'.ADMINPATH.'/';
$prevname_1 = 'Панель управления';
$prevurl_2 = '/'.ADMINPATH.'/support';
$prevname_2 = 'Поддержка';
} else {
$page_name = 'Поддержка';
$page_keys = 'поддержка, тикет';
$page_desc = 'Обращения пользователей в службу поддержки';
$prevurl_1 = '/'.ADMINPATH.'/';
$prevname_1 = 'Панель управления';
if (isset($_GET['type']) && $_GET['type'] == 'closed') { $ticket_t = 'Открытые тикеты'; $ticket_l = ''; } else { $ticket_t = 'Закрытые тикеты'; $ticket_l = '?type=closed'; }
$page_right = '<div class="header-buttons"><div class="collapse" id="header-buttons"><div class="well"><div class="btn-group"><a data-toggle="modal" role="button" href="#ticket_new" class="btn btn-primary">Новый тикет</a><a href="/'.ADMINPATH.'/support'.$ticket_l.'" class="btn btn-primary">'.$ticket_t.'</a></div></div></div></div>';
}
$online_title = 'В панели управления';
$online_url = '/';
include('../wu-engine/wu_header.php');
if(!USER_LOGGED) { header ("Location: /"); exit; }
?>

<?php
//Список обращений
if(!isset($_GET['ticket'])) {
?>

<div id="ticket_new" class="modal fade" tabindex="-1" role="dialog">
<form action="#" id="wu-form-send">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title"><i class="icon-pencil"></i> Новый тикет</h4>
</div>
<div class="modal-body with-padding">
<input type="hidden" name="token" value="<?php echo $token; ?>" />
<div class="form-group">
<label>Логин пользователя:</label>
<input type="text" class="form-control" placeholder="Введите логин пользователя" name="user" />
</div>
<div class="form-group">
<label>Категория обращения:</label><br />
<select class="form-control" name="cat">
<?php
$qin = mysqli_query($connect_db, "SELECT id,ti FROM ".DB_PREFIX."_tickets_cat ORDER BY pos ASC");
while($rowi = mysqli_fetch_assoc($qin)) {
?>
<option value="<?php echo $rowi['id']; ?>"<?php if (isset($_GET['cat']) && $_GET['cat'] == $rowi['id']) { echo ' selected=""'; } ?>><?php echo $rowi['ti']; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label>Срочность:</label><br />
<select class="form-control" name="pr">
<option value="1">Низкая</option>
<option value="2" selected="">Средняя</option>
<option value="3">Высокая</option>
</select>
</div>
<div class="form-group">
<label>Тема обращения:</label>
<input type="text" class="form-control" placeholder="Введите тему" name="theme"<?php if (isset($_GET['theme'])) { echo ' value="'.strip_tags($_GET['theme']).'"'; } ?> maxlength="100" />
</div>
<div class="form-group">
<label>Ваше сообщение:</label>
<textarea rows="5" cols="5" class="form-control" placeholder="Введите текст обращения" id="msg_text" name="message"><?php if (isset($_GET['message'])) { echo htmlspecialchars($_GET['message']); } ?></textarea>
</div>
<center>
<div id="wu-files-output" class="margload"></div>
</center>
</div>
<div class="modal-footer">
<input type="file" id="wu-files" name="wu-files[]" multiple="" class="dnone" />
<label for="wu-files" class="btn btn-default btn-icon"><i class="icon-attachment"></i></label>
<div class="btn-group">
<button data-toggle="dropdown" data-play="bounceIn" class="btn btn-default btn-icon dropdown-toggle"><i class="icon-smiley"></i></button>
<ul class="dropdown-menu" style="width: 280px;">
<li></li>
<li>
<div class="emogiblc smile-main"><div class="webupper_smile"><div><i class="wu-smile wu-1"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-2"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-3"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-4"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-5"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-6"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-7"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-8"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-9"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-10"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-11"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-12"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-13"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-14"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-15"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-16"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-17"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-18"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-19"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-20"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-21"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-22"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-23"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-24"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-25"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-26"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-27"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-28"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-29"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-30"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-31"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-32"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-33"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-34"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-35"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-36"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-37"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-38"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-39"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-40"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-41"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-42"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-43"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-44"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-45"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-46"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-47"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-48"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-49"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-50"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-51"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-52"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-53"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-54"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-55"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-56"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-57"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-58"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-59"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-60"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-61"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-62"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-63"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-64"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-65"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-66"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-67"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-68"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-69"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-70"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-71"></i></div></div><div class="wu-smile-clear"></div></div>
</li>
</ul>
</div>
<button type="button" id="ticket_send" class="btn btn-success margl_5" data-loading-text="<i class='icon-spinner7 spin'></i> Создаём">Создать тикет</button>
<button class="btn btn-warning" data-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</form>
</div>

<?php
//Подключаем пагинацию и функции
include('../wu-engine/wu-functions/wu_pagination.php');
include('../wu-engine/wu-functions/wu_functions.php');

$num = 20; //Сколько выводить на странице
if (isset($_GET['type']) && $_GET['type'] == 'closed') { $where_add = "WHERE closed = '1'"; } else { $where_add = "WHERE closed = '0'"; }
if (isset($_GET['page'])) { $page = intval($_GET['page']); if ($page == 0) { $page = 1; } } else { $page = 1; }
$qu = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT count(`id`) AS `cnt` FROM ".DB_PREFIX."_tickets_main $where_add"));
$co = $qu['cnt'];
$total = intval(($co - 1) / $num) + 1;
$page = intval($page);
if(empty($page) or $page < 0) $page = 1;
if($page > $total) $page = $total;
$start = $page * $num - $num;
$qt = mysqli_query($connect_db, "SELECT ".DB_PREFIX."_tickets_main.id,cat,pr,th,new_a,ti,log FROM `".DB_PREFIX."_tickets_main` INNER JOIN ".DB_PREFIX."_tickets_cat ON ".DB_PREFIX."_tickets_main.cat = ".DB_PREFIX."_tickets_cat.id INNER JOIN ".DB_PREFIX."_users ON ".DB_PREFIX."_tickets_main.usr = ".DB_PREFIX."_users.uid $where_add ORDER BY new_a DESC, dt DESC LIMIT $start, $num");
$ht = mysqli_num_rows($qt);
if ($ht > 0) {
?>
<div id="ticket_list">
<div class="panel panel-default">
<div class="panel-heading"><h6 class="panel-title"><i class="icon-bubbles4"></i> Обращения пользователей</h6></div>
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr align="center">
<th>#</th>
<th>Пользователь</th>
<th>Тема</th>
<th>Категория</th>
<th>Срочность</th>
<th>Статус</th>
<th>Действия</th>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_assoc($qt)) { ?>
<tr class="mc_<?php echo $row['id']; if ($row['new_a'] == 1) { echo ' success'; } ?>">
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['log']; ?></td>
<td><a href="/<?php echo ADMINPATH; ?>/support?ticket=<?php echo $row['id']; ?>"><?php echo htmlspecialchars($row['th']); ?></td>
<td><?php echo $row['ti']; ?></td>
<td><?php echo wu_urgency($row['pr']); ?></a></td>
<td>
<?php if (isset($_GET['type']) && $_GET['type'] == 'closed') { echo 'Закрыт'; } else {
if ($row['new_a'] == 0) { echo 'Открыт'; } else { echo '<span class="text-success">Отвечено</span>'; }
}
?>
</td>
<td>
<a href="javascript://" class="btn btn-icon btn-sm btn-default tip"<?php if (isset($_GET['type']) && $_GET['type'] == 'closed') { echo ' disabled="disabled"'; } ?> data-placement="bottom" data-original-title="Закрыть тикет" onclick="ticket_close('<?php echo $row['id']; ?>');"><i class="icon-lock"></i></a>
<a href="javascript://" class="btn btn-icon btn-sm btn-default tip" data-placement="bottom" data-original-title="Удалить тикет" onclick="ticket_del('<?php echo $row['id']; ?>');"><i class="icon-remove"></i></a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>

<div id="modal_ticket_close" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title"><i class="icon-lock"></i> Закрытие тикета #<font id="mtocl"></font></h4>
</div>
<div class="modal-body with-padding">
<div class="alert alert-danger"><center>Внимание! Тикет будет закрыт.</center></div>
</div>
<div class="modal-footer">
<button type="button" id="ticket_close" class="btn btn-danger" data-loading-text="<i class='icon-spinner7 spin'></i> Закрываем">Закрыть</button>
<button type="button" class="btn btn-warning" data-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</div>

<div id="modal_ticket_del" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title"><i class="icon-remove"></i> Удаление тикета #<font id="mtodel"></font></h4>
</div>
<div class="modal-body with-padding">
<div class="alert alert-danger"><center>Внимание! Тикет будет удалён.</center></div>
</div>
<div class="modal-footer">
<button type="button" id="ticket_del" class="btn btn-danger" data-loading-text="<i class='icon-spinner7 spin'></i> Удаляем">Удалить</button>
<button type="button" class="btn btn-warning" data-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</div>

<script type="text/javascript">
//Предзакрытие тикета
var ticket_to_close;
function ticket_close(id){
ticket_to_close = id;
$('#mtocl').text(id);
$('#modal_ticket_close').modal('show');
};

//Закрытие тикета
$('#ticket_close').click(function(){
var data = {'id': ticket_to_close};
wu_response('/wu-engine/wu-actions/adm_ticket_close.php', data, 'ticket_close', '1', function(wu_result) {
if (wu_result == '1') {
$('.mc_'+ticket_to_close).hide('slow', function(){ $('.mc_'+ticket_to_close).remove(); if ($('#ticket_list').height() < 100) { $('#ticket_list').html('<div class="alert alert-info fade in"><i class="icon-info"></i> Нет <?php if (isset($_GET['type']) && $_GET['type'] == 'closed') { echo 'закрытых тикетов'; } else { echo 'обращений'; } ?></div>'); } });
$('#modal_ticket_close').modal('hide');
}
if (wu_result == '0') {
notif_e('Есть непрочитанные сообщения');
}
if (wu_result == '2') {
notif_e('Тикет уже закрыт');
}
if (wu_result == 'wu-error') {
wu_err();
}
});
});

//Предудаление тикета
var ticket_to_del;
function ticket_del(id){
ticket_to_del = id;
$('#mtodel').text(id);
$('#modal_ticket_del').modal('show');
};

//Удаление тикета
$('#ticket_del').click(function(){
var data = {'id': ticket_to_del};
wu_response('/wu-engine/wu-actions/adm_ticket_del.php', data, 'ticket_del', '1', function(wu_result) {
if (wu_result == '1') {
$('.mc_'+ticket_to_del).hide('slow', function(){ $('.mc_'+ticket_to_del).remove(); if ($('#ticket_list').height() < 100) { $('#ticket_list').html('<div class="alert alert-info fade in"><i class="icon-info"></i> Нет <?php if (isset($_GET['type']) && $_GET['type'] == 'closed') { echo 'закрытых тикетов'; } else { echo 'обращений'; } ?></div>'); } });
$('#modal_ticket_del').modal('hide');
}
if (wu_result == '0') {
notif_e('Есть непрочитанные сообщения');
}
if (wu_result == 'wu-error') {
wu_err();
}
});
});
</script>

<?php
$pageNav = new SimPageNav();
$pages = ceil($co/$num);
echo $pageNav->getLinks($pages, 1, $page, 10, 'page');
} else { if (isset($_GET['type']) && $_GET['type'] == 'closed') { $ticket_no = 'закрытых тикетов'; } else { $ticket_no = 'обращений'; } echo '<div class="alert alert-info fade in"><i class="icon-info"></i> Нет '.$ticket_no.'</div>'; } ?>

<link href="/wu-static/js/lightgallery/css/lightgallery.min.css" rel="stylesheet">
<script src="/wu-static/js/lightgallery/js/picturefill.min.js"></script>
<script src="/wu-static/js/lightgallery/js/lightgallery.min.js"></script>
<script src="/wu-static/js/lightgallery/js/lg-fullscreen.js"></script>
<script src="/wu-static/js/lightgallery/js/lg-thumbnail.js"></script>
<script src="/wu-static/js/lightgallery/js/lg-video.js"></script>
<script src="/wu-static/js/lightgallery/js/lg-autoplay.js"></script>
<script src="/wu-static/js/lightgallery/js/lg-zoom.js"></script>
<script src="/wu-static/js/lightgallery/js/lg-pager.js"></script>
<script src="/wu-static/js/lightgallery/js/jquery.mousewheel.min.js"></script>

<script src="/wu-static/js/bbeditor/jquery.wysibb.js"></script>
<script src="/wu-static/js/fileinput.js" type="text/javascript"></script>
<script src="/wu-static/js/fileinput_locale_ru.js" type="text/javascript"></script>
<script src="/wu-static/js/prettify.js"></script>

<script type="text/javascript">
$(document).ready(function() {
$("#msg_text").wysibb();
<?php if (isset($_GET['new'])) { echo "$('#ticket_new').modal('show');"; } ?>
});

//Смайлы
$('.smile-main .wu-smile').click(function(){
var smile_c = $(this).attr('class');
var smile_c_e = smile_c.replace(/wu-smile wu-/gi, '');
$('#msg_text').execCommand('wu_smile',{seltext: smile_c_e});
});
/* $('.smile-main .wu-smile').click(function(){
var smile_c = $(this).attr('class');
var smile_c_e = smile_c.replace(/wu-smile wu-/gi, '');
var $txt = jQuery("#msg_text");
var caretPos = $txt[0].selectionStart;
var textAreaTxt = $txt.val();
$txt.val(textAreaTxt.substring(0, caretPos) + ' :smile_' + smile_c_e + ': ' + textAreaTxt.substring(caretPos) );
}); */

//Вывод прикрелений
function handleFileSelectMulti(evt) {
var files = evt.target.files;
document.getElementById('wu-files-output').innerHTML = "";
for (var i = 0, f; f = files[i]; i++) {
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
var span = document.createElement('span');
if (theFile.type.match('image.*')) {
span.innerHTML = ['<div class="border-thumbnail-preview tip lightgallerys" data-placement="bottom" title="', theFile.name, '"><a href="', e.target.result, '"><img class="img-thumbnail-preview" src="', e.target.result, '" /></a></div>'].join('');
}
else
{
span.innerHTML = ['<span class="icon-thumbnail-preview tip" data-placement="bottom" title="', theFile.name, '"><i class="icon-file6 text-info"></i></span>'].join('');
}
document.getElementById('wu-files-output').insertBefore(span, null);
$('.lightgallerys').lightGallery();
$('.tip').tooltip();
};
})(f);
reader.readAsDataURL(f);
}
}
document.getElementById('wu-files').addEventListener('change', handleFileSelectMulti, false);

//Отправка нового тикета
$('#ticket_send').click(function(){
$("#msg_text").sync();
var data = new FormData($('#wu-form-send')[0]);
wu_response('/wu-engine/wu-actions/adm_ticket_new.php', data, 'ticket_send', '2', function(wu_result) {
if (wu_result == '0') {
notif_e('Не заполнены все необходимые поля');
}
if (wu_result == '1') {
$(location).attr('href','/<?php echo ADMINPATH; ?>/support');
}
if (wu_result == '2') {
notif_e('Пользователь не найден');
}
if (wu_result == '4') {
notif_e('Разрешённые форматы - gif, jpg, png, jpeg, doc, docx, rtf, rar, zip, 7z, pdf, ppt, pptx, txt, css');
}
if (wu_result == 'wu-error') {
wu_err();
}
});
});
</script>

<?php } else {
include('../wu-engine/wu-functions/wu_functions.php');
include('../wu-engine/wu-functions/bbdecoder/Parser.php');

//Онлайн
$onl = mysqli_num_rows(mysqli_query($connect_db, "SELECT id FROM `".DB_PREFIX."_online` WHERE usr='$now_ticket[usr]' LIMIT 1"));

//Создание аватаров
$ava_link_thumb_u = '/wu-static/img/avatar_default_adm.png'; $ava_link_full_u = '/wu-static/img/avatar_default_adm.png';
if (empty($now_ticket['av'])) { $ava_link_thumb_my = '/wu-static/img/avatar_default.png'; $ava_link_full_my = '/wu-static/img/avatar_default.png'; } else { $ava_link_thumb_my = '/wu-uploads/avatars/thumbs/'.$now_ticket['av']; $ava_link_full_my = '/wu-uploads/avatars/full/'.$now_ticket['av']; }

//Запуск парсера
$parser = new JBBCode\Parser();
$parser->addCodeDefinitionSet(new JBBCode\DefaultCodeDefinitionSet());
?>
<div class="block">
<div class="chat-member-heading clearfix">
<h6 class="pull-left"><i class="icon-bubble6"></i> <?php echo htmlspecialchars($now_ticket['th']); ?> <small>&nbsp;/&nbsp; Пользователь <?php echo $now_ticket['log'].' '; if ($onl == 0) { echo 'офлайн'; } else { echo 'онлайн'; } ?></small></h6>
</div>
<div class="chat" id="chat" style="padding: 10px 0;">
<?php
//Вывод сообщений
$qm = mysqli_query($connect_db, "SELECT * from (SELECT id,msg,files,frm,bb,sm,dt FROM `".DB_PREFIX."_tickets_msg` WHERE tid = '$ticket' ORDER BY id DESC) AS te ORDER BY te.id ASC");
$qh = mysqli_num_rows($qm);
if ($qh > 0) {
mysqli_query($connect_db, "UPDATE `".DB_PREFIX."_tickets_main` SET new_a = '0' WHERE id='$ticket' AND new_a = '1' LIMIT 1");
while($row = mysqli_fetch_assoc($qm)) {

//Вывод прикреплений
if (!empty($row['files'])) {
$images = array('gif','jpg', 'png', 'jpeg');
$files_e = '';
$files = explode('|', $row['files']);
foreach ($files as $file) {
$expl = explode(':', $file);
$ifile = $expl[0];
$iname = $expl[1];
$exp = explode('.', $ifile);
$exp_e = strtolower($exp[1]);
if (!empty($file)){
if (in_array($exp_e, $images)) {
$files_e .= '<div class="border-thumbnail-preview tip lightgallerys" data-placement="bottom" title="'.$iname.'"><a href="/wu-uploads/attach/full/'.$ifile.'"><img class="img-thumbnail-preview" src="/wu-uploads/attach/thumbs/'.$ifile.'" alt="'.$iname.'" /></a></div>';
} else {
if ($row['frm'] == 1) { $txti = ''; } else { $txti = ' text-info'; }
$files_e .= '<a href="/wu-engine/wu-actions/attach_download/'.strrev(base64_encode($ifile.'|'.$iname)).'" class="icon-thumbnail-preview tip" data-placement="bottom" title="'.$iname.'"><i class="icon-file6'.$txti.'"></i></a>';
}
}
}
} else { $files_e = ''; }
?>
<div class="mc_<?php echo $row['id']; ?> message<?php if ($row['frm'] == 0) { echo ' reversed'; } ?>" id="m_<?php echo $row['id']; ?>">
<div class="lightgallerys <?php if ($row['frm'] == 1) { echo 'flleft'; } else { echo 'flright'; } ?>">
<a href="<?php if ($row['frm'] == 0) { echo $ava_link_full_my; } else { echo $ava_link_full_u; } ?>"><img src="<?php if ($row['frm'] == 0) { echo $ava_link_thumb_my; } else { echo $ava_link_thumb_u; } ?>" class="media-object" /></a>
</div>
<div class="message-body<?php if ($row['frm'] == 1) { echo ' msg-link'; } ?>">
<?php
$parser->parse(htmlentities($row['msg']));
$parsered = $parser->getAsHtml();
echo wu_smile(nl2br($parsered));
if (!empty($row['files'])) {
if (!empty($row['msg'])) { echo '<br />'; }
echo '<div>Прикреплённые файлы:<br />'.$files_e.'</div>';
}
?>
<span class="attribution"><?php echo wudatenorm($row['dt']); echo '<i class="icon-pencil msg_control" onclick="msg_edit(\''.$row['id'].'\');"></i><i class="icon-remove msg_control" onclick="msg_del(\''.$row['id'].'\');"></i>'; ?></span>
</div>
</div>
<?php
}
} else { echo '<div class="alert alert-info fade in msgnone" id="m_0"><i class="icon-info"></i> Нет сообщений</div>'; }
?>
</div>

<form class="form-horizontal" role="form" method="post" id="wu-form-send">
<input type="hidden" name="to" value="<?php echo $ticket; ?>" />
<input type="hidden" name="token" value="<?php echo $token; ?>" />
<textarea name="msg_text" class="form-control" rows="3" cols="1" placeholder="Текст сообщения" id="msg_text"></textarea>
<div class="message-controls">
<center>
<div id="wu-files-output" class="margload"></div>
<input type="file" id="wu-files" name="wu-files[]" multiple="" class="dnone" />
<label for="wu-files" class="btn btn-default btn-icon"><i class="icon-attachment"></i></label>
<div class="btn-group">
<button data-toggle="dropdown" data-play="bounceIn" class="btn btn-default btn-icon dropdown-toggle"><i class="icon-smiley"></i></button>
<ul class="dropdown-menu" style="width: 280px;">
<li></li>
<li>
<div class="emogiblc smile-main"><div class="webupper_smile"><div><i class="wu-smile wu-1"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-2"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-3"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-4"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-5"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-6"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-7"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-8"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-9"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-10"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-11"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-12"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-13"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-14"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-15"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-16"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-17"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-18"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-19"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-20"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-21"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-22"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-23"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-24"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-25"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-26"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-27"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-28"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-29"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-30"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-31"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-32"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-33"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-34"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-35"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-36"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-37"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-38"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-39"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-40"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-41"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-42"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-43"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-44"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-45"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-46"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-47"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-48"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-49"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-50"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-51"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-52"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-53"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-54"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-55"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-56"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-57"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-58"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-59"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-60"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-61"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-62"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-63"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-64"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-65"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-66"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-67"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-68"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-69"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-70"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-71"></i></div></div><div class="wu-smile-clear"></div></div>
</li>
</ul>
</div>
<button type="button" id="msg_submit" class="btn btn-default" data-loading-text="<i class='icon-spinner7 spin'></i> Отправляем">Отправить сообщение</button>
<br />
<div class="checkbox">
<label>
<input type="checkbox" class="styled" id="audio_on">
Звуковые оповещения
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" class="styled" id="enter_on">
Отправка клавишей Enter
</label>
</div>
</center>
</div>
</form>
</div>

<br />
<audio id="msg_sound" style="display:none" controls preload="auto">
<source src="/wu-static/audio/msg.mp3" controls></source>
<source src="/wu-static/audio/msg.ogg" controls></source>
</audio>

<div id="modal_msg_del" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title"><i class="icon-remove"></i> Удаление сообщения #<font id="mtodel"></font></h4>
</div>
<div class="modal-body with-padding">
<div class="alert alert-danger"><center>Внимание! Сообщение будет удалено.</center></div>
</div>
<div class="modal-footer">
<button type="button" id="msg_del" class="btn btn-danger" data-loading-text="<i class='icon-spinner7 spin'></i> Удаляем">Удалить</button>
<button type="button" class="btn btn-warning" data-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</div>

<div id="modal_msg_edit" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title"><i class="icon-pencil"></i> Редактирование сообщения #<font id="mtoedit"></font></h4>
</div>
<div class="modal-body with-padding">
<textarea class="form-control" rows="3" cols="1" placeholder="Текст сообщения" id="msg_text_edit"></textarea>
</div>
<div class="modal-footer">
<div class="btn-group">
<button data-toggle="dropdown" data-play="bounceIn" class="btn btn-default btn-icon dropdown-toggle"><i class="icon-smiley"></i></button>
<ul class="dropdown-menu" style="width: 280px;">
<li></li>
<li>
<div class="emogiblc"><div class="webupper_smile"><div><i class="wu-smile wu-1"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-2"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-3"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-4"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-5"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-6"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-7"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-8"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-9"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-10"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-11"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-12"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-13"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-14"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-15"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-16"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-17"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-18"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-19"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-20"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-21"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-22"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-23"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-24"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-25"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-26"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-27"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-28"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-29"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-30"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-31"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-32"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-33"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-34"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-35"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-36"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-37"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-38"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-39"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-40"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-41"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-42"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-43"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-44"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-45"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-46"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-47"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-48"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-49"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-50"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-51"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-52"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-53"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-54"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-55"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-56"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-57"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-58"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-59"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-60"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-61"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-62"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-63"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-64"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-65"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-66"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-67"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-68"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-69"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-70"></i></div></div><div class="webupper_smile"><div><i class="wu-smile wu-71"></i></div></div><div class="wu-smile-clear"></div></div>
</li>
</ul>
</div>
<button type="button" id="msg_edit" class="btn btn-success margl_5" data-loading-text="<i class='icon-spinner7 spin'></i> Сохраняем">Сохранить</button>
<button type="button" class="btn btn-warning" data-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</div>

<link href="/wu-static/js/lightgallery/css/lightgallery.min.css" rel="stylesheet">
<script src="/wu-static/js/lightgallery/js/picturefill.min.js"></script>
<script src="/wu-static/js/lightgallery/js/lightgallery.min.js"></script>
<script src="/wu-static/js/lightgallery/js/lg-fullscreen.js"></script>
<script src="/wu-static/js/lightgallery/js/lg-thumbnail.js"></script>
<script src="/wu-static/js/lightgallery/js/lg-video.js"></script>
<script src="/wu-static/js/lightgallery/js/lg-autoplay.js"></script>
<script src="/wu-static/js/lightgallery/js/lg-zoom.js"></script>
<script src="/wu-static/js/lightgallery/js/lg-pager.js"></script>
<script src="/wu-static/js/lightgallery/js/jquery.mousewheel.min.js"></script>

<script src="/wu-static/js/bbeditor/jquery.wysibb.js"></script>
<script src="/wu-static/js/fileinput.js" type="text/javascript"></script>
<script src="/wu-static/js/fileinput_locale_ru.js" type="text/javascript"></script>
<script src="/wu-static/js/prettify.js"></script>

<script type="text/javascript">
//Скролл вниз
window.onload = function(){
window.scrollTo(0, 999999999999999);
var block = document.getElementById("chat");
block.scrollTop = block.scrollHeight;
}

$(document).ready(function() {
$("#msg_text").wysibb();
$('#msg_text_edit').wysibb();
PR.prettyPrint();
$(".lightgallerys").lightGallery();
});

//Настройки чекбоксов
var msg_audio = 1;
var msg_enter = 1;
$(document).ready(function(){
if ($.cookie('audio_on')) {
if ($.cookie('audio_on') == 1) {
msg_audio = 1;
$("#audio_on").attr("checked","checked");
}
if ($.cookie('audio_on') == 0) {
msg_audio = 0;
}
} else {
msg_audio = 1;
$("#audio_on").attr("checked","checked");
}
if ($.cookie('enter_on')) {
if ($.cookie('enter_on') == 1) {
msg_enter = 1;
$("#enter_on").attr("checked","checked");
}
if ($.cookie('enter_on') == 0) {
msg_enter = 0;
}
} else {
msg_enter = 1;
$("#enter_on").attr("checked","checked");
}
});

$(function() {
var btnn = $('#audio_on');
btnn.click(function(){
var ison = btnn.prop('checked');
if (ison == true) {
msg_audio = 1;
$.cookie('audio_on', '1');
}
if (ison == false) {
msg_audio = 0;
$.cookie('audio_on', '0');
}
});
var btne = $('#enter_on');
btne.click(function(){
var isone = btne.prop('checked');
if (isone == true) {
msg_enter = 1;
$.cookie('enter_on', '1');
}
if (isone == false) {
msg_enter = 0;
$.cookie('enter_on', '0');
}
});

//Отправка сообщения
function msg_send(){
$("#msg_text").sync();
var data = new FormData($('#wu-form-send')[0]);
wu_response('/wu-engine/wu-actions/adm_ticket_send.php', data, 'msg_submit', '2', function(wu_result) {
if (wu_result == '0') {
notif_e('Вы не ввели сообщение');
}
if (wu_result == '1') {
$('#wu-files').val('');
$('#wu-files-output').text('');
$('#msg_text').val('');
$('.wysibb-text-editor').text('');
msg_load();
}
if (wu_result == '2') {
notif_e('Тикет не найден');
}
if (wu_result == '4') {
notif_e('Разрешённые форматы - gif, jpg, png, jpeg, doc, docx, rtf, rar, zip, 7z, pdf, ppt, pptx, txt, css');
}
if (wu_result == 'wu-error') {
wu_err();
}
});
}

//Отправка сообщения при нажатии на кнопку
var btns = $('#msg_submit');
btns.click(function() {
msg_send();
});

//Отправка сообщения при нажатии на Enter
$("#wu-form-send #msg_text, #wu-form-send .wysibb-text-editor").keydown(function(event) {
if (event.keyCode == 13 || event.charCode == 13) {
if (msg_enter == 1) {
msg_send();
return false;
}
}
});
});

//Проверка новых сообщений
function msg_last(){
var last = $('#chat').children().last().attr('id');
var data = {'id': '<?php echo $ticket; ?>', 'last': last};
wu_response('/wu-engine/wu-actions/adm_ticket_last.php', data, '', '1', function(wu_result) {
if (wu_result == '1') {
msg_load();
if (msg_audio == 1) {
var msg_sound = $("#msg_sound")[0];
msg_sound.pause();
msg_sound.play();
}
}
});
};

//Загрузка новых сообщений
function msg_load(){
var last = $('#chat').children().last().attr('id');
var data = {'id': '<?php echo $ticket; ?>', 'last': last};
wu_response('/wu-engine/wu-actions/adm_ticket_load.php', data, '', '1', function(wu_result) {
if (wu_result == 'wu-error') {
} else {
$('.msgnone').hide('');
var tobottom = 0;
var block = document.getElementById("chat");
if (block.scrollHeight - block.scrollTop === block.clientHeight) {
tobottom = 1;
}
$('#chat').append(wu_result);
PR.prettyPrint();
$('.tip').tooltip();
$(".lightgallerys").lightGallery();
if (tobottom === 1) { block.scrollTop = block.scrollHeight; }
$('#chat [id]').each(function() {
var idAttr = $(this).attr('id'),
selector = '[id=' + idAttr + ']';
if ($(selector).length > 1) {
$(selector).not(':first').remove();  
}
});
}
});
};
setInterval(function() {
msg_last();
}, 5000);

//Смайлы
$('.smile-main .wu-smile').click(function(){
var smile_c = $(this).attr('class');
var smile_c_e = smile_c.replace(/wu-smile wu-/gi, '');
$('#msg_text').execCommand('wu_smile',{seltext: smile_c_e});
});
$('#modal_msg_edit .wu-smile').click(function(){
var smile_c = $(this).attr('class');
var smile_c_e = smile_c.replace(/wu-smile wu-/gi, '');
$('#msg_text_edit').execCommand('wu_smile',{seltext: smile_c_e});
});

/* $('.smile-main .wu-smile').click(function(){
var smile_c = $(this).attr('class');
var smile_c_e = smile_c.replace(/wu-smile wu-/gi, '');
var $txt = jQuery("#msg_text");
var caretPos = $txt[0].selectionStart;
var textAreaTxt = $txt.val();
$txt.val(textAreaTxt.substring(0, caretPos) + ' :smile_' + smile_c_e + ': ' + textAreaTxt.substring(caretPos) );
}); */

//Вывод прикрелений
function handleFileSelectMulti(evt) {
var files = evt.target.files;
document.getElementById('wu-files-output').innerHTML = "";
for (var i = 0, f; f = files[i]; i++) {
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
var span = document.createElement('span');
if (theFile.type.match('image.*')) {
span.innerHTML = ['<div class="border-thumbnail-preview tip lightgallerys" data-placement="bottom" title="', theFile.name, '"><a href="', e.target.result, '"><img class="img-thumbnail-preview" src="', e.target.result, '" /></a></div>'].join('');
}
else
{
span.innerHTML = ['<span class="icon-thumbnail-preview tip" data-placement="bottom" title="', theFile.name, '"><i class="icon-file6 text-info"></i></span>'].join('');
}
document.getElementById('wu-files-output').insertBefore(span, null);
$('.lightgallerys').lightGallery();
$('.tip').tooltip();
};
})(f);
reader.readAsDataURL(f);
}
}
document.getElementById('wu-files').addEventListener('change', handleFileSelectMulti, false);

//Предудаление сообщения
var msg_to_del;
function msg_del(id){
msg_to_del = id;
$('#mtodel').text(id);
$('#modal_msg_del').modal('show');
};

//Удаление сообщения
$('#msg_del').click(function(){
var data = {'id': msg_to_del};
wu_response('/wu-engine/wu-actions/adm_ticket_message_del.php', data, 'msg_del', '1', function(wu_result) {
if (wu_result == '1') {
$('.mc_'+msg_to_del).hide('slow', function(){ $('.mc_'+msg_to_del).remove(); if ($('#chat').height() < 50) { $('#chat').html('<div class="alert alert-info fade in msgnone" id="m_1"><i class="icon-info"></i> Нет сообщений</div>'); } });
$('#modal_msg_del').modal('hide');
}
if (wu_result == 'wu-error') {
wu_err();
}
});
});

//Загрузка сообщения для редактирования
var msg_to_edit;
function msg_edit(id){
msg_to_edit = id;
$('#mtoedit').text(id);
var data = {'id': id};
wu_response('/wu-engine/wu-actions/adm_ticket_message_load_to_edit.php', data, '', '1', function(wu_result) {
if (wu_result == 'wu-err-3') {
wu_err();
} else {
$("#msg_text_edit").bbcode(wu_result);
$("#msg_text_edit").htmlcode($('#msg_text_edit').getHTMLfrom(wu_result));
$('#modal_msg_edit').modal('show');
$('#modal_msg_edit').removeAttr("tabindex");
}
});
};

//Редактирование сообщения
$('#msg_edit').click(function(){
$("#msg_text_edit").sync();
var msg = $('#msg_text_edit').val();
var data = {'id': msg_to_edit, 'msg_text_edit': msg};
wu_response('/wu-engine/wu-actions/adm_ticket_message_edit.php', data, 'msg_edit', '1', function(wu_result) {
if (wu_result == 'res-wu-err-msg') {
notif_e('Вы не ввели сообщение');
} else if (wu_result == 'res-wu-error') {
wu_err();
} else {
$('.mc_'+msg_to_edit+' .message-body').html(wu_result);
PR.prettyPrint();
$('.tip').tooltip();
$(".lightgallerys").lightGallery();
$('#modal_msg_edit').modal('hide');
}
});
});
</script>
<?php } ?>

<?php include('../wu-engine/wu_footer.php'); ?>