View file wapforum2/core.php

File size: 67.01Kb
<?php
define (IMAGECOUNTER, '<br/><img src="http://pslink.ru/b.php?id=780" alt="PSLink"/><br/>');
include("conf.php");

/////////////////////////////////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/>";
              }
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////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 "<small>-----<br/>";
        global $logged;
                $page=$page-1;
         if (!$page==0) $pagest=$page*15; else $pagest=0;
         $userforum=mysql_query("SELECT name,perms,id FROM forums ORDER BY position LIMIT $pagest,15");
         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 "<a href=\"index.php?action=viewforum&amp;id=$row[2]&amp;nick=$nick&amp;pass=$pass&amp;page=1\">$txtass(".$postu[0].",".$postuviso[0].")</a>"; echo "<br/>";}
                  if ($row[1]=="1" AND $logged) {$txtass=htmlspecialchars($row[0]); echo "<a href=\"index.php?action=viewforum&amp;id=$row[2]&amp;nick=$nick&amp;pass=$pass&amp;page=1\">$txtass(".$postu[0].",".$postuviso[0].")</a>"; echo "<br/>";}
                  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 "<a href=\"index.php?action=viewforum&amp;id=$row[2]&amp;nick=$nick&amp;pass=$pass&amp;page=1\">$txtass(".$postu[0].",".$postuviso[0].")</a>"; echo "<br/>";
                           }}
                          }
              }
         echo "-----<br/></small>";
        }
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////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 "Вы вошли как $username";} 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 "<small>Вас забанили!<br/>Разбан через: $tleft<br/>$banupdate</small>";
                           $logged=false;
                           $banned=true;
                           };
                 }
                 } else {echo "<small>Вы не вошли в систему</small>!"; $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)
        {
         $useris=mysql_fetch_array(mysql_query("SELECT pass FROM users WHERE name LIKE '".$username."'"));
         if ($useris[0]) echo "<small>Выберите другое имя пользователя</small>"; else
           {
            $username=str_replace(" ","",$username);
            $username=str_replace("$","",$username);
            $username=str_replace("&lt;","",$username);
            $username=str_replace("<","",$username);
            $username=str_replace(">","",$username);
            $username=str_replace("&gt;","",$username);
            $username=str_replace("\"","",$username);
            $username=str_replace("'","",$username);
            $username=str_replace("\\","",$username);
            $username=str_replace("&","",$username);
            $username=trim($username);
            if (!$username==null) {
            if (!$pass==null) {
            $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 ($inserting) { echo "<small>Вы теперь наш зарегистрированный пользователь!</small>";
            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 "<small>Поле пароля пусто!</small>";} else echo "<small>Вы не можете использовать этот ник!</small>!";}
        }
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////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*10; else $page=0;
         $pagemore=$page+10;
         $pinnedposts=mysql_query("SELECT id, name FROM posts WHERE forum='".$id."' AND thread='1' AND pinned='1' ORDER BY position LIMIT ".$page.",5");
         $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.",10");


            echo "<small><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]);
              $enc=htmlspecialchars($enc);
              if ($isclosed[0]==1) $clstxt="(X)"; else $clstxt="";
               echo "<a href=\"index.php?action=viewpost&amp;name=$enc&amp;nick=$nick&amp;pass=$pass&amp;forumas=$id&amp;read=new&amp;page=1\">Pinned: $rowas[1](".$postu[0].")$clstxt</a>"; echo "<br/>";
              }
              echo "<br/>";
           while ($rowas = mysql_fetch_array($userposts))
              {
              $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]);
              $enc=htmlspecialchars($enc);
              if ($isclosed[0]==1) $clstxt="(X)"; else $clstxt="";
               echo "<a href=\"index.php?action=viewpost&amp;name=$enc&amp;nick=$nick&amp;pass=$pass&amp;forumas=$id&amp;read=new&amp;page=1\">$rowas[1](".$postu[0].")$clstxt</a>"; echo "<br/>";
              }
              echo "-----<br/></small>";
             /* } else echo "Cannot view<br/><a href=\"index.php?nick=$nick&amp;pass=$pass\">Back</a>"; */
              } else echo "Вы забанены!";
        }
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////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("y m d - ".$valandos.":i:s");
         $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 "Такое название сообщения уже существует!"; $canpost=false;}
                    if ($namee[0]==$pradinisn) { echo "Такое названия сообщение уже существует!"; $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 "Такой текст уже существует!"; $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)
        {
        //$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*5; else $pagest=0;
        $pagemore=$page*5;
        $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.",5"); else
         $postas=mysql_query("SELECT text, postedby, id, date FROM posts WHERE name='".$post."' AND forum='".$forumas."' ORDER BY position DESC LIMIT ".$pagest.",5"); // ".$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;post=$postencrpt&amp;forumas=$forumas&amp;msg=$postass[2]\">M</a>"; else $modlinks="";
             echo "<small><a href=\"index.php?action=viewuser&amp;nick=$nick&amp;pass=$pass&amp;who=$postass[1]\">$postass[1]: </a> $modlinks</small>";
              $postass[0] = parsebb($postass[0]);
             $postass[0]=htmlspecialchars($postass[0]);
             $postass[0] = reparsebb($postass[0]);

             //$postass[0] = parsebb2($postass[0]);
             echo "<small>$postass[0]</small>";
             echo "<br/><small>$postass[3]</small>";
             echo "<br/>";
           }
           //echo "<br/>";
           $prieshpg=$page;
           $kitaspg=$page+2;
           //echo "</p><p align=\"center\">";
           $post=base64_encode($post);
           if ($page+1<$poststot) echo "<a href=\"index.php?action=viewpost&amp;name=$post&amp;nick=$nick&amp;pass=$pass&amp;forumas=$forumas&amp;read=$read&amp;page=$kitaspg\">Вперед</a><br/>";
           if ($page+1>1) echo "<a href=\"index.php?action=viewpost&amp;name=$post&amp;nick=$nick&amp;pass=$pass&amp;forumas=$forumas&amp;read=$read&amp;page=$prieshpg\">Назад</a>";
           //echo "<br/>";
           } else echo "Просмотр недоступен<br/><a href=\"index.php?nick=$nick&amp;pass=$pass\">[Форумы]</a>";/*}*/  } else echo "Вас забанили!";
        }
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////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 "Статистика юзера $info[1]<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 "Last PlusesUpdate: $plusesupdate<br/>";}
          if ($banupdate[0]!="") {if (strtolower($who)==strtolower($nick)) echo "Последняя причина бана: $banupdate<br/>";}
          if ($plusesupdate[0]!="") {if ($moderator) echo "Last PlusesUpdate: $plusesupdate<br/>";}
          if ($banupdate[0]!="") {if ($moderator) echo "Last BanReason: $banupdate<br/>";}
          echo "<a href=\"index.php?action=sendpm&amp;nick=$nick&amp;pass=$pass&amp;who=$info[1]\">Написать сообщение $info[1]</a><br/><br/>";
          echo "ID: $info[0]<br/>";
          echo "<img src=\"$info[8]\" alt=\"avatar\"/><br/>";
          echo "Постов: $posts[0]<br/>";
          include ("levels.php");        //We get variable $ustat (status) from file levels.php
          echo "Статус: $ustat<br/>";
          echo "Pluses: $info[2]<br/>";
         // echo "Permission level: $info[3]<br/>";
          echo "Браузер: $info[6]<br/>";
          $info[5]=htmlspecialchars($info[5]);
          echo "E-Mail: $info[5]<br/>";
          echo "WAP-сайт: <a href=\"$info[7]\">$info[7]</a><br/>";
          $info[4]=parsebb($info[4]);
          $info[4]=htmlspecialchars($info[4]);
          $info[4]=reparsebb($info[4]);
          echo "Member signature: $info[4]<br/>";
           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\">Забанить</a>";
                         echo "<br/><a href=\"index.php?action=unbanuser&amp;nick=$nick&amp;pass=$pass&amp;who=$who\">Разбанить</a>";

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

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


