function cw_ps_bundle_update($product_id) { global $tables, $config; $product_id = (int) $product_id; if ($_SERVER['REQUEST_METHOD'] != 'POST') { cw_ps_bundle_redirect($product_id); } $offer_id = cw_call('cw_ps_offer_bundle_update', array($product_id, $_POST)); // Delete selected products if (is_array($_POST['del_cond'])) { foreach ($_POST['del_cond'] as $k => $v) { $k = intval($k); db_query("DELETE FROM {$tables['ps_cond_details']} WHERE offer_id='{$offer_id}' AND object_id='{$k}' AND object_type='" . PS_OBJ_TYPE_PRODS . "'"); db_query("DELETE FROM {$tables['ps_bonus_details']} WHERE offer_id='{$offer_id}' AND object_id='{$k}' AND object_type='" . PS_OBJ_TYPE_PRODS . "'"); } } $cond_products = cw_query_column("SELECT object_id FROM {$tables['ps_cond_details']} WHERE offer_id='{$offer_id}' AND object_type='" . PS_OBJ_TYPE_PRODS . "'"); if (count($cond_products) <= 1) { //delete offer cw_call('cw_ps_offer_delete', array($offer_id)); } cw_array2update('ps_offers', array('auto' => 0), "offer_id='{$offer_id}'"); // TODO: Domain assignation cw_ps_bundle_redirect($product_id); }
function export() { global $REQUEST_METHOD, $smarty, $config, $addons, $top_message, $customer_id, $tables; global $mode, $action, $amazon_config; $success = false; if ($REQUEST_METHOD != 'POST') { cw_header_location('index.php?target=' . addon_target); } if ($_POST['export_type'] == 'PaQ' && (empty($_POST['price']) && empty($_POST['quantity']))) { $top_message = array('content' => 'At least Price or Quantity must be exported.', 'type' => 'E'); cw_header_location('index.php?target=' . addon_target); return false; } $_filename = 'files/amazon/' . date('Ymd') . '_' . date('His') . '_' . $_POST['export_type'] . '.csv'; if (($filename = cw_allow_file($_filename, true)) && ($file = cw_fopen($_filename, 'w', true))) { $pids = cw_call('cw_objects_get_list_ids', array('P')); if (empty($pids)) { $pids = cw_query_column("SELECT product_id FROM {$tables['products']} WHERE status=1"); // Very bad. Use API } if ($pids) { $amazon_config = cw_array_merge($amazon_config, $config['amazon'], $_POST); cw_config_update('amazon', $_POST); $warnings = array(); $data = array(); $header_put = false; foreach ($pids as $v) { $variants = array(); $prod = cw_func_call('cw_product_get', array('id' => $v, 'info_type' => 8 | 64 | 128 | 256 | 512 | 2048)); $attr = cw_query_hash("SELECT a.field, av.value\n FROM {$tables['attributes_values']} av, {$tables['attributes']} a\n WHERE av.item_id={$v} AND av.item_type='P' AND a.attribute_id=av.attribute_id", 'field', false, true); // very bad. Use API if ($prod['is_variants']) { $variants = cw_call('cw_get_product_variants', array($v)); } else { $variants[0] = $prod; } foreach ($variants as $var) { $var = cw_array_merge($var, $attr); if ($_POST['export_type'] == 'PaQ') { $data = array('sku' => $var['productcode'], 'price' => $_POST['price'] ? $var['price'] : '', 'quantity' => $_POST['quantity'] ? $var['avail'] : '', 'leadtime-to-ship' => $amazon_config['default_leadtime_to_ship']); } if ($_POST['export_type'] == 'InvLoad') { $data = array('sku' => $var['productcode'], 'product-id' => empty($amazon_config['product_id_type']) ? '' : (string) $var[$amazon_config['product_id']], 'product-id-type' => $amazon_config['product_id_type'], 'price' => $var['price'], 'item-condition' => empty($var[$amazon_config['item_condition']]) ? $amazon_config['default_item_condition'] : $var[$amazon_config['item_condition']], 'quantity' => empty($amazon_config['fulfillment_center_id']) ? $var['avail'] : '', 'add-delete' => empty($_POST['add-delete']) ? 'a' : $_POST['add-delete'], 'will-ship-internationally' => empty($var[$amazon_config['ship_internationally']]) ? $amazon_config['default_ship_internationally'] : $var[$amazon_config['ship_internationally']], 'expedited-shipping' => empty($var[$amazon_config['expedited_shipping']]) ? $amazon_config['default_expedited_shipping'] : $var[$amazon_config['expedited_shipping']], 'standard-plus' => empty($var[$amazon_config['standard_plus']]) ? $amazon_config['default_standard_plus'] : $var[$amazon_config['standard_plus']], 'item-note' => $var[$amazon_config['item_note']], 'fulfillment-center-id' => $amazon_config['fulfillment_center_id'], 'product-tax-code' => $amazon_config['default_product_tax_code'], 'leadtime-to-ship' => $amazon_config['default_leadtime_to_ship']); } if (!$header_put) { fputcsv($file, array_keys($data), "\t"); $header_put = true; } fputcsv($file, $data, "\t"); } } } fclose($file); $top_message = array('content' => 'File <b>' . $_filename . '</b> successfully created'); } cw_header_location('index.php?target=' . addon_target); }
function cw_file_area_delete_list($type, $id, $field = 'customer_id') { global $tables; $list = cw_query_column("select file_id from " . $tables[$type] . " where {$field}='{$id}'"); if (is_array($list)) { foreach ($list as $v) { cw_file_area_delete($type, $v); } } }
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 on_sessions_delete($sess_id) { global $tables; // delete bookmarks of expired non-registered sessions $sess_ids = cw_query_column("SELECT b.sess_id \n\t\tFROM {$tables['bookmarks']} b \n\t\tLEFT JOIN {$tables['sessions_data']} sd ON sd.sess_id = LEFT( b.sess_id, LENGTH( sd.sess_id )) \n\t\tWHERE sd.sess_id IS NULL and b.customer_id=0"); if ($sess_ids) { foreach ($sess_ids as $sess_id) { db_query("delete from {$tables['bookmarks']} where sess_id='{$sess_id}'"); } } }
function cw_web_get_layouts($layout, $like = false) { global $tables; $layouts = cw_query_column("select layout_id from {$tables['layouts']} where layout" . ($like ? ' like ' : ' = ') . "'{$layout}'"); $return = array(); if ($layouts) { foreach ($layouts as $layout_id) { $return[] = cw_web_get_layout_inner("layout_id='{$layout_id}'"); } } return $return; }
function cw_warehouse_get_enabled_for_customer($customer_id) { global $tables; static $cached; if (!isset($cached)) { $is_assigned = cw_query_column("select division_id from {$tables['customers_warehouses']} where customer_id='{$customer_id}'"); $is_enabled = cw_query_column("select division_id from {$tables['warehouse_divisions']} where enabled=1"); if ($is_assigned) { $cached = array_intersect($is_assigned, $is_enabled); } else { $cached = $is_enabled; } } return $cached; }
function cw_addons_get($parent_addon = '') { global $current_language, $tables; $addons = cw_query("select m.*, IFNULL(lng1.value, m.addon) as addon_lng, IFNULL(lng2.value, m.descr) as addon_descr_lng from {$tables['addons']} as m left join {$tables['languages']} as lng1 ON lng1.code = '{$current_language}' and lng1.name = CONCAT('addon_name_', m.addon) left join {$tables['languages']} as lng2 ON lng2.code = '{$current_language}' and lng2.name = CONCAT('addon_descr_', m.addon) where m.parent='{$parent_addon}' order by addon_lng"); $mod_options = cw_query_column("select {$tables['addons']}.addon from {$tables['addons']}, {$tables['config_categories']} where {$tables['addons']}.addon={$tables['config_categories']}.category group by {$tables['addons']}.addon", "addon"); foreach ($addons as $k => $v) { // cw_get_langvar_by_name provides name and descr including tooltip if ($v['addon'] != $v['addon_lng']) { $addons[$k]['addon_lng'] = cw_get_langvar_by_name('addon_name_' . $v['addon']); } if ($v['descr'] != $v['addon_descr_lng']) { $addons[$k]['addon_descr_lng'] = cw_get_langvar_by_name('addon_descr_' . $v['addon']); } if ($parent_id == 0) { $addons[$k]['subaddons'] = cw_addons_get($v['addon']); } if (in_array($v['addon'], $mod_options)) { $addons[$k]['options_url'] = true; } } return $addons; }
function cw_common_tables_diff($conn, $except_of = '') { $comm_tabs = cw_common_tables_names($conn, $except_of); $cv = $xc = ''; foreach ($comm_tabs as $k => $v) { $c = cw_query_column("show create table {$v}", 1); $x = cw_query_column("show create table {$k}", 1, $conn); $cv .= $c[0] . "\n\n"; $xc .= $x[0] . "\n\n"; } $h = fopen("./var/ctc_cv", "w"); fwrite($h, $cv); fclose($h); $h = fopen("./var/ctc_xc", "w"); fwrite($h, $xc); fclose($h); exec("diff -rabEBpd -U 2 ./var/ctc_xc ./var/ctc_cv > ./var/ctc.diff"); }
if ($action == 'delete_one_cat') { $categories_to_delete = array($cat); cw_header_location("index.php?target=categories&cat={$cat}&mode=delete"); } $smarty->assign('js_tab', $js_tab); $featured_types = array('featured_products', 'new_arrivals'); foreach ($featured_types as $tbl) { $products = cw_query("SELECT " . $tables[$tbl] . ".*, {$tables['products']}.product from " . $tables[$tbl] . ", {$tables['products']} where " . $tables[$tbl] . ".product_id={$tables['products']}.product_id AND " . $tables[$tbl] . ".category_id='{$cat}' order by " . $tables[$tbl] . ".product_order"); $smarty->assign($tbl, $products); } $smarty->assign('main', 'categories'); if ($mode == 'delete' && $confirmed != "Y" && is_array($categories_to_delete)) { $subcats = $ids = array(); foreach ($categories_to_delete as $val) { $ids[] = $val; $curr_subcats = cw_query_column("SELECT c.category_id FROM {$tables['categories']} as c, {$tables['categories_parents']} as cp WHERE c.category_id=cp.parent_id and cp.parent_id='{$val}'"); if ($curr_subcats) { $ids = array_merge($ids, $curr_subcats); } } $subcats = cw_query("SELECT category_id, category FROM {$tables['categories']} WHERE category_id in ('" . implode("', '", $ids) . "')"); if (is_array($subcats)) { foreach ($subcats as $k => $v) { # kronev, for the big amount of products - there are no any sense to display it $subcats[$k]['products_count'] = cw_query_first_cell("SELECT count(*) FROM {$tables['products_categories']}, {$tables['products']} WHERE {$tables['products_categories']}.category_id='{$v['category_id']}' AND {$tables['products_categories']}.product_id={$tables['products']}.product_id AND {$tables['products_categories']}.main=1"); // $subcats[$k]['products_count'] = (is_array($subcats[$k]['products']) ? count($subcats[$k]['products']) : 0); } } $smarty->assign('subcats', $subcats); $smarty->assign('main', 'category/delete_confirmation'); } elseif ($mode == 'search') {
function cw_user_get_usertypes() { global $tables; $ut = cw_query_column("SELECT distinct(usertype) FROM {$tables['customers']}"); $result = array(); foreach ($ut as $k => $v) { $result[$v] = cw_get_langvar_by_name('lbl_user_' . $v, null, false, true); if (empty($result[$v])) { $result[$v] = $v . ' usertype'; } } return $result; }
<?php cw_load('addons'); if ($action == 'update' && is_array($upd_addons)) { db_query("update {$tables['addons']} set active='0' where status>'" . constant('ADDON_TYPE_CORE') . "'"); foreach ($upd_addons as $addon => $val) { db_query("update {$tables['addons']} set active='1' where addon='{$addon}'"); } $disabled = cw_query_column("select addon from {$tables['addons']} where active = 0"); db_query("update {$tables['addons']} set active=0 where parent in ('" . implode("', '", $disabled) . "')"); cw_header_location("index.php?target={$target}&mode=addons"); } if ($action == 'ajax_update') { db_query("update {$tables['addons']} set active=abs(active-1) where addon='{$addon}' and status>'" . constant('ADDON_TYPE_CORE') . "'"); $active = cw_query_first_cell("select active from {$tables['addons']} where addon='{$addon}'"); cw_add_ajax_block(array('id' => 'script', 'content' => '$("#' . $addon . '").removeClass("on").removeClass("off").addClass("' . ($active == 1 ? 'on' : 'off') . '");')); cw_add_ajax_block(array('id' => 'script', 'content' => '$("[parent=' . $addon . ']").parent().removeClass("addon_locked")' . ($active == 1 ? '' : '.addClass("addon_locked")') . ';')); } $addon = $_GET['addon']; if (!empty($addon) && $mode == 'addons') { # kornev, TOFIX generally this should be removed if (is_file($app_main_dir . '/addons/' . $addon . '/admin/settings.php')) { cw_include('addons/' . $addon . '/admin/settings.php'); } if ($REQUEST_METHOD == 'POST') { cw_header_location("index.php?target={$target}&mode=addons&addon={$addon}"); } $smarty->assign('addon', $addon); $smarty->assign('addon_name', cw_get_langvar_by_name('addon_name_' . $addon)); $location[] = array(cw_get_langvar_by_name('lbl_addons'), 'index.php?target=' . $target); $location[] = array($addon, '');
function cw_salesman_get_commission($products, $salesman, $membership_id, $doc_id, $warehouse, $applied_coupon = '', $applied_discount = '', $part = 100) { global $tables; $salesman_commission_value = 0; $salesman_plan = cw_query_first_cell($sql = "SELECT {$tables['salesman_commissions']}.plan_id FROM {$tables['salesman_commissions']}, {$tables['salesman_plans']}, {$tables['customers']} WHERE {$tables['salesman_commissions']}.plan_id={$tables['salesman_plans']}.plan_id AND {$tables['salesman_commissions']}.salesman_customer_id='{$salesman}' AND {$tables['customers']}.customer_id='{$salesman}' AND {$tables['customers']}.status='Y' AND {$tables['customers']}.status='Y' AND {$tables['salesman_plans']}.status=1"); if ($salesman_plan) { $tmp = cw_query("SELECT * FROM {$tables['salesman_plans_commissions']} WHERE plan_id='{$salesman_plan}' and membership_id='" . $membership_id . "'"); $plan_info = array(); if ($tmp) { foreach ($tmp as $v) { $plan_info[$v['item_type'] . ($v['item_id'] > 0 ? $v['item_id'] : "")] = array("commission_type" => $v['commission_type'], "commission" => $v['commission']); } } unset($tmp); $products_hash = array(); foreach ($products as $k => $product) { $percent_cost = $product['discounted_price'] / 100; unset($to_salesman); if ($plan_info["P" . $product['product_id']]) { $to_salesman = $plan_info["P" . $product['product_id']]['commission'] * ($plan_info["P" . $product['product_id']]['commission_type'] == '$' ? $product['amount'] : $percent_cost); } # # Check the categories commission rate # if (!isset($to_salesman)) { $product_categories = cw_query_column("SELECT category_id FROM {$tables['products_categories']} WHERE product_id='{$product['product_id']}'"); foreach ($product_categories as $category_id) { if (!isset($plan_info["C" . $category_id])) { continue; } $tmp = $plan_info["C" . $category_id]['commission'] * ($plan_info["C" . $category_id]['commission_type'] == '$' ? $product['amount'] : $percent_cost); if ($tmp > $to_salesman) { $to_salesman = $tmp; } } } # # Apply general value of the commission rate # if (!isset($to_salesman) && $plan_info['G']) { $to_salesman = $plan_info['G']['commission'] * ($plan_info['G']['commission_type'] == '$' ? 1 : $percent_cost); } $salesman_commission_value += price_format($to_salesman); $products_hash[$product['item_id']] = price_format($to_salesman); } # kornev, the comission can be calculated partially, if the order is paid partially $salesman_commission_value = $salesman_commission_value * $part / 100; # kornev, calculate the next levels only if we placed an order # kornev, the level calculation has been changed. The comission is devided by the levels. if ($salesman_commission_value && $doc_id) { # kornev, if discount is taken from the salesman account if (cw_is_salesman_coupon($applied_coupon)) { $from_account = cw_query_first_cell("select from_account from {$tables['discount_coupons']} where coupon='{$applied_coupon}'"); if ($from_account) { $salesman_commission_value -= $applied_discount; } //cw_get_salesman_discount($products, $applied_coupon, $membership_id, $warehouse); } $salesman_level = cw_get_affiliate_level($salesman); $parents = array(); $parents[] = array('customer_id' => $salesman, 'level' => $salesman_level); $__parents = cw_get_parents($salesman); if (is_array($__parents)) { $parents = array_merge($parents, $__parents); } $div_commission_value = $salesman_commission_value; foreach ($parents as $v) { $level = $v['level']; if ($div_commission_value <= 0) { continue; } $percent = cw_query_first_cell("SELECT commission FROM {$tables['salesman_tier_commissions']} WHERE level = '{$level}'"); $commission = price_format($div_commission_value * $percent / 100); $div_commission_value -= $commission; if ($commission > 0) { db_query("INSERT INTO {$tables['salesman_payment']} (salesman_customer_id, doc_id, commissions, paid, affiliate, add_date) VALUES ('{$v['customer_id']}', '{$doc_id}', '{$commission}', 'N', '{$salesman}', '" . (isset($xaff_force_time) ? $xaff_force_time : time()) . "')"); foreach ($products_hash as $id => $c) { $c = price_format($c * $percent / 100); db_query("INSERT INTO {$tables['salesman_product_commissions']} (item_id, doc_id, product_commission, salesman_customer_id) VALUES ('{$id}', '{$doc_id}', '{$c}','{$v['customer_id']}')"); $products_hash[$id] -= $c; } } } } } return $salesman_commission_value; }
$discountbundles_pids = cw_query_column("SELECT objid FROM {$tables['bonuses']} b, {$tables['bonus_conditions']} bc WHERE b.pid='{$product_added}' AND b.bonusid=bc.bonusid AND bc.type='P'"); $pids_query['where'][] = $tables['products'] . ".productid IN ('" . implode($discountbundles_pids, "','") . "')"; $added_products = cw_search_products($pids_query, $userinfo['membershipid']); } else { $added_products[] = cw_select_product($product_added, $userinfo['membershipid']); } #cw_print_r($also_products); $smarty->assign('product_added', $product_added); $smarty->assign('added_products', $added_products); $smarty->assign('also_products', $also_products); unset($addons["Fast_Lane_Checkout"]); include $xcart_dir . "/addons/Promotion_Suite/recently_viewed.php"; } if ($mode == 'add' && !empty($productid) && $discountbundles == '1') { $minimal_amount = cw_query_first_cell("SELECT min_amount FROM {$tables['products']} WHERE productid='{$productid}'"); $amount = max($amount, $minimal_amount); $discountbundles_pids = cw_query_column("SELECT objid FROM {$tables['bonuses']} b, {$tables['bonus_conditions']} bc WHERE b.pid='{$productid}' AND b.bonusid=bc.bonusid AND bc.type='P' AND bc.objid!='{$productid}'"); foreach ($discountbundles_pids as $pid) { # # Add product to the cart # $add_product = array(); $add_product["productid"] = $pid; $minimal_amount = cw_query_first_cell("SELECT min_amount FROM {$tables['products']} WHERE productid='{$pid}'"); $add_product["amount"] = max(1, $minimal_amount); $add_product["product_options"] = ""; $add_product["special_offer"]["bundle_pid"] = $productid; $result = cw_add_to_cart($cart, $add_product); } } // CartWorks.com - Promotion Suite
function cw_shipper($weight, $address, $debug = "N", $cart = false) { global $allowed_shipping_methods, $rates; global $tables; global $config; $__intershipper_userinfo = $address; $rates = array(); $intershipper_countries = array('IE' => 'IR', 'VA' => 'IT', 'FX' => 'FR', 'PR' => 'US'); # # Intershipper depends on XML parser (EXPAT extension) # if (test_expat() == "") { return; } if (empty($address)) { if ($config['General']['apply_default_country'] == "Y" || $debug == "Y") { $__intershipper_userinfo = cw_user_get_default_address(); } else { return array(); } } $pounds = cw_weight_in_grams($weight) / 453; $pounds = sprintf("%.2f", round((double) $pounds + 9.999999999999999E-12, 2)); if ($pounds < 0.1) { $pounds = 0.1; } $servername = "www.intershipper.com"; $scriptname = "/Shipping/Intershipper/XML/v2.0/HTTP.jsp"; $username = $config['Shipping']['intershipper_username']; $password = $config['Shipping']['intershipper_password']; $delivery = $params['param00']; $shipmethod = $params['param01']; $CO = $config['Company']['country']; $ZO = urlencode($config['Company']['zipcode']); $CD = $__intershipper_userinfo['country']; $ZD = urlencode($__intershipper_userinfo['zipcode']); if (!empty($intershipper_countries[$CD])) { $CD = $intershipper_countries[$CD]; } if (!empty($intershipper_countries[$CO])) { $CO = $intershipper_countries[$CO]; } $__intershipper_userinfo['country'] = $CD; $config['Company']['country'] = $CO; $length = (double) $params['param02']; $width = (double) $params['param03']; $height = (double) $params['param04']; $dunit = $params['param05']; $packaging = $params['param06']; $contents = $params['param07']; $codvalue = (double) $params['param08']; $insvalue = (double) $params['param09']; $queryid = substr(uniqid(rand()), 0, 15); $wunit = strtoupper(trim($config['General']['weight_symbol'])); if (strlen($wunit) > 2) { $wunit = substr($wunit, 0, 2); } $allowed_shipping_methods = cw_query("SELECT * FROM {$tables['shipping']} WHERE active=1"); $carriers = cw_query_column("SELECT DISTINCT(code) FROM {$tables['shipping']} WHERE code<>'' AND intershipper_code!='' AND active=1"); if (!$carriers || !$username || !$password) { return array(); } $post[] = "Version=2.0.0.0"; $post[] = "ShipmentID=1"; $post[] = "QueryID=1"; $post[] = "Username={$username}"; $post[] = "Password={$password}"; $post[] = "TotalClasses=4"; $post[] = "ClassCode1=GND"; $post[] = "ClassCode2=1DY"; $post[] = "ClassCode3=2DY"; $post[] = "ClassCode4=3DY"; $post[] = "DeliveryType={$delivery}"; $post[] = "ShipMethod={$shipmethod}"; $post[] = "OriginationPostal={$ZO}"; $post[] = "OriginationCountry={$CO}"; $post[] = "DestinationPostal={$ZD}"; $post[] = "DestinationCountry={$CD}"; $post[] = "Currency=USD"; // Currently, supported only "USD". maxlen=3 $post[] = "TotalPackages=1"; $post[] = "BoxID1=box1"; $post[] = "Weight1={$pounds}"; $post[] = "WeightUnit1=LB"; $post[] = "Length1={$length}"; $post[] = "Width1={$width}"; $post[] = "Height1={$height}"; $post[] = "DimensionalUnit1={$dunit}"; // DimensionalUnit ::= CM | IN $post[] = "Packaging1={$packaging}"; // Packaging ::= BOX | ENV | LTR | TUB $post[] = "Contents1={$contents}"; $post[] = "Cod1={$codvalue}"; $post[] = "Insurance1={$insvalue}"; $post[] = "TotalCarriers=" . count($carriers); foreach ($carriers as $k => $v) { if ($v == 'CPC') { $v = 'CAN'; } $post[] = "CarrierCode" . ($k + 1) . "=" . $v; } $query = join('&', $post); $md5_request = md5($query); if (cw_is_shipping_result_in_cache($md5_request) && $debug != "Y") { return cw_get_shipping_result_from_cache($md5_request); } list($header, $result) = cw_http_get_request($servername, $scriptname, $query); $result = preg_replace("/^<\\?xml\\s+[^>]+>/s", "", trim($result)); $parse_errors = false; $options = array('XML_OPTION_CASE_FOLDING' => 1, 'XML_OPTION_TARGET_ENCODING' => 'ISO-8859-1'); $parsed = cw_xml_parse($result, $parse_errors, $options); $destination = $__intershipper_userinfo['country'] == $config['Company']['country'] ? "L" : "I"; $packages =& cw_array_path($parsed, 'SHIPMENT/PACKAGE'); if (is_array($packages)) { $rates = array(); foreach ($packages as $pkginfo) { if (empty($pkginfo['#']) || !is_array($pkginfo['#'])) { continue; } foreach ($pkginfo['#']['QUOTE'] as $quote) { $carrier = cw_array_path($quote, 'CARRIER/CODE/0/#'); if ($carrier == 'USP') { $carrier = 'USPS'; } $service = cw_array_path($quote, 'SERVICE/NAME/0/#'); $sn = cw_array_path($quote, 'SERVICE/CODE/0/#'); $rate = cw_array_path($quote, 'RATE/AMOUNT/0/#') / 100.0; if (!$carrier || !($service || $sn) || !$rate) { continue; } $saved = -1; foreach ($allowed_shipping_methods as $sk => $sv) { if ($sv['code'] != $carrier || $sv['destination'] != $destination) { continue; } if ($sv['intershipper_code'] == 'CPC') { $sv['intershipper_code'] = 'CAN'; } if ((!$sn || $sv['intershipper_code'] != $sn) && (!$service || !stristr($sv['shipping'], $service))) { continue; } # Suppressing duplicates if ($saved < 0 || strlen($allowed_shipping_methods[$saved]['shipping']) > strlen($sv['shipping'])) { $saved = $sk; } } if ($saved >= 0) { $rates[$allowed_shipping_methods[$saved]['subcode']] = $rate; } } } if (!empty($rates)) { foreach ($rates as $k => $v) { $rates[$k] = array("methodid" => $k, "rate" => $v); } if ($debug != "Y") { cw_save_shipping_result_to_cache($md5_request, $rates); } } } return $rates; }
function cw_cron_sessions_delete($time, $prev_time) { global $tables; $expired_session_ids = cw_query_column("SELECT sess_id FROM {$tables['sessions_data']} where expiry<{$time}"); db_query("delete from {$tables['sessions_data']} where expiry<{$time}"); db_query("delete from {$tables['temporary_data']} where expire<{$time}"); // get group edit data of expired sessions $ge_ids = cw_query_column("select {$tables['group_editing']}.ge_id from {$tables['group_editing']} left join {$tables['sessions_data']} on {$tables['group_editing']}.sess_id = {$tables['sessions_data']}.sess_id where {$tables['sessions_data']}.sess_id IS NULL"); if ($ge_ids) { foreach ($ge_ids as $ge_id) { db_query("delete from {$tables['group_editing']} where ge_id='{$ge_id}'"); } } cw_event('on_sessions_delete', array($expired_session_ids)); return count($expired_session_ids) . ' expired sessions were deleted'; }
$tax_details = cw_query_first("SELECT * FROM {$tables['taxes']} WHERE tax_id='{$tax_id}'"); $tax_details['tax_display_name'] = cw_get_languages_alt('tax_' . $tax_id); } if (empty($tax_details)) { $mode = "add"; if (cw_session_is_registered("tmp_tax_details")) { $tmp_tax_details =& cw_session_register("tmp_tax_details"); $tax_details = $tmp_tax_details; cw_session_unregister("tmp_tax_details"); } } else { $tax_rates = cw_query("SELECT {$tables['tax_rates']}.*, {$tables['zones']}.zone_name FROM {$tables['tax_rates']} LEFT JOIN {$tables['zones']} ON {$tables['tax_rates']}.zone_id={$tables['zones']}.zone_id WHERE {$tables['tax_rates']}.tax_id='{$tax_id}' ORDER BY {$tables['zones']}.zone_name, {$tables['tax_rates']}.rate_value"); $tmp = cw_user_get_memberships(array('C', 'R')); if (!empty($tax_rates)) { foreach ($tax_rates as $k => $v) { $keys = cw_query_column("SELECT membership_id FROM {$tables['tax_rate_memberships']} WHERE rate_id = '{$v['rate_id']}'"); if (!empty($tmp) && !empty($keys)) { $tax_rates[$k]['membership_ids'] = array(); foreach ($tmp as $m) { if (in_array($m['membership_id'], $keys)) { $tax_rates[$k]['membership_ids'][$m['membership_id']] = $m['membership']; } } } } } $smarty->assign('tax_rates', $tax_rates); $rate_details = array(); if (!empty($rate_id) && !empty($tax_rates) && is_array($tax_rates)) { $rate_formula = ""; foreach ($tax_rates as $k => $v) {
foreach ($export_columns_names as $colname => $coltitle) { $exp_line[$colname] = $row[$colname]; } $u_key = md5($row['email']); if (!isset($u_keys[$u_key])) { $u_keys[$u_key] = 1; print implode($delimiter, $exp_line) . "\n"; } } exit; } if ($save_search_id > 0) { cw_array2update('saved_search', array("sql_query" => addslashes($user_search_query)), "ss_id = '{$save_search_id}'"); $save_search_id = 0; } $valid_statuses = cw_query_column("select code from {$tables['order_statuses']} where inventory_decreasing=1"); foreach ($users as $k => $v) { $users[$k]['orders'] = cw_query_first_cell("SELECT count(d.doc_id) FROM {$tables['docs_user_info']} dui, {$tables['docs']} d WHERE dui.customer_id={$v['customer_id']} AND dui.doc_info_id=d.doc_info_id AND d.type='O' and d.status in ('" . implode("','", $valid_statuses) . "')"); } $smarty->assign('users', $users); } $smarty->assign('mode', $mode); } $predefined_lng_variables[] = 'lbl_search_user_' . $usertype; if (is_array($search_data['users'][$usertype]['address']['state'])) { $search_data['users'][$usertype]['address']['state'] = json_encode($search_data['users'][$usertype]['address']['state']); } $smarty->assign('js_tab', $search_data['users'][$usertype]['js_tab']); $smarty->assign('mode', $mode); $smarty->assign('payment_methods', cw_func_call('cw_payment_search', array('data' => array('type' => 1, 'active' => 1)))); $smarty->assign('memberships', cw_user_get_memberships($usertype == 'C' ? array('C', 'R') : $usertype));
function get_newslists_by_customer($customer_id, $direct_only = null) { global $tables; $user = \Customer\get($customer_id); if (empty($user)) { return null; } $direct = $indirect = array(); if (is_null($direct_only) || $direct_only === true) { $direct = cw_query_column("SELECT n.list_id FROM {$tables['newslist_subscription']} s\n INNER JOIN {$tables['newslists']} n ON n.list_id=s.list_id\n WHERE s.email='{$user['email']}'"); } if (is_null($direct_only) || $direct_only === false) { $indirect = cw_query_column("SELECT n.list_id FROM {$tables['newslists_memberships']} m\n INNER JOIN {$tables['newslists']} n ON n.list_id=m.list_id\n WHERE m.membership_id='{$user['membership_id']}'"); } $all = array_merge($indirect, $direct); $result = array(); foreach ($all as $lid) { $result[$lid] = array_merge(get_newslist($lid), array('direct' => intval(in_array($lid, $direct, true)), 'by_membership' => intval(in_array($lid, $indirect, true)))); } return $result; }
foreach ($userids as $l) { if (!cw_check_unique_email($l['email'], $survey_id)) { continue; } cw_array2insert("survey_maillist", array("survey_id" => $survey_id, "email" => addslashes($l['email']), "customer_id" => addslashes($l['customer_id']), "date" => time())); } $top_message = array("content" => cw_get_langvar_by_name("txt_survey_respondents_are_added")); cw_header_location("index.php?target={$target}&survey_id=" . $survey_id . "&js_tab=" . $js_tab . "&show=users"); } elseif ($action == "add_news_users" && $js_tab == 'maillist') { # Add respondents from news list if (empty($newslist)) { $top_message = array("type" => "E", "content" => cw_get_langvar_by_name("lbl_survey_news_list_is_empty")); cw_header_location("index.php?target={$target}&survey_id=" . $survey_id . "&js_tab=" . $js_tab . "&show=news"); } foreach ($newslist as $listid) { $users = cw_query_column("SELECT email FROM {$tables['newslist_subscription']} WHERE list_id = '{$list_id}'"); if (empty($users)) { continue; } foreach ($users as $em) { if (!cw_check_unique_email($em, $survey_id)) { continue; } cw_array2insert("survey_maillist", array("survey_id" => $survey_id, "email" => $em, "date" => time())); } } $top_message = array("content" => cw_get_langvar_by_name("txt_survey_respondents_are_added")); cw_header_location("index.php?target={$target}&survey_id=" . $survey_id . "&js_tab=" . $js_tab . "&show=news"); } elseif ($action == "add_survey_users" && $js_tab == 'maillist') { if (empty($surveylist)) { $top_message = array('type' => 'E', 'content' => cw_get_langvar_by_name("txt_survey_list_is_empty"));
function dod_modify_bonuses($generator_id) { global $tables, $bonus_names; global $dod_bonuses, $dod_bonus; if (empty($generator_id)) { $GLOBALS['_dod_bonuses'] =& $dod_bonuses; cw_session_register('_dod_bonuses'); $GLOBALS['_dod_bonus'] =& $dod_bonus; cw_session_register('_dod_bonus'); return array(true, null); //return array(false, 'generator Id was not provided'); } db_query("DELETE FROM {$tables['dod_bonuses']} WHERE generator_id = '{$generator_id}'"); db_query("DELETE FROM {$tables['dod_bonus_details']} WHERE generator_id = '{$generator_id}'"); $available_fields = array('bonus_id' => 'int', 'generator_id' => 'int', 'type' => 'string', 'apply' => 'int', 'coupon' => 'string', 'discount' => 'float', 'disctype' => 'int'); $excl_from_base_list = array('bonus_id'); foreach ($excl_from_base_list as $field) { if (isset($available_fields[$field])) { unset($available_fields[$field]); } } $optional_fields = array('discount', 'disctype'); $date_fields = array(); $skip_striptags_fields = array(); if (empty($dod_bonuses[DOD_DISCOUNT])) { $dod_bonuses[DOD_DISCOUNT] = 1; $unused_dod_discount_bonus = 1; } else { $unused_dod_discount_bonus = 0; } if (empty($dod_bonuses) || !is_array($dod_bonuses)) { return array(true, null); } $available_btypes = array(DOD_DISCOUNT, DOD_FREE_PRODS, DOD_FREE_SHIP, DOD_COUPON); $bonuses = array(); foreach ($dod_bonuses as $bonus_type => $trash) { if (!isset($dod_bonus[$bonus_type]) || empty($dod_bonus[$bonus_type]) || !in_array($bonus_type, $available_btypes)) { unset($dod_bonuses[$bonus_type]); } else { $bonuses[$bonus_type] = $dod_bonus[$bonus_type]; } } unset($dod_bonus); if (empty($dod_bonuses) || empty($bonuses)) { return array(true, null); } $GLOBALS['_dod_bonuses'] =& $dod_bonuses; cw_session_register('_dod_bonuses'); $errors = array(); $tmp_optional_fields = $optional_fields; foreach ($bonuses as $bonus_type => $input_data) { $optional_fields = $tmp_optional_fields; $additional_lang_data = array(); $pids = $cids = array(); $input_data['generator_id'] = $generator_id; $input_data['type'] = $bonus_type; if ($bonus_type != DOD_COUPON) { $input_data['coupon'] = 1; if ($input_data['apply'] == DOD_APPLY_PRODS || $bonus_type == DOD_FREE_PRODS || $bonus_type == DOD_DISCOUNT) { if (!isset($input_data['products']) && !isset($input_data['cats']) && !isset($input_data['mans']) && !isset($input_data['attr']) || empty($input_data['products']) && empty($input_data['cats']) && empty($input_data['mans']) && empty($input_data['attr'])) { $additional_lang_data = array('bonus' => cw_get_langvar_by_name($bonus_names[$bonus_type])); $errors[] = cw_get_langvar_by_name('msg_dod_bonus_incorrect', $additional_lang_data); continue; } if (isset($input_data['products']) && !empty($input_data['products'])) { $products_data = array(); foreach ($input_data['products'] as $product_data) { $product_data['id'] = trim($product_data['id']); $products_data[$product_data['id']] = $product_data['quantity']; } $pids = array_keys($products_data); $pids = cw_query_column("SELECT product_id as id FROM {$tables['products']} WHERE product_id IN ('" . implode("','", $pids) . "')"); } if (isset($input_data['cats']) && !empty($input_data['cats'])) { $cats_data = array(); foreach ($input_data['cats'] as $cat_data) { $cat_data['id'] = trim($cat_data['id']); $cats_data[$cat_data['id']] = $cat_data['quantity']; } $cids = array_keys($cats_data); $cids = cw_query_column("SELECT category_id as id FROM {$tables['categories']} WHERE category_id IN ('" . implode("','", $cids) . "')"); } if (isset($input_data['mans']) && !empty($input_data['mans'])) { $mids = array_values($input_data['mans']); } if (isset($input_data['attr'])) { // Prepare attributes data if (isset($input_data['attr']) && !empty($input_data['attr'])) { $attr_data = array(); foreach ($input_data['attr'] as $a_data) { $attr_data[trim($a_data['attribute_id'])] = array('quantity' => $a_data['quantity'], 'value' => current($a_data['value']), 'operation' => $a_data['operation']); } $attrids = array_keys($attr_data); $attrids = cw_query_column("SELECT attribute_id as id FROM {$tables['attributes']} WHERE attribute_id IN ('" . implode("','", $attrids) . "')"); } } if (empty($pids) && empty($cids) && empty($mids) && empty($attrids)) { $additional_lang_data = array('bonus' => cw_get_langvar_by_name($bonus_names[$bonus_type])); $errors[] = cw_get_langvar_by_name('msg_dod_bonus_incorrect', $additional_lang_data); continue; } } } if ($bonus_type != DOD_DISCOUNT && $bonus_type != DOD_FREE_SHIP) { $input_data['discount'] = $input_data['disctype'] = null; } elseif ($bonus_type == DOD_FREE_SHIP) { $input_data['disctype'] = null; } else { $optional_fields = array(); } if (in_array($bonus_type, array(DOD_FREE_PRODS, DOD_COUPON))) { $optional_fields[] = 'apply'; } $data = array(); foreach ($date_fields as $field) { if (isset($input_data[$field]) && !empty($input_data[$field])) { $input_data[$field] = cw_core_strtotime($input_data[$field]); } } $error = null; foreach ($available_fields as $field => $field_type) { if (isset($input_data[$field])) { $result = settype($input_data[$field], $field_type); if ($result === false) { $error = 'msg_dod_incorrect_field_type'; $additional_lang_data = array('field_name' => $field); break; } if (empty($input_data[$field]) && !($bonus_type == DOD_DISCOUNT && $unused_dod_discount_bonus)) { if (in_array($field, $optional_fields)) { $data[$field] = null; } else { $additional_lang_data = array('bonus' => cw_get_langvar_by_name($bonus_names[$bonus_type])); $error = 'msg_dod_bonus_incorrect'; break; } } else { if ($field_type == 'string' && !in_array($field, $skip_striptags_fields)) { $input_data[$field] = cw_strip_tags($input_data[$field]); } $data[$field] =& $input_data[$field]; } } else { if ($field_type == 'bool') { $data[$field] = 0; } else { if (in_array($field, $optional_fields)) { $data[$field] = null; } else { $additional_lang_data = array('bonus' => cw_get_langvar_by_name($bonus_names[$bonus_type])); $error = 'msg_dod_bonus_incorrect'; break; } } } } if (!empty($error)) { $errors[] = cw_get_langvar_by_name($error, $additional_lang_data); continue; } if (empty($data)) { continue; } if ($data['type'] == DOD_DISCOUNT) { $data['unused'] = $unused_dod_discount_bonus; } $bonus_id = cw_array2insert($tables['dod_bonuses'], cw_addslashes($data)); if ($bonus_type == DOD_FREE_SHIP) { foreach ($input_data['methods'] as $trash => $shipping_id) { $data = array('generator_id' => $generator_id, 'bonus_id' => $bonus_id, 'object_id' => $shipping_id, 'object_type' => DOD_OBJ_TYPE_SHIPPING); cw_array2insert($tables['dod_bonus_details'], cw_addslashes($data)); } } if ($bonus_type != DOD_COUPON) { if ($input_data['apply'] == DOD_APPLY_PRODS || $bonus_type == DOD_FREE_PRODS || $bonus_type == DOD_DISCOUNT) { if (!empty($pids)) { $data = array(); $data['generator_id'] = $generator_id; $data['bonus_id'] = $bonus_id; foreach ($pids as $pid) { $data['object_id'] = $pid; $data['object_type'] = DOD_OBJ_TYPE_PRODS; $data['quantity'] = $products_data[$pid]; if (empty($data['quantity'])) { $data['quantity'] = 1; } cw_array2insert($tables['dod_bonus_details'], cw_addslashes($data)); } } if (!empty($cids)) { $data = array(); $data['generator_id'] = $generator_id; $data['bonus_id'] = $bonus_id; foreach ($cids as $cid) { $data['object_id'] = $cid; $data['object_type'] = DOD_OBJ_TYPE_CATS; $data['quantity'] = $cats_data[$cid]; if (empty($data['quantity'])) { $data['quantity'] = 1; } cw_array2insert($tables['dod_bonus_details'], cw_addslashes($data)); } } if (!empty($mids)) { $data = array(); $data['generator_id'] = $generator_id; $data['bonus_id'] = $bonus_id; $data['quantity'] = 1; foreach ($mids as $mid) { $data['object_id'] = $mid; $data['object_type'] = DOD_OBJ_TYPE_MANS; cw_array2insert($tables['dod_bonus_details'], cw_addslashes($data)); } } // Save attributes to condition details if (!empty($attrids)) { $data = array(); $data['generator_id'] = $generator_id; $data['bonus_id'] = $bonus_id; $data['quantity'] = 1; foreach ($attrids as $aid) { $data['object_id'] = $aid; $data['object_type'] = DOD_OBJ_TYPE_ATTR; $data['param1'] = $attr_data[$aid]['value']; $data['param2'] = $attr_data[$aid]['operation']; cw_array2insert($tables['dod_bonus_details'], cw_addslashes($data)); } } } } unset($bonuses[$bonus_type]); } if (!empty($bonuses)) { $GLOBALS['_dod_bonus'] =& $bonuses; cw_session_register('_dod_bonus'); } if (!empty($errors)) { $error = implode("<br />\n", $errors); return array(false, $error); } return array(true, null); }
function cw_cms_get_used_attributes_options($selected_filter) { global $tables; $all_attribute_ids = cw_query_column("select distinct(object_id) as attribute_id from {$tables['cms_restrictions']} where object_type='A'"); if (empty($all_attribute_ids)) { return array(); } list($attributes, $navigation) = cw_func_call('cw_attributes_search', array('data' => array('all' => 1, 'active' => 1, 'type' => 'P', 'sort_field' => 'orderby, name'))); $attributes_options = array(); if (is_array($attributes) && count($attributes)) { foreach ($attributes as $value) { if (!in_array($value['attribute_id'], $all_attribute_ids)) { continue; } $default_values = cw_call('cw_attributes_get_attribute_default_value', array('attribute_id' => $value['attribute_id'])); $options = array(); $attribute_value_ids = cw_query_column("select value_id from {$tables['cms_restrictions']} where object_id='{$value['attribute_id']}' AND object_type='A'"); if (is_array($default_values) && count($default_values) && !empty($attribute_value_ids)) { foreach ($default_values as $v) { if (!empty($v['value'])) { if (in_array($v['attribute_value_id'], $attribute_value_ids)) { $options[] = array('attribute_value_id' => $v['attribute_value_id'], 'name' => $v['value'], 'checked' => in_array($v['attribute_value_id'], (array) $selected_filter[$value['attribute_id']])); } } } } if (count($options)) { $attributes_options[] = array('attribute_id' => $value['attribute_id'], 'name' => $value['name'], 'options' => $options); } elseif ($value['type'] == 'text') { $attributes_options[] = array('attribute_id' => $value['attribute_id'], 'name' => $value['name'], 'type' => $value['type'], 'value' => $selected_filter[$value['attribute_id']]); } } } return $attributes_options; }
function cw_check_condition_Z($offer_id) { global $user_address, $tables; $zones = cw_call('cw_cart_get_zones', array('address' => cw_user_get_address_by_type('current'), 'is_shipping' => 1)); $conditions = cw_query_column("SELECT object_id FROM {$tables['ps_cond_details']} WHERE offer_id='{$offer_id}' AND object_type='" . PS_OBJ_TYPE_ZONES . "'"); if (!empty($conditions) && is_array($conditions)) { foreach ($conditions as $k => $v) { if (isset($zones[$v])) { return true; } } # one match found - conndition is met return false; # there are PS_SHIP_ADDRESS conditions, but they don't match customer's zones } return true; // there are no PS_SHIP_ADDRESS conditions at all \ }
function cw_cart_get_zones($address, $is_shipping = 0) { global $tables, $config; static $z_flags = array("C" => 0x1, "S" => 0x2, "G" => 0x4, "T" => 0x8, "Z" => 0x10, "A" => 0x20); static $zone_element_types = array("S" => "state", "G" => "county", "T" => "city", "Z" => "zipcode", "A" => "address"); static $results_cache = array(); if ($config['General']['use_counties'] != "Y") { unset($z_flags['G']); unset($zone_element_types['G']); } $zones = array(); if (!$address && $config['General']['apply_default_country'] == 'Y') { $address = cw_user_get_default_address(); } if (!empty($address)) { $data_key = md5($address["country"] . $address["state"] . $address["county"] . $address["zipcode"] . $address["city"] . $is_shipping); if (isset($results_cache[$data_key])) { return $results_cache[$data_key]; } // get the zones for the shipping or for the taxes $shipping_condition = "and is_shipping='{$is_shipping}'"; # Possible zones for customer's country... $possible_zones = cw_query($sql = "SELECT {$tables['zone_element']}.zone_id FROM {$tables['zone_element']}, {$tables['zones']} WHERE {$tables['zone_element']}.zone_id={$tables['zones']}.zone_id AND {$tables['zone_element']}.field='" . $address["country"] . "' AND {$tables['zone_element']}.field_type='C' {$shipping_condition} GROUP BY {$tables['zone_element']}.zone_id"); if (is_array($possible_zones)) { $zones_completion = array(); $_possible_zones = array(); foreach ($possible_zones as $pzone) { $_possible_zones[$pzone['zone_id']] = cw_query_column("SELECT field_type FROM {$tables['zone_element']} WHERE zone_id='{$pzone['zone_id']}' AND field<>'%' GROUP BY zone_id, field_type"); } foreach ($_possible_zones as $_pzone_id => $_elements) { if (is_array($_elements)) { foreach ($_elements as $k => $v) { $zones_completion[$_pzone_id] += $z_flags[$v]; } } } $cs_state = $address["state"]; $cs_country = $address["country"]; $cs_pair = $cs_country . "_" . $cs_state; $empty_condition = " AND {$tables['zone_element']}.field<>'%'"; foreach ($possible_zones as $pzone) { $zones[$pzone['zone_id']] = $z_flags['C']; # If only country is defined for this zone, skip further actions if ($zones_completion[$pzone['zone_id']] == $z_flags['C']) { continue; } foreach ($z_flags as $field_type => $field_type_flag) { if ($field_type == "C") { continue; } if ($zones_completion[$pzone['zone_id']] & $field_type_flag) { # Checking the field for equal... if ($field_type == "S") { # Checking the state... $found_zones = cw_query_first_cell("SELECT zone_id FROM {$tables['zone_element']}, {$tables['map_states']} WHERE {$tables['zone_element']}.field='" . addslashes($cs_pair) . "' AND {$tables['zone_element']}.field_type='S' AND {$tables['map_states']}.code='" . addslashes($cs_state) . "' AND {$tables['map_states']}.country_code='" . addslashes($cs_country) . "' AND {$tables['zone_element']}.zone_id='{$pzone['zone_id']}'"); } elseif ($field_type == "G") { # Checking the county... $found_zones = cw_query_first_cell("SELECT zone_id FROM {$tables['zone_element']} WHERE field_type='G' AND field='" . $address["county"] . "' AND zone_id='{$pzone['zone_id']}'"); } else { # Checking the rest fields (city, zipcode, address) $found_zones = cw_query_first_cell("SELECT {$tables['zone_element']}.zone_id FROM {$tables['zone_element']}, {$tables['zones']} WHERE {$tables['zone_element']}.zone_id={$tables['zones']}.zone_id AND {$tables['zone_element']}.field_type='{$field_type}' AND '" . addslashes($address[$zone_element_types[$field_type]]) . "' LIKE {$tables['zone_element']}.field AND {$tables['zone_element']}.zone_id='{$pzone['zone_id']}' {$empty_condition} {$shipping_condition}"); } if (!empty($found_zones)) { # Field is found: increase the priority $zones[$pzone['zone_id']] += $field_type_flag; } else { # Remove zone from available zones list unset($zones[$pzone['zone_id']]); continue; } } } # /foreach ($z_flags) } # /foreach ($possible_zones) } } $zones[0] = 0; arsort($zones, SORT_NUMERIC); $results_cache[$data_key] = $zones; return $zones; }
function cw_dod_generate() { global $tables, $config, $current_language; $generator = cw_query_first("select * from {$tables['dod_generators']} where active=1 and startdate<='" . time() . "' and enddate>'" . time() . "' and dod_interval<>0 order by position asc, generator_id asc"); if (!empty($generator)) { //check last generation date $last_gen_date = $generator['current_offer_date']; $hrs_since_last_generation = intval((time() - $last_gen_date) / 3600); $generate_again = false; if ($generator['dod_interval_type'] == 'D') { $generate_again = $hrs_since_last_generation >= $generator['dod_interval'] * 24; $offer_enddate = min($generator['enddate'], time() + $generator['dod_interval'] * 24 * 3600); } elseif ($generator['dod_interval_type'] == 'T') { $dod_period_hrs = intval(($generator['enddate'] - $generator['startdate']) / 3600); $hrs_interval = intval($dod_period_hrs / $generator['dod_interval']); $generate_again = $hrs_since_last_generation >= $hrs_interval; $offer_enddate = min($generator['enddate'], time() + $dod_period_hrs / $generator['dod_interval'] * 3600); } if ($generate_again || $_GET['force_generate']) { if (!empty($generator['used_pids'])) { $used_pids = explode(';', $generator['used_pids']); } else { $used_pids = array(); } $dod_products = cw_query_column("select dbd.object_id from {$tables['dod_bonus_details']} dbd inner join {$tables['dod_bonuses']} db on db.generator_id=dbd.generator_id and db.bonus_id=dbd.bonus_id and db.type='" . DOD_DISCOUNT . "' where dbd.generator_id='{$generator['generator_id']}' and dbd.object_type='" . DOD_OBJ_TYPE_PRODS . "'"); $dod_categories = cw_query_column("select dbd.object_id from {$tables['dod_bonus_details']} dbd inner join {$tables['dod_bonuses']} db on db.generator_id=dbd.generator_id and db.bonus_id=dbd.bonus_id and db.type='" . DOD_DISCOUNT . "' where dbd.generator_id='{$generator['generator_id']}' and dbd.object_type='" . DOD_OBJ_TYPE_CATS . "'"); $dod_manufacturers = cw_query_column("select dbd.object_id from {$tables['dod_bonus_details']} dbd inner join {$tables['dod_bonuses']} db on db.generator_id=dbd.generator_id and db.bonus_id=dbd.bonus_id and db.type='" . DOD_DISCOUNT . "' where dbd.generator_id='{$generator['generator_id']}' and dbd.object_type='" . DOD_OBJ_TYPE_MANS . "'"); $dod_attributes = cw_query("select dbd.* from {$tables['dod_bonus_details']} dbd inner join {$tables['dod_bonuses']} db on db.generator_id=dbd.generator_id and db.bonus_id=dbd.bonus_id and db.type='" . DOD_DISCOUNT . "' where dbd.generator_id='{$generator['generator_id']}' and dbd.object_type='" . DOD_OBJ_TYPE_ATTR . "'"); //select products by dod conditions $data = array(); $dod_data_where_pids = ''; if ($dod_products) { $dod_data_where_pids = "{$tables['products']}.product_id in ('" . implode("','", $dod_products) . "')"; } if ($dod_categories) { $data['search_in_subcategories'] = 1; $data['category_ids'] = $dod_categories; } if ($dod_manufacturers) { $manufacturer_id_attribute = cw_query_first_cell("select attribute_id from {$tables['attributes']} where field='manufacturer_id' and addon='manufacturers'"); if ($manufacturer_id_attribute) { if (!isset($ret_params)) { $ret_params = array(); } if (!isset($ret_params['query_joins'])) { $ret_params['query_joins'] = array(); } $ret_params['query_joins']['atv_manufacturer'] = array('tblname' => 'attributes_values', 'on' => "{$tables['products']}.product_id=atv_manufacturer.item_id and atv_manufacturer.item_type='P' and atv_manufacturer.attribute_id = '{$manufacturer_id_attribute}' and atv_manufacturer.code in ('{$current_language}', '') and atv_manufacturer.value in ('" . implode("','", $dod_manufacturers) . "')", 'is_inner' => 1); } } if ($dod_attributes) { $param2_sql = array('eq' => '=', 'lt' => '<', 'le' => '<=', 'gt' => '>', 'ge' => '=>'); foreach ($dod_attributes as $attr_data_k => $attr_data) { $is_def_values = cw_query_first("select * from {$tables['attributes_default']} where attribute_value_id='{$attr_data['param1']}' and attribute_id='{$attr_data['object_id']}'"); //print_r($is_def_values);print("<br><br>"); $sql_operation = $param2_sql[$attr_data['param2']]; if (empty($sql_operation)) { continue; } if (!isset($ret_params)) { $ret_params = array(); } if (!isset($ret_params['query_joins'])) { $ret_params['query_joins'] = array(); } if ($is_def_values) { $ret_params['query_joins']['atv_dod_' . $attr_data_k] = array('tblname' => 'attributes_values', 'on' => "{$tables['products']}.product_id=atv_dod_{$attr_data_k}.item_id and atv_dod_{$attr_data_k}.item_type='P' and atv_dod_{$attr_data_k}.attribute_id = '{$attr_data['object_id']}' and atv_dod_{$attr_data_k}.code in ('{$current_language}', '')", 'is_inner' => 1); $ret_params['query_joins']['atd_dod_' . $attr_data_k] = array('tblname' => 'attributes_default', 'on' => "atd_dod_{$attr_data_k}.attribute_value_id=atv_dod_{$attr_data_k}.value and atv_dod_{$attr_data_k}.attribute_id=atd_dod_{$attr_data_k}.attribute_id and atd_dod_{$attr_data_k}.value{$sql_operation}'" . addslashes($is_def_values['value']) . "'", 'is_inner' => 1); } else { $ret_params['query_joins']['atv_dod_' . $attr_data_k] = array('tblname' => 'attributes_values', 'on' => "{$tables['products']}.product_id=atv_dod_{$attr_data_k}.item_id and atv_dod_{$attr_data_k}.item_type='P' and atv_dod_{$attr_data_k}.attribute_id = '{$attr_data['object_id']}' and atv_dod_{$attr_data_k}.code in ('{$current_language}', '') and atv_dod_{$attr_data_k}.value{$sql_operation}'{$attr_data['param1']}'", 'is_inner' => 1); } } } global $user_account, $current_area, $items_per_page_targets, $target; $items_per_page_targets[$target] = 1; $new_pid = 0; $safety_cnt = 1000; while (!$new_pid && $safety_cnt > 0) { if (!empty($data) || !empty($dod_data_where_pids)) { $data['sort_field'] = 'rand'; $data['flat_search'] = 1; $dod_data_where = array(); if (!empty($dod_data_where_pids)) { $dod_data_where[] = $dod_data_where_pids; } if (!empty($used_pids)) { $dod_data_where[] = "{$tables['products']}.product_id not in ('" . implode("','", $used_pids) . "')"; } $data['where'] = implode(' and ', $dod_data_where); list($products, $nav, $product_filter) = cw_func_call('cw_product_search', array('data' => $data, 'user_account' => $user_account, 'current_area' => $current_area, 'info_type' => 8, 'product_id_only' => 1), $ret_params); } $product = reset($products); //print_r(array('product'=>$product));print("<br><br>"); $new_pid = $product['product_id']; if (!$new_pid) { if ($generator['no_item_repeat']) { break; } else { if (!empty($used_pids)) { array_shift($used_pids); } else { break; } } } $safety_cnt--; } //die; if ($new_pid) { $used_pids[] = $new_pid; } $generator['used_pids'] = implode(';', $used_pids); $regenerate_offer = true; if ($regenerate_offer) { //regenerate offer if (!empty($generator['current_offer_id'])) { $offer_ids = array($generator['current_offer_id']); $offer_ids_query = implode("', '", $offer_ids); db_query("DELETE FROM {$tables['ps_offers']} WHERE offer_id IN ('" . $offer_ids_query . "')"); db_query("DELETE FROM {$tables['ps_bonuses']} WHERE offer_id IN ('" . $offer_ids_query . "')"); db_query("DELETE FROM {$tables['ps_bonus_details']} WHERE offer_id IN ('" . $offer_ids_query . "')"); db_query("DELETE FROM {$tables['ps_conditions']} WHERE offer_id IN ('" . $offer_ids_query . "')"); db_query("DELETE FROM {$tables['ps_cond_details']} WHERE offer_id IN ('" . $offer_ids_query . "')"); db_query("DELETE FROM {$tables['attributes_values']} WHERE item_id IN ('" . $offer_ids_query . "') and item_type='PS'"); foreach ($offer_ids as $offer_id) { cw_image_delete($offer_id, PS_IMG_TYPE); } cw_attributes_cleanup($offer_ids, PS_ATTR_ITEM_TYPE); cw_cache_clean('shipping_rates'); } if ($new_pid) { cw_log_add('dod_generator', array('new DOD product selected' => $new_pid)); $new_offer_id = cw_array2insert('ps_offers', array('title' => 'Deal Of The Day', 'description' => $generator['description'], 'startdate' => time(), 'enddate' => $offer_enddate, 'active' => 1)); } $current_offer_id = 0; if ($new_offer_id) { $mdm_attribute_id = cw_query_first_cell("select attribute_id from {$tables['attributes']} where addon='multi_domains' and item_type='PS'"); if ($mdm_attribute_id) { cw_array2insert('attributes_values', array('item_id' => $new_offer_id, 'attribute_id' => $mdm_attribute_id, 'value' => 0, 'code' => '', 'item_type' => 'PS')); } //copy bonus and bonus details $dod_bonuses = cw_query("select * from {$tables['dod_bonuses']} where generator_id='{$generator['generator_id']}' and unused=0"); foreach ($dod_bonuses as $dod_bonus) { $_dod_bonus = $dod_bonus; unset($_dod_bonus['generator_id']); $_dod_bonus['offer_id'] = $new_offer_id; $new_bonus_id = cw_array2insert('ps_bonuses', $_dod_bonus); if ($_dod_bonus['type'] == 'D' && $_dod_bonus['apply'] == 3) { cw_array2insert('ps_bonus_details', array('bonus_id' => $new_bonus_id, 'offer_id' => $new_offer_id, 'object_id' => $new_pid, 'quantity' => 1, 'object_type' => DOD_OBJ_TYPE_PRODS)); } else { $dod_bonus_details = cw_query("select * from {$tables['dod_bonus_details']} where generator_id='{$generator['generator_id']}' and bonus_id='{$dod_bonus['bonus_id']}'"); if (!empty($dod_bonus_details)) { foreach ($dod_bonus_details as $dod_bonus_detail) { $_dod_bonus_detail = $dod_bonus_detail; unset($_dod_bonus_detail['generator_id']); $_dod_bonus_detail['offer_id'] = $new_offer_id; $_dod_bonus_detail['bonus_id'] = $new_bonus_id; cw_array2insert('ps_bonus_details', $_dod_bonus_detail); } } } } $new_cond_id = cw_array2insert('ps_conditions', array('type' => 'P', 'total' => '0.00', 'offer_id' => $new_offer_id)); if ($new_cond_id) { cw_array2insert('ps_cond_details', array('cond_id' => $new_cond_id, 'offer_id' => $new_offer_id, 'object_id' => $new_pid, 'quantity' => 1, 'object_type' => DOD_OBJ_TYPE_PRODS)); } $current_offer_id = $new_offer_id; } } //update dod_generator fields cw_array2update('dod_generators', array('current_offer_id' => $current_offer_id, 'used_pids' => $generator['used_pids'], 'current_offer_date' => $current_offer_id ? time() : 0), "generator_id='{$generator['generator_id']}'"); if ($current_offer_id && !empty($config['deal_of_day']['dod_news_template']) && $config['deal_of_day']['dod_newslist']) { $newslist = cw_query_first("select * from {$tables['newslists']} where list_id='" . $config['deal_of_day']['dod_newslist'] . "' and avail=1"); if (!empty($newslist)) { //create message global $smarty; $smarty->assign('promotion', $generator); $smarty->assign('product_id', $new_pid); $product_info = cw_func_call('cw_product_get', array('id' => $new_pid, 'user_account' => $user_account, 'info_type' => 65535)); $smarty->assign('product', $product_info); $smarty->assign('news_message', $config['deal_of_day']['dod_news_template']); $message = cw_display("addons/deal_of_day/admin/generate_news.tpl", $smarty, false, $newslist['lngcode']); $smarty->assign('news_message', $config['deal_of_day']['dod_news_template_subject']); $message_subject = cw_display("addons/deal_of_day/admin/generate_news.tpl", $smarty, false, $newslist['lngcode']); // $message = $smarty->display('addons/deal_of_day/admin/generate_news.tpl'); print $message_subject . "<hr />" . $message; if (!empty($message)) { cw_array2insert('newsletter', array('subject' => $message_subject, 'body' => $message, 'created_date' => time(), 'send_date' => time(), 'updated_date' => time(), 'status' => 'N', 'list_id' => $config['deal_of_day']['dod_newslist'], 'show_as_news' => 1, 'allow_html' => 1)); } } } } } return $new_pid; }
*/ if (constant('PP_STD_DBG')) { cw_log_add('paypal_std', array('start', $REQUEST_METHOD, $request_prepared), false); } if (isset($request_prepared['mode']) && $request_prepared['mode'] == 'success') { $skey = $request_prepared['secureid']; // secureid - ref_id in table payment_data $payment_data = cw_call('cw_payment_get_data', array($skey)); cw_call('cw_payment_put_data', array($skey, array('state' => 'END', 'status' => 'success'))); if (empty($payment_data['doc_ids'])) { $payment_data['bill_error'] = 'callback error'; $payment_data['reason'] = 'Order is not found in stored payment data'; cw_call('cw_payment_put_data', array($skey, array('state' => 'END', 'status' => $payment_data['bill_error'], 'reason' => $payment_data['reason']))); } else { // If user returns to site successfully before callback (or callback missed) - switch status from I to Q $doc_ids = cw_query_column("SELECT doc_id FROM {$tables['docs']} WHERE status='I' AND doc_id IN ('" . implode("','", $payment_data['doc_ids']) . "')"); cw_call('cw_doc_change_status', array($doc_ids, 'Q')); } if (constant('PP_STD_DBG')) { cw_log_add('paypal_std', array('success', $payment_data), false); } cw_call('cw_payment_stop', array($payment_data)); exit; } /** * Cancel return from PayPal */ if (isset($request_prepared['mode']) && $request_prepared['mode'] == 'cancel') { $skey = $request_prepared['secureid']; // secureid - ref_id in table payment_data $payment_data = cw_call('cw_payment_get_data', array($skey));
function cw_faq_rubrik_path($rubrik_id) { global $tables; $data = cw_query_column($sql = "select title FROM {$tables['faq_rubrik']} as c, {$tables['faq_rubrik_parents']} as cp where cp.rubrik_id='{$rubrik_id}' and c.rubrik_id=cp.parent_rubrik_id order by cp.level desc"); return $data; }
function ppd_update($product_id) { global $tables, $top_message, $smarty, $available_fields; global $extra_fields, $optional_fields, $skip_striptags_fields; $product_id = (int) $product_id; if ($_SERVER['REQUEST_METHOD'] != 'POST') { ppd_redirect($product_id); } global $file_ids, $ppd_files; if (!isset($file_ids)) { $file_ids = isset($_POST['file_ids']) ? $_POST['file_ids'] : array(); } if (!isset($ppd_files)) { $ppd_files = isset($_POST['ppd_files']) ? $_POST['ppd_files'] : array(); } if (empty($file_ids) || empty($ppd_files) || !is_array($ppd_files)) { ppd_redirect($product_id); } $file_ids = array_unique(array_map('ppd_process_ids', array_keys($file_ids))); $file_ids_query = implode('\', \'', $file_ids); $file_ids = cw_query_column('SELECT `file_id` FROM ' . $tables['ppd_files'] . ' WHERE product_id = \'' . $product_id . '\' AND file_id IN (\'' . $file_ids_query . '\')'); if (empty($file_ids) || !is_array($file_ids)) { ppd_redirect($product_id); } if (isset($available_fields['file_id'])) { unset($available_fields['file_id']); } $error = null; foreach ($file_ids as $file_id) { $data = array(); $additional_lang_data = array(); if (!isset($ppd_files[$file_id])) { continue; } foreach ($available_fields as $field => $field_type) { if (isset($ppd_files[$file_id][$field])) { if (isset($extra_fields[$field]) && is_array($extra_fields[$field])) { $_total_value = $_value = null; foreach ($extra_fields[$field] as $extra_field) { $_value = isset($ppd_files[$file_id][$field][$extra_field]) ? $ppd_files[$file_id][$field][$extra_field] : null; @settype($_value, $field_type); $_total_value += $_value; } $ppd_files[$file_id][$field] = $_total_value; } $result = settype($ppd_files[$file_id][$field], $field_type); if ($result === false) { $error = 'msg_ppd_incorrect_field_type'; $additional_lang_data = array('field_name' => $field . ' file ID: ' . $file_id); break 2; } if (empty($ppd_files[$file_id][$field])) { if (in_array($field, $optional_fields)) { $data[$field] = null; } } else { if ($field_type == 'string' && !in_array($field, $skip_striptags_fields)) { $ppd_files[$file_id][$field] = cw_strip_tags($ppd_files[$file_id][$field]); } $data[$field] =& $ppd_files[$file_id][$field]; } } else { if ($field_type == 'bool') { $data[$field] = 0; } if (isset($extra_fields[$field])) { $data[$field] = 0; } } } $product_id_condition = 'product_id = \'' . $product_id . '\' AND '; if (!empty($data)) { cw_array2update($tables['ppd_files'], $data, $product_id_condition . 'file_id = \'' . $file_id . '\''); } } $top_message = array('content' => cw_get_langvar_by_name('msg_ppd_updated_succes'), 'type' => 'I'); if (!empty($error)) { $top_message = array('content' => cw_get_langvar_by_name($error, $additional_lang_data), 'type' => 'E'); } ppd_redirect($product_id); }
$logged_data = cw_query($s = "select ld.*, IF(ld.customer_id>0,1,0) as is_logged from {$tables['logged_data']} as ld {$where_string_qry} {$orderby_qry} {$limit_qry}"); $session_ids = array(); foreach ($logged_data as $ld_k => $ld_v) { $session_ids[$ld_v['cwsid']] = 1; $logged_data[$ld_k]['GET_POST'] = unserialize($ld_v['GET_POST']); } $smarty->assign('logged_data', $logged_data); $_sess_data = cw_query("select * from {$tables['logged_data_sessions']} where cwsid in ('" . implode("', '", array_keys($session_ids)) . "')"); $sess_data = array(); foreach ($_sess_data as $s_data) { $s_data['SERVER'] = unserialize($s_data['SERVER']); $s_data['user_account'] = unserialize($s_data['user_account']); $_cwsid = $s_data['cwsid']; unset($s_data['cwsid']); $sess_data[$_cwsid] = $s_data; } $smarty->assign('sess_data', $sess_data); $unq_target_code = cw_query_column("select distinct target_code from {$tables['logged_data']} as ld", 'target_code'); $smarty->assign('unq_target_code', $unq_target_code); $_all_arch_files = cw_files_get_dir($var_dirs['logs_archive'], 1, true); $all_arch_files = array(); foreach ($_all_arch_files as $f_name) { if (is_file($f_name)) { $all_arch_files[] = substr($f_name, strlen($var_dirs['logs_archive'])); } } asort($all_arch_files); $smarty->assign('all_arch_files', $all_arch_files); $smarty->assign('logging_search', $logging_search); $smarty->assign('log_columns', $log_columns); $smarty->assign('main', 'logging');
function cw_ps_bundle_build($action, $category, $category_src, $filter, $products_number, $discount, $disctype) { global $tables; $from_tbls['pc'] = 'products_categories'; $fields[] = 'pc.product_id'; if ($products_number < 2) { $products_number = 2; } if ($category != 0) { cw_load('category'); $subcats = cw_call('cw_category_get_subcategory_ids', array($category)); $where[] = 'pc.category_id IN ("' . join('","', $subcats) . '")'; } $query_joins['o'] = array('tblname' => 'ps_offers', 'on' => 'o.pid = pc.product_id'); if ($filter) { if ($filter['without']) { $where_auto[] = 'auto is NULL'; } if ($filter['auto']) { $where_auto[] = 'auto = 1'; } if ($filter['manual']) { $where_auto[] = 'auto = 0'; } $where[] = '(' . join(' OR ', $where_auto) . ')'; } $sql = cw_db_generate_query($fields, $from_tbls, $query_joins, $where); $pids = cw_query_column($sql); $products_number--; $subcats = cw_call('cw_category_get_subcategory_ids', array($category_src)); $where_src = '1'; if ($category_src != 0) { $where_src = "pc.category_id IN ('" . join("','", $subcats) . "')"; } foreach ($pids as $pid) { $new_pids = cw_query("SELECT pc.product_id as id\n\t\tFROM {$tables['products_categories']} pc \n\t\tWHERE {$where_src} AND pc.product_id!='{$pid}' \n\t\tORDER BY RAND() LIMIT {$products_number}"); $data = array('discount' => $discount, 'disctype' => $disctype, 'bundle' => $new_pids, 'auto' => 1); $offer_id = cw_call('cw_ps_offer_bundle_update', array($pid, $data)); } }