Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
<?php
2
/*************************
3
  Coppermine Photo Gallery
4
  ************************
5
  Copyright (c) 2003-2005 Coppermine Dev Team
6
  v1.1 originaly written by Gregory DEMAR
7
 
8
  This program is free software; you can redistribute it and/or modify
9
  it under the terms of the GNU General Public License as published by
10
  the Free Software Foundation; either version 2 of the License, or
11
  (at your option) any later version.
12
  ********************************************
13
  Coppermine version: 1.3.3
14
  $Source: /cvsroot/coppermine/stable/bridge/vbulletin30.inc.php,v $
15
  $Revision: 1.8 $
16
  $Author: gaugau $
17
  $Date: 2005/04/19 03:17:13 $
18
**********************************************/
19
// ------------------------------------------------------------------------- //
20
// vBulletin 3.0 Integration for Coppermine                                  //
21
// ------------------------------------------------------------------------- //
22
// Modify the values below according to your Board installation              //
23
// ------------------------------------------------------------------------- //
24
// database configuration
25
 
26
//NOTE : Your vBulletin license number is provided at the top of every php file in your vBulletin installation!
27
define('VB_CUST_NO', 'xxxxxxxx'); // Your vBulletin license number (NOT your customer number)
28
define('VB_DB_NAME', 'forum'); // The name of the database used by the board
29
define('VB_BD_HOST', 'localhost'); // The name of the database server
30
define('VB_DB_USERNAME', 'username'); // The username to use to connect to the database
31
define('VB_DB_PASSWORD', 'password'); // The password to use to connect to the database
32
 
33
// The web path to your vBulletin Board directory
34
// In this example http://yoursite_name.com/vbulletin3/
35
define('VB_WEB_PATH', '/vbulletin3/');
36
// ------------------------------------------------------------------------- //
37
// Nothing to edit below this line
38
// ------------------------------------------------------------------------- //
39
// Prefix and names for the database tables
40
define('VB_TABLE_PREFIX', ''); // Leave empty, not supported by vBulletin 2.3
41
define('VB_USER_TABLE', 'user'); // The members table
42
define('VB_SESSION_TABLE', 'session'); // The sessions table
43
define('VB_GROUP_TABLE', 'usergroup'); // The groups table
44
define('VB_COOKIE_PREFIX', '');  // Cookie Prefix, not supported by vBulletin 2
45
 
46
// Group definitions (default values used by the board)
47
define('VB_VALIDATING_GROUP', 3);
48
define('VB_GUEST_GROUP', 1);
49
define('VB_MEMBERS_GROUP', 2);
50
define('VB_ADMIN_GROUP', 6);
51
// Authenticate a user using cookies
52
function udb_authenticate()
53
{
54
    global $HTTP_COOKIE_VARS, $USER_DATA, $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
55
    global $HTTP_SERVER_VARS, $HTTP_X_FORWARDED_FOR, $HTTP_PROXY_USER, $REMOTE_ADDR;
56
    // For error checking
57
    $CONFIG['TABLE_USERS'] = '**ERROR**';
58
    // Permissions for a default group
59
    $default_group = array('group_id' => VB_GUEST_GROUP,
60
        'group_name' => 'Unknown',
61
        'has_admin_access' => 0,
62
        'can_see_all_albums' => 0,
63
        'can_send_ecards' => 0,
64
        'can_rate_pictures' => 0,
65
        'can_post_comments' => 0,
66
        'can_upload_pictures' => 0,
67
        'can_create_albums' => 0,
68
        'pub_upl_need_approval' => 1,
69
        'priv_upl_need_approval' => 1,
70
        'upload_form_config' => 0,
71
        'custom_user_upload' => 0,
72
        'num_file_upload' => 0,
73
        'num_URI_upload' => 0,
74
        );
75
    // get first 50 chars
76
    $HTTP_USER_AGENT = substr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 0, 50);
77
    $REMOTE_ADDR = substr($HTTP_SERVER_VARS['REMOTE_ADDR'], 0, 50);
78
 
79
    if (is_array($HTTP_COOKIE_VARS)) {
80
        $sessionhash = isset($HTTP_COOKIE_VARS[VB_COOKIE_PREFIX . 'sessionhash']) ? $HTTP_COOKIE_VARS[VB_COOKIE_PREFIX . 'sessionhash'] : '';
81
        $bbuserid = isset($HTTP_COOKIE_VARS[VB_COOKIE_PREFIX . 'userid']) ? $HTTP_COOKIE_VARS[VB_COOKIE_PREFIX . 'userid'] : 0;
82
        $bbpassword = isset($HTTP_COOKIE_VARS[VB_COOKIE_PREFIX . 'password']) ? $HTTP_COOKIE_VARS[VB_COOKIE_PREFIX . 'password'] : '';
83
    }
