Файл: forum/includes/showtopic.php
Строк: 260
<?php
# Script by seg0ro http://mobilarts.ru
# Not for sale!!!
defined('_IN_JOHNCMS') or die('Error: restricted access');
if ($user_id){
$lastPost = explode(':|:', $topicRes['lastpost']);
$readedReq = mysql_query("SELECT * FROM `forum_readed` WHERE `topic` = '$topic' AND `user_id` = '$user_id' LIMIT 1 ");
if (mysql_num_rows($readedReq) > 0){
$readedRes = mysql_fetch_assoc($readedReq);
if ($topicRes['time'] > $readedRes['time'] || $readedRes['page'] != $page)
mysql_query("UPDATE `forum_readed` SET `time` = '".time()."', `lastpost` = '".$lastPost['1']."' WHERE `topic` = '$topic' AND `user_id` = '$user_id' ");
}else{
mysql_query("INSERT INTO `forum_readed` SET `topic` = '$topic', `user_id` = '$user_id', `time` = '".time()."', `lastpost` = '".$lastPost['1']."' ");
}
}
echo forum_counter();
$tree = array('<a href="index.php">Форум</a>', '<a href="index.php?forum='.$topicRes['forum'].'">'.functions::checkout($topicRefid['forumname']).'</a>', functions::checkout($topicRes['topicname']));
echo '<div name="up" id="up" class="phdr"><a href="#down"><img src="../images/down.png" alt="Вниз" width="20" height="10" border="0"/></a> '.functions::display_menu($tree).'</div>';
if ($topicRes['close'])
echo '<div class="rmenu">Тема закрыта!</div>';
if ($topicRes['poll_name']){
if ($user_id)
$pollCheck = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_polled` WHERE `topic` = '$topic' AND `user_id` = '$user_id' LIMIT 1 "), 0);
echo '<div class="gmenu"><strong>'.functions::checkout($topicRes['poll_name']).'</strong><br />';
if (!$pollSet['poll_close'] && !isset($_GET['results']) && $user_id && $pollCheck == 0 && !$topicRes['close']){
echo '<form action="index.php?act=poll&topic='.$topic.'&page='.$page.'" method="post">';
while ($pollRes = mysql_fetch_assoc($pollReq)){
echo '<label><input type="'.($pollSet['poll_mod'] < 1 ? 'radio' : 'checkbox').'" name="var[]" value="'.$pollRes['id'].'" /> '.functions::checkout($pollRes['variantname']).'</label><br />';
}
echo '<input type="submit" name="poll" value="Отдать голос" /><br /><a href="index.php?topic='.$topic.'&page='.$page.'&results"><strong>Результаты</strong></a></form>';
}else{
echo '<style type="text/css">
.scale {
border: 1px solid #636869;
height: 5px;
margin-bottom: 3px;
width: 1%;
}
.scaleborder {
width: 70%;
}</style>';
echo '<small>';
while ($pollRes = mysql_fetch_assoc($pollReq)){
$count = $pollSet['total_polls'] ? round(100 / $pollSet['total_polls'] * $pollRes['count']) : 0;
if ($count < 30 || $count == 0)
$color = '#fe5429';
elseif($count < 60)
$color = '#fc8b30';
else
$color = '#7cca35';
echo functions::checkout($pollRes['variantname']).' ('.$pollRes['count'].' - '.$count.'%)<div class="scaleborder"><div class="scale" style="'.($count ? 'width: '.$count.'%;' : '').' background: '.$color.'"></div></div>';
}
echo '</small><strong>Проголосовало: '.($user_id ? '<a href="index.php?act=polled&topic='.$topic.'">'.$pollSet['total_polled'].'</a>' : $pollSet['total_polled']).'</strong>';
if ($user_id && !$pollCheck && !$pollSet['poll_close'])
echo '<br /><a href="index.php?topic='.$topic.'&page='.$page.'"><strong>Отдать голос</strong></a>';
}
echo '</div>';
}
$total = $topicRes['count'];
if ($start >= $total){
// Исправляем запрос на несуществующую страницу
$start = max(0, $total - (($total % $kmess) == 0 ? $kmess : ($total % $kmess)));
}
if ($total){
if ($total > $kmess)
echo '<div class="topmenu">'.functions::display_pagination('index.php?topic='.$topic.'&', $start, $total, $kmess).'</div>';
if ($set_forum['upfp']){
if (($user_id && !$ban['1'] && !$ban['11'] && !$topicRes['close']) || ($rights == 3 || $rights >= 6)){
echo '<form id="form" name="form" action="index.php?act=addpost&topic='.$topic.'&page='.$page.'" method="post"><div class="gmenu">';
if ($set_forum['farea']){
echo 'Быстрый ответ <img style="cursor: pointer;" onclick="alert(this.title);" src="images/question.png" alt="?" title="Для предпросмотра или прикрепления файлов нажмите на кнопку: Расшир. форма" />:<br />'.bbcode::auto_bb('form', 'text').'<textarea name="text" cols="30" rows="'.$set_user['field_h'].'"></textarea>';
echo '<br /><input type="submit" name="send" value="Отправить" /> <input type="submit" name="preview" value="Расшир. форма" />';
}else{
echo '<input type="submit" value="Написать" />';
}
echo '</div></form>';
}
}
if ($topicRes['clip'] && ($set_forum['upfp'] ? $start < (ceil($total - $kmess)) : $start > 0)){
echo '<div class="user">';
$firstPost = mysql_fetch_array(mysql_query("SELECT `forum_posts`.*, `forum_posts`.`user` AS `name`, `forum_posts`.`user_id` AS `id`, `users`.`sex`, `users`.`name`, `users`.`rights`, `users`.`lastdate`, `users`.`status`, `users`.`datereg` FROM `forum_posts` LEFT JOIN `users` ON `forum_posts`.`user_id` = `users`.`id` WHERE `forum_posts`.`topic` = '$topic' ORDER BY `forum_posts`.`time` ASC LIMIT 1 "));
$postHeader .= ' <span class="gray">'.functions::display_date($firstPost['time']).'</span> <a href="index.php?post='.$firstPost['post'].'" title="Ссылка на пост">#1</a>';
$postText = quote(functions::checkout($firstPost['text'], 1, 1));
if ($set_user['smileys'])
$postText = functions::smileys($postText, $firstPost['rights'] >= 1 ? 1 : 0);
if ($firstPost['files']){
$postFile = mysql_query("SELECT * FROM `forum_files` WHERE `post` = '".$firstPost['post']."' LIMIT ".$firstPost['files']." ");
$postText .= '<div class="func">Файл(ы):<br />';
while ($postFileRes = mysql_fetch_array($postFile)){
$postText .= show_file($postFileRes).'<br />';
}
$postText .= '</div>';
}
if ($firstPost['edit']){
$edit = explode(':|:', $firstPost['edit']);
$postText .= '<div style="font-size: x-small; color: gray">Изменил(а) '.$edit['0'].' '.functions::display_date($edit['1']).($edit['2'] ? '<br />Причина: '.functions::checkout($edit['2'], 2) : '').'</div>';
}
if ($firstPost['rating'] > 0) $color = 'C0FFC0';
elseif ($firstPost['rating'] < 0) $color = 'F196A8';
else $color = 'CCCCCC';
if ($user_id && $firstPost['user_id'] != $user_id){
$postText .= '<div style="font-size: x-small; margin-top: 7px;">Рейтинг: <a href="index.php?act=rating&topic='.$topic.'&post='.$firstPost['post'].'&minus"><img src="images/minus.png" alt="-" /></a> <span style="background:#'.$color.'"> '.$firstPost['rating'].' </span> <a href="index.php?act=rating&topic='.$topic.'&post='.$firstPost['post'].'&plus"><img src="images/plus.png" alt="+" /></a></div>';
}else{
$postText .= '<div style="font-size: x-small; margin-top: 7px;">Рейтинг: <span style="background:#'.$color.'"> '.$firstPost['rating'].' </span></div>';
}
$postSub = '';
if ((($user_id == $firstPost['user_id']) && !$topicRes['close'] && (!$ban['1'] || !$ban['11'])) || ($rights == 3 || $rights >= 6)){
$postSub .= '<a href="index.php?act=editpost&topic='.$topic.'&post='.$firstPost['post'].'&page='.$page.'">Изменить</a> <a href="index.php?act=delpost&topic='.$topic.'&post='.$firstPost['post'].'&page='.$page.'">Удалить</a>';
}
$postArray = array('header' => $postHeader, 'body' => $postText, 'sub' => $postSub);
echo functions::display_user($firstPost, $postArray);
echo '</div>';
}
if ($rights == 3 || $rights >= 6){
echo '<form name="form1" action="index.php?act=delpost&topic='.$topic.'&page='.$page.'" method="post">';
echo '';
}
$i = $set_forum['upfp'] ? ($total - $start) + 1 : $start;
$req = mysql_query("SELECT `forum_posts`.*, `forum_posts`.`user` AS `name`, `forum_posts`.`user_id` AS `id`, `users`.`sex`, `users`.`rights`, `users`.`lastdate`, `users`.`status`, `users`.`datereg` FROM `forum_posts` LEFT JOIN `users` ON `forum_posts`.`user_id` = `users`.`id` WHERE `forum_posts`.`topic` = '$topic' ORDER BY `forum_posts`.`time` $postOrder LIMIT $start, $kmess ");
while ($res = mysql_fetch_array($req)){
if ($set_forum['upfp']) --$i;
else ++$i;
echo $i % 2 ? '<div name="p'.$res['post'].'" id="p'.$res['post'].'" class="list1">' : '<div name="p'.$res['post'].'" id="p'.$res['post'].'" class="list2">';
$header = ' <span class="gray">'.functions::display_date($res['time']).'</span>'.($res['rating'] < -4 ? '' : ' <a href="index.php?post='.$res['post'].'" title="Ссылка на пост">#'.$i.'</a>');
$text = quote(functions::checkout($res['text'], 1, 1));
if ($set_user['smileys'])
$text = functions::smileys($text, $res['rights'] >= 1 ? 1 : 0);
if ($res['files']){
$file = mysql_query("SELECT * FROM `forum_files` WHERE `post` = '".$res['post']."' LIMIT ".$res['files']." ");
$text .= '<div class="func">Файл(ы):<br />';
while($fileRes = mysql_fetch_array($file)){
$text .= show_file($fileRes).'<br />';
}
$text .= '</div>';
}
if ($res['edit']){
$edit = explode(':|:', $res['edit']);
$text .= '<div style="font-size: x-small; color: gray">Изменил(а) '.$edit['0'].' '.functions::display_date($edit['1']).($edit['2'] ? '<br />Причина: '.functions::checkout($edit['2'], 2) : '').'</div>';
}
if ($res['rating'] > 0) $color = 'C0FFC0';
elseif ($res['rating'] < 0) $color = 'F196A8';
else $color = 'CCCCCC';
if ($user_id && $res['user_id'] != $user_id && !$topicRes['close']){
$text .= '<div style="font-size: x-small; margin-top: 7px;">Рейтинг: <a href="index.php?act=rating&topic='.$topic.'&post='.$res['post'].'&minus"><img src="images/minus.png" alt="-" /></a> <span style="background:#'.$color.'"> '.$res['rating'].' </span> <a href="index.php?act=rating&topic='.$topic.'&post='.$res['post'].'&plus"><img src="images/plus.png" alt="+" /></a></div>';
}else{
$text .= '<div style="font-size: x-small; margin-top: 7px;">Рейтинг: <span style="background:#'.$color.'"> '.$res['rating'].' </span></div>';
}
if ($res['rating'] < -4){
$text = '<strong>Сообщение скрыто по причине отрицательного рейтинга!</strong><br /><a href="index.php?post='.$res['post'].'">Показать сообщение</a>';
}
$sub = '';
if (($user_id && $user_id != $res['user_id'] && !$ban['1'] && !$ban['11'] && !$topicRes['close']) || ($user_id != $res['user_id'] && ($rights == 3 || $rights >= 6))){
$sub .= '<a href="index.php?act=addpost&post='.$res['post'].'&topic='.$topic.'&page='.$page.'">Ответ</a> <a href="index.php?act=addpost&quote&post='.$res['post'].'&topic='.$topic.'&page='.$page.'">Цитата</a>';
}
if ((($user_id == $res['user_id'] && !$topicRes['close'] && (!$ban['1'] || !$ban['11']) && $res['time'] > time() - 300) || ($user_id == $res['user_id'] && (!$i && (!$page || $page == 1)))) || ($rights == 3 || $rights >=6)){
$sub .= ' <a href="index.php?act=editpost&topic='.$topic.'&post='.$res['post'].'&page='.$page.'">Изменить</a> <a href="index.php?act=delpost&topic='.$topic.'&post='.$res['post'].'&page='.$page.'">Удалить</a>';
}
if ($rights == 3 || $rights >= 6)
$sub .= '<input type="checkbox" name="massdel['.$i.']" value="'.$res['post'].'" /> ';
$array = array('header' => $header, 'body' => $text, 'sub' => $sub);
echo functions::display_user($res, $array);
echo '</div>';
}
if ($rights == 3 || $rights >= 6)
echo '<div class="rmenu"><input type="submit" value="Удал. отмеч." /></div></form>';
}else{
echo '<div class="list1">Пусто</div>';
}
if (!$set_forum['upfp']){
if (($user_id && !$ban['1'] && !$ban['11'] && !$topicRes['close']) || ($rights == 3 || $rights >= 6)){
echo '<form id="form" name="form" action="index.php?act=addpost&topic='.$topic.'&page='.$page.'" method="post"><div class="gmenu">';
if ($set_forum['farea']){
echo 'Быстрый ответ <img style="cursor: pointer;" onclick="alert(this.title);" src="images/question.png" alt="?" title="Для предпросмотра или прикрепления файлов нажмите на кнопку: Расшир. форма" />:<br />'.bbcode::auto_bb('form', 'text').'<textarea name="text" cols="30" rows="'.$set_user['field_h'].'"></textarea>';
echo '<br /><input type="submit" name="send" value="Отправить" /> <input type="submit" name="preview" value="Расшир. форма" />';
}else{
echo '<input type="submit" value="Написать" />';
}
echo '</div></form>';
}
}
if ($total){
echo '<div name="down" id="down" class="phdr"><a href="#up"><img src="../images/up.png" alt="Вверх" width="20" height="10" border="0"/></a> Сообщений: '.$total.'</div>';
if ($total > $kmess){
echo '<div class="topmenu">'.functions::display_pagination('index.php?topic='.$topic.'&', $start, $total, $kmess).'</div>';
}
}
$onltime = time() - 300;
$online_u = mysql_result(mysql_query("SELECT COUNT(*) FROM `users` WHERE `lastdate` > $onltime AND `place` = 'forum,$topic' "), 0);
$online_g = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_sessions` WHERE `lastdate` > $onltime AND `place` = 'forum,$topic' "), 0);
if ($topicRes['curator']){
$curator = mysql_fetch_assoc(mysql_query("SELECT `lastdate`, `sex`, `datereg`, `id`, `name` FROM `users` WHERE `id` = '".$topicRes['curator']."' LIMIT 1 "));
$arrayCurator = array('header' => '', 'body' => '', 'sub' => '', 'iphide' => 1);
core::$user_set['avatar'] = 0;
echo '<p>Куратор темы: '.functions::display_user($curator, $arrayCurator).'</p>';
}
echo '<p><a href="index.php?act=search&topic='.$topic.'">Поиск</a><br />
<a href="index.php?act=onforum&topic='.$topic.'">Кто в теме</a> ('.$online_u.'/'.$online_g.')<br />
<a href="index.php?act=loadtopic&topic='.$topic.'&page='.$page.'">Скачать тему</a><br />
';
if ($user_id){
$favourites = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_favourites` WHERE `topic` = '$topic' AND `user_id` = '$user_id' LIMIT 1 "), 0);
echo $favourites ? '<a href="index.php?act=my&delfavourite&topic='.$topic.'&page='.$page.'">Из избранного</a><br />' : '<a href="index.php?act=my&addfavourite&topic='.$topic.'&page='.$page.'">В избранное</a><br />';
}
echo '<a href="index.php?act=files&topic='.$topic.'">Файлы темы</a></p>';
if (!$user_id)
echo '<p>'.($postOrder == 'DESC' ? '<a href="index.php?act=postorder&asc&topic='.$topic.'&page='.$page.'">Новые внизу</a>' : '<a href="index.php?act=postorder&desc&topic='.$topic.'&page='.$page.'">Новые вверху</a>').'</p>';
if ($rights == 3 || $rights >= 6){
echo '<div class="func"><a href="index.php?act=edittopic&topic='.$topic.'&page='.$page.'">Изменить</a><br />'.
'<a href="index.php?act=edittopic&topic='.$topic.'&page='.$page.'&'.($topicRes['close'] ? 'open">Открыть' : 'close">Закрыть').'</a><br />'.
($rights >= 6 ? '<a href="index.php?act=deltopic&topic='.$topic.'">Удалить</a><br />' : '').
'<a href="index.php?act=movetopic&topic='.$topic.'&page='.$page.'">Перенести</a><br />'.
'<a href="index.php?act=pollsettings&topic='.$topic.'&page='.$page.'">Голосование</a></div>';
}