Subversion Repositories svnkaklik

Rev

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