<?php

global $smarty, $user_account, $customer_id, $user_address;
cw_load('taxes');
$cart =& cw_session_register('cart', array());
if ($user_account['membership_id']) {
    $config['Appearance']['show_cart_summary'] = $user_account['show_summary'];
}
// TODO: move to addon
if ($addons['faq']) {
    cw_load('faq');
    $membership_faq = cw_faq_get_membership_faq($user_account['membership_id']);
    $smarty->assign('membership_faq', $membership_faq);
}
$settings = cw_query_first("select show_prices from {$tables['memberships']} where membership_id='" . $user_account['membership_id'] . "'");
$user_account['show_prices'] = $settings['show_prices'];
    $cat_id = $main_cat_id;
}
$smarty->assign('cat_id', $cat_id);
$path = cw_faq_parent_rubriks($cat_id);
if (is_array($path)) {
    foreach ($path as $result) {
        $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'] . "');");