84
 
85
    $got_user = 0;
86
 
87
    if ($bbuserid && $bbpassword) {
88
        // If userid and password exist in cookies we use them to login
89
        $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) . "'";
90
        $result = db_query($sql, $UDB_DB_LINK_ID);
91
        if (mysql_num_rows($result)) {
92
            $USER_DATA = mysql_fetch_array($result);
93
            if (md5($USER_DATA['password'] . VB_CUST_NO) == $bbpassword) {
94
                $got_user = 1;
95
            }
96
        }
97
    } elseif ($sessionhash) {
98
        // session hash exists
99
        // validate it:
100
        if (isset($HTTP_SERVER_VARS['HTTP_CLIENT_IP']))
101
        {
102
            $alt_ip =  $HTTP_SERVER_VARS['HTTP_CLIENT_IP'];
103
        }
104
        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))
105
        {
106
            $alt_ip = $matches[0];
107
        }
108
        elseif (isset($HTTP_SERVER_VARS['HTTP_FROM']))
109
        {
110
            $alt_ip = $HTTP_SERVER_VARS['HTTP_FROM'];
111
        }
112
        else
113
        {
114
            $alt_ip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
115
        }
116
        $idhash = md5($HTTP_SERVER_VARS['HTTP_USER_AGENT'] . $alt_ip );
117
 
118
        $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) . "'";
119
 
120
        $result = db_query($sql, $UDB_DB_LINK_ID);
121
 
122
        if (mysql_num_rows($result)) {
123
            // session hash exists
124
            $session_data = mysql_fetch_array($result);
125
            mysql_free_result($result);
126
 
127
            $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'] . "'";
128
            $result = db_query($sql, $UDB_DB_LINK_ID);
129
            if (mysql_num_rows($result)) {
130
                $USER_DATA = mysql_fetch_array($result);
131
                $got_user = 1;
132
            }
133
        }
134
    }
135
 
136
    if ($got_user) {
137
        mysql_free_result($result);
138
 
139
        define('USER_ID', (int)$USER_DATA['user_id']);
140
        define('USER_NAME', $USER_DATA['user_name']);
141
        // Retrieve group information
142
        $sql = "SELECT * " . "FROM {$CONFIG['TABLE_USERGROUPS']} " . "WHERE group_id = '{$USER_DATA['mgroup']}'";
143
        $result = db_query($sql);
144
        if (mysql_num_rows($result)) {
145
            $USER_DATA2 = mysql_fetch_array($result);
146
        } else {
147
            $USER_DATA2 = $default_group;
148
        }
149
 
150
        $USER_DATA = array_merge($USER_DATA, $USER_DATA2);
151
 
152
                $USER_DATA['has_admin_access']= ($USER_DATA['mgroup'] == VB_ADMIN_GROUP);
153
                $USER_DATA['can_see_all_albums'] = $USER_DATA['has_admin_access'];
154
                $USER_DATA['groups'] = array($USER_DATA['group_id']);
155
 
156
        define('USER_GROUP', $USER_DATA['group_name']);
157
        define('USER_GROUP_SET', '(' . $USER_DATA['group_id'] . ')');
158
        define('USER_IS_ADMIN', ($USER_DATA['mgroup'] == VB_ADMIN_GROUP));
159
        define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
160
        define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
161
        define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
162
        define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
163
        define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
164
        define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
165
        define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
166
        define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
167
        define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
168
        mysql_free_result($result);
169
    } else {
170
        $result = db_query("SELECT * FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = " . VB_GUEST_GROUP);
171
        if (!mysql_num_rows($result)) {
172
            $USER_DATA = $default_group;
173
        } else {
174
            $USER_DATA = mysql_fetch_array($result);
175
        }
176
 
177
        $USER_DATA['groups'] = array(VB_GUEST_GROUP);
178
 
179
        define('USER_ID', 0);
180
        define('USER_NAME', 'Anonymous');
181
        define('USER_GROUP_SET', '(' . VB_GUEST_GROUP . ')');
182
        define('USER_IS_ADMIN', 0);
183
        define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
184
        define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
185
        define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
186
        define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
187
        define('USER_CAN_CREATE_ALBUMS', 0);
188
        define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
189
        define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
190
        define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
191
        define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
192
        mysql_free_result($result);
193
    }
