Subversion Repositories svnkaklik

Compare Revisions

Ignore whitespace Rev 5 → Rev 6

/web/test/gallery/cpg133/bridge/_vti_cnf/invisionboard.inc.php
0,0 → 1,14
vti_encoding:SR|utf8-nl
vti_timelastmodified:TR|19 Apr 2005 03:17:14 -0000
vti_extenderversion:SR|6.0.2.5516
vti_author:SR|KAKLIK\\Jakub
vti_modifiedby:SR|KAKLIK\\Jakub
vti_timecreated:TR|19 Apr 2005 03:17:14 -0000
vti_cacheddtm:TX|19 Apr 2005 03:17:14 -0000
vti_filesize:IR|21919
vti_cachedneedsrewrite:BR|false
vti_cachedhasbots:BR|false
vti_cachedhastheme:BR|false
vti_cachedhasborder:BR|false
vti_charset:SR|windows-1250
vti_backlinkinfo:VX|
/web/test/gallery/cpg133/bridge/_vti_cnf/phpbb.inc.php
0,0 → 1,14
vti_encoding:SR|utf8-nl
vti_timelastmodified:TR|19 Apr 2005 03:17:14 -0000
vti_extenderversion:SR|6.0.2.5516
vti_author:SR|KAKLIK\\Jakub
vti_modifiedby:SR|KAKLIK\\Jakub
vti_timecreated:TR|19 Apr 2005 03:17:14 -0000
vti_cacheddtm:TX|19 Apr 2005 03:17:14 -0000
vti_filesize:IR|23504
vti_cachedneedsrewrite:BR|false
vti_cachedhasbots:BR|false
vti_cachedhastheme:BR|false
vti_cachedhasborder:BR|false
vti_charset:SR|windows-1250
vti_backlinkinfo:VX|
/web/test/gallery/cpg133/bridge/_vti_cnf/punbb.inc.php
0,0 → 1,14
vti_encoding:SR|utf8-nl
vti_timelastmodified:TR|19 Apr 2005 03:17:14 -0000
vti_extenderversion:SR|6.0.2.5516
vti_author:SR|KAKLIK\\Jakub
vti_modifiedby:SR|KAKLIK\\Jakub
vti_timecreated:TR|19 Apr 2005 03:17:14 -0000
vti_cacheddtm:TX|19 Apr 2005 03:17:14 -0000
vti_filesize:IR|19560
vti_cachedneedsrewrite:BR|false
vti_cachedhasbots:BR|false
vti_cachedhastheme:BR|false
vti_cachedhasborder:BR|false
vti_charset:SR|windows-1250
vti_backlinkinfo:VX|
/web/test/gallery/cpg133/bridge/_vti_cnf/smf.inc.php
0,0 → 1,14
vti_encoding:SR|utf8-nl
vti_timelastmodified:TR|19 Apr 2005 03:17:14 -0000
vti_extenderversion:SR|6.0.2.5516
vti_author:SR|KAKLIK\\Jakub
vti_modifiedby:SR|KAKLIK\\Jakub
vti_timecreated:TR|19 Apr 2005 03:17:14 -0000
vti_cacheddtm:TX|19 Apr 2005 03:17:14 -0000
vti_filesize:IR|23905
vti_cachedneedsrewrite:BR|false
vti_cachedhasbots:BR|false
vti_cachedhastheme:BR|false
vti_cachedhasborder:BR|false
vti_charset:SR|windows-1250
vti_backlinkinfo:VX|
/web/test/gallery/cpg133/bridge/_vti_cnf/vbulletin.inc.php
0,0 → 1,14
vti_encoding:SR|utf8-nl
vti_timelastmodified:TR|19 Apr 2005 03:17:14 -0000
vti_extenderversion:SR|6.0.2.5516
vti_author:SR|KAKLIK\\Jakub
vti_modifiedby:SR|KAKLIK\\Jakub
vti_timecreated:TR|19 Apr 2005 03:17:14 -0000
vti_cacheddtm:TX|19 Apr 2005 03:17:14 -0000
vti_filesize:IR|20540
vti_cachedneedsrewrite:BR|false
vti_cachedhasbots:BR|false
vti_cachedhastheme:BR|false
vti_cachedhasborder:BR|false
vti_charset:SR|windows-1250
vti_backlinkinfo:VX|
/web/test/gallery/cpg133/bridge/_vti_cnf/vbulletin23.inc.php
0,0 → 1,14
vti_encoding:SR|utf8-nl
vti_timelastmodified:TR|19 Apr 2005 03:17:14 -0000
vti_extenderversion:SR|6.0.2.5516
vti_author:SR|KAKLIK\\Jakub
vti_modifiedby:SR|KAKLIK\\Jakub
vti_timecreated:TR|19 Apr 2005 03:17:14 -0000
vti_cacheddtm:TX|19 Apr 2005 03:17:14 -0000
vti_filesize:IR|22164
vti_cachedneedsrewrite:BR|false
vti_cachedhasbots:BR|false
vti_cachedhastheme:BR|false
vti_cachedhasborder:BR|false
vti_charset:SR|windows-1250
vti_backlinkinfo:VX|
/web/test/gallery/cpg133/bridge/_vti_cnf/vbulletin3.0_readme.txt
0,0 → 1,6
vti_encoding:SR|utf8-nl
vti_timelastmodified:TR|19 Apr 2005 02:48:30 -0000
vti_extenderversion:SR|6.0.2.5516
vti_cacheddtm:TX|19 Apr 2005 02:48:30 -0000
vti_filesize:IR|3199
vti_backlinkinfo:VX|
/web/test/gallery/cpg133/bridge/_vti_cnf/vbulletin30.inc.php
0,0 → 1,14
vti_encoding:SR|utf8-nl
vti_timelastmodified:TR|19 Apr 2005 03:17:14 -0000
vti_extenderversion:SR|6.0.2.5516
vti_author:SR|KAKLIK\\Jakub
vti_modifiedby:SR|KAKLIK\\Jakub
vti_timecreated:TR|19 Apr 2005 03:17:14 -0000
vti_cacheddtm:TX|19 Apr 2005 03:17:14 -0000
vti_filesize:IR|23025
vti_cachedneedsrewrite:BR|false
vti_cachedhasbots:BR|false
vti_cachedhastheme:BR|false
vti_cachedhasborder:BR|false
vti_charset:SR|windows-1250
vti_backlinkinfo:VX|
/web/test/gallery/cpg133/bridge/_vti_cnf/vbulletin3gamma.inc.php
0,0 → 1,14
vti_encoding:SR|utf8-nl
vti_timelastmodified:TR|19 Apr 2005 03:17:14 -0000
vti_extenderversion:SR|6.0.2.5516
vti_author:SR|KAKLIK\\Jakub
vti_modifiedby:SR|KAKLIK\\Jakub
vti_timecreated:TR|19 Apr 2005 03:17:14 -0000
vti_cacheddtm:TX|19 Apr 2005 03:17:14 -0000
vti_filesize:IR|21016
vti_cachedneedsrewrite:BR|false
vti_cachedhasbots:BR|false
vti_cachedhastheme:BR|false
vti_cachedhasborder:BR|false
vti_charset:SR|windows-1250
vti_backlinkinfo:VX|
/web/test/gallery/cpg133/bridge/_vti_cnf/woltlab21.inc.php
0,0 → 1,14
vti_encoding:SR|utf8-nl
vti_timelastmodified:TR|19 Apr 2005 03:17:14 -0000
vti_extenderversion:SR|6.0.2.5516
vti_author:SR|KAKLIK\\Jakub
vti_modifiedby:SR|KAKLIK\\Jakub
vti_timecreated:TR|19 Apr 2005 03:17:14 -0000
vti_cacheddtm:TX|19 Apr 2005 03:17:14 -0000
vti_filesize:IR|23809
vti_cachedneedsrewrite:BR|false
vti_cachedhasbots:BR|false
vti_cachedhastheme:BR|false
vti_cachedhasborder:BR|false
vti_charset:SR|windows-1250
vti_backlinkinfo:VX|
/web/test/gallery/cpg133/bridge/_vti_cnf/yabbse.inc.php
0,0 → 1,14
vti_encoding:SR|utf8-nl
vti_timelastmodified:TR|19 Apr 2005 03:17:14 -0000
vti_extenderversion:SR|6.0.2.5516
vti_author:SR|KAKLIK\\Jakub
vti_modifiedby:SR|KAKLIK\\Jakub
vti_timecreated:TR|19 Apr 2005 03:17:14 -0000
vti_cacheddtm:TX|19 Apr 2005 03:17:14 -0000
vti_filesize:IR|25926
vti_cachedneedsrewrite:BR|false
vti_cachedhasbots:BR|false
vti_cachedhastheme:BR|false
vti_cachedhasborder:BR|false
vti_charset:SR|windows-1250
vti_backlinkinfo:VX|
/web/test/gallery/cpg133/bridge/invisionboard.inc.php
0,0 → 1,510
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2005 Coppermine Dev Team
v1.1 originaly written by Gregory DEMAR
 
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.
********************************************
Coppermine version: 1.3.3
$Source: /cvsroot/coppermine/stable/bridge/invisionboard.inc.php,v $
$Revision: 1.9 $
$Author: gaugau $
$Date: 2005/04/19 03:17:13 $
**********************************************/
 
// ------------------------------------------------------------------------- //
// Modify the values below according to your Board installation //
// ------------------------------------------------------------------------- //
 
// database configuration
define('IB_DB_NAME', 'ivboard'); // The name of the database used by the board
define('IB_BD_HOST', 'localhost'); // The name of the database server
define('IB_DB_USERNAME', 'root'); // The username to use to connect to the database
define('IB_DB_PASSWORD', ''); // The password to use to connect to the database
 
// The web path to your Invision Board directory
// In this example http://yoursite_name.com/ivboard/
define('IB_WEB_PATH', '/ivboard/');
// ------------------------------------------------------------------------- //
// You can keep the default values below if your installation is standard
// ------------------------------------------------------------------------- //
// The prefix for the Invision Board cookies
define('IB_COOKIE_PREFIX', ''); // The prefix used for board cookies
 
// Prefix and names for the database tables
define('IB_TABLE_PREFIX', 'ibf_'); // The prefix used for the DB tables
define('IB_USER_TABLE', 'members'); // The members table
define('IB_SESSION_TABLE', 'sessions'); // The sessions table
define('IB_GROUP_TABLE', 'groups'); // The groups table
 
// Group definitions (default values used by the board)
define('IB_VALIDATING_GROUP', 1);
define('IB_GUEST_GROUP', 2);
define('IB_MEMBERS_GROUP', 3);
define('IB_ADMIN_GROUP', 4);
define('IB_BANNED_GROUP', 5);
// ------------------------------------------------------------------------- //
// Nothing to edit below this line
// ------------------------------------------------------------------------- //
// Authenticate a user using cookies
function udb_authenticate()
{
global $HTTP_COOKIE_VARS, $USER_DATA, $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
global $HTTP_SERVER_VARS, $HTTP_X_FORWARDED_FOR, $HTTP_PROXY_USER, $REMOTE_ADDR;
// For error checking
$CONFIG['TABLE_USERS'] = '**ERROR**';
// Permissions for a default group
$default_group = array('group_id' => IB_GUEST_GROUP,
'group_name' => 'Unknown',
'has_admin_access' => 0,
'can_send_ecards' => 0,
'can_rate_pictures' => 0,
'can_post_comments' => 0,
'can_upload_pictures' => 0,
'can_create_albums' => 0,
'pub_upl_need_approval' => 1,
'priv_upl_need_approval' => 1,
'upload_form_config' => 0,
'custom_user_upload' => 0,
'num_file_upload' => 0,
'num_URI_upload' => 0,
'has_admin_access' => 0,
'can_see_all_albums' => 0,
'groups' => array (IB_GUEST_GROUP)
);
// Retrieve cookie stored login information
if (!isset($HTTP_COOKIE_VARS[IB_COOKIE_PREFIX . 'member_id']) || !isset($HTTP_COOKIE_VARS[IB_COOKIE_PREFIX . 'pass_hash'])) {
$cookie_uid = 0;
$cookie_pass = '*';
} else {
$cookie_uid = (int)$HTTP_COOKIE_VARS[IB_COOKIE_PREFIX . 'member_id'];
$cookie_pass = substr(addslashes($HTTP_COOKIE_VARS[IB_COOKIE_PREFIX . 'pass_hash']), 0, 32);
}
// If autologin was not selected, we need to use the sessions table
if (!$cookie_uid && isset($HTTP_COOKIE_VARS[IB_COOKIE_PREFIX . 'session_id'])) {
$session_id = addslashes($HTTP_COOKIE_VARS[IB_COOKIE_PREFIX . 'session_id']);
 
if (isset($HTTP_SERVER_VARS['REMOTE_ADDR'])) {
$remote_ip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
} elseif (isset($HTTP_X_FORWARDED_FOR)) {
$remote_ip = $HTTP_X_FORWARDED_FOR;
} elseif (isset($HTTP_PROXY_USER)) {
$remote_ip = $HTTP_PROXY_USER;
} elseif (isset($REMOTE_ADDR)) {
$remote_ip = $REMOTE_ADDR;
} else {
$remote_ip = '-1';
}
 
$remote_ip = preg_replace("/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/", "\\1.\\2.\\3.\\4", $remote_ip);
 
$sql = "SELECT member_id as user_id, member_name as user_name, member_group as mgroup " . "FROM " . $UDB_DB_NAME_PREFIX . IB_TABLE_PREFIX . IB_SESSION_TABLE . " " . "WHERE id = '$session_id' AND ip_address = '$remote_ip'";
} else {
$sql = "SELECT id as user_id, name as user_name, mgroup " . "FROM " . $UDB_DB_NAME_PREFIX . IB_TABLE_PREFIX . IB_USER_TABLE . " " . "WHERE id='$cookie_uid' AND password='$cookie_pass'";
}
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$USER_DATA = mysql_fetch_array($result);
mysql_free_result($result);
 
define('USER_ID', (int)$USER_DATA['user_id']);
define('USER_NAME', $USER_DATA['user_name']);
// Retrieve group information
$sql = "SELECT * " . "FROM {$CONFIG['TABLE_USERGROUPS']} " . "WHERE group_id = '{$USER_DATA['mgroup']}'";
$result = db_query($sql);
if (mysql_num_rows($result)) {
$USER_DATA2 = mysql_fetch_array($result);
} else {
$USER_DATA2 = $default_group;
}
 
$USER_DATA = array_merge($USER_DATA, $USER_DATA2);
$USER_DATA['groups'] = array ($USER_DATA['group_id']);
 
 
$USER_DATA['has_admin_access'] = USER_ID ? ($USER_DATA['mgroup'] == IB_ADMIN_GROUP) : 0;
$USER_DATA['can_see_all_albums'] = $USER_DATA['has_admin_access'];
 
define('USER_GROUP', $USER_DATA['group_name']);
define('USER_GROUP_SET', '(' . $USER_DATA['group_id'] . ')');
define('USER_IS_ADMIN', USER_ID ? ($USER_DATA['mgroup'] == IB_ADMIN_GROUP) : 0);
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', USER_ID ? (int)$USER_DATA['can_create_albums'] : 0);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
mysql_free_result($result);
} else {
$result = db_query("SELECT * FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = " . IB_GUEST_GROUP);
if (!mysql_num_rows($result)) {
$USER_DATA = $default_group;
} else {
$USER_DATA = mysql_fetch_array($result);
}
 
$USER_DATA['groups'] = array (IB_GUEST_GROUP);
$USER_DATA['has_admin_access'] = 0;
$USER_DATA['can_see_all_albums'] = 0;
 
define('USER_ID', 0);
define('USER_NAME', 'Anonymous');
define('USER_GROUP_SET', '(' . IB_GUEST_GROUP . ')');
define('USER_IS_ADMIN', 0);
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', 0);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
mysql_free_result($result);
}
}
// Retrieve the name of a user
function udb_get_user_name($uid)
{
global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
 
$sql = "SELECT name as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . IB_TABLE_PREFIX . IB_USER_TABLE . " " . "WHERE id = '$uid'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_name'];
} else {
return '';
}
}
// Retrieve the name of a user (Added to fix banning w/ bb integration - Nibbler)
function udb_get_user_id($username)
{
global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
 
$username = addslashes($username);
 
$sql = "SELECT id as user_id " . "FROM " . $UDB_DB_NAME_PREFIX . IB_TABLE_PREFIX . IB_USER_TABLE . " " . "WHERE name = '$username'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_id'];
} else {
return '';
}
}
 
// Redirect
function udb_redirect($target)
{
header('Location: http://' . $_SERVER['HTTP_HOST'] . IB_WEB_PATH . $target);
exit;
}
 
// Register
function udb_register_page()
{
$target = 'index.php?&act=Reg&CODE=00';
udb_redirect($target);
}
// Login
function udb_login_page()
{
$target = 'index.php?&act=Login&CODE=00';
udb_redirect($target);
}
// Logout
function udb_logout_page()
{
$target = 'index.php?&act=Login&CODE=03';
udb_redirect($target);
}
// Edit users
function udb_edit_users()
{
$target = 'admin.php';
udb_redirect($target);
}
// Get user information
function udb_get_user_infos($uid)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
global $lang_register_php;
 
$sql = "SELECT name as user_name, mgroup, email as user_email, joined as user_regdate, " . "location as user_location, interests as user_interests, website as user_website " . "FROM " . $UDB_DB_NAME_PREFIX . IB_TABLE_PREFIX . IB_USER_TABLE . " " . "WHERE id = '$uid'";
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_register_php['err_unk_user'], __FILE__, __LINE__);
$user_data = mysql_fetch_array($result);
mysql_free_result($result);
 
$user_data['group_name'] = '';
$user_data['user_occupation'] = '';
 
$sql = "SELECT group_name " . "FROM {$CONFIG['TABLE_USERGROUPS']} " . "WHERE group_id = {$user_data['mgroup']} ";
$result = db_query($sql);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
$user_data['group_name'] = $row['group_name'];
}
mysql_free_result($result);
 
return $user_data;
}
// Edit user profile
function udb_edit_profile($uid)
{
$target = 'index.php?&act=UserCP&CODE=00';
udb_redirect($target);
}
// Query used to list users
function udb_list_users_query(&$user_count)
{
global $CONFIG, $FORBIDDEN_SET;
 
if ($FORBIDDEN_SET != "") $forbidden = "AND $FORBIDDEN_SET";
$sql = "SELECT (category - " . FIRST_USER_CAT . ") as user_id," . " '???' as user_name," . " COUNT(DISTINCT a.aid) as alb_count," . " COUNT(DISTINCT pid) as pic_count," . " MAX(pid) as thumb_pid " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.aid = a.aid " . "WHERE approved = 'YES' AND category > " . FIRST_USER_CAT . " $forbidden GROUP BY category " . "ORDER BY category ";
$result = db_query($sql);
 
$user_count = mysql_num_rows($result);
 
return $result;
}
 
function udb_list_users_retrieve_data($result, $lower_limit, $count)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
mysql_data_seek($result, $lower_limit);
 
$rowset = array();
$i = 0;
$user_id_set = '';
 
while (($row = mysql_fetch_array($result)) && ($i++ < $count)) {
$user_id_set .= $row['user_id'] . ',';
$rowset[] = $row;
}
mysql_free_result($result);
 
$user_id_set = '(' . substr($user_id_set, 0, -1) . ')';
$sql = "SELECT id as user_id, name as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . IB_TABLE_PREFIX . IB_USER_TABLE . " " . "WHERE id IN $user_id_set";
$result = db_query($sql, $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$name[$row['user_id']] = $row['user_name'];
}
for($i = 0; $i < count($rowset); $i++) {
$rowset[$i]['user_name'] = empty($name[$rowset[$i]['user_id']]) ? '???' : $name[$rowset[$i]['user_id']];
}
 
return $rowset;
}
// Group table synchronisation
function udb_synchronize_groups()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$result = db_query("SELECT g_id, g_title FROM " . $UDB_DB_NAME_PREFIX . IB_TABLE_PREFIX . IB_GROUP_TABLE . " WHERE 1", $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$ib_groups[$row['g_id']] = $row['g_title'];
}
mysql_free_result($result);
 
$result = db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE 1");
while ($row = mysql_fetch_array($result)) {
$cpg_groups[$row['group_id']] = $row['group_name'];
}
mysql_free_result($result);
// Scan Coppermine groups that need to be deleted
foreach($cpg_groups as $c_group_id => $c_group_name) {
if ((!isset($ib_groups[$c_group_id]))) {
db_query("DELETE FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = '" . $c_group_id . "' LIMIT 1");
unset($cpg_groups[$c_group_id]);
}
}
// Scan Invision Board groups that need to be created inside Coppermine table
foreach($ib_groups as $i_group_id => $i_group_name) {
if ((!isset($cpg_groups[$i_group_id]))) {
db_query("INSERT INTO {$CONFIG['TABLE_USERGROUPS']} (group_id, group_name) VALUES ('$i_group_id', '" . addslashes($i_group_name) . "')");
$cpg_groups[$i_group_id] = $i_group_name;
}
}
// Update Group names
foreach($ib_groups as $i_group_id => $i_group_name) {
if ($cpg_groups[$i_group_id] != $i_group_name) {
db_query("UPDATE {$CONFIG['TABLE_USERGROUPS']} SET group_name = '" . addslashes($i_group_name) . "' WHERE group_id = '$i_group_id' LIMIT 1");
}
}
}
// Retrieve the album list used in gallery admin mode
function udb_get_admin_album_list()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID, $FORBIDDEN_SET;
 
if (UDB_CAN_JOIN_TABLES) {
$sql = "SELECT aid, CONCAT('(', name, ') ', a.title) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN " . $UDB_DB_NAME_PREFIX . IB_TABLE_PREFIX . IB_USER_TABLE . " AS u ON category = (" . FIRST_USER_CAT . " + id) " . "ORDER BY title";
return $sql;
} else {
$sql = "SELECT aid, IF(category > " . FIRST_USER_CAT . ", CONCAT('* ', title), CONCAT(' ', title)) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} " . "ORDER BY title";
return $sql;
}
}
 
function udb_util_filloptions()
{
global $albumtbl, $picturetbl, $categorytbl, $lang_util_php, $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$usertbl = $UDB_DB_NAME_PREFIX.IB_TABLE_PREFIX . IB_USER_TABLE;
 
if (UDB_CAN_JOIN_TABLES) {
 
$query = "SELECT aid, category, IF(name IS NOT NULL, CONCAT('(', name, ') ', a.title), CONCAT(' - ', a.title)) AS title " . "FROM $albumtbl AS a " . "LEFT JOIN $usertbl AS u ON category = (" . FIRST_USER_CAT . " + id) " . "ORDER BY category, title";
$result = db_query($query, $UDB_DB_LINK_ID);
// $num=mysql_numrows($result);
echo '<select size="1" name="albumid">';
 
while ($row = mysql_fetch_array($result)) {
$sql = "SELECT name FROM $categorytbl WHERE cid = " . $row["category"];
$result2 = db_query($sql);
$row2 = mysql_fetch_array($result2);
 
print "<option value=\"" . $row["aid"] . "\">" . $row2["name"] . $row["title"] . "</option>\n";
}
 
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
} else {
 
// Query for list of public albums
 
$public_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " ORDER BY title");
 
if (mysql_num_rows($public_albums)) {
$public_result = db_fetch_rowset($public_albums);
} else {
$public_result = array();
}
 
// Initialize $merged_array
$merged_array = array();
 
// Count the number of albums returned.
$end = count($public_result);
 
// Cylce through the User albums.
for($i=0;$i<$end;$i++) {
 
//Create a new array sow we may sort the final results.
$merged_array[$i]['id'] = $public_result[$i]['aid'];
$merged_array[$i]['album_name'] = $public_result[$i]['title'];
 
// Query the database to get the category name.
$vQuery = "SELECT name, parent FROM " . $CONFIG['TABLE_CATEGORIES'] . " WHERE cid='" . $public_result[$i]['category'] . "'";
$vRes = mysql_query($vQuery);
$vRes = mysql_fetch_array($vRes);
if (isset($merged_array[$i]['username_category'])) {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '').$merged_array[$i]['username_category'];
} else {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '');
}
 
}
 
// We transpose and divide the matrix into columns to prepare it for use in array_multisort().
foreach ($merged_array as $key => $row) {
$aid[$key] = $row['id'];
$title[$key] = $row['album_name'];
$album_lineage[$key] = $row['username_category'];
}
 
// We sort all columns in descending order and plug in $album_menu at the end so it is sorted by the common key.
array_multisort($album_lineage, SORT_ASC, $title, SORT_ASC, $aid, SORT_ASC, $merged_array);
 
// Query for list of user albums
 
$user_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category >= " . FIRST_USER_CAT . " ORDER BY aid");
if (mysql_num_rows($user_albums)) {
$user_albums_list = db_fetch_rowset($user_albums);
} else {
$user_albums_list = array();
}
 
// Query for list of user IDs and names
 
$user_album_ids_and_names = db_query("SELECT (id + ".FIRST_USER_CAT.") as id, CONCAT('(', name, ') ') as name FROM $usertbl ORDER BY name ASC",$UDB_DB_LINK_ID);
 
