function cw_fbauth_user_login($user)
{
    global $tables, $current_area;
    cw_load('crypt', 'user', 'mail');
    $user_data = cw_query_first("SELECT customer_id, email, password\n\t\t\t\t\t\t\t\t\tFROM {$tables['customers']} \n\t\t\t\t\t\t\t\t\tWHERE oauth_uid='" . $user['id'] . "' AND oauth_type='F'  \n\t\t\t\t\t\t\t\t\t\tAND usertype='" . $current_area . "' \n\t\t\t\t\t\t\t\t\t\tAND status='Y'");
    if (!empty($user_data)) {
        // login user
        global $email, $password, $action;
        $email = $user_data['email'];
        $password = text_decrypt($user_data['password']);
        $action = 'login';
        cw_include('include/login.php');
    } else {
        // create user
        $register = array();
        $register['email'] = $user['email'];
        if (strpos($user['email'], "proxymail.facebook.com") !== FALSE) {
            cw_header_location("index.php?target=fb_auth_get_email", TRUE);
        }
        $register['password'] = $register['password2'] = md5(uniqid('cw_', TRUE), TRUE);
        $register['usertype'] = $current_area;
        $partner_membership =& cw_session_register('partner_membership');
        $register['membership_id'] = $partner_membership;
        $customer_id = cw_user_create_profile($register);
        $identifiers =& cw_session_register('identifiers', array());
        $identifiers[$current_area] = array('customer_id' => $customer_id);
        $customer = array('oauth_uid' => $user['id']);
        cw_array2update('customers', $customer, "customer_id='{$customer_id}'");
        $address = array('main' => 1, 'firstname' => $user['first_name'], 'lastname' => $user['last_name']);
        $additional_info = array('sex' => $user['gender'] == 'male' ? 1 : 0);
        $userinfo = array('addresses' => $address, 'additional_info' => $additional_info);
        cw_user_update($userinfo, $customer_id, $customer_id);
        cw_user_send_modification_mail($customer_id, TRUE);
    }
}
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 cw_edit_on_place_product($token_data, $value)
{
    $edited_language =& cw_session_register('edited_language');
    if ($token_data['table'] == 'products' && $token_data['field'] == 'product' && !empty($token_data['pk'])) {
        $lng_data = array('product' => $value);
        cw_array2update('products_lng', $lng_data, "code='{$edited_language}' AND product_id='{$token_data['pk']}'");
    }
}
function update_video($product_id)
{
    global $tables;
    assert('!empty($product_id) /* ' . __FUNCTION__ . ' */');
    $video = $_POST['video'];
    foreach ($video as $vid => $v) {
        cw_array2update('product_video', $v, "video_id='{$vid}'", array('pos', 'title', 'descr', 'code'));
    }
    return true;
}
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 cw_web_set_layout_width($layout, $id, $width, $height)
{
    global $tables;
    if (empty($id)) {
        return;
    }
    if (!cw_query_first_cell($sql = "select count(*) from {$tables['layouts_elements']} where layout_id='{$layout}' and id = '{$id}'")) {
        cw_array2insert('layouts_elements', array('layout_id' => $layout, 'id' => $id));
    }
    cw_array2update('layouts_elements', array('width' => $width, 'height' => $height), "layout_id='{$layout}' and id = '{$id}'");
}
function modify()
{
    global $posted_data, $REQUEST_METHOD;
    if ($REQUEST_METHOD == "POST") {
        foreach ($posted_data as $lib_id => $stage_data) {
            if (!empty($stage_data['default_status']) && is_array($stage_data['default_status'])) {
                $stage_data['default_status'] = serialize($stage_data['default_status']);
            }
            cw_array2update('product_stages_library', $stage_data, "stage_lib_id='{$lib_id}'");
        }
        cw_header_location("index.php?target=product_stages");
    }
}
function product_stages_modify()
{
    global $posted_data, $default_status, $REQUEST_METHOD, $product_id;
    if ($REQUEST_METHOD == "POST") {
        foreach ($posted_data as $setting_id => $stage_data) {
            $update_stage_data = array('period' => $stage_data['period'], 'active' => !empty($stage_data['active']) ? 1 : 0);
            if ($default_status[$setting_id]) {
                $update_stage_data['status'] = -1;
            } else {
                $update_stage_data['status'] = serialize($stage_data['status']);
            }
            cw_array2update('product_stages_product_settings', $update_stage_data, "setting_id='{$setting_id}'");
        }
        cw_header_location("index.php?target=products&mode=details&product_id={$product_id}&js_tab=product_stages");
    }
}
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_flexible_import_save_profile($params, $profile_type)
{
    global $tables, $var_dirs;
    $id = $params['id'];
    $name = $params['name'];
    $descr = $params['description'];
    $test_import_file_tmp = $params['test_import_file']['tmp_name'];
    if (!empty($params['test_import_file'])) {
        unset($params['test_import_file']['tmp_name'], $params['test_import_file']['error']);
    }
    unset($params['id'], $params['name'], $params['description'], $params['type']);
    $profile_options = serialize($params);
    if ($id) {
        $res = cw_array2update($tables['flexible_import_profiles'], array('name' => $name, 'description' => $descr, 'type' => $profile_type, 'options' => $profile_options), "id='" . $id . "'");
    } else {
        $res = cw_array2insert($tables['flexible_import_profiles'], array('name' => $name, 'description' => $descr, 'type' => $profile_type, 'options' => $profile_options));
    }
    if (!empty($params['test_import_file']) && $res && file_exists($test_import_file_tmp)) {
        if ($id) {
            $test_import_file_path = $var_dirs['flex_import_test'] . '/' . $id;
        } else {
            $test_import_file_path = $var_dirs['flex_import_test'] . '/' . $res;
        }
        if (!file_exists($var_dirs['flex_import_test'])) {
            mkdir($var_dirs['flex_import_test']);
        }
        if (!file_exists($test_import_file_path)) {
            mkdir($test_import_file_path);
        }
        if ($test_import_file_path . '/' . $params['test_import_file']['name'] != $test_import_file_tmp) {
            @unlink($test_import_file_path . '/' . $params['test_import_file']['name']);
            rename($test_import_file_tmp, $test_import_file_path . '/' . $params['test_import_file']['name']);
        }
    }
    return $res;
}
function cw_user_delete_memberships($del)
{
    global $tables;
    if (!is_array($del)) {
        $del[] = $del;
    }
    if (!count($del)) {
        return;
    }
    $delete_string = "membership_id IN ('" . implode("','", $del) . "')";
    if (cw_query_first_cell("SELECT COUNT(*) FROM {$tables['memberships']} WHERE area IN ('C', 'R') AND " . $delete_string)) {
        $recalc_subcat_count = true;
    }
    db_query("DELETE FROM {$tables['memberships']} WHERE " . $delete_string);
    db_query("DELETE FROM {$tables['super_deals']} WHERE " . $delete_string);
    db_query("DELETE FROM {$tables['categories_memberships']} WHERE " . $delete_string);
    db_query("DELETE FROM {$tables['products_memberships']} WHERE " . $delete_string);
    db_query("DELETE FROM {$tables['tax_rate_memberships']} WHERE " . $delete_string);
    db_query("DELETE FROM {$tables['memberships_lng']} WHERE " . $delete_string);
    db_query("DELETE FROM {$tables['payment_methods_memberships']} WHERE " . $delete_string);
    db_query("DELETE FROM {$tables['discounts_memberships']} WHERE " . $delete_string);
    db_query("DELETE FROM {$tables['access_levels']} WHERE " . $delete_string);
    db_query("DELETE FROM {$tables['newslists_memberships']} WHERE " . $delete_string);
    db_query("DELETE FROM {$tables['products_prices']} WHERE " . $delete_string);
    db_query("DELETE FROM {$tables['tax_rate_memberships']} WHERE " . $delete_string);
    foreach ($del as $id) {
        // TODO: move to addon
        global $addons;
        if ($addons['faq']) {
            cw_load('faq');
            cw_faq_delete_membership($id);
        }
        db_query("DELETE FROM {$tables['register_fields_avails']} WHERE area LIKE '%_{$id}'");
    }
    cw_array2update("customers", array("membership_id" => 0), $delete_string);
    if ($recalc_subcat_count) {
        cw_load('category');
        cw_recalc_subcat_count(0, 100);
    }
}
function setMain($product_id, $category_id = null)
{
    if (empty($product_id)) {
        return false;
    }
    $data = array('main' => 0);
    cw_array2update('products_categories', $data, 'product_id = "' . intval($product_id) . '"');
    $data = array('main' => 1);
    cw_array2update('products_categories', $data, 'product_id = "' . intval($product_id) . '"' . (!is_null($category_id) ? ' AND category_id = "' . intval($category_id) . '"' : '') . ' LIMIT 1');
}
                }
                db_query("DELETE FROM {$tables['shipping_rates']} WHERE rate_id='{$rate_id}' {$warehouse_condition} {$type_condition}");
                $deleted = true;
            }
            if ($deleted) {
                $top_message['content'] = cw_get_langvar_by_name("msg_shipping_rates_del");
            }
        }
    }
    if ($action == "update") {
        #
        # 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}");
}
Пример #14
0
function ppd_modify($product_id)
{
    global $tables, $top_message, $smarty, $available_fields;
    global $extra_fields, $optional_fields, $skip_striptags_fields;
    $product_id = (int) $product_id;
    global $file_id;
    if (!isset($file_id)) {
        $file_id = isset($_POST['file_id']) ? (int) $_POST['file_id'] : 0;
    }
    $file_id = (int) $file_id;
    global $file_data;
    if (!isset($file_data)) {
        $file_data = null;
        if (isset($_POST['file_data'])) {
            $file_data =& $_POST['file_data'];
        }
    }
    if (empty($file_id) || empty($file_data) || !is_array($file_data) || $_SERVER['REQUEST_METHOD'] != 'POST') {
        ppd_redirect($product_id);
    }
    $table = $tables['ppd_files'];
    $file_id = cw_query_first_cell('SELECT file_id FROM ' . $table . ' WHERE file_id = \'' . $file_id . '\'');
    if (empty($file_id)) {
        ppd_redirect($product_id);
    }
    $error = null;
    $data = array();
    if (isset($available_fields['file_id'])) {
        unset($available_fields['file_id']);
    }
    $additional_lang_data = array();
    foreach ($available_fields as $field => $field_type) {
        if (isset($file_data[$field])) {
            if (isset($extra_fields[$field]) && is_array($extra_fields[$field])) {
                $_total_value = $_value = null;
                foreach ($extra_fields[$field] as $extra_field) {
                    $_value = isset($file_data[$field][$extra_field]) ? $file_data[$field][$extra_field] : null;
                    @settype($_value, $field_type);
                    $_total_value += $_value;
                }
                $file_data[$field] = $_total_value;
            }
            $result = settype($file_data[$field], $field_type);
            if ($result === false) {
                $error = 'msg_ppd_incorrect_field_type';
                $additional_lang_data = array('field_name' => $field);
                break;
            }
            if (empty($file_data[$field])) {
                if (in_array($field, $optional_fields)) {
                    $data[$field] = null;
                }
            } else {
                if ($field_type == 'string' && !in_array($field, $skip_striptags_fields)) {
                    $file_data[$field] = cw_strip_tags($file_data[$field]);
                }
                $data[$field] =& $file_data[$field];
            }
        } else {
            if ($field_type == 'bool') {
                $data[$field] = 0;
            }
            if (isset($extra_fields[$field])) {
                $data[$field] = 0;
            }
        }
    }
    if (!empty($error)) {
        $top_message = array('content' => cw_get_langvar_by_name($error, $additional_lang_data), 'type' => 'E');
        ppd_redirect($product_id, $file_id);
    }
    if (empty($data)) {
        $error = 'msg_ppd_nothing_to_update';
        $top_message = array('content' => cw_get_langvar_by_name($error, $additional_lang_data), 'type' => 'E');
        ppd_redirect($product_id, $file_id);
    }
    if (isset($data['type_id']) && !empty($data['type_id'])) {
        $_type_id = cw_query_first_cell('SELECT type_id FROM ' . $tables['ppd_types'] . ' WHERE type_id = \'' . $data['type_id'] . '\'');
        if ($_type_id != $data['type_id']) {
            $error = 'msg_ppd_incorrect_filetype';
            $top_message = array('content' => cw_get_langvar_by_name($error, $additional_lang_data), 'type' => 'E');
            ppd_redirect($product_id, $file_id);
        }
    }
    if (isset($data['type_id']) && empty($data['type_id'])) {
        unset($data['type_id']);
    }
    $product_id_condition = 'product_id = \'' . $product_id . '\' AND ';
    cw_array2update($table, $data, $product_id_condition . 'file_id = \'' . $file_id . '\'');
    $top_message = array('content' => cw_get_langvar_by_name('msg_ppd_updated_succes'), 'type' => 'I');
    ppd_redirect($product_id);
}
Пример #15
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;
}
<?php

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));
Пример #17
0
        $aom_orders =& cw_session_register('aom_orders', array());
        $print_doc_id = $aom_orders[$doc_id]['doc_id'];
    }
    $current_language =& cw_session_register('current_language');
    $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}");