/////////////////////////////////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 "<small>Аватар:</small> <input name=\"avataras\" maxlength=\"200\" value=\"$infoo[2]\"/><br/>";
          echo "<small>Мыло:</small> <input name=\"emailas\" maxlength=\"50\" value=\"$infoo[1]\"/><br/>";
          echo "<small>Сайт:</small> <input name=\"svetajne\" maxlength=\"50\" value=\"$infoo[3]\"/><br/>";
          echo "<small>Signature:</small> <input name=\"owntextas\" maxlength=\"100\" value=\"$infoo[0]\"/><br/>";
          echo "<small><anchor title=\"Update!\">Обновить!";
          echo "<go href=\"update.php?nick=$nick&amp;pass=$pass\" method=\"post\">";
          echo "<postfield name=\"email\" value=\"\$emailas\"/>";
          echo "<postfield name=\"owntext\" value=\"\$owntextas\"/>";
          echo "<postfield name=\"avataras\" value=\"\$avataras\"/>";
          echo "<postfield name=\"svetajne\" value=\"\$svetajne\"/>";
          echo "</go>";
          echo "</anchor></small>";
          echo "<br/><small><b>Р?зменить пароль</b></small><br/>";
          echo "<small>Новый пароль:</small><input type=\"password\" name=\"npass1\" maxlength=\"30\"/><br/>";
          echo "<small>Повторите пароль:</small><input type=\"password\" name=\"npass2\" maxlength=\"30\"/><br/>";
          echo "<small><anchor title=\"Change!\">Р?зменить";
          echo "<go href=\"chpwd.php?nick=$nick&amp;pass=$pass\" method=\"post\">";
          echo "<postfield name=\"npass1\" value=\"\$npass1\"/>";
          echo "<postfield name=\"npass2\" value=\"\$npass2\"/>";
          echo "</go>";
          echo "</anchor></small>";
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////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="+"; else $nw="-";
                            echo "<small><a href=\"index.php?action=readpm&amp;nick=$nick&amp;pass=$pass&amp;pm=$pm[2]\">$nw$pm[1]</a></small><br/>";
                           } } else echo "У вас нет входящих сообщений!";
         };
