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/smf.inc.php,v $
15
  $Revision: 1.8 $
16
  $Author: gaugau $
17
  $Date: 2005/04/19 03:17:13 $
18
**********************************************/
19
 
20
// ------------------------------------------------------------------------- //
21
// As a special exception, the copyright holders of Coppermine Photo Gallery //
22
// give you permission to link Coppermine Photo Gallery with independent     //
23
// modules that communicate with SimpleMachines Forum solely through this    //
24
// 'bridge file' interface, regardless of the license terms of these         //
25
// independent modules, and to copy and distribute the resulting combined    //
26
// work under terms of your choice, provided that every copy of the combined //
27
// work is accompanied by a complete copy of the source code of Coppermine   //
28
// Photo Gallery (the version of Coppermine Photo Gallery used to produce    //
29
// the combined work), being distributed under the terms of the GNU General  //
30
// Public License plus this exception.  An independent module is a module    //
31
// which is not derived from or based on Coppermine Photo Gallery.           //
32
//                                                                           //
33
// Note that people who make modified versions of Coppermine Photo Gallery   //
34
// are not obligated to grant this special exception for their modified      //
35
// versions; it is their choice whether to do so.  The GNU General Public    //
36
// License gives permission to release a modified version without this       //
37
// exception; this exception also makes it possible to release a modified    //
38
// version which carries forward this exception.                             //
39
// ------------------------------------------------------------------------- //
40
// Simple Machines Forum Integration for Coppermine                          //
41
// V0.5 Public Beta                                                          //
42
// ------------------------------------------------------------------------- //
43
// Modify the value below according to your Board installation               //
44
//                                                                           //
45
// WARNING : Do not activate this bridge if you already have pictures or     //
46
//           usergroups in your gallery.                                     //
47
// ------------------------------------------------------------------------- //
48
 
49
// Set this to the location of your Settings file:
50
$path = '../smf';
51
 
52
// Comment this out if you want to default user's group to 'Registered'
53
// rather than using Post Count based groups.
54
define('USE_POST_GROUPS', 1);
55
 
56
// Set the names of implied groups here
57
define('CM_ADMIN_GROUP_NAME', 'Administrators');
58
define('CM_MEMBERS_GROUP_NAME', 'Registered');
59
define('CM_GUEST_GROUP_NAME', 'Anonymous');
60
define('CM_BANNED_GROUP_NAME', 'Banned');
61
define('CM_GMOD_GROUP_NAME', 'Global Moderators');
62
 
63
// ------------------------------------------------------------------------- //
64
// Nothing to edit below this line
65
// ------------------------------------------------------------------------- //
66
 
67
// Otherwise, try to autodetect SMF path if not set:
68
if (substr($path, -1) == '/')
69
        $path = substr($path, 0, -1);
70
 
71
$possible_paths = array($path, '..', '../forum', '../forums',
72
'../community', '../yabbse', '../smf');
73
 
74
$correct = 0;
75
while (!file_exists($possible_paths[$correct] . '/Settings.php') &&
76
count($possible_paths) > $correct)
77
        $correct++;
78
 
79
require_once($possible_paths[$correct] . '/Settings.php');
80
 
81
define ('SMF', 1);
82
 
83
// other includes
84
cm_include_smf_funcs("$sourcedir/Load.php", array("reloadSettings", "md5_hmac", "loadUserSettings"));
85
cm_include_smf_funcs("$sourcedir/Subs.php", array("updateMemberData", "updateStats", "updateSettings"));
86
 
87
// database configuration
88
define('SMF_DB_NAME', $db_name); // The name of the database used by the board
89
define('SMF_DB_HOST', $db_server); // The name of the database server
90
define('SMF_DB_USERNAME', $db_user); // The username to use to connect to the database
91
define('SMF_DB_PASSWORD', $db_passwd); // The password to use to connect to the database
92
 
93
// The web path to your SMF Board directory
94
define('SMF_WEB_PATH', "$boardurl/");
95
 
96
// The Name of the Cookie used for SMF logon
97
define('SMF_COOKIE_NAME', $cookiename);
98
 
99
// Prefix for the database tables
100
define('SMF_TABLE_PREFIX', $db_prefix); // Table Prefix
101
 
