One of the screens in CPG 1.4.9 has a drop down for all albums that uses the OPTGROUP tag to seperate them into categories. I've done the same thing in the XP Publishing screens. All of my users are admins, so I don't know if the user part works.
All changes are to xp_publish.php.
First, the queries must return the categories and be sorted by them primarily.
Find this code (Admin):
$public_albums = cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " ORDER BY title");
Change to this code:
$public_albums = cpg_db_query("SELECT alb.aid, cat.name, alb.title FROM {$CONFIG['TABLE_ALBUMS']} alb INNER JOIN {$CONFIG['TABLE_CATEGORIES']} cat ON category = cid WHERE category < " . FIRST_USER_CAT . " ORDER BY cat.name, alb.title");
Find this code (User):
$user_albums = cpg_db_query("SELECT aid, title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category='" . (FIRST_USER_CAT + USER_ID) . "' ORDER BY title");
Change to this code:
$public_albums = cpg_db_query("SELECT alb.aid, cat.name, alb.title FROM {$CONFIG['TABLE_ALBUMS']} alb INNER JOIN {$CONFIG['TABLE_CATEGORIES']} cat ON category = cid WHERE category = " . (FIRST_USER_CAT + USER_ID) . " ORDER BY cat.name, alb.title");
Now, display the OPTGROUP tags for each category of albums.
Find this code:
$html = "\n";
foreach($user_albums_list as $album) {
$html .= ' <option value="' . $album['aid'] . '">* ' . $album['title'] . "</option>\n";
}
foreach($public_albums_list as $album) {
$html .= ' <option value="' . $album['aid'] . '">' . $album['title'] . "</option>\n";
}
Change to this code:
$html = "\n";
$last_cat = "";
foreach($user_albums_list as $album) {
if ($last_cat != $album['name']) {
$html .= ' <optgroup label="' . $album['name'] . '">';
$last_cat = $album['name'];
}
$html .= ' <option value="' . $album['aid'] . '">* ' . $album['title'] . "</option>\n";
}
foreach($public_albums_list as $album) {
if ($last_cat != $album['name']) {
$html .= ' <optgroup label="' . $album['name'] . '">';
$last_cat = $album['name'];
}
$html .= ' <option value="' . $album['aid'] . '">' . $album['title'] . "</option>\n";
}
Enjoy.