function cw_file_area_save($type, $for_customer_id, $data)
{
    global $tables, $customer_id, $var_dirs, $app_dir;
    $insert = array('customer_id' => $for_customer_id, 'by_customer_id' => $customer_id, 'filename' => $data['filename'], 'date' => cw_core_get_time(), 'md5' => md5(file_get_contents($data['file_path'])));
    if ($data['descr']) {
        $insert['descr'] = $data['descr'];
    }
    if ($data['id']) {
        $insert['id'] = $data['id'];
    }
    $file_id = cw_array2insert($type, $insert);
    if ($file_id) {
        $file_info = explode('.', $data['filename'], 2);
        $stored_file_name = $file_info[0] . '_' . $file_id . '.' . $file_info[1];
        $files_dir = $var_dirs['documents'] . '/' . $type;
        if (!is_dir($files_dir)) {
            @mkdir($files_dir);
        }
        $new_file_path = $files_dir . '/' . $stored_file_name;
        @copy($data['file_path'], $new_file_path);
        @unlink($data['file_path']);
        $new_file_path = cw_relative_path($new_file_path, $app_dir);
        db_query("update " . $tables[$type] . " set file_path='" . addslashes($new_file_path) . "' where file_id='{$file_id}'");
    }
    return $file_id;
}
function cw_save_salesman_order($cart_tmp, $doc_id = 0)
{
    $salesman_order = array();
    $products = $cart_tmp['products'];
    $save_fields = array('product_id', 'productcode', 'product', 'warehouse', 'taxed_price', 'taxes', 'extra_data', 'catalog_price', 'product_options', 'amount', 'new', 'free_price', 'price', 'items_in_stock');
    if (is_array($products)) {
        foreach ($products as $k => $v) {
            if ($v['deleted']) {
                unset($products[$k]);
                continue;
            }
            foreach ($v as $field => $val) {
                if (!in_array($field, $save_fields)) {
                    unset($products[$k][$field]);
                }
            }
        }
    }
    $salesman_order['cart'] = addslashes(serialize($products));
    $salesman_order['customer_id'] = $cart_tmp['customer_id'];
    $salesman_order['salesman_customer_id'] = $cart_tmp['salesman_customer_id'];
    $salesman_order['status'] = 0;
    if ($doc_id) {
        $salesman_order['id'] = $doc_id;
    }
    return cw_array2insert('salesman_orders', $salesman_order, true);
}
function cw_barcode_create_template($title)
{
    $to_insert = array('data' => addslashes(serialize(array('rows' => 5, 'cols' => 10, 'width' => 100, 'height' => 100))), 'layout' => 'barcode', 'title' => $title);
    $layout_id = cw_array2insert('layouts', $to_insert);
    $to_insert = array('layout_id' => $layout_id, 'template' => 'addons/barcode/layout.tpl', 'class' => 'barcode_layout');
    cw_array2insert('layouts_templates', $to_insert);
    return $layout_id;
}
function add()
{
    global $added_data, $REQUEST_METHOD;
    if ($REQUEST_METHOD == "POST") {
        $added_data['default_status'] = serialize($added_data['default_status']);
        cw_array2insert('product_stages_library', $added_data);
        cw_header_location("index.php?target=product_stages");
    }
}
function product_stages_add()
{
    global $new_product_stage, $REQUEST_METHOD, $product_id, $default_status;
    if ($REQUEST_METHOD == "POST") {
        $new_stage_data = array('product_id' => $product_id, 'stage_lib_id' => $new_product_stage['stage_lib_id'], 'period' => $new_product_stage['period'], 'status' => !empty($default_status['new_product_stage']) ? '-1' : (!empty($new_product_stage['status']) ? serialize($new_product_stage['status']) : ''), 'active' => !empty($new_product_stage['active']) ? 1 : 0);
        cw_array2insert('product_stages_product_settings', $new_stage_data);
        cw_header_location("index.php?target=products&mode=details&product_id={$product_id}&js_tab=product_stages");
    }
}
function cw_array2insert_esc($tab, $arr)
{
    foreach ($arr as $k => $v) {
        if (preg_match("'\\''", $v)) {
            $arr[$k] = addslashes($v);
        }
    }
    return cw_array2insert($tab, $arr);
}
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 add_video($product_id)
{
    global $new_video;
    assert('!empty($product_id) /* ' . __FUNCTION__ . ' */');
    $new_video['product_id'] = $product_id;
    $new_video_id = cw_array2insert('product_video', $new_video, false, array('product_id', 'pos', 'title', 'descr', 'code'));
    if ($new_video_id) {
        cw_add_top_message('Video added');
    }
    return $new_video_id;
}
function cw_send_simple_mail($from, $to, $subject, $body, $extra_headers = array(), $files = array())
{
    global $current_language;
    if (empty($to)) {
        return;
    }
    $to = cw_real_mail_address($to);
    $language = $language ? $language : $current_language;
    $_files = implode(",", $files);
    cw_array2insert('mail_spool', cw_addslashes(array('mail_from' => $from, 'mail_to' => $to, 'subject' => $subject, 'body' => $body, 'crypted' => false, 'files' => $_files)));
    return;
}
function cw_serials_add($customer_id, $product_id, $serial)
{
    global $tables;
    $count = cw_query_first_cell("select count(*) from {$tables['serial_numbers']} where sn='{$serial}' and product_id='{$product_id}'");
    if ($count) {
        return false;
    }
    $serial = trim($serial);
    if (empty($serial)) {
        return true;
    }
    $to_insert = array('sn' => $serial, 'product_id' => $product_id, 'doc_id' => 0, 'warehouse_customer_id' => $customer_id, 'date' => time());
    cw_array2insert('serial_numbers', $to_insert);
    return true;
}
function dashboard_action_update()
{
    if ($_SERVER['REQUEST_METHOD'] != 'POST') {
        dashboard_redirect();
    }
    $dashboard = $_POST['dashboard'];
    if (empty($dashboard)) {
        dashboard_redirect();
    }
    foreach ($dashboard as $name => $dash) {
        $data = array('name' => $name, 'pos' => intval($dash['pos']), 'active' => intval($dash['active']));
        cw_array2insert('dashboard', $data, true);
    }
    $top_message = array('content' => cw_get_langvar_by_name('msg_ppd_filetypes_updated_succes'), 'type' => 'I');
    dashboard_redirect();
}
function cw_system_messages_add($code, $msg, $type = SYSTEM_MESSAGE_COMMON, $severity = SYSTEM_MESSAGE_INFO)
{
    global $tables;
    $code = mysql_real_escape_string($code);
    $msg = mysql_real_escape_string($msg);
    $type = intval($type);
    $existing = cw_query_first("SELECT code, hidden FROM {$tables['system_messages']} WHERE code='{$code}'");
    $data = array('date' => cw_core_get_time(), 'message' => $msg, 'type' => $type, 'severity' => $severity);
    if ($existing) {
        $ret = cw_array2update('system_messages', $data, "code='{$code}'");
    } else {
        $data['code'] = $code;
        $data['hidden'] = 0;
        $ret = cw_array2insert('system_messages', $data);
    }
    return $ret;
}
function cw_objects_add_to_set($objects, $type = 'P')
{
    global $tables, $customer_id;
    if (is_array($objects) && count($objects)) {
        $objects = array_unique($objects);
        $objects = array_filter($objects, function ($object) {
            return !empty($object) && is_numeric($object);
        });
        if (count($objects)) {
            foreach ($objects as $object) {
                if (!cw_objects_check_exist($object, $type)) {
                    cw_array2insert("objects_set", array("object_id" => $object, "customer_id" => $customer_id, "set_type" => $type));
                }
            }
            return TRUE;
        }
    }
    return FALSE;
}
function cw_messages_create_new_message($customer_id, $sender_name, $recipient_id, $recipient_email, $subject, $body, $conversation_id)
{
    global $config, $current_location;
    cw_load('email');
    // sent message (incoming folder)
    $new_message_id = cw_array2insert('messages', array('subject' => $subject, 'body' => $body, 'sender_id' => $customer_id, 'recipient_id' => $recipient_id, 'sending_date' => cw_core_get_time(), 'conversation_id' => !empty($conversation_id) ? $conversation_id : 0, 'conversation_customer_id' => $recipient_id));
    // duplicate for sent folder
    $current_conversation_id = !empty($conversation_id) ? $conversation_id : $new_message_id;
    $duplicate_message_id = cw_array2insert('messages', array('subject' => $subject, 'body' => $body, 'sender_id' => $customer_id, 'recipient_id' => $recipient_id, 'sending_date' => cw_core_get_time(), 'read_status' => 1, 'conversation_id' => $current_conversation_id, 'conversation_customer_id' => $customer_id, 'type' => 2, 'link_id' => $new_message_id));
    // unite message if they have not been united
    $data = array('link_id' => $duplicate_message_id);
    if (empty($conversation_id)) {
        $data['conversation_id'] = $new_message_id;
    }
    cw_array2update('messages', $data, "message_id = '{$new_message_id}'");
    // send notification email to recipient
    // notification is sent from system email and says about new received message from Sender at <sitename>
    $from = $config['Company']['site_administrator'];
    /*
        $mail_subject = "The notification of a new message";
        $mail_body = '<b>You have received a new message from "' . $sender_name . '" at <a href="' . $current_location . '">';
        $mail_body .= $config['Company']['company_name'] . '</a></b><br />';
        $mail_body .= '<b>Subject:</b> ' . $subject . '<br />';
        $mail_body .= '<b>Body:</b> ' . nl2br($body) . '<br />';
        $mail_body .= '<a href="' . $current_location . '/index.php?target=message_box&mode=new';
        $mail_body .= '&contact_id=' . $customer_id . '&conversation_id=' . $current_conversation_id . '">Link to reply</a><br />';
        cw_send_simple_mail($from, $recipient_email, $mail_subject, $mail_body);
    */
    global $smarty;
    $smarty->assign('sender_name', $sender_name);
    $smarty->assign('current_location', $current_location);
    $smarty->assign('config', $config);
    $smarty->assign('subject', $subject);
    $smarty->assign('body', $body);
    $smarty->assign('customer_id', $customer_id);
    $smarty->assign('recipient_id', $recipient_id);
    $smarty->assign('current_conversation_id', $current_conversation_id);
    $smarty->assign('new_message_id', $new_message_id);
    cw_call('cw_send_mail', array($from, $recipient_email, 'addons/messaging_system/mail/new_message_subj.tpl', 'addons/messaging_system/mail/new_message.tpl'));
    return $new_message_id;
}
function on_profile_modify($customer_id, $profile)
{
    if (!isset($profile['mailing_list'])) {
        return true;
    }
    $user = \Customer\get($customer_id);
    if (empty($user)) {
        return null;
    }
    global $tables;
    db_query("DELETE FROM {$tables['newslist_subscription']} WHERE email='{$user['email']}' AND list_id NOT IN ('" . join("','", array_keys($profile['mailing_list'])) . "')");
    foreach ($profile['mailing_list'] as $lid => $v) {
        if (!is_numeric($lid) || $lid < 1) {
            continue;
        }
        $is_subscribed = (bool) cw_query("SELECT list_id FROM {$tables['newslist_subscription']} WHERE email='{$user['email']}' AND list_id='{$lid}'");
        if (!$is_subscribed && $v) {
            $data = array('list_id' => $lid, 'email' => $user['email']);
            cw_array2insert('newslist_subscription', $data);
        }
    }
}
Exemplo n.º 16
0
function cw_ebay_add_data_from_file()
{
    global $tables;
    $path = addon_files_location_path . addon_conditions_data_file_name;
    if (!file_exists($path) || !is_readable($path)) {
        return array('content' => 'File "' . addon_conditions_data_file_name . '" does not exist or not readable.', 'type' => 'E');
    }
    if (($handle = fopen($path, "r")) !== FALSE) {
        $attribute_id = cw_query_first_cell("SELECT attribute_id FROM {$tables['attributes']} WHERE field = 'ebay_category' AND addon = 'ebay'");
        if (empty($attribute_id)) {
            fclose($handle);
            return array('content' => 'Error in attribute "ebay Category". Wrong parameter ID.', 'type' => 'E');
        }
        db_query("DELETE FROM {$tables['attributes_default']} WHERE attribute_id = " . $attribute_id);
        // Prepare attributes data
        $attributes = array();
        $attributes[""] = array("value" => "-- Inherited from parent --", "value_key" => 0);
        while (($data = fgetcsv($handle)) !== FALSE) {
            $category_id = intval($data[0]);
            if (!is_numeric($category_id) || $category_id <= 0) {
                continue;
            }
            $category_name = addslashes(trim($data[1]));
            $attributes[$category_name] = array("value" => $category_name, "value_key" => $category_id);
        }
        fclose($handle);
        if (count($attributes)) {
            ksort($attributes);
            $orderby = 0;
            // Add to cw_attributes_default
            foreach ($attributes as $attribute) {
                cw_array2insert("attributes_default", array("value" => $attribute["value"], "value_key" => $attribute["value_key"], "attribute_id" => $attribute_id, "orderby" => $orderby++, "active" => 1));
            }
        }
    } else {
        return array('content' => 'File "' . addon_conditions_data_file_name . '" not readable.', 'type' => 'E');
    }
    return array('content' => 'The operation completed successfully.', 'type' => 'I');
}
Exemplo n.º 17
0
function cw_ps_offer_bundle_update($product_id, $update_data)
{
    global $tables, $config;
    $product_id = (int) $product_id;
    $offer_id = cw_query_first_cell("SELECT offer_id FROM {$tables['ps_offers']} WHERE pid='{$product_id}'");
    if (empty($offer_id)) {
        // There is no offer for this product yet. Create it
        $data = array('title' => "Product #{$product_id} bundle", 'description' => 'Buy products together and get discount ' . $update_data['discount'] . ($update_data['disctype'] == PS_DISCOUNT_TYPE_PERCENT ? '%' : $config['General']['currency_symbol']), 'startdate' => time(), 'enddate' => 9999999999.0, 'exlusive' => 0, 'position' => -1, 'active' => 1, 'priority' => -1, 'pid' => $product_id, 'auto' => $update_data['auto'], 'repeat' => 0);
        $offer_id = cw_array2insert('ps_offers', $data);
        // Add offer to all domains
        $attribute_id = cw_call('cw_attributes_filter', array(array('field' => 'domains', 'item_type' => 'PS'), true, 'attribute_id'));
        $data = array('item_id' => $offer_id, 'attribute_id' => $attribute_id, 'value' => 0, 'item_type' => 'PS');
        cw_array2insert('attributes_values', $data);
    }
    $cond_id = cw_query_first_cell("SELECT cond_id FROM {$tables['ps_conditions']} WHERE offer_id='{$offer_id}' AND type='" . PS_SPEC_PRODUCTS . "'");
    if (empty($cond_id)) {
        // Create condition
        $data = array('type' => PS_SPEC_PRODUCTS, 'offer_id' => $offer_id);
        $cond_id = cw_array2insert('ps_conditions', $data);
        $data = array('cond_id' => $cond_id, 'offer_id' => $offer_id, 'object_id' => $product_id, 'quantity' => 1, 'object_type' => PS_OBJ_TYPE_PRODS);
        cw_array2insert('ps_cond_details', $data);
        // Create bonus
        $data = array('offer_id' => $offer_id, 'type' => PS_DISCOUNT, 'apply' => PS_APPLY_PRODS, 'discount' => floatval($_POST['discount']), 'disctype' => intval($_POST['disctype']));
        $bonus_id = cw_array2insert('ps_bonuses', $data);
        $data = array('bonus_id' => $bonus_id, 'offer_id' => $offer_id, 'object_id' => $product_id, 'quantity' => 1, 'object_type' => PS_OBJ_TYPE_PRODS);
        cw_array2insert('ps_bonus_details', $data);
    }
    // Add new selected products
    foreach ($update_data['bundle'] as $k => $v) {
        if ($v['id'] == $product_id || empty($v['id'])) {
            continue;
        }
        $data = array('cond_id' => $cond_id, 'offer_id' => $offer_id, 'object_id' => $v['id'], 'quantity' => 1, 'object_type' => PS_OBJ_TYPE_PRODS);
        cw_array2insert('ps_cond_details', $data);
        $data = array('bonus_id' => $bonus_id, 'offer_id' => $offer_id, 'object_id' => $v['id'], 'quantity' => 1, 'object_type' => PS_OBJ_TYPE_PRODS);
        cw_array2insert('ps_bonus_details', $data);
    }
    $data = array('discount' => floatval($update_data['discount']), 'disctype' => intval($update_data['disctype']));
    cw_array2update('ps_bonuses', $data, "offer_id='{$offer_id}' AND type='" . PS_DISCOUNT . "'");
    return $offer_id;
}
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);
}
if ($REQUEST_METHOD == "POST" && $action == "add_review") {
    if (!empty($review_new['message'])) {
        $review_new['status'] = $config['estore_products_review']['status_created_reviews'];
        $review_new['email'] = $user_account['email'];
        $review_id = cw_call('cw_review_add_new_review_manual', array($review_new, 0));
    }
    if (!empty($review_id)) {
        $review_data = cw_query_first("SELECT * FROM {$tables['products_reviews']} WHERE review_id='{$review_id}'");
        foreach ($rating as $attr_id => $vote) {
            // update vote value
            $exists = cw_query_first_cell("SELECT vote_id FROM {$tables['products_votes']} WHERE review_id = '{$review_id}' AND attribute_id ='{$attr_id}'");
            if ($exists) {
                cw_array2update('products_votes', array('vote_value' => $vote), "review_id = '{$review_id}' AND attribute_id ='{$attr_id}'");
            } else {
                cw_array2insert('products_votes', array('remote_ip' => $review_data['remote_ip'], 'vote_value' => $vote, 'product_id' => $review_data['product_id'], 'customer_id' => $review_data['customer_id'], 'review_id' => $review_id, 'attribute_id' => $attr_id));
            }
            cw_review_recalculate_avg_rating($review_data['product_id'], $attr_id);
        }
        cw_review_recalculate_avg_rating($review_data['product_id']);
        cw_add_top_message(cw_get_langvar_by_name('txt_thank_you_for_review'));
    } else {
        cw_add_top_message(cw_get_langvar_by_name('err_filling_form'), 'E');
    }
    cw_header_location("index.php?target=global_reviews");
}
$items_per_page_targets[$target] = 10;
$total_items = cw_call('cw_review_get_global_review', array());
$navigation = cw_core_get_navigation($target, $total_items, $page);
$global_reviews = cw_call('cw_review_get_global_review', array('', '', " ORDER BY {$tables['products_reviews']}.ctime DESC ", "LIMIT {$navigation['first_page']}, {$navigation['objects_per_page']}", FALSE));
$items_per_page_targets[$target] = PHP_INT_MAX;
function import_products($xcart_conf)
{
    extract($xcart_conf);
    extract(cw_vers_diff_attr($conn));
    fout("<br /><br />Import of manufacturers, Products, Categories...<br />");
    $cats = cw_table_copy_from_xcart_lit_sn($conn, 'categories', "categoryid as category_id, parentid as parent_id, if(avail='Y',1,0) as status, category, description, order_by");
    cw_table_copy_from_xcart_lit($conn, 'xcart_categories', 'cw_categories_stats', "categoryid as category_id, views_stats");
    cw_table_copy_from_xcart_lit_sn($conn, 'categories_lng', "UPPER(code) as code, categoryid as category_id, category, description");
    cw_table_copy_from_xcart_lit_sn($conn, 'products_categories', "categoryid as category_id, productid as product_id,\n\t\t  if(main='Y',1,0) as main, orderby");
    $prods = cw_table_copy_from_xcart_comm_sn($conn, 'products', "productid as product_id, if(forsale='Y',1,0) as status");
    cw_table_copy_from_xcart_lit($conn, 'xcart_products', 'cw_products_stats', "productid as product_id, views_stats, sales_stats, del_stats");
    cw_table_copy_from_xcart_lit($conn, 'xcart_products', 'cw_products_warehouses_amount', "productid as product_id, avail");
    cw_table_copy_from_xcart_lit_sn($conn, 'products_lng', "UPPER(code) as code, productid as product_id, product,descr,fulldescr,keywords");
    db_query("TRUNCATE TABLE cw_products_prices");
    $sql = "select priceid as price_id, prc.productid as product_id, quantity, price, list_price,\n\t\tvariantid as variant_id, membershipid as membership_id from xcart_pricing prc\n\t\tleft join xcart_products prd on prc.productid=prd.productid order by product_id, variant_id";
    $prices = cw_query($sql, $conn);
    foreach ($prices as $arr) {
        cw_array2insert_esc('cw_products_prices', $arr);
    }
    // Memberships
    db_query("Delete from cw_memberships where membership_id!=0");
    $mbrsh = cw_query("select * from xcart_memberships  where membershipid!=0", $conn);
    $level = cw_query_first_cell("select level from cw_access_levels  where membership_id=0 and area='A'");
    db_query("Delete from cw_access_levels where membership_id!=0");
    foreach ($mbrsh as $v) {
        extract($v);
        if ($area == 'A' || $area == 'P') {
            $area = 'A';
        } else {
            $area = 'C';
        }
        $membership_id = $membershipid;
        $show_prices = 1;
        cw_array2insert_esc('cw_memberships', compact('membership_id', 'area', 'membership', 'active', 'orderby', 'flag', 'show_prices'));
        if ($area == 'A') {
            cw_array2insert_esc('cw_access_levels', compact('membership_id', 'area', 'level'));
        }
    }
    db_query("Delete from cw_memberships_lng where membership_id!=0");
    $mbrshl = cw_query("select * from xcart_memberships_lng  where membershipid!=0", $conn);
    foreach ($mbrshl as $v) {
        extract($v);
        $membership_id = $membershipid;
        $code = strtoupper($code);
        cw_array2insert_esc('cw_memberships_lng', compact('membership_id', 'code', 'membership'));
    }
    cw_table_copy_from_xcart_lit($conn, 'xcart_products', 'cw_products_memberships', "productid as product_id, 0 as memberships_id");
    cw_table_copy_from_xcart_lit($conn, 'xcart_categories', 'cw_categories_memberships', "categoryid as category_id, 0 as memberships_id");
    $catmem = cw_query("select * from xcart_category_memberships", $conn);
    $prodmem = cw_query("select * from xcart_product_memberships", $conn);
    foreach ($catmem as $v) {
        extract($v);
        $membership_id = $membershipid;
        $category_id = $categoryid;
        cw_array2insert('cw_categories_memberships', compact('category_id', 'membership_id'));
    }
    foreach ($prodmem as $v) {
        extract($v);
        $membership_id = $membershipid;
        $product_id = $productid;
        cw_array2insert('cw_products_memberships', compact('product_id', 'membership_id'));
    }
    // manufacturers
    $mans = cw_table_copy_from_xcart_comm_sn($conn, 'manufacturers', "manufacturerid as manufacturer_id,\n\t\tprovider as warehouse_customer_id, if(avail='Y',1,0) as avail");
    cw_table_copy_from_xcart_comm_sn($conn, 'manufacturers_lng', 'manufacturerid as manufacturer_id, UPPER(code) as code');
    // Set Attributes: 0 for domains; Meta Tags, manufacturer_id for products, etc.
    if ($withcurls) {
        $tmp = cw_query("SELECT * from xcart_clean_urls", $conn);
        $clean_urls = array();
        foreach ($tmp as $v) {
            extract($v);
            $clean_urls[$resource_type][$resource_id] = str_replace('.', '-', $clean_url);
        }
    } else {
        $tmp = cw_query("Select 'C' as type, categoryid as id, LCASE(category) as name from xcart_categories\n\t\t\tunion Select 'P' as type, productid as id, LCASE(product) as name from xcart_products\n\t\t\tunion Select 'M' as type, manufacturerid as id, LCASE(manufacturer) as name from xcart_manufacturers", $conn);
        $clean_urls = array();
        $curls = array();
        foreach ($tmp as $v) {
            extract($v);
            $cu = preg_replace("'[^a-z0-9]+'s", ' ', $name);
            $cu = str_replace(' ', '-', $cu);
            $i = 1;
            $curl = $cu;
            while (in_array($curl, $curls)) {
                $curl = $cu . '-' . $i++;
            }
            $clean_urls[$type][$id] = $curl;
            $curls[] = $curl;
        }
        unset($curls);
    }
    unset($tmp);
    if ($pwithmeta) {
        $prodmeta = cw_query("Select productid as id, 'P' as type, product, manufacturerid,\n\t\t  meta_description, meta_keywords, title_tag, add_date from xcart_products", $conn);
    } else {
        $prodmeta = cw_query("Select productid as id, 'P' as type, product, descr,\n\t\t\tmanufacturerid, add_date from xcart_products", $conn);
        foreach ($prodmeta as $k => $v) {
            extract($v);
            $prodmeta[$k]['title_tag'] = trim($product);
            $descr = preg_replace("'</?[a-z]+.*?>'is", " ", $descr);
            $descr = trim(preg_replace("'\\s+'", " ", $descr));
            $prodmeta[$k]['meta_description'] = $descr;
            $mk = preg_replace("'[^a-z]+'is", " ", $product);
            $prodmeta[$k]['meta_keywords'] = str_replace(' ', ', ', trim($mk));
        }
    }
    db_query("TRUNCATE TABLE cw_products_system_info");
    $admin = cw_query_first_cell("select customer_id from cw_customers where usertype='A' limit 1");
    foreach ($prodmeta as $v) {
        extract($v);
        cw_set_attr($type, 'domains', $id, 0);
        cw_set_attr($type, 'meta_title', $id, $title_tag);
        cw_set_attr($type, 'meta_keywords', $id, $meta_keywords);
        cw_set_attr($type, 'meta_description', $id, $meta_description);
        if (isset($clean_urls[$type]) && isset($clean_urls[$type][$id])) {
            cw_set_attr($type, 'clean_url', $id, $clean_urls[$type][$id]);
        }
        cw_set_attr($type, 'manufacturer_id', $id, $manufacturerid);
        $product_id = $id;
        $creation_customer_id = $modification_customer_id = $admin;
        $creation_date = $modification_date = $add_date;
        cw_array2insert('cw_products_system_info', compact('product_id', 'creation_customer_id', 'creation_date', 'modification_customer_id', 'modification_date'));
    }
    if ($cwithmeta) {
        $catmeta = cw_query("Select categoryid as id, 'C' as type, category,\n\t\t  meta_description, meta_keywords, title_tag from xcart_categories", $conn);
    } else {
        foreach ($cats as $k => $v) {
            extract($v);
            $catmeta[$k]['title_tag'] = trim($category);
            $descr = preg_replace("'</?[a-z]+.*?>'is", " ", $description);
            $descr = trim(preg_replace("'\\s+'", " ", $descr));
            $catmeta[$k]['meta_description'] = $descr;
            $mk = preg_replace("'[^a-z]+'is", " ", $category);
            $catmeta[$k]['meta_keywords'] = str_replace(' ', ', ', trim($mk));
            $catmeta[$k]['type'] = 'C';
            $catmeta[$k]['id'] = $category_id;
        }
    }
    foreach ($catmeta as $v) {
        extract($v);
        cw_set_attr($type, 'domains', $id, 0);
        cw_set_attr($type, 'meta_title', $id, $title_tag);
        cw_set_attr($type, 'meta_keywords', $id, $meta_keywords);
        cw_set_attr($type, 'meta_description', $id, $meta_description);
        if (isset($clean_urls[$type]) && isset($clean_urls[$type][$id])) {
            cw_set_attr($type, 'clean_url', $id, $clean_urls[$type][$id]);
        }
    }
    if ($cwithmeta) {
        $manmeta = cw_query("Select manufacturerid as id, 'M' as type, manufacturer,\n\t\t  meta_description, meta_keywords, title_tag from xcart_manufacturers", $conn);
    } else {
        foreach ($mans as $k => $v) {
            extract($v);
            $manmeta[$k]['title_tag'] = trim($manufacturer);
            $descr = preg_replace("'</?[a-z]+.*?>'is", " ", $descr);
            $descr = trim(preg_replace("'\\s+'", " ", $descr));
            $manmeta[$k]['meta_description'] = $descr;
            $mk = preg_replace("'[^a-z]+'is", " ", $manufacturer);
            $manmeta[$k]['meta_keywords'] = str_replace(' ', ', ', trim($mk));
            $manmeta[$k]['type'] = 'M';
            $manmeta[$k]['id'] = $manufacturer_id;
        }
    }
    if (is_array($manmeta)) {
        foreach ($manmeta as $v) {
            extract($v);
            cw_set_attr($type, 'domains', $id, 0);
            cw_set_attr($type, 'meta_title', $id, $title_tag);
            cw_set_attr($type, 'meta_keywords', $id, $meta_keywords);
            cw_set_attr($type, 'meta_description', $id, $meta_description);
            if (isset($clean_urls[$type]) && isset($clean_urls[$type][$id])) {
                cw_set_attr($type, 'clean_url', $id, $clean_urls[$type][$id]);
            }
        }
    }
    // Grab categories, products (Thumbnails & Detailed), and manufacturers related Images
    cw_imgs_copy($xcart_conf, 'xcart_images_C', 'cw_categories_images_thumb', 'categories_images_thumb');
    cw_imgs_copy($xcart_conf, 'xcart_images_T', 'cw_products_images_thumb', 'products_images_thumb', 70);
    cw_imgs_copy($xcart_conf, 'xcart_images_P', 'cw_products_images_det', 'products_images_det');
    cw_imgs_copy($xcart_conf, 'xcart_images_D', 'cw_products_detailed_images', 'products_detailed_images', 800);
    cw_imgs_copy($xcart_conf, 'xcart_images_M', 'cw_manufacturer_images', 'manufacturer_images', 150);
    // Variants -- Classes
    cw_table_copy_from_xcart_comm($conn, 'xcart_variants', 'cw_product_variants', "variantid as variant_id, productid as product_id, concat(productcode,variantid) as eancode");
    cw_table_copy_from_xcart_lit($conn, 'xcart_variant_items', 'cw_product_variant_items', "optionid as option_id, variantid as variant_id");
    // Variants -- available in stock -- adding to cw_products_warehouses_amount,
    // where we alredy have 'avail' field for variants equal 0 (for prods without variants)
    $var_prod_avail = cw_query("Select variantid as variant_id, productid as product_id, avail from xcart_variants", $conn);
    foreach ($var_prod_avail as $v) {
        cw_array2insert('cw_products_warehouses_amount', $v);
    }
    cw_table_copy_from_xcart_comm($conn, 'xcart_classes', 'cw_product_options', "classid as product_option_id, class as field,\n\t\tclasstext as name, productid as product_id, if(avail='Y',1,0) as avail, is_modifier as type");
    cw_table_copy_from_xcart_comm($conn, 'xcart_class_options', 'cw_product_options_values', "classid as product_option_id, option_name as name, if(avail='Y',1,0) as avail,\n\t\t    optionid as option_id, if(modifier_type='\$',0,1) as modifier_type");
    cw_table_copy_from_xcart_lit($conn, 'xcart_class_lng', 'cw_product_options_lng', "UPPER(code) as code, classid as product_option_id, classtext as name");
    db_query("TRUNCATE TABLE cw_product_options_values_lng");
    db_query("TRUNCATE TABLE cw_customers_warehouses");
    // Product Links ---
    cw_table_copy_from_xcart_comm($conn, 'xcart_product_links', 'cw_linked_products', "productid1 as product_id, productid2 as linked_product_id, 1 as active");
    // Featured Products
    cw_table_copy_from_xcart_lit_sn($conn, 'featured_products', "productid as product_id, 0 as category_id,\n\t\tproduct_order, if(avail='Y',1,0) as avail");
    // Product review, ratings
    cw_table_copy_from_xcart_comm($conn, 'xcart_product_reviews', 'cw_products_reviews', "productid as product_id");
    cw_table_copy_from_xcart_comm($conn, 'xcart_product_votes', 'cw_products_votes', "productid as product_id, vote_value/20 as vote_value");
    // Taxes, tax rates
    cw_table_copy_from_xcart_comm_sn($conn, 'taxes', "taxid as tax_id, if(active='Y',1,0) as active,\n\t\t  if(price_includes_tax='Y',1,0) as price_includes_tax, if(display_including_tax='Y',1,0) as display_including_tax");
    cw_table_copy_from_xcart_comm_sn($conn, 'tax_rates', "rateid as rate_id, taxid as tax_id, zoneid as zone_id,\n\t\t  0 as wherehouse_customer_id");
    db_query("DELETE from cw_languages_alt where name rlike '^tax\\_[0-9]+\$'");
    cw_import_config($conn);
    // Menu -- Make top categories featured -- and add 8 top categories (with subcategories) to Top Menu
    db_query("Update cw_categories set featured=1 where parent_id=0 and status=1");
    db_query("Update cw_categories set tm_active=1 where parent_id!=0");
    $ids = cw_query_first_cell("select group_concat(category_id) as cids from\n\t\t(select category_id from cw_categories where parent_id=0 and status=1 order by order_by limit 8) cat");
    db_query("Update cw_categories set tm_active=1 where category_id in ({$ids})");
    cw_cat_tree_building();
    db_query("TRUNCATE TABLE cw_categories_subcount");
    cw_recalc_subcat_count(0);
}
Exemplo n.º 21
0
    $doc_id = $print_doc_id;
}
if ($action == 'set_template' and $current_area == 'A') {
    if (is_array($label_data['elements'])) {
        foreach ($label_data['elements'] as $k => $el) {
            if (empty($el)) {
                unset($label_data['elements'][$k]);
            }
        }
    }
    $data = addslashes(serialize($label_data));
    cw_array2update('layouts', array('data' => $data), "layout='{$target}'");
    cw_header_location("index.php?target={$target}&mode=layout&doc_id={$doc_id}");
}
if ($action == 'create_template' && $current_area == 'A' && $template['title']) {
    $layout_id = cw_array2insert('layouts', array('title' => $template['title'], 'layout' => 'docs_' . $docs_type));
    db_query("update {$tables['docs_info']} set layout_id='{$layout_id}'");
    cw_header_location("index.php?target={$target}&mode=layout&doc_id={$doc_id}");
}
if ($action == 'copy_layout_template' && $current_area == 'A' && $template['source_layout_id'] && $template['source_layout_id'] != $template['layout_id']) {
    cw_web_copy_layout($template['source_layout_id'], $template['layout_id']);
    cw_header_location("index.php?target={$target}&mode=layout&doc_id={$doc_id}");
}
if ($action == 'delete_template' && $current_area == 'A') {
    cw_web_delete_layout($template['layout_id']);
    db_query("update {$tables['docs_info']} set layout_id=0 where layout_id='" . $template['layout_id'] . "'");
    cw_header_location("index.php?target={$target}&mode=layout&doc_id={$doc_id}");
}
$info_type = 1;
if (in_array($current_area, array('A', 'P'))) {
    $info_type += 512 + 8192;
Exemplo n.º 22
0
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;
}
Exemplo n.º 23
0
function cw_user_update_contract($contract_id, $contract)
{
    global $tables;
    $to_insert = array('title' => $contract['title'], 'content' => $contract['content']);
    if ($contract_id) {
        $to_insert['contract_id'] = $contract_id;
    }
    return cw_array2insert('user_contracts', $to_insert, true);
}
function add($product_id, $category_id, $main = true)
{
    // TODO: Implement
    return cw_array2insert();
}
        #
        # Update shipping table
        #
        if (is_array($posted_data)) {
            foreach ($posted_data as $rate_id => $v) {
                cw_array2update("shipping_rates", array("minweight" => cw_convert_number($v['minweight']), "maxweight" => cw_convert_number($v['maxweight']), "mintotal" => cw_convert_number($v['mintotal']), "maxtotal" => cw_convert_number($v['maxtotal']), "rate" => cw_convert_number($v['rate']), "item_rate" => cw_convert_number($v['item_rate']), "rate_p" => cw_convert_number($v['rate_p']), "overweight" => cw_convert_number($v['overweight']), "overweight_rate" => cw_convert_number($v['overweight_rate']), "rate_p" => cw_convert_number($v['rate_p']), "weight_rate" => cw_convert_number($v['weight_rate'])), "rate_id='{$rate_id}' {$warehouse_condition} {$type_condition}");
            }
            $top_message['content'] = cw_get_langvar_by_name("msg_shipping_rates_upd");
        }
    }
    if ($action == "add") {
        #
        # Add new shipping rate
        #
        if ($shipping_id_new) {
            cw_array2insert("shipping_rates", array("shipping_id" => $shipping_id_new, "minweight" => cw_convert_number($minweight_new), "maxweight" => cw_convert_number($maxweight_new), "maxamount" => cw_convert_number($maxamount_new), "mintotal" => cw_convert_number($mintotal_new), "maxtotal" => cw_convert_number($maxtotal_new), "rate" => cw_convert_number($rate_new), "item_rate" => cw_convert_number($item_rate_new), "rate_p" => cw_convert_number($rate_p_new), "weight_rate" => cw_convert_number($weight_rate_new), "warehouse_customer_id" => $user_account['warehouse_customer_id'], "zone_id" => $zone_id_new, "type" => $type, "overweight" => cw_convert_number($overweight_new), "overweight_rate" => cw_convert_number($overweight_rate_new)));
            $top_message['content'] = cw_get_langvar_by_name("msg_shipping_rate_add");
        }
    }
    cw_header_location("index.php?target=shipping_rates&zone_id={$zone_id}&shipping_id={$shipping_id}&type={$type}");
}
$zone_condition = $zone_id != "" ? "and {$tables['shipping_rates']}.zone_id='{$zone_id}'" : "";
$method_condition = $shipping_id != "" ? "and {$tables['shipping_rates']}.shipping_id='{$shipping_id}'" : "";
$shipping_rates = cw_query("SELECT {$tables['shipping_rates']}.*, {$tables['shipping']}.shipping, {$tables['shipping']}.shipping_time, {$tables['shipping']}.destination FROM {$tables['shipping']}, {$tables['shipping_rates']} WHERE {$tables['shipping_rates']}.shipping_id={$tables['shipping']}.shipping_id AND {$tables['shipping']}.active=1 {$warehouse_condition} {$type_condition} {$zone_condition} {$method_condition} " . ($type == "R" ? " AND code!='' " : '') . " ORDER BY {$tables['shipping']}.orderby, {$tables['shipping_rates']}.maxweight");
#
# Prepare zones list
#
$zones = array(array("zone_id" => 0, "zone" => cw_get_langvar_by_name("lbl_zone_default")));
$_tmp = cw_query("SELECT zone_id, zone_name as zone FROM {$tables['zones']} WHERE 1 {$warehouse_condition} and is_shipping=1 ORDER BY zone_id");
if (!empty($_tmp)) {
    $zones = cw_array_merge($zones, $_tmp);
Exemplo n.º 26
0
        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;
                cw_array2insert('newslists_memberships', $arr_to_insert, true);
            }
        }
    } else {
        $top_message = array('content' => cw_get_langvar_by_name('err_filling_form'), 'type' => 'E');
        $nwslt_object =& cw_session_register('nwslt_object');
        $nwslt_object['fill_error'] = $fill_error;
        $nwslt_object['list'] = $list;
        cw_header_location("index.php?target={$target}&list_id=" . $list['list_id']);
    }
    cw_header_location("index.php?target={$target}&list_id=" . $list['list_id']);
}
$location[] = array(cw_get_langvar_by_name('lbl_news_management'), 'index.php?target=' . $target);
if (isset($_GET['list_id'])) {
    if (!empty($list_id)) {
        $list = cw_query_first("select * from {$tables['newslists']} WHERE list_id='{$list_id}'");
<?php

if (!$user_type) {
    $user_type = 'C';
}
cw_load('user', 'profile_fields');
if ($action == 'update_status' && is_array($upd_flag)) {
    foreach ($upd_flag as $field_id => $v) {
        db_query("delete from {$tables['register_fields_avails']} where field_id='{$field_id}' and (area like '" . $user_type . "_%' or area like '#" . $user_type . "_%' or area = '#{$user_type}')");
        if ($upd[$field_id]) {
            foreach ($upd[$field_id] as $area => $state) {
                $ins = array('is_avail' => $state['a'], 'is_required' => $state['r'], 'field_id' => $field_id, 'area' => $area);
                cw_array2insert('register_fields_avails', $ins, true);
            }
        }
    }
    cw_header_location("index.php?target={$target}&user_type={$user_type}&js_tab=profile_options");
}
if ($action == 'update_fields' && is_array($update)) {
    foreach ($update as $k => $v) {
        if ($k == 0) {
            if ($v['field']) {
                cw_profile_fields_add_field($v);
            }
        } else {
            cw_profile_fields_update_field($k, $v);
        }
    }
    cw_header_location("index.php?target={$target}&mode=fields&js_tab=addition_fields");
}
if ($action == 'delete_fields' && is_array($update)) {
Exemplo n.º 28
0
            continue;
        }
        if ($k) {
            $v['rule_id'] = $k;
        }
        if (empty($v['target'])) {
            continue;
        }
        cw_array2insert('user_actions_rules', $v, true);
    }
    foreach ($upd_action as $k => $v) {
        if ($v['del'] == 'Y') {
            db_query("delete from {$tables['user_actions']} where action_id='{$k}'");
            db_query("update {$tables['user_actions_rules']} set action_id=0 where action_id='{$k}'");
            continue;
        }
        if ($k) {
            $v['action_id'] = $k;
        }
        if (empty($v['title'])) {
            continue;
        }
        cw_array2insert('user_actions', $v, true);
    }
    cw_header_location('index.php?target=log');
}
$targets = cw_query("select * from {$tables['user_actions_rules']} order by target, orderby");
$smarty->assign('targets', $targets);
$user_actions = cw_query("select * from {$tables['user_actions']} order by title");
$smarty->assign('user_actions', $user_actions);
$smarty->assign('main', 'log');
Exemplo n.º 29
0
function cw_faq_update_path($rubrik_id)
{
    global $tables;
    $path = array();
    $path[] = $rubrik_id;
    $level = 0;
    cw_faq_generate_path($rubrik_id, $path);
    db_query("delete from {$tables['faq_rubrik_parents']} where rubrik_id='{$rubrik_id}'");
    foreach ($path as $val) {
        cw_array2insert('faq_rubrik_parents', array('rubrik_id' => $rubrik_id, 'parent_rubrik_id' => $val, 'level' => $level++), 1);
    }
    return $path;
}
Exemplo n.º 30
0
                $add_coupon['apply_product_once'] = 1;
            } elseif ($how_to_apply_c == 2) {
                $add_coupon['apply_product_once'] = 0;
                $add_coupon['apply_category_once'] = 0;
            } else {
                $add_coupon['apply_product_once'] = 1;
                $add_coupon['apply_category_once'] = 0;
            }
            break;
    }
    if (empty($add_coupon['coupon']) || empty($add_coupon['discount']) && $add_coupon['coupon_type'] != 'free_ship' || cw_query_first_cell("select count(*) from {$tables['discount_coupons']} where coupon='{$add_coupon['coupon']}'") > 0) {
        $saved_coupon_data = $add_coupon;
        $top_message = array('content' => cw_get_langvar_by_name('msg_err_discount_coupons_add'), 'type' => 'E');
        cw_header_location("index.php?target={$target}&mode=add");
    } else {
        cw_array2insert('discount_coupons', $add_coupon, 1, array('coupon', 'discount', 'coupon_type', 'minimum', 'times', 'per_user', 'expire', 'status', 'product_id', 'category_id', 'recursive', 'apply_category_once', 'apply_product_once'));
        $top_message['content'] = cw_get_langvar_by_name('msg_discount_coupons_add');
        cw_session_unregister('saved_coupon_data');
    }
    cw_header_location("index.php?target={$target}");
}
if ($mode == 'add') {
    $smarty->assign('main', 'add_new_coupon');
} else {
    $coupons = cw_query("select * from {$tables['discount_coupons']}");
    $smarty->assign('coupons', $coupons);
    $smarty->assign('main', 'coupons');
}
$smarty->assign('coupon_data', $saved_coupon_data);
$smarty->assign('current_main_dir', 'addons');
$smarty->assign('current_section_dir', 'discount_coupons');