View file minibb11/setup_mysql.php

File size: 23.09Kb
<?
/*
setup_mysql.php : mySQL calls list for miniBB.
Copyright (C) 2001-2002 miniBB.net.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

@mysql_connect($DBhost, $DBusr, $DBpwd) or die ('<b>Database/configuration error.</b>');
@mysql_select_db($DBname) or die ('<b>Database/configuration error (DB is missing).</b>');

function DB_query ($n, $sus) {
global $result, $user_usr, $topic, $forum, $makeLim, $viewlastdiscussions;
global $Tf,$Tp,$Tt,$Ts,$Tb,$Tu;

if($n==7){
if(!$sus) $result=mysql_query("SELECT poster_id, poster_name, post_time, post_text, poster_ip, post_status, post_id FROM $Tp WHERE topic_id=$topic ORDER BY post_time ASC $makeLim");
$row=mysql_fetch_row($result);
}

elseif($n==10){
if(!$sus) $result=mysql_query("SELECT topic_id, topic_title, topic_poster, topic_poster_name, topic_time, topic_views, topic_status FROM $Tt WHERE forum_id=$forum ORDER BY topic_time DESC $makeLim");
if ($result) $row=mysql_fetch_row($result);
}

elseif($n==11){
if(!$sus) $result=mysql_query("SELECT $Tt.topic_id, $Tt.topic_title, $Tt.topic_poster, $Tp.poster_name, $Tt.topic_time, $Tt.topic_views, $Tt.topic_status FROM $Tt, $Tp WHERE $Tt.topic_last_post_id=$Tp.post_id AND $Tp.forum_id=$forum ORDER BY $Tp.post_time DESC $makeLim");
if ($result) $row=mysql_fetch_row($result);
}

elseif($n==5) $row=mysql_fetch_row(mysql_query("SELECT topic_title, topic_status, topic_poster, topic_poster_name, forum_id FROM $Tt WHERE topic_id=$topic"));

elseif($n==6)
$row=mysql_result(mysql_query("SELECT count(topic_id) FROM $Tp WHERE topic_id=$topic"),0);

elseif($n==95){
/*Get forum replies count*/
$row=mysql_result(mysql_query("select count(forum_id) from $Tp where forum_id=$forum"),0);
}

elseif($n==1)
$row=mysql_fetch_row(mysql_query("SELECT username, user_password FROM $Tu WHERE username='$user_usr' LIMIT 1"));

elseif($n==2)
$row=mysql_fetch_row(mysql_query("SELECT user_id, user_sorttopics FROM $Tu WHERE username='$user_usr'"));

elseif($n==3){
$result=mysql_query("UPDATE $Tt SET topic_views=topic_views+1 WHERE topic_id=$topic");
$row=mysql_affected_rows();
}

elseif($n==14){
if(!$sus) $result=mysql_query("SELECT topic_id, topic_title, topic_poster, topic_poster_name, topic_time, topic_views, forum_id FROM $Tt ORDER BY topic_time DESC limit $viewlastdiscussions") or die("<center><b>".mysql_error()."</b></center>");
if ($result) $row=mysql_fetch_row($result);
}

elseif($n==15){
if(!$sus) $result=mysql_query("SELECT $Tt.topic_id, $Tt.topic_title, $Tt.topic_poster, $Tp.poster_name, $Tp.post_time, $Tt.topic_views, $Tp.forum_id FROM $Tt,$Tp WHERE $Tt.topic_last_post_id=$Tp.post_id ORDER BY $Tp.post_time DESC limit $viewlastdiscussions");
if ($result) $row=mysql_fetch_row($result);
}

elseif($n==16){
if(!$sus) $result=mysql_query("SELECT forum_id, forum_name, forum_desc, forum_icon FROM $Tf ORDER BY forum_order ASC");
$row=mysql_fetch_row($result);
}

elseif($n==26){
/*Check if topic poster and user_usr are the same*/
global $user_id;
$result=mysql_query("SELECT topic_poster FROM $Tt WHERE topic_id=$topic AND topic_poster=$user_id");
if (mysql_num_rows($result)<=0) $row = FALSE;
else $row=mysql_fetch_row($result);
}