if (mysql_num_rows($user_album_ids_and_names)) {
$user_album_ids_and_names_list = db_fetch_rowset($user_album_ids_and_names);
} else {
$user_album_ids_and_names_list = array();
}
 
// Glue what we've got together.
 
// Initialize $udb_i as a counter.
if (count($merged_array)) {
$udb_i = count($merged_array);
} else {
$udb_i = 0;
}
 
//Begin a set of nested loops to merge the various query results.
foreach ($user_albums_list as $aq) {
foreach ($user_album_ids_and_names_list as $uq) {
if ($aq['category'] == $uq['id']) {
$merged_array[$udb_i]['id']= $aq['category'];
$merged_array[$udb_i]['album_name']= $aq['title'];
$merged_array[$udb_i]['username_category']= $uq['name'];
$udb_i++;
}
}
}
 
// The user albums and public albums have been merged into one list. Print the dropdown.
echo '<select size="1" name="albumid">';
 
foreach ($merged_array as $menu_item) {
 
echo "<option value=\"" . $menu_item['id'] . "\">" . (isset($menu_item['username_category']) ? $menu_item['username_category'] : '') . $menu_item['album_name'] . "</option>\n";
 
}
 
// Close list, etc.
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
}
 
}
// ------------------------------------------------------------------------- //
// Define wheter we can join tables or not in SQL queries (same host & same db or user)
define('UDB_CAN_JOIN_TABLES', (IB_BD_HOST == $CONFIG['dbserver'] && (IB_DB_NAME == $CONFIG['dbname'] || IB_DB_USERNAME == $CONFIG['dbuser'])));
// Connect to Invision Board Database if necessary
$UDB_DB_LINK_ID = 0;
$UDB_DB_NAME_PREFIX = IB_DB_NAME ? '`' . IB_DB_NAME . '`.' : '';
if (!UDB_CAN_JOIN_TABLES) {
$UDB_DB_LINK_ID = @mysql_connect(IB_BD_HOST, IB_DB_USERNAME, IB_DB_PASSWORD);
if (!$UDB_DB_LINK_ID) die("<b>Coppermine critical error</b>:<br />Unable to connect to Invision Board database !<br /><br />MySQL said: <b>" . mysql_error() . "</b>");
}
 
?>
/web/test/gallery/cpg133/bridge/phpbb.inc.php
0,0 → 1,536
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2005 Coppermine Dev Team
v1.1 originaly written by Gregory DEMAR
 
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.
********************************************
Coppermine version: 1.3.3
$Source: /cvsroot/coppermine/stable/bridge/phpbb.inc.php,v $
$Revision: 1.11 $
$Author: gaugau $
$Date: 2005/04/19 03:17:13 $
**********************************************/
 
// ------------------------------------------------------------------------- //
// phpBB2 Integration for Coppermine //
// ------------------------------------------------------------------------- //
// Modify the values below according to your Board installation //
// ------------------------------------------------------------------------- //
 
// database configuration
define('PHPBB_DB_NAME', 'phpBB'); // The name of the database used by the board
define('PHPBB_BD_HOST', 'localhost'); // The name of the database server
define('PHPBB_DB_USERNAME', 'root'); // The username to use to connect to the database
define('PHPBB_DB_PASSWORD', ''); // The password to use to connect to the database
 
// The web path to your phpBB directory
// If your URL to your board is for example 'http://yoursite_name.com/phpBB2/',
// you'll have to set the below var to '/phpBB2/'.
define('PHPBB_WEB_PATH', '/phpBB2/');
// Logout Flag
// the value of this boolean constant depends on your phpBB version:
// If your version of phpBB is 2.0.4 or lower - change the value to FALSE;
// if your version of phpBB is 2.0.5 or newer - leave it as TRUE
define('PHPBB_LOGOUT_GET', TRUE);
// ------------------------------------------------------------------------- //
// You can keep the default values below if your instalation is standard
// ------------------------------------------------------------------------- //
// The prefix for the phpBB cookies
define('PHPBB_COOKIE_PREFIX', 'phpbb2mysql'); // The prefix used for board cookies
 
// Prefix and names for the database tables
define('PHPBB_TABLE_PREFIX', 'phpbb_'); // The prefix used for the DB tables
define('PHPBB_USER_TABLE', 'users'); // The members table
define('PHPBB_SESSION_TABLE', 'sessions'); // The session table
define('PHPBB_GROUP_TABLE', 'groups'); // The groups table
define('PHPBB_UGROUP_TABLE', 'user_group'); // The group/user table
 
// ------------------------------------------------------------------------- //
// Nothing to edit below this line
// ------------------------------------------------------------------------- //
// Group definitions
define('PHPBB_ADMIN_GROUP', 1);
define('PHPBB_MEMBERS_GROUP', 2);
define('PHPBB_GUEST_GROUP', 3);
define('PHPBB_BANNED_GROUP', 4);
// Authenticate a user using cookies
function udb_authenticate()
{
global $HTTP_COOKIE_VARS, $USER_DATA, $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
// For error checking
$CONFIG['TABLE_USERS'] = '**ERROR**';
 
$default_group = array('group_id' => PHPBB_GUEST_GROUP,
'group_name' => 'Unknown',
'has_admin_access' => 0,
'can_send_ecards' => 0,
'can_rate_pictures' => 0,
'can_post_comments' => 0,
'can_upload_pictures' => 0,
'can_create_albums' => 0,
'pub_upl_need_approval' => 1,
'priv_upl_need_approval' => 1,
'upload_form_config' => 0,
'custom_user_upload' => 0,
'num_file_upload' => 0,
'num_URI_upload' => 0,
'has_admin_access' => 0,
'can_see_all_albums' => 0,
'groups' => array (PHPBB_GUEST_GROUP)
);
// Retrieve cookie stored login information
if (!isset($HTTP_COOKIE_VARS[PHPBB_COOKIE_PREFIX . '_data'])) {
$cookie_uid = 0;
$cookie_pass = '*';
} else {
$sessiondata = unserialize($HTTP_COOKIE_VARS[PHPBB_COOKIE_PREFIX . '_data']);
if (is_array($sessiondata)) {
$cookie_uid = (isset($sessiondata['userid'])) ? intval($sessiondata['userid']) : 0;
$cookie_pass = (isset($sessiondata['autologinid'])) ? addslashes($sessiondata['autologinid']) : '*';
} else {
$cookie_uid = 0;
$cookie_pass = '*';
}
}
// If autologin was not selected, we need to use the sessions table
if ($cookie_uid && !$cookie_pass && isset($HTTP_COOKIE_VARS[PHPBB_COOKIE_PREFIX . '_sid'])) {
$session_id = addslashes($HTTP_COOKIE_VARS[PHPBB_COOKIE_PREFIX . '_sid']);
 
$sql = "SELECT user_id, username as user_name, user_level " . "FROM " . $UDB_DB_NAME_PREFIX . PHPBB_TABLE_PREFIX . PHPBB_SESSION_TABLE . " " . "INNER JOIN " . $UDB_DB_NAME_PREFIX . PHPBB_TABLE_PREFIX . PHPBB_USER_TABLE . " ON session_user_id = user_id " . "WHERE session_id='$session_id' AND session_user_id ='$cookie_uid' AND user_active='1'";
} else {
$sql = "SELECT user_id, username as user_name, user_level " . "FROM " . $UDB_DB_NAME_PREFIX . PHPBB_TABLE_PREFIX . PHPBB_USER_TABLE . " " . "WHERE user_id='$cookie_uid' AND user_password='$cookie_pass' AND user_active='1'";
}
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$USER_DATA = mysql_fetch_array($result);
mysql_free_result($result);
 
$USER_DATA['groups'] = array();
 
if($USER_DATA['user_id'] == "-1") {
define('USER_ID', 0);
} else {
define('USER_ID', (int)$USER_DATA['user_id']);
}
 
define('USER_NAME', $USER_DATA['user_name']);
 
// Define the basic groups
if ($USER_DATA['user_id'] == "-1") {
 
array_push($USER_DATA['groups'], PHPBB_GUEST_GROUP);
 
} else {
 
if ($USER_DATA['user_level'] == 1) {
array_push($USER_DATA['groups'], PHPBB_ADMIN_GROUP);
}
array_push($USER_DATA['groups'], PHPBB_MEMBERS_GROUP);
 
}
 
// Retrieve the groups the user is a member of
$sql = "SELECT (ug.group_id + 5) as group_id " . "FROM " . $UDB_DB_NAME_PREFIX . PHPBB_TABLE_PREFIX . PHPBB_UGROUP_TABLE . " as ug " . "LEFT JOIN " . $UDB_DB_NAME_PREFIX . PHPBB_TABLE_PREFIX . PHPBB_GROUP_TABLE . " as g ON ug.group_id = g.group_id " . "WHERE user_id = " . USER_ID . " AND user_pending = 0 AND group_single_user = 0";
$result = db_query($sql, $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
array_push($USER_DATA['groups'], $row['group_id']);
}
mysql_free_result($result);
 
$user_group_set = '(' . implode(',', $USER_DATA['groups']) . ')';
// Default group data
$USER_DATA['group_quota'] = 1;
$USER_DATA['can_rate_pictures'] = 0;
$USER_DATA['can_send_ecards'] = 0;
$USER_DATA['can_post_comments'] = 0;
$USER_DATA['can_upload_pictures'] = 0;
$USER_DATA['can_create_albums'] = 0;
$USER_DATA['pub_upl_need_approval'] = 1;
$USER_DATA['priv_upl_need_approval'] = 1;
$USER_DATA['upload_form_config'] = 0;
$USER_DATA['num_file_upload'] = 0;
$USER_DATA['num_URI_upload'] = 0;
$USER_DATA['custom_user_upload'] = 0;
 
$USER_DATA = array_merge($USER_DATA, cpgGetUserData($USER_DATA['groups'][0], $USER_DATA['groups'], PHPBB_GUEST_GROUP));
 
define('USER_GROUP', '');
define('USER_GROUP_SET', $user_group_set);
define('USER_IS_ADMIN', ($USER_DATA['user_level'] == 1));
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
} else {
$USER_DATA = cpgGetUserData(PHPBB_GUEST_GROUP, array(), PHPBB_GUEST_GROUP);
define('USER_ID', 0);
define('USER_NAME', 'Anonymous');
define('USER_GROUP_SET', '(' . PHPBB_GUEST_GROUP . ')');
define('USER_IS_ADMIN', 0);
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', 0);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
mysql_free_result($result);
}
}
// Retrieve the name of a user
function udb_get_user_name($uid)
{
global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
 
$sql = "SELECT username as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . PHPBB_TABLE_PREFIX . PHPBB_USER_TABLE . " " . "WHERE user_id = '$uid'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_name'];
} else {
return '';
}
}
// Retrieve the name of a user (Added to fix banning w/ bb integration - Nibbler)
function udb_get_user_id($username)
{
global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
 
$username = addslashes($username);
 
$sql = "SELECT user_id " . "FROM " . $UDB_DB_NAME_PREFIX . PHPBB_TABLE_PREFIX . PHPBB_USER_TABLE . " " . "WHERE username = '$username'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_id'];
} else {
return '';
}
}
 
// Redirect
function udb_redirect($target)
{
header('Location: http://' . $_SERVER['HTTP_HOST'] . PHPBB_WEB_PATH . $target);
exit;
}
 
// Register
function udb_register_page()
{
$target = 'profile.php?mode=register';
udb_redirect($target);
}
// HTML code for login/logout redirection
DEFINE("REDIR1",'<html><body onload="document.redir.submit();"><form name="redir" method="post" action="');
DEFINE("REDIR2",'"><input type="hidden" name="redirect" value="cpg_redir.php" /></form></body></html>');
DEFINE('LOGIN_REDIR', 'login.php?redirect=cpg_redir.php');
DEFINE('LOGOUT_FLAG', '&logout=true');
// Login
function udb_login_page()
{
udb_redirect(LOGIN_REDIR);
}
// Logout
function udb_logout_page()
{
if (PHPBB_LOGOUT_GET) {
 
udb_redirect(LOGIN_REDIR.LOGOUT_FLAG);
} else {
echo(REDIR1.PHPBB_WEB_PATH.LOGIN_REDIR.LOGOUT_FLAG.REDIR2);
exit();
}
}
// Edit users
function udb_edit_users()
{
$target = 'memberlist.php';
udb_redirect($target);
}
// Get user information
function udb_get_user_infos($uid)
{
global $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
global $lang_register_php;
 
$sql = "SELECT username as user_name, user_email, user_regdate, " . "user_from as user_location, user_interests, user_website, user_occ as user_occupation " . "FROM " . $UDB_DB_NAME_PREFIX . PHPBB_TABLE_PREFIX . PHPBB_USER_TABLE . " " . "WHERE user_id = '$uid'";
$result = db_query($sql, $UDB_DB_LINK_ID);
if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_register_php['err_unk_user'], __FILE__, __LINE__);
 
$user_data = mysql_fetch_array($result);
$user_data['group_name'] = '';
mysql_free_result($result);
 
return $user_data;
}
// Edit user profile
function udb_edit_profile($uid)
{
$target = 'profile.php?mode=editprofile';
udb_redirect($target);
}
// Query used to list users
function udb_list_users_query(&$user_count)
{
global $CONFIG, $FORBIDDEN_SET;
 
if ($FORBIDDEN_SET != "") $forbidden = "AND $FORBIDDEN_SET";
$sql = "SELECT (category - " . FIRST_USER_CAT . ") as user_id," . " '???' as user_name," . " COUNT(DISTINCT a.aid) as alb_count," . " COUNT(DISTINCT pid) as pic_count," . " MAX(pid) as thumb_pid " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.aid = a.aid " . "WHERE approved = 'YES' AND category > " . FIRST_USER_CAT . " $forbidden GROUP BY category " . "ORDER BY category ";
$result = db_query($sql);
 
$user_count = mysql_num_rows($result);
 
return $result;
}
 
function udb_list_users_retrieve_data($result, $lower_limit, $count)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
mysql_data_seek($result, $lower_limit);
 
$rowset = array();
$i = 0;
$user_id_set = '';
 
while (($row = mysql_fetch_array($result)) && ($i++ < $count)) {
$user_id_set .= $row['user_id'] . ',';
$rowset[] = $row;
}
mysql_free_result($result);
 
$user_id_set = '(' . substr($user_id_set, 0, -1) . ')';
$sql = "SELECT user_id, username as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . PHPBB_TABLE_PREFIX . PHPBB_USER_TABLE . " " . "WHERE user_id IN $user_id_set";
$result = db_query($sql, $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$name[$row['user_id']] = $row['user_name'];
}
for($i = 0; $i < count($rowset); $i++) {
$rowset[$i]['user_name'] = empty($name[$rowset[$i]['user_id']]) ? '???' : $name[$rowset[$i]['user_id']];
}
 
return $rowset;
}
// Group table synchronisation
function udb_synchronize_groups()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$PHPBB_groups = array(
PHPBB_ADMIN_GROUP => 'Admin',
PHPBB_MEMBERS_GROUP => 'Members',
PHPBB_GUEST_GROUP => 'Guests',
PHPBB_BANNED_GROUP => 'Banned',
);
 
$sql = "SELECT (ug.group_id + 5) as group_id, group_name " . "FROM " . $UDB_DB_NAME_PREFIX . PHPBB_TABLE_PREFIX . PHPBB_UGROUP_TABLE . " as ug " . "LEFT JOIN " . $UDB_DB_NAME_PREFIX . PHPBB_TABLE_PREFIX . PHPBB_GROUP_TABLE . " as g ON ug.group_id = g.group_id " . "WHERE user_pending=0 AND group_single_user=0";
$result = db_query($sql, $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$PHPBB_groups[$row['group_id']] = $row['group_name'];
}
mysql_free_result($result);
 
$result = db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE 1");
while ($row = mysql_fetch_array($result)) {
$cpg_groups[$row['group_id']] = $row['group_name'];
}
mysql_free_result($result);
// Scan Coppermine groups that need to be deleted
foreach($cpg_groups as $c_group_id => $c_group_name) {
if ((!isset($PHPBB_groups[$c_group_id]))) {
db_query("DELETE FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = '" . $c_group_id . "' LIMIT 1");
unset($cpg_groups[$c_group_id]);
}
}
// Scan phpBB groups that need to be created inside Coppermine table
foreach($PHPBB_groups as $i_group_id => $i_group_name) {
if ((!isset($cpg_groups[$i_group_id]))) {
db_query("INSERT INTO {$CONFIG['TABLE_USERGROUPS']} (group_id, group_name) VALUES ('$i_group_id', '" . addslashes($i_group_name) . "')");
$cpg_groups[$i_group_id] = $i_group_name;
}
}
// Update Group names
foreach($PHPBB_groups as $i_group_id => $i_group_name) {
if ($cpg_groups[$i_group_id] != $i_group_name) {
db_query("UPDATE {$CONFIG['TABLE_USERGROUPS']} SET group_name = '" . addslashes($i_group_name) . "' WHERE group_id = '$i_group_id' LIMIT 1");
}
}
}
// Retrieve the album list used in gallery admin mode
function udb_get_admin_album_list()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID, $FORBIDDEN_SET;
 
if (UDB_CAN_JOIN_TABLES) {
$sql = "SELECT aid, CONCAT('(', username, ') ', title) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN " . $UDB_DB_NAME_PREFIX . PHPBB_TABLE_PREFIX . PHPBB_USER_TABLE . " AS u ON category = (" . FIRST_USER_CAT . " + user_id) " . "ORDER BY title";
return $sql;
} else {
$sql = "SELECT aid, IF(category > " . FIRST_USER_CAT . ", CONCAT('* ', title), CONCAT(' ', title)) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} " . "ORDER BY title";
return $sql;
}
}
 
function udb_util_filloptions()
{
global $albumtbl, $picturetbl, $categorytbl, $lang_util_php, $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$usertbl = $UDB_DB_NAME_PREFIX.PHPBB_TABLE_PREFIX.PHPBB_USER_TABLE;
 
if (UDB_CAN_JOIN_TABLES) {
 
$query = "SELECT aid, category, IF(username IS NOT NULL, CONCAT('(', username, ') ', a.title), CONCAT(' - ', a.title)) AS title " . "FROM $albumtbl AS a " . "LEFT JOIN $usertbl AS u ON category = (" . FIRST_USER_CAT . " + user_id) " . "ORDER BY category, title";
$result = db_query($query, $UDB_DB_LINK_ID);
// $num=mysql_numrows($result);
echo '<select size="1" name="albumid">';
 
while ($row = mysql_fetch_array($result)) {
$sql = "SELECT name FROM $categorytbl WHERE cid = " . $row["category"];
$result2 = db_query($sql);
$row2 = mysql_fetch_array($result2);
 
print "<option value=\"" . $row["aid"] . "\">" . $row2["name"] . $row["title"] . "</option>\n";
}
 
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
} else {
 
// Query for list of public albums
 
$public_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " ORDER BY title");
 
if (mysql_num_rows($public_albums)) {
$public_result = db_fetch_rowset($public_albums);
} else {
$public_result = array();
}
 
// Initialize $merged_array
$merged_array = array();
 
// Count the number of albums returned.
$end = count($public_result);
 
// Cylce through the User albums.
for($i=0;$i<$end;$i++) {
 
//Create a new array sow we may sort the final results.
$merged_array[$i]['id'] = $public_result[$i]['aid'];
$merged_array[$i]['album_name'] = $public_result[$i]['title'];
 
// Query the database to get the category name.
$vQuery = "SELECT name, parent FROM " . $CONFIG['TABLE_CATEGORIES'] . " WHERE cid='" . $public_result[$i]['category'] . "'";
$vRes = mysql_query($vQuery);
$vRes = mysql_fetch_array($vRes);
if (isset($merged_array[$i]['username_category'])) {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '').$merged_array[$i]['username_category'];
} else {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '');
}
 
}
 
// We transpose and divide the matrix into columns to prepare it for use in array_multisort().
foreach ($merged_array as $key => $row) {
$aid[$key] = $row['id'];
$title[$key] = $row['album_name'];
$album_lineage[$key] = $row['username_category'];
}
 
// We sort all columns in descending order and plug in $album_menu at the end so it is sorted by the common key.
array_multisort($album_lineage, SORT_ASC, $title, SORT_ASC, $aid, SORT_ASC, $merged_array);
 
// Query for list of user albums
 
$user_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category >= " . FIRST_USER_CAT . " ORDER BY aid");
if (mysql_num_rows($user_albums)) {
$user_albums_list = db_fetch_rowset($user_albums);
} else {
$user_albums_list = array();
}
 
// Query for list of user IDs and names
 
$user_album_ids_and_names = db_query("SELECT (user_id + ".FIRST_USER_CAT.") as id, CONCAT('(', username, ') ') as name FROM $usertbl ORDER BY name ASC",$UDB_DB_LINK_ID);
 
if (mysql_num_rows($user_album_ids_and_names)) {
$user_album_ids_and_names_list = db_fetch_rowset($user_album_ids_and_names);
} else {
$user_album_ids_and_names_list = array();
}
 
// Glue what we've got together.
 
// Initialize $udb_i as a counter.
if (count($merged_array)) {
$udb_i = count($merged_array);
} else {
$udb_i = 0;
}
 
//Begin a set of nested loops to merge the various query results.
foreach ($user_albums_list as $aq) {
foreach ($user_album_ids_and_names_list as $uq) {
if ($aq['category'] == $uq['id']) {
$merged_array[$udb_i]['id']= $aq['category'];
$merged_array[$udb_i]['album_name']= $aq['title'];
$merged_array[$udb_i]['username_category']= $uq['name'];
$udb_i++;
}
}
}
 
// The user albums and public albums have been merged into one list. Print the dropdown.
echo '<select size="1" name="albumid">';
 
foreach ($merged_array as $menu_item) {
 
echo "<option value=\"" . $menu_item['id'] . "\">" . (isset($menu_item['username_category']) ? $menu_item['username_category'] : '') . $menu_item['album_name'] . "</option>\n";
 
}
 
// Close list, etc.
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
}
 
}
 
// ------------------------------------------------------------------------- //
// Define wheter we can join tables or not in SQL queries (same host & same db or user)
define('UDB_CAN_JOIN_TABLES', (PHPBB_BD_HOST == $CONFIG['dbserver'] && (PHPBB_DB_NAME == $CONFIG['dbname'] || PHPBB_DB_USERNAME == $CONFIG['dbuser'])));
// define('UDB_CAN_JOIN_TABLES', false);
// Connect to phpBB database if necessary
$UDB_DB_LINK_ID = 0;
$UDB_DB_NAME_PREFIX = PHPBB_DB_NAME ? '`' . PHPBB_DB_NAME . '`.' : '';
if (!UDB_CAN_JOIN_TABLES) {
$UDB_DB_LINK_ID = @mysql_connect(PHPBB_BD_HOST, PHPBB_DB_USERNAME, PHPBB_DB_PASSWORD);
if (!$UDB_DB_LINK_ID) die("<b>Coppermine critical error</b>:<br />Unable to connect to phpBB Board database !<br /><br />MySQL said: <b>" . mysql_error() . "</b>");
}
 
?>
/web/test/gallery/cpg133/bridge/punbb.inc.php
0,0 → 1,479
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2005 Coppermine Dev Team
v1.1 originaly written by Gregory DEMAR
 
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.
********************************************
Coppermine version: 1.3.3
$Source: /cvsroot/coppermine/stable/bridge/punbb.inc.php,v $
$Revision: 1.3 $
$Author: gaugau $
$Date: 2005/04/19 03:17:13 $
**********************************************/
 
// ------------------------------------------------------------------------- //
// PunBB 1.1.5 Integration for Coppermine //
// ------------------------------------------------------------------------- //
// Modify the values below according to your Board installation //
// ------------------------------------------------------------------------- //
 
// URL of your punbb
$path = 'http://www.mysite.com/punbb';
 
// local path to your punbb config file
require_once('../punbb/config.php');
 
// punbb mod == cpg Admin ?
define('MOD_IS_ADMIN', FALSE);
 
// ------------------------------------------------------------------------- //
// Nothing to edit below this line
// ------------------------------------------------------------------------- //
 
// automatic configuration
define('PUNBB_DB_NAME', $db_name); // The name of the database used by the board
define('PUNBB_DB_HOST', $db_host); // The name of the database server
define('PUNBB_DB_USERNAME', $db_username); // The username to use to connect to the database
define('PUNBB_DB_PASSWORD', $db_password); // The password to use to connect to the database
define('PUNBB_TABLE_PREFIX', $db_prefix); // The prefix used for the DB tables
define('PUNBB_WEB_PATH', $path); // The prefix used for the DB tables
define('PUNBB_USER_TABLE', 'users'); // The members table
 
// Group definitions
define('PUNBB_MOD_GROUP', 4);
define('PUNBB_GUEST_GROUP', 3);
define('PUNBB_MEMBERS_GROUP', 2);
define('PUNBB_ADMIN_GROUP', 1);
 
