Файл: Krimos/forum.php
Строк: 325
<?php
// Криме / Krime
include('common.php');
$page = intval(getarg('page', 1));
$forumid = getarg('id');
$threadid = getarg('tid');
$do = getarg('do', '');
if(islogged())
{
if($forumid != NULL)
{
$forumid = intval($forumid);
$query = mysql_query('SELECT * FROM `forums` WHERE `id` = '' . $forumid . '';');
if(mysql_num_rows($query) > 0)
{
if($do == 'new')
{
echo theader($lang['newthread']);
if((isset($_POST['title']) && !empty($_POST['title'])) && (isset($_POST['message']) && !empty($_POST['message'])))
{
$ttitle = clean($_POST['title']);
$tmessage = clean($_POST['message']);
$query = mysql_query('SELECT * FROM `threads` WHERE `title` = '' . $ttitle . '';');
if(mysql_num_rows($query) > 0)
{
echo ' <span>' . $lang['threadexists'] . '</span><br />' . "rn";
echo ' <span><a href="' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid . '&do=new">' . $lang['back'] . '</a></span><br />' . "rn";
echo ' <span><a href="' . $s_siteurl . '/index.php?lang=' . $language . '">' . $lang['main'] . '</a></span><br /><br />' . "rn";
}
else
{
$query = mysql_query('INSERT INTO `threads` VALUES('0', '' . $forumid . '', '' . $ttitle . '', '' . $tmessage . '', '' . getid() . '', '' . time() . '', '' . time() . '', '0', '0');');
if(mysql_affected_rows() > 0)
{
$tmessage = bbcode($tmessage);
$tmessage = smile($tmessage);
$query = mysql_query('SELECT `id` FROM `threads` WHERE `title` = '' . $ttitle . '' AND `poster` = '' . getid() . '';');
$result = mysql_result($query, 0);
echo ' <span>' . $lang['threadcreated'] . '</span><br />' . "rn";
echo ' <span><b>' . $tmessage . '</b></span><br /><br />' . "rn";
echo ' <span><a href="' . $s_siteurl . '/thread.php?lang=' . $language . '&id=' . $result . '">' . $lang['thread'] . '</a></span><br />' . "rn";
echo ' <span><a href="' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid . '">' . $lang['back'] . '</a></span><br />' . "rn";
echo ' <span><a href="' . $s_siteurl . '/index.php?lang=' . $language . '">' . $lang['main'] . '</a></span><br /><br />' . "rn";
}
else
{
echo ' <span>' . $lang['newthreaderror'] . '</span><br />' . "rn";
echo ' <span><a href="' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid . '&do=new">' . $lang['back'] . '</a></span><br />' . "rn";
echo ' <span><a href="' . $s_siteurl . '/index.php?lang=' . $language . '">' . $lang['main'] . '</a></span><br /><br />' . "rn";
}
}
}
else
{
echo ' <span>' . $lang['newthread'] . '</span><br /><br />' . "rn";
echo ' <form method="post" action="' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid . '&do=new">' . "rn";
echo ' <span>' . $lang['title'] . ':</span><br />' . "rn";
echo ' <input type="text" name="title" maxlength="30" /><br />' . "rn";
echo ' <span>' . $lang['message'] . ':</span><br />' . "rn";
echo ' <textarea name="message" maxlength="5000"></textarea><br />' . "rn";
echo ' <input type="submit" value="' . $lang['create'] . '" /><br /><br />' . "rn";
echo ' </form>' . "rn";
echo ' <span><a href="' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid . '">' . $lang['back'] . '</a></span><br />' . "rn";
echo ' <span><a href="' . $s_siteurl . '/index.php?lang=' . $language . '">' . $lang['main'] . '</a></span><br /><br />' . "rn";
}
}
elseif($do == 'delete')
{
if($threadid != NULL && checkmod())
{
$query = mysql_query('SELECT * FROM `threads` WHERE `id` = '' . $threadid . '';');
if(mysql_num_rows($query) > 0)
{
@mysql_query('DELETE FROM `posts` WHERE `thread` = '' . $threadid . '';');
@mysql_query('DELETE FROM `threads` WHERE `id` = '' . $threadid . '';');
}
}
header('Location: ' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid);
}
elseif($do == 'edit')
{
$query = mysql_query('SELECT * FROM `threads` WHERE `id` = '' . $threadid . '';');
if(mysql_num_rows($query) > 0)
{
$result = mysql_fetch_array($query);
if(checkmod())
{
if(isset($_POST['title']) && !empty($_POST['title']) && isset($_POST['message']) && !empty($_POST['message']))
{
$title = clean($title);
$message = clean($message);
@mysql_query('UPDATE `threads` SET `title` = '' . $title . '', `post` = '' . $message . '' WHERE `id` = '' . $threadid . '';');
header('Location: ' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid);
}
else
{
$title = $result['title'];
$message = str_replace('<br />', "rn", $result['post']);
echo theader($lang['editthread']);
echo ' <span>' . $lang['editthread'] . '</span><br /><br />' . "rn";
echo ' <form method="post" action="' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid . '&do=edit&tid=' . $threadid . '">' . "rn";
echo ' <span>' . $lang['title'] . ':</span><br />' . "rn";
echo ' <input type="text" name="title" maxlength="30" value="' . $title . '" /><br />' . "rn";
echo ' <span>' . $lang['message'] . ':</span><br />' . "rn";
echo ' <textarea name="message" maxlength="5000">' . $message . '</textarea><br />' . "rn";
echo ' <input type="submit" value="' . $lang['edit'] . '" /><br />' . "rn";
echo ' </form>' . "rn";
echo ' <span><a href="' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid . '">' . $lang['back'] . '</a></span><br />' . "rn";
echo ' <span><a href="' . $s_siteurl . '/index.php?lang=' . $language . '">' . $lang['main'] . '</a></span><br /><br />' . "rn";
}
}
else
header('Location: ' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid);
}
else
header('Location: ' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid);
}
else
{
$result = mysql_fetch_array($query);
echo theader($lang['forum'] . ' / ' . $result['title']);
echo ' <span><a href="' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid . '&do=new">' . $lang['newthread'] . '</a></span><br /><br />' . "rn";
$query = mysql_query('SELECT COUNT(*) FROM `threads` WHERE `forum` = '' . $forumid . '';');
if(intval(mysql_result($query, 0)) > 0)
{
echo ' <div class="left">' . "rn";
$nthreads = mysql_result($query, 0);
$ntpp = 10;
$npages = ceil($nthreads / $ntpp);
if($page > $npages && $page != 1)
$page = $npages;
$limit = ($page - 1) * $ntpp;
$pinned = mysql_query('SELECT * FROM `threads` WHERE `forum` = '' . $forumid . '' AND `pinned` = '1' ORDER BY `lastpost` DESC;');
if(mysql_num_rows($pinned) > 0)
{
while($pin = mysql_fetch_array($pinned))
{
$pid = $pin['id'];
$ptitle = $pin['title'];
$plocked = (bool)$pin['locked'];
$puser = getusername($pin['poster']);
$pdate = $pin['date'];
$query = mysql_query('SELECT COUNT(*) FROM `posts` WHERE `thread` = '' . $pid . '';');
$postsCount = intval(mysql_result($query, 0));
if($postsCount > 0)
{
$query = mysql_query('SELECT `poster` FROM `posts` WHERE `thread` = '' . $pid . '' ORDER BY `date` DESC LIMIT 0, 1;');
$result = intval(mysql_result($query, 0));
$lastbyid = $result;
$lastby = getusername($lastbyid);
}
else
{
$lastbyid = $pin['poster'];
$lastby = $puser;
}
if($plocked)
$lstext = '[X]';
else
$lstext = '';
if(checkmod())
{
$edl = ' <a href="' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid . '&do=edit&tid=' . $pid . '">[E]</a>';
$dll = ' <a href="' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid . '&do=delete&tid=' . $pid . '">[D]</a>';
}
else
{
$edl = '';
$dll = '';
}
echo ' <div class="thread">' . "rn";
echo ' <span><a href="' . $s_siteurl . '/thread.php?lang=' . $language . '&id=' . $pid . '">' . $ptitle . ' (' . $postsCount . ')[^]' . $lstext . '</a> / (' . date('d/m/Y', $pdate) . ', ' . $lang['bywho'] . ': <b><a href="' . $s_siteurl . '/profile.php?lang=' . $language . '&id=' . $pin['poster'] . '">' . $puser . '</a></b>, ' . $lang['lastpost'] . ': <b><a href="' . $s_siteurl . '/profile.php?lang=' . $language . '&id=' . $lastbyid . '">' . $lastby . '</a></b>) <a href="' . $s_siteurl . '/thread.php?lang=' . $language . '&id=' . $pid . '&page=last">>></a>' . $edl . $dll . '</span><br />' . "rn";
echo ' </div>' . "rn";
}
echo ' <br />' . "rn";
}
$threads = mysql_query('SELECT * FROM `threads` WHERE `forum` = '' . $forumid . '' AND `pinned` = '0' ORDER BY `lastpost` DESC LIMIT ' . $limit . ', ' . $ntpp . ';');
while($thread = mysql_fetch_array($threads))
{
$tid = $thread['id'];
$ttitle = $thread['title'];
$tlocked = (bool)$thread['locked'];
$tuser = getusername($thread['poster']);
$tdate = $thread['date'];
$query = mysql_query('SELECT COUNT(*) FROM `posts` WHERE `thread` = '' . $tid . '';');
$postsCount = intval(mysql_result($query, 0));
if($postsCount > 0)
{
$query = mysql_query('SELECT `poster` FROM `posts` WHERE `thread` = '' . $tid . '' ORDER BY `date` DESC LIMIT 0, 1;');
$result = intval(mysql_result($query, 0));
$lastbyid = $result;
$lastby = getusername($lastbyid);
}
else
{
$lastbyid = $thread['poster'];
$lastby = $tuser;
}
if($tlocked)
$lstext = '[X]';
else
$lstext = '';
if(checkmod())
{
$edl = ' <a href="' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid . '&do=edit&tid=' . $tid . '">[E]</a>';
$dll = ' <a href="' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid . '&do=delete&tid=' . $tid . '">[D]</a>';
}
else
{
$edl = '';
$dll = '';
}
echo ' <div class="thread">' . "rn";
echo ' <span><a href="' . $s_siteurl . '/thread.php?lang=' . $language . '&id=' . $tid . '">' . $ttitle . ' (' . $postsCount . ')' . $lstext . '</a> / (' . date('d/m/Y', $tdate) . ', ' . $lang['bywho'] . ': <b><a href="' . $s_siteurl . '/profile.php?lang=' . $language . '&id=' . $thread['poster'] . '">' . $tuser . '</a></b>, ' . $lang['lastpost'] . ': <b><a href="' . $s_siteurl . '/profile.php?lang=' . $language . '&id=' . $lastbyid . '">' . $lastby . '</a></b>) <a href="' . $s_siteurl . '/thread.php?lang=' . $language . '&id=' . $tid . '&page=last">>></a>' . $edl . $dll . '</span><br />' . "rn";
echo ' </div>' . "rn";
}
if($page > 1)
{
$bp = $page - 1;
$bl = '<a href="' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid . '&page=' . $bp . '">< ' . $lang['backward'] . '</a>';
}
else
$bl = '< ' . $lang['backward'];
if($page < $npages)
{
$fp = $page + 1;
$fl = ' | <a href="' . $s_siteurl . '/forum.php?lang=' . $language . '&id=' . $forumid . '&page=' . $fp . '">' . $lang['forward'] . ' ></a>';
}
else
$fl = ' | ' . $lang['forward'] . ' >';
echo ' </div>' . "rn";
echo ' <span>' . $bl . $fl . '</span><br />' . "rn";
echo ' <span><a href="' . $s_siteurl . '/index.php?lang=' . $language . '">' . $lang['back'] . '</a></span><br /><br />' . "rn";
}
else
{
echo ' <span>' . $lang['nothreads'] . '</span><br />' . "rn";
echo ' <span><a href="' . $s_siteurl . '/index.php?lang=' . $language . '">' . $lang['back'] . '</a></span><br /><br />' . "rn";
}
}
}
else
{
echo theader($lang['forums']);
echo ' <span>' . $lang['forumnotexists'] . '</span><br />' . "rn";
echo ' <span><a href="' . $s_siteurl . '/index.php?lang=' . $language . '">' . $lang['back'] . '</a></span><br /><br />' . "rn";
}
echo tfooter();
}
else
{
header('Location: ' . $s_siteurl . '/index.php?lang=' . $language);
}
}
else
{
header('Location: ' . $s_siteurl . '/index.php?lang=' . $language);
}
exit();
?>