194
}
195
// Retrieve the name of a user
196
function udb_get_user_name($uid)
197
{
198
    global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
199
 
200
    $sql = "SELECT username as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE userid = '$uid'";
201
 
202
    $result = db_query($sql, $UDB_DB_LINK_ID);
203
 
204
    if (mysql_num_rows($result)) {
205
        $row = mysql_fetch_array($result);
206
        mysql_free_result($result);
207
        return $row['user_name'];
208
    } else {
209
        return '';
210
    }
211
}
212
// Retrieve the name of a user (Added to fix banning w/ bb integration - Nibbler)
213
function udb_get_user_id($username)
214
{
215
    global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
216
 
217
    $username = addslashes($username);
218
 
219
    $sql = "SELECT userid as user_id " . "FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_USER_TABLE . " " . "WHERE username = '$username'";
220
 
221
    $result = db_query($sql, $UDB_DB_LINK_ID);
222
 
223
    if (mysql_num_rows($result)) {
224
        $row = mysql_fetch_array($result);
225
        mysql_free_result($result);
226
        return $row['user_id'];
227
    } else {
228
        return '';
229
    }
230
}
231
 
232
// Redirect
233
function udb_redirect($target)
234
{
235
    header('Location: http://' . $_SERVER['HTTP_HOST'] . VB_WEB_PATH . $target);
236
    exit;
237
}
238
 
239
// Register
240
function udb_register_page()
241
{
242
    $target = 'register.php';
243
    udb_redirect($target);
244
}
245
// Login
246
function udb_login_page()
247
{
248
    $target = 'login.php';
249
    udb_redirect($target);
250
}
251
// Logout
252
function udb_logout_page()
253
{
254
    $target = 'login.php?&do=logout';
255
    udb_redirect($target);
256
}
257
// Edit users
258
function udb_edit_users()
259
{
260
    $target = 'admincp/index.php';
261
    udb_redirect($target);
262
}
263
// Get user information
264
function udb_get_user_infos($uid)
265
{
266
    global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
267
    global $lang_register_php;
268
 
269
    $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'";
270
    $result = db_query($sql, $UDB_DB_LINK_ID);
271
 
272
    if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_register_php['err_unk_user'], __FILE__, __LINE__);
273
    $user_data = mysql_fetch_array($result);
274
    mysql_free_result($result);
275
 
276
    $user_data['group_name'] = '';
277
    $user_data['user_occupation'] = '';
278
    $user_data['user_location'] = '';
279
    $user_data['user_interests'] = '';
280
 
281
    $sql = "SELECT group_name " . "FROM {$CONFIG['TABLE_USERGROUPS']} " . "WHERE group_id = {$user_data['mgroup']} ";
282
    $result = db_query($sql);
283
 
284
    if (mysql_num_rows($result)) {
285
        $row = mysql_fetch_array($result);
286
        $user_data['group_name'] = $row['group_name'];
287
    }
288
    mysql_free_result($result);
289
 
290
    return $user_data;
291
}
292
// Edit user profile
293
function udb_edit_profile($uid)
294
{
295
    $target = 'usercp.php';
296
    udb_redirect($target);
297
}
298
// Query used to list users
299
function udb_list_users_query(&$user_count)
300
{
301
    global $CONFIG, $FORBIDDEN_SET;
302
 
303
    if ($FORBIDDEN_SET != "") $forbidden = "AND $FORBIDDEN_SET";
304
    $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 ";
305
    $result = db_query($sql);
306
 
307
    $user_count = mysql_num_rows($result);
308
 
309
    return $result;
310
}
311
 