function udb_authenticate()
{
global $USER_DATA, $CONFIG, $cookie_name, $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX;
 
// For error checking
$CONFIG['TABLE_USERS'] = '**ERROR**';
 
function unescape($str)
{
return (get_magic_quotes_gpc() == 1) ? stripslashes($str) : $str;
}
 
// Retrieve cookie stored login information
 
// default user info
$USER_DATA['user_id'] = 0;
$USER_DATA['status'] = -1;
$USER_DATA['user_name'] = 'Guest';
 
if (isset($_COOKIE[$cookie_name]))
{
list($cookie['username'], $cookie['password_hash']) = unserialize(unescape($_COOKIE[$cookie_name]));
 
if (strcasecmp($cookie['username'], 'Guest'))
{
$result = db_query("SELECT id AS user_id, username AS user_name, status FROM ". $UDB_DB_NAME_PREFIX . PUNBB_TABLE_PREFIX . PUNBB_USER_TABLE ." WHERE username='" . addslashes($cookie['username']). "' AND password='". addslashes($cookie['password_hash'])."'",$UDB_DB_LINK_ID);
$USER_DATA = mysql_fetch_assoc($result);
}
}
 
$USER_DATA['groups'] = array();
 
// Define the basic groups
 
switch ($USER_DATA['status']) {
 
case 0:
$USER_DATA['groups'][0] = PUNBB_MEMBERS_GROUP;
break;
case 1:
$USER_DATA['groups'][0] = PUNBB_MOD_GROUP;
break;
case 2:
$USER_DATA['groups'][0] = PUNBB_ADMIN_GROUP;
break;
default:
$USER_DATA['groups'][0] = PUNBB_GUEST_GROUP;
break;
}
 
if ($USER_DATA['status'] == -1) {
define('USER_ID', 0);
} else {
define('USER_ID', (int)$USER_DATA['user_id']);
}
 
$user_group_set = '(' . implode(',', $USER_DATA['groups']) . ')';
 
// Default group data
$USER_DATA['group_quota'] = 1;
$USER_DATA['can_rate_pictures'] = 0;
$USER_DATA['can_send_ecards'] = 0;
$USER_DATA['can_post_comments'] = 0;
$USER_DATA['can_upload_pictures'] = 0;
$USER_DATA['can_create_albums'] = 0;
$USER_DATA['pub_upl_need_approval'] = 1;
$USER_DATA['priv_upl_need_approval'] = 1;
$USER_DATA['upload_form_config'] = 0;
$USER_DATA['num_file_upload'] = 0;
$USER_DATA['num_URI_upload'] = 0;
$USER_DATA['custom_user_upload'] = 0;
 
$USER_DATA = array_merge($USER_DATA, cpgGetUserData($USER_DATA['groups'][0], $USER_DATA['groups'], PUNBB_GUEST_GROUP));
 
$USER_DATA['has_admin_access'] = (($USER_DATA['status'] == 2) || (($USER_DATA['status'] == 1) && MOD_IS_ADMIN)) ? 1 : 0;
$USER_DATA['can_see_all_albums'] = $USER_DATA['has_admin_access'];
 
define('USER_NAME', $USER_DATA['user_name']);
define('USER_GROUP', $USER_DATA['group_name']);
define('USER_GROUP_SET', $user_group_set);
define('USER_IS_ADMIN', $USER_DATA['has_admin_access']);
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
}
 
// Retrieve the name of a user
function udb_get_user_name($uid)
{
global $CONFIG, $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX;
 
$sql = "SELECT username as user_name FROM " . $UDB_DB_NAME_PREFIX . PUNBB_TABLE_PREFIX . PUNBB_USER_TABLE . " WHERE id = '$uid'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_name'];
} else {
return '';
}
}
// Retrieve the id of a user (Added to fix banning w/ bb integration - Nibbler)
function udb_get_user_id($username)
{
global $CONFIG, $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX;
 
$username = addslashes($username);
 
$sql = "SELECT id AS user_id FROM " . $UDB_DB_NAME_PREFIX . PUNBB_TABLE_PREFIX . PUNBB_USER_TABLE . " WHERE username = '$username'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_id'];
} else {
return '';
}
}
 
// Redirect
function udb_redirect($target)
{
header('Location: '. PUNBB_WEB_PATH . $target);
exit;
}
 
// Register
function udb_register_page()
{
$target = '/register.php';
udb_redirect($target);
}
// Login
function udb_login_page()
{
global $path;
 
echo '<html><body onload="document.redir.submit();"><form name="redir" method="post" action="'.$path.'/redir.php"><input type="hidden" name="redir" value="login.php" /></form></body></html>';
exit;
}
// Logout
function udb_logout_page()
{
global $path;
 
echo '<html><body onload="document.redir.submit();"><form name="redir" method="post" action="'.$path.'/redir.php"><input type="hidden" name="redir" value="login.php?action=out" /></form></body></html>';
exit;
}
// Edit users
function udb_edit_users()
{
$target = '/userlist.php';
udb_redirect($target);
}
// Get user information
function udb_get_user_infos($uid)
{
global $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID, $lang_register_php;
 
$sql = "SELECT username AS user_name, email AS user_email, registered AS user_regdate, location AS user_location, url AS user_website FROM " . $UDB_DB_NAME_PREFIX . PUNBB_TABLE_PREFIX . PUNBB_USER_TABLE . " WHERE id = '$uid'";
$result = db_query($sql, $UDB_DB_LINK_ID);
if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_register_php['err_unk_user'], __FILE__, __LINE__);
 
$user_data = mysql_fetch_array($result);
$user_data['group_name'] = '';
mysql_free_result($result);
 
return $user_data;
}
 
// Edit user profile
function udb_edit_profile($uid)
{
$target = "/profile.php?id=$uid";
udb_redirect($target);
}
 
// Query used to list users
function udb_list_users_query(&$user_count)
{
global $CONFIG, $FORBIDDEN_SET, $UDB_DB_LINK_ID;
 
if ($FORBIDDEN_SET != "") $forbidden = "AND $FORBIDDEN_SET";
$sql = "SELECT (category - " . FIRST_USER_CAT . ") as user_id," . " '???' as user_name," . " COUNT(DISTINCT a.aid) as alb_count," . " COUNT(DISTINCT pid) as pic_count," . " MAX(pid) as thumb_pid " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.aid = a.aid " . "WHERE approved = 'YES' AND category > " . FIRST_USER_CAT . " $forbidden GROUP BY category " . "ORDER BY category ";
$result = db_query($sql, $UDB_DB_LINK_ID);
 
$user_count = mysql_num_rows($result);
 
return $result;
}
 
function udb_list_users_retrieve_data($result, $lower_limit, $count)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
mysql_data_seek($result, $lower_limit);
 
$rowset = array();
$i = 0;
$user_id_set = '';
 
while (($row = mysql_fetch_array($result)) && ($i++ < $count)) {
$user_id_set .= $row['user_id'] . ',';
$rowset[] = $row;
}
mysql_free_result($result);
 
$user_id_set = '(' . substr($user_id_set, 0, -1) . ')';
$sql = "SELECT id AS user_id, username AS user_name FROM " . $UDB_DB_NAME_PREFIX . PUNBB_TABLE_PREFIX . PUNBB_USER_TABLE . " WHERE id IN $user_id_set";
$result = db_query($sql, $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$name[$row['user_id']] = $row['user_name'];
}
for($i = 0; $i < count($rowset); $i++) {
$rowset[$i]['user_name'] = empty($name[$rowset[$i]['user_id']]) ? '???' : $name[$rowset[$i]['user_id']];
}
 
return $rowset;
}
 
// Group table synchronisation
function udb_synchronize_groups()
{
global $CONFIG ;
 
$PUNBB_groups = array(
PUNBB_GUEST_GROUP => 'Guests',
PUNBB_MEMBERS_GROUP => 'Members',
PUNBB_ADMIN_GROUP => 'Administrators',
PUNBB_MOD_GROUP => 'Moderators'
);
 
$result = db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE 1");
while ($row = mysql_fetch_array($result)) {
$cpg_groups[$row['group_id']] = $row['group_name'];
}
mysql_free_result($result);
// Scan Coppermine groups that need to be deleted
foreach($cpg_groups as $c_group_id => $c_group_name) {
if ((!isset($PUNBB_groups[$c_group_id]))) {
db_query("DELETE FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = '" . $c_group_id . "' LIMIT 1");
unset($cpg_groups[$c_group_id]);
}
}
// Scan punBB groups that need to be created inside Coppermine table
foreach($PUNBB_groups as $i_group_id => $i_group_name) {
if ((!isset($cpg_groups[$i_group_id]))) {
db_query("INSERT INTO {$CONFIG['TABLE_USERGROUPS']} (group_id, group_name) VALUES ('$i_group_id', '" . addslashes($i_group_name) . "')");
$cpg_groups[$i_group_id] = $i_group_name;
}
}
// Update Group names
foreach($PUNBB_groups as $i_group_id => $i_group_name) {
if ($cpg_groups[$i_group_id] != $i_group_name) {
db_query("UPDATE {$CONFIG['TABLE_USERGROUPS']} SET group_name = '" . addslashes($i_group_name) . "' WHERE group_id = '$i_group_id' LIMIT 1");
}
}
}
// Retrieve the album list used in gallery admin mode
function udb_get_admin_album_list()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID, $FORBIDDEN_SET;
 
if (UDB_CAN_JOIN_TABLES) {
$sql = "SELECT aid, CONCAT('(', username, ') ', a.title) AS cpg_title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN " . $UDB_DB_NAME_PREFIX . PUNBB_TABLE_PREFIX . PUNBB_USER_TABLE . " AS u ON category = (" . FIRST_USER_CAT . " + id) " . "ORDER BY cpg_title";
return $sql;
} else {
$sql = "SELECT aid, IF(category > " . FIRST_USER_CAT . ", CONCAT('* ', a.title), CONCAT(' ', title)) AS cpg_title " . "FROM {$CONFIG['TABLE_ALBUMS']} " . "ORDER BY cpg_title";
return $sql;
}
}
 
function udb_util_filloptions()
{
global $albumtbl, $picturetbl, $categorytbl, $lang_util_php, $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$usertbl = $UDB_DB_NAME_PREFIX . PUNBB_TABLE_PREFIX . PUNBB_USER_TABLE;
 
if (UDB_CAN_JOIN_TABLES) {
 
$query = "SELECT aid, category, IF(username IS NOT NULL, CONCAT('(', username, ') ', a.title), CONCAT(' - ', a.title)) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "LEFT JOIN $usertbl AS u ON category = (" . FIRST_USER_CAT . " + id) " . "ORDER BY category, title";
$result = db_query($query, $UDB_DB_LINK_ID);
// $num=mysql_numrows($result);
echo '<select size="1" name="albumid">';
 
while ($row = mysql_fetch_array($result)) {
$sql = "SELECT name FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = " . $row["category"];
$result2 = db_query($sql);
$row2 = mysql_fetch_array($result2);
 
print "<option value=\"" . $row["aid"] . "\">" . $row2["name"] . $row["title"] . "</option>\n";
}
 
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
} else {
 
// Query for list of public albums
 
$public_albums = db_query("SELECT aid, a.title AS cpg_title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " ORDER BY cpg_title");
 
if (mysql_num_rows($public_albums)) {
$public_result = db_fetch_rowset($public_albums);
} else {
$public_result = array();
}
 
// Initialize $merged_array
$merged_array = array();
 
// Count the number of albums returned.
$end = count($public_result);
 
// Cylce through the User albums.
for($i=0;$i<$end;$i++) {
 
//Create a new array sow we may sort the final results.
$merged_array[$i]['id'] = $public_result[$i]['aid'];
$merged_array[$i]['album_name'] = $public_result[$i]['title'];
 
// Query the database to get the category name.
$vQuery = "SELECT name, parent FROM " . $CONFIG['TABLE_CATEGORIES'] . " WHERE cid='" . $public_result[$i]['category'] . "'";
$vRes = mysql_query($vQuery);
$vRes = mysql_fetch_array($vRes);
if (isset($merged_array[$i]['username_category'])) {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '').$merged_array[$i]['username_category'];
} else {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '');
}
 
}
 
// We transpose and divide the matrix into columns to prepare it for use in array_multisort().
foreach ($merged_array as $key => $row) {
$aid[$key] = $row['id'];
$title[$key] = $row['album_name'];
$album_lineage[$key] = $row['username_category'];
}
 
// We sort all columns in descending order and plug in $album_menu at the end so it is sorted by the common key.
array_multisort($album_lineage, SORT_ASC, $title, SORT_ASC, $aid, SORT_ASC, $merged_array);
 
// Query for list of user albums
 
$user_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category >= " . FIRST_USER_CAT . " ORDER BY aid");
if (mysql_num_rows($user_albums)) {
$user_albums_list = db_fetch_rowset($user_albums);
} else {
$user_albums_list = array();
}
 
// Query for list of user IDs and names
 
$user_album_ids_and_names = db_query("SELECT (id + ".FIRST_USER_CAT.") as id, CONCAT('(', username, ') ') as name FROM $usertbl ORDER BY name ASC",$UDB_DB_LINK_ID);
 
if (mysql_num_rows($user_album_ids_and_names)) {
$user_album_ids_and_names_list = db_fetch_rowset($user_album_ids_and_names);
} else {
$user_album_ids_and_names_list = array();
}
 
// Glue what we've got together.
 
// Initialize $udb_i as a counter.
if (count($merged_array)) {
$udb_i = count($merged_array);
} else {
$udb_i = 0;
}
 
//Begin a set of nested loops to merge the various query results.
foreach ($user_albums_list as $aq) {
foreach ($user_album_ids_and_names_list as $uq) {
if ($aq['category'] == $uq['id']) {
$merged_array[$udb_i]['id']= $aq['category'];
$merged_array[$udb_i]['album_name']= $aq['title'];
$merged_array[$udb_i]['username_category']= $uq['name'];
$udb_i++;
}
}
}
 
// The user albums and public albums have been merged into one list. Print the dropdown.
echo '<select size="1" name="albumid">';
 
foreach ($merged_array as $menu_item) {
 
echo "<option value=\"" . $menu_item['id'] . "\">" . (isset($menu_item['username_category']) ? $menu_item['username_category'] : '') . $menu_item['album_name'] . "</option>\n";
 
}
 
// Close list, etc.
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
}
 
}
 
// ------------------------------------------------------------------------- //
 
// Define wheter we can join tables or not in SQL queries (same host & same db or user)
define('UDB_CAN_JOIN_TABLES', (PUNBB_DB_HOST == $CONFIG['dbserver'] && (PUNBB_DB_NAME == $CONFIG['dbname'] || PUNBB_DB_USERNAME == $CONFIG['dbuser'])));
// Connect to SMF Database if necessary
$UDB_DB_LINK_ID = 0;
$UDB_DB_NAME_PREFIX = PUNBB_DB_NAME ? '`' . PUNBB_DB_NAME . '`.' : '';
if (!UDB_CAN_JOIN_TABLES) {
$UDB_DB_LINK_ID = @mysql_connect(PUNBB_DB_HOST, PUNBB_DB_USERNAME, PUNBB_DB_PASSWORD);
 
if (!$UDB_DB_LINK_ID) die("<b>Coppermine critical error</b>:<br />Unable to connect to PunBB database !<br /><br />MySQL said: <b>" . mysql_error() . "</b>");
mysql_select_db (PUNBB_DB_NAME, $UDB_DB_LINK_ID);
}
?>
/web/test/gallery/cpg133/bridge/smf.inc.php
0,0 → 1,570
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2005 Coppermine Dev Team
v1.1 originaly written by Gregory DEMAR
 
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.
********************************************
Coppermine version: 1.3.3
$Source: /cvsroot/coppermine/stable/bridge/smf.inc.php,v $
$Revision: 1.8 $
$Author: gaugau $
$Date: 2005/04/19 03:17:13 $
**********************************************/
 
// ------------------------------------------------------------------------- //
// As a special exception, the copyright holders of Coppermine Photo Gallery //
// give you permission to link Coppermine Photo Gallery with independent //
// modules that communicate with SimpleMachines Forum solely through this //
// 'bridge file' interface, regardless of the license terms of these //
// independent modules, and to copy and distribute the resulting combined //
// work under terms of your choice, provided that every copy of the combined //
// work is accompanied by a complete copy of the source code of Coppermine //
// Photo Gallery (the version of Coppermine Photo Gallery used to produce //
// the combined work), being distributed under the terms of the GNU General //
// Public License plus this exception. An independent module is a module //
// which is not derived from or based on Coppermine Photo Gallery. //
// //
// Note that people who make modified versions of Coppermine Photo Gallery //
// are not obligated to grant this special exception for their modified //
// versions; it is their choice whether to do so. The GNU General Public //
// License gives permission to release a modified version without this //
// exception; this exception also makes it possible to release a modified //
// version which carries forward this exception. //
// ------------------------------------------------------------------------- //
// Simple Machines Forum Integration for Coppermine //
// V0.5 Public Beta //
// ------------------------------------------------------------------------- //
// Modify the value below according to your Board installation //
// //
// WARNING : Do not activate this bridge if you already have pictures or //
// usergroups in your gallery. //
// ------------------------------------------------------------------------- //
 
// Set this to the location of your Settings file:
$path = '../smf';
 
// Comment this out if you want to default user's group to 'Registered'
// rather than using Post Count based groups.
define('USE_POST_GROUPS', 1);
 
// Set the names of implied groups here
define('CM_ADMIN_GROUP_NAME', 'Administrators');
define('CM_MEMBERS_GROUP_NAME', 'Registered');
define('CM_GUEST_GROUP_NAME', 'Anonymous');
define('CM_BANNED_GROUP_NAME', 'Banned');
define('CM_GMOD_GROUP_NAME', 'Global Moderators');
 
// ------------------------------------------------------------------------- //
// Nothing to edit below this line
// ------------------------------------------------------------------------- //
 
// Otherwise, try to autodetect SMF path if not set:
if (substr($path, -1) == '/')
$path = substr($path, 0, -1);
 
$possible_paths = array($path, '..', '../forum', '../forums',
'../community', '../yabbse', '../smf');
 
$correct = 0;
while (!file_exists($possible_paths[$correct] . '/Settings.php') &&
count($possible_paths) > $correct)
$correct++;
 
require_once($possible_paths[$correct] . '/Settings.php');
 
define ('SMF', 1);
 
// other includes
cm_include_smf_funcs("$sourcedir/Load.php", array("reloadSettings", "md5_hmac", "loadUserSettings"));
cm_include_smf_funcs("$sourcedir/Subs.php", array("updateMemberData", "updateStats", "updateSettings"));
 
// database configuration
define('SMF_DB_NAME', $db_name); // The name of the database used by the board
define('SMF_DB_HOST', $db_server); // The name of the database server
define('SMF_DB_USERNAME', $db_user); // The username to use to connect to the database
define('SMF_DB_PASSWORD', $db_passwd); // The password to use to connect to the database
 
// The web path to your SMF Board directory
define('SMF_WEB_PATH', "$boardurl/");
 
// The Name of the Cookie used for SMF logon
define('SMF_COOKIE_NAME', $cookiename);
 
// Prefix for the database tables
define('SMF_TABLE_PREFIX', $db_prefix); // Table Prefix
 
// Names for the database tables
define('SMF_USER_TABLE', 'members'); // The members table
define('SMF_GROUP_TABLE', 'membergroups'); // The groups table
 
// Group definitions (default values used by the board)
define('SMF_GMOD_GROUP', 2);
define('SMF_BANNED_GROUP', -3);
define('SMF_GUEST_GROUP', -1);
define('SMF_MEMBERS_GROUP', -2);
define('SMF_ADMIN_GROUP', 1);
 
define('SMF_PASSWD_SEED', 'ys');
 
function cm_include_smf_funcs ($source_file, $funcs)
{
$fp = fopen ($source_file, "r");
$len = filesize($source_file);
 
$source = fread($fp, $len);
fclose ($fp);
$oe = error_reporting(E_ERROR | E_WARNING | E_PARSE);
 
foreach ($funcs as $index => $func) {
preg_match('/\n\s*(function ' . $func . '.*?)\n\s*(function|\?>)/si', $source, $f);
$func = preg_replace("/db_query/s", "cm_db_query", $f[1]);
eval ($func);
}
 
error_reporting ($oe);
}
 
function cm_db_query ($query, $other, $other2)
{
global $UDB_DB_LINK_ID;
 
return db_query($query, $UDB_DB_LINK_ID);
}
 
// Authenticate a user using cookies
 
function udb_authenticate()
{
global $HTTP_COOKIE_VARS, $USER_DATA, $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
global $HTTP_SERVER_VARS, $HTTP_X_FORWARDED_FOR, $HTTP_PROXY_USER, $REMOTE_ADDR;
global $password, $username, $pwseed, $settings, $ID_MEMBER, $realname, $txt, $user_info, $user_settings;
 
$pwseed = SMF_PASSWD_SEED;
 
session_start();
 
reloadSettings();
LoadUserSettings();
 
// For error checking
$CONFIG['TABLE_USERS'] = '**ERROR**';
 
// get first 50 chars
$HTTP_USER_AGENT = substr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 0, 50);
$REMOTE_ADDR = substr($HTTP_SERVER_VARS['REMOTE_ADDR'], 0, 50);
 
/* If the user is a guest, initialize all the critial user settings */
if (!$ID_MEMBER) {
$USER_DATA = cpgGetUserData(SMF_GUEST_GROUP, array(SMF_GUEST_GROUP), SMF_GUEST_GROUP);
 
define('USER_ID', 0);
define('USER_NAME', 'Anonymous');
define('USER_GROUP_SET', '(' . SMF_GUEST_GROUP . ')');
define('USER_IS_ADMIN', 0);
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', 0);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
} else {
if ($user_settings['ID_GROUP']){
$cm_group_id = $user_settings['ID_GROUP'];
} else if ($user_settings['ID_POST_GROUP'] && defined ('USE_POST_GROUPS')){
$cm_group_id = $user_settings['ID_POST_GROUP'];
} else {
$cm_group_id = SMF_MEMBERS_GROUP;
}
 
// Retrieve group information
$USER_DATA = cpgGetUserData($cm_group_id, $user_info['groups'], SMF_GUEST_GROUP);
$USER_DATA['has_admin_access'] = $user_info['is_admin'];
$USER_DATA['can_see_all_albums']=$USER_DATA['has_admin_access'] | in_array(SMF_GMOD_GROUP,$user_info['groups']);
 
define('USER_ID', $ID_MEMBER);
define('USER_NAME', $user_info['name']);
define('SMF_USER_NAME', $user_info['username']);
define('USER_GROUP', $USER_DATA['group_name']);
define('USER_GROUP_SET', '(' . implode(",", $USER_DATA['groups']) . ')');
define('USER_IS_ADMIN', $user_info['is_admin']);
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
}
}
 
// Retrieve the name of a user
function udb_get_user_name($uid)
{
global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
 
$sql = "SELECT realName as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . SMF_TABLE_PREFIX . SMF_USER_TABLE . " " . "WHERE ID_MEMBER = '$uid'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_name'];
} else {
return '';
}
}
// Retrieve the name of a user (Added to fix banning w/ bb integration - Nibbler)
function udb_get_user_id($username)
{
global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
 
$username = addslashes($username);
 
$sql = "SELECT ID_MEMBER as user_id " . "FROM " . $UDB_DB_NAME_PREFIX . SMF_TABLE_PREFIX . SMF_USER_TABLE . " " . "WHERE realName = '$username'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_id'];
} else {
return '';
}
}
 
// Redirect
function udb_redirect($target)
{
header('Location: '. SMF_WEB_PATH . $target);
exit;
}
 
// Register
function udb_register_page()
{
$target = 'index.php?action=register';
udb_redirect($target);
}
 
// Login
function udb_login_page()
{
$_SESSION['login_url'] = $HTTP_GET_VARS['referer'] ? $HTTP_GET_VARS['referer'] : 'index.php';
$_SESSION['login_url'] = "http://localhost/cgpcvs/";
$target = 'index.php?action=login';
udb_redirect($target);
}
 
// Logout
function udb_logout_page()
{
$target = 'index.php?&action=logout;sesc=' . $_SESSION['rand_code'];
udb_redirect($target);
}
 
// Edit users
function udb_edit_users()
{
$target = 'index.php?action=mlist';
udb_redirect($target);
}
 
// Get user information
function udb_get_user_infos($uid)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
global $lang_register_php;
 
$sql = "SELECT realName as user_name, ID_GROUP as mgroup, ID_POST_GROUP, emailAddress as user_email, dateRegistered as user_regdate, " . "websiteURL as user_website " . "FROM " . $UDB_DB_NAME_PREFIX . SMF_TABLE_PREFIX . SMF_USER_TABLE . " " . "WHERE ID_MEMBER = '$uid'";
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_register_php['err_unk_user'], __FILE__, __LINE__);
$user_data = mysql_fetch_array($result);
mysql_free_result($result);
 
$user_data['user_occupation'] = '';
$user_data['user_location'] = '';
$user_data['user_interests'] = '';
 
if (!$user_data['mgroup'] && defined('USE_POST_GROUPS')) {
$user_data['mgroup'] = $user_data['ID_POST_GROUP'];
}
 
$sql = "SELECT groupName " . "FROM " . $UDB_DB_NAME_PREFIX . SMF_TABLE_PREFIX . SMF_GROUP_TABLE . " " . "WHERE ID_GROUP = '{$user_data['mgroup']}' ";
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
$user_data['group_name'] = $row['groupName'];
} else {
$user_data['group_name'] = CM_MEMBERS_GROUP_NAME;
}
mysql_free_result($result);
 
