<?php
// Конфиг форума
$bb_host = "localhost";
$bb_dbname = "inv2";
$bb_dbuser = "root";
$bb_dbpasswd = "password";
$bb_url = "forums/";
$bb_panel = $bb_url."index.php?act=UserCP";
$bb_whatsnew = $bb_url."index.php?act=Search&CODE=getnew";
$bb_pms = $bb_url."index.php?act=Msg";
$bb_private = "";
$bb_prefix = "ibf_";
// приваты
if ($bb_private) {
if (preg_match("/,/i",$bb_private)) {
$asql = "WHERE ";
$forums = explode(",",$bb_private);
for($i=0;$i<count($forums);$i++) {
$asql .= "NOT(forum_id = '$forums[$i]')";
if ($i<count($forums)-1) $asql .= " AND ";
}
} else {
$asql = "WHERE NOT(forum_id = '$forums')";
}
}
function BBConnect() {
global $bb_host, $bb_dbname, $bb_dbuser, $bb_dbpasswd;
mysql_connect($bb_host,$bb_dbuser,$bb_dbpasswd);
mysql_select_db("$bb_dbname");
}
function BBGetTopics() {
global $bb_url, $asql, $bb_prefix;
$topics = $bb_prefix."topics";
BBConnect();
$bb_data = array();
$result = mysql_query("SELECT forum_id, tid, title FROM $topics ORDER BY last_post $asql DESC LIMIT 10");
while(list($board, $threadid, $title) = mysql_fetch_row($result)) {
array_push($bb_data, $bb_url."index.php?act=ST&f=$board&t=$threadid||~||$title");
}
return $bb_data;
}
function BBGetUser($username, $password) {
global $bb_prefix;
$members = $bb_prefix."members";
$membersc = $bb_prefix."members_converge";
BBConnect();
$result = mysql_query("SELECT * FROM $members WHERE name = '$username'");
$userdata = mysql_fetch_array($result);
$query = mysql_query("SELECT * FROM $membersc WHERE converge_email = '$userdata[email]'");
$convdata = mysql_fetch_array($query);
$password = md5(md5($convdata[converge_pass_salt]).$password);
if (($userdata[mgroup] == 3) or ($userdata[mgroup] == 4)) {
($convdata[converge_pass_hash] == $password) ? $pwok = 1 : $pwok = 0;
} else {
$pwok = 0;
}
return $pwok;
}
function BBCheckUser($username, $email) {
global $bb_prefix;
$members = $bb_prefix."members";
BBConnect();
$result = mysql_query("SELECT * FROM $members WHERE name = '$username' OR email = '$email'");
(mysql_num_rows($result)) ? $pwok = 1 : $pwok = 0;
return $pwok;
}
function BBUserInsert($username, $password, $birthday, $email, $ipaddress) {
global $bb_prefix;
$members = $bb_prefix."members";
$membersc = $bb_prefix."members_converge";
BBConnect();
$result = mysql_query("SELECT id FROM $members ORDER BY id DESC LIMIT 1");
list ($userid) = mysql_fetch_row($result);
$userid++;
$regdate = mktime();
for ($i=0;$i<5;$i++) $salt .= chr(rand(33, 126));
$password = md5(md5($salt).$password);
$loginkey = md5(rand(1,32768));
mysql_query("INSERT INTO $members ( `id` , `name` , `email` , `ip_address` , `joined` , `mgroup` , `member_login_key` )
VALUES ('$userid', '$username', '$email', '$ipaddress', '$regdate', '3', '$loginkey')");
mysql_query("INSERT INTO $membersc ( `converge_email` , `converge_joined` , `converge_pass_hash` , `converge_pass_salt` )
VALUES ('$email', '$regdate', '$password', '$salt')");
dbconnect();
}
function BBUserCount($username) {
global $bb_prefix;
$members = $bb_prefix."members";
BBConnect();
mysql_query("UPDATE $members SET posts=posts+1 WHERE name = '$username'");
dbconnect();
}
function BBGrabSig($username) {
global $bb_prefix;
$members = $bb_prefix."members";
$memberse = $bb_prefix."member_extra";
BBConnect();
$query = mysql_query("SELECT id FROM $members WHERE name = '$username'");
list($id) = mysql_fetch_row($query);
$query = mysql_query("SELECT signature FROM $memberse WHERE id = '$id'");
list($signature) = mysql_fetch_row($query);
return $signature;
}
function BBGetXML() {
global $bb_url,$siteurl,$asql,$bb_prefix;
$topics = $bb_prefix."topics";
BBConnect();
$bb_data = array();
$result = mysql_query("SELECT forum_id, tid, title, posts FROM $topics $asql ORDER BY last_post DESC LIMIT 20");
while(list($board, $threadid, $title, $posts) = mysql_fetch_row($result)) {
array_push($bb_data, $bb_url."index.php?act=ST&f=$board&t=$threadid||~||$title||~||Replies: $posts");
}
return $bb_data;
}
function BBGetEmail($username) {
global $bb_prefix;
$members = $bb_prefix."members";
BBConnect();
$query = mysql_query("SELECT email FROM $members WHERE name = '$username'");
list($email) = mysql_fetch_row($query);
return $email;
}
function BBLastTopics($date) {
global $bb_prefix;
BBConnect();
$table = $bb_prefix."topics";
$query = mysql_query("SELECT * FROM $table WHERE last_post > ('$date')");
$bb_new = mysql_num_rows($query);
return $bb_new;
}
function BBPMs($user) {
global $bb_prefix;
BBConnect();
$members = $bb_prefix."members";
$query = mysql_query("SELECT id FROM $members WHERE name = '$user'");
list($userid) = mysql_fetch_row($query);
$messages = $bb_prefix."message_topics";
$query = mysql_query("SELECT * FROM $messages WHERE mt_read = '0' AND mt_to_id = '$userid'");
$bb_pmnew = mysql_num_rows($query);
return $bb_pmnew;
}
function BBCookieInit($username, $password) {
global $bb_prefix;
$members = $bb_prefix."members";
$membersc = $bb_prefix."members_converge";
BBConnect();
$result = mysql_query("SELECT * FROM $members WHERE name = '$username'");
$userdata = mysql_fetch_array($result);
if (($userdata[mgroup] == 3) or ($userdata[mgroup] == 4))
{
$query = mysql_query("SELECT * FROM $membersc WHERE converge_email = '$userdata[email]'");
$convdata = mysql_fetch_array($query);
$password = md5(md5($convdata[converge_pass_salt]).$password);
$loginkey = md5(rand(1,32768));
mysql_query("UPDATE $members SET member_login_key = '$loginkey'");
if ($password == $convdata[converge_pass_hash])
{
setcookie("member_id",$userdata[id],time()+60*60*24*360,"/");
setcookie("pass_hash",$loginkey,time()+60*60*24*360,"/");
}
}
}
function BBCookieFlush() {
setcookie("member_id",0,0,"/");
setcookie("pass_hash",0,0,"/");
setcookie("session_id",0,0,"/");
}
?>