Вход Регистрация
Файл: forum.php
Строк: 153
<?php
    
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_fetch_assoc(mysql_query("select * from `forums` where `id`='$forumid'"));
            if(
$query){
                if(
$do == 'new'){
                    echo 
theader($lang['newthread']);
                    if(isset(
$_POST['title']) && isset($_POST['message'])){
                        
$ttitle clean($_POST['title']);
                        
$tmessage clean($_POST['message']);
                        
$query=mysql_fetch_assoc(mysql_query("select * from `threads` where `title`='$ttitle'"));
                        if(
$query){
                            echo 
'<div class="list2">' $lang['threadexists'] . '</div>
                            <div class="list2"><a href="/forum.php?id=' 
$forumid '&amp;do=new">' $lang['back'] . '</a> | <a href="/index.php">' $lang['main'] . '</a></div>';
                        }else{
                            
$query=mysql_query("insert into `threads` set `forum`='$forumid', `title`='$ttitle', `post`='$tmessage',
                            `poster`='"
.getid()."', `date`='".time()."', `lastpost`='".time()."', `pinned`='0', `locked`='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($query0);
                                echo 
'<div class="list2">' $lang['threadcreated'] . '</div>
                                <div class="list2">' 
$tmessage '</div>
                                <div class="list2"><a href="/thread.php?id=' 
$result '">' $lang['thread'] . '</a></div>
                                <div class="list2"><a href="/forum.php?id=' 
$forumid '">' $lang['back'] . '</a></div>
                                <div class="list2"><a href="/index.php">' 
$lang['main'] . '</a></div>';
                            }else{
                                echo 
'<div class="list2">' $lang['newthreaderror'] . '</div>
                                <div class="list2"><a href="/forum.php?id=' 
$forumid '&amp;do=new">' $lang['back'] . '</a></div>
                                <div class="list2"><a href="/index.php">' 
$lang['main'] . '</a></div>';
                            }
                        }
                    }else{
                        echo 
'<div class="list2">' $lang['newthread'] . '</div>
                        <form method="post" action="/forum.php?id=' 
$forumid '&amp;do=new">
                        <div class="list2">
                        ' 
$lang['title'] . ':<br /><input type="text" name="title" maxlength="30" /><br />
                        ' 
$lang['message'] . ':<br /><textarea name="message" maxlength="5000"></textarea><br />
                        <input type="submit" value="' 
$lang['create'] . '" />
                        </form></div><div class="list2">
                        <a href="/forum.php?id=' 
$forumid '">' $lang['back'] . '</a><br />
                        <a href="/index.php">' 
$lang['main'] . '</a></div>';
                    }
                }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'");
                        }
                    }
                    echo
'<div class="list2"><a href="/forum.php?id='.$forumid.'">'.$lang['continue'].'</a></div>';
                }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']) && isset($_POST['message'])){
                                
$title clean($title);
                                
$message clean($message);
                                
mysql_query("update `threads` set `title`='$title', `post`='$message' where `id`='$threadid'");
                                echo
'<div class="list2"><a href="/forum.php?id='.$forumid.'">'.$lang['continue'].'</a></div>';
                            }else{
                                
$title $result['title'];
                                
$message str_replace('<br />'"rn"$result['post']);
                                echo 
theader($lang['editthread']);
                                echo 
'<div class="list2">' $lang['editthread'] . '</div>
                                <form method="post" action="/forum.php?id=' 
$forumid '&amp;do=edit&amp;tid=' $threadid '">
                                <div class="list2">
                                ' 
$lang['title'] . ':<br /><input type="text" name="title" value="' $title '" /><br />
                                ' 
$lang['message'] . ':<br /><textarea name="message">' $message '</textarea><br />
                                <input type="submit" value="' 
$lang['edit'] . '" />
                                </form></div>
                                <div class="list2">
                                <a href="/forum.php?id=' 
$forumid '">' $lang['back'] . '</a><br />
                                <a href="/index.php">' 
$lang['main'] . '</a></div>';
                            }
                        }
                        else
                            echo
'<div class="list2"><a href="/forum.php?id='.$forumid.'">'.$lang['continue'].'</a></div>';
                    }
                    else
                        echo
