function cw_cron_invoice_check_params($time, $prev_time)
{
    global $tables, $config, $smarty;
    $expired_invoices = array();
    $notify_invoices = array();
    $days_notify = intval($config['General']['days_notify_expiration_invoice']);
    $result = cw_query("SELECT d.doc_id, d.display_id, ui.customer_id, di.expiration_date\n\t\t\t\t\t\t\tFROM {$tables['docs']} d\n\t\t\t\t\t\t\tLEFT JOIN {$tables['docs_info']} di ON di.doc_info_id = d.doc_info_id\n\t\t\t\t\t\t\tLEFT JOIN {$tables['docs_user_info']} ui ON ui.doc_info_id = d.doc_info_id\n\t\t\t\t\t\t\tWHERE di.expiration_date <> 0 AND d.type = 'I' AND status <> 'C' AND status <> 'F'");
    if (!empty($result)) {
        foreach ($result as $value) {
            if (!empty($value['customer_id'])) {
                $expiration_date = $value['expiration_date'];
                $days_left = floor(($expiration_date - $time) / SECONDS_PER_DAY);
                // invoice is expired
                if ($days_left <= 0) {
                    cw_load('mail', 'doc');
                    $doc_id = $value['doc_id'];
                    $status = 'F';
                    $expired_invoices[] = "ID:" . $doc_id . " NUMBER:" . $value['display_id'];
                    cw_call('cw_doc_change_status', array($doc_id, $status));
                } elseif ($days_notify > 0 && $days_left == $days_notify) {
                    cw_load('mail', 'doc', 'web');
                    $doc_id = $value['doc_id'];
                    $doc_data = cw_call('cw_doc_get', array($doc_id, 8192));
                    $notify_invoices[] = "ID:" . $doc_id . " NUMBER:" . $value['display_id'];
                    if (empty($doc_data)) {
                        continue;
                    }
                    if ($doc_data['info']['layout_id']) {
                        $layout = cw_web_get_layout_by_id($doc_data['info']['layout_id']);
                    } else {
                        $layout = cw_web_get_layout('docs_' . $doc_data['type']);
                    }
                    $smarty->assign('layout_data', $layout);
                    $smarty->assign('info', $doc_data['info']);
                    $smarty->assign('products', $doc_data['products']);
                    $smarty->assign('order', $doc_data);
                    $smarty->assign('doc', $doc_data);
                    cw_call('cw_send_mail', array($config['Company']['orders_department'], $doc_data['userinfo']['email'], 'mail/docs/customer_subj.tpl', 'mail/docs/customer.tpl', null, false, true));
                }
            }
        }
    }
    $message = "";
    if (count($expired_invoices)) {
        $message = "\n Expired invoices: '" . implode(", ", $expired_invoices) . "'";
    }
    if (count($notify_invoices)) {
        $message .= "\n Notify invoices: '" . implode(", ", $notify_invoices) . "'";
    }
    return $message;
}
    cw_header_location("index.php?target={$target}");
}
if ($action == 'delete' && $saved_template_id) {
    cw_web_delete_layout($saved_template_id);
    $saved_template_id = 0;
    cw_header_location("index.php?target={$target}");
}
if ($action == 'create' && $title) {
    $saved_template_id = cw_barcode_create_template($title);
    cw_header_location("index.php?target={$target}");
}
if ($action == 'update' && $saved_template_id) {
    $data = addslashes(serialize($label_data));
    cw_array2update('layouts', array('data' => $data), "layout_id='{$saved_template_id}'");
    cw_header_location("index.php?target={$target}");
}
if ($saved_template_id) {
    $product = array('eancode' => cw_product_generate_sku($config['barcode']['gen_product_code'], 'eancode'), 'display_price' => '10.00', 'display_discounted_price' => '9.00', 'list_price' => '15.00', 'supplier_code' => cw_product_generate_sku($config['barcode']['gen_product_code'], 'eancode'), 'discount' => '1.00', 'productcode' => 'Product SKU', 'sn' => cw_product_generate_sku($config['barcode']['gen_product_code'], 'eancode'), 'product' => 'Product Title');
    $smarty->assign('product', $product);
    $template = cw_web_get_layout_by_id($saved_template_id);
    if ($template['layout'] != 'barcode') {
        $saved_template_id = 0;
        cw_header_location("index.php?target={$target}");
    }
    $smarty->assign('layout_data', $template);
}
$smarty->assign('template_id', $saved_template_id);
$smarty->assign('home_style', 'popup');
$smarty->assign('current_main_dir', 'addons');
$smarty->assign('current_section_dir', 'barcode');
$smarty->assign('main', 'popup_barcode');
$smarty->assign('customer', $doc_data['userinfo']);
$mem_usertype = $aom_orders[$doc_id]['userinfo']['usertype'];
$smarty->assign('memberships', cw_user_get_memberships($mem_usertype));
if ($real_taxes == "Y") {
    global $current_area, $customer_id, $user_account;
    $_saved_data = compact("current_area", "customer_id", "user_account");
    $current_area = $current_area == 'G' ? 'G' : 'C';
    $customer_id = $aom_orders[$doc_id]['userinfo']['customer_id'];
    $user_account = $aom_orders[$doc_id]['userinfo'];
}
$smarty->assign('payment_methods', cw_func_call('cw_payment_search', array('data' => array('type' => 1))));
//$smarty->assign('shipping', cw_func_call('cw_shipping_search', array('data' => array('active' => 1))));
//$smarty->assign('salesmen', cw_user_get_salesmans_for_register());
$smarty->assign('cod_types', cw_shipping_get_shipping_cod_types($aom_orders[$doc_id]['info']['shipping_id']));
$config['Appearance']['allow_update_quantity_in_cart'] = "N";
$smarty->assign('default_use_only_ean', 'Y');
$smarty->assign('order', $aom_orders[$doc_id]);
$smarty->assign('orig_order', $doc_data);
if ($doc_data['info']['layout_id']) {
    $smarty->assign('layout_data', cw_web_get_layout_by_id($doc_data['info']['layout_id']));
} else {
    $smarty->assign('layout_data', cw_web_get_layout('docs_' . $docs_type));
}
$coupons = cw_query("select * from {$tables['discount_coupons']} where coupon_type != 'free_ship' ORDER BY coupon");
$coupon_exists = cw_query_first_cell("select count(*) from {$tables['discount_coupons']} WHERE coupon = '" . addslashes($aom_orders[$doc_id]['coupon']) . "'") > 0 ? "Y" : "";
if (!empty($coupons)) {
    $smarty->assign('coupons', $coupons);
}
$smarty->assign('coupon_exists', $coupon_exists);
$smarty->assign('js_tab', $js_tab);
$smarty->assign('main', 'order_edit');
}
$location[] = array(cw_get_langvar_by_name('lbl_doc_info_O'), '');
$smarty->assign('product_layout_elements', cw_call('cw_web_get_product_layout_elements', array()));
$smarty->assign('orders', $orders);
$smarty->assign('doc_ids', $doc_ids);
$smarty->assign('current_section_dir', 'cart');
$smarty->assign('main', 'order_message');
if ($_GET['standalone_mode'] == 'Y') {
    if (is_array($doc_ids)) {
        $doc_id = $doc_ids[0];
    } elseif (is_numeric($doc_ids)) {
        $doc_id = $doc_ids;
    }
    $doc_data = cw_call('cw_doc_get', array($doc_id));
    if ($doc_data['info']['layout_id']) {
        $layout = cw_web_get_layout_by_id($doc_data['info']['layout_id']);
    } else {
        $layout = cw_call('cw_web_get_layout', array('docs_' . $doc_data['type'], $_GET['is_email_invoice'] == 'Y'));
    }
    $smarty->assign('layout_data', $layout);
    $smarty->assign('info', $doc_data['info']);
    $smarty->assign('products', $doc_data['products']);
    $smarty->assign('doc', $doc_data);
    if ($_GET['is_email_invoice'] == 'Y') {
        $smarty->assign('is_email_invoice', $_GET['is_email_invoice']);
        cw_display('mail/docs/customer.tpl', $smarty);
    } else {
        cw_display('customer/cart/order_message.tpl', $smarty);
    }
    exit;
}
function cw_doc_print($doc_data, $mode)
{
    global $smarty, $current_area, $app_skins_dirs;
    cw_load('web');
    if ($doc_data['info']['layout_id']) {
        $layout = cw_web_get_layout_by_id($doc_data['info']['layout_id']);
    } else {
        $layout = cw_web_get_layout('docs_' . $doc_data['type']);
    }
    $smarty->assign('layout_data', $layout);
    $smarty->assign('doc', $doc_data);
    $smarty->assign('current_section', '');
    $smarty->assign('main', 'order_print');
    $smarty->assign('home_style', 'iframe');
    $smarty->assign('is_printing', true);
    if ($mode == 'print') {
        cw_display($app_skins_dirs[$current_area] . '/index.tpl', $smarty);
    } elseif ($mode == 'print_pdf' || ($mode = 'print_aom_pdf')) {
        cw_load('pdf');
        cw_pdf_generate(cw_get_langvar_by_name('lbl_doc_info_' . $doc_data['type'], false, false, true), $app_skins_dirs[$current_area] . '/index.tpl');
    }
}
function cw_barcode_print_product($product_id, $options)
{
    global $tables, $user_account, $current_area;
    # kornev, not required to restore...
    //    $current_area = 'C';
    $layout = cw_web_get_layout_by_id($options['template_id']);
    $product = cw_func_call('cw_product_get', array('id' => $product_id, 'user_account' => $user_account, 'info_type' => 17));
    if ($layout['data']['use_tax']) {
        $taxes = cw_get_product_tax_rates($product, $user_info, true, true);
        cw_get_products_taxes($product, $user_account, false, $taxes, true);
        $_tmp_price = $product['price'];
        $product['price'] = $product['list_price'];
        cw_get_products_taxes($product, $user_account, false, $taxes, true);
        $product['list_price'] = $product['display_price'];
        $product['price'] = $_tmp_price;
    }
    $amount = $options['amount'];
    if (!$amount) {
        $amount = 1;
    }
    for ($i = 0; $i < $amount; $i++) {
        $products[] = $product;
    }
    cw_barcode_print($products, $layout, $options);
}