function cw_group_edit_update_category($ge_id, $cat, $fields, $data)
{
    if (!$ge_id || !$cat || !count($fields)) {
        return;
    }
    global $tables, $config, $edited_language;
    $query_fields = cw_query_column("desc {$tables['categories']}", 'Field');
    $to_update = array_intersect($query_fields, array_keys($fields));
    # kornev, add attributes to update
    if ($edited_language != $config['default_admin_language']) {
        cw_unset($to_update, 'category', 'description');
    }
    if ($to_update) {
        cw_group_edit_copy($ge_id, 'categories', 'category_id', $cat, $to_update);
    }
    if ($fields['membership_ids']) {
        while ($id = cw_group_edit_each($ge_id, 1, $cat)) {
            cw_membership_update('categories', $id, $data['membership_ids'], 'category_id');
        }
    }
    if ($fields['avail']) {
        while ($id = cw_group_edit_each($ge_id, 1, $cat)) {
            cw_category_update_status($id, $data['avail']);
        }
    }
    if ($fields['category'] || $fields['description']) {
        $to_update = array_intersect(array('category', 'description'), array_keys($fields));
        cw_group_edit_copy($ge_id, 'categories_lng', 'category_id', $cat, $to_update, "code='{$edited_language}'");
    }
    if ($fields['image']) {
        cw_group_edit_copy($ge_id, 'categories_images_thumb', 'id', $cat);
    }
    cw_attributes_group_update($ge_id, $cat, 'C', $fields);
}
function cw_add_class_data($data, $product_id)
{
    global $tables;
    # Update class data
    $comp = $data['class'];
    $comp['product_id'] = $product_id;
    cw_unset($comp, "product_option_id");
    $comp = cw_addslashes($comp);
    $product_option_id = cw_query_first_cell("SELECT product_option_id FROM {$tables['product_options']} WHERE class = '{$comp['class']}' AND product_id = '{$comp['product_id']}'");
    $is_new = empty($product_option_id);
    if (!empty($product_option_id)) {
        cw_array2update("product_options", $comp, "product_option_id = '{$product_option_id}'");
    } else {
        $product_option_id = cw_array2insert("product_options", $comp);
    }
    # Update class multilanguage data
    db_query("DELETE FROM {$tables['product_options_lng']} WHERE product_option_id = '{$product_option_id}'");
    foreach ($data['product_options_lng'] as $v) {
        $v['product_option_id'] = $product_option_id;
        $v = cw_addslashes($v);
        cw_array2insert("product_options_lng", $v, true);
    }
    # Update class options
    $ids = array();
    foreach ($data['product_options_values'] as $k => $opt) {
        $opt['product_option_id'] = $product_option_id;
        $old_option_id = $opt['option_id'];
        cw_unset($opt, "option_id");
        $opt = cw_addslashes($opt);
        $option_id = cw_query_first_cell("SELECT option_id FROM {$tables['product_options_values']} WHERE product_option_id = '{$product_option_id}' AND name = '{$opt['name']}'");
        if (empty($option_id)) {
            $option_id = cw_array2insert("product_options_values", $opt);
        } else {
            cw_array2update("product_options_values", $opt, "option_id = '{$option_id}'");
        }
        $ids[$old_option_id] = $option_id;
    }
    # Update class option multilanguage data
    db_query("DELETE FROM {$tables['product_options_values_lng']} WHERE option_id = '{$option_id}'");
    foreach ($data['product_options_values_lng'] as $v) {
        if (!isset($ids[$v['option_id']])) {
            continue;
        }
        $v['option_id'] = $ids[$v['option_id']];
        $v = cw_addslashes($v);
        cw_array2insert("product_options_values_lng", $v, true);
    }
    # Detect and delete old product option class options
    $ids = cw_query_column("SELECT option_id FROM {$tables['product_options_values']} WHERE product_option_id = '{$product_option_id}' AND option_id NOT IN ('" . implode("','", $ids) . "')");
    if (!empty($ids)) {
        db_query("DELETE FROM {$tables['product_options_values']} WHERE product_option_id = '{$product_option_id}' AND option_id IN ('" . implode("','", $ids) . "')");
        db_query("DELETE FROM {$tables['product_options_values_lng']} WHERE option_id IN ('" . implode("','", $ids) . "')");
        db_query("DELETE FROM {$tables['products_options_ex']} WHERE option_id IN ('" . implode("','", $ids) . "')");
    }
}
/**
 * function build correct url from base URL and GET parameters
 * get parameters can be passed separately as params of {build_url} tag or as array in parameter "params"
 * 
 * @param url - base url
 * @param assign - optional name of smarty var
 * @param params - array of get params
 * other params considered as part of "params"
 * 
 * @example {build_url url='http://www.domain.com/cw/index.php?target=orders' mode='list' page='1' params=$array_of_get_params assign='order_url'}
 */
function smarty_function_build_url($params, &$smarty)
{
    $base_url = $params['url'];
    $get_params = $params['params'];
    $assign = $params['assign'];
    $force_sign = $params['force_sign'];
    cw_unset($params, 'url', 'params', 'assign', 'force_sign');
    foreach ($params as $k => $v) {
        $get_params[$k] = $v;
    }
    $url = cw_core_assign_addition_params($base_url, $get_params);
    if ($force_sign) {
        if (strpos($url, '?') === false) {
            $url .= '?';
        } else {
            $url .= '&';
        }
    }
    if (empty($assign)) {
        return $url;
    }
    $smarty->assign($assign, $url);
    return null;
}
     unset($aom_orders[$doc_id]['info']['use_discount_alt']);
 }
 if (!empty($total_details['use_coupon_discount_alt']) && !empty($total_details['coupon_discount_alt'])) {
     $aom_orders[$doc_id]['info']['coupon_discount_alt'] = $aom_orders[$doc_id]['coupon_discount'] = $total_details['coupon_discount_alt'] = cw_aom_validate_price($total_details['coupon_discount_alt']);
     $aom_orders[$doc_id]['info']['use_coupon_discount_alt'] = "Y";
     if (empty($total_details['coupon_alt'])) {
         $aom_orders[$doc_id]['info']['coupon'] = $aom_orders[$doc_id]['info']['coupon'] = "#" . $aom_orders[$doc_id]['doc_id'];
         $aom_orders[$doc_id]['info']['use_coupon_alt'] = "Y";
     }
 } else {
     unset($aom_orders[$doc_id]['info']['use_coupon_discount_alt']);
 }
 if (!empty($total_details['coupon_alt'])) {
     if ($total_details['coupon_alt'] == '__old_coupon__') {
         $aom_orders[$doc_id]['info']['coupon'] = $aom_orders[$doc_id]['info']['coupon'] = $doc_data['order']['coupon'];
         cw_unset($aom_orders[$doc_id]['info'], "use_coupon_alt");
     } else {
         $aom_orders[$doc_id]['info']['coupon'] = $aom_orders[$doc_id]['info']['coupon'] = $total_details['coupon_alt'];
         $aom_orders[$doc_id]['info']['use_coupon_alt'] = "Y";
     }
 }
 $aom_orders[$doc_id]['info']['expiration_date'] = cw_core_strtotime($total_details['expiration_date']);
 $aom_orders[$doc_id]['info']['payment_id'] = $total_details['payment_method'];
 $aom_orders[$doc_id]['info']['payment_label'] = cw_func_call('cw_payment_get_label', array('payment_id' => $total_details['payment_method']));
 if (isset($total_details['shipping_id'])) {
     $aom_orders[$doc_id]['info']['shipping_id'] = $total_details['shipping_id'];
 }
 $aom_orders[$doc_id]['info']['shipping_label'] = cw_query_first_cell("SELECT shipping FROM {$tables['shipping']} WHERE shipping_id='" . $total_details['shipping_id'] . "'");
 $aom_orders[$doc_id]['info']['salesman_customer_id'] = "";
 //$total_details['salesman_customer_id'];
 $aom_orders[$doc_id]['info']['cod_type_id'] = $total_details['cod_type_id'];
