cw_doc_make_relation($relation_doc_id, $rel_item_id, $v['amount']);
                    }
                    cw_doc_recalc($relation_doc_id);
                }
            }
            if ($doc_data['giftcerts'] && is_numeric($relation_doc_id)) {
                cw_doc_make_related_doc($doc_id, $relation_doc_id);
            }
        }
    }
    $secure_oid = $doc_ids;
} else {
    $doc_ids = $secure_oid;
}
cw_session_save();
if ($action == 'request_for_quote') {
    cw_call('cw_doc_change_status', array($doc_ids, "Q"));
    $request = $app_catalogs['customer'] . "/index.php?target=order-message&doc_ids=" . implode(",", $doc_ids);
    $cart = $secure_oid = array();
    cw_save_customer_cart($customer_id, $cart);
    cw_header_location($request);
} else {
    $return = cw_func_call('cw_payment_run_processor', array('payment_data' => $payment_data, 'doc_ids' => $doc_ids, 'userinfo' => $userinfo));
    if ($return && $payment_data['payment_type'] == 'cc') {
        $a = strlen($userinfo['card_cvv2']);
        $return['cvvmes'] = ($a ? $a . " digit(s)" : "not set") . " / ";
    }
    $return = cw_call('cw_payment_check_results', array($return));
    cw_call('cw_payment_stop', array($return));
}
exit;
function cw_payment_stop($payment_data)
{
    global $app_catalogs, $customer_id;
    cw_load('cart_process');
    $cart =& cw_session_register('cart', array());
    $top_message =& cw_session_register('top_message');
    if ($payment_data['bill_error']) {
        $top_message = array('type' => 'E', 'content' => $payment_data['bill_error'] . ' ' . $payment_data['reason']);
        $request = $app_catalogs['customer'] . '/index.php?target=cart&mode=checkout';
    } else {
        $_doc_ids = cw_get_urlencoded_doc_ids($payment_data['doc_ids']);
        $request = $app_catalogs['customer'] . "/index.php?target=order-message&doc_ids=" . $_doc_ids;
        $cart = array();
        cw_session_save();
        cw_save_customer_cart($customer_id, $cart);
    }
    cw_header_location($request);
}