/////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////Send PM//////////////////////////////
function sendpm($nick,$pass,$who,$ttextas)
         {
          global $logged;
          $valandos=date("H")+$timezone;
        if ($valandos>23) $valandos=$valandos-24;
        $data=date("y m d - ".$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 "Сообщение успешно отправлено!<br/>";
          $ttextas=parsebb($ttextas);
          $ttextas=htmlspecialchars($ttextas);
                     $rparsedtxtas=reparsebb($ttextas);
                     echo $rparsedtxtas;} else echo "РћРЁР?БКА!";} else echo "Пользователь РЅРµ существует!";
         } else echo "Войдите в систему перед отправлением сообщений!";};};
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////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 "PM by: $pminfo[2]<br/>$pminfo[5]<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]\">Ответить</a><br/>";
                   echo "<a href=\"delpm.php?nick=$nick&amp;pass=$pass&amp;who=$pminfo[0]\">Удалить</a>";
                  } else echo "Хочешь прочесть то, что адресовано не тебе? Ха ха!";
         };
/////////////////////////////////////////////////////////////////////////////


////////////////////////////////////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 "Всего зарегистрировано: <b>$useriu[0]</b><br/>Последний зарегистрированный пользователь: <a href=\"index.php?action=viewuser&amp;nick=$nick&amp;pass=$pass&amp;who=$paskutinis[0]\">$paskutinis[0]</a><br/>";
          echo "Всего сообщений: <b>$postu[0]</b><br/>Всего тем:<b>$temu[0]</b><br/>";
          echo "Отправлено личных сообщений: <b>$privates[0]</b><br/>";
          $lankytoju=mysql_fetch_array(mysql_query("SELECT visitors FROM counter"));
          echo "Счетчик: $lankytoju[0]";
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////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 name,perms,forum 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=base64_encode($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;name=$postenc&amp;nick=$nick&amp;pass=$pass&amp;forumas=$resultai[2]&amp;read=new&amp;page=1\">$resultai[0]</a><br/>";
            };
          $pagefrw=$page+2;
        $pagepws=$page;
        echo "<br/>";
        if ($page<$srchtot-1) {
        echo "<anchor title=\"Forward\">Вперед";
        echo "<go href=\"search.php?nick=$nick&amp;pass=$pass&amp;page=$pagefrw\" method=\"post\">";
        echo "<postfield name=\"ttextas\" value=\"\$ttextas\"/>";
        echo "</go>";
        echo "</anchor>";
        echo "<br/>";
        //echo "<a href=\"search.php?nick=$nick&amp;pass=$pass&amp;page=$pagefrw\">Forward</a><br/>";
                            };
        $page=$page-1;
        if ($page>-1) {
        echo "<anchor title=\"Backward\">Назад";
        echo "<go href=\"search.php?nick=$nick&amp;pass=$pass&amp;page=$pagepws\" method=\"post\">";
        echo "<postfield name=\"ttextas\" value=\"\$ttextas\"/>";
        echo "</go>";
        echo "</anchor>";
        echo "<br/>";
        //echo "<a href=\"search.php?nick=$nick&amp;pass=$pass&amp;page=$pagepws\">Backward</a><br/>";
                      };
        $page=$page+2;
        if ($srchtot<1) $srchtot=1;
        echo "Страница: $page/$srchtot";
        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);

         $text = ereg_replace("http://[A-Za-z0-9./=?-]+","<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("&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;
         };
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////Online////////////////////////////////////
function onlineadd($nick)
         {
          $nick=strtolower($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"На форуме пользователей: <a href=\"index.php?action=online&amp;nick=$nick&amp;pass=$pass&amp;page=1\">$vartotojai</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,$name,$forumas)
         {
          $nameenc=base64_decode($name);
          $closed=@mysql_query("UPDATE posts SET closed='1' WHERE name='".$nameenc."' AND forum='".$forumas."'");
          if ($closed) echo "Тема закрыта!<br/>"; else echo "РћРЁР?БКА!";
          addlog("<b>$nick</b> закрыл <b>$nameenc</b>");
         };
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////Open topic/////////////////////////////////
function open($nick,$pass,$name,$forumas)
         {
          $nameenc=base64_decode($name);
          $closed=@mysql_query("UPDATE posts SET closed='0' WHERE name='".$nameenc."' AND forum='".$forumas."'");
          if ($closed) echo "Тема открыта!<br/>"; else echo "РћРЁР?БКА!";
          addlog("<b>$nick</b> отрыл <b>$nameenc</b>");
         };
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////Pin topic//////////////////////////////////
function pin($nick,$pass,$name,$forumas)
         {
          $nameenc=base64_decode($name);
          $closed=@mysql_query("UPDATE posts SET pinned='1' WHERE name='".$nameenc."' AND forum='".$forumas."'");
          if ($closed) echo "Тема заблокирована!<br/>"; else echo "РћРЁР?БКА!";
          addlog("<b>$nick</b> заблокирова <b>$nameenc</b>");
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////Unpin topic/////////////////////////////////////
function unpin($nick,$pass,$name,$forumas)
         {
          $nameenc=base64_decode($name);
          $closed=@mysql_query("UPDATE posts SET pinned='0' WHERE name='".$nameenc."' AND forum='".$forumas."'");
          if ($closed) echo "Тема разблокирована!<br/>"; else echo "РћРЁР?БКА!";
          addlog("<b>$nick</b> разблокировал <b>$nameenc</b>");
         };
/////////////////////////////////////////////////////////////////////////////


/////////////////////////////Delete topic////////////////////////////////////
function deletet($nick,$pass,$name,$forumas)
         {
          $nameenc=base64_decode($name);
          $closed=@mysql_query("DELETE FROM posts WHERE name='".$nameenc."' 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,$name,$forumas,$rnm,$rnm2)
         {
          $nameenc=base64_decode($name);
         $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='".$nameenc."' AND forum='".$forumas."'");
          $closed=@mysql_query("UPDATE posts SET text='".$rnm2."' WHERE name='".$nameenc."' 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,$name,$forumas,$rnm,$id)
          {
           $nameenc=base64_decode($name);
           $closed=@mysql_query("UPDATE posts SET text='".$rnm."' WHERE name='".$nameenc."' AND 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,$name,$forumas,$rnm,$id)
         {
          $nameenc=base64_decode($name);
          $closed=@mysql_query("DELETE FROM posts WHERE name='".$nameenc."' AND 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 "Forum deleted!<br/>"; else echo "Problems!";
         };
/////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////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 "Forum created!<br/>"; else echo "Problems!";
          } else echo "Wrong permissions!<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 "Forum updated!<br/>"; else echo "Problems!";
          } else echo "Wrong permissions!<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 "User updated!<br/>"; else echo "Problems!";
         };
/////////////////////////////////////////////////////////////////////////////


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


///////////////////////////////////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 "Permissions added!<br/>"; else echo "Problems!";
        //  } 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 "Moderator deleted!<br/>"; else echo "Problems!";
         };
/////////////////////////////////////////////////////////////////////////////


///////////////////////////////////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 "Moderator added!<br/>"; else echo "Problems!";
         };
/////////////////////////////////////////////////////////////////////////////


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


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


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


/////////////////////////////////////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 "Password changed!<br/>"; else echo "Problems!";
         };
/////////////////////////////////////////////////////////////////////////////


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


////////////////////////////////////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/>";
                };
         };
/////////////////////////////////////////////////////////////////////////////
?>