Updated code:
if (!$user_count) {
msg_box($lang_list_users['user_list'], $lang_list_users['no_user_gal'], '', '', 'info');
return;
}
$user_per_page = $CONFIG['thumbcols'] * $CONFIG['thumbrows'];
$totalPages = ceil($user_count / $user_per_page);
$users_this_page = count($rowset);
if ($user_count > $users_this_page && $users_this_page < $user_per_page) {
$sql = "SELECT {$cpg_udb->field['user_id']} AS user_id FROM {$cpg_udb->usertable}";
$result = cpg_db_query($sql);
while ($row = cpg_db_fetch_assoc($result)) {
$user_ids_existing[] = $row['user_id'];
}
cpg_db_free_result($result);
$sql = "SELECT category "
. "FROM {$CONFIG['TABLE_ALBUMS']} AS p "
. "INNER JOIN {$CONFIG['TABLE_PICTURES']} AS pics ON pics.aid = p.aid "
. "WHERE ( category > " . FIRST_USER_CAT . " $FORBIDDEN_SET) "
. "GROUP BY category";
$result = cpg_db_query($sql);
while ($row = cpg_db_fetch_assoc($result)) {
$user_ids_all[] = $row['category'] - FIRST_USER_CAT;
}
cpg_db_free_result($result);
$users_missing = array_diff($user_ids_all, $user_ids_existing);
$users_w_albums = count(array_intersect($user_ids_all, $user_ids_existing));
$offset = max(0, ($PAGE - 1) * $user_per_page - $users_w_albums);
$user_ids = array_slice($users_missing, $offset, $user_per_page - $users_this_page);
foreach ($user_ids as $user_id) {
$user_categories[] = $user_id + FIRST_USER_CAT;
}
$result = cpg_db_query("
SELECT p.owner_id, p.aid, COUNT(*) AS pic_count, MAX(pid) AS thumb_pid, MAX(galleryicon) AS gallery_pid
FROM {$CONFIG['TABLE_PICTURES']} AS p
INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a
ON a.aid = p.aid
WHERE a.category IN (".implode(',', $user_categories).")
GROUP BY p.aid
");
while ($row = cpg_db_fetch_assoc($result)) {
$user_category_data[$row['owner_id']]['alb_count']++;
$user_category_data[$row['owner_id']]['pic_count'] += $row['pic_count'];
$user_category_data[$row['owner_id']]['thumb_pid'] = $row['thumb_pid'];
$user_category_data[$row['owner_id']]['gallery_pid'] = $row['gallery_pid'];
}
foreach ($user_ids as $user_id) {
$rowset[] = array(
'user_id' => $user_id,
'user_name' => 'Former user '.$user_id,
'alb_count' => $user_category_data[$user_id]['alb_count'],
'pic_count' => $user_category_data[$user_id]['pic_count'],
'thumb_pid' => $user_category_data[$user_id]['thumb_pid'],
'gallery_pid' => $user_category_data[$user_id]['gallery_pid'],
);
}
}
I've already applied it to your gallery, and it seems to work for most user categories. Some have still the trash can icon, but I haven't checked in detail yet why this happens. Maybe you find something obvious.