Файл: thread.php
Строк: 166
<?php
include('common.php');
$page = getarg('page', 1);
$threadid = getarg('id');
$postid = getarg('pid');
$do = getarg('do', '');
if(islogged()){
if($threadid != NULL){
$threadid = intval($threadid);
$query = mysql_query('SELECT * FROM `threads` WHERE `id` = '' . $threadid . '';');
if(mysql_num_rows($query) > 0){
if($do == 'new'){
echo theader($lang['newpost']);
$query = mysql_query('SELECT `locked` FROM `threads` WHERE `id` = '' . $threadid . '';');
$result = (bool)mysql_result($query, 0);
if(!$result || checkmod()) $locked = FALSE; else $locked = TRUE;
if($locked){
echo '<div class="list2">' . $lang['threadlocked'] . '</div>
<div class="list2"><a href="/thread.php?id=' . $threadid . '">' . $lang['back'] . '</a></div>
<div class="list2"><a href="/index.php">' . $lang['main'] . '</a></div>';
}else{
if(isset($_POST['message']) && !empty($_POST['message'])){
mysql_query("update `threads` set `lastpost`='".time()."' where `id`='$threadid'");
$query=mysql_query("insert into `posts` set `thread`='$threadid', `post`='".clean($_POST['message'])."',
`poster`='".getid()."', `date`='".time()."'");
if(mysql_affected_rows() > 0){
$tmessage = bbcode(clean($_POST['message']));
$tmessage = smile($tmessage);
echo '<div class="list2">' . $lang['postcreated'] . '</div>
<div class="list2">'. $tmessage . '</div>
<div class="list2"><a href="/thread.php?id='.$threadid.'&page=last">'.$lang['thread'].'</a></div>
<div class="list2"><a href="/index.php">' . $lang['main'] . '</a></div>';
}else{
echo '<div class="list2">' . $lang['newposterror'] . '</div>
<div class="list2"><a href="/thread.php?id='.$threadid .'&do=new">'.$lang['back'].'</a></div>
<div class="list2"><a href="/index.php">' . $lang['main'] . '</a></div>';
}
}else{
echo '<div class="list2">' . $lang['newpost'] . '</div>
<form method="post" action="/thread.php?id=' . $threadid . '&do=new">
<div class="list2">
' . $lang['message'] . ':<br /><textarea name="message"></textarea><br />
<input type="submit" value="' . $lang['postit'] . '" />
</form></div><div class="list2">
<a href="/thread.php?id=' . $threadid . '">' . $lang['back'] . '</a><br />
<a href="/index.php">' . $lang['main'] . '</a></div>';
}
}
}
elseif($do == 'lock'){
if($threadid > 0 && checkmod()){
$query = mysql_query('SELECT `locked` FROM `threads` WHERE `id` = '' . $threadid . '';');
if(mysql_num_rows($query) > 0){
$locked = (bool)intval(mysql_result($query, 0));
if($locked)
@mysql_query('UPDATE `threads` SET `locked` = '0' WHERE `id` = '' . $threadid . '';');
else
@mysql_query('UPDATE `threads` SET `locked` = '1' WHERE `id` = '' . $threadid . '';');
}
}
echo'<div class="list2"><a href="/thread.php?id='.$threadid.'">'.$lang['continue'].'</a></div>';
}elseif($do == 'pin'){
if($threadid > 0 && checkmod()){
$query = mysql_query('SELECT `pinned` FROM `threads` WHERE `id` = '' . $threadid . '';');
if(mysql_num_rows($query) > 0){
$pinned = (bool)intval(mysql_result($query, 0));
if($pinned)
mysql_query("update `threads` set `pinned`='0' where `id`='$threadid'");
else
mysql_query("update `threads` set `pinned`='1' where `id`='$threadid'");
}
}
echo'<div class="list2"><a href="/thread.php?id='.$threadid.'">'.$lang['continue'].'</a></div>';
}elseif($do == 'delete'){
if($postid > 0 && checkmod()){
$query = mysql_query('SELECT * FROM `posts` WHERE `id` = '' . $postid . '';');
if(mysql_num_rows($query) > 0){
mysql_query("delete from `posts` where `id`='$postid'");
}
}
echo'<div class="list2"><a href="/thread.php?id='.$threadid.'">'.$lang['continue'].'</a></div>';
}elseif($do == 'edit'){
$query = mysql_query('SELECT * FROM `posts` WHERE `id` = '' . $postid . '';');
if(mysql_num_rows($query) > 0){
$result = mysql_fetch_array($query);
if($result['poster'] == getid() || checkmod()){
if(isset($_POST['message']) && !empty($_POST['message'])){
$message = clean($_POST['message']);
mysql_query("update `posts` set `post`='$message' where `id`='$postid'");
echo'<div class="list2"><a href="/thread.php?id='.$threadid.'">'.$lang['continue'].'</a></div>';
}else{
$message = str_replace('<br />', "rn", $result['post']);
echo theader($lang['editpost']);
echo '<div class="list2">' . $lang['editpost'] . '</div>
<form method="post" action="/thread.php?id=' . $threadid . '&do=edit&pid=' . $postid . '">
<div class="list2">
' . $lang['message'] . '<br />
<textarea name="message" maxlength="5000">' . $message . '</textarea><br />
<input type="submit" value="' . $lang['edit'] . '" />
</form></div><div class="list2">
<a href="/thread.php?id=' . $threadid . '">' . $lang['back'] . '</a><br />
<a href="/index.php">' . $lang['main'] . '</a></div>';
}
}
else
echo'<div class="list2"><a href="/thread.php?id='.$threadid.'">'.$lang['continue'].'</a></div>';
}
else
echo'<div class="list2"><a href="/thread.php?id='.$threadid.'">'.$lang['continue'].'</a></div>';
}else{
$result = mysql_fetch_array($query);
echo theader($lang['thread'] . ' / ' . $result['title']);
$locked = (bool)intval($result['locked']);
$pinned = (bool)intval($result['pinned']);
$query = mysql_query('SELECT COUNT(*) FROM `posts` WHERE `thread` = '' . $threadid . '';');
$nposts = mysql_result($query, 0);
$ntpp = 9;
$npages = ceil($nposts / $ntpp);
if($page == 'last')
$page = $npages;
$page = intval($page);
if($page > $npages && $page != 1)
$page = $npages;
if($page > 1)
echo ' <span><a href="/thread.php?id=' . $threadid . '&page=1">' . $lang['firstpage'] . '</a></span><br />' . "rn";
if($npages > 1 && $page < $npages)
echo ' <span><a href="/thread.php?id=' . $threadid . '&page=' . $npages . '">' . $lang['lastpage'] . '</a></span><br />' . "rn";
if(!$locked || checkmod()){
echo '<form method="post" action="/thread.php?id=' . $threadid . '&do=new">
<div class="list2">' . $lang['message'] . ':<br />
<textarea name="message" maxlength="5000"></textarea><br />
<input type="submit" value="' . $lang['postit'] . '" />
</form></div><div class="list2">
<a href="/thread.php?id=' . $threadid . '&do=new">' . $lang['newpost'] . '</a></div>';
}
if($pinned){
if(checkmod())
echo '<div class="list2"><a href="/thread.php?id='.$threadid.'&do=pin">' . $lang['unpin'] . '</a></div>';
}else{
if(checkmod())
echo '<div class="list2"><a href="/thread.php?id='.$threadid.'&do=pin">' . $lang['pin'] . '</a></div>';
}
if($locked){
if(checkmod())
echo '<div class="list2"><a href="/thread.php?id='.$threadid.'&do=lock">'.$lang['unlock'].'</a></div>';
}else{
if(checkmod())
echo '<div class="list2"><a href="/thread.php?id='.$threadid.'&do=lock">' . $lang['lock'] . '</a></div>';
}
$limit = ($page - 1) * $ntpp;
$query = mysql_query('SELECT * FROM `threads` WHERE `id` = '' . $threadid . '';');
$result = mysql_fetch_array($query);
$fmessage = bbcode($result['post']);
$fmessage = smile($fmessage);
$forumid = intval($result['forum']);
echo '<div class="list2">
<a href="/profile.php?id=' . intval($result['poster']) . '">' . getusername(intval($result['poster'])) . '</a>: (' . date('d/m/Y, H:i:s', $result['date']) . ')<br />
' . $fmessage . '</div>';
$posts = mysql_query('SELECT * FROM `posts` WHERE `thread` = '' . $threadid . '' ORDER BY `date` ASC LIMIT ' . $limit . ', ' . $ntpp . ';');
if($nposts > 0){
while($post = mysql_fetch_array($posts)){
$ppid = $post['id'];
$pid = $post['poster'];
$puser = getusername($pid);
$pmessage = bbcode($post['post']);
$pmessage = smile($pmessage);
$pdate = $post['date'];
if($pid == getid() || checkmod())
$edl = ' <a href="/thread.php?id=' . $threadid . '&do=edit&pid=' . $ppid . '">[E]</a>';
else
$edl = '';
if(checkmod())
$dll = ' | <a href="/thread.php?id=' . $threadid . '&do=delete&pid=' . $ppid . '">[D]</a>';
else
$dll = '';
echo '<div class="list2">
<a href="/profile.php?id=' . $pid . '">' . $puser . '</a>: (' . date('d/m/Y, H:i:s', $pdate) . ')' . $edl . $dll . '<br />
' . $pmessage . '</div>';
}
}
if($page > 1){
$bp = $page - 1;
$bl = '<a href="/thread.php?id=' . $threadid . '&page=' . $bp . '">< ' . $lang['backward'] . '</a>';
}else
$bl = '< ' . $lang['backward'];
if($page < $npages){
$fp = $page + 1;
$fl = ' | <a href="/thread.php?id=' . $threadid . '&page=' . $fp . '">' . $lang['forward'] . ' ></a>';
}else
$fl = ' | ' . $lang['forward'] . ' >';
echo '<div class="list2">' . $bl . $fl . '</div>
<div class="list2"><a href="/forum.php?id=' . $forumid . '">' . $lang['threads'] . '</a><br />
<a href="/index.php">' . $lang['back'] . '</a></div>';
}
}else{
echo theader($lang['threads']);
echo '<div class="list2">' . $lang['threadnotexists'] . '</div>
<div class="list2"><a href="/index.php">' . $lang['back'] . '</a></div>';
}
echo tfooter();
}else{
echo'<div class="list2"><a href="/">'.$lang['continue'].'</a></div>';
}
}else{
echo'<div class="list2"><a href="/">'.$lang['continue'].'</a></div>';
}
exit();
?>