Просмотр файла account/messages.php

Размер файла: 34.94Kb
<?php
if(isset($_GET['usr'])) {
require_once('../wu-engine/wu_init.php');
$usr = intval($_GET['usr']);
$isusr = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT uid FROM `".DB_PREFIX."_users` WHERE uid='$usr' LIMIT 1"));
if (empty($isusr['uid']) || $isusr['uid'] == 0) {
$wie = explode('.php/', $_GET['usr']); wu_log_act(2, 'Пытался открыть не существующий диалог с uid '.wu_filter($wie['0']));
header ("Location: /account/messages"); exit;
}
$page_name = 'Просмотр диалога';
$page_keys = 'диалог';
$page_desc = 'Просмотр диалога с пользователем системы';
$prevurl_1 = '/account/messages';
$prevname_1 = 'Сообщения';
} else {
$page_name = 'Сообщения';
$page_keys = 'сообщения';
$page_desc = 'Ваши сообщения';
}
$online_title = 'На странице личных сообщений';
$online_url = '/account/messages';
$page_right = '<div class="header-buttons"><div class="collapse" id="header-buttons"><div class="well"><a data-toggle="modal" role="button" href="#write" class="btn btn-primary">Написать пользователю</a></div></div></div>';
include('../wu-engine/wu_header.php');
include('../wu-engine/wu_account_menu.php');
if(!USER_LOGGED) { header ("Location: /"); exit; }
?>

<div id="write" 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-pencil4"></i> Написать пользователю</h4>
</div>
<div class="modal-body with-padding">
<center><input id="wr" type="text" required="required" placeholder="Ник пользоателя" autocomplete="off" class="form-control" style="width:70%; margin: 20px 0px 20px 0px;" /></center>
</div>
<div class="modal-footer">
<a class="btn btn-success" href="javascript://" id="gowr">Написать</a>
<button class="btn btn-warning" data-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</div>

<script type="text/javascript">
//Автозаполнение
$(function() {
$("#wr").autocomplete({
source: "/wu-engine/wu-actions/acc_message_load_users.php",
minLength: 2
});
});

//Переход к диалогу
$('#gowr').click(function() {
if ($('#wr').val().length > 0) {
var to = $('#wr').val();
$(location).attr('href','/wu-engine/wu-actions/acc_message_write.php?usr='+to);
} else {
notif_e('Введите логин пользователя');
}
});
</script>

