} else {
            $question_id = cw_array2insert('faq_questions', $to_insert, "question_id='{$question_id}'");
        }
        $lng_insert = array('question_id' => $question_id, 'thema' => $data['thema'], 'content' => $data['content'], 'code' => $current_language);
        cw_array2insert('faq_questions_lng', $lng_insert, true);
        if ($_FILES) {
            $data = array();
            $data['file_path'] = cw_move_uploaded_file('file', '');
            $data['filename'] = $_FILES['file']['name'];
            if ($data['file_path']) {
                cw_file_area_save('faq_files', $question_id, $data);
            }
        }
        //        cw_faq_recalc_counters(array_shift(cw_faq_rubrik_path($to_insert['rubrik_id'])));
        $parents = cw_faq_parent_rubriks($to_insert['rubrik_id']);
        cw_faq_recalc_counters($parents[0]['rubrik_id']);
        cw_header_location('index.php?target=faq&mode=question&question_id=' . $question_id);
    }
    $saved_question = $to_insert;
    cw_header_location('index.php?target=faq&mode=question&error=1&question_id=' . $question_id);
}
if ($error) {
    $smarty->assign('question', array_map('stripslashes', $saved_question));
    $smarty->assign('field_errors', $field_errors);
    $field_errors = array();
    $saved_question = array();
} else {
    $smarty->assign('question', cw_faq_get_article($question_id, $current_language, false, false));
}
$smarty->assign('all_rubriks', cw_faq_get_all_rubriks());
$location[] = array(cw_get_langvar_by_name('lbl_faq_questions'), 'index.php?target=faq&mode=questions');
function cw_faq_delete_rubrik($rubrik_id)
{
    global $tables;
    cw_faq_generate_path($rubrik_id, $path);
    $cats = cw_faq_get_sub_rubriks($rubrik_id);
    $cats[] = $rubrik_id;
    if ($cats) {
        foreach ($cats as $v) {
            $questions = cw_query("select question_id from {$tables['faq_questions']} where rubrik_id='{$rubrik_id}'");
            if ($questions) {
                foreach ($questions as $qn) {
                    cw_faq_delete_question($qn['question_id']);
                }
            }
            db_query($sql = "delete from {$tables['faq_rubrik']} where rubrik_id='{$rubrik_id}'");
        }
    }
    cw_faq_recalc_counters($path);
}
cw_load('faq');
if ($action == 'add' && $data['title']) {
    $rubrik_id = cw_faq_create_rubrik($data['title'], $cat);
    cw_faq_recalc_counters($cat);
    cw_header_location('index.php?target=' . $target . '&mode=category&rubrik_id=' . $rubrik_id);
}
if ($action == 'edit') {
    db_query("update {$tables['faq_rubrik']} set title='{$data['title']}' where rubrik_id='{$rubrik_id}'");
    cw_faq_recalc_counters($rubrik_id);
    if ($data['parent_id'] >= 0) {
        db_query("update {$tables['faq_rubrik']} set parent_id='{$data['parent_id']}' where rubrik_id='{$rubrik_id}'");
        cw_faq_update_path($rubrik_id);
        cw_faq_recalc_counters($current_parent);
        if ($new_parent != $current_parent) {
            cw_faq_recalc_counters($new_parent);
        }
    }
    cw_header_location('index.php?target=' . $target . '&mode=category&rubrik_id=' . $rubrik_id);
}
$location[] = array(cw_get_langvar_by_name('lbl_faq_categories'), 'index.php?target=faq_categories');
if (!$rubrik_id) {
    if ($cat && !cw_faq_is_category($cat)) {
        cw_header_location('index.php?target=faq_categories');
    }
    $smarty->assign('cat', $cat);
    $smarty->assign('mode', 'add');
} else {
    $smarty->assign('all_rubriks', cw_faq_get_all_rubriks($rubrik_id));
    $smarty->assign('current_rubrik', cw_faq_get_rubrik($rubrik_id));
    $smarty->assign('rubrik_id', $rubrik_id);