elseif($n==8){
if($rslt=mysql_query("SELECT forum_name, forum_id, forum_icon FROM $Tf WHERE forum_id=$forum")) $row=mysql_fetch_row($rslt);
else $row=FALSE;
}

elseif($n==9)
$row=mysql_result(mysql_query("SELECT count(topic_id) FROM $Tt WHERE forum_id=$forum"),0);

elseif($n==52){
/*Search - Topics only*/
global $searchString;
if(!$sus) $result=mysql_query("SELECT $Tt.topic_id, $Tt.forum_id, $Tt.topic_title, $Tt.topic_time, $Tf.forum_name FROM $Tt, $Tf WHERE $Tt.forum_id=$Tf.forum_id AND $Tt.topic_title LIKE $searchString ORDER BY $Tt.topic_time DESC $makeLim");
$row=mysql_fetch_row($result);
}

elseif($n==53){
/*Search - numRows topics & posts*/
global $searchString, $searchString2;
$row=mysql_result(mysql_query("SELECT count($Tt.topic_id) FROM $Tp, $Tt WHERE $Tp.topic_id=$Tt.topic_id AND (($Tp.post_text LIKE $searchString ) OR ($Tt.topic_title LIKE $searchString2 ))"),0);
}

elseif($n==54){
/*Search - numRows topics only*/
global $searchString;
$row=mysql_result(mysql_query("SELECT count(topic_id) FROM $Tt WHERE topic_title LIKE $searchString"),0);
}

elseif($n==4){
global $searchString, $searchString2;
/*Search - Topics & posts*/
if(!$sus) $result=mysql_query("SELECT $Tp.post_id, $Tp.forum_id, $Tp.topic_id, $Tp.post_text, $Tp.post_time, $Tt.topic_title, $Tf.forum_name FROM $Tp, $Tt, $Tf WHERE $Tp.topic_id=$Tt.topic_id AND $Tt.forum_id=$Tf.forum_id AND (($Tp.post_text LIKE $searchString ) OR ($Tt.topic_title LIKE $searchString2 )) ORDER BY post_time DESC $makeLim");
$row=mysql_fetch_row($result);
}

elseif($n==57){
/*Search - users*/
global $searchString;
if(!$sus) $result=mysql_query("SELECT $Tp.post_id, $Tp.forum_id, $Tp.topic_id, $Tp.post_text, $Tp.post_time, $Tt.topic_title, $Tf.forum_name FROM $Tp, $Tt, $Tf WHERE $Tp.topic_id=$Tt.topic_id AND $Tt.forum_id=$Tf.forum_id AND poster_name LIKE $searchString ORDER BY post_time DESC $makeLim");
$row=mysql_fetch_row($result);
}

elseif($n==58){
/*Search - numRows users*/
global $searchString;
$row=mysql_result(mysql_query("SELECT count(*) FROM $Tp, $Tt WHERE $Tp.topic_id=$Tt.topic_id AND (($Tp.poster_name LIKE $searchString) OR ($Tt.topic_poster LIKE $searchString))"),0);
}

elseif($n==76){
global $tmpRslt;
/*Search - this one used in search func. for reverse page redirects only(topics by time)*/
if(!$sus) $tmpRslt=mysql_query("SELECT topic_id FROM $Tt WHERE forum_id=$forum ORDER BY topic_time DESC");
$row=mysql_fetch_array($tmpRslt);
}

elseif($n==77){
global $tmpRslt;
/*Search - this one used in search func. for reverse page redirects only(topics by new answers)*/
if(!$sus) $tmpRslt=mysql_query("SELECT $Tt.topic_id FROM $Tt, $Tp WHERE $Tt.topic_last_post_id=$Tp.post_id AND $Tt.forum_id=$forum ORDER BY $Tp.post_time DESC");
$row=mysql_fetch_array($tmpRslt);
}

elseif($n==78){
global $tmpRslt;
/*Search - this one used in search func. for reverse page redirects only(posts by time)*/
if(!$sus) $tmpRslt=mysql_query("SELECT post_id FROM $Tp WHERE topic_id=$topic ORDER BY post_time ASC");
$row=mysql_fetch_array($tmpRslt);
}

