Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Albums with same name - searchnew.php  (Read 2152 times)

0 Members and 1 Guest are viewing this topic.

bowserbabe

  • Coppermine newbie
  • Offline Offline
  • Posts: 15
Albums with same name - searchnew.php
« on: June 11, 2007, 03:59:14 am »

Paver posted a general solution here:
http://forum.coppermine-gallery.net/index.php?topic=31146

But I'm having the same problem as the question at the bottom... I can't apply the solution to searchnew.php.

Mostly because I don't understand how to change this:
Code: [Select]
    if ($select == "") {
        $result = cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = 0");
        while ($row = mysql_fetch_array($result)) {
            // Add to multi-dim array for later sorting
            $listArray[$list_count]['cat'] = $lang_search_new_php['albums_no_category'];
            $listArray[$list_count]['aid'] = $row['aid'];
            $listArray[$list_count]['title'] = $row['title'];
            $list_count++;
        }
        mysql_free_result($result);

        $result = cpg_db_query("SELECT DISTINCT a.aid as aid, a.title as title, c.name as cname FROM {$CONFIG['TABLE_ALBUMS']} as a, {$CONFIG['TABLE_CATEGORIES']} as c WHERE a.category = c.cid AND a.category < '" . FIRST_USER_CAT . "'");
        while ($row = mysql_fetch_array($result)) {
            // Add to multi-dim array for later sorting
            $listArray[$list_count]['cat'] = $row['cname'];
            $listArray[$list_count]['aid'] = $row['aid'];
            $listArray[$list_count]['title'] = $row['title'];
            $list_count++;
        }
        mysql_free_result($result);

        //if (defined('UDB_INTEGRATION')) {
            $sql = $cpg_udb->get_batch_add_album_list();
        /*} else {
            $sql = "SELECT aid, CONCAT('(', user_name, ') ', title) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN {$CONFIG['TABLE_USERS']} AS u ON category = (" . FIRST_USER_CAT . " + user_id)";
        }*/
        $result = cpg_db_query($sql);
        while ($row = mysql_fetch_array($result)) {
            // Add to multi-dim array for later sorting
            $listArray[$list_count]['cat'] = $lang_search_new_php['personal_albums'];
            $listArray[$list_count]['aid'] = $row['aid'];
            $listArray[$list_count]['title'] = $row['title'];
            $list_count++;
        }
        mysql_free_result($result);

Into this:
Code: [Select]
    // Cycle through the User albums
    foreach($user_albums_list as $album) {

        // Add to multi-dim array for later sorting
        $listArray[$list_count]['cat'] = $lang_upload_php['personal_albums'];
        $listArray[$list_count]['aid'] = $album['aid'];
        $listArray[$list_count]['title'] = $album['title'];
        $list_count++;
    }

    // Cycle through the public albums
    foreach($public_albums_list as $album) {

        // Set $album_id to the actual album ID
        $album_id = $album['aid'];

        // Get the category name
        $vQuery = "SELECT cat.name, cat.cid FROM " . $CONFIG['TABLE_CATEGORIES'] . " cat, " . $CONFIG['TABLE_ALBUMS'] . " alb WHERE alb.aid='" . $album_id . "' AND cat.cid=alb.category";
        $vResult = cpg_db_query($vQuery);
        $vRes = cpg_db_fetch_row($vResult);
        mysql_free_result($vResult);

        // Add to multi-dim array for sorting later
        if ($vRes['name']) {
            $listArray[$list_count]['cat'] = $catAnces[$vRes['cid']] . ' - ' . $vRes['name'];
            $listArray[$list_count]['cid'] = $vRes['cid'];
        } else {
            $listArray[$list_count]['cat'] = $lang_upload_php['albums_no_category'];
            $listArray[$list_count]['cid'] = 0;
        }
        $listArray[$list_count]['aid'] = $album['aid'];
        $listArray[$list_count]['title'] = $album['title'];
        $list_count++;
    }

...as a concept.

If I just replace it with the mod version, it gives me "select album" and nothing else on the drop-down box.

I think I'm missing something... help?
« Last Edit: June 11, 2007, 07:55:33 am by GauGau »
Logged

bowserbabe

  • Coppermine newbie
  • Offline Offline
  • Posts: 15
Re: Albums with same name - searchnew.php
« Reply #1 on: June 11, 2007, 04:56:08 am »

Got it. Although I skipped over the "integration" part... I have no integration. And so I just left it. >.>

In searchnew.php, under function albumselect:

Below
Code: [Select]
    static $select = "";
Add:
Code: [Select]
    // Get the ancestry of the categories
    $vQuery = "SELECT cid, parent, name FROM " . $CONFIG['TABLE_CATEGORIES'] . " WHERE 1";
    $vResult = cpg_db_query($vQuery);
    $vRes = cpg_db_fetch_rowset($vResult);
    mysql_free_result($vResult);
    foreach ($vRes as $vResI => $vResV) {
        $vResRow = $vRes[$vResI];
        $catParent[$vResRow['cid']] = $vResRow['parent'];
        $catName[$vResRow['cid']] = $vResRow['name'];
    }
    $catAnces = array();
    foreach ($catParent as $cid => $cid_parent) {
        $catAnces[$cid] = '';
        while ($cid_parent != 0) {
            $catAnces[$cid] = $catName[$cid_parent] . ($catAnces[$cid]?' - '.$catAnces[$cid]:'');
            $cid_parent = $catParent[$cid_parent];
        }
    }


Replace:
Code: [Select]
        $result = cpg_db_query("SELECT DISTINCT a.aid as aid, a.title as title, c.name as cname FROM {$CONFIG['TABLE_ALBUMS']} as a, {$CONFIG['TABLE_CATEGORIES']} as c WHERE a.category = c.cid AND a.category < '" . FIRST_USER_CAT . "'");
        while ($row = mysql_fetch_array($result)) {
            // Add to multi-dim array for later sorting
            $listArray[$list_count]['cat'] = $row['cname'];
            $listArray[$list_count]['aid'] = $row['aid'];
            $listArray[$list_count]['title'] = $row['title'];
            $list_count++;
        }
        mysql_free_result($result);

with
Code: [Select]
        $result = cpg_db_query("SELECT DISTINCT a.aid as aid, a.title as title, c.name as cname, c.cid as ccid FROM

{$CONFIG['TABLE_ALBUMS']} as a, {$CONFIG['TABLE_CATEGORIES']} as c WHERE a.category = c.cid AND a.category <

'" . FIRST_USER_CAT . "'");
        while ($row = mysql_fetch_array($result)) {
            // Add to multi-dim array for later sorting
            if ($row['cname']) {
                $listArray[$list_count]['cat'] = $catAnces[$row['ccid']] . ' - ' . $row['cname'];
                $listArray[$list_count]['cid'] = $row['ccid'];
            } else {
                $listArray[$list_count]['cat'] = $lang_upload_php['albums_no_category'];
                $listArray[$list_count]['cid'] = 0;
            }
            $listArray[$list_count]['aid'] = $row['aid'];
            $listArray[$list_count]['title'] = $row['title'];
            $list_count++;
        }
        mysql_free_result($result);

I think that's it.
Logged
Pages: [1]   Go Up
 

Page created in 0.018 seconds with 19 queries.