Opening incorrect picture Opening incorrect picture
 

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]

Main Menu

Opening incorrect picture

Started by harustak, October 13, 2006, 12:58:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

harustak

Hi,

I've detected the problem on my coppermine (1.4.8, now upgraded to 1.4.9 with no improvement).
When I use "Last additions" or "Most viewed" folder view of a specific category, and I click on the picture thumbnail, I get the wrong picture opened. It seems like if the "cat=X&pos=Y" in URL is not generated or resolved properly.

However, when I do the same WITHOUT selecting specific category, I always get correct picture.

Url: http://www.harustak.sk

Any hints?

Thnks!
Marian

djpushplay

Quote from: harustak on October 13, 2006, 12:58:04 PM
I've detected the problem on my coppermine (1.4.8, now upgraded to 1.4.9 with no improvement).
When I use "Last additions" or "Most viewed" folder view of a specific category, and I click on the picture thumbnail, I get the wrong picture opened. It seems like if the "cat=X&pos=Y" in URL is not generated or resolved properly.

However, when I do the same WITHOUT selecting specific category, I always get correct picture.


One of my users told me the same thing but I wasn't able to reproduce this problem.  I just assumed (maybe incorrectly) that somebody had somehow changed the order of the "Most viewed" while he was looking at the list of images, but before he actually clicked on the thumbnail.  Don't know if that would cause it or not.  Just my 2 cents.

kegobeer

Which category?  Post a link to an example of this problem.
Do not send me a private message unless I ask for one.  Make your post public so everyone can benefit.

There are no stupid questions
But there are a LOT of inquisitive idiots

harustak

e.g.
Category "Kingdom Animalia [Zivocichy]", click on the first from last additions, click on the folder view icon, go to page 3, click on cricket, goose will be displayed.
http://galleries.harustak.sk/displayimage.php?album=lastup&cat=4&pos=28
vs.
No category selected, click on the fist from last additions, click in the folder view icon, go to page 4, click on cricket, cricket will be displayed as expected.

The same will happen with most viewed, following similar steps or with different pictures.

Thnks
Marian

Joachim Müller

The behaviour of meta albums like "last additions" will of course change as you keep on uploading pics to your gallery. Unable to replicate.

kegobeer

I'm sorry, but I can't replicate this on your gallery.  Every thumbnail I click takes me to the correct page.  I don't know what "cricket" is, as all of the pictures are of birds.  I'm not a bird person, so can you provide screenshots of each step so I can see what's happening?

Can you try using a different computer and/or internet connection?
Do not send me a private message unless I ask for one.  Make your post public so everyone can benefit.

There are no stupid questions
But there are a LOT of inquisitive idiots

harustak

#6
Ok, so I did a little investigation myself...
After some investigation, I noticed that the thumbnail view logic doesn't select subcategories properly in thumbnails.php. I could see no pictures from albums placed in the 2nd subcategories of selected category displayed as thumbnails.
Investigating further, I found that in "thumbnails.php", thumb_get_subcat_data() is used. But it goes to subcategories only until "subcat_level".
Contrary, in "displayimage.php", new get_meta_album_set_data() is used, which works recursively REGARDLESS of subcat_level.
Also, in "thumbnails.php", the call to the subcats was made out of the loop over categories!
As a result, both functions build different sets of albums, resulting in displaying incorect image.

The "thumbnails.php" piece of code:

function thumb_get_subcat_data($parent, &$album_set_array, $level)
{
    global $CONFIG;

    $result = cpg_db_query("SELECT cid, name, description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent'");
    if (mysql_num_rows($result) > 0) {
        $rowset = cpg_db_fetch_rowset($result);
        foreach ($rowset as $subcat) {
            $result = cpg_db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = {$subcat['cid']}");
            $album_count = mysql_num_rows($result);
            while ($row = mysql_fetch_array($result)) {
                $album_set_array[] = $row['aid'];
            } // while
        }
        if ($level > 1) thumb_get_subcat_data($subcat['cid'], $album_set_array, $level -1);
    }
}

As you can see, the serach is limited to the number of levels defined in "subcat_level" and the recursive call is outside the loop.

Proper code (IMHO):
function thumb_get_subcat_data($parent, &$album_set_array, $level)
{
    global $CONFIG;

    $result = cpg_db_query("SELECT cid, name, description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$parent'");
    if (mysql_num_rows($result) > 0) {
        $rowset = cpg_db_fetch_rowset($result);
        foreach ($rowset as $subcat) {
            $result = cpg_db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = {$subcat['cid']}");
            $album_count = mysql_num_rows($result);
            while ($row = mysql_fetch_array($result)) {
                $album_set_array[] = $row['aid'];
            } // while
    thumb_get_subcat_data($subcat['cid'], $album_set_array, $level -1);
        }
        //if ($level > 1) thumb_get_subcat_data($subcat['cid'], $album_set_array, $level -1);
    }
}

The recursive call ignores subcat level and it is placed inside the loop. The $level could be removed completely, as it is not used.
Or, even better, "functions.inc.php" method get_meta_album_set_data() could be used to avoid duplicity of the code.

function get_meta_album_set_data($cid,&$meta_album_set_array) //adapted from index.php get_subcat_data()
{
    global $CONFIG, $cat;

    if ($cid == USER_GAL_CAT) {
       $sql = "SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE category>=" . FIRST_USER_CAT;
       $result = cpg_db_query($sql);
       $album_count = mysql_num_rows($result);
       while ($row = mysql_fetch_array($result)) {
           $meta_album_set_array[] = $row['aid'];
       } // while
       mysql_free_result($result);
    } else {
       $result = cpg_db_query("SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = {$cid}");
       $album_count = mysql_num_rows($result);
       while ($row = mysql_fetch_array($result)) {
           $meta_album_set_array[] = $row['aid'];
       } // while

       mysql_free_result($result);
    }

    $result = cpg_db_query("SELECT cid FROM {$CONFIG['TABLE_CATEGORIES']} WHERE parent = '$cid'");

    if (mysql_num_rows($result) > 0) {
        $rowset = cpg_db_fetch_rowset($result);
        foreach ($rowset as $subcat) {
            if ($subcat['cid']) {
                get_meta_album_set_data($subcat['cid'], $meta_album_set_array);
            }
        }
    }
}


Of course, all info posted above is my opinion only - I can't say for sure as my knowledge of cpg source code is limited to what I learned during this invetigation, so maybe I missed something.
But it seams that after the fix my gallery is working.

Marian

[Edit by Sami] Put code sections in code block