elseif($n==9)
$row=mysql_result(mysql_query("SELECT count(forum_id) FROM $Tt WHERE forum_id=$forum"),0);

elseif($n==19)
/*Check if topic and forum ID exist*/
$row=mysql_num_rows(mysql_query("SELECT topic_id FROM $Tt WHERE forum_id=$forum AND topic_id=$topic"));

elseif($n==20){
/* Insert new post and update topics db correspondly*/
global $user_id, $user_usr, $postText, $poster_ip;
$result = mysql_query("INSERT INTO $Tp (forum_id, topic_id, poster_id, poster_name, post_text, post_time, poster_ip, post_status) VALUES ($forum, $topic, $user_id, '$user_usr', '$postText', now(), '$poster_ip', 0)") or die("a1".mysql_error());
$lastID=mysql_insert_id();
$result=mysql_query("UPDATE $Tt set topic_last_post_id=$lastID WHERE topic_id=$topic;");
$row=mysql_affected_rows();
}

elseif($n==22){
/*Insert new topic*/
global $topicTitle, $user_id, $user_usr;
$result=mysql_query("INSERT INTO $Tt VALUES(0,'$topicTitle',$user_id,'$user_usr',now(),0,$forum,0,0)");
$row=mysql_insert_id();
}

elseif($n==23){
/*Delete topic*/
$result=mysql_query("DELETE FROM $Tt WHERE topic_id=$topic AND forum_id=$forum");
$row=mysql_affected_rows();
}

elseif($n==24){
/*Delete all posts with associated topic*/
$result=mysql_query("DELETE FROM $Tp WHERE topic_id=$topic AND forum_id=$forum");
$row=mysql_affected_rows();
}

elseif($n==25){
/* Getting Topic name or not*/
$rslt = mysql_query("SELECT topic_title FROM $Tt WHERE topic_id=$topic");
$row = mysql_fetch_row($rslt); $row = $row[0];
}

elseif($n==27){
$result=mysql_query("UPDATE $Tt SET topic_status=$sus WHERE topic_id=$topic");
$row=mysql_affected_rows();
}

elseif($n==28)
/*Num forums*/
$row=mysql_result(mysql_query("SELECT count(forum_id) FROM $Tf"),0);

elseif($n==29)
$row=mysql_fetch_row(mysql_query("select username, user_password from $Tu where username='$user_usr' limit 1"));

elseif($n==30){
/*Admin - add forum*/
global $forumname, $forumdesc, $forumicon;
$result=mysql_query("insert into $Tf (forum_name, forum_desc, forum_icon) values ('$forumname', '$forumdesc', '$forumicon')");
$used_id=mysql_insert_id();
$result=mysql_query("update $Tf set forum_order=forum_id where forum_id=$used_id");
$row=mysql_affected_rows();
}

elseif($n==31){
/*Admin - edit forum*/
if(!$sus) $result=mysql_query("select * from $Tf order by forum_order, forum_name");
$row=mysql_fetch_array($result);
}

elseif($n==32){
if(!$sus) $result=mysql_query("select * from $Tf order by forum_order");
$row=mysql_fetch_array($result);
}

elseif($n==33){
global $forumID;
if(!$sus) $result=mysql_query("select * from $Tf where forum_id=$forumID");
$row=mysql_fetch_array($result);
}

elseif($n==34){
/*Admin - update forums*/
global $forumname, $forumdesc, $forum_order, $forumicon, $forumID;
$result=mysql_query("update $Tf set forum_name='$forumname', forum_desc='$forumdesc', forum_order='$forum_order', forum_icon='$forumicon' where forum_id=$forumID");
$row=mysql_affected_rows();
}

elseif($n==35){
/*Admin - Deleting forum*/
global $forumID;
$result=mysql_query("DELETE FROM $Tf WHERE forum_id=$forumID");
$row=mysql_affected_rows();
$result=mysql_query("DELETE FROM $Tt WHERE forum_id=$forumID");
$row=$row+mysql_affected_rows();
$result=mysql_query("DELETE FROM $Tp WHERE forum_id=$forumID");
$row=$row+mysql_affected_rows();
}

