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/woltlab21.inc.php,v $
15
  $Revision: 1.7 $
16
  $Author: gaugau $
17
  $Date: 2005/04/19 03:17:13 $
18
**********************************************/
19
// ------------------------------------------------------------------------- //
20
//  Woltlab Burning Board 2.1 Integration for Coppermine                     //
21
// ------------------------------------------------------------------------- //
22
//  Modify the values below according to your Board installation             //
23
// ------------------------------------------------------------------------- //
24
//  user contribution by sugar                                               //
25
// (see http://coppermine.sourceforge.net/oldboard/viewtopic.php?t=2547      //
26
//  for details)                                                             //
27
// ------------------------------------------------------------------------- //
28
// Updated by Mr. S                                                          //
29
// http://coppermine.sourceforge.net/board/index.php?topic=5559.0            //
30
// ------------------------------------------------------------------------- //
31
 
32
// In this example there are 2 subdirectories
33
// WBB: http://yoursite_name.com/wbb2/
34
// CPG: http://yoursite_name.com/cpg/
35
// Setup path to your Woltlab Board directory to change this
36
 
37
// The paths to your Woltlab Board directory
38
define('RELATIVE_WBB_PATH','../wbb2/');
39
define('WBB_WEB_PATH','/wbb2/');
40
 
41
// database configuration
42
require_once(RELATIVE_WBB_PATH."acp/lib/config.inc.php");
43
require_once(RELATIVE_WBB_PATH."acp/lib/options.inc.php");
44
define('WBB_DB_NAME',$sqldb);
45
define('WBB_BD_HOST',$sqlhost);
46
define('WBB_DB_USERNAME',$sqluser);
47
define('WBB_DB_PASSWORD',$sqlpassword);
48
 
49
// cookies configuration
50
define('WBB_COOKIE_HASH',$cookieprefix."cookiehash");
51
define('WBB_COOKIE_USERID',$cookieprefix."userid");
52
define('WBB_COOKIE_USERPW',$cookieprefix."userpassword");
53
 
54
// ------------------------------------------------------------------------- //
55
//  Nothing to edit below this line
56
// ------------------------------------------------------------------------- //
57
 
58
// Prefix and names for the database tables
59
define('WBB_TABLE_PREFIX','bb'.$n.'_');    // Leave empty, not supported by vBulletin 2.3
60
define('WBB_USER_TABLE', 'users');      // The members table
61
define('WBB_SESSION_TABLE', 'sessions');   // The sessions table
62
define('WBB_GROUP_TABLE', 'groups');   // The groups table
63
 
64
// Group definitions (default values used by the board)
65
define('WBB_GUEST_GROUP', 5);
66
define('WBB_MEMBERS_GROUP', 4);
67
define('WBB_ADMIN_GROUP', 1);
68
 