return $user_data;
}
 
// Edit user profile
function udb_edit_profile($uid)
{
$target = 'index.php?action=profile;u=' . USER_ID;
udb_redirect($target);
}
 
// Query used to list users
function udb_list_users_query(&$user_count)
{
global $CONFIG, $FORBIDDEN_SET;
 
if ($FORBIDDEN_SET != "") $forbidden = "AND $FORBIDDEN_SET";
$sql = "SELECT (category - " . FIRST_USER_CAT . ") as user_id," . " '???' as user_name," . " COUNT(DISTINCT a.aid) as alb_count," . " COUNT(DISTINCT pid) as pic_count," . " MAX(pid) as thumb_pid " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.aid = a.aid " . "WHERE approved = 'YES' AND category > " . FIRST_USER_CAT . " $forbidden GROUP BY category " . "ORDER BY category ";
$result = db_query($sql);
 
$user_count = mysql_num_rows($result);
 
return $result;
}
 
function udb_list_users_retrieve_data($result, $lower_limit, $count)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
mysql_data_seek($result, $lower_limit);
 
$rowset = array();
$i = 0;
$user_id_set = '';
 
while (($row = mysql_fetch_array($result)) && ($i++ < $count)) {
$user_id_set .= $row['user_id'] . ',';
$rowset[] = $row;
}
 
mysql_free_result($result);
 
$user_id_set = '(' . substr($user_id_set, 0, -1) . ')';
$sql = "SELECT ID_MEMBER as user_id, realName as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . SMF_TABLE_PREFIX . SMF_USER_TABLE . " " . "WHERE ID_MEMBER IN $user_id_set";
$result = db_query($sql, $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$name[$row['user_id']] = $row['user_name'];
}
for($i = 0; $i < count($rowset); $i++) {
$rowset[$i]['user_name'] = empty($name[$rowset[$i]['user_id']]) ? '???' : $name[$rowset[$i]['user_id']];
}
 
return $rowset;
}
 
// Group table synchronisation
function udb_synchronize_groups()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$result = db_query("SELECT ID_GROUP as usergroupid, groupName as title FROM " . $UDB_DB_NAME_PREFIX . SMF_TABLE_PREFIX . SMF_GROUP_TABLE , $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$SMF_groups[$row['usergroupid']] = $row['title'];
}
mysql_free_result($result);
 
$SMF_groups[SMF_MEMBERS_GROUP] = CM_MEMBERS_GROUP_NAME;
$SMF_groups[SMF_GUEST_GROUP] = CM_GUEST_GROUP_NAME;
 
$result = db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE 1");
while ($row = mysql_fetch_array($result)) {
$cpg_groups[$row['group_id']] = $row['group_name'];
}
mysql_free_result($result);
// Scan Coppermine groups that need to be deleted
foreach($cpg_groups as $c_group_id => $c_group_name) {
if ((!isset($SMF_groups[$c_group_id]))) {
db_query("DELETE FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = '" . $c_group_id . "' LIMIT 1");
unset($cpg_groups[$c_group_id]);
}
}
// Scan Board groups that need to be created inside Coppermine table
foreach($SMF_groups as $i_group_id => $i_group_name) {
if ((!isset($cpg_groups[$i_group_id]))) {
db_query("INSERT INTO {$CONFIG['TABLE_USERGROUPS']} (group_id, group_name, group_quota) VALUES ('$i_group_id', '" . addslashes($i_group_name) . "', 1)");
$cpg_groups[$i_group_id] = $i_group_name;
}
}
// Update Group names
 
foreach($SMF_groups as $i_group_id => $i_group_name){
if ($cpg_groups[$i_group_id] != $i_group_name) {
db_query("UPDATE {$CONFIG['TABLE_USERGROUPS']} SET group_name = '".addslashes($i_group_name)."' WHERE group_id = '$i_group_id' LIMIT 1");
}
}
}
 
// Retrieve the album list used in gallery admin mode
function udb_get_admin_album_list()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID, $FORBIDDEN_SET;
 
if (UDB_CAN_JOIN_TABLES) {
$sql = "SELECT aid, CONCAT('(', realName, ') ', a.title) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN " . $UDB_DB_NAME_PREFIX . SMF_TABLE_PREFIX . SMF_USER_TABLE . " AS u ON category = (" . FIRST_USER_CAT . " + ID_MEMBER) " . "ORDER BY title";
return $sql;
} else {
$sql = "SELECT aid, IF(category > " . FIRST_USER_CAT . ", CONCAT('* ', title), CONCAT(' ', title)) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} " . "ORDER BY title";
return $sql;
}
}
 
function udb_util_filloptions()
{
global $albumtbl, $picturetbl, $categorytbl, $lang_util_php, $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$usertbl = $UDB_DB_NAME_PREFIX.SMF_TABLE_PREFIX.SMF_USER_TABLE;
 
if (UDB_CAN_JOIN_TABLES) {
 
$query = "SELECT aid, category, IF(realName IS NOT NULL, CONCAT('(', realName, ') ', a.title), CONCAT(' - ', a.title)) AS title " . "FROM $albumtbl AS a " . "LEFT JOIN $usertbl AS u ON category = (" . FIRST_USER_CAT . " + ID_MEMBER) " . "ORDER BY category, title";
$result = db_query($query, $UDB_DB_LINK_ID);
// $num=mysql_numrows($result);
echo '<select size="1" name="albumid">';
 
while ($row = mysql_fetch_array($result)) {
$sql = "SELECT name FROM $categorytbl WHERE cid = " . $row["category"];
$result2 = db_query($sql);
$row2 = mysql_fetch_array($result2);
 
print "<option value=\"" . $row["aid"] . "\">" . $row2["name"] . $row["title"] . "</option>\n";
}
 
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
} else {
 
// Query for list of public albums
 
$public_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " ORDER BY title");
 
if (mysql_num_rows($public_albums)) {
$public_result = db_fetch_rowset($public_albums);
} else {
$public_result = array();
}
 
// Initialize $merged_array
$merged_array = array();
 
// Count the number of albums returned.
$end = count($public_result);
 
// Cylce through the User albums.
for($i=0;$i<$end;$i++) {
 
//Create a new array sow we may sort the final results.
$merged_array[$i]['id'] = $public_result[$i]['aid'];
$merged_array[$i]['album_name'] = $public_result[$i]['title'];
 
// Query the database to get the category name.
$vQuery = "SELECT name, parent FROM " . $CONFIG['TABLE_CATEGORIES'] . " WHERE cid='" . $public_result[$i]['category'] . "'";
$vRes = mysql_query($vQuery);
$vRes = mysql_fetch_array($vRes);
if (isset($merged_array[$i]['username_category'])) {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '').$merged_array[$i]['username_category'];
} else {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '');
}
 
}
 
// We transpose and divide the matrix into columns to prepare it for use in array_multisort().
foreach ($merged_array as $key => $row) {
$aid[$key] = $row['id'];
$title[$key] = $row['album_name'];
$album_lineage[$key] = $row['username_category'];
}
 
// We sort all columns in descending order and plug in $album_menu at the end so it is sorted by the common key.
array_multisort($album_lineage, SORT_ASC, $title, SORT_ASC, $aid, SORT_ASC, $merged_array);
 
// Query for list of user albums
 
$user_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category >= " . FIRST_USER_CAT . " ORDER BY aid");
if (mysql_num_rows($user_albums)) {
$user_albums_list = db_fetch_rowset($user_albums);
} else {
$user_albums_list = array();
}
 
// Query for list of user IDs and names
 
$user_album_ids_and_names = db_query("SELECT (ID_MEMBER + ".FIRST_USER_CAT.") as id, CONCAT('(', realName, ') ') as name FROM $usertbl ORDER BY name ASC",$UDB_DB_LINK_ID);
 
if (mysql_num_rows($user_album_ids_and_names)) {
$user_album_ids_and_names_list = db_fetch_rowset($user_album_ids_and_names);
} else {
$user_album_ids_and_names_list = array();
}
 
// Glue what we've got together.
 
// Initialize $udb_i as a counter.
if (count($merged_array)) {
$udb_i = count($merged_array);
} else {
$udb_i = 0;
}
 
//Begin a set of nested loops to merge the various query results.
foreach ($user_albums_list as $aq) {
foreach ($user_album_ids_and_names_list as $uq) {
if ($aq['category'] == $uq['id']) {
$merged_array[$udb_i]['id']= $aq['category'];
$merged_array[$udb_i]['album_name']= $aq['title'];
$merged_array[$udb_i]['username_category']= $uq['name'];
$udb_i++;
}
}
}
 
// The user albums and public albums have been merged into one list. Print the dropdown.
echo '<select size="1" name="albumid">';
 
foreach ($merged_array as $menu_item) {
 
echo "<option value=\"" . $menu_item['id'] . "\">" . (isset($menu_item['username_category']) ? $menu_item['username_category'] : '') . $menu_item['album_name'] . "</option>\n";
 
}
 
// Close list, etc.
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
}
 
}
 
// ------------------------------------------------------------------------- //
 
// Define wheter we can join tables or not in SQL queries (same host & same db or user)
define('UDB_CAN_JOIN_TABLES', (SMF_DB_HOST == $CONFIG['dbserver'] && (SMF_DB_NAME == $CONFIG['dbname'] || SMF_DB_USERNAME == $CONFIG['dbuser'])));
// Connect to SMF Database if necessary
$UDB_DB_LINK_ID = 0;
$UDB_DB_NAME_PREFIX = SMF_DB_NAME ? '`' . SMF_DB_NAME . '`.' : '';
if (!UDB_CAN_JOIN_TABLES) {
$UDB_DB_LINK_ID = @mysql_connect(SMF_DB_HOST, SMF_DB_USERNAME, SMF_DB_PASSWORD);
 
if (!$UDB_DB_LINK_ID) die("<b>Coppermine critical error</b>:<br />Unable to connect to SMF Board database !<br /><br />MySQL said: <b>" . mysql_error() . "</b>");
mysql_select_db (SMF_DB_NAME, $UDB_DB_LINK_ID);
}
?>
/web/test/gallery/cpg133/bridge/vbulletin.inc.php
0,0 → 1,466
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2005 Coppermine Dev Team
v1.1 originaly written by Gregory DEMAR
 
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.
********************************************
Coppermine version: 1.3.3
$Source: /cvsroot/coppermine/stable/bridge/vbulletin.inc.php,v $
$Revision: 1.7 $
$Author: gaugau $
$Date: 2005/04/19 03:17:13 $
**********************************************/
// ------------------------------------------------------------------------- //
// vBulletin 2.3 Integration for Coppermine
// ------------------------------------------------------------------------- //
 
// ------------------------------------------------------------------------- //
// Modify the values below according to your Board installation
// ------------------------------------------------------------------------- //
// database configuration
define('VB_DB_NAME', 'vbulletin23'); // The name of the database used by the board
define('VB_BD_HOST', 'localhost'); // The name of the database server
define('VB_DB_USERNAME', 'root'); // The username to use to connect to the database
define('VB_DB_PASSWORD', ''); // The password to use to connect to the database
 
// The web path to your vBulletin Board directory
// In this example http://yoursite_name.com/vbulletin23/
define('VB_WEB_PATH', '/vbulletin23/');
// ------------------------------------------------------------------------- //
// Nothing to edit below this line
// ------------------------------------------------------------------------- //
// Prefix and names for the database tables
define('VB_TABLE_PREFIX', ''); // Leave empty, not supported by vBulletin 2.3
define('VB_USER_TABLE', 'user'); // The members table
define('VB_SESSION_TABLE', 'session'); // The sessions table
define('VB_GROUP_TABLE', 'usergroup'); // The groups table
 
// Group definitions (default values used by the board)
define('VB_VALIDATING_GROUP', 3);
define('VB_GUEST_GROUP', 1);
define('VB_MEMBERS_GROUP', 2);
define('VB_ADMIN_GROUP', 6);
// Authenticate a user using cookies
function udb_authenticate()
{
global $HTTP_COOKIE_VARS, $USER_DATA, $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
global $HTTP_SERVER_VARS, $HTTP_X_FORWARDED_FOR, $HTTP_PROXY_USER, $REMOTE_ADDR;
// For error checking
$CONFIG['TABLE_USERS'] = '**ERROR**';
// Permissions for a default group
$default_group = array('group_id' => VB_GUEST_GROUP,
'group_name' => 'Unknown',
'has_admin_access' => 0,
'can_send_ecards' => 0,
'can_rate_pictures' => 0,
'can_post_comments' => 0,
'can_upload_pictures' => 0,
'can_create_albums' => 0,
'pub_upl_need_approval' => 1,
'priv_upl_need_approval' => 1,
);
// get first 50 chars
$HTTP_USER_AGENT = substr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 0, 50);
$REMOTE_ADDR = substr($HTTP_SERVER_VARS['REMOTE_ADDR'], 0, 50);
 
if (is_array($HTTP_COOKIE_VARS)) {
$sessionhash = isset($HTTP_COOKIE_VARS['sessionhash']) ? $HTTP_COOKIE_VARS['sessionhash'] : '';
$bbuserid = isset($HTTP_COOKIE_VARS['bbuserid']) ? $HTTP_COOKIE_VARS['bbuserid'] : 0;
$bbpassword = isset($HTTP_COOKIE_VARS['bbpassword']) ? $HTTP_COOKIE_VARS['bbpassword'] : '';
$bbalthash = isset($HTTP_COOKIE_VARS['bbalthash']) ? $HTTP_COOKIE_VARS['bbalthash'] : '';
}
 
if ($bbuserid && $bbpassword) {
// If userid and password exist in cookies we use them to login
$sql = "SELECT userid as user_id, username as user_name, usergroupid as mgroup " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid='" . addslashes($bbuserid) . "' AND password='" . addslashes($bbpassword) . "'";
} elseif ($sessionhash) {
// session hash exists
// validate it:
$sql = "SELECT sessionhash,userid,host,useragent,styleid " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_SESSION_TABLE . " " . "WHERE sessionhash='" . addslashes($sessionhash) . "' " . " AND (host='" . addslashes($REMOTE_ADDR) . "' " . " OR (althash='" . addslashes($bbalthash) . "' AND althash<>'')) " . " AND useragent='" . addslashes($HTTP_USER_AGENT) . "'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
// session hash exists
$session_data = mysql_fetch_array($result);
mysql_free_result($result);
 
$sql = "SELECT userid as user_id, username as user_name, usergroupid as mgroup " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid='" . $session_data['userid'] . "'";
$result = db_query($sql, $UDB_DB_LINK_ID);
} else {
$sql = "SELECT userid as user_id, username as user_name, usergroupid as mgroup " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE 0";
}
} else {
$sql = "SELECT userid as user_id, username as user_name, usergroupid as mgroup " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE 0";
}
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$USER_DATA = mysql_fetch_array($result);
mysql_free_result($result);
 
define('USER_ID', (int)$USER_DATA['user_id']);
define('USER_NAME', $USER_DATA['user_name']);
// Retrieve group information
$sql = "SELECT * " . "FROM {$CONFIG['TABLE_USERGROUPS']} " . "WHERE group_id = '{$USER_DATA['mgroup']}'";
$result = db_query($sql);
if (mysql_num_rows($result)) {
$USER_DATA2 = mysql_fetch_array($result);
} else {
$USER_DATA2 = $default_group;
}
 
$USER_DATA = array_merge($USER_DATA, $USER_DATA2);
 
define('USER_GROUP', $USER_DATA['group_name']);
define('USER_GROUP_SET', '(' . $USER_DATA['group_id'] . ')');
define('USER_IS_ADMIN', ($USER_DATA['mgroup'] == VB_ADMIN_GROUP));
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
mysql_free_result($result);
} else {
$result = db_query("SELECT * FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = " . VB_GUEST_GROUP);
if (!mysql_num_rows($result)) {
$USER_DATA = $default_group;
} else {
$USER_DATA = mysql_fetch_array($result);
}
define('USER_ID', 0);
define('USER_NAME', 'Anonymous');
define('USER_GROUP_SET', '(' . VB_GUEST_GROUP . ')');
define('USER_IS_ADMIN', 0);
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', 0);
mysql_free_result($result);
}
}
// Retrieve the name of a user
function udb_get_user_name($uid)
{
global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
 
$sql = "SELECT username as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid = '$uid'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_name'];
} else {
return '';
}
}
// Redirect
function udb_redirect($target)
{
header('Location: ' . VB_WEB_PATH . $target);
exit;
}
// Register
function udb_register_page()
{
$target = 'register.php';
udb_redirect($target);
}
// Login
function udb_login_page()
{
$target = 'index.php';
udb_redirect($target);
}
// Logout
function udb_logout_page()
{
$target = 'member.php?&action=logout';
udb_redirect($target);
}
// Edit users
function udb_edit_users()
{
$target = 'admin/index.php';
udb_redirect($target);
}
// Get user information
function udb_get_user_infos($uid)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
global $lang_register_php;
 
$sql = "SELECT username as user_name, usergroupid as mgroup, email as user_email, joindate as user_regdate, " . "homepage as user_website " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid = '$uid'";
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_register_php['err_unk_user'], __FILE__, __LINE__);
$user_data = mysql_fetch_array($result);
mysql_free_result($result);
 
$user_data['group_name'] = '';
$user_data['user_occupation'] = '';
$user_data['user_location'] = '';
$user_data['user_interests'] = '';
 
$sql = "SELECT group_name " . "FROM {$CONFIG['TABLE_USERGROUPS']} " . "WHERE group_id = {$user_data['mgroup']} ";
$result = db_query($sql);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
$user_data['group_name'] = $row['group_name'];
}
mysql_free_result($result);
 
return $user_data;
}
// Edit user profile
function udb_edit_profile($uid)
{
$target = 'usercp.php';
udb_redirect($target);
}
// Query used to list users
function udb_list_users_query(&$user_count)
{
global $CONFIG, $FORBIDDEN_SET;
 
if ($FORBIDDEN_SET != "") $forbidden = "AND $FORBIDDEN_SET";
$sql = "SELECT (category - " . FIRST_USER_CAT . ") as user_id," . " '???' as user_name," . " COUNT(DISTINCT a.aid) as alb_count," . " COUNT(DISTINCT pid) as pic_count," . " MAX(pid) as thumb_pid " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.aid = a.aid " . "WHERE approved = 'YES' AND category > " . FIRST_USER_CAT . " $forbidden GROUP BY category " . "ORDER BY category ";
$result = db_query($sql);
 
$user_count = mysql_num_rows($result);
 
return $result;
}
 
function udb_list_users_retrieve_data($result, $lower_limit, $count)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
mysql_data_seek($result, $lower_limit);
 
$rowset = array();
$i = 0;
$user_id_set = '';
 
while (($row = mysql_fetch_array($result)) && ($i++ < $count)) {
$user_id_set .= $row['user_id'] . ',';
$rowset[] = $row;
}
mysql_free_result($result);
 
$user_id_set = '(' . substr($user_id_set, 0, -1) . ')';
$sql = "SELECT userid as user_id, username as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid IN $user_id_set";
$result = db_query($sql, $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$name[$row['user_id']] = $row['user_name'];
}
for($i = 0; $i < count($rowset); $i++) {
$rowset[$i]['user_name'] = empty($name[$rowset[$i]['user_id']]) ? '???' : $name[$rowset[$i]['user_id']];
}
 
return $rowset;
}
// Group table synchronisation
function udb_synchronize_groups()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$result = db_query("SELECT usergroupid, title FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_GROUP_TABLE . " WHERE 1", $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$VB_groups[$row['usergroupid']] = $row['title'];
}
mysql_free_result($result);
 
$result = db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE 1");
while ($row = mysql_fetch_array($result)) {
$cpg_groups[$row['group_id']] = $row['group_name'];
}
mysql_free_result($result);
// Scan Coppermine groups that need to be deleted
foreach($cpg_groups as $c_group_id => $c_group_name) {
if ((!isset($VB_groups[$c_group_id]))) {
db_query("DELETE FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = '" . $c_group_id . "' LIMIT 1");
unset($cpg_groups[$c_group_id]);
}
}
// Scan vBulletin Board groups that need to be created inside Coppermine table
foreach($VB_groups as $i_group_id => $i_group_name) {
if ((!isset($cpg_groups[$i_group_id]))) {
db_query("INSERT INTO {$CONFIG['TABLE_USERGROUPS']} (group_id, group_name) VALUES ('$i_group_id', '" . addslashes($i_group_name) . "')");
$cpg_groups[$i_group_id] = $i_group_name;
}
}
// Update Group names
foreach($VB_groups as $i_group_id => $i_group_name) {
if ($cpg_groups[$i_group_id] != $i_group_name) {
db_query("UPDATE {$CONFIG['TABLE_USERGROUPS']} SET group_name = '" . addslashes($i_group_name) . "' WHERE group_id = '$i_group_id' LIMIT 1");
}
}
}
// Retrieve the album list used in gallery admin mode
function udb_get_admin_album_list()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID, $FORBIDDEN_SET;
 
if (UDB_CAN_JOIN_TABLES) {
$sql = "SELECT aid, CONCAT('(', username, ') ', a.title) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " AS u ON category = (" . FIRST_USER_CAT . " + userid) " . "ORDER BY title";
return $sql;
} else {
$sql = "SELECT aid, IF(category > " . FIRST_USER_CAT . ", CONCAT('* ', title), CONCAT(' ', title)) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} " . "ORDER BY title";
return $sql;
}
}
 
function udb_util_filloptions()
{
global $albumtbl, $picturetbl, $categorytbl, $lang_util_php, $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$usertbl = $UDB_DB_NAME_PREFIX.VB_TABLE_PREFIX.VB_USER_TABLE;
 
if (UDB_CAN_JOIN_TABLES) {
 
$query = "SELECT aid, category, IF(username IS NOT NULL, CONCAT('(', username, ') ', a.title), CONCAT(' - ', a.title)) AS title " . "FROM $albumtbl AS a " . "LEFT JOIN $usertbl AS u ON category = (" . FIRST_USER_CAT . " + userid) " . "ORDER BY category, title";
$result = db_query($query, $UDB_DB_LINK_ID);
// $num=mysql_numrows($result);
echo '<select size="1" name="albumid">';
 
while ($row = mysql_fetch_array($result)) {
$sql = "SELECT name FROM $categorytbl WHERE cid = " . $row["category"];
$result2 = db_query($sql);
$row2 = mysql_fetch_array($result2);
 
print "<option value=\"" . $row["aid"] . "\">" . $row2["name"] . $row["title"] . "</option>\n";
}
 
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
} else {
 
// Query for list of public albums
 
$public_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " ORDER BY title");
 
if (mysql_num_rows($public_albums)) {
$public_result = db_fetch_rowset($public_albums);
} else {
$public_result = array();
}
 
// Initialize $merged_array
$merged_array = array();
 
// Count the number of albums returned.
$end = count($public_result);
 
// Cylce through the User albums.
for($i=0;$i<$end;$i++) {
 
//Create a new array sow we may sort the final results.
$merged_array[$i]['id'] = $public_result[$i]['aid'];
$merged_array[$i]['album_name'] = $public_result[$i]['title'];
 
// Query the database to get the category name.
$vQuery = "SELECT name, parent FROM " . $CONFIG['TABLE_CATEGORIES'] . " WHERE cid='" . $public_result[$i]['category'] . "'";
$vRes = mysql_query($vQuery);
$vRes = mysql_fetch_array($vRes);
if (isset($merged_array[$i]['username_category'])) {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '').$merged_array[$i]['username_category'];
} else {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '');
}
 
}
 
// We transpose and divide the matrix into columns to prepare it for use in array_multisort().
foreach ($merged_array as $key => $row) {
$aid[$key] = $row['id'];
$title[$key] = $row['album_name'];
$album_lineage[$key] = $row['username_category'];
}
 
// We sort all columns in descending order and plug in $album_menu at the end so it is sorted by the common key.
array_multisort($album_lineage, SORT_ASC, $title, SORT_ASC, $aid, SORT_ASC, $merged_array);
 
// Query for list of user albums
 
$user_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category >= " . FIRST_USER_CAT . " ORDER BY aid");
if (mysql_num_rows($user_albums)) {
$user_albums_list = db_fetch_rowset($user_albums);
} else {
$user_albums_list = array();
}
 
// Query for list of user IDs and names
 
$user_album_ids_and_names = db_query("SELECT (userid + ".FIRST_USER_CAT.") as id, CONCAT('(', username, ') ') as name FROM $usertbl ORDER BY name ASC",$UDB_DB_LINK_ID);
 
if (mysql_num_rows($user_album_ids_and_names)) {
$user_album_ids_and_names_list = db_fetch_rowset($user_album_ids_and_names);
} else {
$user_album_ids_and_names_list = array();
}
 
// Glue what we've got together.
 
// Initialize $udb_i as a counter.
if (count($merged_array)) {
$udb_i = count($merged_array);
} else {
$udb_i = 0;
}
 
//Begin a set of nested loops to merge the various query results.
foreach ($user_albums_list as $aq) {
foreach ($user_album_ids_and_names_list as $uq) {
if ($aq['category'] == $uq['id']) {
$merged_array[$udb_i]['id']= $aq['category'];
$merged_array[$udb_i]['album_name']= $aq['title'];
$merged_array[$udb_i]['username_category']= $uq['name'];
$udb_i++;
}
}
}
 