102
// Names for the database tables
103
define('SMF_USER_TABLE', 'members'); // The members table
104
define('SMF_GROUP_TABLE', 'membergroups'); // The groups table
105
 
106
// Group definitions (default values used by the board)
107
define('SMF_GMOD_GROUP', 2);
108
define('SMF_BANNED_GROUP', -3);
109
define('SMF_GUEST_GROUP', -1);
110
define('SMF_MEMBERS_GROUP', -2);
111
define('SMF_ADMIN_GROUP', 1);
112
 
113
define('SMF_PASSWD_SEED', 'ys');
114
 
115
function cm_include_smf_funcs ($source_file, $funcs)
116
{
117
        $fp = fopen ($source_file, "r");
118
        $len = filesize($source_file);
119
 
120
        $source = fread($fp, $len);
121
        fclose ($fp);
122
        $oe = error_reporting(E_ERROR | E_WARNING | E_PARSE);
123
 
124
        foreach ($funcs as $index => $func) {
125
                preg_match('/\n\s*(function ' . $func . '.*?)\n\s*(function|\?>)/si', $source, $f);
126
                $func = preg_replace("/db_query/s", "cm_db_query", $f[1]);
127
                eval ($func);
128
        }
129
 
130
        error_reporting ($oe);
131
}
132
 
133
function cm_db_query ($query, $other, $other2)
134
{
135
                global $UDB_DB_LINK_ID;
136
 
137
        return db_query($query, $UDB_DB_LINK_ID);
138
}
139
 
140
// Authenticate a user using cookies
141
 
142
function udb_authenticate()
143
{
144
    global $HTTP_COOKIE_VARS, $USER_DATA, $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
145
    global $HTTP_SERVER_VARS, $HTTP_X_FORWARDED_FOR, $HTTP_PROXY_USER, $REMOTE_ADDR;
146
    global $password, $username, $pwseed, $settings, $ID_MEMBER, $realname, $txt, $user_info, $user_settings;
147
 
148
    $pwseed = SMF_PASSWD_SEED;
149
 
150
        session_start();
151
 
152
        reloadSettings();
153
        LoadUserSettings();
154
 
155
    // For error checking
156
    $CONFIG['TABLE_USERS'] = '**ERROR**';
157
 
158
    // get first 50 chars
159
    $HTTP_USER_AGENT = substr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 0, 50);
160
    $REMOTE_ADDR = substr($HTTP_SERVER_VARS['REMOTE_ADDR'], 0, 50);
161
 
162
    /* If the user is a guest, initialize all the critial user settings */
163
    if (!$ID_MEMBER) {
164
        $USER_DATA = cpgGetUserData(SMF_GUEST_GROUP, array(SMF_GUEST_GROUP), SMF_GUEST_GROUP);
165
 
166
        define('USER_ID', 0);
167
        define('USER_NAME', 'Anonymous');
168
        define('USER_GROUP_SET', '(' . SMF_GUEST_GROUP . ')');
169
        define('USER_IS_ADMIN', 0);
170
        define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
171
        define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
172
        define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
173
        define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
174
        define('USER_CAN_CREATE_ALBUMS', 0);
175
        define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
176
        define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
177
        define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
178
        define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
179
    } else {
180
        if ($user_settings['ID_GROUP']){
181
                $cm_group_id = $user_settings['ID_GROUP'];
182
        }  else if ($user_settings['ID_POST_GROUP'] && defined ('USE_POST_GROUPS')){
183
                $cm_group_id = $user_settings['ID_POST_GROUP'];
184
        } else {
185
                $cm_group_id = SMF_MEMBERS_GROUP;
186
        }
187
 
188
        // Retrieve group information
189
                $USER_DATA = cpgGetUserData($cm_group_id, $user_info['groups'], SMF_GUEST_GROUP);
190
                $USER_DATA['has_admin_access'] = $user_info['is_admin'];
191
        $USER_DATA['can_see_all_albums']=$USER_DATA['has_admin_access'] | in_array(SMF_GMOD_GROUP,$user_info['groups']);
192
 
193
        define('USER_ID', $ID_MEMBER);
194
        define('USER_NAME', $user_info['name']);
195
        define('SMF_USER_NAME', $user_info['username']);
196
        define('USER_GROUP', $USER_DATA['group_name']);
197
        define('USER_GROUP_SET', '(' . implode(",", $USER_DATA['groups']) . ')');
198
        define('USER_IS_ADMIN', $user_info['is_admin']);
199
        define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
200
        define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
201
        define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
202
        define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
203
        define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
204
        define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
205
        define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
206
        define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
207
        define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
208
    }