elseif($n==40){
global $post;
$result = mysql_query("SELECT poster_name FROM $Tp WHERE post_id=$post");
$row=mysql_fetch_row($result);
}

elseif($n==41){
global $post;
$result=mysql_query("DELETE FROM $Tp WHERE post_id=$post");
$row=mysql_affected_rows();
}

elseif($n==42){
/*Check if post has to be deleted is not the first topic*/
global $post, $topic;
$row=mysql_fetch_row(mysql_query("select post_id from $Tp where topic_id=$topic order by post_id ASC limit 1"));
$row = $row[0];
if ($row == $post) $row = TRUE; else $row = FALSE;
}

elseif($n==43){
/*Check if topic isn't locked*/
$row=mysql_fetch_row(mysql_query("select topic_status from $Tt where topic_id=$topic"));
$row=$row[0];
}

elseif($n==44){
/*Check if user is allowed to edit his post*/
global $post, $user_id;
$result = mysql_query("select poster_id from $Tp where post_id=$post and poster_id=$user_id;");
$row=mysql_fetch_row($result);
}

elseif($n==45){
/*Get info about (edit) post text and possible topic title*/
global $post;
$result = mysql_query("select $Tp.post_text, $Tt.topic_title from $Tp,$Tt where $Tp.post_id=$post and $Tp.topic_id=$Tt.topic_id;");
$row=mysql_fetch_row($result);
}

elseif($n==46){
/*Update topic title when editing message*/
global $topic, $postTopic;
$row = mysql_query("update $Tt set topic_title='$postTopic' where topic_id=$topic") or die(mysql_error());
}

elseif($n==47){
/*Check if post wasn't edited by admin before*/
global $post;
$row = mysql_fetch_row(mysql_query("select post_status from $Tp where post_id=$post"));
$row = $row[0];
}

elseif($n==61){
/*User registration*/
$userData = $sus;
$userData[2] = md5($userData[2]);
$result = mysql_query("INSERT into $Tu (username, user_regdate, user_password, user_email, user_icq, user_website, user_occ, user_from, user_interest, user_viewemail, user_sorttopics, user_newpasswd) values ('$userData[1]', now(), '$userData[2]', '$userData[4]', '$userData[5]', '$userData[6]', '$userData[7]', '$userData[8]', '$userData[9]', '$userData[10]', '$userData[11]', '')");
$row=mysql_insert_id();
}

elseif($n==62){
/*Check if there is a user with following username and/or email*/
$result = mysql_query("SELECT * from $Tu where username='$sus[1]' or user_email='$sus[4]'");
$row = mysql_fetch_row($result);
}

elseif($n==63){
/*Get user data*/
$result = mysql_query("SELECT * from $Tu where user_id=$sus");
if (mysql_num_rows($result)>0) { $row = mysql_fetch_row($result); } else $row=FALSE;
}

elseif($n==12){
/*Stats Stuff*/
if(!$sus) $result=mysql_query("SELECT topic_id, topic_views, topic_title, forum_id FROM $Tt WHERE topic_views>0 ORDER BY topic_views DESC , topic_time DESC $makeLim");
if ($result) $row=mysql_fetch_row($result);
}

elseif($n==36)
/*Stats Stuff - Num Users*/
$row=mysql_result(mysql_query("SELECT count(user_id) FROM $Tu WHERE user_id>1"),0);

elseif($n==37)
/*Stats Stuff - Num Topics*/
$row=mysql_result(mysql_query("SELECT count(topic_id) FROM $Tt"),0);

elseif($n==38)
/*Stats Stuff - Num Posts*/
$row=mysql_result(mysql_query("SELECT count(post_id) FROM $Tp"),0);

elseif($n==39){
/*Stats Stuff - Num Posts*/
if(!$sus) $result=mysql_query("SELECT $Tt.topic_id, $Tt.topic_title, $Tt.forum_id, count($Tp.topic_id) as cnt FROM $Tt, $Tp WHERE $Tt.topic_id=$Tp.topic_id GROUP BY $Tp.topic_id ORDER BY cnt DESC, $Tt.topic_id DESC $makeLim ");
if($result) $row=mysql_fetch_row($result);
}