69
// Authenticate a user using cookies
70
function udb_authenticate()
71
{
72
   global $HTTP_COOKIE_VARS, $USER_DATA, $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
73
   global $HTTP_SERVER_VARS, $REMOTE_ADDR, $HTTP_X_FORWARDED_FOR;
74
   global $lang_errors;
75
 
76
   // For error checking
77
   $CONFIG['TABLE_USERS'] = '**ERROR**';
78
 
79
   // Permissions for a default group
80
   $default_group = array(
81
      'group_id' => WBB_GUEST_GROUP,
82
      'group_name' => 'Unknown',
83
      'has_admin_access' => 0,
84
      'can_see_all_albums' => 0,
85
      'can_send_ecards' => 0,
86
      'can_rate_pictures' => 0,
87
      'can_post_comments' => 0,
88
      'can_upload_pictures' => 0,
89
      'can_create_albums' => 0,
90
      'pub_upl_need_approval' => 1,
91
      'priv_upl_need_approval' => 1,
92
      'upload_form_config' => 0,
93
      'custom_user_upload' => 0,
94
      'num_file_upload' => 0,
95
      'num_URI_upload' => 0,
96
   );
97
 
98
   $REMOTE_ADDR=$_SERVER['REMOTE_ADDR'];
99
   $HTTP_X_FORWARDED_FOR=(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
100
 
101
   if($HTTP_X_FORWARDED_FOR!="") {
102
      if(preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", $HTTP_X_FORWARDED_FOR, $ip_match)) {
103
         $private_ip_list = array("/^0\./", "/^127\.0\.0\.1/", "/^192\.168\..*/", "/^172\.16\..*/", "/^10..*/", "/^224..*/", "/^240..*/");
104
         $REMOTE_ADDR = preg_replace($private_ip_list, $REMOTE_ADDR, $ip_match[1]);
105
      }
106
   }
107
   $HTTP_USER_AGENT = substr($_SERVER['HTTP_USER_AGENT'], 0, 100);
108
   $REQUEST_URI = $_SERVER['REQUEST_URI'];
109
   if(!$REQUEST_URI) {
110
      if($_SERVER['PATH_INFO']) $REQUEST_URI = $_SERVER['PATH_INFO'];
111
      else $REQUEST_URI = $_SERVER['PHP_SELF'];
112
      if($_SERVER['QUERY_STRING']) $REQUEST_URI.="?".$_SERVER['QUERY_STRING'];
113
   }
114
   $REQUEST_URI = substr(basename($REQUEST_URI), 0, 250);
115
   if(!strstr($REQUEST_URI,".")) $REQUEST_URI="index.php";
116
 
117
   $REMOTE_ADDR=htmlspecialchars($REMOTE_ADDR);
118
   $HTTP_USER_AGENT=htmlspecialchars($HTTP_USER_AGENT);
119
 
120
   if ( is_array($_COOKIE) ) {
121
      $sessionhash = isset($_COOKIE[WBB_COOKIE_HASH]) ? $_COOKIE[WBB_COOKIE_HASH] : '';
122
      $bbuserid = isset($_COOKIE[WBB_COOKIE_USERID]) ? $_COOKIE[WBB_COOKIE_USERID] : 0;
123
      $bbpassword = isset($_COOKIE[WBB_COOKIE_USERPW]) ? $_COOKIE[WBB_COOKIE_USERPW] : '';
124
   }
125
 
126
   if ($bbuserid && $bbpassword) {
127
      // If userid and password exist in cookies we use them to login
128
       $sql =  "SELECT userid as user_id, username as user_name, useronlinegroupid as mgroup ".
129
            "FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." ".
130
            "WHERE userid='".addslashes($bbuserid)."' AND password='".addslashes($bbpassword)."'";
131
   } elseif ($sessionhash) {
132
      // session hash exists
133
      // validate it:
134
      $sql =  "SELECT * ".
135
            "FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_SESSION_TABLE." ".
136
            "WHERE sessionhash = '".addslashes($sessionhash)."' ".
137
            " AND ipaddress = '".addslashes($REMOTE_ADDR)."' ".
138
            " AND useragent = '".addslashes($HTTP_USER_AGENT)."'";
139
 
140
      $result = db_query($sql, $UDB_DB_LINK_ID);
141
 
142
      if (mysql_num_rows($result)) {
143
          // session hash exists
144
         $session_data = mysql_fetch_array($result);
145
         mysql_free_result($result);
146
 
147
          $sql =  "SELECT userid as user_id, username as user_name, useronlinegroupid as mgroup ".
148
               "FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." ".
149
               "WHERE userid='".$session_data['userid']."'";
150
         $result = db_query($sql, $UDB_DB_LINK_ID);
151
      } else {
152
          $sql =  "SELECT userid as user_id, username as user_name, useronlinegroupid as mgroup ".
153
               "FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." ".
154
               "WHERE 0";
155
      }
156
   } else {
157
      $sql =  "SELECT userid as user_id, username as user_name, useronlinegroupid as mgroup ".
158
            "FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." ".
159
            "WHERE 0";
160
   }
161
 
162
   $result = db_query($sql, $UDB_DB_LINK_ID);
163
 
164
   if (mysql_num_rows($result)){
165
      $USER_DATA = mysql_fetch_array($result);
166
      mysql_free_result($result);
167
 
168
       define('USER_ID', (int)$USER_DATA['user_id']);
169
       define('USER_NAME', $USER_DATA['user_name']);
170
 
171
      // Retrieve group information
172
      $sql = "SELECT * ".
173
            "FROM {$CONFIG['TABLE_USERGROUPS']} ".
174
            "WHERE group_id = '{$USER_DATA['mgroup']}'";
175
      $result = db_query($sql);
176
      if (mysql_num_rows($result)){
177
         $USER_DATA2 = mysql_fetch_array($result);
178
      } else {
179
         $USER_DATA2 = $default_group;
180
      }
181
 
182
      $USER_DATA = array_merge($USER_DATA, $USER_DATA2);
183
 
184
                $USER_DATA['has_admin_access']= ($USER_DATA['mgroup'] == WBB_ADMIN_GROUP);
185
                $USER_DATA['can_see_all_albums'] = $USER_DATA['has_admin_access'];
186
                $USER_DATA['groups'] = array($USER_DATA['group_id']);
187
 
188
       define('USER_GROUP', $USER_DATA['group_name']);
189
      define('USER_GROUP_SET', '('.$USER_DATA['group_id'].')');
190
       define('USER_IS_ADMIN', ($USER_DATA['mgroup'] == WBB_ADMIN_GROUP));
191
       define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
192
       define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
193
       define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
194
       define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
195
       define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
196
       define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
197
       define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
198
       define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
199
       define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
200
      mysql_free_result($result);
201
   } else {
202
       $result = db_query("SELECT * FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = ".WBB_GUEST_GROUP);
203
      if (!mysql_num_rows($result)) {
204
         $USER_DATA = $default_group;
205
      } else {
206
         $USER_DATA = mysql_fetch_array($result);
207
      }
208
 
209
            $USER_DATA['groups'] = array(WBB_GUEST_GROUP);
210
 
211
       define('USER_ID', 0);
212
       define('USER_NAME', 'Anonymous');
213
      define('USER_GROUP_SET', '('.WBB_GUEST_GROUP.')');
214
       define('USER_IS_ADMIN', 0);
215
       define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
216
       define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
217
       define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
218
       define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
219
       define('USER_CAN_CREATE_ALBUMS', 0);
220
       define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
221
       define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
222
       define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
223
       define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
224
      mysql_free_result($result);
225
   }
226
}
227
 
228
// Retrieve the name of a user
229
function udb_get_user_name($uid)
230
{
231
   global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
232
 
233
   $sql = "SELECT username as user_name ".
234
         "FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." ".
235
         "WHERE userid = '$uid'";
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_name'];
243
   } else {
244
      return '';
245
   }
246
}
247
// Retrieve the name of a user (Added to fix banning w/ bb integration - Nibbler)
248
function udb_get_user_id($username)
249
{
250
    global $UDB_DB_LINK_ID, $UDB_DB_NAME_PREFIX, $CONFIG;
251
 
252
    $username = addslashes($username);
253
 
254
       $sql = "SELECT userid as user_id ".
255
         "FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." ".
256
         "WHERE username = '$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: http://' . $_SERVER['HTTP_HOST'] . WBB_WEB_PATH . $target);
273
    exit;
274
}
275
 