209
}
210
 
211
// Retrieve the name of a user
212
function udb_get_user_name($uid)
213
{
214
    global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
215
 
216
    $sql = "SELECT realName as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . SMF_TABLE_PREFIX . SMF_USER_TABLE . " " . "WHERE ID_MEMBER = '$uid'";
217
 
218
    $result = db_query($sql, $UDB_DB_LINK_ID);
219
 
220
    if (mysql_num_rows($result)) {
221
        $row = mysql_fetch_array($result);
222
        mysql_free_result($result);
223
        return $row['user_name'];
224
    } else {
225
        return '';
226
    }
227
}
228
// Retrieve the name of a user (Added to fix banning w/ bb integration - Nibbler)
229
function udb_get_user_id($username)
230
{
231
    global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
232
 
233
    $username = addslashes($username);
234
 
235
    $sql = "SELECT ID_MEMBER as user_id " . "FROM " . $UDB_DB_NAME_PREFIX . SMF_TABLE_PREFIX . SMF_USER_TABLE . " " . "WHERE realName = '$username'";
236
 
237
    $result = db_query($sql, $UDB_DB_LINK_ID);
238
 
239
    if (mysql_num_rows($result)) {
240
        $row = mysql_fetch_array($result);
241
        mysql_free_result($result);
242
        return $row['user_id'];
243
    } else {
244
        return '';
245
    }
246
}
247
 
248
// Redirect
249
function udb_redirect($target)
250
{
251
    header('Location: '. SMF_WEB_PATH . $target);
252
    exit;
253
}
254
 
255
// Register
256
function udb_register_page()
257
{
258
    $target = 'index.php?action=register';
259
    udb_redirect($target);
260
}
261
 
262
// Login
263
function udb_login_page()
264
{
265
        $_SESSION['login_url'] = $HTTP_GET_VARS['referer'] ? $HTTP_GET_VARS['referer'] : 'index.php';
266
        $_SESSION['login_url'] = "http://localhost/cgpcvs/";
267
    $target = 'index.php?action=login';
268
    udb_redirect($target);
269
}
270
 
271
// Logout
272
function udb_logout_page()
273
{
274
    $target = 'index.php?&action=logout;sesc=' . $_SESSION['rand_code'];
275
    udb_redirect($target);
276
}
277
 
278
// Edit users
279
function udb_edit_users()
280
{
281
    $target = 'index.php?action=mlist';
282
    udb_redirect($target);
283
}
284
 
285
// Get user information
286
function udb_get_user_infos($uid)
287
{
288
    global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
289
    global $lang_register_php;
290
 
291
    $sql = "SELECT realName as user_name, ID_GROUP as mgroup, ID_POST_GROUP, emailAddress as user_email, dateRegistered as user_regdate, " . "websiteURL as user_website " . "FROM " . $UDB_DB_NAME_PREFIX . SMF_TABLE_PREFIX . SMF_USER_TABLE . " " . "WHERE ID_MEMBER = '$uid'";
292
    $result = db_query($sql, $UDB_DB_LINK_ID);
293
 
294
    if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_register_php['err_unk_user'], __FILE__, __LINE__);
295
    $user_data = mysql_fetch_array($result);
296
    mysql_free_result($result);
297
 
298
    $user_data['user_occupation'] = '';
299
    $user_data['user_location'] = '';
300
    $user_data['user_interests'] = '';
301
 
302
    if (!$user_data['mgroup'] && defined('USE_POST_GROUPS')) {
303
            $user_data['mgroup'] = $user_data['ID_POST_GROUP'];
304
    }
305
 