elseif($n==55){
/*Stats Stuff - most active users*/
if(!$sus) $result=mysql_query("SELECT $Tu.user_id, $Tu.username, count($Tp.poster_id) as cnt FROM $Tu, $Tp WHERE $Tu.user_id>1 AND $Tu.user_id=$Tp.poster_id GROUP BY $Tp.poster_id ORDER BY cnt DESC, $Tu.user_id DESC $makeLim ");
if($result) $row=mysql_fetch_row($result);
}

elseif($n==75){
/*Stats - admin name*/
$row=mysql_result(mysql_query("SELECT username FROM $Tu WHERE user_id=1"),0);
}

elseif($n==74)
/*Stats - last registered usr*/
$row=mysql_fetch_row(mysql_query("SELECT user_id, username FROM $Tu WHERE user_id>1 ORDER BY user_id DESC LIMIT 1"));

elseif($n==72){
/*User Stats Forums*/
global $userID;
if(!$sus) $result=mysql_query("SELECT $Tf.forum_id, $Tf.forum_name, count($Tp.forum_id) as cnt FROM $Tf, $Tp WHERE $Tf.forum_id=$Tp.forum_id AND $Tp.poster_id=$userID GROUP BY $Tp.forum_id ORDER BY cnt DESC, $Tf.forum_order, forum_name");
$row=mysql_fetch_array($result);
}

elseif($n==79){
global $poster_ip, $postRange;
/*Anti-Spam*/
if($postRange) $z=mysql_result(mysql_query("SELECT count(post_id) FROM $Tp WHERE poster_ip='$poster_ip' AND TO_DAYS(post_time)=TO_DAYS(now()) AND TIME_TO_SEC(now())-TIME_TO_SEC(post_time)<$postRange"),0);
if($z>0) $row=FALSE; else $row=TRUE;
}

elseif($n==64){
/*Deleting user from users table*/
$result = mysql_query("DELETE from $Tu where user_id=$sus");
$row = mysql_affected_rows();
}

elseif($n==65){
/*Deleting user messages from posts and topics table. Topics - delete also all associated posts*/
$prom1 = mysql_query("SELECT topic_id from $Tt where topic_poster='$sus'");
if (mysql_num_rows($prom1)>0) {
$row1=TRUE;
$doit = mysql_fetch_row($prom1);
do {
$topic_id = $doit[0];
$prom2 = mysql_query("DELETE from $Tp where topic_id=$topic_id");
$prom3 = mysql_query("DELETE from $Tt where topic_id=$topic_id");
}
while ($doit = mysql_fetch_row($prom1));
}
/*Topics*/

/*Posts - update also all associated topic_last_post_id's*/
$trm1 = mysql_query("SELECT topic_id from $Tp where poster_id=$sus");
if (mysql_num_rows($trm1)>0) {
$row2=TRUE;
$toWhat = mysql_fetch_row($trm1); 
do {
$topic_id = $toWhat[0];
$res0 = mysql_query("DELETE from $Tp where topic_id=$topic_id and poster_id=$sus");
$res1 = mysql_query("SELECT post_id from $Tp where topic_id={$toWhat[0]} order by post_id DESC limit 1");
if (mysql_num_rows($res1)>0) { $lastID = mysql_fetch_row($res1); $lastID = $lastID[0]; } else $lastID = 0;
$res2 = mysql_query("UPDATE $Tt set topic_last_post_id=$lastID where topic_id={$toWhat[0]}");
}
while ($toWhat = mysql_fetch_row($trm1));
}
/*Posts*/

/*Delete from sendMails*/
$res = mysql_query("delete from $Ts where user_id=$sus");

if ($row1 or $row2) $row = TRUE; else $row = FALSE;
}

elseif($n==48){
/*Update post text*/
global $post, $topic, $postText;
$result = mysql_query("update $Tp set post_text='$postText', post_status='$sus' where post_id=$post and topic_id=$topic");
$row = mysql_affected_rows();
}