Пример #18
0
     $rate_id = intval(@$rate_id);
     $rate_value = cw_convert_number($rate_value, "3" . substr($config['Appearance']['number_format'], 1));
     $zone_id = intval($zone_id);
     if (!in_array($rate_type, array("%", "\$"))) {
         $rate_type = "%";
     }
     if (empty($membership_ids) || in_array(-1, $membership_ids)) {
         $membership_ids_where = "IS NULL ";
     } else {
         $membership_ids_where = "IN ('" . implode("','", $membership_ids) . "') ";
     }
     if (cw_query_first_cell("SELECT COUNT(*) FROM {$tables['tax_rates']} LEFT JOIN {$tables['tax_rate_memberships']} ON {$tables['tax_rates']}.rate_id = {$tables['tax_rate_memberships']}.rate_id WHERE {$tables['tax_rates']}.tax_id = '{$tax_id}' AND {$tables['tax_rates']}.rate_id != '{$rate_id}' AND {$tables['tax_rates']}.zone_id = '{$zone_id}' AND {$tables['tax_rate_memberships']}.membership_id " . $membership_ids_where) == 0) {
         $rate_formula = preg_replace("/^=/", "", $rate_formula);
         $query_data = array("zone_id" => $zone_id, "formula" => $rate_formula, "rate_value" => $rate_value, "rate_type" => $rate_type);
         if (!empty($rate_id)) {
             cw_array2update("tax_rates", $query_data, "rate_id='{$rate_id}' ");
             db_query("DELETE FROM {$tables['tax_rate_memberships']} WHERE rate_id='{$rate_id}'");
             $top_message['content'] = cw_get_langvar_by_name("msg_tax_rate_upd");
         } else {
             $query_data['tax_id'] = $tax_id;
             $rate_id = cw_array2insert("tax_rates", $query_data);
             $top_message['content'] = cw_get_langvar_by_name("msg_tax_rate_add");
         }
         cw_membership_update("tax_rate", $rate_id, $membership_ids, "rate_id");
     } else {
         $top_message['content'] = cw_get_langvar_by_name("msg_err_tax_rate_add");
         $top_message['type'] = "E";
     }
     $top_message['anchor'] = "rates";
     $redirect_to = "&tax_id={$tax_id}";
 }
