Mod to display album name with category prefix Mod to display album name with category prefix
 

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

Mod to display album name with category prefix

Started by ttn, November 14, 2003, 09:06:27 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ttn

Not sure if I post in the right place, DJMaze said post mod here so I'm posting here :-)

Mod description: Different categories with same album name inside them, album list box displays only album name and it's impossible to know which album belongs to which category. This mod is to add a category name in front of album name, ie. Category - Album, in every album list box for clarification.
It's not new. Coppermine Dev Team had put this mod in CPG 1.2 file searchnew.php for Batch Added Pictures. There are 3 more places in Coppermine that album name list box is used the same way,  so I just follow the idea and replicate the logic to the rest:  editpics.php (Edit Pics), modifyalb.php (Modify Album) and upload.php (Upload Pics).

File editpics.php, line 393, replace

if (GALLERY_ADMIN_MODE) {
    $public_albums = db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < '".FIRST_USER_CAT."' ORDER BY title");
        if (mysql_num_rows($public_albums)) {
            $public_albums_list=db_fetch_rowset($public_albums);
        } else {
                $public_albums_list = array();
        }
        mysql_free_result($public_albums);
} else {
        $public_albums_list = array();
}

with

if (GALLERY_ADMIN_MODE) {
    $public_albums =  mysql_query("SELECT DISTINCT a.aid as aid, a.title as title, c.catname as cname FROM {$CONFIG['TABLE_ALBUMS']} as a, {$CONFIG['TABLE_CATEGORIES']} as c WHERE a.category = c.cid AND a.category < '" . FIRST_USER_CAT . "' ORDER BY title");
        if (mysql_num_rows($public_albums)) {
            while ($row = mysql_fetch_array($public_albums)) {
                $row['title'] = $row['cname'] . " - " . $row['title'];
                $public_albums_list[] = $row;
            }
        } else {
                $public_albums_list = array();
        }
        mysql_free_result($public_albums);
} else {
        $public_albums_list = array();
}


File modifyalb.php, line 356, replace

function alb_list_box()
{
        global $CONFIG, $album, $PHP_SELF, $CPG_URL;

        if (GALLERY_ADMIN_MODE) {
                $sql = "SELECT aid, IF(username IS NOT NULL, CONCAT('(', username, ') ', title), CONCAT(' - ', title)) AS title ".
                           "FROM {$CONFIG['TABLE_ALBUMS']} AS a ".
                           "LEFT JOIN {$CONFIG['TABLE_USERS']} AS u ON category = (".FIRST_USER_CAT." + user_id) ".
                           "ORDER BY title";
                $result = db_query($sql);
        } else {
                $result = db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = '".(FIRST_USER_CAT + USER_ID)."' ORDER BY title");
        }

        if (mysql_num_rows($result) > 0 ){
                $lb = "<select name=\"album_listbox\" class=\"listbox\" onChange=\"if(this.options[this.selectedIndex].value) window.location.href='".$CPG_URL."&file=modifyalb&album='+this.options[this.selectedIndex].value;\">\n";
                while ($row = mysql_fetch_array($result)) {
                        $selected = ($row['aid'] == $album) ? "SELECTED" : "";
                        $lb .= "        <option value=\"" . $row['aid'] . "\" $selected>" . $row['title'] . "</option>\n";
                }
                $lb.= "</select>\n";
                return $lb;
        }
}        }

with

function alb_list_box()
{
        global $CONFIG, $album, $PHP_SELF, $CPG_URL;

        if (GALLERY_ADMIN_MODE) {
                $sql = "SELECT aid, category, IF(username IS NOT NULL, CONCAT('(', username, ') ', title), CONCAT('', title)) AS title ".
                           "FROM {$CONFIG['TABLE_ALBUMS']} AS a ".
                           "LEFT JOIN {$CONFIG['TABLE_USERS']} AS u ON category = (".FIRST_USER_CAT." + user_id) ".
                           "ORDER BY category, title";

                $result = db_query($sql);

        } else {
                $result = db_query("SELECT aid, category, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = '".(FIRST_USER_CAT + USER_ID)."' ORDER BY category, title");
        }

        if (mysql_num_rows($result) > 0 ){
                $lb = "<select name=\"album_listbox\" class=\"listbox\" onChange=\"if(this.options[this.selectedIndex].value) window.location.href='" $CPG_URL."&file=modifyalb&album='+this.options[this.selectedIndex].value;\">\n";
                while ($row = mysql_fetch_array($result)) {
                        $result2 = db_query("SELECT catname FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '".$row['category']."'");
                        $row2 = mysql_fetch_array($result2);
                        $selected = ($row['aid'] == $album) ? "SELECTED" : "";
                        $lb .= "        <option value=\"" . $row['aid'] . "\" $selected>" . $row2["catname"] . " - " . $row['title'] . "</option>\n";
                }
                $lb.= "</select>\n";
                return $lb;
        }
}


