<?php

cw_load('faq');
$cat = intval($cat);
if ($action == 'delete_categories' && is_array($faq_cat)) {
    foreach ($faq_cat as $k => $_tmp) {
        cw_faq_delete_rubrik($k);
    }
    cw_header_location('index.php?target=faq&mode=categories&cat=' . $cat);
}
$location[] = array(cw_get_langvar_by_name('lbl_faq_categories'), 'index.php?target=' . $target);
if ($rubrik_id && !cw_faq_is_category($rubrik_id)) {
    cw_header_location('index.php?target=' . $target);
}
$smarty->assign('faq_categories', cw_faq_get_subcategories($rubrik_id));
$smarty->assign('current_category', cw_faq_get_rubrik($rubrik_id));
$smarty->assign('main', 'categories');
        $location[] = array($result['title'], "index.php?target={$target}&mode=category&cat_id=" . $result['rubrik']);
    }
}
if ($cat_id) {
    $__tmp = array();
    $__tmp['main_category'] = cw_faq_get_main($cat_id);
    $smarty->assign('faq', $__tmp);
}
if ($mode == 'membership') {
    $smarty->assign('faq', cw_faq_get_membership_faq($user_account['membership_id']));
    $smarty->assign('main', 'product');
} elseif ($mode == 'salesman') {
    $smarty->assign('faq', cw_faq_get_salesman_faq());
    $smarty->assign('mode', 'membership');
} elseif ($mode == 'category') {
    $smarty->assign('faq_category', cw_faq_get_rubrik($cat_id));
    $smarty->assign('faq_subcategories', cw_faq_get_subcategories($cat_id));
    $smarty->assign('faq_articles', cw_faq_get_articles($cat_id));
    $smarty->assign('main', 'category');
} elseif ($mode == 'article') {
    if ($action == "rate" && $vote) {
        if (cw_faq_voting_check($id, $_SERVER['REMOTE_ADDR'])) {
            $user = cw_query_first_cell("select user from {$tables['faq_voting']} WHERE question_id='{$id}'");
            if (!$user) {
                db_query("INSERT INTO {$tables['faq_voting']} (question_id, vote, user, date, ip) VALUES ('{$id}', '{$vote}', '1', '" . time() . "', '" . $_SERVER['REMOTE_ADDR'] . "');");
            } else {
                db_query("UPDATE {$tables['faq_voting']} SET vote = vote+'" . $vote . "', user = user+'1', date = '" . time() . "', ip = '" . $_SERVER['REMOTE_ADDR'] . "' where question_id='{$id}'");
            }
            $top_message = array('content' => cw_get_langvar_by_name('txt_faq_vote_placed'), 'type' => 'I');
        } else {
            $top_message = array('content' => cw_get_langvar_by_name('txt_faq_vote_error'), 'type' => 'E');