Пример #19
0
     if ($file_upload_data['categories_images_thumb']) {
         $file_upload_data['categories_images_thumb']['is_redirect'] = false;
         $saved_category['image'] = $file_upload_data['categories_images_thumb'];
     }
     cw_header_location("index.php?target={$target}&mode={$mode}&cat={$cat}&ge_id={$ge_id}");
 }
 if ($mode == 'add') {
     $cat = cw_array2insert('categories', array('parent_id' => $cat));
     cw_category_update_path($cat);
 }
 $update_fields = array('category', 'description', 'featured', 'order_by', 'short_list');
 array_push($update_fields, 'meta_descr', 'meta_keywords');
 if ($edited_language != $config['default_admin_language']) {
     cw_unset($update_fields, 'category', 'description');
 }
 cw_array2update('categories', $category_update, "category_id='{$cat}'", $update_fields);
 cw_category_update_status($cat, $category_update['status']);
 cw_category_update_path($cat);
 cw_membership_update('categories', $cat, $category_update['membership_ids'], 'category_id');
 $category_lng = array();
 $category_lng['code'] = $edited_language;
 $category_lng['category_id'] = $cat;
 $category_lng['category'] = $category_update['category'];
 $category_lng['description'] = $category_update['description'];
 cw_array2insert('categories_lng', $category_lng, true, array('code', 'category_id', 'category', 'description'));
 if (cw_image_check_posted($file_upload_data['categories_images_thumb'])) {
     cw_image_save($file_upload_data['categories_images_thumb']);
 }
 $parent_categories = cw_category_get_path($cat);
 if (is_array($parent_categories)) {
     cw_recalc_subcat_count($parent_categories);
#
# Countries per page
#
$objects_per_page = 40;
if ($action == "deactivate_all") {
    db_query("UPDATE {$tables['map_countries']} SET active=0");
    $top_message['content'] = cw_get_langvar_by_name("msg_adm_countries_disabled");
}
if ($action == "activate_all") {
    db_query("UPDATE {$tables['map_countries']} SET active=1");
    $top_message['content'] = cw_get_langvar_by_name("msg_adm_countries_enabled");
}
if ($action == 'update' && is_array($posted_data)) {
    foreach ($posted_data as $k => $v) {
        $to_update = array('active' => $v['active'], 'display_regions' => $v['display_regions'], 'display_states' => $v['display_states'], 'display_counties' => $v['display_counties'], 'display_cities' => $v['display_cities'], 'lang' => $v['lang']);
        cw_array2update('map_countries', $to_update, "code='{$k}'");
        db_query("UPDATE {$tables['languages']} SET value = '{$v['country']}' WHERE name = 'country_{$k}' AND code = '{$current_language}'");
    }
    $top_message['content'] = cw_get_langvar_by_name("msg_adm_countries_upd");
    cw_header_location("index.php?target=countries&zone={$zone}&page={$page}");
}
if ($action) {
    cw_header_location("index.php?target=countries&zone={$zone}&page={$page}");
}
$condition = "";
if (!empty($zone)) {
    if ($zone == "SU") {
        $condition = " WHERE {$tables['map_countries']}.code IN ('AM','AZ','BY','EE','GE','KZ','KG','LV','LT','MD','RU','TJ','TM','UA','UZ')";
    } else {
        $condition = " WHERE {$tables['map_countries']}.region='{$zone}'";
    }
Пример #21
0
            $is_code_exists = cw_query_first_cell("SELECT COUNT(*) FROM {$tables['map_states']} WHERE code = '{$v['code']}' AND country_code = '{$country}'") > 0;
            if (!$is_code_exists) {
                if ($v['code'] && $v['state']) {
                    $query_data = array('state' => $v['state'], 'code' => $v['code'], 'country_code' => $country);
                    cw_array2insert('map_states', $query_data);
                }
            } else {
                $top_message = array("content" => cw_get_langvar_by_name("msg_adm_warn_states_duplicate"), "type" => "W");
                break;
            }
        } else {
            $is_code_exists = cw_query_first_cell("SELECT COUNT(*) FROM {$tables['map_states']} WHERE code = '{$v['code']}' AND country_code = '{$country}'") > 0;
            if ($is_code_exists) {
                cw_unset($v, "code");
            }
            cw_array2update("map_states", $v, "state_id = '{$k}'");
        }
    }
    cw_header_location("index.php?target={$target}&mode=states&country={$country}" . (!empty($page) ? "&page={$page}" : ""));
}
$search_query = "FROM {$tables['map_states']}, {$tables['map_countries']} LEFT JOIN {$tables['languages']} as lng1 ON lng1.name = CONCAT('country_', {$tables['map_countries']}.code) AND lng1.code = '{$current_language}' LEFT JOIN {$tables['languages']} as lng2 ON lng2.name = CONCAT('country_', {$tables['map_countries']}.code) AND lng2.code = '{$config['default_admin_language']}' WHERE {$tables['map_states']}.country_code={$tables['map_countries']}.code AND {$tables['map_states']}.country_code='{$country}'";
$total_items_in_search = cw_query_first_cell("SELECT COUNT(*) {$search_query}");
if ($total_items_in_search > 0) {
    $navigation = cw_core_get_navigation($target, $total_items_in_search, $page);
    $navigation['script'] = "index.php?target={$target}&mode=states&country={$country}";
    $smarty->assign('navigation', $navigation);
    $states = cw_query("SELECT {$tables['map_states']}.*, IFNULL(lng1.value, lng2.value) as country {$search_query} ORDER BY country_code, state LIMIT {$navigation['first_page']}, {$navigation['objects_per_page']}");
    $smarty->assign('states', $states);
}
$smarty->assign('country', $country);
$smarty->assign('country_info', cw_map_get_country($country));
Пример #22
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 cw_array2update_esc($tab, $arr, $where = '')
{
    foreach ($arr as $k => $v) {
        if (preg_match("'\\''", $v)) {
            $arr[$k] = addslashes($v);
        }
    }
    print "u ";
    /*
    print("<br>");
    print_r(array($tab,$arr,$where)); 
    print("<br>\n");
    return;*/
    cw_log_add("import_xcart", array("update", $tab, $arr, $where));
    return cw_array2update($tab, $arr, $where);
}
         cw_add_top_message(cw_get_langvar_by_name('err_account_temporary_disabled'), 'E');
         if (!empty($linkedin_login_info['return_url'])) {
             cw_header_location($linkedin_login_info['return_url']);
         } else {
             cw_header_location($linkedin_redirect_url);
         }
     }
 } else {
     //add new customer to database
     $register = array();
     $register['email'] = $linkedin_email;
     $register['usertype'] = $current_area;
     $partner_membership =& cw_session_register('partner_membership');
     $register['membership_id'] = $partner_membership;
     $customer_id = cw_user_create_profile($register);
     cw_array2update('customers', array('oauth_uid' => $linkedin_user_id, 'oauth_type' => 'L'), "customer_id='{$customer_id}'");
     $user_name = array($linkedin_user_firstname, $linkedin_user_lastname);
     $address = array('main' => 1, 'firstname' => $user_name[0], 'lastname' => $user_name[1]);
     $userinfo = array('addresses' => $address);
     cw_user_update($userinfo, $customer_id, $customer_id);
     $user_data = cw_query_first("SELECT {$tables['customers']}.* FROM {$tables['customers']} WHERE customer_id='{$customer_id}'");
 }
 if (!empty($user_data)) {
     //perform login
     $email = $user_data['email'];
     if ($usertype == 'R') {
         $usertype = 'C';
         $product_list_template =& cw_session_register("product_list_template");
         $product_list_template = 2;
     }
     $identifiers[$current_area == 'R' ? 'C' : $current_area] = array('customer_id' => $user_data['customer_id']);
function dod_modify_details($generator_id)
{
    global $tables, $available_fields, $optional_fields, $skip_striptags_fields, $date_fields;
    /*if (empty($generator_id)) {
          return array(false, 'generator Id was not provided');
      }*/
    global $generator_data;
    if (empty($generator_data) || !is_array($generator_data)) {
        return array(true, null);
    }
    $error = null;
    $data = array();
    $excl_from_base_list = array('generator_id');
    foreach ($excl_from_base_list as $field) {
        if (isset($available_fields[$field])) {
            unset($available_fields[$field]);
        }
    }
    $additional_lang_data = array();
    foreach ($date_fields as $field) {
        if (isset($generator_data[$field]) && !empty($generator_data[$field])) {
            $generator_data[$field] = cw_core_strtotime($generator_data[$field]);
        }
    }
    foreach ($available_fields as $field => $field_type) {
        if (isset($generator_data[$field])) {
            $result = settype($generator_data[$field], $field_type);
            if ($result === false) {
                $error = 'msg_dod_incorrect_field_type';
                $additional_lang_data = array('field_name' => $field);
                break;
            }
            if ($field == 'description') {
                if ($generator_data[$field] == '<p>&#160;</p>') {
                    $generator_data[$field] = null;
                }
            }
            if (empty($generator_data[$field])) {
                if (in_array($field, $optional_fields)) {
                    $data[$field] = null;
                } else {
                    $error = 'msg_dod_empty_fields';
                    break;
                }
            } else {
                if ($field_type == 'string' && !in_array($field, $skip_striptags_fields)) {
                    $generator_data[$field] = cw_strip_tags($generator_data[$field]);
                }
                $data[$field] =& $generator_data[$field];
            }
        } else {
            if ($field_type == 'bool') {
                $data[$field] = 0;
            } else {
                if (in_array($field, $optional_fields)) {
                    $data[$field] = null;
                } else {
                    $error = 'msg_dod_empty_fields';
                    break;
                }
            }
        }
    }
    $sess_generator_data =& cw_session_register('_generator_data');
    $GLOBALS['_generator_data'] =& $generator_data;
    cw_session_register('_generator_data');
    if (!empty($error)) {
        return array(false, cw_get_langvar_by_name($error, $additional_lang_data));
    }
    global $attributes;
    $data['attributes'] = $attributes;
    $error = cw_error_check($data, array(), dod_ATTR_ITEM_TYPE);
    //cw_attributes_check($array_to_check['attribute_class_id'], $array_to_check['attributes'], $attributes_type, $index)
    if (!empty($error)) {
        return array(false, $error);
    }
    global $file_upload_data;
    if (empty($generator_id)) {
        if (empty($data)) {
            return array(false, null);
        }
        $generator_id = cw_array2insert($tables['dod_generators'], cw_addslashes($data));
    } else {
        cw_array2update($tables['dod_generators'], cw_addslashes($data), 'generator_id = \'' . $generator_id . '\'');
    }
    cw_call('cw_attributes_save', array('item_id' => $generator_id, 'item_type' => dod_ATTR_ITEM_TYPE, 'attributes' => $attributes));
    cw_session_unregister('_generator_data');
    return array($generator_id, null);
}
                 $cs_value_string = cw_query_first_cell("select value from {$tables['attributes_default']} where attribute_id='{$cs_attr['attribute_id']}' and attribute_value_id='{$cs_attr_value}'");
                 cw_array2insert('cms_restrictions', $st = array('contentsection_id' => $contentsection_id, 'object_type' => 'A', 'object_id' => $cs_attr['attribute_id'], 'operation' => $cs_attr['operation'], 'value_id' => !empty($cs_value_string) ? $cs_attr_value : 0, 'value' => !empty($cs_value_string) ? $cs_value_string : $cs_attr_value), true);
             }
         }
     }
 }
 switch ($content_section['type']) {
     case 'staticpage':
     case 'staticpopup':
     case 'html':
         if (isset($content_section_content) && strlen($content_section_content) > 0 && !empty($contentsection_id)) {
             $data = array('content' => htmlspecialchars_decode(trim($content_section_content)));
             if ($current_language == $config['default_customer_language']) {
                 cw_array2update('cms', $data, "contentsection_id = '" . $contentsection_id . "'");
             }
             cw_array2update('cms_alt_languages', $data, "contentsection_id = '" . $contentsection_id . "' AND code = '" . $current_language . "'");
         }
         // no break here because 'html' type needs image processing as well
     // no break here because 'html' type needs image processing as well
     case 'image':
         if (!empty($contentsection_id) && !empty($file_upload_data) && is_array($file_upload_data)) {
             $is_image_uploaded_and_saved = false;
             if (cw_image_check_posted($file_upload_data['cms_images'])) {
                 if (cw_image_save($file_upload_data['cms_images'], array('id' => $contentsection_id, 'code' => $current_language))) {
                     $is_image_uploaded_and_saved = true;
                 }
             }
             if (!$is_image_uploaded_and_saved) {
                 cw_add_top_message(cw_get_langvar_by_name('msg_ab_err_banner_image_not_uploaded_or_saved'), 'E');
                 cw_header_location('index.php?target=cms&mode=add');
             }
Пример #27
0
 }
 if (!count($fill_error)) {
     $list_values = $list;
     $list_values['salesman_customer_id'] = '';
     if (AREA_TYPE == 'B') {
         $list['salesman_customer_id'] = $customer_id;
         if ($list['list_id']) {
             $def_val = cw_query_first("select * from {$tables['newslists']} where list_id='" . $list['list_id'] . "'");
             $list_values['avail'] = $def_val['avail'];
         } else {
             $list_values['avail'] = 0;
         }
     }
     cw_unset($list_values, 'list_id');
     if (!empty($list['list_id'])) {
         cw_array2update('newslists', $list_values, "list_id='{$list['list_id']}'");
         $top_message['content'] = cw_get_langvar_by_name("msg_adm_newslist_upd");
     } else {
         $list_values['lngcode'] = empty($edit_lng) ? $current_language : $edit_lng;
         cw_array2insert('newslists', $list_values);
         $list['list_id'] = db_insert_id();
         $top_message['content'] = cw_get_langvar_by_name("msg_adm_newslists_add");
     }
     db_query("delete from {$tables['newslists_memberships']} where list_id='{$list['list_id']}'");
     if (is_array($memberships)) {
         $arr_to_insert = array();
         $arr_to_insert['list_id'] = $list['list_id'];
         foreach ($memberships as $membership_id) {
             $arr_to_insert['membership_id'] = $membership_id;
             cw_array2insert('newslists_memberships', $arr_to_insert, true);
         }
function ppd_filetype_update()
{
    global $tables, $top_message, $smarty, $available_fields;
    global $optional_fields, $skip_striptags_fields;
    if ($_SERVER['REQUEST_METHOD'] != 'POST') {
        ppd_filetype_redirect();
    }
    global $type_ids, $ppd_types;
    if (!isset($type_ids)) {
        $type_ids = isset($_POST['type_ids']) ? $_POST['type_ids'] : array();
    }
    if (!isset($ppd_types)) {
        $ppd_types = isset($_POST['ppd_types']) ? $_POST['ppd_types'] : array();
    }
    if (empty($type_ids) || empty($ppd_types) || !is_array($ppd_types)) {
        ppd_filetype_redirect();
    }
    $type_ids = array_unique(array_map('ppd_filetype_process_ids', array_keys($type_ids)));
    $type_ids_query = implode('\', \'', $type_ids);
    $type_ids = cw_query_column('SELECT `type_id` FROM ' . $tables['ppd_types'] . ' WHERE type_id IN (\'' . $type_ids_query . '\')');
    if (empty($type_ids) || !is_array($type_ids)) {
        ppd_filetype_redirect();
    }
    if (isset($available_fields['type_id'])) {
        unset($available_fields['type_id']);
    }
    $error = null;
    foreach ($type_ids as $type_id) {
        $data = array();
        $additional_lang_data = array();
        if (!isset($ppd_types[$type_id])) {
            continue;
        }
        foreach ($available_fields as $field => $field_type) {
            if (isset($ppd_types[$type_id][$field])) {
                $result = settype($ppd_types[$type_id][$field], $field_type);
                if ($result === false) {
                    $error = 'msg_ppd_incorrect_field_type';
                    $additional_lang_data = array('field_name' => $field . ' type ID: ' . $type_id);
                    break 2;
                }
                if (empty($ppd_types[$type_id][$field])) {
                    if (in_array($field, $optional_fields)) {
                        $data[$field] = null;
                    }
                } else {
                    if ($field_type == 'string' && !in_array($field, $skip_striptags_fields)) {
                        $ppd_types[$type_id][$field] = cw_strip_tags($ppd_types[$type_id][$field]);
                    }
                    $data[$field] =& $ppd_types[$type_id][$field];
                }
            } else {
                if ($field_type == 'bool') {
                    $data[$field] = 0;
                }
            }
        }
        if (!empty($data)) {
            cw_array2update($tables['ppd_types'], $data, 'type_id = \'' . $type_id . '\'');
        }
    }
    $top_message = array('content' => cw_get_langvar_by_name('msg_ppd_filetypes_updated_succes'), 'type' => 'I');
    if (!empty($error)) {
        $top_message = array('content' => cw_get_langvar_by_name($error, $additional_lang_data), 'type' => 'E');
    }
    ppd_filetype_redirect();
}
 if (!empty($user_data)) {
     // login user
     if ($user_data['status'] != 'Y') {
         //error message disabled login
         cw_add_top_message(cw_get_langvar_by_name('err_account_temporary_disabled'), 'E');
         cw_header_location($instagram_redirect_url);
     }
 } else {
     //add new customer to database
     $register = array();
     $register['email'] = $instagram_email;
     $register['usertype'] = $current_area;
     $partner_membership =& cw_session_register('partner_membership');
     $register['membership_id'] = $partner_membership;
     $customer_id = cw_user_create_profile($register);
     cw_array2update('customers', array('oauth_uid' => $instagram_user_id, 'oauth_type' => 'I'), "customer_id='{$customer_id}'");
     $user_name = explode(" ", $instagram_user_name);
     $address = array('main' => 1, 'firstname' => $user_name[0], 'lastname' => $user_name[1]);
     $userinfo = array('addresses' => $address);
     cw_user_update($userinfo, $customer_id, $customer_id);
     $user_data = cw_query_first("SELECT {$tables['customers']}.* FROM {$tables['customers']} WHERE customer_id='{$customer_id}'");
 }
 if (!empty($user_data)) {
     //perform login
     $email = $user_data['email'];
     if ($usertype == 'R') {
         $usertype = 'C';
         $product_list_template =& cw_session_register("product_list_template");
         $product_list_template = 2;
     }
     $identifiers[$current_area == 'R' ? 'C' : $current_area] = array('customer_id' => $user_data['customer_id']);
                    continue;
                }
                $query_data['answer_id'] = $aid;
                if ($answers[$aid]['textbox_type'] != 'N' && isset($v['comment'][$aid])) {
                    $query_data['comment'] = $v['comment'][$aid];
                }
                cw_array2insert('survey_result_answers', $query_data);
                if ($question['answers_type'] == 'R') {
                    continue;
                }
            }
            cw_unset($quids, $qid);
        }
    }
    $completed = empty($quids) ? "Y" : (count($quids) == $quids_count ? 'E' : 'N');
    cw_array2update("survey_results", array("completed" => $completed), "survey_result_id = '{$survey_result_id}'");
    $filled_surveys[$survey_result_id] = $survey_id;
    $top_message = array('content' => !empty($survey['complete']) ? $survey['complete'] : cw_get_langvar_by_name('txt_survey_default_complete_message'));
    if ($survey['publish_results']) {
        cw_header_location("index.php?target=surveys&survey_id=" . $survey_id . "&mode=view");
    }
    cw_header_location("index.php");
}
if ((!empty($survey_id) || !empty($survey_key)) && empty($mode)) {
    # Display survey
    if (!empty($survey_key)) {
        $survey_id = cw_query_first_cell("SELECT survey_id FROM {$tables['survey_maillist']} WHERE access_key = '{$survey_key}'");
    }
    $survey = cw_get_survey($survey_id);
    if (!empty($survey) && $survey['valid'] && ($survey['survey_type'] != 'R' || !empty($customer_id) || !empty($survey_key))) {
        if ($check_res = cw_check_survey_filling($survey_id)) {