// The user albums and public albums have been merged into one list. Print the dropdown.
echo '<select size="1" name="albumid">';
 
foreach ($merged_array as $menu_item) {
 
echo "<option value=\"" . $menu_item['id'] . "\">" . (isset($menu_item['username_category']) ? $menu_item['username_category'] : '') . $menu_item['album_name'] . "</option>\n";
 
}
 
// Close list, etc.
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
}
 
}
 
// ------------------------------------------------------------------------- //
// Define wheter we can join tables or not in SQL queries (same host & same db or user)
define('UDB_CAN_JOIN_TABLES', (VB_BD_HOST == $CONFIG['dbserver'] && (VB_DB_NAME == $CONFIG['dbname'] || VB_DB_USERNAME == $CONFIG['dbuser'])));
// Connect to vBulletin Board Database if necessary
$UDB_DB_LINK_ID = 0;
$UDB_DB_NAME_PREFIX = VB_DB_NAME ? '`' . VB_DB_NAME . '`.' : '';
if (!UDB_CAN_JOIN_TABLES) {
$UDB_DB_LINK_ID = @mysql_connect(VB_BD_HOST, VB_DB_USERNAME, VB_DB_PASSWORD);
if (!$UDB_DB_LINK_ID) die("<b>Coppermine critical error</b>:<br />Unable to connect to vBulletin Board database !<br /><br />MySQL said: <b>" . mysql_error() . "</b>");
}
 
?>
/web/test/gallery/cpg133/bridge/vbulletin23.inc.php
0,0 → 1,504
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2005 Coppermine Dev Team
v1.1 originaly written by Gregory DEMAR
 
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.
********************************************
Coppermine version: 1.3.3
$Source: /cvsroot/coppermine/stable/bridge/vbulletin23.inc.php,v $
$Revision: 1.7 $
$Author: gaugau $
$Date: 2005/04/19 03:17:13 $
**********************************************/
// ------------------------------------------------------------------------- //
// vBulletin 2.3 Integration for Coppermine //
// ------------------------------------------------------------------------- //
// Modify the values below according to your Board installation //
// ------------------------------------------------------------------------- //
 
// database configuration
define('VB_DB_NAME', 'vbulletin23'); // The name of the database used by the board
define('VB_BD_HOST', 'localhost'); // The name of the database server
define('VB_DB_USERNAME', 'root'); // The username to use to connect to the database
define('VB_DB_PASSWORD', ''); // The password to use to connect to the database
 
// The web path to your vBulletin Board directory
// In this example http://yoursite_name.com/vbulletin23/
define('VB_WEB_PATH', '/vbulletin23/');
// ------------------------------------------------------------------------- //
// Nothing to edit below this line
// ------------------------------------------------------------------------- //
// Prefix and names for the database tables
define('VB_TABLE_PREFIX', ''); // Leave empty, not supported by vBulletin 2.3
define('VB_USER_TABLE', 'user'); // The members table
define('VB_SESSION_TABLE', 'session'); // The sessions table
define('VB_GROUP_TABLE', 'usergroup'); // The groups table
 
// Group definitions (default values used by the board)
define('VB_VALIDATING_GROUP', 3);
define('VB_GUEST_GROUP', 1);
define('VB_MEMBERS_GROUP', 2);
define('VB_ADMIN_GROUP', 6);
// Authenticate a user using cookies
function udb_authenticate()
{
global $HTTP_COOKIE_VARS, $USER_DATA, $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
global $HTTP_SERVER_VARS, $HTTP_X_FORWARDED_FOR, $HTTP_PROXY_USER, $REMOTE_ADDR;
// For error checking
$CONFIG['TABLE_USERS'] = '**ERROR**';
// Permissions for a default group
$default_group = array('group_id' => VB_GUEST_GROUP,
'group_name' => 'Unknown',
'has_admin_access' => 0,
'can_see_allAalbums' =>0,
'can_send_ecards' => 0,
'can_rate_pictures' => 0,
'can_post_comments' => 0,
'can_upload_pictures' => 0,
'can_create_albums' => 0,
'pub_upl_need_approval' => 1,
'priv_upl_need_approval' => 1,
'upload_form_config' => 0,
'custom_user_upload' => 0,
'num_file_upload' => 0,
'num_URI_upload' => 0,
);
// get first 50 chars
$HTTP_USER_AGENT = substr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 0, 50);
$REMOTE_ADDR = substr($HTTP_SERVER_VARS['REMOTE_ADDR'], 0, 50);
 
if (is_array($HTTP_COOKIE_VARS)) {
$sessionhash = isset($HTTP_COOKIE_VARS['sessionhash']) ? $HTTP_COOKIE_VARS['sessionhash'] : '';
$bbuserid = isset($HTTP_COOKIE_VARS['bbuserid']) ? $HTTP_COOKIE_VARS['bbuserid'] : 0;
$bbpassword = isset($HTTP_COOKIE_VARS['bbpassword']) ? $HTTP_COOKIE_VARS['bbpassword'] : '';
$bbalthash = isset($HTTP_COOKIE_VARS['bbalthash']) ? $HTTP_COOKIE_VARS['bbalthash'] : '';
}
 
if ($bbuserid && $bbpassword) {
// If userid and password exist in cookies we use them to login
$sql = "SELECT userid as user_id, username as user_name, usergroupid as mgroup " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid='" . addslashes($bbuserid) . "' AND password='" . addslashes($bbpassword) . "'";
} elseif ($sessionhash) {
// session hash exists
// validate it:
$sql = "SELECT sessionhash,userid,host,useragent,styleid " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_SESSION_TABLE . " " . "WHERE sessionhash='" . addslashes($sessionhash) . "' " . " AND (host='" . addslashes($REMOTE_ADDR) . "' " . " OR (althash='" . addslashes($bbalthash) . "' AND althash<>'')) " . " AND useragent='" . addslashes($HTTP_USER_AGENT) . "'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
// session hash exists
$session_data = mysql_fetch_array($result);
mysql_free_result($result);
 
$sql = "SELECT userid as user_id, username as user_name, usergroupid as mgroup " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid='" . $session_data['userid'] . "'";
$result = db_query($sql, $UDB_DB_LINK_ID);
} else {
$sql = "SELECT userid as user_id, username as user_name, usergroupid as mgroup " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE 0";
}
} else {
$sql = "SELECT userid as user_id, username as user_name, usergroupid as mgroup " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE 0";
}
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$USER_DATA = mysql_fetch_array($result);
mysql_free_result($result);
 
define('USER_ID', (int)$USER_DATA['user_id']);
define('USER_NAME', $USER_DATA['user_name']);
// Retrieve group information
$sql = "SELECT * " . "FROM {$CONFIG['TABLE_USERGROUPS']} " . "WHERE group_id = '{$USER_DATA['mgroup']}'";
$result = db_query($sql);
if (mysql_num_rows($result)) {
$USER_DATA2 = mysql_fetch_array($result);
} else {
$USER_DATA2 = $default_group;
}
 
$USER_DATA = array_merge($USER_DATA, $USER_DATA2);
$USER_DATA['groups'] = array($USER_DATA['group_id']);
$USER_DATA['can_see_all_albums'] = ($USER_DATA['mgroup'] == VB_ADMIN_GROUP);
define('USER_GROUP', $USER_DATA['group_name']);
define('USER_GROUP_SET', '(' . $USER_DATA['group_id'] . ')');
define('USER_IS_ADMIN', ($USER_DATA['mgroup'] == VB_ADMIN_GROUP));
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
mysql_free_result($result);
} else {
$result = db_query("SELECT * FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = " . VB_GUEST_GROUP);
if (!mysql_num_rows($result)) {
$USER_DATA = $default_group;
} else {
$USER_DATA = mysql_fetch_array($result);
}
 
$USER_DATA['groups'] = array(VB_GUEST_GROUP);
$USER_DATA['can_see_all_albums'] =0;
 
define('USER_ID', 0);
define('USER_NAME', 'Anonymous');
define('USER_GROUP_SET', '(' . VB_GUEST_GROUP . ')');
define('USER_IS_ADMIN', 0);
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', 0);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
mysql_free_result($result);
}
}
// Retrieve the name of a user
function udb_get_user_name($uid)
{
global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
 
$sql = "SELECT username as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid = '$uid'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_name'];
} else {
return '';
}
}
// Retrieve the name of a user (Added to fix banning w/ bb integration - Nibbler)
function udb_get_user_id($username)
{
global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
 
$username = addslashes($username);
 
$sql = "SELECT userid as user_id " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE username = '$username'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_id'];
} else {
return '';
}
}
 
// Redirect
function udb_redirect($target)
{
header('Location: http://' . $_SERVER['HTTP_HOST'] . VB_WEB_PATH . $target);
exit;
}
 
// Register
function udb_register_page()
{
$target = 'register.php';
udb_redirect($target);
}
// Login
function udb_login_page()
{
$target = 'index.php';
udb_redirect($target);
}
// Logout
function udb_logout_page()
{
$target = 'member.php?&action=logout';
udb_redirect($target);
}
// Edit users
function udb_edit_users()
{
$target = 'admin/index.php';
udb_redirect($target);
}
// Get user information
function udb_get_user_infos($uid)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
global $lang_register_php;
 
$sql = "SELECT username as user_name, usergroupid as mgroup, email as user_email, joindate as user_regdate, " . "homepage as user_website " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid = '$uid'";
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_register_php['err_unk_user'], __FILE__, __LINE__);
$user_data = mysql_fetch_array($result);
mysql_free_result($result);
 
$user_data['group_name'] = '';
$user_data['user_occupation'] = '';
$user_data['user_location'] = '';
$user_data['user_interests'] = '';
 
$sql = "SELECT group_name " . "FROM {$CONFIG['TABLE_USERGROUPS']} " . "WHERE group_id = {$user_data['mgroup']} ";
$result = db_query($sql);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
$user_data['group_name'] = $row['group_name'];
}
mysql_free_result($result);
 
return $user_data;
}
// Edit user profile
function udb_edit_profile($uid)
{
$target = 'usercp.php';
udb_redirect($target);
}
// Query used to list users
function udb_list_users_query(&$user_count)
{
global $CONFIG, $FORBIDDEN_SET;
 
if ($FORBIDDEN_SET != "") $forbidden = "AND $FORBIDDEN_SET";
$sql = "SELECT (category - " . FIRST_USER_CAT . ") as user_id," . " '???' as user_name," . " COUNT(DISTINCT a.aid) as alb_count," . " COUNT(DISTINCT pid) as pic_count," . " MAX(pid) as thumb_pid " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.aid = a.aid " . "WHERE approved = 'YES' AND category > " . FIRST_USER_CAT . " $forbidden GROUP BY category " . "ORDER BY category ";
$result = db_query($sql);
 
$user_count = mysql_num_rows($result);
 
return $result;
}
 
function udb_list_users_retrieve_data($result, $lower_limit, $count)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
mysql_data_seek($result, $lower_limit);
 
$rowset = array();
$i = 0;
$user_id_set = '';
 
while (($row = mysql_fetch_array($result)) && ($i++ < $count)) {
$user_id_set .= $row['user_id'] . ',';
$rowset[] = $row;
}
mysql_free_result($result);
 
$user_id_set = '(' . substr($user_id_set, 0, -1) . ')';
$sql = "SELECT userid as user_id, username as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid IN $user_id_set";
$result = db_query($sql, $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$name[$row['user_id']] = $row['user_name'];
}
for($i = 0; $i < count($rowset); $i++) {
$rowset[$i]['user_name'] = empty($name[$rowset[$i]['user_id']]) ? '???' : $name[$rowset[$i]['user_id']];
}
 
return $rowset;
}
// Group table synchronisation
function udb_synchronize_groups()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$result = db_query("SELECT usergroupid, title FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_GROUP_TABLE . " WHERE 1", $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$VB_groups[$row['usergroupid']] = $row['title'];
}
mysql_free_result($result);
 
$result = db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE 1");
while ($row = mysql_fetch_array($result)) {
$cpg_groups[$row['group_id']] = $row['group_name'];
}
mysql_free_result($result);
// Scan Coppermine groups that need to be deleted
foreach($cpg_groups as $c_group_id => $c_group_name) {
if ((!isset($VB_groups[$c_group_id]))) {
db_query("DELETE FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = '" . $c_group_id . "' LIMIT 1");
unset($cpg_groups[$c_group_id]);
}
}
// Scan vBulletin Board groups that need to be created inside Coppermine table
foreach($VB_groups as $i_group_id => $i_group_name) {
if ((!isset($cpg_groups[$i_group_id]))) {
db_query("INSERT INTO {$CONFIG['TABLE_USERGROUPS']} (group_id, group_name) VALUES ('$i_group_id', '" . addslashes($i_group_name) . "')");
$cpg_groups[$i_group_id] = $i_group_name;
}
}
// Update Group names
foreach($VB_groups as $i_group_id => $i_group_name) {
if ($cpg_groups[$i_group_id] != $i_group_name) {
db_query("UPDATE {$CONFIG['TABLE_USERGROUPS']} SET group_name = '" . addslashes($i_group_name) . "' WHERE group_id = '$i_group_id' LIMIT 1");
}
}
}
// Retrieve the album list used in gallery admin mode
function udb_get_admin_album_list()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID, $FORBIDDEN_SET;
 
if (UDB_CAN_JOIN_TABLES) {
$sql = "SELECT aid, CONCAT('(', username, ') ', a.title) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " AS u ON category = (" . FIRST_USER_CAT . " + userid) " . "ORDER BY title";
return $sql;
} else {
$sql = "SELECT aid, IF(category > " . FIRST_USER_CAT . ", CONCAT('* ', title), CONCAT(' ', title)) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} " . "ORDER BY title";
return $sql;
}
}
 
function udb_util_filloptions()
{
global $albumtbl, $picturetbl, $categorytbl, $lang_util_php, $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$usertbl = $UDB_DB_NAME_PREFIX.VB_TABLE_PREFIX.VB_USER_TABLE;
 
if (UDB_CAN_JOIN_TABLES) {
 
$query = "SELECT aid, category, IF(username IS NOT NULL, CONCAT('(', username, ') ', a.title), CONCAT(' - ', a.title)) AS title " . "FROM $albumtbl AS a " . "LEFT JOIN $usertbl AS u ON category = (" . FIRST_USER_CAT . " + userid) " . "ORDER BY category, title";
$result = db_query($query, $UDB_DB_LINK_ID);
// $num=mysql_numrows($result);
echo '<select size="1" name="albumid">';
 
while ($row = mysql_fetch_array($result)) {
$sql = "SELECT name FROM $categorytbl WHERE cid = " . $row["category"];
$result2 = db_query($sql);
$row2 = mysql_fetch_array($result2);
 
print "<option value=\"" . $row["aid"] . "\">" . $row2["name"] . $row["title"] . "</option>\n";
}
 
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
} else {
 
// Query for list of public albums
 
$public_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " ORDER BY title");
 
if (mysql_num_rows($public_albums)) {
$public_result = db_fetch_rowset($public_albums);
} else {
$public_result = array();
}
 
// Initialize $merged_array
$merged_array = array();
 
// Count the number of albums returned.
$end = count($public_result);
 
// Cylce through the User albums.
for($i=0;$i<$end;$i++) {
 
//Create a new array sow we may sort the final results.
$merged_array[$i]['id'] = $public_result[$i]['aid'];
$merged_array[$i]['album_name'] = $public_result[$i]['title'];
 
// Query the database to get the category name.
$vQuery = "SELECT name, parent FROM " . $CONFIG['TABLE_CATEGORIES'] . " WHERE cid='" . $public_result[$i]['category'] . "'";
$vRes = mysql_query($vQuery);
$vRes = mysql_fetch_array($vRes);
if (isset($merged_array[$i]['username_category'])) {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '').$merged_array[$i]['username_category'];
} else {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '');
}
 
}
 
// We transpose and divide the matrix into columns to prepare it for use in array_multisort().
foreach ($merged_array as $key => $row) {
$aid[$key] = $row['id'];
$title[$key] = $row['album_name'];
$album_lineage[$key] = $row['username_category'];
}
 
// We sort all columns in descending order and plug in $album_menu at the end so it is sorted by the common key.
array_multisort($album_lineage, SORT_ASC, $title, SORT_ASC, $aid, SORT_ASC, $merged_array);
 
// Query for list of user albums
 
$user_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category >= " . FIRST_USER_CAT . " ORDER BY aid");
if (mysql_num_rows($user_albums)) {
$user_albums_list = db_fetch_rowset($user_albums);
} else {
$user_albums_list = array();
}
 
// Query for list of user IDs and names
 
$user_album_ids_and_names = db_query("SELECT (userid + ".FIRST_USER_CAT.") as id, CONCAT('(', username, ') ') as name FROM $usertbl ORDER BY name ASC",$UDB_DB_LINK_ID);
 
if (mysql_num_rows($user_album_ids_and_names)) {
$user_album_ids_and_names_list = db_fetch_rowset($user_album_ids_and_names);
} else {
$user_album_ids_and_names_list = array();
}
 
// Glue what we've got together.
 
// Initialize $udb_i as a counter.
if (count($merged_array)) {
$udb_i = count($merged_array);
} else {
$udb_i = 0;
}
 
//Begin a set of nested loops to merge the various query results.
foreach ($user_albums_list as $aq) {
foreach ($user_album_ids_and_names_list as $uq) {
if ($aq['category'] == $uq['id']) {
$merged_array[$udb_i]['id']= $aq['category'];
$merged_array[$udb_i]['album_name']= $aq['title'];
$merged_array[$udb_i]['username_category']= $uq['name'];
$udb_i++;
}
}
}
 
// The user albums and public albums have been merged into one list. Print the dropdown.
echo '<select size="1" name="albumid">';
 
foreach ($merged_array as $menu_item) {
 
echo "<option value=\"" . $menu_item['id'] . "\">" . (isset($menu_item['username_category']) ? $menu_item['username_category'] : '') . $menu_item['album_name'] . "</option>\n";
 
}
 
// Close list, etc.
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
}
 
}
 
// ------------------------------------------------------------------------- //
// Define wheter we can join tables or not in SQL queries (same host & same db or user)
define('UDB_CAN_JOIN_TABLES', (VB_BD_HOST == $CONFIG['dbserver'] && (VB_DB_NAME == $CONFIG['dbname'] || VB_DB_USERNAME == $CONFIG['dbuser'])));
// Connect to vBulletin Board Database if necessary
$UDB_DB_LINK_ID = 0;
$UDB_DB_NAME_PREFIX = VB_DB_NAME ? '`' . VB_DB_NAME . '`.' : '';
if (!UDB_CAN_JOIN_TABLES) {
$UDB_DB_LINK_ID = @mysql_connect(VB_BD_HOST, VB_DB_USERNAME, VB_DB_PASSWORD);
if (!$UDB_DB_LINK_ID) die("<b>Coppermine critical error</b>:<br />Unable to connect to vBulletin Board database !<br /><br />MySQL said: <b>" . mysql_error() . "</b>");
}
 
?>
/web/test/gallery/cpg133/bridge/vbulletin3.0_readme.txt
0,0 → 1,67
Coppermine Gallery 1.3.3 and vBulletin 3.0.0 Integration
Version 1.0
Compiled by SpeedStreet
 
I'm not the hacker for this; I am merely the guy who poured through all of the threads on vBulletin.org and the Coppermine Development Forums to come up with one definitive post about integrating vBulletin with Coppermine.
 
WHAT IT DOES:
At the end of this how-to, you're installations of vBulletin and Coppermine will work together off of the same login. While everyone else wants to see all sorts of integration between the two, I believe this is the first step to making those things happen.
 
CREDITS:
A big thanks to everyone over at Coppermine for a terrific product and the users that support and mod it on a daily basis. I am merely standing on the shoulders of giants here, folks. Also, Nanobot was the guy over there that did the vB3 Gamma bridge, so the credit for that is all his.
 
FILES TO EDIT (2):
/bridge/vbulletin30.inc.php (Coppermine)
/include/init.inc.php (Coppermine)
 
HACK REQUIREMENTS:
vBulletin 3.0.0 Installed and Running
Coppermine 1.2.1 Installed and Running
5 Minutes of your time
 
SUPPORT THREADS:
Coppermine Gamma Thread (original thread): http://coppermine.sourceforge.net/board/viewtopic.php?t=2370&start=30&postdays=0&postorder=asc&highlight=
vBulletin.org Hack Thread:
Coppermine vB 3.0.0 Thread:
 
FINAL WARNINGS:
 
There are seem to be some issues with people integrating this with forums located on subdomains (e.g. subaruforums.speedstreet.org). Please reference the Coppermine Gamma Thread above for more info.
Please ensure that Coppermine and vBulletin cookies are NOT named the same thing.
 
-------------------------------------
 
HOW TO INTEGRATE:
1.) Download vbulletin30.inc.php (provided as an archive with this hack)
2.) Open for Editing vbulletin30.inc.php and edit the following with data specific to your site:
 
//NOTE : Your vBulletin license number is provided at the top of every php file in your vBulletin installation!
define('VB_CUST_NO', 'xxxxxxxx'); // Your vBulletin license number (NOT your customer number)
define('VB_DB_NAME', 'forum'); // The name of the database used by the board
define('VB_BD_HOST', 'localhost'); // The name of the database server
define('VB_DB_USERNAME', 'username'); // The username to use to connect to the database
define('VB_DB_PASSWORD', 'password'); // The password to use to connect to the database
 
// The web path to your vBulletin Board directory
// In this example http://yoursite_name.com/vbulletin3/
define('VB_WEB_PATH', '/vbulletin3/');
 