306
        $sql = "SELECT groupName " . "FROM " . $UDB_DB_NAME_PREFIX . SMF_TABLE_PREFIX . SMF_GROUP_TABLE . " " . "WHERE ID_GROUP = '{$user_data['mgroup']}' ";
307
    $result = db_query($sql, $UDB_DB_LINK_ID);
308
 
309
        if (mysql_num_rows($result)) {
310
            $row = mysql_fetch_array($result);
311
            $user_data['group_name'] = $row['groupName'];
312
    } else {
313
            $user_data['group_name'] = CM_MEMBERS_GROUP_NAME;
314
    }
315
    mysql_free_result($result);
316
 
317
    return $user_data;
318
}
319
 
320
// Edit user profile
321
function udb_edit_profile($uid)
322
{
323
    $target = 'index.php?action=profile;u=' . USER_ID;
324
    udb_redirect($target);
325
}
326
 
327
// Query used to list users
328
function udb_list_users_query(&$user_count)
329
{
330
    global $CONFIG, $FORBIDDEN_SET;
331
 
332
        if ($FORBIDDEN_SET != "") $forbidden = "AND $FORBIDDEN_SET";
333
    $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 ";
334
    $result = db_query($sql);
335
 
336
    $user_count = mysql_num_rows($result);
337
 
338
    return $result;
339
}
340
 
341
function udb_list_users_retrieve_data($result, $lower_limit, $count)
342
{
343
    global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
344
 
345
    mysql_data_seek($result, $lower_limit);
346
 
347
    $rowset = array();
348
    $i = 0;
349
    $user_id_set = '';
350
 
351
    while (($row = mysql_fetch_array($result)) && ($i++ < $count)) {
352
        $user_id_set .= $row['user_id'] . ',';
353
        $rowset[] = $row;
354
    }
355
 
356
    mysql_free_result($result);
357
 
358
    $user_id_set = '(' . substr($user_id_set, 0, -1) . ')';
359
    $sql = "SELECT ID_MEMBER as user_id, realName as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . SMF_TABLE_PREFIX . SMF_USER_TABLE . " " . "WHERE ID_MEMBER IN $user_id_set";
360
    $result = db_query($sql, $UDB_DB_LINK_ID);
361
    while ($row = mysql_fetch_array($result)) {
362
        $name[$row['user_id']] = $row['user_name'];
363
    }
364
    for($i = 0; $i < count($rowset); $i++) {
365
        $rowset[$i]['user_name'] = empty($name[$rowset[$i]['user_id']]) ? '???' : $name[$rowset[$i]['user_id']];
366
    }
367
 
368
    return $rowset;
369
}
370
 
371
// Group table synchronisation
372
function udb_synchronize_groups()
373
{
374
    global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
375
 
376
    $result = db_query("SELECT ID_GROUP as usergroupid, groupName as title FROM " . $UDB_DB_NAME_PREFIX . SMF_TABLE_PREFIX . SMF_GROUP_TABLE , $UDB_DB_LINK_ID);
377
    while ($row = mysql_fetch_array($result)) {
378
        $SMF_groups[$row['usergroupid']] = $row['title'];
379
    }
380
    mysql_free_result($result);
381
 
382
    $SMF_groups[SMF_MEMBERS_GROUP] = CM_MEMBERS_GROUP_NAME;
383
    $SMF_groups[SMF_GUEST_GROUP] = CM_GUEST_GROUP_NAME;
384
 
385
    $result = db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE 1");
386
    while ($row = mysql_fetch_array($result)) {
387
        $cpg_groups[$row['group_id']] = $row['group_name'];
388
    }
389
    mysql_free_result($result);
390
    // Scan Coppermine groups that need to be deleted
391
    foreach($cpg_groups as $c_group_id => $c_group_name) {
392
        if ((!isset($SMF_groups[$c_group_id]))) {
393
            db_query("DELETE FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = '" . $c_group_id . "' LIMIT 1");
394
            unset($cpg_groups[$c_group_id]);
395
        }
396
    }
397
    // Scan Board groups that need to be created inside Coppermine table
398
    foreach($SMF_groups as $i_group_id => $i_group_name) {
399
        if ((!isset($cpg_groups[$i_group_id]))) {
400
            db_query("INSERT INTO {$CONFIG['TABLE_USERGROUPS']} (group_id, group_name, group_quota) VALUES ('$i_group_id', '" . addslashes($i_group_name) . "', 1)");
401
            $cpg_groups[$i_group_id] = $i_group_name;
402
        }
403
    }
404
    // Update Group names
405
 
406
    foreach($SMF_groups as $i_group_id => $i_group_name){
407
            if ($cpg_groups[$i_group_id] != $i_group_name) {
408
                    db_query("UPDATE {$CONFIG['TABLE_USERGROUPS']} SET group_name = '".addslashes($i_group_name)."' WHERE group_id = '$i_group_id' LIMIT 1");
409
            }
410
    }
411
}
412
 
