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: Mod to display album name with category prefix  (Read 3476 times)

0 Members and 1 Guest are viewing this topic.

ttn

  • Coppermine newbie
  • Offline Offline
  • Posts: 5
Mod to display album name with category prefix
« on: November 14, 2003, 09:06:27 pm »

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
Code: [Select]

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
Code: [Select]

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
Code: [Select]

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
Code: [Select]

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
Code: [Select]

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
Code: [Select]

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
Logged
ThichTN

RickC

  • Coppermine newbie
  • Offline Offline
  • Posts: 3
    • http://www.hopetoseeyousoon.com
display album name with category prefix
« Reply #1 on: November 26, 2003, 03:58:51 am »

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 :?:
Logged

ttn

  • Coppermine newbie
  • Offline Offline
  • Posts: 5
RC4 Mods
« Reply #2 on: November 28, 2003, 10:56:16 am »

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:
Code: [Select]

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
Code: [Select]

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


Cheers,

TTN
Logged
ThichTN
Pages: [1]   Go Up
 

Page created in 0.021 seconds with 19 queries.