<?php
//Список диалогов
if(!isset($_GET['usr'])) {

//Подключаем парсер, пагинацию и смайлы
require_once('../wu-engine/wu-functions/wu_pagination.php');
require_once('../wu-engine/wu-functions/wu_functions.php');
require_once('../wu-engine/wu-functions/bbdecoder/Parser.php');
$parser = new JBBCode\Parser();
$parser->addCodeDefinitionSet(new JBBCode\DefaultCodeDefinitionSet());

if (isset($_GET['st']) && $_GET['st'] == 'not') { echo '<div class="alert alert-info fade in" style="margin-bottom:20px"><button type="button" class="close" data-dismiss="alert">×</button><i class="icon-info"></i> Пользователь с таким логином не найден</div>'; }

$num = 20; //Сколько выводить на странице
if (isset($_GET['page'])) { $page = intval($_GET['page']); if ($page == 0) { $page = 1; } } else { $page = 1; }
$co = mysqli_num_rows(mysqli_query($connect_db, "SELECT id FROM ( SELECT id, `fr` AS fr, `tou` AS wi, `msg`, `files`, 0 AS `new`, `dt` FROM ".DB_PREFIX."_messages AS m1 WHERE `fr` = '$u_id' UNION SELECT id, `tou` AS wi, `fr` AS wi, `msg`, `files`, `new`, `dt` FROM ".DB_PREFIX."_messages AS m2 WHERE `tou` = '$u_id' ORDER BY `id` DESC ) AS msg_o GROUP BY `wi`"));
$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 id,wi,msg,files,new,dt,log,av FROM ( SELECT id, `fr` AS fr, `tou` AS wi, `msg`, `files`, 0 AS `new`, `dt` FROM ".DB_PREFIX."_messages AS m1 WHERE `fr` = '$u_id' UNION SELECT id, `tou` AS wi, `fr` AS wi, `msg`, `files`, `new`, `dt` FROM ".DB_PREFIX."_messages AS m2 WHERE `tou` = '$u_id' ORDER BY `id` DESC ) AS msg_o INNER JOIN ".DB_PREFIX."_users ON msg_o.wi = ".DB_PREFIX."_users.uid GROUP BY `wi` ORDER BY `dt` DESC LIMIT $start, $num");
$ht = mysqli_num_rows($qt);
if ($ht > 0) {
?>
<div class="block">
<ul class="message-list">
<?php while($row = mysqli_fetch_assoc($qt)) {
if (empty($row['av'])) { $ava_link_thumb = '/wu-static/img/avatar_default.png'; } else { $ava_link_thumb = '/wu-uploads/avatars/thumbs/'.$row['av']; }
$onl = mysqli_num_rows(mysqli_query($connect_db, "SELECT id FROM ".DB_PREFIX."_online WHERE usr='$row[wi]' LIMIT 1"));
?>
<li class="mc_<?php echo $row['wi']; ?>">
<div class="clearfix chat-usr-msg">
<div class="chat-member" onclick="location.href = '/account/messages/<?php echo $row['wi']; ?>'">
<a class="img40"><img src="<?php echo $ava_link_thumb; ?>" alt="Аватар пользователя <?php echo $row['log']; ?>" /></a>
<h6><?php echo $row['log']; ?> <span data-placement="bottom" class="status status-<?php if ($onl == 0) { echo 'default tip" data-original-title="Пользователь не в сети'; } else { echo 'success tip" data-original-title="Пользователь онлайн'; } ?>"></span> <small<?php if ($row['new'] == 1) { echo ' style="color: #000000;"'; } ?>>&nbsp;
<?php
//Вывод сообщения
$parser->parse(htmlentities($row['msg']));
$etext = strip_tags($parser->getAsHtml());
if (strlen($etext) >= 300) {
$etext = substr($etext, 0, 300);
$etext = rtrim($etext, "!,.-");
$etext = substr($etext, 0, strrpos($etext, ' '));
$etext = $etext.'...';
}
echo wu_smile($etext);

//Вывод прикреплений
if (empty($etext) && !empty($row['files'])) {
$files_e = '';
$files = explode('|', $row['files']);
foreach ($files as $file) {
$expl = explode(':', $file);
$iname = $expl[1];
if (!empty($file)){
$files_e .= $iname.', ';
}
}
$files_e = substr($files_e,0,-2);
echo "Прикреплённые файлы: $files_e";
}
?></small></h6>
</div>
<div class="chat-actions">
<a href="javascript://" onclick="msg_del('<?php echo $row['wi']; ?>','<?php echo $row['log']; ?>');" class="btn btn-link btn-icon ibtnh"><i class="icon-remove"></i></a>
</div>
</div>
</li>
<?php } ?>
</ul>
</div>

<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>

<script type="text/javascript">
//Предудаление диалога
var msg_to_del;
function msg_del(id,log){
msg_to_del = id;
$('#mtodel').text(log);
$('#modal_msg_del').modal('show');
};

//Удаление диалога
$('#msg_del').click(function(){
var data = {'id': msg_to_del};
wu_response('/wu-engine/wu-actions/acc_message_del_all.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 ($('.message-list').height() < 50) { $('.message-list').html('<div class="alert alert-info fade in"><i class="icon-info"></i> У Вас пока что нет диалогов с пользователями</div>'); } });
$('#modal_msg_del').modal('hide');
}
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 { echo '<div class="alert alert-info fade in"><i class="icon-info"></i> У Вас пока что нет диалогов с пользователями</div>'; } ?>
<?php } else {
require_once('../wu-engine/wu-functions/wu_functions.php');
require_once('../wu-engine/wu-functions/bbdecoder/Parser.php');

//Список сообщений
$nlog = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT uid,log,av FROM ".DB_PREFIX."_users WHERE uid='$usr' LIMIT 1"));
$onl = mysqli_num_rows(mysqli_query($connect_db, "SELECT id FROM ".DB_PREFIX."_online WHERE usr='$usr' LIMIT 1"));

//Создание аватаров
if (empty($nlog['av'])) { $ava_link_thumb_u = '/wu-static/img/avatar_default.png'; $ava_link_full_u = '/wu-static/img/avatar_default.png'; } else { $ava_link_thumb_u = '/wu-uploads/avatars/thumbs/'.$nlog['av']; $ava_link_full_u = '/wu-uploads/avatars/full/'.$nlog['av']; }
if (empty($nowuser['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/'.$nowuser['av']; $ava_link_full_my = '/wu-uploads/avatars/full/'.$nowuser['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 $nlog['log']; ?> <small>&nbsp;/&nbsp; <?php 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,fr,msg,files,dt FROM ".DB_PREFIX."_messages WHERE (`fr` = '$u_id' AND `tou` = '$usr') OR (`fr` = '$usr' AND `tou` = '$u_id') 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."_messages SET new = '0' WHERE fr='$usr' AND tou='$u_id' AND new = '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['fr'] == $u_id) { $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['fr'] != $u_id) { echo ' reversed'; } ?>" id="m_<?php echo $row['id']; ?>">
<div class="lightgallerys <?php if ($row['fr'] == $u_id) { echo 'flleft'; } else { echo 'flright'; } ?>">
<a href="<?php if ($row['fr'] == $u_id) { echo $ava_link_full_my; } else { echo $ava_link_full_u; } ?>"><img src="<?php if ($row['fr'] == $u_id) { echo $ava_link_thumb_my; } else { echo $ava_link_thumb_u; } ?>" class="media-object" /></a>
</div>
<div class="message-body<?php if ($row['fr'] == $u_id) { 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']); ?><?php if ($row['fr'] == $u_id) { 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_1"><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 $usr; ?>" />
<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/acc_message_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 = {'usr': '<?php echo $usr; ?>', 'last': last};
wu_response('/wu-engine/wu-actions/acc_message_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 = {'usr': '<?php echo $usr; ?>', 'av': '<?php echo $nlog['av']; ?>', 'last': last};
wu_response('/wu-engine/wu-actions/acc_message_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/acc_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/acc_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/acc_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'); ?>