413
// Retrieve the album list used in gallery admin mode
414
function udb_get_admin_album_list()
415
{
416
    global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID, $FORBIDDEN_SET;
417
 
418
    if (UDB_CAN_JOIN_TABLES) {
419
        $sql = "SELECT aid, CONCAT('(', realName, ') ', a.title) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN " . $UDB_DB_NAME_PREFIX . SMF_TABLE_PREFIX . SMF_USER_TABLE . " AS u ON category = (" . FIRST_USER_CAT . " + ID_MEMBER) " . "ORDER BY title";
420
        return $sql;
421
    } else {
422
        $sql = "SELECT aid, IF(category > " . FIRST_USER_CAT . ", CONCAT('* ', title), CONCAT(' ', title)) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} " . "ORDER BY title";
423
        return $sql;
424
    }
425
}
426
 
427
function udb_util_filloptions()
428
{
429
    global $albumtbl, $picturetbl, $categorytbl, $lang_util_php, $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
430
 
431
    $usertbl = $UDB_DB_NAME_PREFIX.SMF_TABLE_PREFIX.SMF_USER_TABLE;
432
 
433
    if (UDB_CAN_JOIN_TABLES) {
434
 
435
        $query = "SELECT aid, category, IF(realName IS NOT NULL, CONCAT('(', realName, ') ', a.title), CONCAT(' - ', a.title)) AS title " . "FROM $albumtbl AS a " . "LEFT JOIN $usertbl AS u ON category = (" . FIRST_USER_CAT . " + ID_MEMBER) " . "ORDER BY category, title";
436
        $result = db_query($query, $UDB_DB_LINK_ID);
437
        // $num=mysql_numrows($result);
438
        echo '<select size="1" name="albumid">';
439
 
440
        while ($row = mysql_fetch_array($result)) {
441
            $sql = "SELECT name FROM $categorytbl WHERE cid = " . $row["category"];
442
            $result2 = db_query($sql);
443
            $row2 = mysql_fetch_array($result2);
444
 
445
            print "<option value=\"" . $row["aid"] . "\">" . $row2["name"] . $row["title"] . "</option>\n";
446
        }
447
 
448
        print '</select> (3)';
449
        print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
450
        print '</form>';
451
 
452
    } else {
453
 
454
        // Query for list of public albums
455
 
456
        $public_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " ORDER BY title");
457
 
458
        if (mysql_num_rows($public_albums)) {
459
            $public_result = db_fetch_rowset($public_albums);
460
        } else {
461
            $public_result = array();
462
        }
463
 
464
        // Initialize $merged_array
465
        $merged_array = array();
466
 
467
        // Count the number of albums returned.
468
        $end = count($public_result);
469
 
470
        // Cylce through the User albums.
471
        for($i=0;$i<$end;$i++) {
472
 
473
            //Create a new array sow we may sort the final results.
474
            $merged_array[$i]['id'] = $public_result[$i]['aid'];
475
            $merged_array[$i]['album_name'] = $public_result[$i]['title'];
476
 
477
            // Query the database to get the category name.
478
            $vQuery = "SELECT name, parent FROM " . $CONFIG['TABLE_CATEGORIES'] . " WHERE cid='" . $public_result[$i]['category'] . "'";
479
            $vRes = mysql_query($vQuery);
480
            $vRes = mysql_fetch_array($vRes);
481
            if (isset($merged_array[$i]['username_category'])) {
482
                $merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '').$merged_array[$i]['username_category'];
483
            } else {
484
                $merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '');
485
            }
