include_once './languages/' . $userdata['user_lang'] . '/lang_main.php';
include_once './includes/template.inc.php';
if (!is_dir($dir)) {
    $dir = $config_vars['default_upload_dir'];
}
$add_to_contentgroups = get_contentgroups_data_where_perm('id,name', 'add_to_group');
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']++;
            }
        $child_cat_infos[$i]['parent_id'] = $child_cats[$i]->get_parent_id();
        $child_cat_infos[$i]['name'] = htmlspecialchars($child_cats[$i]->get_name());
        $child_cat_infos[$i]['description'] = htmlspecialchars($child_cats[$i]->get_description());
        $child_cat_infos[$i]['content_amount'] = $child_cats[$i]->get_content_amount();
        $child_cat_infos[$i]['content_child_amount'] = $child_cats[$i]->get_child_content_amount() - $child_cat_infos[$i]['content_amount'];
        $child_cat_infos[$i]['current_rating'] = $child_cats[$i]->get_current_rating();
        $child_cat_infos[$i]['remove_from_group'] = $child_cats[$i]->check_perm('remove_from_group');
        $child_cat_infos[$i]['delete'] = $child_cats[$i]->check_perm('delete');
        $child_cat_infos[$i]['edit'] = $child_cats[$i]->check_perm('edit');
        $child_cat_infos[$i]['catgroup_id'] = $child_cats[$i]->get_catgroup_id();
        $child_cat_infos[$i]['comments_amount'] = $child_cats[$i]->get_child_comments_amount();
    }
    // in edit mode check on which cats user has rights to remove cat
    if ($HTTP_GET_VARS['mode'] == 'edit') {
        $smarty->assign('allow_cat_remove', check_cat_action_allowed($category->get_catgroup_id(), $userdata['user_id'], 'cat_remove'));
        $add_to_cats_unparsed = get_cats_data_where_perm('id,name', 'cat_add');
        $add_to_cats = get_cats_string($add_to_cats_unparsed);
        $smarty->assign('add_to_cats', $add_to_cats);
    }
    $smarty->assign('child_cat_infos', $child_cat_infos);
    $smarty->assign('number_of_child_cats', $i);
} else {
    //no child cats
    $smarty->assign('number_of_child_cats', 0);
}
// check is user is allowed to add a child cat
$smarty->assign('allow_cat_add', check_cat_action_allowed($category->get_catgroup_id(), $userdata['user_id'], 'cat_add'));
if ($HTTP_GET_VARS['mode'] == 'edit') {
    $smarty->assign('mode', 'edit');
    $add_to_catgroups = get_catgroups_data_where_perm('id,name', 'add_to_group');
    $smarty->assign('add_to_catgroups', $add_to_catgroups);