312
function udb_list_users_retrieve_data($result, $lower_limit, $count)
313
{
314
    global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
315
 
316
    mysql_data_seek($result, $lower_limit);
317
 
318
    $rowset = array();
319
    $i = 0;
320
    $user_id_set = '';
321
 
322
    while (($row = mysql_fetch_array($result)) && ($i++ < $count)) {
323
        $user_id_set .= $row['user_id'] . ',';
324
        $rowset[] = $row;
325
    }
326
    mysql_free_result($result);
327
 
328
    $user_id_set = '(' . substr($user_id_set, 0, -1) . ')';
329
    $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";
330
    $result = db_query($sql, $UDB_DB_LINK_ID);
331
    while ($row = mysql_fetch_array($result)) {
332
        $name[$row['user_id']] = $row['user_name'];
333
    }
334
    for($i = 0; $i < count($rowset); $i++) {
335
        $rowset[$i]['user_name'] = empty($name[$rowset[$i]['user_id']]) ? '???' : $name[$rowset[$i]['user_id']];
336
    }
337
 
338
    return $rowset;
339
}
340
// Group table synchronisation
341
function udb_synchronize_groups()
342
{
343
    global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
344
 
345
    $result = db_query("SELECT usergroupid, title FROM " . $UDB_DB_NAME_PREFIX . VB_TABLE_PREFIX . VB_GROUP_TABLE . " WHERE 1", $UDB_DB_LINK_ID);
346
    while ($row = mysql_fetch_array($result)) {
347
        $VB_groups[$row['usergroupid']] = $row['title'];
348
    }
349
    mysql_free_result($result);
350
 
351
    $result = db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE 1");
352
    while ($row = mysql_fetch_array($result)) {
353
        $cpg_groups[$row['group_id']] = $row['group_name'];
354
    }
355
    mysql_free_result($result);
356
    // Scan Coppermine groups that need to be deleted
357
    foreach($cpg_groups as $c_group_id => $c_group_name) {
358
        if ((!isset($VB_groups[$c_group_id]))) {
359
            db_query("DELETE FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = '" . $c_group_id . "' LIMIT 1");
360
            unset($cpg_groups[$c_group_id]);
361
        }
362
    }
363
    // Scan vBulletin Board groups that need to be created inside Coppermine table
364
    foreach($VB_groups as $i_group_id => $i_group_name) {
365
        if ((!isset($cpg_groups[$i_group_id]))) {
366
            db_query("INSERT INTO {$CONFIG['TABLE_USERGROUPS']} (group_id, group_name) VALUES ('$i_group_id', '" . addslashes($i_group_name) . "')");
367
            $cpg_groups[$i_group_id] = $i_group_name;
368
        }
369
    }
370
    // Update Group names
371
    foreach($VB_groups as $i_group_id => $i_group_name) {
372
        if ($cpg_groups[$i_group_id] != $i_group_name) {
373
            db_query("UPDATE {$CONFIG['TABLE_USERGROUPS']} SET group_name = '" . addslashes($i_group_name) . "' WHERE group_id = '$i_group_id' LIMIT 1");
374
        }
375
    }
376
}
377
// Retrieve the album list used in gallery admin mode
378
function udb_get_admin_album_list()
379
{
380
    global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID, $FORBIDDEN_SET;
381
 
382
    if (UDB_CAN_JOIN_TABLES) {
383
        $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";
384
        return $sql;
385
    } else {
386
        $sql = "SELECT aid, IF(category > " . FIRST_USER_CAT . ", CONCAT('* ', title), CONCAT(' ', title)) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} " . "ORDER BY title";
387
        return $sql;
388
    }
389
}
390
 
391
function udb_util_filloptions()
392
{
393
    global $albumtbl, $picturetbl, $categorytbl, $lang_util_php, $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
394
 
395
    $usertbl = $UDB_DB_NAME_PREFIX.VB_TABLE_PREFIX.VB_USER_TABLE;
396
 
397
    if (UDB_CAN_JOIN_TABLES) {
398
 
399
        $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";
400
        $result = db_query($query, $UDB_DB_LINK_ID);
401
        // $num=mysql_numrows($result);
402
        echo '<select size="1" name="albumid">';
403
 
404
        while ($row = mysql_fetch_array($result)) {
405
            $sql = "SELECT name FROM $categorytbl WHERE cid = " . $row["category"];
406
            $result2 = db_query($sql);
407
            $row2 = mysql_fetch_array($result2);
408
 
409
            print "<option value=\"" . $row["aid"] . "\">" . $row2["name"] . $row["title"] . "</option>\n";
410
        }
411
 
412
        print '</select> (3)';
413
        print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
414
        print '</form>';
415
 
416
    } else {
417
 
418
        // Query for list of public albums
419
 
420
        $public_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " ORDER BY title");
421
 
422
        if (mysql_num_rows($public_albums)) {
423
            $public_result = db_fetch_rowset($public_albums);
424
        } else {
425
            $public_result = array();
426
        }
427
 
428
        // Initialize $merged_array
429
        $merged_array = array();
430
 
431
        // Count the number of albums returned.
432
        $end = count($public_result);
433
 
434
        // Cylce through the User albums.
435
        for($i=0;$i<$end;$i++) {
436
 
437
            //Create a new array sow we may sort the final results.
438
            $merged_array[$i]['id'] = $public_result[$i]['aid'];
439
            $merged_array[$i]['album_name'] = $public_result[$i]['title'];
440
 
441
            // Query the database to get the category name.
442
            $vQuery = "SELECT name, parent FROM " . $CONFIG['TABLE_CATEGORIES'] . " WHERE cid='" . $public_result[$i]['category'] . "'";
443
            $vRes = mysql_query($vQuery);
444
            $vRes = mysql_fetch_array($vRes);
445
            if (isset($merged_array[$i]['username_category'])) {
446
                $merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '').$merged_array[$i]['username_category'];
447
            } else {
448
                $merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '');
449
            }