'<div class="list2"><a href="/forum.php?id='.$forumid.'">'.$lang['continue'].'</a></div>';
                }else{
                    
$id=clean(intval($_GET['id']));
                    
$query=mysql_query("select * from `threads` where `forum`='$id'");
                    
$result mysql_fetch_array($query);
                    echo 
theader($lang['forum'] . ' / ' $result['title']);

                    echo 
'<div class="list2"><a href="/forum.php?id='.$forumid.'&amp;do=new">' $lang['newthread'] . '</a></div>';

                    
$query mysql_query("SELECT COUNT(*) FROM `threads` WHERE `forum` ='$forumid'");
                    if(
intval(mysql_result($query0)) > 0){

                        
$nthreads mysql_result($query0);
                        
$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($query0));
                                if(
$postsCount 0){
                                    
$query mysql_query('SELECT `poster` FROM `posts` WHERE `thread` = '' . $pid . '' ORDER BY `date` DESC LIMIT 0, 1;');
                                    
$result intval(mysql_result($query0));
                                    
$lastbyid $result;
                                    
$lastby getusername($lastbyid);
                                }else{
                                    
$lastbyid $pin['poster'];
                                    
$lastby $puser;
                                }

                                if(
$plocked)
                                    
$lstext '[X]';
                                else
                                    
$lstext '';

                                if(
checkmod()){
                                    
$edl ' <a href="/forum.php?id=' $forumid '&amp;do=edit&amp;tid=' $pid '">[E]</a>';
                                    
$dll ' <a href="/forum.php?id=' $forumid '&amp;do=delete&amp;tid=' $pid '">[D]</a>';
                                }else{
                                    
$edl '';
                                    
$dll '';
                                }

                                echo 
'<div class="list2">
                                <a href="/thread.php?id=' 
$pid '">' $ptitle ' (' $postsCount ')[^]' $lstext '</a> / (' date('d/m/Y'$pdate) . ', ' $lang['bywho'] . ': <b><a href="/profile.php?id=' $pin['poster'] . '">' $puser '</a></b>, ' $lang['lastpost'] . ': <b><a href="/profile.php?id=' $lastbyid '">' $lastby '</a></b>) <a href="/thread.php?id=' $pid '&amp;page=last">&gt;&gt;</a>' $edl $dll '</div>';
                            }
                        }

                        
$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($query0));
                            if(
$postsCount 0){
                                
$query mysql_query('SELECT `poster` FROM `posts` WHERE `thread` = '' . $tid . '' ORDER BY `date` DESC LIMIT 0, 1;');
                                
$result intval(mysql_result($query0));
                                
$lastbyid $result;
                                
$lastby getusername($lastbyid);
                            }else{
                                
$lastbyid $thread['poster'];
                                
$lastby $tuser;
                            }

                            if(
$tlocked)
                                
$lstext '[X]';
                            else
                                
$lstext '';

                            if(
checkmod()){
                                
$edl ' <a href="/forum.php?id=' $forumid '&amp;do=edit&amp;tid=' $tid '">[E]</a>';
                                
$dll ' <a href="/forum.php?id=' $forumid '&amp;do=delete&amp;tid=' $tid '">[D]</a>';
                            }else{
                                
$edl '';
                                
$dll '';
                            }

                            echo 
'<div class="list2">
                            <a href="/thread.php?id=' 
$tid '">' $ttitle ' (' $postsCount ')
                            <a href="/thread.php?id=' 
$tid '&amp;page=last">&gt;&gt;</a>'.$edl.$dll.$lstext.'</a><br />
                            ('
.date('d/m/Y'$tdate).', '.$lang['bywho'].': <b><a href="/profile.php?id=' $thread['poster'] . '">' $tuser '</a></b>, ' $lang['lastpost'] . ': <b><a href="/profile.php?id=' $lastbyid '">' $lastby '</a></b>)</div>';
                        }

                        if(
$page 1){
                            
$bp $page 1;
                            
$bl '<a href="/forum.php?id=' $forumid '&amp;page=' $bp '">&lt; ' $lang['backward'] . '</a>';
                        }else
                            
$bl '&lt; ' $lang['backward'];

                        if(
$page $npages){
                            
$fp $page 1;
                            
$fl ' | <a href="/forum.php?id=' $forumid '&amp;page=' $fp '">' $lang['forward'] . ' &gt;</a>';
                        }
                        else
                            
$fl ' | ' $lang['forward'] . ' &gt;';
                        echo 
'<div class="list2">' $bl $fl '</div>
                        <div class="list2"><a href="/index.php">' 
$lang['back'] . '</a></div>';
                    }else{
                        echo 
'<div class="list2">' $lang['nothreads'] . '</div>
                        <div class="list2"><a href="/index.php">' 
$lang['back'] . '</a></div>';
                    }
                }
            }else{
                echo 
theader($lang['forums']);
                echo 
'<div class="list2">' $lang['forumnotexists'] . '</div>
                <div class="list2"><a href="/index.php">' 
$lang['back'] . '</a></div>';
            }

            echo 
tfooter();
        }else{
            echo
'<div class="list2">'.$lang['error'].'</div>';
        }
    }else{
        echo
'<div class="list2">'.$lang['error'].'</div>';
    }

    exit();

?>
Онлайн: 2
Реклама