Пример #5
0
function cw_payment_sagepaygo_form_clean_crypt($data)
{
    $fields_specs = cw_payment_sagepaygo_form_get_allowed_fields();
    foreach ($fields_specs as $field => $spec) {
        if (!isset($data[$field]) || isset($spec['skip'])) {
            continue;
        }
        if (isset($fields_specs[$field]['allowed_values'])) {
            if (!in_array($data[$field], $spec['allowed_values'])) {
                cw_unset($data, $field);
            }
            continue;
        }
        $pattern = $spec['filter'] == 'Custom' ? $spec['pattern'] : false;
        $data[$field] = cw_payment_sagepaygo_form_clean_input($data[$field], $spec['filter'], $spec['max'], $pattern);
    }
    $_data = array();
    foreach ($data as $k => $v) {
        $_data[] = $k . "=" . $v;
    }
    return $_data;
}
//include $app_main_dir.'/addons/product_options/customer/product.php';
cw_include('addons/product_options/customer/product.php');
if ($REQUEST_METHOD == "POST" && $action == "update") {
    $poptions = $_POST['product_options'];
    if (!cw_check_product_options($product_id, $poptions)) {
        cw_header_location("index.php?target=popup_poptions&target={$target}&id={$id}&err=exception");
    }
    if ($mode == 'wishlist') {
        db_query("UPDATE {$tables['wishlist']} SET options = '" . addslashes(serialize($poptions)) . "' WHERE wishlist_id = '{$id}' AND event_id = '{$eventid}'");
    } else {
        $variant_id = cw_get_variant_id($product_options, $product_id);
        $amount = cw_warehouse_get_warehouse_avail($cart['products'][$cartindex]['warehouse'], $product_id, null, $variant_id);
        //		$amount = cw_get_options_amount($poptions, $cart['products'][$cartindex]['product_id']);
        if ($amount >= $cart['products'][$cartindex]['amount']) {
            $cart['products'][$cartindex]['options'] = $poptions;
            cw_unset($cart['products'][$cartindex], 'variant_id');
        } else {
            cw_header_location("index.php?target=popup_poptions&target={$target}&id={$id}&err=avail");
        }
        # Recalculate cart totals after updating
        $products = cw_call('cw_products_in_cart', array($cart, $user_account));
        $cart = cw_func_call('cw_cart_calc', array('cart' => $cart, 'products' => $products, 'userinfo' => $user_account));
    }
    ?>
<script type="text/javascript">
<!--
if (window.opener) window.opener.location.reload();
window.close();
-->
</script>
<?php 
Пример #7
0
<?php

cw_addons_set_template(array('replace', 'customer/products/thumbnail.tpl', 'addons/magnifier/popup_magnifier.tpl', 'zoomer_images_count'));
$gd_not_loaded = false;
if (extension_loaded('gd') && function_exists("gd_info")) {
    $gd_config = gd_info();
    if (!empty($gd_config['GIF Read Support']) && !empty($gd_config['JPG Support']) && !empty($gd_config['PNG Support'])) {
        $gd_config['correct_version'] = true;
    }
} else {
    $gd_not_loaded = true;
}
define("NO_CHANGE_LOCATION_Z", true);
$max_image_size = 2000;
$x_tile_size = 100;
$y_tile_size = 100;
$x_thmb = 80;
$y_thmb = 65;
$x_work_area = 366 - 2;
$y_work_area = 281 - 2;
$jpg_qlt_tile = '80';
$jpg_qlt_level = '85';
$jpg_qlt_thmb = '95';
if (!function_exists("imagejpeg") || !function_exists("imagecopyresampled") || !function_exists("imageCreatetruecolor")) {
    cw_unset($addons, "magnifier");
    return;
}
function cw_products_from_scratch($scratch_products, $user_info, $persistent_products, $leave_info = false)
{
    global $addons, $tables, $config, $app_main_dir;
    global $current_area, $current_language, $customer_id;
    cw_load('image');
    $products = array();
    if (empty($scratch_products)) {
        return $products;
    }
    $pids = array();
    foreach ($scratch_products as $product_data) {
        $pids[] = $product_data['product_id'];
    }
    $int_res = cw_query_hash("SELECT * FROM {$tables['products_lng']} WHERE code = '{$current_language}' AND product_id IN ('" . implode("','", $pids) . "')", "product_id", false);
    unset($pids);
    cw_event('on_before_products_from_scratch', array(&$scratch_products));
    $hash = array();
    cw_load('warehouse');
    foreach ($scratch_products as $product_data) {
        $product_id = $product_data['product_id'];
        $cartid = $product_data['cartid'];
        $amount = $product_data['amount'];
        $variant_id = $product_data['variant_id'];
        $warehouse = $product_data['warehouse_customer_id'];
        if (!cw_warehouse_is_customer($customer_id, $warehouse)) {
            continue;
        }
        if (!is_numeric($amount)) {
            $amount = 0;
        }
        $options = $product_data['options'];
        $product_options = false;
        $variant = array();
        # kornev, TOFIX
        if ($addons['product_options'] && !empty($options) && is_array($options)) {
            if (!cw_check_product_options($product_id, $options)) {
                continue;
            }
            list($variant, $product_options) = cw_get_product_options_data($product_id, $options, $membership_id);
            if (empty($variant_id) && isset($variant['variant_id'])) {
                $variant_id = $variant['variant_id'];
            }
        }
        $fields[] = "p.*";
        # kornev, supplier has got it's own prices
        if ($current_area != 'S') {
            $fields[] = "min(pq.price) as price";
        }
        $fields[] = 'avail';
        $status = cw_core_get_required_status($current_area);
        $products_array = cw_func_call('cw_product_get', array('id' => $product_id, 'variant_id' => $variant_id, 'amount' => $amount, 'user_account' => $user_info, 'info_type' => 8192));
        //cw_query_first($sql="select ".implode(', ', $fields)." from $tables[products] as p, $tables[products_prices] as pq, $tables[products_enabled] as pe left join $tables[products_warehouses_amount] as pwa on pwa.product_id=pe.product_id and pwa.variant_id='$variant_id' and pwa.warehouse_customer_id='$warehouse' WHERE p.product_id= pe.product_id and pe.product_id=pq.product_id AND pe.status in (".implode(", ", $status).") AND pe.product_id='$product_id' AND pq.quantity<='$amount' AND pq.membership_id IN(0, '$user_info[membership_id]') AND pq.variant_id = '$variant_id' ORDER BY pq.quantity DESC");
        $unlimited_products = true;
        if ($products_array['avail'] < $amount && in_array($current_area, array('G', 'C'))) {
            $unlimited_products = cw_query_first_cell("select backorder & " . ($current_area == 'G' ? 2 : 1) . " from {$tables['warehouse_divisions']} where division_id = '{$warehouse}'");
            if (!$unlimited_products) {
                $amount = $products_array['avail'];
            }
        }
        if ($products_array) {
            $products_array = cw_array_merge($product_data, $products_array);
            if ($leave_info) {
                $products_array['price'] = abs($product_data['price']);
            }
            $products_array['warehouse_customer_id'] = $warehouse;
            $hash_key = $product_id . "|" . $warehouse;
            cw_event('on_product_from_scratch', array(&$products_array));
            #
            # If priduct's price is 0 then use customer-defined price
            #
            $free_price = false;
            if ($products_array['price'] == 0) {
                $free_price = true;
                $products_array['taxed_price'] = $products_array['price'] = price_format($product_data['free_price'] ? $product_data['free_price'] : 0);
            }
            # kornev, TOFIX
            if ($addons['product_options'] && $options) {
                if (!empty($variant)) {
                    # kornev, it's not allow to set the variant price.
                    //					unset($variant['price']);
                    if (is_null($variant['pimage_path'])) {
                        cw_unset($variant, "pimage_path", "pimage_x", "pimage_y");
                    } else {
                        $variant['is_pimage'] = 'W';
                    }
                    $products_array = cw_array_merge($products_array, $variant);
                }
                $hash_key .= "|" . $products_array['variant_id'];
                if ($product_options === false) {
                    unset($product_options);
                } else {
                    $variant['price'] = $products_array['price'];
                    $variant['cost'] = $products_array['cost'];
                    $products_array['options_surcharge'] = 0;
                    $products_array['cost_surcharge'] = 0;
                    if ($product_options) {
                        foreach ($product_options as $o) {
                            $products_array['options_surcharge'] += $o['modifier_type'] ? $products_array['price'] * $o['price_modifier'] / 100 : $o['price_modifier'];
                            $products_array['cost_surcharge'] += $o['cost_modifier_type'] ? $products_array['cost'] * $o['cost_modifier'] / 100 : $o['cost_modifier'];
                        }
                    }
                }
            }
            if (!$unlimited_products && !$persistent_products && $products_array['avail'] - $hash[$hash_key] < $amount) {
                continue;
            }
            # Get thumbnail's URL (uses only if images stored in FS)
            $products_array['image_thumb'] = cw_image_get('products_images_thumb', $product_id);
            $products_array['price'] += $products_array['options_surcharge'];
            $products_array['cost'] += $products_array['cost_surcharge'];
            if ($products_array['price'] < 0) {
                $products_array['price'] = 0;
            }
            if ($products_array['cost'] < 0) {
                $products_array['cost'] = 0;
            }
            if (in_array($current_area, array('C', 'G'))) {
                $products_array['taxes'] = cw_get_products_taxes($products_array, $user_info, false, '', $current_area == 'G' && $customer_info['usertype'] != 'R');
                if ($config['Taxes']['display_taxed_order_totals'] == 'Y') {
                    $products_array['display_price'] = $products_array['taxed_price'];
                    $products_array['display_net_price'] = $products_array['taxed_net_price'];
                } else {
                    $products_array['display_price'] = $products_array['price'];
                    $products_array['display_net_price'] = $products_array['net_price'];
                }
            }
            $products_array['total'] = $amount * $products_array['price'];
            $products_array['product_options'] = $product_options;
            $products_array['options'] = $options;
            $products_array['amount'] = $amount;
            $products_array['cartid'] = $cartid;
            $products_array['product_orig'] = $products_array['product'];
            if (isset($int_res[$product_id])) {
                $products_array['product'] = stripslashes($int_res[$product_id]['product']);
                $products_array['descr'] = stripslashes($int_res[$product_id]['descr']);
                $products_array['fulldescr'] = stripslashes($int_res[$product_id]['fulldescr']);
                cw_unset($int_res, $product_id);
            }
            if ($products_array['descr'] == strip_tags($products_array['descr'])) {
                $products_array['descr'] = str_replace("\n", "<br />", $products_array['descr']);
            }
            if ($products_array['fulldescr'] == strip_tags($products_array['fulldescr'])) {
                $products_array['fulldescr'] = str_replace("\n", "<br />", $products_array['fulldescr']);
            }
            // Order hash defines how all products in cart will be split by orders
            // Listen for the event and return own part of hash
            $order_hash = cw_event('on_build_order_hash', array($products_array), array());
            $order_hash[] = 'W' . $products_array['warehouse_customer_id'];
            $products_array['order_hash'] = join('-', $order_hash);
            $products[] = $products_array;
            $hash[$hash_key] += $amount;
        }
    }
    //cw_var_dump($products);
    return $products;
}
Пример #9
0
function cw_query_hash($query, $column = false, $is_multirow = true, $only_first = false)
{
    $result = array();
    $is_multicolumn = false;
    if ($p_result = db_query($query)) {
        if ($column === false) {
            # Get first field name
            $c = db_fetch_field($p_result);
            $column = $c->name;
        } elseif (is_array($column)) {
            if (count($column) == 1) {
                $column = current($column);
            } else {
                $is_multicolumn = true;
            }
        }
        while ($row = db_fetch_array($p_result)) {
            # Get key(s) column value and remove this column from row
            if ($is_multicolumn) {
                $keys = array();
                foreach ($column as $c) {
                    $keys[] = $row[$c];
                    cw_unset($row, $c);
                }
                $keys = implode('"]["', $keys);
            } else {
                $key = $row[$column];
                cw_unset($row, $column);
            }
            if ($only_first) {
                $row = array_shift($row);
            }
            if ($is_multicolumn) {
                # If keys count > 1
                if ($is_multirow) {
                    eval('$result["' . $keys . '"][] = $row;');
                } else {
                    eval('$is = isset($result["' . $keys . '"]);');
                    if (!$is) {
                        eval('$result["' . $keys . '"] = $row;');
                    }
                }
            } elseif ($is_multirow) {
                $result[$key][] = $row;
            } elseif (!isset($result[$key])) {
                $result[$key] = $row;
            }
        }
        db_free_result($p_result);
    }
    return $result;
}
<?php

global $smarty, $user_account, $customer_id, $user_address;
$user_address =& cw_session_register('user_address', array());
$user_account['membership_id'] = 0;
if ($customer_id) {
    $user_account = cw_user_get_user_account($customer_id, "status='Y' and usertype in ('" . (AREA_TYPE == 'C' ? "C', 'R" : AREA_TYPE) . "')");
    $user_address['current_address'] = cw_user_get_address_by_type('current');
    $user_address['main_address'] = cw_user_get_address_by_type('main');
    $user_account = array_merge($user_account, (array) $user_address['current_address']);
    if (!$user_account['customer_id']) {
        cw_unset($identifiers, AREA_TYPE);
        $customer_id = 0;
        $user_account = array();
    }
    // Force redirect to change password page
    if ($user_account["change_password"] && !in_array($target, array('change_password', 'ajax', 'acc_manager', 'user'), true) && !defined('IS_AJAX')) {
        cw_header_location('index.php?target=change_password&redirect=Y');
    }
}
$user_address['current_address'] = cw_user_get_address_by_type('current');
$user_address['main_address'] = cw_user_get_address_by_type('main');
$smarty->assign('user_address', $user_address);
$smarty->assign('customer_id', $customer_id);
$smarty->assign('usertype', $current_area);
$smarty->assign('current_area', $current_area);
Пример #11
0
    if (!$fillerror && !$antibot_err) {
        $contact['b_statename'] = cw_get_state($contact['b_state'], $contact['b_country']);
        $contact['b_countryname'] = cw_get_country($contact['b_country']);
        if ($config['General']['use_counties'] == "Y") {
            $contact['b_countyname'] = cw_get_county($contact['b_county']);
        }
        $contact = cw_stripslashes($contact);
        $smarty->assign('contact', $contact);
        $smarty->assign('profile_fields', $profile_fields);
        $smarty->assign('is_areas', $is_areas);
        $smarty->assign('additional_fields', $additional_fields);
        cw_call('cw_send_mail', array($contact['email'], $config['Company']['support_department'], 'mail/contactus/subj.tpl', 'mail/contactus/body.tpl', $config['default_admin_language']));
        $top_message = array('content' => cw_get_langvar_by_name('txt_contact_us_sent'), 'type' => 'I');
        cw_header_location(cw_call('cw_core_get_html_page_url', array(array("var" => "help", "section" => "contactus", 'delimiter' => '&'))));
    } else {
        cw_unset($_POST, 'additional_values');
        $userinfo = $_POST;
        $userinfo['customer_id'] = $userinfo['uname'];
    }
}
#
# Recover password feature regenerates password and sends it to user if mail match
#
if ($REQUEST_METHOD == "POST" && $action == "recover_password") {
    $accounts = cw_query("SELECT customer_id, password, usertype, email FROM {$tables['customers']} WHERE email='{$email}' AND status='Y' and usertype='{$current_area}'");
    #
    # Regenerate password
    #
    /* do not expose to anyone if email is registered or not in the system
        if (empty($accounts)) {
            $top_message = array(
Пример #12
0
<?php

cw_load("image");
if (!$addons['magnifier']) {
    return;
}
$zoomer_images_old = cw_query("SELECT * from {$tables['magnifier_images']} WHERE id='" . $product_id . "'");
if (empty($zoomer_images_old)) {
    return;
}
foreach ($zoomer_images_old as $image_old) {
    $folder_with_images = cw_image_dir("Z") . DIRECTORY_SEPARATOR . $product_id . DIRECTORY_SEPARATOR . $image_old['imageid'] . DIRECTORY_SEPARATOR;
    cw_unset($image_old, "imageid");
    $image_old['id'] = $new_product_id;
    $new_imageid = cw_array2insert("magnifier_images", $image_old);
    $new_folder_with_images = cw_image_dir("Z") . DIRECTORY_SEPARATOR . $new_product_id . DIRECTORY_SEPARATOR . $new_imageid . DIRECTORY_SEPARATOR;
    if (!file_exists($new_folder_with_images)) {
        cw_mkdir($new_folder_with_images);
    }
    cw_magnifier_dircpy($folder_with_images, $new_folder_with_images);
}
             $query_data['productcode'] = $v['productcode'];
         }
         if (!cw_query_first_cell("select count(*) from {$tables['product_variants']} where eancode = '{$v['eancode']}'")) {
             $query_data['eancode'] = $v['eancode'];
         }
         //if ($v['mpn']=='' || !cw_query_first_cell("select count(*) from $tables[product_variants] where mpn = '$v[mpn]'"))
         $query_data['mpn'] = $v['mpn'];
         cw_array2update('product_variants', $query_data, "variant_id = '{$k}'");
         cw_price_lists_replace_price($product_id, $v['price'], $k, false, $v['is_manual_price']);
         $v['variant_id'] = $k;
         $v['product_id'] = $product_id;
         $v['warehouse_customer_id'] = 0;
         cw_array2insert('products_warehouses_amount', $v, 1, array('product_id', 'avail', 'avail_ordered', 'avail_sold', 'avail_reserved', 'variant_id', 'warehouse_customer_id'));
         cw_call('cw_warehouse_recalculate', array($product_id));
         if ($ge_id && !$fields['variants'][$k]) {
             cw_unset($query_data, 'productcode');
             while ($pid = cw_group_edit_each($ge_id, 1, $product_id)) {
                 $vid = cw_variants_get_same($k, $pid);
                 if (empty($vid)) {
                     continue;
                 }
                 cw_array2update('product_variants', $query_data, "variant_id = '{$vid}'");
                 cw_price_lists_replace_price($pid, $v['price'], $vid, false, $v['is_manual_price']);
                 if ($def_variant == $k) {
                     cw_array2update('product_variants', array('def' => ''), "product_id = '{$pid}'");
                     cw_array2update('product_variants', array('def' => 'Y'), "product_id = '{$pid}' and variant_id='{$vid}'");
                 }
             }
         }
     }
 }
Пример #14
0
                    $recipients[] = $v['email'];
                }
            }
        }
    }
}
// Cleanup or translate anonymous emails
foreach ($recipients as $k => $v) {
    if (cw_is_anonymous($v)) {
        if (defined('NEWS_SEND_TO_ANONYMOUS') && constant('NEWS_SEND_TO_ANONYMOUS')) {
            $recipients[$k] = cw_real_mail_address($v);
        } else {
            unset($recipients[$k]);
        }
    }
}
$recipients = array_unique($recipients);
if (count($recipients) > 0) {
    cw_call('cw_spam', array($message, $recipients, $list_lng, $list_id));
    if (!$do_not_update_status) {
        db_query("UPDATE {$tables['newsletter']} SET status = 'S', send_date = '" . time() . "' WHERE news_id = '{$message['news_id']}'");
    }
}
if (!empty($limit) && count($recipients) > 0) {
    $news_send_data[$messageid]['lastpos'] += count($recipients);
    if ($news_send_data[$messageid]['lastpos'] >= $news_send_data[$messageid]['count']) {
        cw_unset($news_send_data, $messageid);
        return;
    }
    cw_html_location("index.php?target={$target}&mode=messages&list_id={$list_id}&messageid={$messageid}&action=send_continue", $config['news']['news_sleep_interval']);
}
         $GLOBALS[$__avar] = cw_stripslashes_sybase($GLOBALS[$__avar]);
         $GLOBALS[$__avar] = cw_addslashes($GLOBALS[$__avar]);
     } else {
         $GLOBALS[$__avar] = cw_addslashes_keys($GLOBALS[$__avar]);
     }
     foreach ($GLOBALS[$__avar] as $__var => $__res) {
         if (cw_allowed_var($__var)) {
             global ${$__var};
             // Only admin scripts and "html_*" vars are trusted until addons init.
             // Add your html_* vars into $cw_trusted_variables list in addon init to allow HTML tags
             if (APP_AREA != 'admin' && strpos($__var, 'html_') !== 0) {
                 $__res = cw_strip_tags($__res);
             }
             $GLOBALS[$__avar][$__var] = ${$__var} = $request_prepared[$__var] = $__res;
         } else {
             cw_unset($GLOBALS[$__avar], $__var);
         }
     }
     reset($GLOBALS[$__avar]);
 }
 foreach ($_FILES as $__name => $__value) {
     if (!cw_allowed_var($__name)) {
         continue;
     }
     ${$__name} = $__value['tmp_name'];
     foreach ($__value as $__k => $__v) {
         $__varname_ = $__name . "_" . $__k;
         if (!cw_allowed_var($__varname_)) {
             continue;
         }
         $request_prepared[$__varname_] = $__v;
function cw_get_product_variants($product_id, $membership_id = 0, $area = false)
{
    global $tables, $current_area, $current_language, $keys, $cart, $user_account, $addons, $user_account;
    cw_load('files', 'taxes');
    $keys = cw_get_hash_options($product_id);
    if ($area === false) {
        $area = $current_area;
    }
    if ($area != 'C' || !$addons['wholesale_trading']) {
        $products_prices_membership = "= 0";
    } else {
        $products_prices_membership = "IN (0, '{$user_account['membership_id']})')";
    }
    $fields[] = "{$tables['products_warehouses_amount']}.avail";
    $fields[] = "{$tables['products_warehouses_amount']}.avail_ordered";
    $fields[] = "{$tables['products_warehouses_amount']}.avail_sold";
    $fields[] = "{$tables['products_warehouses_amount']}.avail_reserved";
    if ($current_area == 'C') {
        $sql = "SELECT {$tables['product_variants']}.*, {$tables['products_prices']}.price, IF({$tables['products_images_var']}.id IS NULL, '', 'Y') as is_image, {$tables['products_images_var']}.image_path as image_path_W, " . implode(", ", $fields) . " FROM {$tables['product_variants']} LEFT JOIN {$tables['products_prices']} ON {$tables['product_variants']}.product_id = {$tables['products_prices']}.product_id AND {$tables['products_prices']}.variant_id = {$tables['product_variants']}.variant_id AND {$tables['products_prices']}.membership_id {$products_prices_membership} AND {$tables['products_prices']}.quantity = 1 LEFT JOIN {$tables['products_warehouses_amount']} on {$tables['products_warehouses_amount']}.product_id={$tables['product_variants']}.product_id and {$tables['products_warehouses_amount']}.variant_id={$tables['product_variants']}.variant_id and {$tables['products_warehouses_amount']}.warehouse_customer_id='" . (AREA_TYPE == 'P' ? $user_account['warehouse_customer_id'] : 0) . "' LEFT JOIN {$tables['products_images_var']} ON {$tables['products_images_var']}.id = {$tables['product_variants']}.variant_id WHERE {$tables['product_variants']}.product_id = '{$product_id}' GROUP BY {$tables['product_variants']}.variant_id";
    } else {
        $sql = "SELECT {$tables['product_variants']}.*, {$tables['products_prices']}.price, IF({$tables['products_images_var']}.id IS NULL, '', 'Y') as is_image, {$tables['products_images_var']}.image_path as image_path_W, " . implode(", ", $fields) . " FROM {$tables['product_variants']} LEFT JOIN {$tables['products_prices']} ON {$tables['product_variants']}.product_id = {$tables['products_prices']}.product_id AND {$tables['products_prices']}.variant_id = {$tables['product_variants']}.variant_id LEFT JOIN {$tables['products_warehouses_amount']} on {$tables['products_warehouses_amount']}.product_id={$tables['product_variants']}.product_id and {$tables['products_warehouses_amount']}.variant_id={$tables['product_variants']}.variant_id and {$tables['products_warehouses_amount']}.warehouse_customer_id='" . (AREA_TYPE == 'P' ? $user_account['warehouse_customer_id'] : 0) . "' LEFT JOIN {$tables['products_images_var']} ON {$tables['products_images_var']}.id = {$tables['product_variants']}.variant_id WHERE {$tables['product_variants']}.product_id = '{$product_id}' GROUP BY {$tables['product_variants']}.variant_id";
    }
    $variants = cw_query_hash($sql, 'variant_id', false);
    if (!$variants) {
        return false;
    }
    if ($area == 'C') {
        # Check variants' items
        $counts = cw_query_column("SELECT COUNT({$tables['product_variant_items']}.option_id) FROM {$tables['product_variant_items']}, {$tables['product_variants']}, {$tables['product_options_values']}, {$tables['product_options']} WHERE {$tables['product_variant_items']}.variant_id = {$tables['product_variants']}.variant_id AND {$tables['product_variants']}.product_id = '{$product_id}' AND {$tables['product_variant_items']}.option_id = {$tables['product_options_values']}.option_id AND {$tables['product_options']}.product_option_id= {$tables['product_options_values']}.product_option_id AND {$tables['product_options_values']}.avail = 1 AND {$tables['product_options']}.avail = 1 GROUP BY {$tables['product_variant_items']}.variant_id");
        if (empty($counts) || count($counts) < count($variants)) {
            return false;
        } else {
            $counts = array_unique($counts);
            if (count($counts) != 1) {
                return false;
            }
        }
        $chains = cw_query_hash("SELECT {$tables['product_variant_items']}.* FROM {$tables['product_variant_items']}, {$tables['product_variants']}, {$tables['product_options_values']}, {$tables['product_options']} WHERE {$tables['product_variant_items']}.variant_id = {$tables['product_variants']}.variant_id AND {$tables['product_variants']}.product_id = '{$product_id}' AND {$tables['product_variant_items']}.option_id = {$tables['product_options_values']}.option_id AND {$tables['product_options']}.product_option_id = {$tables['product_options_values']}.product_option_id AND {$tables['product_options_values']}.avail = 1 AND {$tables['product_options']}.avail = 1", "variant_id", true, true);
    } else {
        $chains = cw_query_hash("SELECT {$tables['product_variant_items']}.* FROM {$tables['product_variant_items']}, {$tables['product_variants']}, {$tables['product_options_values']} WHERE {$tables['product_variant_items']}.variant_id = {$tables['product_variants']}.variant_id AND {$tables['product_variants']}.product_id = '{$product_id}' AND {$tables['product_variant_items']}.option_id = {$tables['product_options_values']}.option_id", "variant_id", true, true);
    }
    if (empty($chains)) {
        return false;
    }
    # Get variants' wholesale prices
    $prices = array();
    if ($addons['wholesale_trading']) {
        $products_prices_membership = "";
        $min_amount = 1;
        if ($area == 'C') {
            $min_amount = intval(cw_query_first_cell("SELECT min_amount FROM {$tables['products']} WHERE product_id = '{$product_id}'"));
            $products_prices_membership = "AND membership_id IN (0, '{$user_account['membership_id']}')";
        }
        $prices = cw_query_hash("select *, price from {$tables['products_prices']} as pps where pps.product_id = '{$product_id}' AND pps.variant_id > 0 {$products_prices_membership} GROUP BY variant_id, quantity, membership_id ORDER BY quantity", "variant_id");
        if (!empty($prices)) {
            foreach ($prices as $vid => $ps) {
                $last_key = false;
                foreach ($ps as $pid => $p) {
                    cw_unset($ps[$pid], "product_id");
                    if ($last_key !== false) {
                        $ps[$last_key]['next_quantity'] = $p['quantity'];
                        if ($area == 'C') {
                            if ($min_amount > $ps[$last_key]['next_quantity']) {
                                unset($ps[$last_key]);
                            } elseif ($min_amount > $ps[$last_key]['quantity']) {
                                $ps[$last_key]['quantity'] = $min_amount;
                            }
                        }
                    }
                    $last_key = $pid;
                }
                if (empty($ps)) {
                    unset($prices[$vid]);
                    continue;
                }
                $ps[$pid]['next_quantity'] = 0;
                $prices[$vid] = $ps;
            }
        }
    }
    $product = cw_query_first("SELECT product_id, free_shipping, shipping_freight, distribution, free_tax FROM {$tables['products']} WHERE product_id='{$product_id}'");
    $taxes = cw_get_product_tax_rates($product, $user_account);
    foreach ($variants as $kv => $variant) {
        # Get references to option array
        if (empty($chains[$kv])) {
            if ($area == "C") {
                unset($variants[$kv]);
            }
            continue;
        }
        # Get wholesale prices
        if (isset($prices[$kv])) {
            $variants[$kv]['wholesale'] = $prices[$kv];
            $variants[$kv]['wholesale'][0]['price'] = $variant['price'];
            unset($prices[$kv]);
            if ($area == 'C') {
                $last_price = $variant['price'];
                foreach ($variants[$kv]['wholesale'] as $wpk => $wpv) {
                    if ($wpv['price'] > $last_price) {
                        unset($variants[$kv]['wholesale'][$wpk]);
                        continue;
                    }
                    $last_price = $wpv['price'];
                }
                if (empty($variants[$kv]['wholesale'])) {
                    unset($variants[$kv]['wholesale']);
                } else {
                    $variants[$kv]['wholesale'] = array_values($variants[$kv]['wholesale']);
                }
            }
        }
        if ($area == "C") {
            if ($variant['is_image'] == 'Y') {
                $variants[$kv]['image'] = cw_image_get('products_images_var', $kv);
            }
            # Get variant's tax rates
            $_taxes = cw_tax_price($variant['price'], 0, true, NULL, "", $taxes);
            $variants[$kv]['taxed_price'] = $_taxes['taxed_price'];
            if (!empty($_taxes['taxes'])) {
                $variants[$kv]['taxes'] = $_taxes['taxes'];
            }
            if (!empty($variants[$kv]['wholesale'])) {
                # Get variant's wholesale prices' tax rates
                foreach ($variants[$kv]['wholesale'] as $k => $v) {
                    $_taxes = cw_tax_price($v['price'], 0, true, NULL, "", $taxes);
                    $variants[$kv]['wholesale'][$k]['taxed_price'] = $_taxes['taxed_price'];
                    if (!empty($_taxes['taxes'])) {
                        $variants[$kv]['wholesale'][$k]['taxes'] = $_taxes['taxes'];
                    }
                }
            }
            if (!empty($cart['products']) && is_array($cart['products'])) {
                foreach ($cart['products'] as $v) {
                    if ($v['product_id'] != $product_id) {
                        continue;
                    }
                    if ($kv == cw_get_variant_id($v['options'], $product_id)) {
                        $variants[$kv]['avail'] -= $v['amount'];
                    }
                }
            }
        } elseif ($variant['is_image'] == 'Y') {
            $variants[$kv]['image'] = cw_image_get('products_images_var', $kv);
        }
        $variants[$kv]['options'] = array();
        foreach ($chains[$kv] as $oid) {
            $variants[$kv]['options'][$oid] = $keys[$oid];
        }
        if (empty($variants[$kv]['options']) && $area == "C") {
            unset($variants[$kv]);
            continue;
        }
    }
    return $variants;
}
function cw_unlock($lockname)
{
    global $var_dirs, $_lock_hash;
    if (empty($lockname)) {
        return false;
    }
    if (empty($_lock_hash[$lockname])) {
        return false;
    }
    $fname = $var_dirs['tmp'] . DIRECTORY_SEPARATOR . $lockname;
    if (!file_exists($fname)) {
        return false;
    }
    $fp = fopen($fname, "r");
    if (!$fp) {
        return false;
    }
    $tmp = fread($fp, 43);
    fclose($fp);
    $file_id = substr($tmp, 0, 32);
    $file_time = substr($tmp, 32);
    if ($file_id == $_lock_hash[$lockname]) {
        @unlink($fname);
    }
    cw_unset($_lock_hash, $lockname);
    return true;
}
Пример #18
0
     $top_message = array('content' => $fillerror, 'type' => 'E');
     $saved_category = $category_update;
     if ($file_upload_data['categories_images_thumb']) {
         $file_upload_data['categories_images_thumb']['is_redirect'] = false;
         $saved_category['image'] = $file_upload_data['categories_images_thumb'];
     }
     cw_header_location("index.php?target={$target}&mode={$mode}&cat={$cat}&ge_id={$ge_id}");
 }
 if ($mode == 'add') {
     $cat = cw_array2insert('categories', array('parent_id' => $cat));
     cw_category_update_path($cat);
 }
 $update_fields = array('category', 'description', 'featured', 'order_by', 'short_list');
 array_push($update_fields, 'meta_descr', 'meta_keywords');
 if ($edited_language != $config['default_admin_language']) {
     cw_unset($update_fields, 'category', 'description');
 }
 cw_array2update('categories', $category_update, "category_id='{$cat}'", $update_fields);
 cw_category_update_status($cat, $category_update['status']);
 cw_category_update_path($cat);
 cw_membership_update('categories', $cat, $category_update['membership_ids'], 'category_id');
 $category_lng = array();
 $category_lng['code'] = $edited_language;
 $category_lng['category_id'] = $cat;
 $category_lng['category'] = $category_update['category'];
 $category_lng['description'] = $category_update['description'];
 cw_array2insert('categories_lng', $category_lng, true, array('code', 'category_id', 'category', 'description'));
 if (cw_image_check_posted($file_upload_data['categories_images_thumb'])) {
     cw_image_save($file_upload_data['categories_images_thumb']);
 }
 $parent_categories = cw_category_get_path($cat);
function cw_paypal_pro_payflow_do($post)
{
    global $config;
    $str = array();
    $str['vendor'] = $config['paypal_pro_payflow']['vendor'];
    $str['partner'] = $config['paypal_pro_payflow']['partner'];
    $str['user'] = $config['paypal_pro_payflow']['user'];
    $str['pwd'] = $config['paypal_pro_payflow']['password'];
    $requestid = isset($post['requestid']) ? $post['requestid'] : time();
    cw_unset($post, "requestid");
    if ($config['paypal_pro_payflow']['currency']) {
        $post['currency'] = $config['paypal_pro_payflow']['currency'];
    }
    if (isset($post['invnum'])) {
        $post['invnum'] = $config['paypal_pro_payflow']['prefix'] . $post['invnum'];
    }
    $post['reqconfirmshipping'] = $config['paypal_pro_payflow']['is_confirmed_address'] == 'Y' ? 1 : 0;
    if ($config['paypal_pro_payflow']['page_style']) {
        $post['page_style'] = $config['paypal_pro_payflow']['page_style'];
    }
    if ($config['paypal_pro_payflow']['header_image_url']) {
        $post['hdrimg'] = $config['paypal_pro_payflow']['header_image_url'];
    }
    if (isset($post['notifyurl'])) {
        global $current_location;
        $post['notifyurl'] = $current_location . '/payment/index.php?target=paypal_pro-vendor';
    }
    $str = cw_array_merge($str, $post);
    $data = array();
    foreach ($str as $k => $v) {
        $data[] = strtoupper($k) . "=" . $v;
    }
    #$url = $config['paypal_pro_payflow']['test_mode'] ? "https://pilot-payflowpro.verisign.com:443/transaction" : "https://payflowpro.verisign.com:443/transaction";
    $url = $config['paypal_pro_payflow']['test_mode'] == 'Y' ? "https://pilot-payflowpro.paypal.com:443/" : "https://payflowpro.paypal.com:443/";
    $headers = array("X-VPS-REQUEST-ID" => $requestid, "X-VPS-VIT-CLIENT-CERTIFICATION-ID" => "7894b92104f04ffb4f38a8236ca48db3");
    //cw_log_add('payflow_pro', array('url'=>$url, 'data'=>$data, 'headers'=>$headers));
    # kornev, we are making the implode here - because we don't need the urlencode
    list($headers, $response) = cw_https_request("POST", $url, array(implode('&', $data)), "", "", "application/x-www-form-urlencoded", "", "", "", $headers);
    //cw_log_add('payflow_pro', array('headers'=>$headers, 'response'=>$response));
    if (empty($response)) {
        return array($headers, $response);
    }
    $result = array();
    $tmp = array();
    parse_str($response, $tmp);
    if (empty($tmp) || !is_array($tmp)) {
        return array($headers, $response);
    }
    foreach ($tmp as $k => $v) {
        $result[strtolower($k)] = urldecode($v);
    }
    return array($headers, $response, $result);
}
function cw_attributes_create_attribute($params, $return)
{
    global $current_language, $config, $tables;
    extract($params);
    $language = $language ? $language : $current_language;
    $lng_data = $data;
    if ($attribute_id && $language != $config['default_admin_language']) {
        cw_unset($data, 'name');
    }
    $data['field'] = cw_call('cw_attributes_cleanup_field', array($data['field']));
    if ($attribute_id) {
        $attribute_id = $data['attribute_id'];
        cw_array2update('attributes', $data, "attribute_id='{$attribute_id}'");
    } else {
        $attribute_id = cw_array2insert('attributes', $data, 1);
    }
    cw_func_call('cw_attributes_update_lng', array('attribute_id' => $attribute_id, 'data' => $lng_data, 'language' => $language));
    if (in_array($data['type'], array('selectbox', 'multiple_selectbox'))) {
        # kornev, we should remove not updated attributes;
        if ($config['edit_attribute_options_together'] == 'Y') {
            $existing = cw_query_key("select attribute_value_id from {$tables['attributes_default']} where attribute_id='{$attribute_id}'");
            if (is_array($data['default_value'])) {
                foreach ($data['default_value'] as $v) {
                    cw_call('cw_attributes_update_default_value', array('attribute_id' => $attribute_id, 'data' => $v, 'language' => $language));
                    if ($v['attribute_value_id']) {
                        unset($existing[$v['attribute_value_id']]);
                    }
                }
            }
            if (count($existing)) {
                cw_call('cw_attributes_delete_values', array(array_keys($existing)));
            }
        }
    } else {
        $counter = cw_query_first_cell("select count(*) from {$tables['attributes_default']} where attribute_id='{$attribute_id}'");
        if ($counter == 0) {
            cw_array2insert('attributes_default', array('attribute_id' => $attribute_id));
        }
        $data['attribute_value_id'] = cw_query_first_cell("select attribute_value_id from {$tables['attributes_default']} where attribute_id='{$attribute_id}' and is_default=1");
        $data['value'] = $data['default_value'] ? $data['default_value'] : $data['value'];
        $data['facet'] = $data['default_values']['facet'];
        $data['description'] = $data['default_values']['description'];
        $data['is_default'] = 1;
        unset($data['default_values']);
        # kornev, the text attribute might be multilng, for the other attributes - set the default lng
        if (in_array($data['type'], array('text', 'textarea'))) {
            cw_call('cw_attributes_update_default_value', array($attribute_id, $data, $language));
        } else {
            cw_call('cw_attributes_update_default_value', array($attribute_id, $data, $config['default_admin_language']));
        }
    }
    cw_call('cw_attributes_init');
    return $attribute_id;
}
    $search_data['manufacturers']['substring'] = $posted_data['substring'];
    cw_header_location('index.php?target=' . $target);
}
if ($action == 'details') {
    $rules = array('manufacturer' => '');
    $manufacturer_update['attributes'] = $attributes;
    $fillerror = cw_error_check($manufacturer_update, $rules, 'M');
    if ($fillerror) {
        $top_message = array('content' => $fillerror, 'type' => 'E');
        $saved_manufacturer = $manufacturer_update;
        cw_header_location("index.php?target={$target}&" . ($manufacturer_id ? "manufacturer_id={$manufacturer_id}" : 'mode=add'));
    }
    $to_update = array('manufacturer' => $manufacturer_update['manufacturer'], 'url' => $manufacturer_update['url'], 'descr' => $manufacturer_update['descr'], 'featured' => $manufacturer_update['featured'], 'avail' => $manufacturer_update['avail'], 'orderby' => $manufacturer_update['orderby'], 'show_image' => $manufacturer_update['show_image']);
    $to_update_lng = array('manufacturer_id' => $manufacturer_id, 'code' => $edited_language, 'descr' => $manufacturer_update['descr'], 'manufacturer' => $manufacturer_update['manufacturer']);
    if ($edited_language != $config['default_admin_language'] && $manufacturer_id) {
        cw_unset($to_update, 'manufacturer', 'descr');
    }
    if (!$manufacturer_id) {
        $top_message['content'] = cw_get_langvar_by_name("msg_adm_err_manufacturer_add");
        $manufacturer_id = cw_array2insert('manufacturers', $to_update);
        $to_update_lng['manufacturer_id'] = $manufacturer_id;
    } else {
        $top_message['content'] = cw_get_langvar_by_name("msg_adm_err_manufacturer_upd");
    }
    cw_array2update('manufacturers', $to_update, "manufacturer_id='{$manufacturer_id}' " . $warehouse_condition);
    cw_array2insert('manufacturers_lng', $to_update_lng, true);
    cw_call('cw_attributes_save', array('item_id' => $manufacturer_id, 'item_type' => 'M', 'attributes' => $attributes, 'language' => $edited_language));
    if (cw_image_check_posted($file_upload_data['manufacturer_images'])) {
        cw_image_save($file_upload_data['manufacturer_images'], array('id' => $manufacturer_id));
    }
    cw_cache_clean('manufacturers_all');
function cw_session_unregister($varname, $unset_global = false)
{
    global $APP_SESSION_VARS, $APP_SESSION_UNPACKED_VARS;
    if (empty($varname)) {
        return false;
    }
    cw_unset($APP_SESSION_VARS, $varname);
    cw_unset($APP_SESSION_UNPACKED_VARS, $varname);
    if ($unset_global) {
        cw_unset($GLOBALS, $varname);
    }
}
Пример #23
0
    foreach ($posted_data as $k => $v) {
        if ($k == 0) {
            $is_code_exists = cw_query_first_cell("SELECT COUNT(*) FROM {$tables['map_states']} WHERE code = '{$v['code']}' AND country_code = '{$country}'") > 0;
            if (!$is_code_exists) {
                if ($v['code'] && $v['state']) {
                    $query_data = array('state' => $v['state'], 'code' => $v['code'], 'country_code' => $country);
                    cw_array2insert('map_states', $query_data);
                }
            } else {
                $top_message = array("content" => cw_get_langvar_by_name("msg_adm_warn_states_duplicate"), "type" => "W");
                break;
            }
        } else {
            $is_code_exists = cw_query_first_cell("SELECT COUNT(*) FROM {$tables['map_states']} WHERE code = '{$v['code']}' AND country_code = '{$country}'") > 0;
            if ($is_code_exists) {
                cw_unset($v, "code");
            }
            cw_array2update("map_states", $v, "state_id = '{$k}'");
        }
    }
    cw_header_location("index.php?target={$target}&mode=states&country={$country}" . (!empty($page) ? "&page={$page}" : ""));
}
$search_query = "FROM {$tables['map_states']}, {$tables['map_countries']} LEFT JOIN {$tables['languages']} as lng1 ON lng1.name = CONCAT('country_', {$tables['map_countries']}.code) AND lng1.code = '{$current_language}' LEFT JOIN {$tables['languages']} as lng2 ON lng2.name = CONCAT('country_', {$tables['map_countries']}.code) AND lng2.code = '{$config['default_admin_language']}' WHERE {$tables['map_states']}.country_code={$tables['map_countries']}.code AND {$tables['map_states']}.country_code='{$country}'";
$total_items_in_search = cw_query_first_cell("SELECT COUNT(*) {$search_query}");
if ($total_items_in_search > 0) {
    $navigation = cw_core_get_navigation($target, $total_items_in_search, $page);
    $navigation['script'] = "index.php?target={$target}&mode=states&country={$country}";
    $smarty->assign('navigation', $navigation);
    $states = cw_query("SELECT {$tables['map_states']}.*, IFNULL(lng1.value, lng2.value) as country {$search_query} ORDER BY country_code, state LIMIT {$navigation['first_page']}, {$navigation['objects_per_page']}");
    $smarty->assign('states', $states);
}
Пример #24
0
function cw_doc_update($doc_id, $cart, $old_products = array(), $is_create_user = false)
{
    global $tables, $addons, $config;
    global $app_main_dir;
    $old_doc = cw_call('cw_doc_get', array($doc_id));
    $products = $cart['products'];
    $userinfo = $cart['userinfo'];
    $_extra = $cart['info']['extra'];
    $_extra['tax_info']['taxed_subtotal'] = $cart['info']['display_subtotal'];
    $_extra['tax_info']['taxed_discounted_subtotal'] = $cart['info']['display_discounted_subtotal'];
    $_extra['tax_info']['taxed_shipping'] = $cart['info']['display_shipping_cost'];
    unset($_extra['tax_info']['product_tax_name']);
    $_extra['additional_fields'] = $userinfo['additional_fields'];
    if (!empty($dhl_ext_country)) {
        $is_dhl_shipping = cw_query_first_cell("SELECT COUNT(*) FROM {$tables['shipping']} WHERE shipping_id = '{$cart['shipping_id']}' AND code = 'ARB' AND destination = 'I'") > 0;
        if ($is_dhl_shipping) {
            if (!function_exists("cw_shipper_ARB")) {
                require_once $app_main_dir . '/addons/shipping_dhl/mod_ARB.php';
            } else {
                global $dhl_ext_countries;
            }
            if (empty($dhl_ext_countries)) {
                $dhl_ext_country = false;
            }
        } else {
            $dhl_ext_country = false;
        }
    }
    if (!empty($dhl_ext_country)) {
        $_extra['dhl_ext_country'] = $dhl_ext_country;
    } else {
        cw_unset($_extra, 'dhl_ext_country');
    }
    $applied_taxes = addslashes(serialize($cart['info']['taxes']));
    $cart['info']['extra'] = addslashes(serialize($_extra));
    # kornev, update order information
    cw_doc_update_general($doc_id, $cart);
    # kornev, update calculated information
    $doc_info_id = $cart['info']['doc_info_id'];
    cw_doc_update_info($doc_info_id, $cart['info']);
    cw_doc_update_settings($doc_info_id, $cart['settings']);
    if ($cart['type'] == 'G' && $addons['pos']) {
        cw_doc_update_pos($doc_info_id, $cart['pos']);
    }
    # kornev, update address information
    cw_doc_update_user_information($cart['type'], $doc_info_id, $userinfo, $is_create_user);
    $margin_value = $cart['info']['total'];
    if (is_array($products)) {
        $items = array();
        foreach ($products as $pk => $product) {
            // if used quote
            if ($addons['quote_system'] && isset($cart['info']['quote_doc_id']) && !empty($cart['info']['quote_doc_id'])) {
                $product['item_id'] = null;
            }
            $items[] = cw_call('cw_doc_update_item', array($doc_id, &$product));
            // Calculate margin
            $margin_value = $margin_value - $product['cost'] * $product['amount'];
        }
        $deleted_items = cw_query_column("select item_id from {$tables['docs_items']} where doc_id='{$doc_id}' and item_id not in ('" . implode("','", $items) . "')");
        if ($deleted_items) {
            db_query("delete from {$tables['docs_items']} where item_id in ('" . implode("', '", $deleted_items) . "')");
        }
    }
    $_extras = $cart['info']['extras'];
    // Calculate and save margin
    $shipping_value = $config['General']['include_shipping_in_margin_calc'] == 'Y' ? $cart['info']['display_shipping_cost'] : 0;
    $margin_value = $margin_value - $shipping_value;
    if ($margin_value < 0) {
        $margin_value = 0;
    }
    $_extras['margin_value'] = price_format($margin_value);
    cw_call('cw_doc_place_extras_data', array($doc_id, $_extras));
    cw_load('accounting');
    if ($old_doc['info']['payment_id'] != $cart['info']['payment_id'] || 1) {
        $ready_part = cw_doc_update_quote($doc_id, $cart);
        cw_doc_update_commissions($doc_id, $cart, $ready_part);
    } else {
        cw_doc_update_commissions($doc_id, $cart);
    }
}
         if (!$is_valid) {
             unset($surveys[$sid]);
             continue;
         }
         $count_surveys++;
         if (cw_check_survey_filling($sid)) {
             $surveys[$sid]['is_filled'] = true;
             $count_filled++;
         }
         if (!empty($filled_surveys) && in_array($sid, $filled_surveys) && $v['publish_results'] == 'Y') {
             $id = array_search($sid, $filled_surveys);
             $rid = cw_query_first_cell("SELECT survey_result_id FROM {$tables['survey_results']} WHERE survey_result_id = '{$id}' AND survey_id = '{$sid}'");
             if (!empty($rid)) {
                 $surveys[$sid]['is_view_results'] = true;
             } else {
                 cw_unset($filled_surveys, $id);
             }
         }
         $surveys[$sid]['survey'] = cw_get_languages_alt("survey_name_" . $sid, false, true);
     }
     if (!empty($surveys)) {
         $smarty->assign('surveys', $surveys);
         $smarty->assign('count_surveys', $count_surveys);
         $smarty->assign('count_filled', $count_filled);
         $smarty->assign('count_unfilled', $count_surveys - $count_filled);
     }
 }
 $location[] = array(cw_get_langvar_by_name("lbl_survey_surveys"));
 $smarty->assign('current_main_dir', 'addons');
 $smarty->assign('current_section_dir', 'survey');
 $smarty->assign('main', 'customer_surveys');
Пример #26
0
<?php

cw_load('warehouse', 'image', 'category', 'attributes');
global $products, $product_filter, $search_data, $category_page, $use_search_conditions, $mode, $navigation;
$search_data =& cw_session_register("search_data", array());
$category_page =& cw_session_register('category_page', array());
if (isset($new_search) || defined('FACET_URL') && !$search_data['products']['customer_search']['redirected_to_facet']) {
    // New search requested or
    // Customer puts facet_url directly in address without autoredirect from combination (redirect happens when product filter is used)
    // see addons/clean_urls/init/abstract.php for related flags
    $search_data['products']['customer_search'] = array();
    unset($new_search, $_GET['new_search']);
} else {
    cw_unset($search_data['products']['customer_search'], 'redirected_to_facet');
}
$search_data['products']['customer_search']['flat_search'] = 1;
$search_data['products']['customer_search']['status'] = cw_core_get_required_status($current_area);
$search_data['products']['customer_search']['objects_per_page'] = $category_page['objects_per_page'];
$search_data['products']['customer_search']['sort_field'] = $category_page['sort_field'];
$search_data['products']['customer_search']['sort_direction'] = $category_page['sort_direction'];
$search_data['products']['customer_search']['info_type'] = $product_list_template == 2 ? 8 + 32 + 128 + 256 : 8 + 32 + 128;
# kornev, add product filter
$search_data['products']['customer_search']['info_type'] += 1024;
$search_data['products']['customer_search']['attributes'] = $att;
$use_search_conditions = 'customer_search';
// clean page num for infinite scroll if change display type
if ($config['Appearance']['infinite_scroll'] == 'Y' && !$_GET['page'] && (isset($_GET['items_per_page']) || isset($_GET['sort']) || isset($_GET['sort_direction']) || isset($_GET['set_view']))) {
    $search_data['products'][$use_search_conditions]['page'] = 1;
}
cw_include('include/products/search.php');
if (count($products)) {
Пример #27
0
         $fill_error[$key] = true;
     }
 }
 if (!count($fill_error)) {
     $list_values = $list;
     $list_values['salesman_customer_id'] = '';
     if (AREA_TYPE == 'B') {
         $list['salesman_customer_id'] = $customer_id;
         if ($list['list_id']) {
             $def_val = cw_query_first("select * from {$tables['newslists']} where list_id='" . $list['list_id'] . "'");
             $list_values['avail'] = $def_val['avail'];
         } else {
             $list_values['avail'] = 0;
         }
     }
     cw_unset($list_values, 'list_id');
     if (!empty($list['list_id'])) {
         cw_array2update('newslists', $list_values, "list_id='{$list['list_id']}'");
         $top_message['content'] = cw_get_langvar_by_name("msg_adm_newslist_upd");
     } else {
         $list_values['lngcode'] = empty($edit_lng) ? $current_language : $edit_lng;
         cw_array2insert('newslists', $list_values);
         $list['list_id'] = db_insert_id();
         $top_message['content'] = cw_get_langvar_by_name("msg_adm_newslists_add");
     }
     db_query("delete from {$tables['newslists_memberships']} where list_id='{$list['list_id']}'");
     if (is_array($memberships)) {
         $arr_to_insert = array();
         $arr_to_insert['list_id'] = $list['list_id'];
         foreach ($memberships as $membership_id) {
             $arr_to_insert['membership_id'] = $membership_id;
function cw_product_get($params, $return = null)
{
    extract($params);
    global $customer_id, $customer_id_type, $current_area, $cart, $current_location;
    global $current_language, $tables, $config, $addons;
    cw_load('files', 'taxes', 'tags');
    $lang = $lang ? $lang : $current_language;
    $variant_id = $variant_id ? $variant_id : 0;
    $amount = intval($amount > 0 ? $amount : 1);
    $fields = $from_tbls = $query_joins = $where = array();
    # kornev, merge standart and additional variables
    if ($return) {
        foreach ($return as $saname => $sadata) {
            if (isset(${$saname}) && is_array(${$saname}) && empty(${$saname})) {
                ${$saname} = $sadata;
            }
        }
    }
    $from_tbls[] = 'products';
    $where[] = "{$tables['products']}.product_id='{$id}'";
    # kornev
    # customer area - all of the checkings
    # pos area - not check for membership, just available for sale property
    if (in_array($current_area, array('C'))) {
        $memberships = array(0);
        if ($user_account['membership_id'] > 0) {
            $memberships[] = intval($user_account['membership_id']);
        }
        $where[] = "{$tables['products_memberships']}.membership_id IN (" . join(',', $memberships) . ")";
        $where[] = "{$tables['products_prices']}.quantity <= {$amount} and {$tables['products_prices']}.membership_id in (" . join(',', $memberships) . ")";
        if ($config['Appearance']['categories_in_products'] == '1') {
            $where[] = "{$tables['categories_memberships']}.membership_id IN (" . join(',', $memberships) . ")";
            $query_joins['products_categories'] = array('on' => "{$tables['products_categories']}.product_id = {$tables['products']}.product_id", 'pos' => '0', 'is_straight' => 1);
            $query_joins['categories'] = array('on' => "{$tables['products_categories']}.category_id = {$tables['categories']}.category_id", 'parent' => 'products_categories');
            $query_joins['categories_memberships'] = array('on' => "{$tables['categories_memberships']}.category_id = {$tables['categories']}.category_id", 'parent' => 'categories', 'is_straight' => 1);
        }
        $where[] = "{$tables['products']}.status in ('" . implode("', '", cw_core_get_required_status($current_area)) . "')";
    } elseif (in_array($current_area, array('G'))) {
        $where[] = "{$tables['products']}.product_id = {$tables['products_prices']}.product_id AND {$tables['products_prices']}.quantity <= {$amount} and {$tables['products_prices']}.membership_id in (" . join(',', $memberships) . ")";
    }
    $fields[] = "{$tables['products']}.*";
    $query_joins['products_warehouses_amount'] = array('on' => "{$tables['products']}.product_id = {$tables['products_warehouses_amount']}.product_id and {$tables['products_warehouses_amount']}.warehouse_customer_id=0 and {$tables['products_warehouses_amount']}.variant_id='{$variant_id}'");
    $in_cart = 0;
    if ($current_area == 'C' && !empty($cart) && !empty($cart['products'])) {
        foreach ($cart['products'] as $cart_item) {
            if ($cart_item['product_id'] == $id) {
                $in_cart += $cart_item['amount'];
            }
        }
    }
    $fields[] = "{$tables['products_warehouses_amount']}.avail-{$in_cart} AS avail";
    # kornev, TOFIX
    if ($addons['product_options'] && in_array($current_area, array('A', 'P'))) {
        $query_joins['product_variants'] = array('on' => "{$tables['products']}.product_id = {$tables['product_variants']}.product_id");
        $fields[] = "IF({$tables['product_variants']}.product_id IS NULL, '', 'Y') as is_variants";
    }
    /*
        if ($addons['manufacturers']) {
            $query_joins['manufacturers'] = array(
                'on' => "$tables[manufacturers].manufacturer_id = $tables[products].manufacturer_id",
            );
            $fields[] = "$tables[manufacturers].manufacturer";
        }
    */
    // statistic
    $fields[] = "{$tables['products_stats']}.views_stats";
    $fields[] = "{$tables['products_stats']}.sales_stats";
    $fields[] = "{$tables['products_stats']}.del_stats";
    $fields[] = "{$tables['products_stats']}.add_to_cart";
    $query_joins['products_stats'] = array('on' => "{$tables['products_stats']}.product_id = {$tables['products']}.product_id");
    if ($current_area == 'A' || $current_area == 'P') {
        $fields[] = "{$tables['products_prices']}.price";
        $fields[] = "{$tables['products_prices']}.list_price";
        $query_joins['products_prices'] = array('on' => "{$tables['products_prices']}.product_id={$tables['products']}.product_id AND {$tables['products_prices']}.variant_id = '{$variant_id}' and {$tables['products_prices']}.quantity <= {$amount}");
    } else {
        $query_joins['products_prices'] = array('on' => "{$tables['products_prices']}.product_id={$tables['products']}.product_id", 'is_inner' => 1);
        # kornev, find the min price and select only this record.
        $fields[] = "min({$tables['products_prices']}.price) as price";
        $fields[] = "{$tables['products_prices']}.variant_id";
        $fields[] = "min({$tables['products_prices']}.list_price) as list_price";
    }
    $fields[] = "IF({$tables['products_lng']}.product_id != '', {$tables['products_lng']}.product, {$tables['products']}.product) as product";
    $fields[] = "IF({$tables['products_lng']}.product_id != '', {$tables['products_lng']}.descr, {$tables['products']}.descr) as descr";
    $fields[] = "IF({$tables['products_lng']}.product_id != '', {$tables['products_lng']}.fulldescr, {$tables['products']}.fulldescr) as fulldescr";
    $fields[] = "IF({$tables['products_lng']}.product_id != '', {$tables['products_lng']}.features_text, {$tables['products']}.features_text) as features_text";
    $fields[] = "IF({$tables['products_lng']}.product_id != '', {$tables['products_lng']}.specifications, {$tables['products']}.specifications) as specifications";
    $query_joins['products_lng'] = array('on' => "{$tables['products_lng']}.code='{$lang}' AND {$tables['products_lng']}.product_id = {$tables['products']}.product_id");
    if (in_array($current_area, array('C', 'G', 'S'))) {
        $fields[] = "{$tables['products_flat']}.*";
        $query_joins['products_flat'] = array('on' => "{$tables['products']}.product_id = {$tables['products_flat']}.product_id");
        if ($current_area == 'C') {
            $query_joins['products_memberships'] = array('on' => "{$tables['products_memberships']}.product_id = {$tables['products']}.product_id", 'is_inner' => 1);
        }
    }
    if ($config['Appearance']['categories_in_products'] == '1') {
        $fields[] = "{$tables['products_categories']}.category_id";
        $query_joins['categories'] = array('parent' => 'products_categories', 'on' => "{$tables['categories']}.category_id = {$tables['products_categories']}.category_id");
        $query_joins['products_categories'] = array('on' => "{$tables['products_categories']}.product_id = {$tables['products']}.product_id and {$tables['products_categories']}.main=1", 'pos' => '0', 'is_straight' => 1);
    }
    $fields[] = "{$tables['products']}.product_id";
    $query = cw_db_generate_query($fields, $from_tbls, $query_joins, $where, array("{$tables['products']}.product_id"), array(), array());
    $product = cw_query_first($query);
    # Error handling
    if (!$product || $current_area == 'C' && !$product['category_id'] && $config['Appearance']['categories_in_products'] == '1') {
        return false;
    }
    $product['system'] = cw_call('cw_product_get_system_info', array($product['product_id']));
    $product['attribute_class_ids'] = cw_func_call('cw_items_attribute_classes_get', array('item_id' => $product['product_id'], 'item_type' => 'P', 'for_product_modify' => $for_product_modify));
    if ($info_type & 1) {
        $product['membership_ids'] = cw_query_key("select membership_id from {$tables['products_memberships']} where product_id = '{$product['product_id']}'");
    }
    # kornev, TOFIX
    if ($info_type & 64 && $product['variant_id'] && $addons['product_options']) {
        $tmp = cw_query_first("SELECT * FROM {$tables['product_variants']} WHERE variant_id = '{$product['variant_id']}'");
        if (!empty($tmp)) {
            cw_unset($tmp, "def");
            $product = cw_array_merge($product, $tmp);
        } else {
            cw_unset($product, 'variant_id');
        }
    }
    if ($info_type & 128) {
        cw_load('image');
        $product['image_thumb'] = cw_image_get('products_images_thumb', $id);
    }
    if ($info_type & 512) {
        $product['image_det'] = cw_image_get('products_images_det', $id);
        # kornev, TOFIX
        if (in_array($current_area, array('C', 'B')) && $product['variant_id'] && $addons['product_options']) {
            $var_image = cw_image_get('products_images_var', $id);
            if (!$var_image['is_default']) {
                $product['image_det'] = $var_image;
            }
        }
    }
    # TOFIX
    if (in_array($current_area, array('C', 'B', 'G'))) {
        if (!$addons['egoods']) {
            $product['distribution'] = '';
        }
        $product['display_price'] = $product['price'];
        if ($current_area == 'C' && $info_type & 8) {
            $_tmp_price = $product['price'];
            $product['price'] = $product['list_price'];
            cw_get_products_taxes($product, $user_account);
            $product['list_price_net'] = $product['list_price'];
            $product['list_price'] = $product['taxed_price'];
            $product['price'] = $_tmp_price;
        }
        $product['taxes'] = cw_get_products_taxes($product, $user_account, false, '', $current_area == 'G' && $user_account['usertype'] != 'R');
    }
    if (in_array($current_area, array('C', 'B'))) {
        $product['descr'] = cw_eol2br($product['descr']);
        $product['fulldescr'] = cw_eol2br($product['fulldescr']);
    }
    $product['uns_shippings'] = unserialize($product['shippings']);
    $product['tags'] = cw_tags_get_product_tags($id);
    if ($info_type & 4096 && $product['warranty_id']) {
        $wr = cw_get_warranty($product['warranty_id'], $lang);
        $product['warranties'] = $wr['body'];
    }
    // TODO: move to addon as on_product_get handler
    if ($info_type & 8192) {
        cw_load('warehouse');
        if ($addons['warehouse']) {
            if (AREA_TYPE == 'A') {
                $product['avail_ordered'] = cw_warehouse_get_avail($id, 0, 'avail_ordered');
                $product['avail_sold'] = cw_warehouse_get_avail($id, 0, 'avail_sold');
                $product['avail_reserved'] = cw_warehouse_get_avail($id, 0, 'avail_reserved');
            } elseif (AREA_TYPE == 'P') {
                $product['avail'] = cw_warehouse_get_warehouse_avail($customer_id, $id);
                $product['avail_ordered'] = cw_warehouse_get_warehouse_avail($customer_id, $id, 'avail_ordered');
            } else {
                // TOFIX:  $product['avail'] becomes different meanings when info_type & 8192 flag is raised or not
                // without flag - avail of all variants without products already in cart
                // with flag - total avail as set in admin per variant
                //                $product['avail'] = cw_warehouse_get_avail_for_customer($id, $product['variant_id']);
                //                $product['avails']= cw_warehouse_get_avails_customer($id);
                $product['avail'] = cw_warehouse_get_avail_for_customer($id, $product['variant_id']);
            }
        } else {
            $product['avails'] = cw_warehouse_get_avails_customer($id, $product['avail'] + $product['avail_ordered']);
        }
    }
    return $product;
}
Пример #29
0
}
$image_type = '';
$image_path = '';
$image_size = 0;
if (isset($_GET['tmp'])) {
    $file_upload_data =& cw_session_register('file_upload_data', array());
    if ($available_images[$type]['multiple'] && is_array($file_upload_data)) {
        if ($file_upload_data[$type][$imgid]) {
            $image_posted = $file_upload_data[$type][intval($imgid)];
        }
    } else {
        $image_posted = $file_upload_data[$type];
    }
    if (!empty($image_posted)) {
        if ($image_posted['date'] == 0 || time() - $image_posted['date'] > USE_SESSION_LENGTH) {
            cw_unset($file_upload_data, $type);
            unset($image_posted);
        } elseif (!empty($image_posted['file_path']) && $image_posted['id'] == $id && $image_posted['type'] == $type) {
            $image_type = $image_posted['image_type'];
            $image_path = $image_posted['file_path'];
            $image_type = $image_posted['image_type'];
            $image_size = $image_posted['file_size'];
        }
    }
}
$orig_type = $type;
if (zerolen($image_path) && isset($available_images[$type]) && !empty($tables[$type]) && !empty($id)) {
    $hash_types = array();
    $i = 0;
    $max_attempts = 1;
    while ($i++ < $max_attempts) {
Пример #30
0
     if ($group_edit_fields) {
         cw_group_edit_copy($ge_id, 'products_lng', 'product_id', $product_id, $group_edit_fields, "code='{$edited_language}'");
     }
 }
 $product_data['warehouse_customer_id'] = 0;
 if (!$is_variant) {
     cw_array2insert('products_warehouses_amount', $product_data, 1, array('product_id', 'avail', 'avail_ordered', 'avail_sold', 'avail_reserved', 'variant_id', 'warehouse_customer_id'));
 } else {
     cw_call('cw_warehouse_recalculate', array($product_id));
 }
 cw_call('cw_product_update_status', array($product_id, $product_data['status']));
 if ($fields['status']) {
     cw_group_edit_copy_product_status($product_data['status']);
 }
 if ($edited_language != $config['default_admin_language']) {
     cw_unset($query_fields, 'descr', 'fulldescr', 'product', 'features_text', 'specifications');
 }
 if (!$addons['warehouse']) {
     $query_fields[] = 'avail';
 }
 if (!$is_variant) {
     $query_fields[] = 'weight';
 }
 cw_array2update('products', $product_data, "product_id = '{$product_id}'", $query_fields);
 // TODO: move to addon
 if ($addons['faq']) {
     cw_load('faq');
     cw_faq_create_product($product_id);
 }
 if (AREA_TYPE == 'A') {
     cw_insert_product_to_sections($product_id, $ins_sections);