elseif($n==50){
/*Update topics DB after deleted post*/
$row=mysql_fetch_row(mysql_query("SELECT post_id from $Tp where topic_id=$topic order by post_id DESC limit 1"));
$row=$row[0];
if($row) $row=mysql_query("UPDATE $Tt set topic_last_post_id=$row where topic_id=$topic");
}

elseif($n==51){
/*Move topic to another forum*/
global $forumWhere;
$row=mysql_fetch_row(mysql_query("SELECT forum_id from $Tf where forum_id=$forum"));
$row=$row[0];
if ($row) {
$row1=mysql_query("UPDATE $Tt set forum_id=$forumWhere where topic_id=$topic and forum_id=$forum");
$row2=mysql_query("UPDATE $Tp set forum_id=$forumWhere where topic_id=$topic and forum_id=$forum");
if ($row1==TRUE and $row2==TRUE) $row = TRUE; else $row=FALSE;
}
}

elseif($n==59){
/*View all posters that are posted under requested IP*/
global $postip;
if (!$sus) $result=mysql_query("SELECT DISTINCT poster_name, poster_id from $Tp where poster_ip='$postip'");
$row=mysql_fetch_row($result);
}

elseif($n==60){
/*Check if there is an admin in database, and get all available data about him*/
$result = mysql_query("SELECT * from $Tu where user_id=1");
$row = mysql_fetch_row($result);
}

elseif($n==66){
/*Make user posts as anonymous*/
$result1 = mysql_query("UPDATE $Tp set poster_id=0 where poster_id=$sus");
$result2 = mysql_query("UPDATE $Tt set topic_poster=0 where topic_poster='$sus'");
if ($result1 or $result2) $row = TRUE; else $row = FALSE;
}

elseif($n==67){
/*Check if email exists*/
global $email;
$result = mysql_query("select user_id from $Tu where user_email='$email'");
if (mysql_num_rows($result)>0) { $row = mysql_fetch_row($result); $row=$row[0]; } else $row=0;
}

elseif($n==68){
/*Create new user password and accept key*/
global $newPasswd, $confirmCode, $updID;
mysql_query("update $Tu set user_newpasswd='$newPasswd', user_newpwdkey='$confirmCode' where user_id=$updID");
$row = mysql_affected_rows();
}

elseif($n==69){
/*Update confirmed password*/
global $confirmCode;
$res = mysql_query("select user_newpasswd from $Tu where user_newpwdkey='$confirmCode'");
if (mysql_num_rows($res)>0) {
$newPasswd = mysql_fetch_row($res); $newPasswd=md5($newPasswd[0]);
mysql_query("update $Tu set user_password='$newPasswd', user_newpwdkey='', user_newpasswd='' where user_newpwdkey='$confirmCode'");
$row = mysql_affected_rows();
}
else {
$row=0;
}
}

elseif($n==70){
/*Update user prefs*/
global $user_id; 
$userData=$sus;
if ($userData[2]!='') { $updPwd = 'user_password=\''.md5($userData[2]).'\','; } else { $updPwd=''; }
$result = mysql_query("update $Tu set $updPwd user_email='$userData[4]', user_icq='$userData[5]', user_website='$userData[6]', user_occ='$userData[7]', user_from='$userData[8]', user_interest='$userData[9]', user_viewemail='$userData[10]', user_sorttopics='$userData[11]' where user_id=$user_id");
$row=mysql_affected_rows();
}

elseif($n==71){
/*When updating user email, see if no other exists*/
global $user_id, $email1;
$res = mysql_query("select user_id from $Tu where user_email='$email1' and user_id<>'$user_id'");
if (mysql_num_rows($res)>0) $row=1; else $row=0;
}

elseif($n==80){
global $user_id;
$rs = mysql_result(mysql_query("SELECT count(*) from $Ts where user_id=$user_id and topic_id=$topic"),0);
if($rs>0) $row=TRUE; else $row=FALSE;
}

