This is the next step (fixes the list structure - adds some countings)
<?php
define('IN_COPPERMINE', true);
require('include/init.inc.php');
global $CONFIG, $HIDE_USER_CAT, $FORBIDDEN_SET, $cpg_show_private_album, $pic_count, $alb_count, $cat_count;
if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) {
$album_filter = ' and ' . str_replace('p.', 'a.', $FORBIDDEN_SET);
$count_filter = ' WHERE ' . str_replace('p.', '', $FORBIDDEN_SET);
}
$sql = "SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} as a WHERE category>=" . FIRST_USER_CAT . $album_filter;
$result = db_query($sql);
$private_album_count = mysql_num_rows($result);
if (!$private_album_count) {
$HIDE_USER_CAT = 1;
}
$sql = "SELECT parent, COUNT(*) FROM {$CONFIG['TABLE_CATEGORIES']} GROUP BY parent";
$result = db_query($sql);
$tmp = db_fetch_rowset($result);
foreach ($tmp as $tmp2) {
$cat_count[$tmp2[0]] = $tmp2[1];
}
$sql = "SELECT category, COUNT(*) FROM {$CONFIG['TABLE_ALBUMS']}". $count_filter ." GROUP BY category";
$result = db_query($sql);
$tmp = db_fetch_rowset($result);
foreach ($tmp as $tmp2) {
$alb_count[$tmp2[0]] = $tmp2[1];
}
$sql = "SELECT aid, COUNT(*) FROM {$CONFIG['TABLE_PICTURES']}". $count_filter ." GROUP BY aid";
$result = db_query($sql);
$tmp = db_fetch_rowset($result);
foreach ($tmp as $tmp2) {
$pic_count[$tmp2[0]] = $tmp2[1];
}
function get_tree_subcat_data($parent) {
global $CONFIG, $HIDE_USER_CAT, $catStr, $cat_count, $alb_count;
if ($CONFIG['categories_alpha_sort'] == 1) {
$cat_sort_order = 'name';
} else {
$cat_sort_order = 'pos';
}
$sql = "SELECT cid, name " . "FROM {$CONFIG['TABLE_CATEGORIES']} " . "WHERE parent = '$parent' " . "ORDER BY ". $cat_sort_order;
$result = db_query($sql);
if (mysql_num_rows($result) > 0) {
$rowset = db_fetch_rowset($result);
$pos = 0;
foreach ($rowset as $subcat) {
if ($subcat['cid'] == USER_GAL_CAT && $HIDE_USER_CAT == 1) {
} else {
if ($cat_count[$subcat['cid']] == "1") {
$count_cat = " - ".$cat_count[$subcat['cid']]." sub-category";
} elseif ($cat_count[$subcat['cid']] > "1") {
$count_cat = " - ".$cat_count[$subcat['cid']]." sub-categories";
}
if ($alb_count[$subcat['cid']] == "1") {
$count_alb = " - ".$alb_count[$subcat['cid']]." album";
} elseif ($alb_count[$subcat['cid']] > "1") {
$count_alb = " - ".$alb_count[$subcat['cid']]." albums";
}
$catStr .= "<li class=\"tree\"><a href=\"#\" onclick=\"togVis('".$subcat['cid']."'); return false;\"><img class=\"tree\" src=\"images/nolines_plus.gif\" alt=\"+\" id=\"".$subcat['cid']."Button\" /></a> <a href=\"index.php?cat=".$subcat['cid']."\">".$subcat['name']."</a>".$count_cat.$count_alb.$count_pic."\n\n";
$catStr .= "<ul class=\"tree\" id=\"".$subcat['cid']."List\">\n\n";
get_tree_subcat_data($subcat['cid']);
get_tree_album_data($subcat['cid']);
$catStr .= "</ul></li>\n\n";
$count_cat = "";
$count_alb = "";
}
}
if ($parent == 0) {
get_tree_album_data($parent);
}
}
}
function get_tree_album_data($category) {
global $catStr, $ALBUM_SET, $alb_count, $pic_count;
global $CONFIG, $HIDE_USER_CAT, $FORBIDDEN_SET, $cpg_show_private_album;
$album_filter='';
$pic_filter='';
if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album) {
$album_filter = ' and '.str_replace('p.','a.',$FORBIDDEN_SET);
$pic_filter = ' and '.str_replace('p.',$CONFIG['TABLE_PICTURES'].'.',$FORBIDDEN_SET);
}
if ($category == USER_GAL_CAT) {
$sql = "SELECT DISTINCT user_id, user_name FROM {$CONFIG['TABLE_USERS']}, {$CONFIG['TABLE_ALBUMS']} WHERE 10000 + {$CONFIG['TABLE_USERS']}.user_id = {$CONFIG['TABLE_ALBUMS']}.category ORDER BY user_name ASC";
$result = db_query($sql);
if (mysql_num_rows($result) > 0) {
$rowset = db_fetch_rowset($result);
foreach ($rowset as $subcat) {
$catStr .= "<li class=\"tree\"><a href=\"#\" onclick=\"togVis('". (FIRST_USER_CAT + (int) $subcat['user_id']) ."'); return false;\"><img class=\"tree\" src=\"images/nolines_plus.gif\" alt=\"+\" id=\"". (FIRST_USER_CAT + (int) $subcat['user_id']) ."Button\" /></a> <a href=\"index.php?cat=". (FIRST_USER_CAT + (int) $subcat['user_id']) ."\">".$subcat['user_name']."</a>\n\n";
$catStr .= "<ul class=\"tree\" id=\"". (FIRST_USER_CAT + (int) $subcat['user_id']) ."List\">\n\n";
get_tree_album_data(FIRST_USER_CAT + (int) $subcat['user_id']);
$catStr .= "</ul></li>\n\n";
}
}
} else {
if ($category == USER_GAL_CAT) {
$sql = "SELECT aid,title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = $category ".$ALBUM_SET .$album_filter . " ORDER BY pos";
} else {
$unaliased_album_filter = str_replace('a.','',$album_filter);
$sql = "SELECT aid,title FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = $category ".$ALBUM_SET .$unaliased_album_filter . " ORDER BY pos";
}
$result = db_query($sql);
if (mysql_num_rows($result) > 0) {
$rowset = db_fetch_rowset($result);
foreach ($rowset as $subcat) {
if ($pic_count[$subcat['aid']] == "1") {
$count_pic = " - ".$pic_count[$subcat['aid']]." image";
} elseif ($pic_count[$subcat['aid']] > "1") {
$count_pic = " - ".$pic_count[$subcat['aid']]." images";
}
$catStr .= "<li class=\"tree\"><img class=\"tree\" src=\"images/page.gif\" alt=\"album\" /> <a href=\"thumbnails.php?album=".$subcat['aid']."\">".$subcat['title']."</a>".$count_pic."</li>\n";
$count_pic = "";
}
}
}
}
get_tree_subcat_data(0);
?>
<script type="text/javascript" language="javascript">
function togVis(id) {
var list = id+"List";
list = document.getElementById(list);
var button = id+"Button";
button = document.getElementById(button);
if(list.style.display == "block") {
list.style.display = "none";
button.src = "images/nolines_plus.gif";
} else {
list.style.display = "block";
button.src = "images/nolines_minus.gif";
}
}
</script>
<style type="text/css">
img.tree {border: 0; vertical-align: middle}
li.tree {list-style: none outside}
ul.tree {display: none; padding-left: 20; padding-top: 0; margin: 0}
body {font-family : Verdana, Arial, Helvetica, sans-serif; font-size: 12px}
</style>
<?php
echo "<ul style=\"padding: 0; margin: 0\">\n\n";
echo $catStr;
echo "</ul>\n\n";
?>
Maybe some admin/mod could move this topic into the Mods/Hacks forum...