function add_mediacat_options(&$select, &$mediacat, &$mediacat_ids, $groupName = '')
{
    if (empty($mediacat)) {
        return;
    }
    $mname = $mediacat->getName();
    $mediacat_ids[] = $mediacat->getId();
    $select->add_option($mname, $mediacat->getId(), $mediacat->getId(), $mediacat->getParentId());
    $childs = $mediacat->getChildren();
    if (is_array($childs)) {
        foreach ($childs as $child) {
            add_mediacat_options($select, $child, $mediacat_ids, $mname);
        }
    }
}
        foreach ($childs as $child) {
            add_cat_options($select, $child, $cat_ids, $cat->getName());
        }
    }
}
// zugriff auf mediacategorien
$sel_media = new rex_select();
$sel_media->setMultiple(1);
$sel_media->setStyle('class=rex-perm-fselect');
$sel_media->setSize(20);
$sel_media->setName('userperm_media[]');
$sel_media->setId('userperm_media');
$mediacat_ids = array();
if ($rootCats = OOMediaCategory::getRootCategories()) {
    foreach ($rootCats as $rootCat) {
        add_mediacat_options($sel_media, $rootCat, $mediacat_ids);
    }
}
function add_mediacat_options(&$select, &$mediacat, &$mediacat_ids, $groupName = '')
{
    if (empty($mediacat)) {
        return;
    }
    $mediacat_ids[] = $mediacat->getId();
    $select->addOption($mediacat->getName(), $mediacat->getId(), $mediacat->getId(), $mediacat->getParentId());
    $childs = $mediacat->getChildren();
    if (is_array($childs)) {
        foreach ($childs as $child) {
            add_cat_options($select, $child, $mediacat_ids, $mediacat->getName());
        }
    }