File upload.c, line 190, replace

if (GALLERY_ADMIN_MODE) {
    $public_albums = mysql_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < ".FIRST_USER_CAT." ORDER BY title");
} else {
        $public_albums = mysql_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < ".FIRST_USER_CAT." AND uploads='YES' ORDER BY title");
}
if (mysql_num_rows($public_albums)) {
    $public_albums_list=db_fetch_rowset($public_albums);
} else {
        $public_albums_list = array();
}

with

if (GALLERY_ADMIN_MODE) {
    $public_albums =  mysql_query("SELECT DISTINCT a.aid as aid, a.title as title, c.catname as cname FROM {$CONFIG['TABLE_ALBUMS']} as a, {$CONFIG['TABLE_CATEGORIES']} as c WHERE a.category = c.cid AND a.category < '" . FIRST_USER_CAT . "' ORDER BY title");

} else {
    $public_albums =  mysql_query("SELECT DISTINCT a.aid as aid, a.title as title, c.catname as cname FROM {$CONFIG['TABLE_ALBUMS']} as a, {$CONFIG['TABLE_CATEGORIES']} as c WHERE a.category = c.cid AND a.category < '" . FIRST_USER_CAT . "' AND uploads='YES' ORDER BY title");

}
if (mysql_num_rows($public_albums)) {
    while ($row = mysql_fetch_array($public_albums)) {
        $row['title'] = $row['cname'] . " - " . $row['title'];
        $public_albums_list[] = $row;
    }

} else {
        $public_albums_list = array();
}


Works for me with phpNuke 6.9 & CPG Nuke 1.2 RC2,  a small contrib to Coppermine community from a PHP newbie, hope it helps somebody out there that had raised this question in the old board.
Note: Currently display only 1 category level in front album name, consistent with searchnew.php. For multiple category hierarchy, eg. Category1->Sub-category1->SameNameAlbum, Sub-category1 - SameNameAlbum will be displayed in list box.

TTN
ThichTN

RickC

Thanks for the code.

Can this be expanded to include 2 categories and an album?

Category-Subcategory-Album

I have my album set up for year, month, and then event :?:

ttn

Hi Rick,

I just hacked the code a little and here it is for n levels of categories.
File upload.c , replace the code above with this new code:

if (GALLERY_ADMIN_MODE) {
        $public_albums =  mysql_query("SELECT DISTINCT a.aid as aid, a.title as title, c.catname as cname, c.parent as parentcid FROM {$CONFIG['TABLE_ALBUMS']} as a, {$CONFIG['TABLE_CATEGORIES']} as c WHERE a.category = c.cid AND a.category < '" . FIRST_USER_CAT . "' ORDER BY title");
} else {
        $public_albums =  mysql_query("SELECT DISTINCT a.aid as aid, a.title as title, c.catname as cname, c.parent as parentcid FROM {$CONFIG['TABLE_ALBUMS']} as a, {$CONFIG['TABLE_CATEGORIES']} as c WHERE a.category = c.cid AND a.category < '" . FIRST_USER_CAT . "' AND uploads='YES' ORDER BY title");

}
if (mysql_num_rows($public_albums)) {
        while ($row = mysql_fetch_array($public_albums)) {
                $row['title'] = $row['cname'] . " - " . $row['title']; // 1st level
                   
                // walk up category tree 'til parent = 0
                $parentcid = $row['parentcid'];
                while ($parentcid) {
                        $rowcat = mysql_query("SELECT catname, parent FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '$parentcid'");
                        if (mysql_num_rows($rowcat))
                        {
                                $parentCat = mysql_fetch_array($rowcat); // can't have more than 1 parent
                                $row['title'] = $parentCat['catname'] . " - " . $row['title']; // nth level
                                $parentcid = $parentCat['parent']; // next parent
                        }
                        else {
                                break;        //  can't get here unless table_categories got corrupted somewhere
                        }

                }    
                $public_albums_list[] = $row;
        }
} else {
        $public_albums_list = array();
}


I tested Upload function quickly and it seems to work okay. Changes in other files are similar, modifyalb.php is like a jungle to me, Brrrrr :-)  
You might want to add some calls to sort the list, original "order by album titles" won't align categories & subcategories in front of albums, asort just might do the trick, I would insert this before the last else statement

    asort($public_albums_list);
    reset($public_albums_list);


Cheers,

TTN
ThichTN