Просмотр файла forum/core.php

Размер файла: 72.45Kb
<?php
include("conf.php");
include "include.inc";

function unicodes ($s)
{
                if ( (ord($s)>=192) & (ord($s)<=255) ) $hexvalue=dechex(ord($s)+848);
                if ($s=="") $hexvalue="401";
                 if ($s=="") $hexvalue="451"; return("&#x0".$hexvalue.";");
}
function utf ($s)
 {
               return(preg_replace("/[-]/e","unicodes('\\0')",$s));
 }



/////////////////////////////////Protect against SQL-injections///////////////
if(!get_magic_quotes_gpc())
{
$_GET = array_map('trim', $_GET);
$_POST = array_map('trim', $_POST);
$_COOKIE = array_map('trim', $_COOKIE);

$_GET = array_map('addslashes', $_GET);
$_POST = array_map('addslashes', $_POST);
$_COOKIE = array_map('addslashes', $_COOKIE);
}
//////////////////////////////////////////////////////////////////////////////


///////////////////////////////////Connect to db//////////////////////////////
function connect($dbuser,$dbpass,$dbserver,$dbname)
              {
//global $conn;
$conn=@mysql_connect($dbserver,$dbuser,$dbpass);       //connect to mysql db
if (!$conn) echo "<b>Не могу соединиться с базой!</b><br/>";
$db=@mysql_select_db($dbname);                       //select mysql db
if (!$db) echo "<b>Не могу выбрать базу!</b><br/>";
mysql_query ("set character_set_client='cp1251'");
mysql_query ("set character_set_results='cp1251'");
mysql_query ("set collation_connection='cp1251_general_ci'");
              }
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////Get buttons///////////////////////////////
if ($loginbtn=="") $logintext="Вход"; else $logintext="<a href=\"\"><img src=\"$loginbtn\"/></a>";
if ($reloginbtn=="") $relogintext="Войти заново"; else $logintext="<a href=\"\"><img src=\"$loginbtn\"/></a>";
if ($registerbtn=="") $registertext="Регистрация"; else $registertext="<a href=\"\"><img src=\"$registerbtn\"/></a>";
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////Get forums/////////////////////////////////
function getforums($permissions,$nick,$pass,$page)
        {
        echo "<hr/><br/>";
        global $logged;
                $page=$page-1;
         if (!$page==0) $pagest=$page*20; else $pagest=0;
         $userforum=mysql_query("SELECT name,perms,id FROM forums ORDER BY position LIMIT $pagest,20");
         while ($row = mysql_fetch_array($userforum))
              {
                  $postu=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM posts WHERE thread=1 AND forum='".$row[2]."'"));
                  $postuviso=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM posts WHERE forum='".$row[2]."'"));
                  if ($row[1]=="0") {$txtass=htmlspecialchars($row[0]);

                   echo "<div class=\"blue\"><a href=\"index.php?action=viewforum&amp;id=$row[2]&amp;nick=$nick&amp;pass=$pass&amp;page=1\"><font color=\"#FFFF00\">$txtass</font></a>";
                   echo "<font color=\"#FF0000\"> ($postu[0] ,$postuviso[0])</font>";
                   echo "</div>";}
                   
                  if ($row[1]=="1" AND $logged) {$txtass=htmlspecialchars($row[0]);
                  echo "<div class=\"blue\"><a href=\"index.php?action=viewforum&amp;id=$row[2]&amp;nick=$nick&amp;pass=$pass&amp;page=1\"><font color=\"#FFFF00\">$txtass</font></a>";
                   echo "<font color=\"#FF0000\"> ($postu[0] ,$postuviso[0])</font>";
                   echo "</div>";}
                  if ($row[1]=="2" AND $logged) {
                          $forribdforums=mysql_query("SELECT forum FROM permissions WHERE name='".$nick."'");
                           while ($frumas=mysql_fetch_array($forribdforums)) {
                            if ($frumas[0]==$row[2] or $frumas[0]=="*") {
                            $txtass=htmlspecialchars($row[0]); echo "<div class=\"blue\"><a href=\"index.php?action=viewforum&amp;id=$row[2]&amp;nick=$nick&amp;pass=$pass&amp;page=1\"><font color=\"#FFFF00\">$txtass$txtass</font></a><br/>";
                   echo "<font color=\"#FF0000\"> ($postu[0], $postuviso[0])</font>";
                   echo "</div><br/>";
                           }}
                          }
              }
         echo "<hr/><br/>";
        }
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////Login//////////////////////////////////////
function login($username,$pass)
        {
       
        
         global $logged;
         global $banned;
         $banned=false;
         $pwd=md5($pass);
         $pasw=mysql_fetch_array(mysql_query("SELECT pass FROM users WHERE name='".$username."'"));
         $paswd=$pasw[0];
         if ($paswd==$pwd) {
                 $banas=mysql_fetch_array(mysql_query("SELECT banned FROM users WHERE name='".$username."'"));
                 if ($banas[0] != 1) {
                 $logged=true; echo "<font color=\"#FF0000\">Вы вошли как $username</font>";} else {
                  $baninfo=mysql_fetch_array(mysql_query("SELECT banto FROM users WHERE name='".$username."'"));
                  if ($baninfo[0]-time()<0) {mysql_query("UPDATE users SET banned='0' WHERE name='".$username."'"); login($username,$pass);} else {
                           $tleft=$baninfo[0]-time();
                           $banupdate=mysql_fetch_array(mysql_query("SELECT banreason FROM users WHERE name='".$username."'"));
                           $banupdate=htmlspecialchars($banupdate[0]);
                           echo "<font color=\"#FF0000\">Вас забанили!<br/>Разбан через: $tleft<br/>$banupdate</font>";
                           $logged=false;
                           $banned=true;
                           };
                 }
                 } else {echo "<font color=\"#FF0000\">Вы не вошли в систему!</font>"; $logged=false;}
        }
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////Silent login///////////////////////////////
function slogin($username,$pass)
        {
        
        
         global $logged;
         global $banned;
         $banned=false;
        
         
         $pwd=md5($pass);
         $pasw=mysql_fetch_array(mysql_query("SELECT pass FROM users WHERE name='".$username."'"));
         $paswd=$pasw[0];
         if ($paswd==$pwd) {
                 $banas=mysql_fetch_array(mysql_query("SELECT banned FROM users WHERE name='".$username."'"));
                 if ($banas[0] != 1) {
                 $logged=true;} else {
                  $baninfo=mysql_fetch_array(mysql_query("SELECT banto FROM users WHERE name='".$username."'"));
                  if ($baninfo[0]-time()<0) {mysql_query("UPDATE users SET banned='0' WHERE name='".$username."'"); login($username,$pass);} else {
                           $logged=false;
                           $banned=true;
                           };
                 }
                 } else {$logged=false;}
        }
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////Register///////////////////////////////////
function register($username,$pass)
        {
        $flag1=0;
        $flag2=0;
        $users=$username;
         $username=ConvUtf8ToWin($username);


require_once"translit.php";


         $emc=0;
         $countname=strlen($username);
         for ($er=0;$er<$countname;$er++){
         $fr=0;
         for($em=0;$em<$countall;$em++){
         if ($username[$er]==$all_array[$em])
         $fr=1;
         }
         if ($fr==0)
         $emc=1;
        }


         $coun_name_eng=count($name_eng);
         $coun_win_name=count($winnameru);
         for($ee=0;$ee<$coun_win_name;$ee++){
         if (strpos("$username","$winnameru[$ee]")!==false)
         $flag1=1;
         }

         for($ea=0;$ea<$coun_name_eng;$ea++){
         if (strpos("$username","$name_eng[$ea]")!==false)
         $flag2=1;
         }

         $useris=mysql_fetch_array(mysql_query("SELECT pass FROM users WHERE name LIKE '".$username."'"));
         if ($useris[0]) "Имя уже занято, выберите другое."; else
           {

           if ($emc!==1){
            if ($flag1!==$flag2){
            if (!$username==null) {
            if (!$pass==null) {
            $username=$users;
            $hashedpass=md5($pass);
            $inserting=mysql_query("INSERT INTO users SET name='".$username."',
            pass='".$hashedpass."', pluses='0', status='1', site='http://', avatar='http://', bannedby='unknown'");
            if ($g=1)

            if ($inserting) { echo "Вы теперь наш зарегистрированный пользователь!";
            global $memberban;
            $bantoo=time()+$memberban;
            /*mysql_query("UPDATE users SET banned='1', banto='".$bantoo."', bannedby='Reg-Ban', banreason='Новые пользователи автоматически получают короткий бан' WHERE name='".$username."'");*/} else echo "Ошибка! Свяжитесь с администратором!";
           } else echo "Поле пароля пусто!";} else echo "Вы не можете использовать этот ник!!";}
           else "Вы не можете одноврименно использовать русские и аглиские символы";
        }
    else echo "Вы не можете использовать никакие другие символы кроме русских и англиских букв и символов !$%*[],.?:=+-|~')( ";
        }}
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////Get posts/////////////////////////////////
function getposts($id,$nick,$pass,$page)
        {
        slogin($nick,$pass);
        global $banned;
      //  $letssee=false;
        if (!$banned) {
         $page=$page-1;
         if (!$page==0) $page=$page*15; else $page=0;
         $pagemore=$page+15;
         $pinnedposts=mysql_query("SELECT id, name FROM posts WHERE forum='".$id."' AND thread='1' AND pinned='1' ORDER BY position LIMIT ".$page.",10");
         $kiekpinnintu=mysql_num_rows($pinnedposts);
         $ikipage=10-$kiekpinnintu;
         if ($ikipage<0) $ikipage=0;
         $userposts=mysql_query("SELECT id, name FROM posts WHERE forum='".$id."' AND thread='1' AND pinned='0' ORDER BY position LIMIT ".$page.",15");


            echo "<br/>";
            while ($rowas = mysql_fetch_array($pinnedposts))
              {
              $isclosed=mysql_fetch_array(mysql_query("SELECT closed FROM posts WHERE name='".$rowas[1]."' AND forum='".$id."'"));
              
              $postu=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM posts WHERE forum='".$id."' AND name='".$rowas[1]."'"));
              $rowas[1]=htmlspecialchars($rowas[1]);
              $enc=base64_encode($rowas[1]);
               $idpost=mysql_fetch_array(mysql_query("SELECT id FROM posts WHERE name='".$rowas[1]."' AND forum='".$id."'"));
              if ($isclosed[0]==1) $clstxt="<b>[Close]</b>"; else $clstxt="";
               echo "<div class=\"blue\"><b>Закреплена::</b>"; echo "$clstxt<a href=\"index.php?action=viewpost&amp;idp=$idpost[0]&amp;nick=$nick&amp;pass=$pass&amp;forumas=$id&amp;read=new&amp;page=1\"> $rowas[1]</a>(".$postu[0].")</div>"; echo "<br/>";
              }
              echo "<br/>";
           while ($rowas = mysql_fetch_array($userposts))
              {
              $postby=mysql_fetch_array(mysql_query("SELECT postedby FROM posts WHERE name='".$rowas[1]."' AND forum='".$id."'"));
              $postdate=mysql_fetch_array(mysql_query("SELECT date FROM posts WHERE name='".$rowas[1]."' AND forum='".$id."'"));
              $isclosed=mysql_fetch_array(mysql_query("SELECT closed FROM posts WHERE name='".$rowas[1]."' AND forum='".$id."'"));
              $postu=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM posts WHERE forum='".$id."' AND name='".$rowas[1]."'"));
              $idpost=mysql_fetch_array(mysql_query("SELECT id FROM posts WHERE name='".$rowas[1]."' AND forum='".$id."'"));
              
              
              $rowas[1]=htmlspecialchars($rowas[1]);
              
              $enc=base64_encode($rowas[1]);
              if ($isclosed[0]==1) $clstxt="<b>[Close]</b>"; else $clstxt="";
               echo "<div class=\"blue\"><font color=\"#FF0000\"><b>$clstxt $postby[0]</b></font> <small><font color=\"#FF00FF\">($postdate[0])</font></small><br/><a href=\"index.php?action=viewpost&amp;idp=$idpost[0]&amp;nick=$nick&amp;pass=$pass&amp;forumas=$id&amp;read=new&amp;page=1\"><font color=\"#FFFF00\">$rowas[1]</font></a> <font color=\"#00FFFF\">(".$postu[0].")</font></div>";
              }
              
             /* } else echo "Cannot view<br/><a href=\"index.php?nick=$nick&amp;pass=$pass\">Back</a>"; */
              } else echo "<font color=\"#FF0000\">Тебя выебали!</font><br/>";
        }
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////New thread or post/////////////////////////////
function post($thread,$nick,$pass,$tname,$ttext,$forumas,$phone)
        {
        $lastpostt=mysql_fetch_array(mysql_query("SELECT lastpost FROM users WHERE name='".$nick."'"));
        $lastpostt2=mysql_fetch_array(mysql_query("SELECT lastthread FROM users WHERE name='".$nick."'"));
              global $antiflood;
              global $antiflood2;
             if ($thread==1) { if (time() < $lastpostt2[0]+$antiflood2) { echo "FloodControl: "; echo $antiflood2-(time()-$lastpostt2[0]); echo "<br/>Thread NOT added<br/>"; $canpostthis=false;} else $canpostthis=true;}
             if ($thread==0) { if (time() < $lastpostt[0]+$antiflood) { echo "FloodControl: "; echo $antiflood-(time()-$lastpostt[0]); echo "<br/>Message NOT added<br/>"; $canpostthis=false;} else $canpostthis=true;}
             if ($canpostthis) {
         $pradinisn=$tname;
         global $timezone;
        $valandos=date("H")+$timezone;
        if ($valandos>23) $valandos=$valandos-24;
        $data=date("d.m-".$valandos.":i");
         $tnameas=htmlspecialchars($tname);
         $ttextas=htmlspecialchars($ttext);
         $ttext=str_replace("$","*",$ttext);
         $tname=str_replace("$","",$tname);
         $tname=str_replace("&lt;","",$tname);
         $tname=str_replace("<","",$tname);
         $tname=str_replace(">","",$tname);
         $tname=str_replace("&gt;","",$tname);
         $tname=str_replace("\"","",$tname);
         $tname=str_replace("'","",$tname);
         $tname=str_replace("\\","",$tname);
         $tname=str_replace("&","",$tname);
         if (is_string($tname)) {
         $canpost=true;
         if ($tname==null) $canpost=false;
         if ($canpost==true) {
         if ($thread==1) {$sqlq=mysql_query("SELECT name FROM posts WHERE forum='".$forumas."'");
         while ($namee=mysql_fetch_array($sqlq))
                  {
                    if ($namee[0]==$tname) { echo "<font color=\"#FF0000\">Такое название сообщения уже существует!<br/></font>"; $canpost=false;}
                    if ($namee[0]==$pradinisn) { echo "<font color=\"#FFFF00\">Придумайте другое название темы<br/></font>"; $canpost=false;}
                  }}
         $sqlq=mysql_query("SELECT text FROM posts WHERE forum='".$forumas."' AND name='".$tname."'");
         while ($namee=mysql_fetch_array($sqlq))
                  {
                    if ($namee[0]==$ttext) { echo "<font color=\"#00FFFF\">Такой текст уже существует!<br/></font>"; $canpost=false;}
                  }
         if ($canpost==true)
                  {
                    $pwdp=md5($pass);
                    $paswp=mysql_fetch_array(mysql_query("SELECT pass FROM users WHERE name='".$nick."'"));
                    $paswdp=$paswp[0];
                    if ($paswdp==$pwdp) {
                                         if ($thread==1)
                                               {
                                                 mysql_query("UPDATE users SET lastthread='".time()."' WHERE name='".$nick."'");
                                                $aryraforumas=mysql_fetch_array(mysql_query("SELECT id FROM forums WHERE id='".$forumas."'"));
                                                if ($aryraforumas[0]!=null) {
                                                $fulltext="$ttext";
                                                $pozicijaa=mysql_fetch_array(mysql_query("SELECT MAX(position) FROM posts WHERE forum='".$forumas."' AND thread='1' AND name='".$tname."'"));
                                                $pozicija=$pozicijaa[0]+1;
                                                //$pozicija++;
                                                $currpoz=mysql_fetch_array(mysql_query("SELECT MIN(position) FROM posts WHERE forum='".$forumas."' AND thread='1'"));
                                                $currpoz=$currpoz[0]-1;
                                                $permsai=mysql_fetch_array(mysql_query("SELECT perms FROM forums WHERE id='".$forumas."'"));
                                                $sent=mysql_query("INSERT INTO posts SET forum='".$forumas."',
                                                name='".$tname."', text='".$ttext."', thread='".$thread."',
                                                position='".$currpoz."', perms='".$permsai[0]."', postedby='".$nick."', pinned='0', date='".$data."'");
                                                if ($sent) echo "Ваше сообщение успешно добавлено!"; else echo "ОШИБКА!";
                                                } else echo "Такой форум не существует!";
                                               }
                                         if ($thread==0)
                                               {
                                                 mysql_query("UPDATE users SET lastpost='".time()."' WHERE name='".$nick."'");
                                                $aryratema=mysql_fetch_array(mysql_query("SELECT name FROM posts WHERE name='".$tname."' AND thread='1'"));
                                                  if ($aryratema[0]!=null) {
                                                $fulltext="$ttext";
                                                $pozicijaa=mysql_fetch_array(mysql_query("SELECT MAX(position) FROM posts WHERE forum='".$forumas."' AND thread='0' AND name='".$tname."'"));
                                                $pozicija=$pozicijaa[0]+1;
                                                //$pozicija++;
                                                $permsai=mysql_fetch_array(mysql_query("SELECT perms FROM forums WHERE id='".$forumas."'"));
                                                $sent=mysql_query("INSERT INTO posts SET forum='".$forumas."',
                                                name='".$tname."', text='".$ttext."', thread='".$thread."',
                                                position='".$pozicija."', perms='".$permsai[0]."', postedby='".$nick."', date='".$data."'");
                                                $currpoz=mysql_fetch_array(mysql_query("SELECT MIN(position) FROM posts WHERE forum='".$forumas."' AND thread='1'"));
                                                $currpoz=$currpoz[0]-1;
                                                $sent2=mysql_query("UPDATE posts SET position='".$currpoz."' WHERE thread='1' AND name='".$tname."'");
                                                if ($sent and $sent2) echo "Ваше сообщение было успешно добавлено!"; else echo "ОШИБКА!";
                                                } else echo "Эта тема не существует!";
                                               }

                                                        $phnupdated=mysql_query("UPDATE users SET tlphone='".$phone."' WHERE name='".$nick."'");

                                             //  $postuuseristuri=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM posts WHERE postedby='".$nick."'"));
                                             //  if (fmod($postuuseristuri[0],10)==0)
                                             //   {
                                                 $pliusiuku=mysql_fetch_array(mysql_query("SELECT pluses FROM users WHERE name='".$nick."'"));
                                                 $pliusiuku=$pliusiuku[0]+1;
                                                 $apdeitinta=mysql_query("UPDATE users SET pluses='".$pliusiuku."' WHERE name='".$nick."'");
                                                 $pliusiuku=mysql_fetch_array(mysql_query("SELECT postno FROM users WHERE name='".$nick."'"));
                                                 $pliusiuku=$pliusiuku[0]+1;
                                                 $apdeitinta=mysql_query("UPDATE users SET postno='".$pliusiuku."' WHERE name='".$nick."'");
                                                 if ($apdeitinta) echo "";
                                              //  };
                                       } else echo "You are not logged in!";
                  }
                  } else echo "Вы не можете использовать такое название темы!";
                  } else echo "Можно использовать только буквы в названии темы!";
                  };
        }
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////Read the desired post/////////////////////
function getpost($nick,$pass,$post,$read,$page,$id,$forumas,$poststot,$idp)
        {
        
        //$post=htmlspecialchars($post);
       slogin($nick,$pass);
        $letssee=false;
        global $banned;
        if (!$banned) {
     //   if ($page==1) $pagest=0; else $pagest=$page*$page+1;
 $page=$page-1;
         if (!$page==0) $pagest=$page*10; else $pagest=0;
        $pagemore=$page*10;
        $pwdp=md5($pass);
                   	/*	$paswp=mysql_fetch_array(mysql_query("SELECT pass FROM users WHERE name='".$nick."'"));
                    $paswdp=$paswp[0];
                    if ($paswdp==$pwdp) {*/
           $fperms=mysql_fetch_array(mysql_query("SELECT perms FROM posts WHERE name='".$post."' AND forum='".$forumas."'"));

                  if ($fperms[0]=="0") {$letssee=true;}
                  if ($fperms[0]=="1") {$letssee=true;}
                  if ($fperms[0]=="2") {
                          $forribdforums=mysql_query("SELECT forum FROM permissions WHERE name='".$nick."'");
                           while ($frumas=mysql_fetch_array($forribdforums)) {
                            if ($frumas[0]==$forumas or $frumas[0]=="*") {
                            $letssee=true;
                           }}
                          }

           if ($letssee==true) {
         if ($read=="old") $postas=mysql_query("SELECT text, postedby, id, date FROM posts WHERE name='".$post."' AND forum='".$forumas."' ORDER BY position LIMIT ".$pagest.",10"); else
         $postas=mysql_query("SELECT text, postedby, id, date FROM posts WHERE name='".$post."' AND forum='".$forumas."' ORDER BY position DESC LIMIT ".$pagest.",10"); // ".$pagemore."
         while ($postass=mysql_fetch_array($postas))
           {

             //$postass[0]=htmlentities($postass[0]);
             //$postass[0]=str_replace('$','&#36;',$postass[0]);
             ismod($nick,$pass,$forumas);
             global $moderator;
             $postencrpt=base64_encode($post);
             $areweatthread=mysql_fetch_array(mysql_query("SELECT thread FROM posts WHERE id='".$postass[2]."'"));
              

             
             if ($moderator and $areweatthread[0]!=="1") $modlinks="<a href=\"index.php?action=modlinks&amp;nick=$nick&amp;pass=$pass&amp;forumas=$forumas&amp;msg=$postass[2]\"><font color=\"#FF0000\">[M] </font></a>"; else $modlinks="";
             echo "<div class=\"blue\">";
             echo "<b><a href=\"index.php?action=viewuser&amp;nick=$nick&amp;pass=$pass&amp;who=$postass[1]\"><font color=\"#FF0000\">$postass[1]: </font></a></b> <font color=\"#FF00FF\">$modlinks</font>";
              $postass[0] = parsebb($postass[0]);
             $postass[0]=htmlspecialchars($postass[0]);
             $postass[0] = reparsebb($postass[0]);
$postass[0]=getmenow($postass[0]);

             //$postass[0] = parsebb2($postass[0]);
             if(strpos("$postass[0]","</a>")==false)
             if(strpos("$postass[0]","img")==false)
             {
             $postass[0]=WordWrap($postass[0],80,"<br/>");}
             echo "<small><font color=\"#00FF00\">($postass[3])</font></small>";
             echo "<br/><font color=\"#FFFF00\">$postass[0]</font>";
             echo "</div>";
           }
           //echo "<br/>";
           $prieshpg=$page;
           $kitaspg=$page+2;
           $post=base64_encode($post);
           if ($page+1<$poststot) echo "<a href=\"index.php?action=viewpost&amp;idp=$idp&amp;nick=$nick&amp;pass=$pass&amp;forumas=$forumas&amp;read=$read&amp;page=$kitaspg\"><font color=\"#00FF00\">Вперед&gt;&gt;</font></a><br/>";
           if ($page+1>1) echo "<a href=\"index.php?action=viewpost&amp;idp=$idp&amp;nick=$nick&amp;pass=$pass&amp;forumas=$forumas&amp;read=$read&amp;page=$prieshpg\"><font color=\"#00FFFF\">&lt;&lt;Назад</font></a>";
           //echo "<br/><div>";
           } else echo "<font color=\"#FF0000\">Просмотр недоступен</font><br/><a href=\"index.php?nick=$nick&amp;pass=$pass\"><font color=\"#FFFF00\">Хуерумы</font></a>";/*}*/  } else echo "<font color=\"#FF0000\">Тебя поимели!</font>";
        }
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////View user information///////////////////////
function viewuser($who,$nick,$pass)
         {
          $info=mysql_fetch_array(mysql_query("SELECT id, name, pluses, status, owntext, email, tlphone, site, avatar FROM users WHERE name='".$who."'"));
          $posts=mysql_fetch_array(mysql_query("SELECT postno FROM users WHERE name='".$who."'"));
          $info[1]=htmlspecialchars($info[1]);
          echo "<font color=\"#FF00FF\">Статистика юзера $info[1]</font><br/><br/>";
          global $moderator;
          ismod2($nick,$pass);
          $plusesupdate=mysql_fetch_array(mysql_query("SELECT plusreason FROM users WHERE name='".$who."'"));
          $banupdate=mysql_fetch_array(mysql_query("SELECT banreason FROM users WHERE name='".$who."'"));
          $plusesupdate=htmlspecialchars($plusesupdate[0]);
          $banupdate=htmlspecialchars($banupdate[0]);
          if ($plusesupdate[0]!="") {if (strtolower($who)==strtolower($nick)) echo "<font color=\"#FF0000\">Last PlusesUpdate: $plusesupdate</font><br/>";}
          if ($banupdate[0]!="") {if (strtolower($who)==strtolower($nick)) echo "<font color=\"#FFFFFF\">Последняя причина бана: $banupdate</font><br/>";}
          if ($plusesupdate[0]!="") {if ($moderator) echo "<font color=\"#00FFFF\">Last PlusesUpdate: $plusesupdate</font><br/>";}
          if ($banupdate[0]!="") {if ($moderator) echo "<font color=\"#00FF00\">Last BanReason: $banupdate</font><br/>";}
          echo "<a href=\"index.php?action=sendpm&amp;nick=$nick&amp;pass=$pass&amp;who=$info[1]\"><font color=\"#FFFF00\">Написать сообщение $info[1]</font></a><br/><br/>";
          echo "<font color=\"#FF0000\">ID: $info[0]</font><br/>";
          echo "<img src=\"$info[8]\" alt=\"\"/><br/>";
          echo "<font color=\"#FF00FF\">Постов: $posts[0]</font><br/>";
          include ("levels.php");        //We get variable $ustat (status) from file levels.php
          echo "<font color=\"#00FF00\">Статус: $ustat</font><br/>";
          echo "<font color=\"#00FFFF\">Pluses: $info[2]</font><br/>";
         // echo "Permission level: $info[3]<br/>";
          echo "<font color=\"#FFFF00\">Браузер: $info[6]</font><br/>";
          $info[5]=htmlspecialchars($info[5]);
          echo "<font color=\"#FF00FF\">E-Mail: $info[5]</font><br/>";
          echo "<font color=\"#00FF00\">WAP-сайт:</font> <a href=\"$info[7]\"><font color=\"#FF0000\">$info[7]</font></a><br/>";
          $info[4]=parsebb($info[4]);
          $info[4]=htmlspecialchars($info[4]);
          $info[4]=reparsebb($info[4]);
          echo "<font color=\"#00FFFF\">Подпись:"; echo "$info[4]<br/></font>";
           ismod2($nick,$pass);
         global $moderator;
         if ($moderator) {
          $aruzhbannintas=mysql_fetch_array(mysql_query("SELECT banned FROM users WHERE name='".$who."'"));
                         echo "<br/><a href=\"index.php?action=banuser&amp;nick=$nick&amp;pass=$pass&amp;who=$who\"><font color=\"#00FF00\">Забанить</font></a>";
                         echo "<br/><a href=\"index.php?action=unbanuser&amp;nick=$nick&amp;pass=$pass&amp;who=$who\"><font color=\"#FFFF00\">Разбанить</font></a>";

                 echo "<br/><a href=\"index.php?action=pluses&amp;nick=$nick&amp;pass=$pass&amp;who=$who&amp;pluses=$info[2]\"><font color=\"#00FFFF\">Add, subtract pluses</font></a><br/>";

                 if ($aruzhbannintas[0]=="1") {
                  $kiekliko=mysql_fetch_array(mysql_query("SELECT banto FROM users WHERE name='".$who."'"));
                         $kiekliko=$kiekliko[0]-time();
                         echo "<br/><font color=\"#FFFFFF\">Banned for another $kiekliko seconds</font><br/>";
                                              };
                }
         }
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////Draw UserCP/////////////////////////////////
function usercpget($nick,$pass)
         {
          $infoo=mysql_fetch_array(mysql_query("SELECT owntext, email, avatar, site FROM users WHERE name='".$nick."'"));
          $infoo[0]=htmlspecialchars($infoo[0]);
          $infoo[1]=htmlspecialchars($infoo[1]);
          $infoo[2]=htmlspecialchars($infoo[2]);
          $infoo[3]=htmlspecialchars($infoo[3]);
          echo "<form method=\"post\" action=\"update.php?nick=$nick&amp;pass=$pass\">";
          
          echo "<font color=\"#00FFFF\">Аватар:</font><br/> <input name=\"avataras\" maxlength=\"200\" value=\"$infoo[2]\"/><br/>";
          echo "<font color=\"#00FF00\">Мыло:</font><br/> <input name=\"email\" maxlength=\"50\" value=\"$infoo[1]\"/><br/>";
          echo "<font color=\"#FFFF00\">Сайт:</font><br/> <input name=\"svetajne\" maxlength=\"50\" value=\"$infoo[3]\"/><br/>";
          echo "<font color=\"#FF00FF\">Подпись:</font><br/> <input name=\"owntext\" maxlength=\"100\" value=\"$infoo[0]\"/><br/><br/>";
           
           echo "<input type=\"submit\" value=\"Обновить\"/></form></div><div><hr/>";
          
          echo "<br/><b><font color=\"#FF0000\">Изменить Пароль</font></b><br/>";
          echo "<form method=\"post\" action=\"chpwd.php?nick=$nick&amp;pass=$pass\">";
        
        echo "<font color=\"#FFFF00\">Новый пароль:</font><br/><input  name=\"npass1\" type=\"password\" value=\"\" size=\"12\" maxlength=\"12\" /><br/>";
        echo "<font color=\"#00FFFF\">Повторите пароль:</font><br/><input  name=\"npass2\" type=\"password\" value=\"\" size=\"12\" maxlength=\"12\" /><br/><br/>";
        echo "<input type=\"submit\" value=\"Изменить\"/>";
        echo "</form></div><div>";
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////Get PM's////////////////////////////////////
function private($nick,$pass,$page)
         {
                   //if ($page==1) $pagest=0; else $pagest=$page*$page+1;
                  $page=$page-1;
         if (!$page==0) $pagest=$page*5; else $pagest=0;
                   $pagemore=$page*5;
                   $pms=mysql_query("SELECT unread,sentby,id FROM private WHERE sentto='".$nick."' ORDER BY id DESC LIMIT ".$pagest.",5");
                   if ($pms) {
                   while ($pm=mysql_fetch_array($pms))
                           {
                            if ($pm[0]==y) $nw="<font color=\"#FF0000\">(new)</font>"; else $nw="";
                            echo "<a href=\"index.php?action=readpm&amp;nick=$nick&amp;pass=$pass&amp;pm=$pm[2]\"><font color=\"#FFFF00\">$nw$pm[1]</font></a><br/>";
                           } } else echo "<font color=\"#FFFF00\">У вас нет входящих сообщений!</font>";
         };
/////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////Send PM//////////////////////////////
function sendpm($nick,$pass,$who,$ttextas)
         {
          global $logged;
          $valandos=date("H")+$timezone;
        if ($valandos>23) $valandos=$valandos-24;
        $data=date("[d.m.y - ".$valandos.":i:s]");
        $lastpostt=mysql_fetch_array(mysql_query("SELECT MAX(timesent) FROM private WHERE sentby='".$nick."'"));
              global $pmantiflood;
             if (time() < $lastpostt[0]+$pmantiflood) {echo "Сообщение не отправлено!";} else
             {
          //$ttextas=str_replace("$","$$",$ttextas);
          echo login($nick,$pass);
          echo "<br/>";
          if ($logged) {
          $artoxyra=mysql_fetch_array(mysql_query("SELECT name FROM users WHERE name='".$who."'"));
          if ($artoxyra[0]) {
          $pmsent=mysql_query("INSERT INTO private SET unread='y', sentby='".$nick."', sentto='".$who."', text='".$ttextas."', date='".$data."', timesent='".time()."'");
          if ($pmsent) {echo "<font color=\"#00FF00\">Сообщение успешно отправлено!</font><br/>";
          $ttextas=parsebb($ttextas);
          $ttextas=htmlspecialchars($ttextas);
                     $rparsedtxtas=reparsebb($ttextas);
                     echo $rparsedtxtas;} else echo "<font color=\"#FF0000\">ОШИБКА!</font>";} else echo "<font color=\"#FF0000\">Пользователь не существует!</font>";
         } else echo "<font color=\"#FF0000\">Войдите в систему перед отправлением сообщений!</font>";};};
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////Read PM///////////////////////////////
function readpm($nick,$pass,$pm)
         {
          $pminfo=mysql_fetch_array(mysql_query("SELECT id,unread,sentby,sentto,text,date FROM private WHERE id='".$pm."'"));
          if (strtolower($pminfo[3])==strtolower($nick))
                  {
                   mysql_query("UPDATE private SET unread='n' WHERE id='".$pm."'");
                   echo "<font color=\"#00FF00\">Письмо от: $pminfo[2]</font><br/><font color=\"#FF00FF\">$pminfo[5]</font><br/><br/>";

                   $pminfo[4]=parsebb($pminfo[4]);
                   $pminfo[4]=htmlspecialchars($pminfo[4]);
                    echo reparsebb($pminfo[4]);
                   echo "<br/><br/>";
                   //echo "$pminfo[4]<br/><br/>";
                   echo "<a href=\"index.php?action=sendpm&amp;nick=$nick&amp;pass=$pass&amp;who=$pminfo[2]\"><font color=\"#00FFFF\">Ответить</font></a><br/>";
                   echo "<a href=\"delpm.php?nick=$nick&amp;pass=$pass&amp;who=$pminfo[0]\"><font color=\"#FF00FF\">Удалить</font></a>";
                  } else echo "<font color=\"#FF0000\">Хочешь прочесть то, что адресовано не тебе? Ха ха!</font>";
         };
/////////////////////////////////////////////////////////////////////////////


////////////////////////////////////Forum stats//////////////////////////////
function stats($nick,$pass)
         {
          $useriu=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM users"));
          $maxid=mysql_fetch_array(mysql_query("SELECT MAX(id) FROM users"));
          $paskutinis=mysql_fetch_array(mysql_query("SELECT name FROM users WHERE id='".$maxid[0]."'"));
          $postu=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM posts"));
          $temu=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM posts WHERE thread='1'"));
          $privates=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM private"));
          echo "<font color=\"#FF0000\">Всего захуярено: <b>$useriu[0]</b></font><br/><font color=\"#FF00FF\">Последний захуяченный хуеплет: </font><a href=\"index.php?action=viewuser&amp;nick=$nick&amp;pass=$pass&amp;who=$paskutinis[0]\"><font color=\"#00FFFF\">$paskutinis[0]</font></a><br/>";
          echo "<font color=\"#FFFF00\">Всего пиздежа: <b>$postu[0]</b></font><br/><font color=\"#00FF00\">Всего тем:<b>$temu[0]</b></font><br/>";
          echo "<font color=\"#FF0000\">Отправлено личного пиздежа: <b>$privates[0]</b></font><br/>";
          $lankytoju=mysql_fetch_array(mysql_query("SELECT visitors FROM counter"));
          echo "<font color=\"#FF00FF\">Щетчик: $lankytoju[0]</font><br/><hr/>";
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////Get the memberlist//////////////////////////
function membersget($nick,$pass,$whattoget,$page)
         {
         // if ($page==1) $pagest=0; else $pagest=$page*$page+1;
          $page=$page-1;
         if (!$page==0) $pagest=$page*5; else $pagest=0;
          if ($whattoget=="id") $nariai=mysql_query("SELECT name,pluses FROM users ORDER BY id DESC LIMIT ".$pagest.", 5");
          if ($whattoget=="name") $nariai=mysql_query("SELECT name,pluses FROM users ORDER BY name LIMIT ".$pagest.", 5");
          while ($narys=mysql_fetch_array($nariai))
             {
              $postu=mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM posts WHERE postedby='".$narys[0]."'"));
              echo "<a href=\"index.php?action=viewuser&amp;nick=$nick&amp;pass=$pass&amp;who=$narys[0]\">Имя: $narys[0], Постов: $postu[0], Pluses: $narys[1]</a><br/>";
             };
         };
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////Search////////////////////////////////////
function search($nick,$pass,$ttextas,$page)
         {
       //  if ($page==1) $pagest=0; else $pagest=$page*$page+1;
        $page=$page-1;
         if (!$page==0) $pagest=$page*5; else $pagest=0;
          $permsai=mysql_fetch_array(mysql_query("SELECT status FROM users WHERE name='".$nick."'"));
          $results=mysql_query("SELECT name,perms,forum FROM posts WHERE text LIKE '%".$ttextas."%'");
          $srchtot=mysql_num_rows($results);
          $results=mysql_query("SELECT id,perms,forum,name FROM posts WHERE text LIKE '%".$ttextas."%' LIMIT ".$pagest.", 5");
          $srchtot=$srchtot-1;
           $srchtot=ceil($srchtot/5);
           $srchtot=$srchtot;
          while ($resultai=mysql_fetch_array($results))
            {
             $postenc=$resultai[0];
             $letssee=false;

             $fperms=mysql_fetch_array(mysql_query("SELECT perms FROM forums WHERE id='".$resultai[2]."'"));

                  if ($fperms[0]=="0") {$letssee=true;}
                  if ($fperms[0]=="1") {$letssee=true;}
                  if ($fperms[0]=="2") {
                          $forribdforums=mysql_query("SELECT forum FROM permissions WHERE name='".$nick."'");
                           while ($frumas=mysql_fetch_array($forribdforums)) {
                            if ($frumas[0]==$resultai[2] or $frumas[0]=="*") {
                            $letssee=true;
                           }}
                          }

             if ($letssee==true) echo "<a href=\"index.php?action=viewpost&amp;idp=$postenc&amp;nick=$nick&amp;pass=$pass&amp;forumas=$resultai[2]&amp;read=new&amp;page=1\"><font color=\"#FFFF00\">$resultai[3]</font></a><br/>";
            };
          $pagefrw=$page+2;
        $pagepws=$page;
        echo "<br/>";
        if ($page<$srchtot-1) {
        
        echo "<br/>";
        echo "<a href=\"search.php?nick=$nick&amp;pass=$pass&amp;page=$pagefrw\"><font color=\"#FF00FF\">Вперед</font></a><br/>";
                            };
        $page=$page-1;
        if ($page>-1) {
        echo "<a href=\"search.php?nick=$nick&amp;pass=$pass&amp;page=$pagepws\"><font color=\"#00FF00\">Назад</font></a><br/>";
                      };
        $page=$page+2;
        if ($srchtot<1) $srchtot=1;
        echo "<font color=\"#00FFFF\">Страница: $page/$srchtot</font>";
        echo "<br/>";
         };
/////////////////////////////////////////////////////////////////////////////


////////////////////////////////Emoticons////////////////////////////////////
function parsebb($text)
         {
          //include("smilies.php");
          //$text=str_replace("http://","http:\\\\",$text);
        //  $text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\">\\0</a>", $text);
          $bbkoded=mysql_query("SELECT bbcode, changeto FROM smilies ORDER BY length(bbcode)");
          while ($zhiurim=mysql_fetch_array($bbkoded))
                {
                 $text=str_replace($zhiurim[0],"<img src=\"$zhiurim[1]\" alt=\"$zhiurim[0]\">",$text);
                };
          //echo "$text";
          return $text;
         };
/////////////////////////////////////////////////////////////////////////////


////////////////////////////////Emoticons////////////////////////////////////
function reparsebb($text)
         {
         $text=preg_replace("/\[b\](.*?)\[\/b\]/i","<b>\\1</b>", $text);
        


         
          $bbkoded=mysql_query("SELECT bbcode, changeto FROM smilies ORDER BY length(bbcode)");
          while ($zhiurim=mysql_fetch_array($bbkoded))
                {
                 $text=str_replace("&lt;img src=&quot;$zhiurim[1]&quot; alt=&quot;$zhiurim[0]&quot;&gt;","<img src=\"$zhiurim[1]\" alt=\"$zhiurim[0]\"/>",$text);
                };
          //$text = ereg_replace("[[:alpha:]]+<img src=\"smilies/dry.gif\" alt=\":/\"/>/\[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\">\\0</a>", $text);

          //echo "$text";
          return $text;
         };
/////////////////////////////////////////////////////////////////////////////
function getmenow($text)
{

if(strpos("$text","[a]")!==false)
if(strpos("$text","[/a]")!==false)
{
$htt=explode("[a]",$text);
if(isset($htt[1]))
$httm=explode("[/a]",$htt[1]);
}
$ker=$httm[0];
$ker=urlencode($ker);
$text=str_replace("[a]$httm[0][/a]","<a href=\"go.php?strn=$ker\">$httm[0]</a>",$text);
return $text;

}
function getmeimg($text)
{

if(strpos("$text","[img]")!==false)
if(strpos("$text","[/img]")!==false)
{
$htt=explode("[img]",$text);
if(isset($htt[1]))
$httm=explode("[/img]",$htt[1]);
}
$ker=$httm[0];
$ker=urlencode($ker);
$imsize=getimagesize($httm[0]);


$text=str_replace("[img]$httm[0][/img]","<a href=\"$httm[0]\"><img src=\"pic.php?id=$httm[0]\" alt=\"\"/></a>($imsize[0]x$imsize[1])",$text);
return $text;

}
///////////////////////////////////Online////////////////////////////////////
function onlineadd($nick)
         {
         $nick=ConvUtf8ToWin($nick);
          
          $taimautas_sekundem = 300;
          $laikas = time();
          $timeout = $laikas-$taimautas_sekundem;
           if ($nick!=null) {
          $insert = mysql_query("INSERT INTO online VALUES
          ('".$laikas."','".$nick."')");  }
          $deleted = mysql_query("DELETE FROM online WHERE laikas<".$timeout."");
         };
/////////////////////////////////////////////////////////////////////////////


////////////////////////////////////Get online users/////////////////////////
function onlineget($nick,$pass)
         {
          $result = mysql_query("SELECT DISTINCT username FROM online WHERE username IS NOT NULL");
          $vartotojai = mysql_num_rows($result);

          echo"<font color=\"#00FF00\">Онлайн хуеплетов:</font> <a href=\"index.php?action=online&amp;nick=$nick&amp;pass=$pass&amp;page=1\"><font color=\"#FF0000\">$vartotojai</font></a>";
         };
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////List online users/////////////////////
function onlinelist($nick,$pass,$page)
         {
          if ($page==1) $pagest=0; else $pagest=$page*$page+1;
          $nicks=mysql_query("SELECT DISTINCT username FROM online WHERE username IS NOT NULL LIMIT ".$pagest.",5");
          while ($nikas=mysql_fetch_array($nicks))
                 {
                  echo "<a href=\"index.php?action=viewuser&amp;nick=$nick&amp;pass=$pass&amp;who=$nikas[0]\">$nikas[0]</a><br/>";
                 };
         };
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////Is moderator?//////////////////////////
function ismod($nick,$pass,$forum)
         {
          global $moderator;
          $moderator=false;
          $pwd=mysql_fetch_array(mysql_query("SELECT pass FROM users WHERE name='".$nick."'"));
          if (md5($pass)==$pwd[0])
             {
              $forumsmod=mysql_query("SELECT forum FROM moderators WHERE name='".$nick."'");
              while ($forummod=mysql_fetch_array($forumsmod))
                    {
                     if ($forummod[0]==$forum) $moderator=true;
                     if ($forummod[0]=='*') $moderator=true;
                    }
             };
         };
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////Close topic////////////////////////////////
function close($nick,$pass,$idp,$forumas)
         {
         $name=mysql_fetch_array(mysql_query("SELECT name FROM posts WHERE id='".$idp."' AND forum='".$forumas."'"));
          $closed=@mysql_query("UPDATE posts SET closed='1' WHERE name='".$name[0]."' AND forum='".$forumas."'");
          if ($closed) echo "Тема закрыта!<br/>"; else echo "ОШИБКА!";
          addlog("<b>$nick</b> закрыл <b>$nameenc</b>");
         };
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////Open topic/////////////////////////////////
function open($nick,$pass,$idp,$forumas)
         {
         $name=mysql_fetch_array(mysql_query("SELECT name FROM posts WHERE id='".$idp."' AND forum='".$forumas."'"));
          $closed=@mysql_query("UPDATE posts SET closed='0' WHERE name='".$name[0]."' AND forum='".$forumas."'");
          if ($closed) echo "Тема открыта!<br/>"; else echo "ОШИБКА!";
          addlog("<b>$nick</b> отрыл <b>$nameenc</b>");
         };
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////Pin topic//////////////////////////////////
function pin($nick,$pass,$idp,$forumas)
         {
       $name=mysql_fetch_array(mysql_query("SELECT name FROM posts WHERE id='".$idp."' AND forum='".$forumas."'"));
          $closed=@mysql_query("UPDATE posts SET pinned='1 'WHERE   name='".$name[0]."' AND forum='".$forumas."'");
          if ($closed) echo "Тема заблокирована!<br/>"; else echo "ОШИБКА!";
          addlog("<b>$nick</b> заблокирова <b>$nameenc</b>");
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////Unpin topic/////////////////////////////////////
function unpin($nick,$pass,$idp,$forumas)
         {
$name=mysql_fetch_array(mysql_query("SELECT name FROM posts WHERE id='".$idp."' AND forum='".$forumas."'"));
          $closed=@mysql_query("UPDATE posts SET pinned='0'WHERE   name='".$name[0]."' AND forum='".$forumas."'");
          if ($closed) echo "Тема разблокирована!<br/>"; else echo "ОШИБКА!";
          addlog("<b>$nick</b> разблокировал <b>$nameenc</b>");
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////Delete topic////////////////////////////////////
function deletet($nick,$pass,$idp,$forumas)
         {
         $name=mysql_fetch_array(mysql_query("SELECT name FROM posts WHERE id='".$idp."' AND forum='".$forumas."'"));
          $closed=@mysql_query("DELETE FROM posts WHERE name='".$name[0]."' AND forum='".$forumas."'");
          if ($closed) echo "Тема удалена!<br/>"; else echo "ОШИБКА!";
          $forumas=mysql_fetch_array(mysql_query("SELECT name FROM forums WHERE id='".$forumas."'"));
          addlog("<b>$nick</b> удалил <b>$nameenc</b> в форуме <b>$forumas[0]</b>");
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////Rename topic////////////////////////////////////
function renamet($nick,$pass,$idp,$forumas,$rnm,$rnm2)
         {
          $name=mysql_fetch_array(mysql_query("SELECT name FROM posts WHERE id='".$idp."' AND forum='".$forumas."'"));
         $rnm=str_replace("$","",$rnm);
         $rnm=str_replace("&lt;","",$rnm);
         $rnm=str_replace("<","",$rnm);
         $rnm=str_replace(">","",$rnm);
         $rnm=str_replace("&gt;","",$rnm);
         $rnm=str_replace("\"","",$rnm);
         $rnm=str_replace("'","",$rnm);
         $rnm=str_replace("\\","",$rnm);
          $closed=@mysql_query("UPDATE posts SET name='".$rnm."'WHERE  name='".$name[0]."' AND forum='".$forumas."'");
          $closed=@mysql_query("UPDATE posts SET text='".$rnm2."' WHERE  id='".$idp."' AND forum='".$forumas."' AND thread='1'");
          if ($closed) echo "Тема переименована!<br/>"; else echo "ОШИБКА!";
          $forumas=mysql_fetch_array(mysql_query("SELECT name FROM forums WHERE id='".$forumas."'"));
          addlog("<b>$nick</b> переименовал <b>$nameenc</b> в <b>$rnm</b> в форуме <b>$forumas[0]</b>");
         };
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////Edit post/////////////////////////////////////
function renamep($nick,$pass,$forumas,$rnm,$id)
          {
           
           $closed=@mysql_query("UPDATE posts SET text='".$rnm."' WHERE  forum='".$forumas."' AND id='".$id."'");
           if ($closed) echo "Пост редактирован!<br/>"; else echo "ОШИБКА!";
           $forumas=mysql_fetch_array(mysql_query("SELECT name FROM forums WHERE id='".$forumas."'"));
           addlog("<b>$nick</b> отредактировал пост с номером <b>$id</b> темы <b>$nameenc</b> в форуме <b>$forumas[0]</b>");
          };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////Delete post/////////////////////////////////
function deletep($nick,$pass,$forumas,$rnm,$id)
         {
          
          $closed=@mysql_query("DELETE FROM posts WHERE  forum='".$forumas."' AND id='".$id."'");
          if ($closed) echo "Пост удален!<br/>"; else echo "ОШИБКА!";
          $forumas=mysql_fetch_array(mysql_query("SELECT name FROM forums WHERE id='".$forumas."'"));
          addlog("<b>$nick</b> удалил пост под номером <b>$id</b> темы <b>$nameenc</b> в форуме <b>$forumas[0]</b>");
         };
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////Is moderator?//////////////////////////
function ismod2($nick,$pass)
         {
          global $moderator;
          $moderator=false;
          $pwd=mysql_fetch_array(mysql_query("SELECT pass FROM users WHERE name='".$nick."'"));
          if (md5($pass)==$pwd[0])
             {
              $forumsmod=mysql_query("SELECT name FROM moderators");
             while ($forummod=mysql_fetch_array($forumsmod))
                    {
                     if (strtolower($forummod[0])==strtolower($nick)) $moderator=true;
                    }
             };
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////Ban/////////////////////////////////////
function ban($nick,$pass,$who,$bannedto,$reason)
         {
          $closed=@mysql_query("UPDATE users SET banned='1', banto='".$bannedto."', bannedby='".$nick."', banreason='".$reason."' WHERE name='".$who."'");
          if ($closed) echo "Пользователь забанен!<br/>"; else echo "ОШИБКА!";
          if ($bannedto<=time()) addlog("<b>$nick</b> разбанил <b>$who</b>"); else addlog("<b>$nick</b> забанил <b>$who</b>($reason)");
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////Pluses//////////////////////////////////
function pluses($nick,$pass,$who,$pluses,$reason)
         {
          $plsbef=mysql_fetch_array(mysql_query("SELECT pluses FROM users WHERE name='".$who."'"));
          $closed=@mysql_query("UPDATE users SET pluses='".$pluses."', plusreason='".$reason."' WHERE name='".$who."'");
          if ($closed) echo "User pluses updated!<br/>"; else echo "Problems!";
          addlog("<b>$nick</b> updated <b>$who</b> pluses from <b>$plsbef[0]</b> to <b>$pluses</b>($reason)");
         };
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////Is administrator?//////////////////////
function isadmin($nick,$pass)
         {
          global $administrator;
          $administrator=false;
          $pwd=mysql_fetch_array(mysql_query("SELECT pass FROM users WHERE name='".$nick."'"));
          if (md5($pass)==$pwd[0])
             {
              $forumsmod=mysql_query("SELECT name FROM administrators");
             while ($forummod=mysql_fetch_array($forumsmod))
                    {
                     if (strtolower($forummod[0])==strtolower($nick)) $administrator=true;
                    }
             };
         };
/////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////Delete forum/////////////////////////
function delforum($nick,$pass,$forumas,$id)
         {
        // $forumoidas=mysql_query("SELECT id FROM forums WHERE name='".$forumas."'");
        //  $forumoidnr=mysql_fetch_array($forumoidas);
          $pstsdel=@mysql_query("DELETE FROM posts WHERE forum='".$id."'");
          $moddel=@mysql_query("DELETE FROM moderators WHERE forum='".$id."'");
          $succeeded=@mysql_query("DELETE FROM forums WHERE name='".$forumas."'");
          if ($succeeded and $pstsdel and $moddel) echo "<font color=\"#00FF00\">Раздел форума успешно удален!</font><br/>"; else echo "<font color=\"#FF0000\">Problems!</font>";
         };
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////Add forum//////////////////////////////
function addforum($nick,$pass,$forumname,$perms)
         {
          if ($perms==0 or $perms==1 or $perms==2) {
          $pskpoz=mysql_fetch_array(mysql_query("SELECT MAX(position) FROM forums"));
          if (!$pskpoz[0]) $pskpoz[0]=0;
          $pskpoz[0]=$pskpoz[0]+1;
          $succeeded=@mysql_query("INSERT INTO forums SET name='".$forumname."', perms='".$perms."', position='".$pskpoz[0]."', adminonl='n', modonl='n'");
          if ($succeeded) echo "<font color=\"#00FF00\">Раздел форума создан!</font><br/>"; else echo "<font color=\"#FF0000\">Problems!</font>";
          } else echo "<font color=\"#FF0000\">Wrong permissions!</font><br/>";
         }
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////Edit forum/////////////////////////////
function editforum($nick,$pass,$forumas,$chngto,$perms,$adminonl,$modonl)
         {
          if ($perms==0 or $perms==1 or $perms==2) {
          $succeeded=@mysql_query("UPDATE forums SET name='".$chngto."', perms='".$perms."', adminonl='".$adminonl."', modonl='".$modonl."' WHERE name='".$forumas."'");
          if ($succeeded) echo "<font color=\"#00FF00\">Форум отредактирован!</font><br/>"; else echo "<font color=\"#FF0000\">Problems!</font>";
          } else echo "<font color=\"#FF0000\">Wrong permissions!</font><br/>";
         };
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////Edit user//////////////////////////////////////
function edituser($nick,$pass,$useris,$username,$signature,$email,$tlphone,$avatar,$site)
         {
          $succeeded=@mysql_query("UPDATE users SET name='".$username."', owntext='".$signature."', email='".$email."', tlphone='".$tlphone."', avatar='".$avatar."', site='".$site."' WHERE name='".$useris."'");
          $succeeded2=@mysql_query("UPDATE posts SET postedby='".$username."' WHERE postedby='".$useris."'");
          $succeeded3=@mysql_query("UPDATE permissions SET name='".$username."' WHERE name='".$useris."'");
          $succeeded4=@mysql_query("UPDATE moderators SET name='".$username."' WHERE name='".$useris."'");
          if ($succeeded and $succeeded2 and $succeeded3 and $succeeded4) echo "<font color=\"#FF0000\">User updated!</font><br/>"; else echo "<font color=\"#FF0000\">Problems!</font>";
         };
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////Delete permissions////////////////////////
function delperms($nick,$pass,$useris,$perms)
         {
          $succeeded=@mysql_query("DELETE FROM permissions WHERE name='".$useris."' AND forum='".$perms."'");
          if ($succeeded) echo "<font color=\"#FF0000\">Permissions deleted!</font><br/>"; else echo "<font color=\"#FF0000\">Problems!</font>";
         };
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////Add permissions///////////////////////////
function addperms($nick,$pass,$useris,$forumux)
         {
        //  if ($forumux=="0" or $forumux=="1" or $forumux=="2" or $forumux=="*") {
           if ($forumux=="*") mysql_query("DELETE FROM permissions WHERE name='".$useris."'");
          $succeeded=@mysql_query("INSERT INTO permissions SET name='".$useris."', forum='".$forumux."'");
          if ($succeeded) echo "<font color=\"#FF0000\">Permissions added!</font><br/>"; else echo "<font color=\"#FF0000\">Problems!</font>";
        //  } else echo "Wrong permissions!<br/>";
         };
/////////////////////////////////////////////////////////////////////////////


////////////////////////////////Delete moderators////////////////////////////
function delmod($nick,$pass,$useris,$modai)
         {
          $succeeded=@mysql_query("DELETE FROM moderators WHERE name='".$useris."' AND forum='".$modai."'");
          if ($succeeded) echo "<font color=\"#FF0000\">Moderator deleted!</font><br/>"; else echo "<font color=\"#FF0000\">Problems!</font>";
         };
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////Add moderator/////////////////////////////
function addmod($nick,$pass,$useris,$forumux)
         {
          if ($forumux=="*") mysql_query("DELETE FROM moderators WHERE name='".$useris."'");
          $succeeded=@mysql_query("INSERT INTO moderators SET name='".$useris."', forum='".$forumux."'");
          if ($succeeded) echo "<font color=\"#FF0000\">Moderator added!</font><br/>"; else echo "<font color=\"#FF0000\">Problems!</font>";
         };
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////Delete user////////////////////////////
function deluser($nick,$pass,$useris)
         {
          $succeeded=@mysql_query("DELETE FROM users WHERE name='".$useris."'");
          if ($succeeded) echo "<font color=\"#FF0000\">User deleted!</font><br/>"; else echo "<font color=\"#FF0000\">Problems!</font>";
         };
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////Add admin/////////////////////////////////
function addadmin($nick,$pass,$useris)
         {
          $succeeded=@mysql_query("INSERT INTO administrators SET name='".$useris."'");
          if ($succeeded) echo "<font color=\"#FF0000\">Administrator added!</font><br/>"; else echo "<font color=\"#FF0000\">Problems!</font>";
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////Remove admin////////////////////////////
function removeadmin($nick,$pass,$useris)
         {
           $succeeded=@mysql_query("DELETE FROM administrators WHERE name='".$useris."'");
          if ($succeeded) echo "<font color=\"#FF0000\">Administrator deleted!</font><br/>"; else echo "<font color=\"#FF0000\">Problems!</font>";
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////Change password/////////////////////////
function chpass($nick,$pass,$npass1,$npass2)
         {
          $hshdpwd=md5($npass1);
          $succeeded=@mysql_query("UPDATE users SET pass='".$hshdpwd."' WHERE name='".$nick."'");
          if ($succeeded) echo "<font color=\"#FF0000\">Пароль изменен!</font><br/>"; else echo "<font color=\"#FF0000\">Problems!</font>";
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////Add smilies/////////////////////////////
function addbb($nick,$pass,$chfrom,$chto)
         {
          $succeeded=@mysql_query("INSERT INTO smilies SET bbcode='".$chfrom."', changeto='".$chto."'");
          if ($succeeded) echo "<font color=\"#FF0000\">Smilie added!!</font><br/>"; else echo "<font color=\"#FF0000\">Problems!</font>";
         };
/////////////////////////////////////////////////////////////////////////////


////////////////////////////////////Get BBCode and smilies///////////////////
function getbb($nick,$pass,$page)
         {
         isadmin($nick,$pass);
         global $administrator;
           $page=$page-1;
         if (!$page==0) $pagest=$page*5; else $pagest=0;
         $bbkodai=mysql_query("SELECT bbcode,changeto,id FROM smilies ORDER BY id DESC LIMIT ".$pagest.", 5");
          while ($bbkodas=mysql_fetch_array($bbkodai))
             {
              if ($administrator) $admintext=" <a href=\"admin.php?action=editbb&amp;nick=$nick&amp;pass=$pass&amp;id=$bbkodas[2]\">M</a>";
              echo "$bbkodas[0] - <img src=\"$bbkodas[1]\" alt=\"$bbkodas[0]\"/>$admintext<br/>";
             };
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////Edit BBCode/////////////////////////////
function editbb($nick,$pass,$chfrom,$chto,$id)
         {
          $succeeded=@mysql_query("UPDATE smilies SET bbcode='".$chfrom."', changeto='".$chto."' WHERE id='".$id."'");
          if ($succeeded) echo "Smilie edited!<br/>"; else echo "Problems!";
         };
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////Is administrator?//////////////////////
function isadmin2($nick)
         {
          global $administrator;
          $administrator=false;
              $forumsmod=mysql_query("SELECT name FROM administrators");
             while ($forummod=mysql_fetch_array($forumsmod))
                    {
                     if (strtolower($forummod[0])==strtolower($nick)) $administrator=true;
                    }
         };
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////Is moderator?//////////////////////////
function ismod3($nick)
         {
          global $moderator;
          $moderator=false;
              $forumsmod=mysql_query("SELECT name FROM moderators");
             while ($forummod=mysql_fetch_array($forumsmod))
                    {
                     if (strtolower($forummod[0])==strtolower($nick)) $moderator=true;
                    }
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////Counter/////////////////////////////////////
function addvisitor()
         {
         $lankytoju=@mysql_fetch_array(mysql_query("SELECT visitors FROM counter"));
         if (!$lankytoju) {mysql_query("INSERT INTO counter SET visitors='0', id='1'"); $lankytoju=mysql_fetch_array(mysql_query("SELECT visitors FROM counter"));
         }
         else {//$lankytoju=mysql_fetch_array($lankytoju);
         $lankytoju[0]=$lankytoju[0]+1;
          mysql_query("UPDATE counter SET visitors='".$lankytoju[0]."' WHERE id='1'");}
         };
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////List moderators///////////////////////
function listmods($nick,$pass,$page)
         {
           $page=$page-1;
         if (!$page==0) $pagest=$page*5; else $pagest=0;
         ismod2($nick,$pass);
         global $moderator;
         isadmin($nick,$pass);
         global $administrator;
         $moderatorz=mysql_query("SELECT name,forum FROM moderators LIMIT ".$pagest.",5");
         while ($modz=mysql_fetch_array($moderatorz))
                {
                if ($modz[1]=="*") $forumas[0]="All"; else $forumas=mysql_fetch_array(mysql_query("SELECT name FROM forums WHERE id='".$modz[1]."'"));
                 echo "<a href=\"index.php?action=viewuser&amp;nick=$nick&amp;pass=$pass&amp;who=$modz[0]\">$modz[0] - $forumas[0]</a><br/>";
                };
         };
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////List administrators///////////////////
function listadmins($nick,$pass,$page)
         {
           $page=$page-1;
         if (!$page==0) $pagest=$page*5; else $pagest=0;
         ismod2($nick,$pass);
         global $moderator;
         isadmin($nick,$pass);
         global $administrator;
         $moderatorz=mysql_query("SELECT name FROM administrators LIMIT ".$pagest.",5");
         while ($modz=mysql_fetch_array($moderatorz))
                {
                 echo "<a href=\"index.php?action=viewuser&amp;nick=$nick&amp;pass=$pass&amp;who=$modz[0]\">$modz[0]</a><br/>";
                };
         };
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////List banned///////////////////////////
function listbanned($nick,$pass,$page)
         {
           $page=$page-1;
         if (!$page==0) $pagest=$page*5; else $pagest=0;
         ismod2($nick,$pass);
         global $moderator;
         isadmin($nick,$pass);
         global $administrator;
         $moderatorz=mysql_query("SELECT name,bannedby,banreason FROM users WHERE banned='1' LIMIT ".$pagest.",5");
         while ($modz=mysql_fetch_array($moderatorz))
                {
                ismod2($nick,$pass);
                global $moderator;
                if ($moderator) $modwho=" banned by $modz[1]"; else $modwho="";
                $modz[2]=htmlspecialchars($modz[2]);
                 echo "<a href=\"index.php?action=viewuser&amp;nick=$nick&amp;pass=$pass&amp;who=$modz[0]\">$modz[0]$modwho($modz[2])</a><br/>";
                };
         };
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////List permissions//////////////////////
function listperms($nick,$pass,$page)
         {
           $page=$page-1;
         if (!$page==0) $pagest=$page*5; else $pagest=0;
         ismod2($nick,$pass);
         global $moderator;
         isadmin($nick,$pass);
         global $administrator;
         $moderatorz=mysql_query("SELECT name,forum FROM permissions LIMIT ".$pagest.",5");
         while ($modz=mysql_fetch_array($moderatorz))
                {
                if ($modz[1]=="*") $forumas[0]="All"; else $forumas=mysql_fetch_array(mysql_query("SELECT name FROM forums WHERE id='".$modz[1]."'"));
                 echo "<a href=\"index.php?action=viewuser&amp;nick=$nick&amp;pass=$pass&amp;who=$modz[0]\">$modz[0] - $forumas[0]</a><br/>";
                };
         };
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////Reorder forums/////////////////////////
function reorderfrms($nick,$pass,$forumas,$pozicija)
         {
          $succeeded=@mysql_query("UPDATE forums SET position='".$pozicija."' WHERE id='".$forumas."'");
          if ($succeeded) echo "Order edited!<br/>"; else echo "Problems!";
         };
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////Can post in admin or mod forums?///////////
function canuppost($nick,$pass,$forum)
         {
          slogin($nick,$pass);
          global $logged;
          global $postlet;
          $postlet=true;
          if ($logged)
            {
             isadmin($nick,$pass);
             ismod2($nick,$pass);
             global $moderator;
             global $administrator;
             $aradmin=mysql_fetch_array(mysql_query("SELECT adminonl FROM forums WHERE id='".$forum."'"));
             $armod=mysql_fetch_array(mysql_query("SELECT modonl FROM forums WHERE id='".$forum."'"));
             if ($armod[0]=="y") { if ($moderator) $postlet=true; else $postlet=false;}
             if ($aradmin[0]=="y") { if ($administrator) $postlet=true; else $postlet=false;}
            } else echo "Login first!";
         };
/////////////////////////////////////////////////////////////////////////////


////////////////////////////Add info to log//////////////////////////////////
function addlog($text)
         {
          global $timezone;
          $valandos=date("H")+$timezone;
          if ($valandos>23) $valandos=$valandos-24;
          $data=date("y m d - ".$valandos.":i:s");
          $uzhloginta=mysql_query("INSERT INTO log SET date='".$data."',text='".$text."'");
          if (!$uzhloginta) echo "Problems while trying to log this action!<br/>";
          $maxofid=mysql_fetch_array(mysql_query("SELECT MAX(id) FROM log"));
          $maxxx=$maxofid[0]-499;
          $deleded=mysql_query("DELETE FROM log WHERE id<".$maxxx."");
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////Read log////////////////////////////////////
function getlog($nick,$pass,$page)
         {
         $page=$page-1;
         if (!$page==0) $pagest=$page*5; else $pagest=0;
         $logaz=mysql_query("SELECT id,date,text FROM log ORDER BY id DESC LIMIT ".$pagest.",5");
         while ($logazz=mysql_fetch_array($logaz))
             {
              echo "$logazz[0]. ($logazz[1]) $logazz[2]<br/><br/>";
             };
         };
/////////////////////////////////////////////////////////////////////////////


////////////////////////////////////Unban////////////////////////////////////
function unban($nick,$pass,$who)
         {
          $closed=@mysql_query("UPDATE users SET banned='0' WHERE name='".$who."'");
          if ($closed) echo "User unbanned!<br/>"; else echo "Problems!";
          addlog("<b>$nick</b> unbanned <b>$who</b>");
         };
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////List banned///////////////////////////
function listtop($nick,$pass,$page)
         {
           $page=$page-1;
         if (!$page==0) $pagest=$page*5; else $pagest=0;
         ismod2($nick,$pass);
         global $moderator;
         isadmin($nick,$pass);
         global $administrator;
         $moderatorz=mysql_query("SELECT name,postno FROM users ORDER BY postno DESC LIMIT ".$pagest.",5");
         while ($modz=mysql_fetch_array($moderatorz))
                {
                 echo "<a href=\"index.php?action=viewuser&amp;nick=$nick&amp;pass=$pass&amp;who=$modz[0]\">$modz[0] Posts:$modz[1]</a><br/>";
                };
         };
/////////////////////////////////////////////////////////////////////////////
?>