3.) Save vbulletin30.inc.php to the bridge directory of your Coppermine installation
4.) Open for Editing init.inc.php (located in the /include directory of your Coppermine installation
Find:
// define('UDB_INTEGRATION', 'vbulletin30');
Remove the double slashes in front of the line to uncomment
 
5. Save init.inc.php to the include directory of your Coppermine installation
6. Point your browser to your Coppermine installation and verify integration is complete.
 
That should do it. I tried it on a fresh install of both, and a custom install to an existing board. Both worked fine.
 
 
 
 
 
 
 
 
 
/web/test/gallery/cpg133/bridge/vbulletin30.inc.php
0,0 → 1,532
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2005 Coppermine Dev Team
v1.1 originaly written by Gregory DEMAR
 
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.
********************************************
Coppermine version: 1.3.3
$Source: /cvsroot/coppermine/stable/bridge/vbulletin30.inc.php,v $
$Revision: 1.8 $
$Author: gaugau $
$Date: 2005/04/19 03:17:13 $
**********************************************/
// ------------------------------------------------------------------------- //
// vBulletin 3.0 Integration for Coppermine //
// ------------------------------------------------------------------------- //
// Modify the values below according to your Board installation //
// ------------------------------------------------------------------------- //
// database configuration
 
//NOTE : Your vBulletin license number is provided at the top of every php file in your vBulletin installation!
define('VB_CUST_NO', 'xxxxxxxx'); // Your vBulletin license number (NOT your customer number)
define('VB_DB_NAME', 'forum'); // The name of the database used by the board
define('VB_BD_HOST', 'localhost'); // The name of the database server
define('VB_DB_USERNAME', 'username'); // The username to use to connect to the database
define('VB_DB_PASSWORD', 'password'); // The password to use to connect to the database
 
// The web path to your vBulletin Board directory
// In this example http://yoursite_name.com/vbulletin3/
define('VB_WEB_PATH', '/vbulletin3/');
// ------------------------------------------------------------------------- //
// Nothing to edit below this line
// ------------------------------------------------------------------------- //
// Prefix and names for the database tables
define('VB_TABLE_PREFIX', ''); // Leave empty, not supported by vBulletin 2.3
define('VB_USER_TABLE', 'user'); // The members table
define('VB_SESSION_TABLE', 'session'); // The sessions table
define('VB_GROUP_TABLE', 'usergroup'); // The groups table
define('VB_COOKIE_PREFIX', ''); // Cookie Prefix, not supported by vBulletin 2
 
// Group definitions (default values used by the board)
define('VB_VALIDATING_GROUP', 3);
define('VB_GUEST_GROUP', 1);
define('VB_MEMBERS_GROUP', 2);
define('VB_ADMIN_GROUP', 6);
// Authenticate a user using cookies
function udb_authenticate()
{
global $HTTP_COOKIE_VARS, $USER_DATA, $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
global $HTTP_SERVER_VARS, $HTTP_X_FORWARDED_FOR, $HTTP_PROXY_USER, $REMOTE_ADDR;
// For error checking
$CONFIG['TABLE_USERS'] = '**ERROR**';
// Permissions for a default group
$default_group = array('group_id' => VB_GUEST_GROUP,
'group_name' => 'Unknown',
'has_admin_access' => 0,
'can_see_all_albums' => 0,
'can_send_ecards' => 0,
'can_rate_pictures' => 0,
'can_post_comments' => 0,
'can_upload_pictures' => 0,
'can_create_albums' => 0,
'pub_upl_need_approval' => 1,
'priv_upl_need_approval' => 1,
'upload_form_config' => 0,
'custom_user_upload' => 0,
'num_file_upload' => 0,
'num_URI_upload' => 0,
);
// get first 50 chars
$HTTP_USER_AGENT = substr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 0, 50);
$REMOTE_ADDR = substr($HTTP_SERVER_VARS['REMOTE_ADDR'], 0, 50);
 
if (is_array($HTTP_COOKIE_VARS)) {
$sessionhash = isset($HTTP_COOKIE_VARS[VB_COOKIE_PREFIX . 'sessionhash']) ? $HTTP_COOKIE_VARS[VB_COOKIE_PREFIX . 'sessionhash'] : '';
$bbuserid = isset($HTTP_COOKIE_VARS[VB_COOKIE_PREFIX . 'userid']) ? $HTTP_COOKIE_VARS[VB_COOKIE_PREFIX . 'userid'] : 0;
$bbpassword = isset($HTTP_COOKIE_VARS[VB_COOKIE_PREFIX . 'password']) ? $HTTP_COOKIE_VARS[VB_COOKIE_PREFIX . 'password'] : '';
}
 
$got_user = 0;
 
if ($bbuserid && $bbpassword) {
// If userid and password exist in cookies we use them to login
$sql = "SELECT userid as user_id, username as user_name, usergroupid as mgroup, password " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid='" . addslashes($bbuserid) . "'";
$result = db_query($sql, $UDB_DB_LINK_ID);
if (mysql_num_rows($result)) {
$USER_DATA = mysql_fetch_array($result);
if (md5($USER_DATA['password'] . VB_CUST_NO) == $bbpassword) {
$got_user = 1;
}
}
} elseif ($sessionhash) {
// session hash exists
// validate it:
if (isset($HTTP_SERVER_VARS['HTTP_CLIENT_IP']))
{
$alt_ip = $HTTP_SERVER_VARS['HTTP_CLIENT_IP'];
}
elseif (isset($HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR']) AND preg_match('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'], $matches))
{
$alt_ip = $matches[0];
}
elseif (isset($HTTP_SERVER_VARS['HTTP_FROM']))
{
$alt_ip = $HTTP_SERVER_VARS['HTTP_FROM'];
}
else
{
$alt_ip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
}
$idhash = md5($HTTP_SERVER_VARS['HTTP_USER_AGENT'] . $alt_ip );
 
$sql = "SELECT sessionhash,userid,host,useragent,styleid " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_SESSION_TABLE . " " . "WHERE sessionhash='" . addslashes(trim($sessionhash)) . "' " . " AND host='" . addslashes(substr($HTTP_SERVER_VARS['REMOTE_ADDR'], 0, 15)) . "' " . " AND idhash='" . addslashes($idhash) . "'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
// session hash exists
$session_data = mysql_fetch_array($result);
mysql_free_result($result);
 
$sql = "SELECT userid as user_id, username as user_name, usergroupid as mgroup " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid='" . $session_data['userid'] . "'";
$result = db_query($sql, $UDB_DB_LINK_ID);
if (mysql_num_rows($result)) {
$USER_DATA = mysql_fetch_array($result);
$got_user = 1;
}
}
}
 
if ($got_user) {
mysql_free_result($result);
 
define('USER_ID', (int)$USER_DATA['user_id']);
define('USER_NAME', $USER_DATA['user_name']);
// Retrieve group information
$sql = "SELECT * " . "FROM {$CONFIG['TABLE_USERGROUPS']} " . "WHERE group_id = '{$USER_DATA['mgroup']}'";
$result = db_query($sql);
if (mysql_num_rows($result)) {
$USER_DATA2 = mysql_fetch_array($result);
} else {
$USER_DATA2 = $default_group;
}
 
$USER_DATA = array_merge($USER_DATA, $USER_DATA2);
 
$USER_DATA['has_admin_access']= ($USER_DATA['mgroup'] == VB_ADMIN_GROUP);
$USER_DATA['can_see_all_albums'] = $USER_DATA['has_admin_access'];
$USER_DATA['groups'] = array($USER_DATA['group_id']);
 
define('USER_GROUP', $USER_DATA['group_name']);
define('USER_GROUP_SET', '(' . $USER_DATA['group_id'] . ')');
define('USER_IS_ADMIN', ($USER_DATA['mgroup'] == VB_ADMIN_GROUP));
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
mysql_free_result($result);
} else {
$result = db_query("SELECT * FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = " . VB_GUEST_GROUP);
if (!mysql_num_rows($result)) {
$USER_DATA = $default_group;
} else {
$USER_DATA = mysql_fetch_array($result);
}
 
$USER_DATA['groups'] = array(VB_GUEST_GROUP);
 
define('USER_ID', 0);
define('USER_NAME', 'Anonymous');
define('USER_GROUP_SET', '(' . VB_GUEST_GROUP . ')');
define('USER_IS_ADMIN', 0);
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', 0);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
mysql_free_result($result);
}
}
// Retrieve the name of a user
function udb_get_user_name($uid)
{
global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
 
$sql = "SELECT username as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid = '$uid'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_name'];
} else {
return '';
}
}
// Retrieve the name of a user (Added to fix banning w/ bb integration - Nibbler)
function udb_get_user_id($username)
{
global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
 
$username = addslashes($username);
 
$sql = "SELECT userid as user_id " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE username = '$username'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_id'];
} else {
return '';
}
}
 
// Redirect
function udb_redirect($target)
{
header('Location: http://' . $_SERVER['HTTP_HOST'] . VB_WEB_PATH . $target);
exit;
}
 
// Register
function udb_register_page()
{
$target = 'register.php';
udb_redirect($target);
}
// Login
function udb_login_page()
{
$target = 'login.php';
udb_redirect($target);
}
// Logout
function udb_logout_page()
{
$target = 'login.php?&do=logout';
udb_redirect($target);
}
// Edit users
function udb_edit_users()
{
$target = 'admincp/index.php';
udb_redirect($target);
}
// Get user information
function udb_get_user_infos($uid)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
global $lang_register_php;
 
$sql = "SELECT username as user_name, usergroupid as mgroup, email as user_email, joindate as user_regdate, " . "homepage as user_website " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid = '$uid'";
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_register_php['err_unk_user'], __FILE__, __LINE__);
$user_data = mysql_fetch_array($result);
mysql_free_result($result);
 
$user_data['group_name'] = '';
$user_data['user_occupation'] = '';
$user_data['user_location'] = '';
$user_data['user_interests'] = '';
 
$sql = "SELECT group_name " . "FROM {$CONFIG['TABLE_USERGROUPS']} " . "WHERE group_id = {$user_data['mgroup']} ";
$result = db_query($sql);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
$user_data['group_name'] = $row['group_name'];
}
mysql_free_result($result);
 
return $user_data;
}
// Edit user profile
function udb_edit_profile($uid)
{
$target = 'usercp.php';
udb_redirect($target);
}
// Query used to list users
function udb_list_users_query(&$user_count)
{
global $CONFIG, $FORBIDDEN_SET;
 
if ($FORBIDDEN_SET != "") $forbidden = "AND $FORBIDDEN_SET";
$sql = "SELECT (category - " . FIRST_USER_CAT . ") as user_id," . " '???' as user_name," . " COUNT(DISTINCT a.aid) as alb_count," . " COUNT(DISTINCT pid) as pic_count," . " MAX(pid) as thumb_pid " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.aid = a.aid " . "WHERE approved = 'YES' AND category > " . FIRST_USER_CAT . " $forbidden GROUP BY category " . "ORDER BY category ";
$result = db_query($sql);
 
$user_count = mysql_num_rows($result);
 
return $result;
}
 
function udb_list_users_retrieve_data($result, $lower_limit, $count)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
mysql_data_seek($result, $lower_limit);
 
$rowset = array();
$i = 0;
$user_id_set = '';
 
while (($row = mysql_fetch_array($result)) && ($i++ < $count)) {
$user_id_set .= $row['user_id'] . ',';
$rowset[] = $row;
}
mysql_free_result($result);
 
$user_id_set = '(' . substr($user_id_set, 0, -1) . ')';
$sql = "SELECT userid as user_id, username as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid IN $user_id_set";
$result = db_query($sql, $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$name[$row['user_id']] = $row['user_name'];
}
for($i = 0; $i < count($rowset); $i++) {
$rowset[$i]['user_name'] = empty($name[$rowset[$i]['user_id']]) ? '???' : $name[$rowset[$i]['user_id']];
}
 
return $rowset;
}
// Group table synchronisation
function udb_synchronize_groups()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$result = db_query("SELECT usergroupid, title FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_GROUP_TABLE . " WHERE 1", $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$VB_groups[$row['usergroupid']] = $row['title'];
}
mysql_free_result($result);
 
$result = db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE 1");
while ($row = mysql_fetch_array($result)) {
$cpg_groups[$row['group_id']] = $row['group_name'];
}
mysql_free_result($result);
// Scan Coppermine groups that need to be deleted
foreach($cpg_groups as $c_group_id => $c_group_name) {
if ((!isset($VB_groups[$c_group_id]))) {
db_query("DELETE FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = '" . $c_group_id . "' LIMIT 1");
unset($cpg_groups[$c_group_id]);
}
}
// Scan vBulletin Board groups that need to be created inside Coppermine table
foreach($VB_groups as $i_group_id => $i_group_name) {
if ((!isset($cpg_groups[$i_group_id]))) {
db_query("INSERT INTO {$CONFIG['TABLE_USERGROUPS']} (group_id, group_name) VALUES ('$i_group_id', '" . addslashes($i_group_name) . "')");
$cpg_groups[$i_group_id] = $i_group_name;
}
}
// Update Group names
foreach($VB_groups as $i_group_id => $i_group_name) {
if ($cpg_groups[$i_group_id] != $i_group_name) {
db_query("UPDATE {$CONFIG['TABLE_USERGROUPS']} SET group_name = '" . addslashes($i_group_name) . "' WHERE group_id = '$i_group_id' LIMIT 1");
}
}
}
// Retrieve the album list used in gallery admin mode
function udb_get_admin_album_list()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID, $FORBIDDEN_SET;
 
if (UDB_CAN_JOIN_TABLES) {
$sql = "SELECT aid, CONCAT('(', username, ') ', a.title) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " AS u ON category = (" . FIRST_USER_CAT . " + userid) " . "ORDER BY title";
return $sql;
} else {
$sql = "SELECT aid, IF(category > " . FIRST_USER_CAT . ", CONCAT('* ', title), CONCAT(' ', title)) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} " . "ORDER BY title";
return $sql;
}
}
 
function udb_util_filloptions()
{
global $albumtbl, $picturetbl, $categorytbl, $lang_util_php, $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$usertbl = $UDB_DB_NAME_PREFIX.VB_TABLE_PREFIX.VB_USER_TABLE;
 
if (UDB_CAN_JOIN_TABLES) {
 
$query = "SELECT aid, category, IF(username IS NOT NULL, CONCAT('(', username, ') ', a.title), CONCAT(' - ', a.title)) AS title " . "FROM $albumtbl AS a " . "LEFT JOIN $usertbl AS u ON category = (" . FIRST_USER_CAT . " + userid) " . "ORDER BY category, title";
$result = db_query($query, $UDB_DB_LINK_ID);
// $num=mysql_numrows($result);
echo '<select size="1" name="albumid">';
 
while ($row = mysql_fetch_array($result)) {
$sql = "SELECT name FROM $categorytbl WHERE cid = " . $row["category"];
$result2 = db_query($sql);
$row2 = mysql_fetch_array($result2);
 
print "<option value=\"" . $row["aid"] . "\">" . $row2["name"] . $row["title"] . "</option>\n";
}
 
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
} else {
 
// Query for list of public albums
 
$public_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " ORDER BY title");
 
if (mysql_num_rows($public_albums)) {
$public_result = db_fetch_rowset($public_albums);
} else {
$public_result = array();
}
 
// Initialize $merged_array
$merged_array = array();
 
// Count the number of albums returned.
$end = count($public_result);
 
// Cylce through the User albums.
for($i=0;$i<$end;$i++) {
 
//Create a new array sow we may sort the final results.
$merged_array[$i]['id'] = $public_result[$i]['aid'];
$merged_array[$i]['album_name'] = $public_result[$i]['title'];
 
// Query the database to get the category name.
$vQuery = "SELECT name, parent FROM " . $CONFIG['TABLE_CATEGORIES'] . " WHERE cid='" . $public_result[$i]['category'] . "'";
$vRes = mysql_query($vQuery);
$vRes = mysql_fetch_array($vRes);
if (isset($merged_array[$i]['username_category'])) {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '').$merged_array[$i]['username_category'];
} else {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '');
}
 
}
 
// We transpose and divide the matrix into columns to prepare it for use in array_multisort().
foreach ($merged_array as $key => $row) {
$aid[$key] = $row['id'];
$title[$key] = $row['album_name'];
$album_lineage[$key] = $row['username_category'];
}
 
// We sort all columns in descending order and plug in $album_menu at the end so it is sorted by the common key.
array_multisort($album_lineage, SORT_ASC, $title, SORT_ASC, $aid, SORT_ASC, $merged_array);
 
// Query for list of user albums
 
$user_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category >= " . FIRST_USER_CAT . " ORDER BY aid");
if (mysql_num_rows($user_albums)) {
$user_albums_list = db_fetch_rowset($user_albums);
} else {
$user_albums_list = array();
}
 
// Query for list of user IDs and names
 
$user_album_ids_and_names = db_query("SELECT (userid + ".FIRST_USER_CAT.") as id, CONCAT('(', username, ') ') as name FROM $usertbl ORDER BY name ASC",$UDB_DB_LINK_ID);
 
if (mysql_num_rows($user_album_ids_and_names)) {
$user_album_ids_and_names_list = db_fetch_rowset($user_album_ids_and_names);
} else {
$user_album_ids_and_names_list = array();
}
 
// Glue what we've got together.
 
// Initialize $udb_i as a counter.
if (count($merged_array)) {
$udb_i = count($merged_array);
} else {
$udb_i = 0;
}
 
//Begin a set of nested loops to merge the various query results.
foreach ($user_albums_list as $aq) {
foreach ($user_album_ids_and_names_list as $uq) {
if ($aq['category'] == $uq['id']) {
$merged_array[$udb_i]['id']= $aq['category'];
$merged_array[$udb_i]['album_name']= $aq['title'];
$merged_array[$udb_i]['username_category']= $uq['name'];
$udb_i++;
}
}
}
 
// The user albums and public albums have been merged into one list. Print the dropdown.
echo '<select size="1" name="albumid">';
 
foreach ($merged_array as $menu_item) {
 
echo "<option value=\"" . $menu_item['id'] . "\">" . (isset($menu_item['username_category']) ? $menu_item['username_category'] : '') . $menu_item['album_name'] . "</option>\n";
 
}
 
// Close list, etc.
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
}
 
}
 
// ------------------------------------------------------------------------- //
// Define wheter we can join tables or not in SQL queries (same host & same db or user)
define('UDB_CAN_JOIN_TABLES', (VB_BD_HOST == $CONFIG['dbserver'] && (VB_DB_NAME == $CONFIG['dbname'] || VB_DB_USERNAME == $CONFIG['dbuser'])));
// Connect to vBulletin Board Database if necessary
$UDB_DB_LINK_ID = 0;
$UDB_DB_NAME_PREFIX = VB_DB_NAME ? '`' . VB_DB_NAME . '`.' : '';
if (!UDB_CAN_JOIN_TABLES) {
$UDB_DB_LINK_ID = @mysql_connect(VB_BD_HOST, VB_DB_USERNAME, VB_DB_PASSWORD);
if (!$UDB_DB_LINK_ID) die("<b>Coppermine critical error</b>:<br />Unable to connect to vBulletin Board database !<br /><br />MySQL said: <b>" . mysql_error() . "</b>");
}
 
?>
/web/test/gallery/cpg133/bridge/vbulletin3gamma.inc.php
0,0 → 1,490
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2005 Coppermine Dev Team
v1.1 originaly written by Gregory DEMAR
 
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.
********************************************
Coppermine version: 1.3.3
$Source: /cvsroot/coppermine/stable/bridge/vbulletin3gamma.inc.php,v $
$Revision: 1.6 $
$Author: gaugau $
$Date: 2005/04/19 03:17:13 $
**********************************************/
// ------------------------------------------------------------------------- //
// vBulletin 3.0 Integration for Coppermine
// ------------------------------------------------------------------------- //
 
// ------------------------------------------------------------------------- //
// Modify the values below according to your Board installation
// ------------------------------------------------------------------------- //
// database configuration
define('VB_CUST_NO', 'xxxxxxxx'); // Your vBulletin license number (NOT your customer number)
define('VB_DB_NAME', 'forum'); // The name of the database used by the board
define('VB_BD_HOST', 'localhost'); // The name of the database server
define('VB_DB_USERNAME', 'username'); // The username to use to connect to the database
define('VB_DB_PASSWORD', 'password'); // The password to use to connect to the database
 
// The web path to your vBulletin Board directory
// In this example http://yoursite_name.com/vbulletin3/
define('VB_WEB_PATH', '/vbulletin3/');
// ------------------------------------------------------------------------- //
// Nothing to edit below this line
// ------------------------------------------------------------------------- //
// Prefix and names for the database tables
define('VB_TABLE_PREFIX', ''); // Leave empty, not supported by vBulletin 2.3
define('VB_USER_TABLE', 'user'); // The members table
define('VB_SESSION_TABLE', 'session'); // The sessions table
define('VB_GROUP_TABLE', 'usergroup'); // The groups table
 
// Group definitions (default values used by the board)
define('VB_VALIDATING_GROUP', 3);
define('VB_GUEST_GROUP', 1);
define('VB_MEMBERS_GROUP', 2);
define('VB_ADMIN_GROUP', 6);
// Authenticate a user using cookies
function udb_authenticate()
{
global $HTTP_COOKIE_VARS, $USER_DATA, $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
global $HTTP_SERVER_VARS, $HTTP_X_FORWARDED_FOR, $HTTP_PROXY_USER, $REMOTE_ADDR;
// For error checking
$CONFIG['TABLE_USERS'] = '**ERROR**';
// Permissions for a default group
$default_group = array('group_id' => VB_GUEST_GROUP,
'group_name' => 'Unknown',
'has_admin_access' => 0,
'can_send_ecards' => 0,
'can_rate_pictures' => 0,
'can_post_comments' => 0,
'can_upload_pictures' => 0,
'can_create_albums' => 0,
'pub_upl_need_approval' => 1,
'priv_upl_need_approval' => 1,
);
// get first 50 chars
$HTTP_USER_AGENT = substr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 0, 50);
$REMOTE_ADDR = substr($HTTP_SERVER_VARS['REMOTE_ADDR'], 0, 50);
 
if (is_array($HTTP_COOKIE_VARS)) {
$sessionhash = isset($HTTP_COOKIE_VARS['sessionhash']) ? $HTTP_COOKIE_VARS['sessionhash'] : '';
$bbuserid = isset($HTTP_COOKIE_VARS['bbuserid']) ? $HTTP_COOKIE_VARS['bbuserid'] : 0;
$bbpassword = isset($HTTP_COOKIE_VARS['bbpassword']) ? $HTTP_COOKIE_VARS['bbpassword'] : '';
}
 
$got_user = 0;
 
if ($bbuserid && $bbpassword) {
// If userid and password exist in cookies we use them to login
$sql = "SELECT userid as user_id, username as user_name, usergroupid as mgroup, password " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid='" . addslashes($bbuserid) . "'";
$result = db_query($sql, $UDB_DB_LINK_ID);
if (mysql_num_rows($result)) {
$USER_DATA = mysql_fetch_array($result);
if (md5($USER_DATA['password'] . VB_CUST_NO) == $bbpassword) {
$got_user = 1;
}
}
} elseif ($sessionhash) {
// session hash exists
// validate it:
if ($HTTP_SERVER_VARS['HTTP_CLIENT_IP'])
{
$alt_ip = $HTTP_SERVER_VARS['HTTP_CLIENT_IP'];
}
else if ($HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'] AND preg_match('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'], $matches))
{
$alt_ip = $matches[0];
}
else if ($HTTP_SERVER_VARS['HTTP_FROM'])
{
$alt_ip = $HTTP_SERVER_VARS['HTTP_FROM'];
}
else
{
$alt_ip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
}
$idhash = md5($HTTP_SERVER_VARS['HTTP_USER_AGENT'] . $alt_ip );
 
$sql = "SELECT sessionhash,userid,host,useragent,styleid " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_SESSION_TABLE . " " . "WHERE sessionhash='" . addslashes(trim($sessionhash)) . "' " . " AND host='" . addslashes(substr($HTTP_SERVER_VARS['REMOTE_ADDR'], 0, 15)) . "' " . " AND idhash='" . addslashes($idhash) . "'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
// session hash exists
$session_data = mysql_fetch_array($result);
mysql_free_result($result);
 
$sql = "SELECT userid as user_id, username as user_name, usergroupid as mgroup " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid='" . $session_data['userid'] . "'";
$result = db_query($sql, $UDB_DB_LINK_ID);
if (mysql_num_rows($result)) {
$USER_DATA = mysql_fetch_array($result);
$got_user = 1;
}
}
}
 
if ($got_user) {
mysql_free_result($result);
 
define('USER_ID', (int)$USER_DATA['user_id']);
define('USER_NAME', $USER_DATA['user_name']);
// Retrieve group information
$sql = "SELECT * " . "FROM {$CONFIG['TABLE_USERGROUPS']} " . "WHERE group_id = '{$USER_DATA['mgroup']}'";
$result = db_query($sql);
if (mysql_num_rows($result)) {
$USER_DATA2 = mysql_fetch_array($result);
} else {
$USER_DATA2 = $default_group;
}
 
$USER_DATA = array_merge($USER_DATA, $USER_DATA2);
 
define('USER_GROUP', $USER_DATA['group_name']);
define('USER_GROUP_SET', '(' . $USER_DATA['group_id'] . ')');
define('USER_IS_ADMIN', ($USER_DATA['mgroup'] == VB_ADMIN_GROUP));
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
mysql_free_result($result);
} else {
$result = db_query("SELECT * FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = " . VB_GUEST_GROUP);
if (!mysql_num_rows($result)) {
$USER_DATA = $default_group;
} else {
$USER_DATA = mysql_fetch_array($result);
}
define('USER_ID', 0);
define('USER_NAME', 'Anonymous');
define('USER_GROUP_SET', '(' . VB_GUEST_GROUP . ')');
define('USER_IS_ADMIN', 0);
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', 0);
mysql_free_result($result);
}
}
// Retrieve the name of a user
function udb_get_user_name($uid)
{
global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
 
$sql = "SELECT username as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid = '$uid'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_name'];
} else {
return '';
}
}
// Redirect
function udb_redirect($target)
{
header('Location: ' . VB_WEB_PATH . $target);
exit;
}
// Register
function udb_register_page()
{
$target = 'register.php';
udb_redirect($target);
}
// Login
function udb_login_page()
{
$target = 'login.php';
udb_redirect($target);
}
// Logout
function udb_logout_page()
{
$target = 'login.php?&do=logout';
udb_redirect($target);
}
// Edit users
function udb_edit_users()
{
$target = 'admincp/index.php';
udb_redirect($target);
}
// Get user information
function udb_get_user_infos($uid)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
global $lang_register_php;
 
$sql = "SELECT username as user_name, usergroupid as mgroup, email as user_email, joindate as user_regdate, " . "homepage as user_website " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid = '$uid'";
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_register_php['err_unk_user'], __FILE__, __LINE__);
$user_data = mysql_fetch_array($result);
mysql_free_result($result);
 
$user_data['group_name'] = '';
$user_data['user_occupation'] = '';
$user_data['user_location'] = '';
$user_data['user_interests'] = '';
 
$sql = "SELECT group_name " . "FROM {$CONFIG['TABLE_USERGROUPS']} " . "WHERE group_id = {$user_data['mgroup']} ";
$result = db_query($sql);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
$user_data['group_name'] = $row['group_name'];
}
mysql_free_result($result);
 
return $user_data;
}
// Edit user profile
function udb_edit_profile($uid)
{
$target = 'usercp.php';
udb_redirect($target);
}
// Query used to list users
function udb_list_users_query(&$user_count)
{
global $CONFIG, $FORBIDDEN_SET;
 
if ($FORBIDDEN_SET != "") $forbidden = "AND $FORBIDDEN_SET";
$sql = "SELECT (category - " . FIRST_USER_CAT . ") as user_id," . " '???' as user_name," . " COUNT(DISTINCT a.aid) as alb_count," . " COUNT(DISTINCT pid) as pic_count," . " MAX(pid) as thumb_pid " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.aid = a.aid " . "WHERE approved = 'YES' AND category > " . FIRST_USER_CAT . " $forbidden GROUP BY category " . "ORDER BY category ";
$result = db_query($sql);
 
$user_count = mysql_num_rows($result);
 
return $result;
}
 
function udb_list_users_retrieve_data($result, $lower_limit, $count)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
mysql_data_seek($result, $lower_limit);
 
$rowset = array();
$i = 0;
$user_id_set = '';
 
while (($row = mysql_fetch_array($result)) && ($i++ < $count)) {
$user_id_set .= $row['user_id'] . ',';
$rowset[] = $row;
}
mysql_free_result($result);
 