276
// Register
277
function udb_register_page()
278
{
279
   $target = 'register.php';
280
   udb_redirect($target);
281
}
282
 
283
// Login
284
function udb_login_page()
285
{
286
   $target = 'index.php';
287
   udb_redirect($target);
288
}
289
 
290
// Logout
291
function udb_logout_page()
292
{
293
   $target = 'logout.php';
294
   udb_redirect($target);
295
}
296
 
297
// Edit users
298
function udb_edit_users()
299
{
300
   $target = 'acp/users.php';
301
   udb_redirect($target);
302
}
303
 
304
// Get user information
305
function udb_get_user_infos($uid)
306
{
307
   global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
308
   global $lang_register_php;
309
 
310
   $sql = "SELECT username as user_name, useronlinegroupid as mgroup, email as user_email, regdate as user_regdate, ".
311
         "homepage as user_website ".
312
         "FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." ".
313
         "WHERE userid = '$uid'";
314
   $result = db_query($sql, $UDB_DB_LINK_ID);
315
 
316
   if(!mysql_num_rows($result)) cpg_die(ERROR, $lang_register_php['err_unk_user'], __FILE__, __LINE__);
317
   $user_data = mysql_fetch_array($result);
318
   mysql_free_result($result);
319
 
320
   $user_data['group_name'] = '';
321
   $user_data['user_occupation'] = '';
322
   $user_data['user_location'] = '';
323
   $user_data['user_interests'] = '';
324
 
325
   $sql =  "SELECT group_name ".
326
         "FROM {$CONFIG['TABLE_USERGROUPS']} ".
327
         "WHERE group_id = {$user_data['mgroup']} ";
328
   $result = db_query($sql);
329
 
330
   if(mysql_num_rows($result)){
331
      $row = mysql_fetch_array($result);
332
      $user_data['group_name'] = $row['group_name'];
333
   }
334
   mysql_free_result($result);
335
 
336
   return $user_data;
337
}
338
 
