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);
}
session_start();
stop_view($HTTP_SESSION_VARS['view_start'], $HTTP_SESSION_VARS['view_content_id']);
$HTTP_SESSION_VARS['view_start'] = 0;
$HTTP_SESSION_VARS['view_content_id'] = 0;
if (isset($HTTP_GET_VARS['first_content'])) {
    $HTTP_SESSION_VARS['first_content'] = $HTTP_GET_VARS['first_content'];
}
unset($HTTP_SESSION_VARS['contents']);
if (!isset($HTTP_GET_VARS['cat_id'])) {
    $HTTP_GET_VARS['cat_id'] = $config_vars['root_categorie'];
    $template_file = 'index';
}
// create new categorie
if (isset($HTTP_POST_VARS['newcat'])) {
    $new_cat = new categorie();
    $new_cat->set_parent_id($HTTP_GET_VARS['cat_id']);
    $new_cat->set_name($HTTP_POST_VARS['cat_name']);
    $new_cat->set_description($HTTP_POST_VARS['cat_describtion']);
    if ($HTTP_POST_VARS['cat_is_serie'] == 'on') {
        $new_cat->set_is_serie(1);
    }
    $new_cat->set_catgroup_id($HTTP_POST_VARS['add_to_catgroup']);
    $new_cat->commit();
}
//get the cats in the actual cat and information about them
$child_cats = get_cats_of_cat($HTTP_GET_VARS['cat_id']);
// get the amount of child_cats without perm checking
$sql = "SELECT * FROM " . $config_vars['table_prefix'] . "cats WHERE (parent_id = {$HTTP_GET_VARS['cat_id']})";
if (!($result = $db->sql_query($sql))) {
    error_report(SQL_ERROR, 'get_cats_of_cat', __LINE__, __FILE__, $sql);
}