I have one more problem too. It appears my forum admin account lost admin privileges as there is a user in my dating panel called admin and one in phpbb called admin. For some reason it overwrote permissions.
FYI I'm using the "perfect phpbb integration script now to even get phpbb3 working at all. It was having some default_lang column doesn't exist error for the one that comes with vldpersonals."
<?php
/*
=====================================================
vldPersonals - by VLD Interactive
----------------------------------------------------
http://www.vldpersonals.com/
http://www.vldinteractive.com/
-----------------------------------------------------
Copyright (c) 2005-2010 VLD Interactive
=====================================================
THIS IS COPYRIGHTED SOFTWARE
PLEASE READ THE LICENSE AGREEMENT
http://www.vldpersonals.com/agreement/
=====================================================
*/
// ------------------------------------------------
// Add member
// ------------------------------------------------
function mod_phpbb3_add_member(&$MDB, $params)
{
global $DB, $SESSION, $PREFS;
// fetch system member
$result = $DB->query("SELECT username, password, email, lastvisit, joindate, ipaddress FROM " . DB_PREFIX . "members WHERE member_id='" . $params['member_id'] . "' LIMIT 1");
if (!$DB->num_rows($result)) return;
$user_data = $DB->fetch_array($result);
// set general details
$user_data['username'] = mysql_real_escape_string($user_data['username']);
$user_data['email'] = mysql_real_escape_string($user_data['email']);
$user_data['ipaddress'] = mysql_real_escape_string($user_data['ipaddress']);
$user_data['lastvisit'] = mysql_real_escape_string($user_data['lastvisit'] ? $user_data['lastvisit'] : time());
$user_data['joindate'] = mysql_real_escape_string($user_data['joindate']);
$user_data['ipaddress'] = mysql_real_escape_string($user_data['ipaddress'] != 'Uknown' ? $user_data['ipaddress'] : '127.0.0.1');
// set password
if (isset($params['password']) && $params['password']) {
$user_data['password'] = mysql_real_escape_string(md5($params['password']));
} else {
$user_data['password'] = mysql_real_escape_string($user_data['password']);
}
// set group/block
if (isset($params['block']) && $params['block']) {
$user_data['inactive'] = "1";
$user_data['admin'] = "0";
} elseif (isset($params['admin']) && $params['admin']) {
$user_data['inactive'] = "0";
$user_data['admin'] = "1";
} else {
$user_data['inactive'] = "0";
$user_data['admin'] = "0";
}
$usernameTL = strtolower($user_data['username']);
// fetch forum member
$result = $MDB->query("SELECT user_id, user_type FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "users WHERE username_clean='" . $usernameTL . "' LIMIT 1");
if ($MDB->num_rows($result)) {
$arrUserID = $MDB->fetch_array($result);
} else {
$arrUserID = array('user_id' => 0, 'user_type' => 0);
}
// set commmon details
$where_sql = "SET group_id=2,
username = '" . $user_data['username'] . "',
username_clean = '" . strtolower($user_data['username']) . "',
user_password = '{$user_data['password']}',
user_passchg = '{$user_data['lastvisit']}',
user_email = '{$user_data['email']}',
user_type = {$user_data['inactive']},
user_inactive_reason = {$user_data['inactive']},
user_regdate = '{$user_data['joindate']}',
user_lastmark = '{$user_data['lastvisit']}',
user_lastvisit = '{$user_data['lastvisit']}'";
// new member
if (! $arrUserID['user_id']) {
$where_sql .= ",user_style = 1,
user_ip = '{$user_data['ipaddress']}',
user_lang = 'en'";
$MDB->query("INSERT INTO " . $PREFS->conf['module_phpbb3_table_prefix'] . "users {$where_sql}");
$userID = $MDB->get_insert_id();
$MDB->query("INSERT INTO " . $PREFS->conf['module_phpbb3_table_prefix'] . "user_group (user_id, group_id, group_leader, user_pending) VALUES ({$userID}, 2, 0, 0)");
if (!$user_data['inactive']) {
$MDB->query("UPDATE " . $PREFS->conf['module_phpbb3_table_prefix'] . "config SET config_value=config_value+1 WHERE config_name='num_users' LIMIT 1");
}
}
// existing member
else {
$MDB->query("UPDATE " . $PREFS->conf['module_phpbb3_table_prefix'] . "users {$where_sql} WHERE user_id = {$arrUserID['user_id']} LIMIT 1");
if (!$arrUserID['user_type'] && $user_data['inactive']) {
$MDB->query("UPDATE " . $PREFS->conf['module_phpbb3_table_prefix'] . "config SET config_value=config_value-1 WHERE config_name='num_users' LIMIT 1");
} elseif ($arrUserID['user_type'] && !$user_data['inactive']) {
$MDB->query("UPDATE " . $PREFS->conf['module_phpbb3_table_prefix'] . "config SET config_value=config_value+1 WHERE config_name='num_users' LIMIT 1");
}
}
// set admin permissions if ($user_data['admin']) {
$MDB->query("INSERT INTO " . $PREFS->conf['module_phpbb3_table_prefix'] . "acl_users (user_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ({$arrUserID['user_id']}, 0, 0, 11, 0)");
$MDB->query("INSERT INTO " . $PREFS->conf['module_phpbb3_table_prefix'] . "moderator_cache (forum_id, user_id, username, group_id, group_name, display_on_index) values (0,{$arrUserID['user_id']},'{$user_data['username']}',0,'',
1)");
} else {
$MDB->query("DELETE FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "acl_users WHERE user_id = {$arrUserID['user_id']}");
$MDB->query("DELETE FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "moderator_cache WHERE user_id = {$arrUserID['user_id']}");
}
}
// End function
// ------------------------------------------------
// Update member
// ------------------------------------------------
function mod_phpbb3_update_member(&$MDB, $params)
{
global $DB, $SESSION, $PREFS;
mod_phpbb3_add_member($MDB, $params);
}
// End function
// ------------------------------------------------
// Block member
// ------------------------------------------------
function mod_phpbb3_block_member(&$MDB, $params)
{
global $DB, $SESSION, $PREFS;
// fetch system member
$result = $DB->query("SELECT username FROM " . DB_PREFIX . "members WHERE member_id='" . $params['member_id'] . "' LIMIT 1");
if (!$DB->num_rows($result)) return;
$user_data = $DB->fetch_array($result);
$usernameTL = strtolower($user_data['username']);
// fetch forum member
$result = $MDB->query("SELECT user_id FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "users WHERE username_clean = '$usernameTL' LIMIT 1");
if ($MDB->num_rows($result)) {
$arrUserID = $MDB->fetch_array($result);
} else {
$arrUserID = array('user_id' => 0);
}
// block member
if ($arrUserID['user_id']) {
$DB->query("UPDATE " . $PREFS->conf['module_phpbb3_table_prefix'] . "users SET user_type=1, user_inactive_reason=1 WHERE user_id = {$arrUserID['user_id']} LIMIT 1");
$DB->query("UPDATE " . $PREFS->conf['module_phpbb3_table_prefix'] . "config SET config_value=config_value-1 WHERE config_name='num_users' LIMIT 1");
}
}
// End function
// ------------------------------------------------
// Unblock member
// ------------------------------------------------
function mod_phpbb3_unblock_member(&$MDB, $params)
{
global $DB, $SESSION, $PREFS;
// fetch system member
$result = $DB->query("SELECT username FROM " . DB_PREFIX . "members WHERE member_id='" . $params['member_id'] . "' LIMIT 1");
if (!$DB->num_rows($result)) return;
$user_data = $DB->fetch_array($result);
$usernameTL = strtolower($user_data['username']);
// fetch forum member
$result = $MDB->query("SELECT user_id FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "users WHERE username_clean = '$usernameTL' LIMIT 1");
if ($MDB->num_rows($result)) {
$arrUserID = $MDB->fetch_array($result);
} else {
$arrUserID = array('user_id' => 0);
}
// unblock member
if ($arrUserID['user_id']) {
$MDB->query("UPDATE " . $PREFS->conf['module_phpbb3_table_prefix'] . "users SET user_type=0, user_inactive_reason=0 WHERE user_id = {$arrUserID['user_id']} LIMIT 1");
$MDB->query("UPDATE " . $PREFS->conf['module_phpbb3_table_prefix'] . "config SET config_value=config_value+1 WHERE config_name='num_users' LIMIT 1");
}
}
// End function
// ------------------------------------------------
// Delete member
// ------------------------------------------------
function mod_phpbb3_delete_member(&$MDB, $params)
{
global $DB, $SESSION, $PREFS;
// fetch system member
$result = $DB->query("SELECT username, email, joindate FROM " . DB_PREFIX . "members WHERE member_id='" . $params['member_id'] . "' LIMIT 1");
if (!$DB->num_rows($result)) return;
$user_data = $DB->fetch_array($result);
$usernameTL = strtolower($user_data['username']);
// fetch forum member
$result = $MDB->query("SELECT * FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "users WHERE username_clean = '$usernameTL' LIMIT 1");
if ($MDB->num_rows($result)) {
$arrUserID = $MDB->fetch_array($result);
} else {
$arrUserID = array('user_id' => 0, 'user_type' => 0);
}
// delete member
if ($arrUserID['user_id']) {
// $arrUserID - contains a user;
if(!defined("GUEST_NAME"))
define("GUEST_NAME", "Ospite"); // name of the guest in your language;
if(!defined("ANONYMOUS"))
define('ANONYMOUS', 1); //Anonymous ID. Default is 1;
$uname=$arrUserID['username'];
// set forum's laster postred name to Guest;
$sql = 'UPDATE ' . $PREFS->conf['module_phpbb3_table_prefix'] . 'forums
SET forum_last_poster_id = ' . ANONYMOUS . ", forum_last_poster_colour = '',
forum_last_poster_name = '" .$uname . "'
WHERE forum_last_poster_id = " . $arrUserID['user_id'] ;
$MDB->query($sql);
// reset all their posts to Anonymous user
$sql = 'UPDATE ' . $PREFS->conf['module_phpbb3_table_prefix'] . 'posts
SET poster_id = ' . ANONYMOUS . ",
post_username = '" . $uname . "'
WHERE poster_id = " . $arrUserID['user_id'] ;
$MDB->query($sql);
// reset last edit
$sql = 'UPDATE ' . $PREFS->conf['module_phpbb3_table_prefix'] . 'posts
SET post_edit_user = ' . ANONYMOUS . "
WHERE post_edit_user = " . $arrUserID['user_id'] ;
$MDB->query($sql);
// reset first poster for every topic;
$sql = 'UPDATE ' . $PREFS->conf['module_phpbb3_table_prefix'] . 'topics
SET topic_poster = ' . ANONYMOUS . ", topic_first_poster_colour = '', topic_first_poster_name = '" . $uname . "'
WHERE topic_poster = " . $arrUserID['user_id'] ;
$MDB->query($sql);
// reset last poster for every topic
$sql = 'UPDATE ' . $PREFS->conf['module_phpbb3_table_prefix'] . 'topics
SET topic_last_poster_id = ' . ANONYMOUS . ", topic_last_poster_colour = '',
topic_last_poster_name = '" . $uname . "'
WHERE topic_last_poster_id = " . $arrUserID['user_id'] ;
$MDB->query($sql);
// reset attachments;
$sql = 'UPDATE ' . $PREFS->conf['module_phpbb3_table_prefix'] . 'attachments
SET poster_id = ' . ANONYMOUS . "
WHERE poster_id = " . $arrUserID['user_id'] ;
$MDB->query($sql);
// if user had posts; we increment the number of posts for anonymous;
if ($arrUserID['user_posts']) {
$sql = 'UPDATE ' . $PREFS->conf['module_phpbb3_table_prefix'] . 'users
SET user_posts = user_posts + ' . $arrUserID['user_posts'] . '
WHERE user_id = ' . ANONYMOUS;
$MDB->query($sql);
}
// removing the user as per original script;
$MDB->query("DELETE FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "users WHERE user_id = {$arrUserID['user_id']} LIMIT 1");
$MDB->query("DELETE FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "banlist WHERE ban_userid = {$arrUserID['user_id']} LIMIT 1");
$MDB->query("DELETE FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "sessions WHERE session_user_id = {$arrUserID['user_id']}");
$MDB->query("DELETE FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "sessions_keys WHERE user_id = {$arrUserID['user_id']}");
$MDB->query("DELETE FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "user_group WHERE user_id = {$arrUserID['user_id']}");
$MDB->query("DELETE FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "acl_users WHERE user_id = {$arrUserID['user_id']}");
if (!$arrUserID['user_type']) {
$MDB->query("UPDATE " . $PREFS->conf['module_phpbb3_table_prefix'] . "config SET config_value=config_value-1 WHERE config_name='num_users' LIMIT 1");
}
}
}
// End function
// ------------------------------------------------
// Login member
// ------------------------------------------------
function mod_phpbb3_login_member(&$MDB, $params)
{
global $DB, $SESSION, $PREFS, $LANG;
$config = array();
$config = get_config($MDB);
$usernameTL = strtolower($params['username']);
// fetch forum member
$result = $MDB->query("SELECT user_id FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "users WHERE username_clean = '$usernameTL' LIMIT 1");
if ($MDB->num_rows($result)) {
$arrUserID = $MDB->fetch_array($result);
} else {
return;
}
unset($result);
$userID = $arrUserID['user_id'];
$current_time = time();
$auto_login_key = unique_id($MDB);
// fetch forum data
$result = $MDB->query("SELECT key_id FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "sessions_keys WHERE user_id = '$userID' LIMIT 1");
if ($MDB->num_rows($result)) {
$arrUSK = $MDB->fetch_array($result);
$key_id = $arrUSK['key_id'];
$MDB->query("UPDATE " . $PREFS->conf['module_phpbb3_table_prefix'] . "sessions_keys
SET key_id = '" . md5($auto_login_key) . "' WHERE key_id = '$key_id' LIMIT 1");
} else {
$MDB->query("INSERT INTO " . $PREFS->conf['module_phpbb3_table_prefix'] . "sessions_keys
(key_id, user_id, last_ip, last_login)
VALUES ('" . md5($auto_login_key) . "', $userID, 0, $current_time)");
}
// And now rebuild the cookie
$cookie_expire = time() + (($config['max_autologin_time']) ? 86400 * (int) $config['max_autologin_time'] : 31536000);
set_cookie('u', $userID, $cookie_expire, $MDB);
set_cookie('k', $auto_login_key, $cookie_expire, $MDB);
set_cookie('sid', session_id(), $cookie_expire, $MDB);
}
// End function
// ------------------------------------------------
// Logout member
// ------------------------------------------------
function mod_phpbb3_logout_member(&$MDB, $params)
{
global $DB, $SESSION, $PREFS, $LANG;
$config = array();
$config = get_config($MDB);
$usernameTL = strtolower($params['username']);
// fetch forum member
$result = $MDB->query("SELECT user_id FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "users WHERE username_clean = '$usernameTL' LIMIT 1");
if ($MDB->num_rows($result)) {
$arrUserID = $MDB->fetch_array($result);
} else {
return;
}
unset($result);
$userID = $arrUserID['user_id'];
$current_time = time();
$MDB->query("DELETE FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "sessions WHERE session_user_id ='$userID'");
$MDB->query("DELETE FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "sessions_keys WHERE user_id = '$userID'");
// And now kill the cookie
$cookie_expire = $current_time - 31536000;
set_cookie('u', '', $cookie_expire, $MDB);
set_cookie('k', '', $cookie_expire, $MDB);
set_cookie('sid', '', $cookie_expire, $MDB);
unset($current_time, $cookie_expire);
}
// End Function
function get_config(&$MDB)
{
global $DB, $PREFS;
$result = $MDB->query("SELECT config_name, config_value
FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "config");
if ($MDB->num_rows($result)) {
// ------------------------------------------------
// Fetch resultset
// ------------------------------------------------
while ($obj = $MDB->fetch_array($result, MYSQL_ASSOC)) {
$board_config[$obj['config_name']] = $obj['config_value'];
}
unset($obj);
}
unset($result);
return $board_config;
}
function set_cookie($name, $cookiedata, $cookietime, &$MDB)
{
$config = get_config($MDB);
$name_data = rawurlencode($config['cookie_name'] . '_' . $name) . '=' . rawurlencode($cookiedata);
$expire = gmdate('D, d-M-Y H:i:s \\G\\M\\T', $cookietime);
$domain = (!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain'];
header('Set-Cookie: ' . $name_data . (($cookietime) ? '; expires=' . $expire : '') . '; path=' . $config['cookie_path'] . $domain . ((!$config['cookie_secure']) ? '' : '; secure') . '; HttpOnly', false);
}
/**
* Return unique id
*
* @param string $extra additional entropy
*/
function unique_id(&$MDB)
{
global $DB;
$config = get_config($MDB);
unset($current_time, $cookie_expire);
}
// End Function
function get_config(&$MDB)
{
global $DB, $PREFS;
$result = $MDB->query("SELECT config_name, config_value
FROM " . $PREFS->conf['module_phpbb3_table_prefix'] . "config");
if ($MDB->num_rows($result)) {
// ------------------------------------------------
// Fetch resultset
// ------------------------------------------------
while ($obj = $MDB->fetch_array($result, MYSQL_ASSOC)) {
$board_config[$obj['config_name']] = $obj['config_value'];
}
unset($obj);
}
unset($result);
return $board_config;
}
function set_cookie($name, $cookiedata, $cookietime, &$MDB)
{
$config = get_config($MDB);
$name_data = rawurlencode($config['cookie_name'] . '_' . $name) . '=' . rawurlencode($cookiedata);
$expire = gmdate('D, d-M-Y H:i:s \\G\\M\\T', $cookietime);
$domain = (!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain'];
header('Set-Cookie: ' . $name_data . (($cookietime) ? '; expires=' . $expire : '') . '; path=' . $config['cookie_path'] . $domain . ((!$config['cookie_secure']) ? '' : '; secure') . '; HttpOnly', false);
}
/**
* Return unique id
*
* @param string $extra additional entropy
*/
function unique_id(&$MDB)
{
global $DB;
$config = get_config($MDB);
$val = $config['rand_seed'] . microtime();
$val = md5($val);
return substr($val, 4, 16);
}
?>