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