450
 
451
        }
452
 
453
        // We transpose and divide the matrix into columns to prepare it for use in array_multisort().
454
        foreach ($merged_array as $key => $row) {
455
           $aid[$key] = $row['id'];
456
           $title[$key] = $row['album_name'];
457
           $album_lineage[$key] = $row['username_category'];
458
        }
459
 
460
        // We sort all columns in descending order and plug in $album_menu at the end so it is sorted by the common key.
461
        array_multisort($album_lineage, SORT_ASC, $title, SORT_ASC, $aid, SORT_ASC, $merged_array);
462
 
463
        // Query for list of user albums
464
 
465
        $user_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category >= " . FIRST_USER_CAT . " ORDER BY aid");
466
        if (mysql_num_rows($user_albums)) {
467
            $user_albums_list = db_fetch_rowset($user_albums);
468
        } else {
469
            $user_albums_list = array();
470
        }
471
 
472
        // Query for list of user IDs and names
473
 
474
        $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);
475
 
476
        if (mysql_num_rows($user_album_ids_and_names)) {
477
            $user_album_ids_and_names_list = db_fetch_rowset($user_album_ids_and_names);
478
        } else {
479
            $user_album_ids_and_names_list = array();
480
        }
481
 
482
        // Glue what we've got together.
483
 
484
        // Initialize $udb_i as a counter.
485
        if (count($merged_array)) {
486
            $udb_i = count($merged_array);
487
        } else {
488
            $udb_i = 0;
489
        }
490
 
491
        //Begin a set of nested loops to merge the various query results.
492
        foreach ($user_albums_list as $aq) {
493
            foreach ($user_album_ids_and_names_list as $uq) {
494
                if ($aq['category'] == $uq['id']) {
495
                    $merged_array[$udb_i]['id']= $aq['category'];
496
                    $merged_array[$udb_i]['album_name']= $aq['title'];
497
                    $merged_array[$udb_i]['username_category']= $uq['name'];
498
                    $udb_i++;
499
                }
500
            }
501
        }
502
 
503
        // The user albums and public albums have been merged into one list. Print the dropdown.
504
        echo '<select size="1" name="albumid">';
505
 
506
        foreach ($merged_array as $menu_item) {
507
 
508
            echo "<option value=\"" . $menu_item['id'] . "\">" . (isset($menu_item['username_category']) ? $menu_item['username_category'] : '') . $menu_item['album_name'] . "</option>\n";
509
 
510
        }
511
 
512
        // Close list, etc.
513
        print '</select> (3)';
514
        print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
515
        print '</form>';
516
 
517
    }
518
 
519
}
520
 
521
// ------------------------------------------------------------------------- //
522
// Define wheter we can join tables or not in SQL queries (same host & same db or user)
523
define('UDB_CAN_JOIN_TABLES', (VB_BD_HOST == $CONFIG['dbserver'] && (VB_DB_NAME == $CONFIG['dbname'] || VB_DB_USERNAME == $CONFIG['dbuser'])));
524
// Connect to vBulletin Board Database if necessary
525
$UDB_DB_LINK_ID = 0;
526
$UDB_DB_NAME_PREFIX = VB_DB_NAME ? '`' . VB_DB_NAME . '`.' : '';
527
if (!UDB_CAN_JOIN_TABLES) {
528
    $UDB_DB_LINK_ID = @mysql_connect(VB_BD_HOST, VB_DB_USERNAME, VB_DB_PASSWORD);
529
    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>");
530
}
531
 
532
?>