Пример #1
0
function fn_update_payment($payment_data, $payment_id, $lang_code = DESCR_SL)
{
    if (!empty($payment_data['processor_id'])) {
        $payment_data['template'] = db_get_field("SELECT processor_template FROM ?:payment_processors WHERE processor_id = ?i", $payment_data['processor_id']);
    }
    $payment_data['localization'] = !empty($payment_data['localization']) ? fn_implode_localizations($payment_data['localization']) : '';
    $payment_data['usergroup_ids'] = !empty($payment_data['usergroup_ids']) ? implode(',', $payment_data['usergroup_ids']) : '';
    if (!empty($payment_id)) {
        db_query("UPDATE ?:payments SET ?u WHERE payment_id = ?i", $payment_data, $payment_id);
        db_query("UPDATE ?:payment_descriptions SET ?u WHERE payment_id = ?i AND lang_code = ?s", $payment_data, $payment_id, $lang_code);
    } else {
        $payment_data['payment_id'] = $payment_id = db_query("INSERT INTO ?:payments ?e", $payment_data);
        foreach ((array) Registry::get('languages') as $payment_data['lang_code'] => $_v) {
            db_query("INSERT INTO ?:payment_descriptions ?e", $payment_data);
        }
    }
    fn_attach_image_pairs('payment_image', 'payment', $payment_id, $lang_code);
    // Update payment processor settings
    if (!empty($payment_data['processor_params'])) {
        db_query("UPDATE ?:payments SET params = ?s WHERE payment_id = ?i", serialize($payment_data['processor_params']), $payment_id);
    }
    return $payment_id;
}
Пример #2
0
function fn_banners_update_banner($data, $banner_id, $lang_code = DESCR_SL)
{
    if (isset($data['timestamp'])) {
        $data['timestamp'] = fn_parse_date($data['timestamp']);
    }
    $data['localization'] = empty($data['localization']) ? '' : fn_implode_localizations($data['localization']);
    if (!empty($banner_id)) {
        db_query("UPDATE ?:banners SET ?u WHERE banner_id = ?i", $data, $banner_id);
        db_query("UPDATE ?:banner_descriptions SET ?u WHERE banner_id = ?i AND lang_code = ?s", $data, $banner_id, $lang_code);
        $banner_image_id = fn_get_banner_image_id($banner_id, $lang_code);
        $banner_image_exist = !empty($banner_image_id);
        $banner_is_multilang = Registry::get('addons.banners.banner_multilang') == 'Y';
        $image_is_update = fn_banners_need_image_update();
        if ($banner_is_multilang) {
            if ($banner_image_exist && $image_is_update) {
                fn_delete_image_pairs($banner_image_id, 'promo');
                db_query("DELETE FROM ?:banner_images WHERE banner_id = ?i AND lang_code = ?s", $banner_id, $lang_code);
                $banner_image_exist = false;
            }
        } else {
            if (isset($data['url'])) {
                db_query("UPDATE ?:banner_descriptions SET url = ?s WHERE banner_id = ?i", $data['url'], $banner_id);
            }
        }
        if ($image_is_update && !$banner_image_exist) {
            $banner_image_id = db_query("INSERT INTO ?:banner_images (banner_id, lang_code) VALUE(?i, ?s)", $banner_id, $lang_code);
        }
        $pair_data = fn_attach_image_pairs('banners_main', 'promo', $banner_image_id, $lang_code);
        if (!$banner_is_multilang && !$banner_image_exist) {
            fn_banners_image_all_links($banner_id, $pair_data, $lang_code);
        }
    } else {
        $banner_id = $data['banner_id'] = db_query("REPLACE INTO ?:banners ?e", $data);
        foreach (Languages::getAll() as $data['lang_code'] => $v) {
            db_query("REPLACE INTO ?:banner_descriptions ?e", $data);
        }
        if (fn_banners_need_image_update()) {
            $data_banner_image = array('banner_id' => $banner_id, 'lang_code' => $lang_code);
            $banner_image_id = db_get_next_auto_increment_id('banner_images');
            $pair_data = fn_attach_image_pairs('banners_main', 'promo', $banner_image_id, $lang_code);
            if (!empty($pair_data)) {
                db_query("INSERT INTO ?:banner_images ?e", $data_banner_image);
                fn_banners_image_all_links($banner_id, $pair_data, $lang_code);
            }
        }
    }
    return $banner_id;
}
Пример #3
0
function fn_update_banner($data, $banner_id, $lang_code = DESCR_SL)
{
    if (isset($data['timestamp'])) {
        $data['timestamp'] = fn_parse_date($data['timestamp']);
    }
    $data['localization'] = empty($data['localization']) ? '' : fn_implode_localizations($data['localization']);
    if (!empty($banner_id)) {
        db_query("UPDATE ?:banners SET ?u WHERE banner_id = ?i", $data, $banner_id);
        db_query("UPDATE ?:banner_descriptions SET ?u WHERE banner_id = ?i AND lang_code = ?s", $data, $banner_id, $lang_code);
    } else {
        $banner_id = $data['banner_id'] = db_query("REPLACE INTO ?:banners ?e", $data);
        foreach ((array) Registry::get('languages') as $data['lang_code'] => $v) {
            db_query("REPLACE INTO ?:banner_descriptions ?e", $data);
        }
    }
    fn_attach_image_pairs('banners_main', 'banner', $banner_id, $lang_code);
    return $banner_id;
}
Пример #4
0
function fn_update_product($product_data, $product_id = 0, $lang_code = CART_LANGUAGE)
{
    $_data = $product_data;
    if (!empty($product_data['timestamp'])) {
        $_data['timestamp'] = fn_parse_date($product_data['timestamp']);
        // Minimal data for product record
    }
    if (!empty($product_data['avail_since'])) {
        $_data['avail_since'] = fn_parse_date($product_data['avail_since']);
    }
    if (isset($product_data['tax_ids'])) {
        $_data['tax_ids'] = empty($product_data['tax_ids']) ? '' : fn_create_set($product_data['tax_ids']);
    }
    if (isset($product_data['localization'])) {
        $_data['localization'] = empty($product_data['localization']) ? '' : fn_implode_localizations($_data['localization']);
    }
    if (isset($product_data['usergroup_ids'])) {
        $_data['usergroup_ids'] = empty($product_data['usergroup_ids']) ? '' : implode(',', $_data['usergroup_ids']);
    }
    if (Registry::get('settings.General.allow_negative_amount') == 'N' && isset($_data['amount'])) {
        $_data['amount'] = abs($_data['amount']);
    }
    // add new product
    if (empty($product_id)) {
        $create = true;
        // product title can't be empty
        if (empty($product_data['product'])) {
            return false;
        }
        $product_id = db_query("INSERT INTO ?:products ?e", $_data);
        if (empty($product_id)) {
            return false;
        }
        //
        // Adding same product descriptions for all cart languages
        //
        $_data = $product_data;
        $_data['product_id'] = $product_id;
        $_data['product'] = trim($_data['product'], " -");
        foreach ((array) Registry::get('languages') as $_data['lang_code'] => $_v) {
            db_query("INSERT INTO ?:product_descriptions ?e", $_data);
        }
        // update product
    } else {
        if (isset($product_data['product']) && empty($product_data['product'])) {
            unset($product_data['product']);
        }
        db_query("UPDATE ?:products SET ?u WHERE product_id = ?i", $_data, $product_id);
        $_data = $product_data;
        if (!empty($_data['product'])) {
            $_data['product'] = trim($_data['product'], " -");
        }
        db_query("UPDATE ?:product_descriptions SET ?u WHERE product_id = ?i AND lang_code = ?s", $_data, $product_id, $lang_code);
    }
    // Log product add/update
    fn_log_event('products', !empty($create) ? 'create' : 'update', array('product_id' => $product_id));
    if (!empty($product_data['product_features'])) {
        $i_data = array('product_id' => $product_id, 'lang_code' => $lang_code);
        foreach ($product_data['product_features'] as $feature_id => $value) {
            // Check if feature is applicable for this product
            $id_paths = db_get_fields("SELECT ?:categories.id_path FROM ?:products_categories LEFT JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id WHERE product_id = ?i", $product_id);
            $_params = array('category_ids' => array_unique(explode('/', implode('/', $id_paths))), 'feature_id' => $feature_id);
            list($_feature) = fn_get_product_features($_params);
            if (empty($_feature)) {
                $_feature = db_get_field("SELECT description FROM ?:product_features_descriptions WHERE feature_id = ?i AND lang_code = ?s", $feature_id, CART_LANGUAGE);
                $_product = db_get_field("SELECT product FROM ?:product_descriptions WHERE product_id = ?i AND lang_code = ?s", $product_id, CART_LANGUAGE);
                fn_set_notification('E', fn_get_lang_var('error'), str_replace(array('[feature_name]', '[product_name]'), array($_feature, $_product), fn_get_lang_var('product_feature_cannot_assigned')));
                continue;
            }
            $i_data['feature_id'] = $feature_id;
            unset($i_data['value']);
            unset($i_data['variant_id']);
            unset($i_data['value_int']);
            $feature_type = db_get_field("SELECT feature_type FROM ?:product_features WHERE feature_id = ?i", $feature_id);
            // Delete variants in current language
            if ($feature_type == 'T') {
                db_query("DELETE FROM ?:product_features_values WHERE feature_id = ?i AND product_id = ?i AND lang_code = ?s", $feature_id, $product_id, $lang_code);
            } else {
                db_query("DELETE FROM ?:product_features_values WHERE feature_id = ?i AND product_id = ?i", $feature_id, $product_id);
            }
            if ($feature_type == 'D') {
                $i_data['value_int'] = fn_parse_date($value);
            } elseif ($feature_type == 'M') {
                if (!empty($product_data['add_new_variant'][$feature_id]['variant'])) {
                    $value = empty($value) ? array() : $value;
                    $value[] = fn_add_feature_variant($feature_id, $product_data['add_new_variant'][$feature_id]);
                }
                if (!empty($value)) {
                    foreach ($value as $variant_id) {
                        foreach (Registry::get('languages') as $i_data['lang_code'] => $_d) {
                            // insert for all languages
                            $i_data['variant_id'] = $variant_id;
                            db_query("REPLACE INTO ?:product_features_values ?e", $i_data);
                        }
                    }
                }
                continue;
            } elseif (in_array($feature_type, array('S', 'N', 'E'))) {
                if (!empty($product_data['add_new_variant'][$feature_id]['variant'])) {
                    $i_data['variant_id'] = fn_add_feature_variant($feature_id, $product_data['add_new_variant'][$feature_id]);
                } elseif (!empty($value) && $value != 'disable_select') {
                    if ($feature_type == 'N') {
                        $i_data['value_int'] = db_get_field("SELECT variant FROM ?:product_feature_variant_descriptions WHERE variant_id = ?i AND lang_code = ?s", $value, CART_LANGUAGE);
                    }
                    $i_data['variant_id'] = $value;
                } else {
                    continue;
                }
            } else {
                if ($value == '') {
                    continue;
                }
                if ($feature_type == 'O') {
                    $i_data['value_int'] = $value;
                } else {
                    $i_data['value'] = $value;
                }
            }
            if ($feature_type != 'T') {
                // feature values are common for all languages, except text (T)
                foreach (Registry::get('languages') as $i_data['lang_code'] => $_d) {
                    db_query("REPLACE INTO ?:product_features_values ?e", $i_data);
                }
            } else {
                // for text feature, update current language only
                $i_data['lang_code'] = $lang_code;
                db_query("INSERT INTO ?:product_features_values ?e", $i_data);
            }
        }
    }
    // Update product prices
    if (isset($product_data['price'])) {
        if (!isset($product_data['prices'])) {
            $product_data['prices'] = array();
            $skip_price_delete = true;
        }
        $_price = array('price' => abs($product_data['price']), 'lower_limit' => 1);
        array_unshift($product_data['prices'], $_price);
    }
    if (!empty($product_data['prices'])) {
        if (empty($skip_price_delete)) {
            db_query("DELETE FROM ?:product_prices WHERE product_id = ?i", $product_id);
        }
        foreach ($product_data['prices'] as $v) {
            if (!empty($v['lower_limit'])) {
                $v['product_id'] = $product_id;
                db_query("REPLACE INTO ?:product_prices ?e", $v);
            }
        }
    }
    if (!empty($product_data['popularity'])) {
        $_data = array('product_id' => $product_id, 'total' => intval($product_data['popularity']));
        db_query("INSERT INTO ?:product_popularity ?e ON DUPLICATE KEY UPDATE total = ?i", $_data, $product_data['popularity']);
    }
    fn_set_hook('update_product', $product_data, $product_id, $lang_code);
    return $product_id;
}
Пример #5
0
function fn_update_news($news_id, $news_data, $lang_code = CART_LANGUAGE)
{
    // news title required
    if (empty($news_data['news'])) {
        return false;
    }
    if (!empty($news_id) && !fn_check_company_id('news', 'news_id', $news_id)) {
        fn_company_access_denied_notification();
        return false;
    }
    $_data = $news_data;
    $_data['date'] = fn_parse_date($news_data['date']);
    if (isset($_data['localization'])) {
        $_data['localization'] = empty($_data['localization']) ? '' : fn_implode_localizations($_data['localization']);
    }
    if (empty($news_id)) {
        $create = true;
        $news_id = $_data['news_id'] = db_query("REPLACE INTO ?:news ?e", $_data);
        if (empty($news_id)) {
            return false;
        }
        // Adding descriptions
        foreach (fn_get_translation_languages() as $_data['lang_code'] => $v) {
            db_query("INSERT INTO ?:news_descriptions ?e", $_data);
        }
    } else {
        $create = false;
        db_query("UPDATE ?:news SET ?u WHERE news_id = ?i", $_data, $news_id);
        // update news descriptions
        $_data = $news_data;
        db_query("UPDATE ?:news_descriptions SET ?u WHERE news_id = ?i AND lang_code = ?s", $_data, $news_id, $lang_code);
    }
    // Log news update/add
    fn_log_event('news', !empty($create) ? 'create' : 'update', array('news_id' => $news_id));
    fn_set_hook('update_news', $news_data, $news_id, $lang_code, $create);
    return $news_id;
}
Пример #6
0
function fn_update_page($page_data, $page_id = 0, $lang_code = CART_LANGUAGE)
{
    if (!empty($page_data['avail_from_timestamp'])) {
        $page_data['avail_from_timestamp'] = fn_parse_date($page_data['avail_from_timestamp']);
    } else {
        $page_data['avail_from_timestamp'] = 0;
    }
    if (!empty($page_data['avail_till_timestamp'])) {
        $page_data['avail_till_timestamp'] = fn_parse_date($page_data['avail_till_timestamp']) + 86399;
    } else {
        $page_data['avail_till_timestamp'] = 0;
    }
    if (isset($page_data['usergroup_ids'])) {
        $page_data['usergroup_ids'] = empty($page_data['usergroup_ids']) ? '' : implode(',', $page_data['usergroup_ids']);
    }
    $_data = $page_data;
    if (isset($page_data['timestamp'])) {
        $_data['timestamp'] = fn_parse_date($page_data['timestamp']);
    }
    if (isset($_data['localization'])) {
        $_data['localization'] = empty($_data['localization']) ? '' : fn_implode_localizations($_data['localization']);
    }
    fn_set_company_id($_data);
    if (empty($page_id)) {
        // page title required
        if (empty($page_data['page'])) {
            return false;
        }
        // add new page
        $_data['page_id'] = $page_id = db_query('INSERT INTO ?:pages ?e', $_data);
        foreach ((array) Registry::get('languages') as $_data['lang_code'] => $v) {
            db_query('INSERT INTO ?:page_descriptions ?e', $_data);
        }
        // now we need to update 'id_path' field, as we know $page_id
        /* Generate id_path for page */
        $parent_id = intval($_data['parent_id']);
        if ($parent_id == 0) {
            $id_path = $page_id;
        } else {
            $id_path = db_get_row("SELECT id_path FROM ?:pages WHERE page_id = ?i", $parent_id);
            $id_path = $id_path['id_path'] . '/' . $page_id;
        }
        db_query('UPDATE ?:pages SET ?u WHERE page_id = ?i', array('id_path' => $id_path), $page_id);
    } else {
        if (!fn_check_company_id('pages', 'page_id', $page_id)) {
            fn_company_access_denied_notification();
            return false;
        }
        $old_company_id = fn_get_company_id('pages', 'page_id', $page_id);
        if ($_data['company_id'] != $old_company_id) {
            fn_change_page_company($page_id, $_data['company_id']);
        }
        // page title is not updated
        if (empty($page_data['page'])) {
            unset($page_data['page']);
        }
        // update existing page
        db_query('UPDATE ?:pages SET ?u WHERE page_id = ?i', $_data, $page_id);
        db_query('UPDATE ?:page_descriptions SET ?u WHERE page_id = ?i AND lang_code = ?s', $_data, $page_id, $lang_code);
        // regenerate id_path for child pages
        if (isset($page_data['parent_id'])) {
            fn_change_page_parent($page_id, $page_data['parent_id']);
        }
    }
    if (!empty($page_data['block_id'])) {
        fn_add_items_to_block($page_data['block_id'], $page_data['add_items'], $page_id, 'pages');
    }
    fn_set_hook('update_page', $page_data, $page_id, $lang_code);
    return $page_id;
}
Пример #7
0
/**
 * Adds or updates category
 *
 * @param array $category_data Category data
 * @param int $category_id Category identifier
 * @param string $lang_code Two-letter language code (e.g. 'en', 'ru', etc.)
 * @return int New or updated category identifier
 */