elseif($n==81){
global $user_id, $user_email;
if ($user_email!='') {
$rs = mysql_query("insert into $Ts (user_id, user_email, forum_id, topic_id) values ('$user_id', '$user_email', '$forum', '$topic')")or die(mysql_error());
$row = mysql_affected_rows();
}
else $row=FALSE;
}

elseif($n==82){
global $delemail;
$sql = "delete from $Ts";
if ($delemail!='') $sql.=" where user_email='$delemail'";
$sql.=";";
$res = mysql_query($sql);
$row = mysql_affected_rows();
}

elseif($n==83){
/*User mass emailing*/
if (!$sus) $result = mysql_query("select user_id, user_email from $Ts where topic_id=$topic and forum_id=$forum");
$row = mysql_fetch_row($result);
}

elseif($n==84){
/*Admin - restore data*/
global $admin_usr, $admin_pwd, $admin_email;
$pwd = md5($admin_pwd);
$check = mysql_query("select * from $Tu where user_id=1");
if ($check and mysql_num_rows($check)>0) $res = mysql_query("update $Tu set username='$admin_usr', user_password='$pwd', user_email='$admin_email' where user_id=1");
else $res = mysql_query("insert into $Tu (user_id, username, user_password, user_email, user_regdate) values (1, '$admin_usr', '$pwd', '$admin_email', now())");
$row = mysql_affected_rows();
}

elseif($n==85){
global $banip;
$res = mysql_query ("select * from $Tb where banip='$banip'");
$row=mysql_fetch_row($res);
}

elseif($n==86){
global $banip;
$res = mysql_query("insert into $Tb (banip) values ('$banip')");
$row = mysql_affected_rows();
}

elseif($n==87){
/*Bans - admin panel*/
if (!$sus) $result = mysql_query ("select * from $Tb order by banip");
$row=mysql_fetch_row($result);
}

elseif($n==88){
$sql = "delete from $Tb";
if (sizeof($sus)>0) $sql.=' where';
for ($i=0; $i<sizeof($sus); $i++) {
if ($i!=0) $sql.=" or id={$sus[$i]}"; else $sql.=" id={$sus[$i]}";
}
$sql.=';';

$res = mysql_query ($sql);
$row = mysql_affected_rows();
}

elseif($n==89){
global $thisIp, $thisIpMask;
$res = mysql_query("select id from $Tb where banip='$thisIp' or banip='$thisIpMask'");
if ($res) $row = mysql_fetch_row($res);
}

elseif($n==90){
global $user, $viewmaxtopic;
if (!$sus) $result = mysql_query("select topic_id, forum_id, topic_title from $Tt where topic_poster=$user order by topic_time desc limit $viewmaxtopic");
$row = mysql_fetch_row($result);
}

elseif($n==91){
global $user, $viewmaxtopic;
if (!$sus) $result = mysql_query("select distinct $Tp.topic_id, $Tp.forum_id, $Tt.topic_title from $Tt,$Tp where $Tp.topic_id=$Tt.topic_id and $Tp.poster_id=$user and $Tp.poster_id!=$Tt.topic_poster group by $Tp.topic_id order by $Tp.post_time desc limit $viewmaxtopic");
$row = mysql_fetch_row($result);
}

elseif($n==92){
if (!$sus) $result = mysql_query("select * from $Tu");
if ($result) $row = mysql_fetch_row($result); else $row=FALSE;
}

elseif($n==93){
/*Get user posts count*/
global $user;
$result = mysql_query("select count(poster_id) from $Tp where poster_id!=0 and poster_id=$user");
if ($result) $row = mysql_fetch_row($result); else $row=FALSE;
}

elseif($n==94){
/*Get user topics count*/
global $user;
$result = mysql_query("select count(topic_poster) from $Tt where topic_poster!=0 and topic_poster=$user");
if ($result) $row = mysql_fetch_row($result); else $row=FALSE;
}

elseif ($n==96) {
/* Unsubscribe from topic */
global $user_id, $topicU;
$result=mysql_query("delete from $Ts where user_id={$user_id} and topic_id={$topicU}");
$row = mysql_affected_rows();
}

else $row=FALSE;

return $row;
}

?>