339
// Edit user profile
340
function udb_edit_profile($uid)
341
{
342
   $target = 'usercp.php';
343
   udb_redirect($target);
344
}
345
 
346
// Query used to list users
347
function udb_list_users_query(&$user_count)
348
{
349
   global $CONFIG, $FORBIDDEN_SET;
350
 
351
    if ($FORBIDDEN_SET != "") $forbidden = "AND $FORBIDDEN_SET";
352
   $sql =  "SELECT (category - ".FIRST_USER_CAT.") as user_id,".
353
         "      '???' as user_name,".
354
         "      COUNT(DISTINCT a.aid) as alb_count,".
355
         "      COUNT(DISTINCT pid) as pic_count,".
356
         "      MAX(pid) as thumb_pid ".
357
         "FROM {$CONFIG['TABLE_ALBUMS']} AS a ".
358
         "INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.aid = a.aid ".
359
         "WHERE approved = 'YES' AND category > ".FIRST_USER_CAT." ".
360
         "$forbidden ".
361
         "GROUP BY category ".
362
         "ORDER BY category ";
363
   $result = db_query($sql);
364
 
365
   $user_count = mysql_num_rows($result);
366
 
367
   return $result;
368
}
369
 
370
function udb_list_users_retrieve_data($result, $lower_limit, $count)
371
{
372
   global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
373
 
374
   mysql_data_seek($result, $lower_limit);
375
 
376
   $rowset = array();
377
   $i=0;
378
   $user_id_set='';
379
 
380
   while (($row = mysql_fetch_array($result)) && ($i++ < $count)){
381
      $user_id_set .= $row['user_id'].',';
382
      $rowset[] = $row;
383
   }
384
   mysql_free_result($result);
385
 
386
   $user_id_set = '('.substr($user_id_set, 0, -1).')';
387
   $sql = "SELECT userid as user_id, username as user_name ".
388
         "FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." ".
389
         "WHERE userid IN $user_id_set";
390
   $result = db_query($sql, $UDB_DB_LINK_ID);
391
   while ($row = mysql_fetch_array($result)){
392
      $name[$row['user_id']] = $row['user_name'];
393
   }
394
   for($i=0; $i<count($rowset); $i++){
395
      $rowset[$i]['user_name'] = empty($name[$rowset[$i]['user_id']]) ? '???' : $name[$rowset[$i]['user_id']];
396
   }
397
 
398
   return $rowset;
399
}
400
 
