Файл: forum/my.php
Строк: 152
<?php
# Script by seg0ro http://mobilarts.ru
# Not for sale!!!
defined('_IN_JOHNCMS') or die('Error: restricted access');
$textl .= ' | Моя страница';
require_once('../incfiles/head.php');
if (!$user_id){
echo functions::display_error('Только для авторизованных!<br /><a href="index.php">Форум</a>');
require_once('../incfiles/end.php');
exit;
}
if (isset($_GET['addfavourite']) && $topic){
$check = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_favourites` WHERE `topic` = '$topic' AND `user_id` = '$user_id' LIMIT 1 "), 0);
if ($check){
echo functions::display_error('Данная тема уже в избранном!<br /><a href="index.php?topic='.$topic.'&page='.$page.'">Назад</a>');
require_once('../incfiles/end.php');
exit;
}
$check = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_favourites` WHERE `user_id` = '$user_id' "), 0);
if ($check >= 20){
echo functions::display_error('Максимальное количество тем в избранном (20 шт.)!<br /><a href="index.php?topic='.$topic.'&page='.$page.'">Назад</a>');
require_once('../incfiles/end.php');
exit;
}
mysql_query("INSERT INTO `forum_favourites` SET
`topic` = '$topic',
`user_id` = '$user_id' ");
echo '<div class="gmenu">Тема добавлена в избранное<br /><a href="index.php?act=my&favourites">В избранное</a> <a href="index.php?topic='.$topic.'&page='.$page.'">В тему</a></div>';
require_once('../incfiles/end.php');
exit;
}
if (isset($_GET['delfavourite']) && $topic){
mysql_query("DELETE FROM `forum_favourites` WHERE `topic` = '$topic' AND `user_id` = '$user_id' LIMIT 1 ");
echo '<div class="gmenu">Тема удалена из избранного<br /><a href="index.php?act=my&favourites">В избранное</a> <a href="index.php?topic='.$topic.'&page='.$page.'">В тему</a></div>';
require_once('../incfiles/end.php');
exit;
}
if (isset($_GET['cleanjournal'])){
if (isset($_POST['yes'])){
if (journal::deleteEntry()){
header ('Refresh:1; URL=index.php');
echo '<div class="gmenu">Журнал очищен<br /><a href="index.php">Форум</a></div>';
require_once('../incfiles/end.php');
exit;
}else{
echo '<div class="rmenu">Возникла ошибка при очистке журнала!<br /><a href="index.php?act=my&journal">Журнал</a></div>';
require_once('../incfiles/end.php');
exit;
}
}else{
echo '<form action="index.php?act=my&cleanjournal" method="post"><div class="rmenu">Вы действительно хотите очистить журнал?<br />';
echo '<input type="submit" name="yes" value="Очистить" /> <a href="index.php?act=my&journal">Отмена</a></div></form>';
require_once('../incfiles/end.php');
exit;
}
}
if (isset($_GET['posts'])){
$sqlTotal = 'posts';
$sql = "* FROM `forum_posts` WHERE `user_id` = '$user_id' ORDER BY `time` DESC";
$url = 'posts';
$hdr = 'Мои сообщения';
$bottom = 'Сообщений: ';
$goto = '<a href="index.php?act=my&topics">Темы</a> <a href="index.php?act=my&files">Файлы</a> <a href="index.php?act=my&favourites">Избранное</a> <a href="index.php?act=my&journal">Журнал</a>';
}elseif(isset($_GET['files'])){
$sqlTotal = 'files';
$sql = "* FROM `forum_files` WHERE `user_id` = '$user_id' ";
$url = 'files';
$hdr = 'Мои файлы';
$bottom = 'Файлов: ';
$goto = '<a href="index.php?act=my&topics">Темы</a> <a href="index.php?act=my&posts">Сообщения</a> <a href="index.php?act=my&favourites">Избранное</a> <a href="index.php?act=my&journal">Журнал</a>';
}elseif(isset($_GET['favourites'])){
$sqlTotal = 'favourites';
$sql = "`forum_favourites`.*, `forum_topics`.*, `forum_favourites`.`topic` AS `topic` FROM `forum_favourites` LEFT JOIN `forum_topics` ON `forum_favourites`.`topic` = `forum_topics`.`topic` WHERE `forum_favourites`.`user_id` = '$user_id' ";
$url = 'favourites';
$hdr = 'Избранное';
$bottom = 'Тем: ';
$goto = '<a href="index.php?act=my&topics">Темы</a> <a href="index.php?act=my&posts">Сообщения</a> <a href="index.php?act=my&files">Файлы</a> <a href="index.php?act=my&journal">Журнал</a>';
}elseif(isset($_GET['journal'])){
$sqlTotal = 'journal';
$sql = "* FROM `forum_journal` WHERE `user_id` = '$user_id' ORDER BY `time` DESC";
$url = 'journal';
$hdr = 'Журнал';
$bottom = 'Записей (из 100): ';
$goto = '<a href="index.php?act=my&topics">Темы</a> <a href="index.php?act=my&posts">Сообщения</a> <a href="index.php?act=my&files">Файлы</a> <a href="index.php?act=my&favourites">Избранное</a>';
}else{
$sqlTotal = 'topics';
$sql = "* FROM `forum_topics` WHERE `user_id` = '$user_id' ORDER BY `time` DESC";
$url = 'topics';
$hdr = 'Мои темы';
$bottom = 'Тем: ';
$goto = '<a href="index.php?act=my&posts">Сообщения</a> <a href="index.php?act=my&files">Файлы</a> <a href="index.php?act=my&favourites">Избранное</a> <a href="index.php?act=my&journal">Журнал</a>';
}
$tree = array('<a href="index.php">Форум</a>', $hdr);
echo '<div class="phdr">'.functions::display_menu($tree).'</div>';
$total = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_$sqlTotal` WHERE `user_id` = '$user_id' "), 0);
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?act=my&'.$url.'&', $start, $total, $kmess).'</div>';
$req = mysql_query("SELECT $sql LIMIT $start, $kmess ");
if (isset($_GET['posts'])){
while ($res = mysql_fetch_array($req)){
echo $i % 2 ? '<div class="list2">' : '<div class="list1">';
echo '<span class="gray">'.functions::display_date($res['time']).'</span> <a href="index.php?post='.$res['post'].'&find" title="Перейти к сообщению">>></a> '.'<br />';
echo quote(functions::checkout($res['text'], 1, 1));
if ($res['files']){
$file = mysql_query("SELECT * FROM `forum_files` WHERE `post` = '".$res['post']."' LIMIT ".$res['files']." ");
echo '<div class="func">Файл(ы):<br />';
while($fileRes = mysql_fetch_array($file)){
echo show_file($fileRes).'<br />';
}
echo '</div>';
}
$topicRes = mysql_fetch_array(mysql_query("SELECT * FROM `forum_topics` WHERE `topic` = '".$res['topic']."' LIMIT 1 "));
echo '<div class="sub">Тема: <a href="index.php?topic='.$topicRes['topic'].'">'.$topicRes['topicname'].'</a></div></div>';
++$i;
}
}elseif(isset($_GET['files'])){
while ($res = mysql_fetch_array($req)){
echo $i % 2 ? '<div class="list2">' : '<div class="list1">';
echo '<span class="gray">'.functions::display_date($res['time']).'</span> <a href="index.php?post='.$res['post'].'&find" title="Перейти к сообщению">>></a><br />';
echo show_file($res);
$topicRes = mysql_fetch_array(mysql_query("SELECT * FROM `forum_topics` WHERE `topic` = '".$res['topic']."' LIMIT 1 "));
echo '<div class="sub"><a href="index.php?topic='.$topicRes['topic'].'">'.$topicRes['topicname'].'</a></div></div>';
++$i;
}
}elseif(isset($_GET['favourites'])){
while ($res = mysql_fetch_array($req)){
echo $i % 2 ? '<div class="list2">' : '<div class="list1">';
$sub = 'Автор: '.$res['user'];
if ($res['count'] > 1){
$lastPost = explode(':|:', $res['lastpost']);
$sub .= ' <a href="index.php?post='.$lastPost[1].'&find" title="Перейти к сообщению">Последн.</a>: '.$lastPost[0];
}
$sub .= ' '.functions::display_date($res['time']).'<br />'.
'Подфорум: <a href="index.php?forum='.$res['forum'].'">'.$res['forumname'].'</a>'.
'<br /><a href="index.php?act=my&delfavourite&topic='.$res['topic'].'">Удалить из избранного</a>';
echo show_topic($res, $sub).'</div>';
++$i;
}
}elseif(isset($_GET['journal'])){
while ($res = mysql_fetch_array($req)){
echo $i % 2 ? '<div class="list2">' : '<div class="list1">';
echo functions::display_date($res['time']).'<br /><img src="images/topic'.(!$res['readed'] ? '.new' : '').'.png" alt="-" /> '.functions::checkout($res['text'], 1, 1).'</div>';
if (!$res['readed'])
mysql_query("UPDATE `forum_journal` SET `readed` = '1' WHERE `time` = '".$res['time']."' AND `user_id` = '$user_id' LIMIT 1 ");
++$i;
}
}else{
while ($res = mysql_fetch_array($req)){
echo $i % 2 ? '<div class="list2">' : '<div class="list1">';
$sub = '';
$lastPost = explode(':|:', $res['lastpost']);
$sub .= ' <a href="index.php?post='.$lastPost[1].'&find" title="Перейти к сообщению">Последн.</a>: '.$lastPost[0].
' '.functions::display_date($res['time']).'<br />'.
'Подфорум: <a href="index.php?forum='.$res['forum'].'">'.$res['forumname'].'</a>';
echo show_topic($res, $sub).'</div>';
++$i;
}
}
echo '<div class="phdr">'.$bottom.$total.'</div>';
if ($total > $kmess){
echo '<div class="topmenu">'.functions::display_pagination('index.php?act=my&'.$url.'&', $start, $total, $kmess).'</div>';
}
if (isset($_GET['journal']) && $total)
echo '<div class="rmenu"><a href="index.php?act=my&cleanjournal">Очистить журнал</a></div>';
}else{
echo '<div class="list1">Пусто</div>';
}
echo '<p>Показать: '.$goto.'</p>';