$user_id_set = '(' . substr($user_id_set, 0, -1) . ')';
$sql = "SELECT userid as user_id, username as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid IN $user_id_set";
$result = db_query($sql, $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$name[$row['user_id']] = $row['user_name'];
}
for($i = 0; $i < count($rowset); $i++) {
$rowset[$i]['user_name'] = empty($name[$rowset[$i]['user_id']]) ? '???' : $name[$rowset[$i]['user_id']];
}
 
return $rowset;
}
// Group table synchronisation
function udb_synchronize_groups()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$result = db_query("SELECT usergroupid, title FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_GROUP_TABLE . " WHERE 1", $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$VB_groups[$row['usergroupid']] = $row['title'];
}
mysql_free_result($result);
 
$result = db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE 1");
while ($row = mysql_fetch_array($result)) {
$cpg_groups[$row['group_id']] = $row['group_name'];
}
mysql_free_result($result);
// Scan Coppermine groups that need to be deleted
foreach($cpg_groups as $c_group_id => $c_group_name) {
if ((!isset($VB_groups[$c_group_id]))) {
db_query("DELETE FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = '" . $c_group_id . "' LIMIT 1");
unset($cpg_groups[$c_group_id]);
}
}
// Scan vBulletin Board groups that need to be created inside Coppermine table
foreach($VB_groups as $i_group_id => $i_group_name) {
if ((!isset($cpg_groups[$i_group_id]))) {
db_query("INSERT INTO {$CONFIG['TABLE_USERGROUPS']} (group_id, group_name) VALUES ('$i_group_id', '" . addslashes($i_group_name) . "')");
$cpg_groups[$i_group_id] = $i_group_name;
}
}
// Update Group names
foreach($VB_groups as $i_group_id => $i_group_name) {
if ($cpg_groups[$i_group_id] != $i_group_name) {
db_query("UPDATE {$CONFIG['TABLE_USERGROUPS']} SET group_name = '" . addslashes($i_group_name) . "' WHERE group_id = '$i_group_id' LIMIT 1");
}
}
}
// Retrieve the album list used in gallery admin mode
function udb_get_admin_album_list()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID, $FORBIDDEN_SET;
 
if (UDB_CAN_JOIN_TABLES) {
$sql = "SELECT aid, CONCAT('(', username, ') ', a.title) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " AS u ON category = (" . FIRST_USER_CAT . " + userid) " . "ORDER BY title";
return $sql;
} else {
$sql = "SELECT aid, IF(category > " . FIRST_USER_CAT . ", CONCAT('* ', title), CONCAT(' ', title)) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} " . "ORDER BY title";
return $sql;
}
}
 
function udb_util_filloptions()
{
global $albumtbl, $picturetbl, $categorytbl, $lang_util_php, $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$usertbl = $UDB_DB_NAME_PREFIX.VB_TABLE_PREFIX.VB_USER_TABLE;
 
if (UDB_CAN_JOIN_TABLES) {
 
$query = "SELECT aid, category, IF(username IS NOT NULL, CONCAT('(', username, ') ', a.title), CONCAT(' - ', a.title)) AS title " . "FROM $albumtbl AS a " . "LEFT JOIN $usertbl AS u ON category = (" . FIRST_USER_CAT . " + userid) " . "ORDER BY category, title";
$result = db_query($query, $UDB_DB_LINK_ID);
// $num=mysql_numrows($result);
echo '<select size="1" name="albumid">';
 
while ($row = mysql_fetch_array($result)) {
$sql = "SELECT name FROM $categorytbl WHERE cid = " . $row["category"];
$result2 = db_query($sql);
$row2 = mysql_fetch_array($result2);
 
print "<option value=\"" . $row["aid"] . "\">" . $row2["name"] . $row["title"] . "</option>\n";
}
 
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
} else {
 
// Query for list of public albums
 
$public_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " ORDER BY title");
 
if (mysql_num_rows($public_albums)) {
$public_result = db_fetch_rowset($public_albums);
} else {
$public_result = array();
}
 
// Initialize $merged_array
$merged_array = array();
 
// Count the number of albums returned.
$end = count($public_result);
 
// Cylce through the User albums.
for($i=0;$i<$end;$i++) {
 
//Create a new array sow we may sort the final results.
$merged_array[$i]['id'] = $public_result[$i]['aid'];
$merged_array[$i]['album_name'] = $public_result[$i]['title'];
 
// Query the database to get the category name.
$vQuery = "SELECT name, parent FROM " . $CONFIG['TABLE_CATEGORIES'] . " WHERE cid='" . $public_result[$i]['category'] . "'";
$vRes = mysql_query($vQuery);
$vRes = mysql_fetch_array($vRes);
if (isset($merged_array[$i]['username_category'])) {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '').$merged_array[$i]['username_category'];
} else {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '');
}
 
}
 
// We transpose and divide the matrix into columns to prepare it for use in array_multisort().
foreach ($merged_array as $key => $row) {
$aid[$key] = $row['id'];
$title[$key] = $row['album_name'];
$album_lineage[$key] = $row['username_category'];
}
 
// We sort all columns in descending order and plug in $album_menu at the end so it is sorted by the common key.
array_multisort($album_lineage, SORT_ASC, $title, SORT_ASC, $aid, SORT_ASC, $merged_array);
 
// Query for list of user albums
 
$user_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category >= " . FIRST_USER_CAT . " ORDER BY aid");
if (mysql_num_rows($user_albums)) {
$user_albums_list = db_fetch_rowset($user_albums);
} else {
$user_albums_list = array();
}
 
// Query for list of user IDs and names
 
$user_album_ids_and_names = db_query("SELECT (userid + ".FIRST_USER_CAT.") as id, CONCAT('(', username, ') ') as name FROM $usertbl ORDER BY name ASC",$UDB_DB_LINK_ID);
 
if (mysql_num_rows($user_album_ids_and_names)) {
$user_album_ids_and_names_list = db_fetch_rowset($user_album_ids_and_names);
} else {
$user_album_ids_and_names_list = array();
}
 
// Glue what we've got together.
 
// Initialize $udb_i as a counter.
if (count($merged_array)) {
$udb_i = count($merged_array);
} else {
$udb_i = 0;
}
 
//Begin a set of nested loops to merge the various query results.
foreach ($user_albums_list as $aq) {
foreach ($user_album_ids_and_names_list as $uq) {
if ($aq['category'] == $uq['id']) {
$merged_array[$udb_i]['id']= $aq['category'];
$merged_array[$udb_i]['album_name']= $aq['title'];
$merged_array[$udb_i]['username_category']= $uq['name'];
$udb_i++;
}
}
}
 
// The user albums and public albums have been merged into one list. Print the dropdown.
echo '<select size="1" name="albumid">';
 
foreach ($merged_array as $menu_item) {
 
echo "<option value=\"" . $menu_item['id'] . "\">" . (isset($menu_item['username_category']) ? $menu_item['username_category'] : '') . $menu_item['album_name'] . "</option>\n";
 
}
 
// Close list, etc.
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
}
 
}
 
// ------------------------------------------------------------------------- //
// Define wheter we can join tables or not in SQL queries (same host & same db or user)
define('UDB_CAN_JOIN_TABLES', (VB_BD_HOST == $CONFIG['dbserver'] && (VB_DB_NAME == $CONFIG['dbname'] || VB_DB_USERNAME == $CONFIG['dbuser'])));
// Connect to vBulletin Board Database if necessary
$UDB_DB_LINK_ID = 0;
$UDB_DB_NAME_PREFIX = VB_DB_NAME ? '`' . VB_DB_NAME . '`.' : '';
if (!UDB_CAN_JOIN_TABLES) {
$UDB_DB_LINK_ID = @mysql_connect(VB_BD_HOST, VB_DB_USERNAME, VB_DB_PASSWORD);
if (!$UDB_DB_LINK_ID) die("<b>Coppermine critical error</b>:<br />Unable to connect to vBulletin Board database !<br /><br />MySQL said: <b>" . mysql_error() . "</b>");
}
 
?>
/web/test/gallery/cpg133/bridge/woltlab21.inc.php
0,0 → 1,603
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2005 Coppermine Dev Team
v1.1 originaly written by Gregory DEMAR
 
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.
********************************************
Coppermine version: 1.3.3
$Source: /cvsroot/coppermine/stable/bridge/woltlab21.inc.php,v $
$Revision: 1.7 $
$Author: gaugau $
$Date: 2005/04/19 03:17:13 $
**********************************************/
// ------------------------------------------------------------------------- //
// Woltlab Burning Board 2.1 Integration for Coppermine //
// ------------------------------------------------------------------------- //
// Modify the values below according to your Board installation //
// ------------------------------------------------------------------------- //
// user contribution by sugar //
// (see http://coppermine.sourceforge.net/oldboard/viewtopic.php?t=2547 //
// for details) //
// ------------------------------------------------------------------------- //
// Updated by Mr. S //
// http://coppermine.sourceforge.net/board/index.php?topic=5559.0 //
// ------------------------------------------------------------------------- //
 
// In this example there are 2 subdirectories
// WBB: http://yoursite_name.com/wbb2/
// CPG: http://yoursite_name.com/cpg/
// Setup path to your Woltlab Board directory to change this
 
// The paths to your Woltlab Board directory
define('RELATIVE_WBB_PATH','../wbb2/');
define('WBB_WEB_PATH','/wbb2/');
 
// database configuration
require_once(RELATIVE_WBB_PATH."acp/lib/config.inc.php");
require_once(RELATIVE_WBB_PATH."acp/lib/options.inc.php");
define('WBB_DB_NAME',$sqldb);
define('WBB_BD_HOST',$sqlhost);
define('WBB_DB_USERNAME',$sqluser);
define('WBB_DB_PASSWORD',$sqlpassword);
 
// cookies configuration
define('WBB_COOKIE_HASH',$cookieprefix."cookiehash");
define('WBB_COOKIE_USERID',$cookieprefix."userid");
define('WBB_COOKIE_USERPW',$cookieprefix."userpassword");
 
// ------------------------------------------------------------------------- //
// Nothing to edit below this line
// ------------------------------------------------------------------------- //
 
// Prefix and names for the database tables
define('WBB_TABLE_PREFIX','bb'.$n.'_'); // Leave empty, not supported by vBulletin 2.3
define('WBB_USER_TABLE', 'users'); // The members table
define('WBB_SESSION_TABLE', 'sessions'); // The sessions table
define('WBB_GROUP_TABLE', 'groups'); // The groups table
 
// Group definitions (default values used by the board)
define('WBB_GUEST_GROUP', 5);
define('WBB_MEMBERS_GROUP', 4);
define('WBB_ADMIN_GROUP', 1);
 
// Authenticate a user using cookies
function udb_authenticate()
{
global $HTTP_COOKIE_VARS, $USER_DATA, $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
global $HTTP_SERVER_VARS, $REMOTE_ADDR, $HTTP_X_FORWARDED_FOR;
global $lang_errors;
 
// For error checking
$CONFIG['TABLE_USERS'] = '**ERROR**';
 
// Permissions for a default group
$default_group = array(
'group_id' => WBB_GUEST_GROUP,
'group_name' => 'Unknown',
'has_admin_access' => 0,
'can_see_all_albums' => 0,
'can_send_ecards' => 0,
'can_rate_pictures' => 0,
'can_post_comments' => 0,
'can_upload_pictures' => 0,
'can_create_albums' => 0,
'pub_upl_need_approval' => 1,
'priv_upl_need_approval' => 1,
'upload_form_config' => 0,
'custom_user_upload' => 0,
'num_file_upload' => 0,
'num_URI_upload' => 0,
);
 
$REMOTE_ADDR=$_SERVER['REMOTE_ADDR'];
$HTTP_X_FORWARDED_FOR=(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
 
if($HTTP_X_FORWARDED_FOR!="") {
if(preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", $HTTP_X_FORWARDED_FOR, $ip_match)) {
$private_ip_list = array("/^0\./", "/^127\.0\.0\.1/", "/^192\.168\..*/", "/^172\.16\..*/", "/^10..*/", "/^224..*/", "/^240..*/");
$REMOTE_ADDR = preg_replace($private_ip_list, $REMOTE_ADDR, $ip_match[1]);
}
}
$HTTP_USER_AGENT = substr($_SERVER['HTTP_USER_AGENT'], 0, 100);
$REQUEST_URI = $_SERVER['REQUEST_URI'];
if(!$REQUEST_URI) {
if($_SERVER['PATH_INFO']) $REQUEST_URI = $_SERVER['PATH_INFO'];
else $REQUEST_URI = $_SERVER['PHP_SELF'];
if($_SERVER['QUERY_STRING']) $REQUEST_URI.="?".$_SERVER['QUERY_STRING'];
}
$REQUEST_URI = substr(basename($REQUEST_URI), 0, 250);
if(!strstr($REQUEST_URI,".")) $REQUEST_URI="index.php";
 
$REMOTE_ADDR=htmlspecialchars($REMOTE_ADDR);
$HTTP_USER_AGENT=htmlspecialchars($HTTP_USER_AGENT);
 
if ( is_array($_COOKIE) ) {
$sessionhash = isset($_COOKIE[WBB_COOKIE_HASH]) ? $_COOKIE[WBB_COOKIE_HASH] : '';
$bbuserid = isset($_COOKIE[WBB_COOKIE_USERID]) ? $_COOKIE[WBB_COOKIE_USERID] : 0;
$bbpassword = isset($_COOKIE[WBB_COOKIE_USERPW]) ? $_COOKIE[WBB_COOKIE_USERPW] : '';
}
 
if ($bbuserid && $bbpassword) {
// If userid and password exist in cookies we use them to login
$sql = "SELECT userid as user_id, username as user_name, useronlinegroupid as mgroup ".
"FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." ".
"WHERE userid='".addslashes($bbuserid)."' AND password='".addslashes($bbpassword)."'";
} elseif ($sessionhash) {
// session hash exists
// validate it:
$sql = "SELECT * ".
"FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_SESSION_TABLE." ".
"WHERE sessionhash = '".addslashes($sessionhash)."' ".
" AND ipaddress = '".addslashes($REMOTE_ADDR)."' ".
" AND useragent = '".addslashes($HTTP_USER_AGENT)."'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
// session hash exists
$session_data = mysql_fetch_array($result);
mysql_free_result($result);
 
$sql = "SELECT userid as user_id, username as user_name, useronlinegroupid as mgroup ".
"FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." ".
"WHERE userid='".$session_data['userid']."'";
$result = db_query($sql, $UDB_DB_LINK_ID);
} else {
$sql = "SELECT userid as user_id, username as user_name, useronlinegroupid as mgroup ".
"FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." ".
"WHERE 0";
}
} else {
$sql = "SELECT userid as user_id, username as user_name, useronlinegroupid as mgroup ".
"FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." ".
"WHERE 0";
}
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)){
$USER_DATA = mysql_fetch_array($result);
mysql_free_result($result);
 
define('USER_ID', (int)$USER_DATA['user_id']);
define('USER_NAME', $USER_DATA['user_name']);
 
// Retrieve group information
$sql = "SELECT * ".
"FROM {$CONFIG['TABLE_USERGROUPS']} ".
"WHERE group_id = '{$USER_DATA['mgroup']}'";
$result = db_query($sql);
if (mysql_num_rows($result)){
$USER_DATA2 = mysql_fetch_array($result);
} else {
$USER_DATA2 = $default_group;
}
 
$USER_DATA = array_merge($USER_DATA, $USER_DATA2);
 
$USER_DATA['has_admin_access']= ($USER_DATA['mgroup'] == WBB_ADMIN_GROUP);
$USER_DATA['can_see_all_albums'] = $USER_DATA['has_admin_access'];
$USER_DATA['groups'] = array($USER_DATA['group_id']);
 
define('USER_GROUP', $USER_DATA['group_name']);
define('USER_GROUP_SET', '('.$USER_DATA['group_id'].')');
define('USER_IS_ADMIN', ($USER_DATA['mgroup'] == WBB_ADMIN_GROUP));
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
mysql_free_result($result);
} else {
$result = db_query("SELECT * FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = ".WBB_GUEST_GROUP);
if (!mysql_num_rows($result)) {
$USER_DATA = $default_group;
} else {
$USER_DATA = mysql_fetch_array($result);
}
 
$USER_DATA['groups'] = array(WBB_GUEST_GROUP);
 
define('USER_ID', 0);
define('USER_NAME', 'Anonymous');
define('USER_GROUP_SET', '('.WBB_GUEST_GROUP.')');
define('USER_IS_ADMIN', 0);
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', 0);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
mysql_free_result($result);
}
}
 
// Retrieve the name of a user
function udb_get_user_name($uid)
{
global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
 
$sql = "SELECT username as user_name ".
"FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." ".
"WHERE userid = '$uid'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_name'];
} else {
return '';
}
}
// Retrieve the name of a user (Added to fix banning w/ bb integration - Nibbler)
function udb_get_user_id($username)
{
global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
 
$username = addslashes($username);
 
$sql = "SELECT userid as user_id ".
"FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." ".
"WHERE username = '$username'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_id'];
} else {
return '';
}
}
 
// Redirect
function udb_redirect($target)
{
header('Location: http://' . $_SERVER['HTTP_HOST'] . WBB_WEB_PATH . $target);
exit;
}
 
// Register
function udb_register_page()
{
$target = 'register.php';
udb_redirect($target);
}
 
// Login
function udb_login_page()
{
$target = 'index.php';
udb_redirect($target);
}
 
// Logout
function udb_logout_page()
{
$target = 'logout.php';
udb_redirect($target);
}
 
// Edit users
function udb_edit_users()
{
$target = 'acp/users.php';
udb_redirect($target);
}
 
// Get user information
function udb_get_user_infos($uid)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
global $lang_register_php;
 
$sql = "SELECT username as user_name, useronlinegroupid as mgroup, email as user_email, regdate as user_regdate, ".
"homepage as user_website ".
"FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." ".
"WHERE userid = '$uid'";
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if(!mysql_num_rows($result)) cpg_die(ERROR, $lang_register_php['err_unk_user'], __FILE__, __LINE__);
$user_data = mysql_fetch_array($result);
mysql_free_result($result);
 
$user_data['group_name'] = '';
$user_data['user_occupation'] = '';
$user_data['user_location'] = '';
$user_data['user_interests'] = '';
 
$sql = "SELECT group_name ".
"FROM {$CONFIG['TABLE_USERGROUPS']} ".
"WHERE group_id = {$user_data['mgroup']} ";
$result = db_query($sql);
 
if(mysql_num_rows($result)){
$row = mysql_fetch_array($result);
$user_data['group_name'] = $row['group_name'];
}
mysql_free_result($result);
 
return $user_data;
}
 
// Edit user profile
function udb_edit_profile($uid)
{
$target = 'usercp.php';
udb_redirect($target);
}
 
// Query used to list users
function udb_list_users_query(&$user_count)
{
global $CONFIG, $FORBIDDEN_SET;
 
if ($FORBIDDEN_SET != "") $forbidden = "AND $FORBIDDEN_SET";
$sql = "SELECT (category - ".FIRST_USER_CAT.") as user_id,".
" '???' as user_name,".
" COUNT(DISTINCT a.aid) as alb_count,".
" COUNT(DISTINCT pid) as pic_count,".
" MAX(pid) as thumb_pid ".
"FROM {$CONFIG['TABLE_ALBUMS']} AS a ".
"INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.aid = a.aid ".
"WHERE approved = 'YES' AND category > ".FIRST_USER_CAT." ".
"$forbidden ".
"GROUP BY category ".
"ORDER BY category ";
$result = db_query($sql);
 
$user_count = mysql_num_rows($result);
 
return $result;
}
 
function udb_list_users_retrieve_data($result, $lower_limit, $count)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
mysql_data_seek($result, $lower_limit);
 
$rowset = array();
$i=0;
$user_id_set='';
 
while (($row = mysql_fetch_array($result)) && ($i++ < $count)){
$user_id_set .= $row['user_id'].',';
$rowset[] = $row;
}
mysql_free_result($result);
 
$user_id_set = '('.substr($user_id_set, 0, -1).')';
$sql = "SELECT userid as user_id, username as user_name ".
"FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." ".
"WHERE userid IN $user_id_set";
$result = db_query($sql, $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)){
$name[$row['user_id']] = $row['user_name'];
}
for($i=0; $i<count($rowset); $i++){
$rowset[$i]['user_name'] = empty($name[$rowset[$i]['user_id']]) ? '???' : $name[$rowset[$i]['user_id']];
}
 
return $rowset;
}
 
// Group table synchronisation
function udb_synchronize_groups()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$result = db_query("SELECT groupid, title FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_GROUP_TABLE." WHERE 1", $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)){
$WBB_groups[$row['groupid']] = $row['title'];
}
mysql_free_result($result);
 
$result=db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE 1");
while ($row = mysql_fetch_array($result)){
$cpg_groups[$row['group_id']] = $row['group_name'];
}
mysql_free_result($result);
 
// Scan Coppermine groups that need to be deleted
foreach($cpg_groups as $c_group_id => $c_group_name){
if ((!isset($WBB_groups[$c_group_id]))) {
db_query("DELETE FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = '".$c_group_id."' LIMIT 1");
unset($cpg_groups[$c_group_id]);
}
}
 
// Scan Woltlab Board groups that need to be created inside Coppermine table
foreach($WBB_groups as $i_group_id => $i_group_name){
if ((!isset($cpg_groups[$i_group_id]))) {
db_query("INSERT INTO {$CONFIG['TABLE_USERGROUPS']} (group_id, group_name) VALUES ('$i_group_id', '".addslashes($i_group_name)."')");
$cpg_groups[$i_group_id] = $i_group_name;
}
}
 
// Update Group names
foreach($WBB_groups as $i_group_id => $i_group_name){
if ($cpg_groups[$i_group_id] != $i_group_name) {
db_query("UPDATE {$CONFIG['TABLE_USERGROUPS']} SET group_name = '".addslashes($i_group_name)."' WHERE group_id = '$i_group_id' LIMIT 1");
}
}
}
 
// Retrieve the album list used in gallery admin mode
function udb_get_admin_album_list()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID, $FORBIDDEN_SET;
 
if (UDB_CAN_JOIN_TABLES) {
$sql = "SELECT aid, CONCAT('(', username, ') ', a.title) AS title ".
"FROM {$CONFIG['TABLE_ALBUMS']} AS a ".
"INNER JOIN ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." AS u ON category = (".FIRST_USER_CAT." + userid) ".
"ORDER BY title";
return $sql;
} else {
$sql = "SELECT aid, IF(category > ".FIRST_USER_CAT.", CONCAT('* ', title), CONCAT(' ', title)) AS title ".
"FROM {$CONFIG['TABLE_ALBUMS']} ".
"ORDER BY title";
return $sql;
}
}
 
function udb_util_filloptions()
{
global $albumtbl, $picturetbl, $categorytbl, $lang_util_php, $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$usertbl = $UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE;
 
if (UDB_CAN_JOIN_TABLES) {
 
$query = "SELECT aid, category, IF(username IS NOT NULL, CONCAT('(', username, ') ', a.title), CONCAT(' - ', a.title)) AS title " . "FROM $albumtbl AS a " . "LEFT JOIN $usertbl AS u ON category = (" . FIRST_USER_CAT . " + userid) " . "ORDER BY category, title";
$result = db_query($query, $UDB_DB_LINK_ID);
// $num=mysql_numrows($result);
echo '<select size="1" name="albumid">';
 
while ($row = mysql_fetch_array($result)) {
$sql = "SELECT name FROM $categorytbl WHERE cid = " . $row["category"];
$result2 = db_query($sql);
$row2 = mysql_fetch_array($result2);
 
print "<option value=\"" . $row["aid"] . "\">" . $row2["name"] . $row["title"] . "</option>\n";
}
 
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
} else {
 
// Query for list of public albums
 
$public_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " ORDER BY title");
 
if (mysql_num_rows($public_albums)) {
$public_result = db_fetch_rowset($public_albums);
} else {
$public_result = array();
}
 
// Initialize $merged_array
$merged_array = array();
 
// Count the number of albums returned.
$end = count($public_result);
 
// Cylce through the User albums.
for($i=0;$i<$end;$i++) {
 
//Create a new array sow we may sort the final results.
$merged_array[$i]['id'] = $public_result[$i]['aid'];
$merged_array[$i]['album_name'] = $public_result[$i]['title'];
 
// Query the database to get the category name.
$vQuery = "SELECT name, parent FROM " . $CONFIG['TABLE_CATEGORIES'] . " WHERE cid='" . $public_result[$i]['category'] . "'";
$vRes = mysql_query($vQuery);
$vRes = mysql_fetch_array($vRes);
if (isset($merged_array[$i]['username_category'])) {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '').$merged_array[$i]['username_category'];
} else {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '');
}
 
}
 
// We transpose and divide the matrix into columns to prepare it for use in array_multisort().
foreach ($merged_array as $key => $row) {
$aid[$key] = $row['id'];
$title[$key] = $row['album_name'];
$album_lineage[$key] = $row['username_category'];
}
 
// We sort all columns in descending order and plug in $album_menu at the end so it is sorted by the common key.
array_multisort($album_lineage, SORT_ASC, $title, SORT_ASC, $aid, SORT_ASC, $merged_array);
 
// Query for list of user albums
 