401
// Group table synchronisation
402
function udb_synchronize_groups()
403
{
404
   global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
405
 
406
   $result = db_query("SELECT groupid, title FROM ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_GROUP_TABLE." WHERE 1", $UDB_DB_LINK_ID);
407
   while ($row = mysql_fetch_array($result)){
408
      $WBB_groups[$row['groupid']] = $row['title'];
409
   }
410
   mysql_free_result($result);
411
 
412
   $result=db_query("SELECT group_id, group_name FROM {$CONFIG['TABLE_USERGROUPS']} WHERE 1");
413
   while ($row = mysql_fetch_array($result)){
414
      $cpg_groups[$row['group_id']] = $row['group_name'];
415
   }
416
   mysql_free_result($result);
417
 
418
   // Scan Coppermine groups that need to be deleted
419
   foreach($cpg_groups as $c_group_id => $c_group_name){
420
      if ((!isset($WBB_groups[$c_group_id]))) {
421
            db_query("DELETE FROM {$CONFIG['TABLE_USERGROUPS']} WHERE group_id = '".$c_group_id."' LIMIT 1");
422
         unset($cpg_groups[$c_group_id]);
423
      }
424
   }
425
 
426
   // Scan Woltlab Board groups that need to be created inside Coppermine table
427
   foreach($WBB_groups as $i_group_id => $i_group_name){
428
      if ((!isset($cpg_groups[$i_group_id]))) {
429
         db_query("INSERT INTO {$CONFIG['TABLE_USERGROUPS']} (group_id, group_name) VALUES ('$i_group_id', '".addslashes($i_group_name)."')");
430
         $cpg_groups[$i_group_id] = $i_group_name;
431
      }
432
   }
433
 
434
   // Update Group names
435
   foreach($WBB_groups as $i_group_id => $i_group_name){
436
      if ($cpg_groups[$i_group_id] != $i_group_name) {
437
         db_query("UPDATE {$CONFIG['TABLE_USERGROUPS']} SET group_name = '".addslashes($i_group_name)."' WHERE group_id = '$i_group_id' LIMIT 1");
438
      }
439
   }
440
}
441
 
442
// Retrieve the album list used in gallery admin mode
443
function udb_get_admin_album_list()
444
{
445
   global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID, $FORBIDDEN_SET;
446
 
447
   if (UDB_CAN_JOIN_TABLES) {
448
      $sql = "SELECT aid, CONCAT('(', username, ') ', a.title) AS title ".
449
            "FROM {$CONFIG['TABLE_ALBUMS']} AS a ".
450
            "INNER JOIN ".$UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE." AS u ON category = (".FIRST_USER_CAT." + userid) ".
451
            "ORDER BY title";
452
      return $sql;
453
   } else {
454
      $sql = "SELECT aid, IF(category > ".FIRST_USER_CAT.", CONCAT('* ', title), CONCAT(' ', title)) AS title ".
455
            "FROM {$CONFIG['TABLE_ALBUMS']} ".
456
            "ORDER BY title";
457
      return $sql;
458
   }
459
}
460
 
461
function udb_util_filloptions()
462
{
463
    global $albumtbl, $picturetbl, $categorytbl, $lang_util_php, $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
464
 
465
    $usertbl = $UDB_DB_NAME_PREFIX.WBB_TABLE_PREFIX.WBB_USER_TABLE;
466
 
467
    if (UDB_CAN_JOIN_TABLES) {
468
 
469
        $query = "SELECT aid, category, IF(username IS NOT NULL, CONCAT('(', username, ') ', a.title), CONCAT(' - ', a.title)) AS title " . "FROM $albumtbl AS a " . "LEFT JOIN $usertbl AS u ON category = (" . FIRST_USER_CAT . " + userid) " . "ORDER BY category, title";
470
        $result = db_query($query, $UDB_DB_LINK_ID);
471
        // $num=mysql_numrows($result);
472
        echo '<select size="1" name="albumid">';
473
 
474
        while ($row = mysql_fetch_array($result)) {
475
            $sql = "SELECT name FROM $categorytbl WHERE cid = " . $row["category"];
476
            $result2 = db_query($sql);
477
            $row2 = mysql_fetch_array($result2);
478
 
479
            print "<option value=\"" . $row["aid"] . "\">" . $row2["name"] . $row["title"] . "</option>\n";
480
        }
481
 
482
        print '</select> (3)';
483
        print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
484
        print '</form>';
485
 
486
    } else {
487
 
488
        // Query for list of public albums
489
 
490
        $public_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " ORDER BY title");
491
 
492
        if (mysql_num_rows($public_albums)) {
493
            $public_result = db_fetch_rowset($public_albums);
494
        } else {
495
            $public_result = array();
496
        }
497
 
498
        // Initialize $merged_array
499
        $merged_array = array();
500
 
501
        // Count the number of albums returned.
502
        $end = count($public_result);
503
 
504
        // Cylce through the User albums.
505
        for($i=0;$i<$end;$i++) {
506
 
507
            //Create a new array sow we may sort the final results.
508
            $merged_array[$i]['id'] = $public_result[$i]['aid'];
509
            $merged_array[$i]['album_name'] = $public_result[$i]['title'];
510
 
511
            // Query the database to get the category name.
512
            $vQuery = "SELECT name, parent FROM " . $CONFIG['TABLE_CATEGORIES'] . " WHERE cid='" . $public_result[$i]['category'] . "'";
513
            $vRes = mysql_query($vQuery);
514
            $vRes = mysql_fetch_array($vRes);
515
            if (isset($merged_array[$i]['username_category'])) {
516
                $merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '').$merged_array[$i]['username_category'];
517
            } else {
518
                $merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '');
519
            }
520
 
521
        }
