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