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