522
 
523
        // We transpose and divide the matrix into columns to prepare it for use in array_multisort().
524
        foreach ($merged_array as $key => $row) {
525
           $aid[$key] = $row['id'];
526
           $title[$key] = $row['album_name'];
527
           $album_lineage[$key] = $row['username_category'];
528
        }
529
 
530
        // We sort all columns in descending order and plug in $album_menu at the end so it is sorted by the common key.
531
        array_multisort($album_lineage, SORT_ASC, $title, SORT_ASC, $aid, SORT_ASC, $merged_array);
532
 
533
        // Query for list of user albums
534
 
535
        $user_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category >= " . FIRST_USER_CAT . " ORDER BY aid");
536
        if (mysql_num_rows($user_albums)) {
537
            $user_albums_list = db_fetch_rowset($user_albums);
538
        } else {
539
            $user_albums_list = array();
540
        }
541
 
542
        // Query for list of user IDs and names
543
 
544
        $user_album_ids_and_names = db_query("SELECT (userid + ".FIRST_USER_CAT.") as id, CONCAT('(', username, ') ') as name FROM $usertbl ORDER BY name ASC",$UDB_DB_LINK_ID);
545
 
546
        if (mysql_num_rows($user_album_ids_and_names)) {
547
            $user_album_ids_and_names_list = db_fetch_rowset($user_album_ids_and_names);
548
        } else {
549
            $user_album_ids_and_names_list = array();
550
        }
551
 
552
        // Glue what we've got together.
553
 
554
        // Initialize $udb_i as a counter.
555
        if (count($merged_array)) {
556
            $udb_i = count($merged_array);
557
        } else {
558
            $udb_i = 0;
559
        }
560
 
561
        //Begin a set of nested loops to merge the various query results.
562
        foreach ($user_albums_list as $aq) {
563
            foreach ($user_album_ids_and_names_list as $uq) {
564
                if ($aq['category'] == $uq['id']) {
565
                    $merged_array[$udb_i]['id']= $aq['category'];
566
                    $merged_array[$udb_i]['album_name']= $aq['title'];
567
                    $merged_array[$udb_i]['username_category']= $uq['name'];
568
                    $udb_i++;
569
                }
570
            }
571
        }
572
 
573
        // The user albums and public albums have been merged into one list. Print the dropdown.
574
        echo '<select size="1" name="albumid">';
575
 
576
        foreach ($merged_array as $menu_item) {
577
 
578
            echo "<option value=\"" . $menu_item['id'] . "\">" . (isset($menu_item['username_category']) ? $menu_item['username_category'] : '') . $menu_item['album_name'] . "</option>\n";
579
 
580
        }
581
 
582
        // Close list, etc.
583
        print '</select> (3)';
584
        print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="'.$lang_util_php['submit_form'].'" class="submit" /> (4)';
585
        print '</form>';
586
 
587
    }
588
 
589
}
590
 
591
// ------------------------------------------------------------------------- //
592
 
593
// Define wheter we can join tables or not in SQL queries (same host & same db or user)
594
define('UDB_CAN_JOIN_TABLES', (WBB_BD_HOST == $CONFIG['dbserver'] && (WBB_DB_NAME == $CONFIG['dbname'] || WBB_DB_USERNAME == $CONFIG['dbuser'])));
595
 
596
// Connect to Woltlab Board Database if necessary
597
$UDB_DB_LINK_ID = 0;
598
$UDB_DB_NAME_PREFIX = WBB_DB_NAME ? '`'.WBB_DB_NAME.'`.' : '';
599
if (!UDB_CAN_JOIN_TABLES) {
600
   $UDB_DB_LINK_ID = @mysql_connect(WBB_BD_HOST, WBB_DB_USERNAME, WBB_DB_PASSWORD);
601
   if (!$UDB_DB_LINK_ID) die("<b>Coppermine critical error</b>:<br />Unable to connect to Woltlab Board database !<br /><br />MySQL said: <b>".mysql_error()."</b>");
602
}
603
?>