$user_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category >= " . FIRST_USER_CAT . " ORDER BY aid");
if (mysql_num_rows($user_albums)) {
$user_albums_list = db_fetch_rowset($user_albums);
} else {
$user_albums_list = array();
}
 
// Query for list of user IDs and names
 
$user_album_ids_and_names = db_query("SELECT (userid + ".FIRST_USER_CAT.") as id, CONCAT('(', username, ') ') as name FROM $usertbl ORDER BY name ASC",$UDB_DB_LINK_ID);
 
if (mysql_num_rows($user_album_ids_and_names)) {
$user_album_ids_and_names_list = db_fetch_rowset($user_album_ids_and_names);
} else {
$user_album_ids_and_names_list = array();
}
 
// Glue what we've got together.
 
// Initialize $udb_i as a counter.
if (count($merged_array)) {
$udb_i = count($merged_array);
} else {
$udb_i = 0;
}
 
//Begin a set of nested loops to merge the various query results.
foreach ($user_albums_list as $aq) {
foreach ($user_album_ids_and_names_list as $uq) {
if ($aq['category'] == $uq['id']) {
$merged_array[$udb_i]['id']= $aq['category'];
$merged_array[$udb_i]['album_name']= $aq['title'];
$merged_array[$udb_i]['username_category']= $uq['name'];
$udb_i++;
}
}
}
 
// The user albums and public albums have been merged into one list. Print the dropdown.
echo '<select size="1" name="albumid">';
 
foreach ($merged_array as $menu_item) {
 
echo "<option value=\"" . $menu_item['id'] . "\">" . (isset($menu_item['username_category']) ? $menu_item['username_category'] : '') . $menu_item['album_name'] . "</option>\n";
 
}
 
// Close list, etc.
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
}
 
}
 
// ------------------------------------------------------------------------- //
 
// Define wheter we can join tables or not in SQL queries (same host & same db or user)
define('UDB_CAN_JOIN_TABLES', (WBB_BD_HOST == $CONFIG['dbserver'] && (WBB_DB_NAME == $CONFIG['dbname'] || WBB_DB_USERNAME == $CONFIG['dbuser'])));
 
// Connect to Woltlab Board Database if necessary
$UDB_DB_LINK_ID = 0;
$UDB_DB_NAME_PREFIX = WBB_DB_NAME ? '`'.WBB_DB_NAME.'`.' : '';
if (!UDB_CAN_JOIN_TABLES) {
$UDB_DB_LINK_ID = @mysql_connect(WBB_BD_HOST, WBB_DB_USERNAME, WBB_DB_PASSWORD);
if (!$UDB_DB_LINK_ID) die("<b>Coppermine critical error</b>:<br />Unable to connect to Woltlab Board database !<br /><br />MySQL said: <b>".mysql_error()."</b>");
}
?>
/web/test/gallery/cpg133/bridge/yabbse.inc.php
0,0 → 1,585
<?php
/*************************
Coppermine Photo Gallery
************************
Copyright (c) 2003-2005 Coppermine Dev Team
v1.1 originaly written by Gregory DEMAR
 
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.
********************************************
Coppermine version: 1.3.3
$Source: /cvsroot/coppermine/stable/bridge/yabbse.inc.php,v $
$Revision: 1.9 $
$Author: gaugau $
$Date: 2005/04/19 03:17:13 $
**********************************************/
// ------------------------------------------------------------------------- //
// As a special exception, the copyright holders of Coppermine Photo Gallery //
// give you permission to link Coppermine Photo Gallery with independent //
// modules that communicate with YaBB SE Forum solely through this //
// 'bridge file' interface, regardless of the license terms of YaBB SE, and //
// to copy and distribute the resulting combined work under terms of your //
// choice, provided that every copy of the combined work is accompanied by a //
// complete copy of the source code of Coppermine Photo Gallery (the version //
// of Coppermine Photo Gallery used to produce the combined work), being //
// distributed under the terms of the GNU General Public License plus this //
// exception. An independent module is a module which is not derived from //
// or based on Coppermine Photo Gallery. //
// //
// Note that people who make modified versions of Coppermine Photo Gallery //
// are not obligated to grant this special exception for their modified //
// versions; it is their choice whether to do so. The GNU General Public //
// License gives permission to release a modified version without this //
// exception; this exception also makes it possible to release a modified //
// version which carries forward this exception. //
// ------------------------------------------------------------------------- //
// YaBB SE 1.5.4 Integration for Coppermine //
// ------------------------------------------------------------------------- //
// Modify the value below according to your Board installation //
// ------------------------------------------------------------------------- //
 
// Set this to the location of your Settings file
require_once("../yabbse/Settings.php");
 
// ------------------------------------------------------------------------- //
// Nothing to edit below this line
// ------------------------------------------------------------------------- //
 
// other includes
require_once("$sourcedir/Load.php");
require_once("$sourcedir/Security.php");
// database configuration
define('YS_DB_NAME', $db_name); // The name of the database used by the board
define('YS_DB_HOST', $db_server); // The name of the database server
define('YS_DB_USERNAME', $db_user); // The username to use to connect to the database
define('YS_DB_PASSWORD', $db_passwd); // The password to use to connect to the database
 
// The web path to your YaBB SE Board directory
// In this example http://yoursite_name.com/yabbse/
define('YS_WEB_PATH', "$boardurl/");
// The Name of the Cookie used for YaBBSE logon
define('YS_COOKIE_NAME', $cookiename);
// Prefix for the database tables
define('YS_TABLE_PREFIX', $db_prefix); // Table Prefix
 
// Names for the database tables
define('YS_USER_TABLE', 'members'); // The members table
define('YS_GROUP_TABLE', 'membergroups'); // The groups table
 
// Group definitions (default values used by the board)
define('YS_GMOD_GROUP', 5);
define('YS_BANNED_GROUP', 4);
define('YS_GUEST_GROUP', 3);
define('YS_MEMBERS_GROUP', 2);
define('YS_ADMIN_GROUP', 1);
 
define('CM_ADMIN_GROUP_NAME', 'Administrators');
define('CM_MEMBERS_GROUP_NAME', 'Registered');
define('CM_GUEST_GROUP_NAME', 'Anonymous');
define('CM_BANNED_GROUP_NAME', 'Banned');
define('CM_GMOD_GROUP_NAME', 'Global Moderators');
 
define('YS_PASSWD_SEED', 'ys');
 
if (function_exists('session_start') && (!session_id()))
session_start();
 
function database_error($file="", $line="") {
global $CONFIG;
 
if (!$CONFIG['debug_mode']) {
cpg_die(CRITICAL_ERROR, 'There was an error while processing a database query', $file, $line);
} else {
$the_error = "\n\nmySQL error: ".mysql_error()."\n";
$out = "<br />There was an error while processing a database query.<br /><br/>" .
"<form name='mysql'><textarea rows=\"8\" cols=\"60\">".htmlspecialchars($the_error)."</textarea></form>";
cpg_die(CRITICAL_ERROR, $out, $file, $line);
}
}
 
function cm_banning()
{
global $txt, $settings, $username, $REMOTE_ADDR, $db_prefix, $UDB_DB_NAME_PREFIX;
// ALL TYPES OF BANNING AT ONCE (SpeedUpBoardIndex mod)
$remote_ip = $REMOTE_ADDR;
$ipparts = explode(".", $REMOTE_ADDR);
$registeredUserString = ($username != 'Guest' ? "OR (type='email' AND value='$settings[2]') OR (type='username' AND value='$username')" : '');
$request = mysql_query("SELECT value FROM {$db_prefix}banned WHERE (type='ip' AND (value='$remote_ip' OR value='$ipparts[0].$ipparts[1].$ipparts[2].*' OR value='$ipparts[0].$ipparts[1].*.*')) $registeredUserString;") or database_error(__FILE__, __LINE__);
if (mysql_num_rows($request) != 0) {
$registeredUserString2 = ($username != 'Guest' ? ',email' : '');
$registeredUserString3 = ($username != 'Guest' ? ",'$settings[2]'" : '');
$request = mysql_query("INSERT INTO {$db_prefix}log_banned (ip $registeredUserString2,logTime) VALUES ('$remote_ip' $registeredUserString3," . time() . ");") or database_error(__FILE__, __LINE__);
$username = "Guest";
cpg_die(ERROR, "You are BANNED, go away!", __FILE__, __LINE__);
return;
}
}
// Authenticate a user using cookies
function udb_authenticate()
{
global $HTTP_COOKIE_VARS, $USER_DATA, $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
global $HTTP_SERVER_VARS, $HTTP_X_FORWARDED_FOR, $HTTP_PROXY_USER, $REMOTE_ADDR;
global $password, $username, $pwseed, $settings, $ID_MEMBER, $realname, $txt;
 
$pwseed = YS_PASSWD_SEED;
 
LoadCookie();
LoadUserSettings();
cm_banning();
// For error checking
$CONFIG['TABLE_USERS'] = '**ERROR**';
// Permissions for a default group
$default_group = array('group_id' => YS_GUEST_GROUP,
'group_name' => CM_GUEST_GROUP_NAME,
'has_admin_access' => 0,
'can_see_all_albums' => 0,
'can_send_ecards' => 0,
'can_rate_pictures' => 0,
'can_post_comments' => 0,
'can_upload_pictures' => 0,
'can_create_albums' => 0,
'pub_upl_need_approval' => 1,
'priv_upl_need_approval' => 1,
'upload_form_config' => 0,
'custom_user_upload' => 0,
'num_file_upload' => 0,
'num_URI_upload' => 0,
);
// get first 50 chars
$HTTP_USER_AGENT = substr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 0, 50);
$REMOTE_ADDR = substr($HTTP_SERVER_VARS['REMOTE_ADDR'], 0, 50);
 
/* If the user is a guest, initialize all the critial user settings */
if ($username == '' || $username == 'Guest') {
$result = db_query("SELECT * FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = " . YS_GUEST_GROUP);
if (!mysql_num_rows($result)) {
$USER_DATA = $default_group;
} else {
$USER_DATA = mysql_fetch_array($result);
}
 
$USER_DATA['has_admin_access']=0;
$USER_DATA['can_see_all_albums'] =0;
$USER_DATA['groups'] = array(YS_GUEST_GROUP);
 
define('USER_ID', 0);
define('USER_NAME', 'Anonymous');
define('USER_GROUP_SET', '(' . YS_GUEST_GROUP . ')');
define('USER_IS_ADMIN', 0);
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', 0);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
mysql_free_result($result);
} else {
if ($settings[7] == 'Administrator' || $settings[7] == 'Global Moderator')
$cm_group_id = ($settings[7] == 'Administrator') ? YS_ADMIN_GROUP : YS_GMOD_GROUP;
if ($settings[7] == '') $cm_group_id = YS_MEMBERS_GROUP;
 
if (!$cm_group_id) {
$sql = "SELECT group_id " . "FROM {$CONFIG['TABLE_USERGROUPS']} " . "WHERE group_name = '" . $settings[7] . "'";
$result = db_query($sql);
if (mysql_num_rows($result)) {
$temp = mysql_fetch_array($result);
$cm_group_id = $temp[0];
} else {
$cm_group_id = YS_MEMBERS_GROUP;
}
}
// Retrieve group information
$sql = "SELECT * " . "FROM {$CONFIG['TABLE_USERGROUPS']} " . "WHERE group_id = '" . $cm_group_id . "'";
$result = db_query($sql);
if (mysql_num_rows($result)) {
$USER_DATA = mysql_fetch_assoc($result);
} else {
$USER_DATA = $default_group;
}
if (get_magic_quotes_gpc() == 0) {
$realname = mysql_escape_string($realname);
$USER_DATA['group_name'] = mysql_escape_string($USER_DATA['group_name']);
}
 
$USER_DATA['has_admin_access']= ($settings[7]== YS_ADMIN_GROUP);
$USER_DATA['can_see_all_albums'] = $USER_DATA['has_admin_access'];
$USER_DATA['groups'] = array($USER_DATA['group_id']);
 
define('USER_ID', $ID_MEMBER);
define('USER_NAME', $realname);
define('YSE_USER_NAME', $username);
define('USER_GROUP', $USER_DATA['group_name']);
define('USER_GROUP_SET', '(' . $USER_DATA['group_id'] . ')');
define('USER_IS_ADMIN', ($settings[7] == 'Administrator'));
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
mysql_free_result($result);
}
}
// Retrieve the name of a user
function udb_get_user_name($uid)
{
global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
 
$sql = "SELECT realName as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . YS_TABLE_PREFIX . YS_USER_TABLE . " " . "WHERE ID_MEMBER = '$uid'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_name'];
} else {
return '';
}
}
// Retrieve the name of a user (Added to fix banning w/ bb integration - Nibbler)
function udb_get_user_id($username)
{
global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
 
$username = addslashes($username);
 
$sql = "SELECT ID_MEMBER as user_id " . "FROM " . $UDB_DB_NAME_PREFIX . YS_TABLE_PREFIX . YS_USER_TABLE . " " . "WHERE realName = '$username'";
 
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row['user_id'];
} else {
return '';
}
}
 
// Redirect
function udb_redirect($target)
{
header('Location: ' . YS_WEB_PATH . $target);
exit;
}
 
// Register
function udb_register_page()
{
$target = 'index.php?action=register';
udb_redirect($target);
}
// Login
function udb_login_page()
{
$target = 'index.php?action=login';
udb_redirect($target);
}
// Logout
function udb_logout_page()
{
$target = 'index.php?&action=logout;sesc=' . session_id();
udb_redirect($target);
}
// Edit users
function udb_edit_users()
{
$target = 'index.php';
udb_redirect($target);
}
// Get user information
function udb_get_user_infos($uid)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
global $lang_register_php;
 
$sql = "SELECT realName as user_name, memberGroup as group_name, emailAddress as user_email, dateRegistered as user_regdate, " . "websiteURL as user_website " . "FROM " . $UDB_DB_NAME_PREFIX . YS_TABLE_PREFIX . YS_USER_TABLE . " " . "WHERE ID_MEMBER = '$uid'";
$result = db_query($sql, $UDB_DB_LINK_ID);
 
if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_register_php['err_unk_user'], __FILE__, __LINE__);
$user_data = mysql_fetch_array($result);
mysql_free_result($result);
 
$user_data['mgroup'] = '';
$user_data['user_occupation'] = '';
$user_data['user_location'] = '';
$user_data['user_interests'] = '';
 
if ($user_data['group_name'] == 'Administrator') {
$user_data['mgroup'] = YS_ADMIN_GROUP;
} else if ($user_data['group_name'] == 'Global Moderator') {
$user_data['mgroup'] = YS_GMOD_GROUP;
} else if ($user_data['group_name'] == '') {
$user_data['mgroup'] = YS_MEMBERS_GROUP;
} else {
$sql = "SELECT ID_GROUP as mgroup " . "FROM " . $UDB_DB_NAME_PREFIX . YS_TABLE_PREFIX . YS_GROUP_TABLE . " " . "WHERE membergroup = '{$user_data['group_name']}' ";
$result = db_query($sql);
 
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
$user_data['mgroup'] = $row['mgroup'];
} else {
$user_data['mgroup'] = YS_MEMBERS_GROUP;
}
mysql_free_result($result);
}
 
return $user_data;
}
// Edit user profile
function udb_edit_profile($uid)
{
$target = 'index.php?action=profile;user=' . YSE_USER_NAME;
udb_redirect($target);
}
// Query used to list users
function udb_list_users_query(&$user_count)
{
global $CONFIG, $FORBIDDEN_SET;
 
if ($FORBIDDEN_SET != "") $forbidden = "AND $FORBIDDEN_SET";
$sql = "SELECT (category - " . FIRST_USER_CAT . ") as user_id," . " '???' as user_name," . " COUNT(DISTINCT a.aid) as alb_count," . " COUNT(DISTINCT pid) as pic_count," . " MAX(pid) as thumb_pid " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.aid = a.aid " . "WHERE approved = 'YES' AND category > " . FIRST_USER_CAT . " $forbidden GROUP BY category " . "ORDER BY category ";
$result = db_query($sql);
 
$user_count = mysql_num_rows($result);
 
return $result;
}
 
function udb_list_users_retrieve_data($result, $lower_limit, $count)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
mysql_data_seek($result, $lower_limit);
 
$rowset = array();
$i = 0;
$user_id_set = '';
 
while (($row = mysql_fetch_array($result)) && ($i++ < $count)) {
$user_id_set .= $row['user_id'] . ',';
$rowset[] = $row;
}
mysql_free_result($result);
 
$user_id_set = '(' . substr($user_id_set, 0, -1) . ')';
$sql = "SELECT ID_MEMBER as user_id, realName as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . YS_TABLE_PREFIX . YS_USER_TABLE . " " . "WHERE ID_MEMBER IN $user_id_set";
$result = db_query($sql, $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$name[$row['user_id']] = $row['user_name'];
}
for($i = 0; $i < count($rowset); $i++) {
$rowset[$i]['user_name'] = empty($name[$rowset[$i]['user_id']]) ? '???' : $name[$rowset[$i]['user_id']];
}
 
return $rowset;
}
// Group table synchronisation
function udb_synchronize_groups()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$result = db_query("SELECT ID_GROUP as usergroupid, membergroup as title FROM " . $UDB_DB_NAME_PREFIX . YS_TABLE_PREFIX . YS_GROUP_TABLE . " WHERE grouptype=1", $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$YS_groups[$row['title']] = $row['usergroupid'];
}
mysql_free_result($result);
 
$YS_groups[CM_ADMIN_GROUP_NAME] = YS_ADMIN_GROUP;
$YS_groups[CM_MEMBERS_GROUP_NAME] = YS_MEMBERS_GROUP;
$YS_groups[CM_GUEST_GROUP_NAME] = YS_GUEST_GROUP;
$YS_groups[CM_BANNED_GROUP_NAME] = YS_BANNED_GROUP;
$YS_groups[CM_GMOD_GROUP_NAME] = YS_GMOD_GROUP;
 
$result = db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE 1");
while ($row = mysql_fetch_array($result)) {
$cpg_groups[$row['group_name']] = $row['group_id'];
}
mysql_free_result($result);
// Scan Coppermine groups that need to be deleted
foreach($cpg_groups as $c_group_name => $c_group_id) {
if ((!isset($YS_groups[$c_group_name]))) {
db_query("DELETE FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = '" . $c_group_id . "' LIMIT 1");
unset($cpg_groups[$c_group_name]);
}
}
// Scan Board groups that need to be created inside Coppermine table
foreach($YS_groups as $i_group_name => $i_group_id) {
if ((!isset($cpg_groups[$i_group_name]))) {
db_query("INSERT INTO {$CONFIG['TABLE_USERGROUPS']} (group_id, group_name) VALUES ('$i_group_id', '" . addslashes($i_group_name) . "')");
$cpg_groups[$i_group_name] = $i_group_id;
}
}
// Update Group names -- Can't be done with YSE
// foreach($YS_groups as $i_group_id => $i_group_name){
// if ($cpg_groups[$i_group_id] != $i_group_name) {
// db_query("UPDATE {$CONFIG['TABLE_USERGROUPS']} SET group_name = '".addslashes($i_group_name)."' WHERE group_id = '$i_group_id' LIMIT 1");
// }
// }
}
// Retrieve the album list used in gallery admin mode
function udb_get_admin_album_list()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID, $FORBIDDEN_SET;
 
if (UDB_CAN_JOIN_TABLES) {
$sql = "SELECT aid, CONCAT('(', realName, ') ', a.title) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN " . $UDB_DB_NAME_PREFIX . YS_TABLE_PREFIX . YS_USER_TABLE . " AS u ON category = (" . FIRST_USER_CAT . " + ID_MEMBER) " . "ORDER BY title";
return $sql;
} else {
$sql = "SELECT aid, IF(category > " . FIRST_USER_CAT . ", CONCAT('* ', title), CONCAT(' ', title)) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} " . "ORDER BY title";
return $sql;
}
}
 
function udb_util_filloptions()
{
global $albumtbl, $picturetbl, $categorytbl, $lang_util_php, $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
 
$usertbl = $UDB_DB_NAME_PREFIX.YS_TABLE_PREFIX.YS_USER_TABLE;
 
if (UDB_CAN_JOIN_TABLES) {
 
$query = "SELECT aid, category, IF(realName IS NOT NULL, CONCAT('(', realName, ') ', a.title), CONCAT(' - ', a.title)) AS title " . "FROM $albumtbl AS a " . "LEFT JOIN $usertbl AS u ON category = (" . FIRST_USER_CAT . " + ID_MEMBER) " . "ORDER BY category, title";
$result = db_query($query, $UDB_DB_LINK_ID);
// $num=mysql_numrows($result);
echo '<select size="1" name="albumid">';
 
while ($row = mysql_fetch_array($result)) {
$sql = "SELECT name FROM $categorytbl WHERE cid = " . $row["category"];
$result2 = db_query($sql);
$row2 = mysql_fetch_array($result2);
 
print "<option value=\"" . $row["aid"] . "\">" . $row2["name"] . $row["title"] . "</option>\n";
}
 
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
} else {
 
// Query for list of public albums
 
$public_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " ORDER BY title");
 
if (mysql_num_rows($public_albums)) {
$public_result = db_fetch_rowset($public_albums);
} else {
$public_result = array();
}
 
// Initialize $merged_array
$merged_array = array();
 
// Count the number of albums returned.
$end = count($public_result);
 
// Cylce through the User albums.
for($i=0;$i<$end;$i++) {
 
//Create a new array sow we may sort the final results.
$merged_array[$i]['id'] = $public_result[$i]['aid'];
$merged_array[$i]['album_name'] = $public_result[$i]['title'];
 
// Query the database to get the category name.
$vQuery = "SELECT name, parent FROM " . $CONFIG['TABLE_CATEGORIES'] . " WHERE cid='" . $public_result[$i]['category'] . "'";
$vRes = mysql_query($vQuery);
$vRes = mysql_fetch_array($vRes);
if (isset($merged_array[$i]['username_category'])) {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '').$merged_array[$i]['username_category'];
} else {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '');
}
 
}
 
// We transpose and divide the matrix into columns to prepare it for use in array_multisort().
foreach ($merged_array as $key => $row) {
$aid[$key] = $row['id'];
$title[$key] = $row['album_name'];
$album_lineage[$key] = $row['username_category'];
}
 
// We sort all columns in descending order and plug in $album_menu at the end so it is sorted by the common key.
array_multisort($album_lineage, SORT_ASC, $title, SORT_ASC, $aid, SORT_ASC, $merged_array);
 
// Query for list of user albums
 
$user_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category >= " . FIRST_USER_CAT . " ORDER BY aid");
if (mysql_num_rows($user_albums)) {
$user_albums_list = db_fetch_rowset($user_albums);
} else {
$user_albums_list = array();
}
 
// Query for list of user IDs and names
 
$user_album_ids_and_names = db_query("SELECT (ID_MEMBER + ".FIRST_USER_CAT.") as id, CONCAT('(', realName, ') ') as name FROM $usertbl ORDER BY name ASC",$UDB_DB_LINK_ID);
 
if (mysql_num_rows($user_album_ids_and_names)) {
$user_album_ids_and_names_list = db_fetch_rowset($user_album_ids_and_names);
} else {
$user_album_ids_and_names_list = array();
}
 
// Glue what we've got together.
 
// Initialize $udb_i as a counter.
if (count($merged_array)) {
$udb_i = count($merged_array);
} else {
$udb_i = 0;
}
 
//Begin a set of nested loops to merge the various query results.
foreach ($user_albums_list as $aq) {
foreach ($user_album_ids_and_names_list as $uq) {
if ($aq['category'] == $uq['id']) {
$merged_array[$udb_i]['id']= $aq['category'];
$merged_array[$udb_i]['album_name']= $aq['title'];
$merged_array[$udb_i]['username_category']= $uq['name'];
$udb_i++;
}
}
}
 
// The user albums and public albums have been merged into one list. Print the dropdown.
echo '<select size="1" name="albumid">';
 
foreach ($merged_array as $menu_item) {
 
echo "<option value=\"" . $menu_item['id'] . "\">" . (isset($menu_item['username_category']) ? $menu_item['username_category'] : '') . $menu_item['album_name'] . "</option>\n";
 
}
 
// Close list, etc.
print '</select> (3)';
print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
print '</form>';
 
}
 
}
 
// ------------------------------------------------------------------------- //
// Define wheter we can join tables or not in SQL queries (same host & same db or user)
define('UDB_CAN_JOIN_TABLES', (YS_DB_HOST == $CONFIG['dbserver'] && (YS_DB_NAME == $CONFIG['dbname'] || YS_DB_USERNAME == $CONFIG['dbuser'])));
// Connect to YaBB SE Database if necessary
$UDB_DB_LINK_ID = 0;
$UDB_DB_NAME_PREFIX = YS_DB_NAME ? '`' . YS_DB_NAME . '`.' : '';
if (!UDB_CAN_JOIN_TABLES) {
$UDB_DB_LINK_ID = @mysql_connect(YS_DB_HOST, YS_DB_USERNAME, YS_DB_PASSWORD);
if (!$UDB_DB_LINK_ID) die("<b>Coppermine critical error</b>:<br />Unable to connect to YaBB SE Board database !<br /><br />MySQL said: <b>" . mysql_error() . "</b>");
}
 
?>