if (!is_array($add_to_contentgroups)) {
    die('You dont have perms to add content to any contentgroup');
}
$smarty->assign('add_to_contentgroups', $add_to_contentgroups);
$add_to_catgroups = get_catgroups_data_where_perm('id,name', 'add_to_group');
if (!is_array($add_to_catgroups)) {
    die('You dont have perms to add content to any categorie');
}
$smarty->assign('add_to_catgroups', $add_to_catgroups);
$add_to_cats = get_cats_data_where_perm('id,name', 'content_add');
if (!is_array($add_to_cats)) {
    die('You dont have perms to add content to any categorie');
}
$smarty->assign('add_to_cats', $add_to_cats);
if (isset($add_content)) {
    echo add_dir_parsed($dir, $new_content_group, $new_cat_group, $parent_cat_id);
    echo "added";
}
if (isset($dir)) {
    $dir_handle = opendir($dir);
    while ($file = readdir($dir_handle)) {
        if ($file != "." && $file != "..") {
            if (is_dir("{$dir}/{$file}")) {
                $amount['dirs']++;
            }
            if (is_file("{$dir}/{$file}")) {
                $amount['files']++;
            }
        }
    }
}
function add_dir_parsed($dir, $group_id, $parent_id = -1)
{
    // Add all pictures under the Directory $dir to categories and series depending on the relativ path to $dir
    global $db, $config_vars, $filetypes;
    if ($parent_id == -1) {
        $parent_id = $config_vars['root_categorie'];
    }
    $dir_handle = opendir($dir);
    while ($file = readdir($dir_handle)) {
        if ($file != "." && $file != "..") {
            $dir_and_file = $dir . '/' . $file;
            if (isset($filetypes[getext($file)])) {
                // $file is content
                // generate a new album_content obj
                add_content($file, $dir_and_file, getfile($file), $parent_id, 0, $group_id);
            } elseif (is_dir($dir_and_file)) {
                //file is a sub dir
                $cat = new categorie();
                $cat->set_name($file);
                $cat->set_parent_id($parent_id);
                $cat->fill_up();
                $cat->set_catgroup_id($group_id);
                if (!isset($cat->id)) {
                    $cat->commit();
                }
                add_dir_parsed($dir . '/' . $file, $group_id, $cat->get_id());
            }
        }
    }
    closedir($dir_handle);
}
if (check_cat_action_allowed($category->get_catgroup_id(), $userdata['user_id'], 'content_add')) {
    $smarty->assign('allow_content_add', true);
    // get catgroups where add_to_group is allowed
    $add_to_contentgroups = get_contentgroups_data_where_perm('id,name', 'add_to_group');
    $smarty->assign('add_to_contentgroups', $add_to_contentgroups);
    if (isset($HTTP_POST_VARS['newcontent'])) {
        $objtyp = $filetypes[getext($HTTP_POST_FILES['new_content_file']['name'])];
        if (isset($objtyp)) {
            add_content($HTTP_POST_FILES['new_content_file']['name'], $HTTP_POST_FILES['new_content_file']['tmp_name'], $HTTP_POST_VARS['new_content_name'], $HTTP_GET_VARS['cat_id'], $HTTP_POST_VARS['new_content_place_in_cat'], $HTTP_POST_VARS['new_content_group']);
        } elseif (eregi("zip\$", $HTTP_POST_FILES['new_content_file']['name'])) {
            // its a zip file
            $zip = new PclZip($HTTP_POST_FILES['new_content_file']['tmp_name']);
            $folder = $config_vars['default_upload_dir'] . "/zip_" . $userdata['username'];
            makedir($folder);
            $zip->extract(PCLZIP_OPT_PATH, $folder);
            add_dir_parsed($folder, $HTTP_POST_VARS['new_content_group'], $HTTP_GET_VARS['cat_id']);
            // remove directory;
            unlink($folder . "/index.html");
            rmdir($folder);
        }
    }
}
if (intval($HTTP_SESSION_VARS['first_content']) == '') {
    $HTTP_SESSION_VARS['first_content'] = 0;
}
if (!isset($HTTP_GET_VARS['content_per_page'])) {
    if (!isset($HTTP_SESSION_VARS['content_per_page'])) {
        $content_per_page = $userdata['content_per_page'];
        $HTTP_SESSION_VARS['content_per_page'] = $content_per_page;
    } else {
        $content_per_page = $HTTP_SESSION_VARS['content_per_page'];