486
 
487
        }
488
 
489
        // We transpose and divide the matrix into columns to prepare it for use in array_multisort().
490
        foreach ($merged_array as $key => $row) {
491
           $aid[$key] = $row['id'];
492
           $title[$key] = $row['album_name'];
493
           $album_lineage[$key] = $row['username_category'];
494
        }
495
 
496
        // We sort all columns in descending order and plug in $album_menu at the end so it is sorted by the common key.
497
        array_multisort($album_lineage, SORT_ASC, $title, SORT_ASC, $aid, SORT_ASC, $merged_array);
498
 
499
        // Query for list of user albums
500
 
501
        $user_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category >= " . FIRST_USER_CAT . " ORDER BY aid");
502
        if (mysql_num_rows($user_albums)) {
503
            $user_albums_list = db_fetch_rowset($user_albums);
504
        } else {
505
            $user_albums_list = array();
506
        }
507
 
508
        // Query for list of user IDs and names
509
 
510
        $user_album_ids_and_names = db_query("SELECT (ID_MEMBER + ".FIRST_USER_CAT.") as id, CONCAT('(', realName, ') ') as name FROM $usertbl ORDER BY name ASC",$UDB_DB_LINK_ID);
511
 
512
        if (mysql_num_rows($user_album_ids_and_names)) {
513
            $user_album_ids_and_names_list = db_fetch_rowset($user_album_ids_and_names);
514
        } else {
515
            $user_album_ids_and_names_list = array();
516
        }
517
 
518
        // Glue what we've got together.
519
 
520
        // Initialize $udb_i as a counter.
521
        if (count($merged_array)) {
522
            $udb_i = count($merged_array);
523
        } else {
524
            $udb_i = 0;
525
        }
526
 
527
        //Begin a set of nested loops to merge the various query results.
528
        foreach ($user_albums_list as $aq) {
529
            foreach ($user_album_ids_and_names_list as $uq) {
530
                if ($aq['category'] == $uq['id']) {
531
                    $merged_array[$udb_i]['id']= $aq['category'];
532
                    $merged_array[$udb_i]['album_name']= $aq['title'];
533
                    $merged_array[$udb_i]['username_category']= $uq['name'];
534
                    $udb_i++;
535
                }
536
            }
537
        }
538
 
539
        // The user albums and public albums have been merged into one list. Print the dropdown.
540
        echo '<select size="1" name="albumid">';
541
 
542
        foreach ($merged_array as $menu_item) {
543
 
544
            echo "<option value=\"" . $menu_item['id'] . "\">" . (isset($menu_item['username_category']) ? $menu_item['username_category'] : '') . $menu_item['album_name'] . "</option>\n";
545
 
546
        }
547
 
548
        // Close list, etc.
549
        print '</select> (3)';
550
        print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
551
        print '</form>';
552
 
553
    }
554
 
555
}
556
 
557
// ------------------------------------------------------------------------- //
558
 
559
// Define wheter we can join tables or not in SQL queries (same host & same db or user)
560
define('UDB_CAN_JOIN_TABLES', (SMF_DB_HOST == $CONFIG['dbserver'] && (SMF_DB_NAME == $CONFIG['dbname'] || SMF_DB_USERNAME == $CONFIG['dbuser'])));
561
// Connect to SMF Database if necessary
562
$UDB_DB_LINK_ID = 0;
563
$UDB_DB_NAME_PREFIX = SMF_DB_NAME ? '`' . SMF_DB_NAME . '`.' : '';
564
if (!UDB_CAN_JOIN_TABLES) {
565
    $UDB_DB_LINK_ID = @mysql_connect(SMF_DB_HOST, SMF_DB_USERNAME, SMF_DB_PASSWORD);
566
 
567
    if (!$UDB_DB_LINK_ID) die("<b>Coppermine critical error</b>:<br />Unable to connect to SMF Board database !<br /><br />MySQL said: <b>" . mysql_error() . "</b>");
568
    mysql_select_db (SMF_DB_NAME, $UDB_DB_LINK_ID);
569
}
570
?>