function fn_update_category($category_data, $category_id = 0, $lang_code = CART_LANGUAGE)
{
    /**
     * Update category data (running before fn_update_category() function)
     *
     * @param array  $category_data Category data
     * @param int    $category_id   Category identifier
     * @param string $lang_code     Two-letter language code (e.g. 'en', 'ru', etc.)
     */
    fn_set_hook('update_category_pre', $category_data, $category_id, $lang_code);
    // category title required
    if (empty($category_data['category'])) {
        //return false; // FIXME: management page doesn't have category name
    }
    if (isset($category_data['localization'])) {
        $category_data['localization'] = empty($category_data['localization']) ? '' : fn_implode_localizations($category_data['localization']);
    }
    if (isset($category_data['usergroup_ids'])) {
        $category_data['usergroup_ids'] = empty($category_data['usergroup_ids']) ? '0' : implode(',', $category_data['usergroup_ids']);
    }
    if (fn_allowed_for('ULTIMATE')) {
        fn_set_company_id($category_data);
    }
    $_data = $category_data;
    unset($_data['parent_id']);
    if (isset($category_data['timestamp'])) {
        $_data['timestamp'] = fn_parse_date($category_data['timestamp']);
    }
    if (isset($_data['position']) && empty($_data['position']) && $_data['position'] != '0' && isset($category_data['parent_id'])) {
        $_data['position'] = db_get_field("SELECT max(position) FROM ?:categories WHERE parent_id = ?i", $category_data['parent_id']);
        $_data['position'] = $_data['position'] + 10;
    }
    if (isset($_data['selected_layouts'])) {
        $_data['selected_layouts'] = serialize($_data['selected_layouts']);
    }
    if (isset($_data['use_custom_templates']) && $_data['use_custom_templates'] == 'N') {
        // Clear the layout settings if the category custom templates were disabled
        $_data['product_columns'] = $_data['selected_layouts'] = $_data['default_layout'] = '';
    }
    // create new category
    if (empty($category_id)) {
        if (fn_allowed_for('ULTIMATE') && empty($_data['company_id'])) {
            fn_set_notification('E', __('error'), __('need_company_id'));
            return false;
        }
        $create = true;
        $category_id = db_query("INSERT INTO ?:categories ?e", $_data);
        $_data['category_id'] = $category_id;
        foreach (fn_get_translation_languages() as $_data['lang_code'] => $v) {
            db_query("INSERT INTO ?:category_descriptions ?e", $_data);
        }
        $category_data['parent_id'] = !empty($category_data['parent_id']) ? $category_data['parent_id'] : 0;
        // update existing category
    } else {
        $category_data['old_company_id'] = db_get_field("SELECT company_id FROM ?:categories WHERE category_id = ?i", $category_id);
        $arow = db_query("UPDATE ?:categories SET ?u WHERE category_id = ?i", $_data, $category_id);
        $arow_description = db_query("UPDATE ?:category_descriptions SET ?u WHERE category_id = ?i AND lang_code = ?s", $_data, $category_id, $lang_code);
        if ($arow === false && $arow_description === false) {
            fn_set_notification('E', __('error'), __('object_not_found', array('[object]' => __('category'))), '', '404');
            $category_id = false;
        }
    }
    if ($category_id) {
        // regenerate id_path for all child categories of the updated category
        if (isset($category_data['parent_id'])) {
            fn_change_category_parent($category_id, intval($category_data['parent_id']));
        }
        // Log category add/update
        fn_log_event('categories', !empty($create) ? 'create' : 'update', array('category_id' => $category_id));
        // Assign usergroup to all subcategories
        if (!empty($_data['usergroup_to_subcats']) && $_data['usergroup_to_subcats'] == 'Y') {
            $id_path = db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", $category_id);
            db_query("UPDATE ?:categories SET usergroup_ids = ?s WHERE id_path LIKE ?l", $_data['usergroup_ids'], "{$id_path}/%");
        }
    }
    /**
     * Update category data (running after fn_update_category() function)
     *
     * @param array  $category_data Category data
     * @param int    $category_id   Category identifier
     * @param string $lang_code     Two-letter language code (e.g. 'en', 'ru', etc.)
     */
    fn_set_hook('update_category_post', $category_data, $category_id, $lang_code);
    return $category_id;
}
Пример #8
0
function fn_update_static_data($data, $param_id, $section, $lang_code = DESCR_SL)
{
    $current_id_path = '';
    $schema = fn_get_schema('static_data', 'schema');
    $section_data = $schema[$section];
    if (!empty($section_data['has_localization'])) {
        $data['localization'] = empty($data['localization']) ? '' : fn_implode_localizations($data['localization']);
    }
    if (!empty($data['megabox'])) {
        // parse megabox value
        foreach ($data['megabox']['type'] as $p => $v) {
            if (!empty($v)) {
                $data[$p] = $v . ':' . intval($data[$p][$v]) . ':' . $data['megabox']['use_item'][$p];
            } else {
                $data[$p] = '';
            }
        }
    }
    if (!empty($param_id)) {
        $current_id_path = db_get_field("SELECT id_path FROM ?:static_data WHERE param_id = ?i", $param_id);
        db_query("UPDATE ?:static_data SET ?u WHERE param_id = ?i", $data, $param_id);
        db_query('UPDATE ?:static_data_descriptions SET ?u WHERE param_id = ?i AND lang_code = ?s', $data, $param_id, $lang_code);
    } else {
        $data['section'] = $section;
        $param_id = $data['param_id'] = db_query("INSERT INTO ?:static_data ?e", $data);
        foreach ((array) Registry::get('languages') as $data['lang_code'] => $_v) {
            db_query('REPLACE INTO ?:static_data_descriptions ?e', $data);
        }
    }
    // Generate ID path
    if (isset($data['parent_id'])) {
        if (!empty($data['parent_id'])) {
            $new_id_path = db_get_field("SELECT id_path FROM ?:static_data WHERE param_id = ?i", $data['parent_id']);
            $new_id_path .= '/' . $param_id;
        } else {
            $new_id_path = $param_id;
        }
        if (!empty($current_id_path) && $current_id_path != $new_id_path) {
            db_query("UPDATE ?:static_data SET id_path = CONCAT(?s, SUBSTRING(id_path, ?i)) WHERE id_path LIKE ?l", "{$new_id_path}/", strlen($current_id_path . '/') + 1, "{$current_id_path}/%");
        }
        db_query("UPDATE ?:static_data SET id_path = ?s WHERE param_id = ?i", $new_id_path, $param_id);
    }
    if (!empty($section_data['icon'])) {
        fn_attach_image_pairs('static_data_icon', $section_data['icon']['type'], $param_id, $lang_code);
    }
    return $param_id;
}
Пример #9
0
function fn_update_shipping($data, $shipping_id, $lang_code = DESCR_SL)
{
    $data['localization'] = empty($data['localization']) ? '' : fn_implode_localizations($data['localization']);
    $data['tax_ids'] = !empty($data['tax_ids']) ? fn_create_set($data['tax_ids']) : '';
    $data['usergroup_ids'] = empty($data['usergroup_ids']) ? '' : implode(',', $data['usergroup_ids']);
    fn_set_hook('update_shipping', $data, $shipping_id, $lang_code);
    if (!empty($shipping_id)) {
        db_query("UPDATE ?:shippings SET ?u WHERE shipping_id = ?i", $data, $shipping_id);
        db_query("UPDATE ?:shipping_descriptions SET ?u WHERE shipping_id = ?i AND lang_code = ?s", $data, $shipping_id, $lang_code);
    } else {
        $shipping_id = $data['shipping_id'] = db_query("INSERT INTO ?:shippings ?e", $data);
        foreach ((array) Registry::get('languages') as $data['lang_code'] => $_v) {
            db_query("INSERT INTO ?:shipping_descriptions ?e", $data);
        }
    }
    if ($shipping_id) {
        fn_attach_image_pairs('shipping', 'shipping', $shipping_id, $lang_code);
    }
    return $shipping_id;
}
Пример #10
0
                    db_query('UPDATE ?:store_locations SET ?u WHERE store_location_id = ?i', $entry, $key);
                    db_query('UPDATE ?:store_location_descriptions SET ?u WHERE store_location_id = ?i AND lang_code = ?s', $entry, $key, DESCR_SL);
                }
            }
        }
        $suffix .= '.manage';
    }
    if ($mode == 'add') {
        if (!empty($_REQUEST['add_store_location'][0])) {
            $data = $_REQUEST['add_store_location'][0];
            if (!empty($data['name'])) {
                if (empty($data['position'])) {
                    $data['position'] = db_get_field('SELECT MAX(position) FROM ?:store_locations');
                    $data['position'] += 10;
                }
                $data['localization'] = empty($data['localization']) ? '' : fn_implode_localizations($data['localization']);
                $id = db_query('INSERT INTO ?:store_locations ?e', $data);
                if ($id) {
                    $data['store_location_id'] = $id;
                    foreach ((array) Registry::get('languages') as $data['lang_code'] => $v) {
                        db_query("INSERT INTO ?:store_location_descriptions ?e", $data);
                    }
                }
            }
        }
        $suffix .= '.manage';
    }
    return array(CONTROLLER_STATUS_OK, 'store_locator' . $suffix);
}
if ($mode == 'delete') {
    if (!empty($_REQUEST['store_location_id'])) {
Пример #11
0
function fn_update_store_location($store_location_data, $store_location_id, $lang_code = DESCR_SL)
{
    $store_location_data['localization'] = empty($store_location_data['localization']) ? '' : fn_implode_localizations($store_location_data['localization']);
    if (empty($store_location_id)) {
        if (empty($store_location_data['position'])) {
            $store_location_data['position'] = db_get_field('SELECT MAX(position) FROM ?:store_locations');
            $store_location_data['position'] += 10;
        }
        $store_location_id = db_query('INSERT INTO ?:store_locations ?e', $store_location_data);
        $store_location_data['store_location_id'] = $store_location_id;
        foreach (fn_get_translation_languages() as $store_location_data['lang_code'] => $v) {
            db_query("INSERT INTO ?:store_location_descriptions ?e", $store_location_data);
        }
    } else {
        db_query('UPDATE ?:store_locations SET ?u WHERE store_location_id = ?i', $store_location_data, $store_location_id);
        db_query('UPDATE ?:store_location_descriptions SET ?u WHERE store_location_id = ?i AND lang_code = ?s', $store_location_data, $store_location_id, $lang_code);
    }
    // Update main images pair
    fn_attach_image_pairs('store_locations', 'store_locations', $store_location_id, $lang_code);
    // Update additional images
    fn_attach_image_pairs('store_locations_additional', 'store_locations', $store_location_id, $lang_code);
    // Adding new additional images
    fn_attach_image_pairs('store_locations_add_additional', 'store_locations', $store_location_id, $lang_code);
    //die($store_location_id);
    return $store_location_id;
}
Пример #12
0
function fn_update_postcode_location($postcode_location_data, $postcode_location_id, $lang_code = DESCR_SL)
{
    $postcode_location_data['localization'] = empty($postcode_location_data['localization']) ? '' : fn_implode_localizations($postcode_location_data['localization']);
    if (empty($postcode_location_id)) {
        if (empty($postcode_location_data['position'])) {
            $postcode_location_data['position'] = db_get_field('SELECT MAX(position) FROM ?:postcode_locations');
            $postcode_location_data['position'] += 10;
        }
        $postcode_location_id = db_query('INSERT INTO ?:postcode_locations ?e', $postcode_location_data);
        $postcode_location_data['postcode_location_id'] = $postcode_location_id;
        foreach (fn_get_translation_languages() as $postcode_location_data['lang_code'] => $v) {
            db_query("INSERT INTO ?:postcode_location_descriptions ?e", $postcode_location_data);
        }
    } else {
        db_query('UPDATE ?:postcode_locations SET ?u WHERE postcode_location_id = ?i', $postcode_location_data, $postcode_location_id);
        db_query('UPDATE ?:postcode_location_descriptions SET ?u WHERE postcode_location_id = ?i AND lang_code = ?s', $postcode_location_data, $postcode_location_id, $lang_code);
    }
    return $postcode_location_id;
}
Пример #13
0
function fn_update_news($news_id, $news_data, $lang_code = CART_LANGUAGE)
{
    // news title required
    if (empty($news_data['news'])) {
        return false;
    }
    $_data = $news_data;
    $_data['date'] = fn_parse_date($news_data['date']);
    if (isset($_data['localization'])) {
        $_data['localization'] = empty($_data['localization']) ? '' : fn_implode_localizations($_data['localization']);
    }
    if (empty($news_id)) {
        $create = true;
        $news_id = $_data['news_id'] = db_query("REPLACE INTO ?:news ?e", $_data);
        if (empty($news_id)) {
            return false;
        }
        // Adding descriptions
        foreach ((array) Registry::get('languages') as $_data['lang_code'] => $v) {
            db_query("INSERT INTO ?:news_descriptions ?e", $_data);
        }
    } else {
        if (!empty($news_data['block_id'])) {
            fn_add_items_to_block($news_data['block_id'], $news_data['add_items'], $news_id, 'news');
        }
        db_query("UPDATE ?:news SET ?u WHERE news_id = ?i", $_data, $news_id);
        // update news descriptions
        $_data = $news_data;
        db_query("UPDATE ?:news_descriptions SET ?u WHERE news_id = ?i AND lang_code = ?s", $_data, $news_id, $lang_code);
    }
    // Log news update/add
    fn_log_event('news', !empty($create) ? 'create' : 'update', array('news_id' => $news_id));
    fn_set_hook('update_news', $news_data, $news_id, $lang_code);
    return $news_id;
}
Пример #14
0
function fn_update_destination($data, $destination_id, $lang_code = DESCR_SL)
{
    $data['localization'] = empty($data['localization']) ? '' : fn_implode_localizations($data['localization']);
    if (!empty($destination_id)) {
        db_query('UPDATE ?:destinations SET ?u WHERE destination_id = ?i', $data, $destination_id);
        db_query('UPDATE ?:destination_descriptions SET ?u WHERE destination_id = ?i AND lang_code = ?s', $data, $destination_id, $lang_code);
        db_query("DELETE FROM ?:destination_elements WHERE destination_id = ?i", $destination_id);
    } else {
        $destination_id = $data['destination_id'] = db_query("REPLACE INTO ?:destinations ?e", $data);
        foreach (fn_get_translation_languages() as $data['lang_code'] => $_v) {
            db_query("REPLACE INTO ?:destination_descriptions ?e", $data);
        }
    }
    $_data = array('destination_id' => $destination_id);
    if (!empty($data['states'])) {
        $_data['element_type'] = 'S';
        foreach ($data['states'] as $key => $_data['element']) {
            db_query("INSERT INTO ?:destination_elements ?e", $_data);
        }
    }
    if (!empty($data['countries'])) {
        $_data['element_type'] = 'C';
        foreach ($data['countries'] as $key => $_data['element']) {
            db_query("INSERT INTO ?:destination_elements ?e", $_data);
        }
    }
    if (!empty($data['zipcodes'])) {
        $zipcodes = explode("\n", $data['zipcodes']);
        $_data['element_type'] = 'Z';
        foreach ($zipcodes as $key => $value) {
            $value = trim($value);
            if (!empty($value)) {
                $_data['element'] = $value;
                db_query("INSERT INTO ?:destination_elements ?e", $_data);
            }
        }
    }
    if (!empty($data['cities'])) {
        $cities = explode("\n", $data['cities']);
        $_data['element_type'] = 'T';
        foreach ($cities as $key => $value) {
            $value = trim($value);
            if (!empty($value)) {
                $_data['element'] = $value;
                db_query("INSERT INTO ?:destination_elements ?e", $_data);
            }
        }
    }
    if (!empty($data['addresses'])) {
        $addresses = explode("\n", $data['addresses']);
        $_data['element_type'] = 'A';
        foreach ($addresses as $key => $value) {
            $value = trim($value);
            if (!empty($value)) {
                $_data['element'] = $value;
                db_query("INSERT INTO ?:destination_elements ?e", $_data);
            }
        }
    }
    return $destination_id;
}
Пример #15
0
/**
 * Create/Update shipping name
 *
 * @param array $shipping_data shipping info
 * @param int $shipping_id shipping identifier
 * @param string $lang_code 2-letter language code (e.g. 'en', 'ru', etc.)
 * @return string Shipping name if shipping identifier is not null; false otherwise
 */
function fn_update_shipping($shipping_data, $shipping_id, $lang_code = DESCR_SL)
{
    if (!empty($shipping_data['shipping']) || !empty($shipping_id)) {
        $shipping_data['localization'] = empty($shipping_data['localization']) ? '' : fn_implode_localizations($shipping_data['localization']);
        $shipping_data['tax_ids'] = !empty($shipping_data['tax_ids']) ? fn_create_set($shipping_data['tax_ids']) : '';
        $shipping_data['usergroup_ids'] = empty($shipping_data['usergroup_ids']) ? USERGROUP_ALL : (is_array($shipping_data['usergroup_ids']) ? implode(',', $shipping_data['usergroup_ids']) : $shipping_data['usergroup_ids']);
        unset($shipping_data['shipping_id']);
        if (isset($shipping_data['rate_calculation']) && $shipping_data['rate_calculation'] == 'M') {
            $shipping_data['service_id'] = 0;
            $shipping_data['service_params'] = array();
        }
        if (isset($shipping_data['service_params'])) {
            $shipping_data['service_params'] = serialize($shipping_data['service_params']);
        }
        fn_set_hook('update_shipping', $shipping_data, $shipping_id, $lang_code);
        if (!empty($shipping_id)) {
            $action = 'update';
            $arow = db_query("UPDATE ?:shippings SET ?u WHERE shipping_id = ?i", $shipping_data, $shipping_id);
            db_query("UPDATE ?:shipping_descriptions SET ?u WHERE shipping_id = ?i AND lang_code = ?s", $shipping_data, $shipping_id, $lang_code);
            if ($arow === false) {
                fn_set_notification('E', __('error'), __('object_not_found', array('[object]' => __('shipping'))), '', '404');
                $shipping_id = false;
            }
        } else {
            $action = 'add';
            $shipping_id = $shipping_data['shipping_id'] = db_query("INSERT INTO ?:shippings ?e", $shipping_data);
            foreach (fn_get_translation_languages() as $shipping_data['lang_code'] => $_v) {
                db_query("INSERT INTO ?:shipping_descriptions ?e", $shipping_data);
            }
        }
        fn_set_hook('update_shipping_post', $shipping_data, $shipping_id, $lang_code, $action);
        if ($shipping_id) {
            fn_attach_image_pairs('shipping', 'shipping', $shipping_id, $lang_code);
            if (!empty($shipping_data['rates'])) {
                fn_update_shipping_rates($shipping_data, $shipping_id);
            }
        }
    }
    return $shipping_id;
}
Пример #16
0
/**
 * Updates page data by id or create new
 *
 * @param array $page_data Page data
 * @param int $page_id Page idetifier, if equals zero new page will be created
 * @param string $lang_code 2 letters language code
 * @return int Page identifier on success, false otherwise
 */
function fn_update_page($page_data, $page_id = 0, $lang_code = CART_LANGUAGE)
{
    /**
     * Actions before all checks and initializations
     *
     * @param array  $page_data Page data
     * @param int    $page_id   Page idetifier, if equals zero new page will be created
     * @param string $lang_code 2 letters language code
     */
    fn_set_hook('update_page_pre', $page_data, $page_id, $lang_code);
    if (!empty($page_id) && !fn_check_company_id('pages', 'page_id', $page_id)) {
        fn_company_access_denied_notification();
        return false;
    }
    if (!empty($page_data)) {
        SecurityHelper::sanitizeObjectData('page', $page_data);
        if (!empty($page_data['avail_from_timestamp'])) {
            $page_data['avail_from_timestamp'] = fn_parse_date($page_data['avail_from_timestamp']);
        } else {
            $page_data['avail_from_timestamp'] = 0;
        }
        if (!empty($page_data['avail_till_timestamp'])) {
            $page_data['avail_till_timestamp'] = fn_parse_date($page_data['avail_till_timestamp']) + 86399;
        } else {
            $page_data['avail_till_timestamp'] = 0;
        }
        if (isset($page_data['usergroup_ids'])) {
            $page_data['usergroup_ids'] = empty($page_data['usergroup_ids']) ? '0' : implode(',', $page_data['usergroup_ids']);
        }
        $page_data['add_items'] = empty($page_data['add_items']) ? array() : $page_data['add_items'];
        if (isset($page_data['timestamp'])) {
            $page_data['timestamp'] = fn_parse_date($page_data['timestamp']);
        }
        if (isset($page_data['localization'])) {
            $page_data['localization'] = empty($page_data['localization']) ? '' : fn_implode_localizations($page_data['localization']);
        }
        $old_page_data = array();
        /**
         * Actions after all checks and initializations and before update page
         *
         * @param array $page_data Page data
         * @param int $page_id Page idetifier, if equals zero new page will be created
         * @param string $lang_code 2 letters language code
         */
        fn_set_hook('update_page_before', $page_data, $page_id, $lang_code);
        $parent_id = isset($page_data['parent_id']) ? $page_data['parent_id'] : null;
        unset($page_data['parent_id']);
        if (empty($page_id)) {
            // page title required
            if (empty($page_data['page'])) {
                return false;
            }
            // add new page
            $create = true;
            $page_data['page_id'] = $page_id = db_query('INSERT INTO ?:pages ?e', $page_data);
            foreach (fn_get_translation_languages() as $page_data['lang_code'] => $v) {
                db_query('INSERT INTO ?:page_descriptions ?e', $page_data);
            }
        } else {
            $old_page_data = fn_get_page_data($page_id, $lang_code);
            $create = false;
            // page title is not updated
            if (empty($page_data['page'])) {
                unset($page_data['page']);
            }
            // update existing page
            db_query('UPDATE ?:pages SET ?u WHERE page_id = ?i', $page_data, $page_id);
            db_query('UPDATE ?:page_descriptions SET ?u WHERE page_id = ?i AND lang_code = ?s', $page_data, $page_id, $lang_code);
        }
        $page_data['parent_id'] = $parent_id;
        // regenerate id_path for child pages
        if (isset($page_data['parent_id'])) {
            fn_change_page_parent($page_id, intval($page_data['parent_id']));
        }
    }
    /**
     * Actions after page update
     *
     * @param array  $page_data     Page data
     * @param int    $page_id       Page idetifier, if equals zero new page will be created
     * @param string $lang_code     2 letters language code
     * @param bool   $create        True if page was created, falce otherwise
     * @param array  $old_page_data Page data before update
     */
    fn_set_hook('update_page_post', $page_data, $page_id, $lang_code, $create, $old_page_data);
    return $page_id;
}
Пример #17
0
function fn_update_category($category_data, $category_id = 0, $lang_code = CART_LANGUAGE)
{
    // category title required
    if (empty($category_data['category'])) {
        //return false; // FIXME: management page doesn't have category name
    }
    if (isset($category_data['localization'])) {
        $category_data['localization'] = empty($category_data['localization']) ? '' : fn_implode_localizations($category_data['localization']);
    }
    if (isset($category_data['usergroup_ids'])) {
        $category_data['usergroup_ids'] = empty($category_data['usergroup_ids']) ? '' : implode(',', $category_data['usergroup_ids']);
    }
    $_data = $category_data;
    if (isset($category_data['timestamp'])) {
        $_data['timestamp'] = fn_parse_date($category_data['timestamp']);
    }
    if (empty($_data['position']) && isset($_data['parent_id'])) {
        $_data['position'] = db_get_field("SELECT max(position) FROM ?:categories WHERE parent_id = ?i", $_data['parent_id']);
        $_data['position'] = $_data['position'] + 10;
    }
    if (!empty($_data['selected_layouts'])) {
        $_data['selected_layouts'] = serialize($_data['selected_layouts']);
    }
    if (isset($_data['use_custom_templates']) && $_data['use_custom_templates'] == 'N') {
        // Clear the layout settings if the category custom templates were disabled
        $_data['product_columns'] = $_data['selected_layouts'] = $_data['default_layout'] = '';
    }
    // create new category
    if (empty($category_id)) {
        $create = true;
        $category_id = db_query("INSERT INTO ?:categories ?e", $_data);
        if (empty($category_id)) {
            return false;
        }
        // now we need to update 'id_path' field, as we know $category_id
        /* Generate id_path for category */
        $parent_id = intval($_data['parent_id']);
        if ($parent_id == 0) {
            $id_path = $category_id;
        } else {
            $id_path = db_get_row("SELECT id_path FROM ?:categories WHERE category_id = ?i", $parent_id);
            $id_path = $id_path['id_path'] . '/' . $category_id;
        }
        db_query('UPDATE ?:categories SET ?u WHERE category_id = ?i', array('id_path' => $id_path), $category_id);
        //
        // Adding same category descriptions for all cart languages
        //
        $_data = $category_data;
        $_data['category_id'] = $category_id;
        foreach ((array) Registry::get('languages') as $_data['lang_code'] => $v) {
            db_query("INSERT INTO ?:category_descriptions ?e", $_data);
        }
        // update existing category
    } else {
        /* regenerate id_path for all child categories of the updated category */
        if (isset($category_data['parent_id'])) {
            fn_change_category_parent($category_id, intval($category_data['parent_id']));
        }
        db_query("UPDATE ?:categories SET ?u WHERE category_id = ?i", $_data, $category_id);
        $_data = $category_data;
        db_query("UPDATE ?:category_descriptions SET ?u WHERE category_id = ?i AND lang_code = ?s", $_data, $category_id, $lang_code);
    }
    // Log category add/update
    fn_log_event('categories', !empty($create) ? 'create' : 'update', array('category_id' => $category_id));
    // Assign usergroup to all subcategories
    if (!empty($category_data['usergroup_to_subcats']) && $category_data['usergroup_to_subcats'] == 'Y') {
        $id_path = db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", $category_id);
        db_query("UPDATE ?:categories SET usergroup_ids = ?s WHERE id_path LIKE ?l", $category_data['usergroup_ids'], "{$id_path}/%");
    }
    if (!empty($category_data['block_id'])) {
        fn_add_items_to_block($category_data['block_id'], $category_data['add_items'], $category_id, 'categories');
    }
    fn_set_hook('update_category', $category_data, $category_id, $lang_code);
    return $category_id;
}