Пример #1
0
 /**
  * Prepare products list for get shippings
  *
  * @param  array $products Products list with products data
  * @param  array $location User location
  * @return array Product groups
  */
 public static function groupProductsList($products, $location)
 {
     $groups = array();
     foreach ($products as $key_product => $product) {
         if (fn_allowed_for('ULTIMATE')) {
             $company_id = Registry::ifGet('runtime.company_id', fn_get_default_company_id());
         } else {
             $company_id = $product['company_id'];
         }
         if (empty($groups[$company_id])) {
             $origination = self::_getOriginationData($company_id);
             $groups[$company_id] = array('name' => $origination['name'], 'company_id' => (int) $company_id, 'origination' => $origination, 'location' => $location);
         }
         $groups[$company_id]['products'][$key_product] = $product;
     }
     fn_set_hook('shippings_group_products_list', $products, $groups);
     foreach ($groups as $key_group => $group) {
         $groups[$key_group]['package_info'] = self::_getPackageInfo($group);
         $groups[$key_group]['package_info_full'] = self::_getPackageInfo($group, true);
         unset($groups[$key_group]['origination']);
         unset($groups[$key_group]['location']);
         $all_edp_free_shipping = true;
         $all_free_shipping = true;
         $free_shipping = true;
         $shipping_no_required = true;
         foreach ($group['products'] as $product) {
             if ($product['is_edp'] != 'Y' || $product['edp_shipping'] == 'Y') {
                 $all_edp_free_shipping = false;
                 // shipping is required when having non-EDP products with shipping
                 if (empty($product['shipping_no_required']) || $product['shipping_no_required'] != 'Y') {
                     $shipping_no_required = false;
                 }
                 if (empty($product['free_shipping']) || $product['free_shipping'] != 'Y') {
                     $free_shipping = false;
                 }
             }
             if (empty($product['free_shipping']) || $product['free_shipping'] != 'Y') {
                 $all_free_shipping = false;
             }
         }
         $groups[$key_group]['all_edp_free_shipping'] = $all_edp_free_shipping;
         $groups[$key_group]['all_free_shipping'] = $all_free_shipping;
         $groups[$key_group]['free_shipping'] = $free_shipping;
         $groups[$key_group]['shipping_no_required'] = $shipping_no_required;
     }
     return array_values($groups);
 }
Пример #2
0
function fn_google_export_add_feature($new_features, $parent_feature_id, $show_process = false, $lang = DEFAULT_LANGUAGE)
{
    static $company_id = 0;
    if (!$company_id) {
        $company_id = fn_get_default_company_id();
    }
    foreach ($new_features as $feature_name => $feature_data) {
        foreach ($feature_data as $feature_type => $feature_variants) {
            if (fn_allowed_for('ULTIMATE')) {
                $f_id = db_query("INSERT INTO ?:product_features" . " (feature_type, categories_path, parent_id, display_on_product, display_on_catalog, status, position, comparison, company_id)" . " VALUES" . " (?s, '', ?i, 0, 0, 'A', 0, 'N', ?i)", $feature_type, $parent_feature_id, $company_id);
                fn_share_object_to_all('product_features', $f_id);
            } else {
                $f_id = db_query("INSERT INTO ?:product_features" . " (feature_type, categories_path, parent_id, display_on_product, display_on_catalog, status, position, comparison)" . " VALUES" . " (?s, '', ?i, 0, 0, 'A', 0, 'N')", $feature_type, $parent_feature_id);
            }
            db_query("INSERT INTO ?:product_features_descriptions" . " (feature_id, description, full_description, prefix, suffix, lang_code)" . " VALUES" . " (?i, ?s, '', '', '', ?s)", $f_id, $feature_name, $lang);
            if ($show_process) {
                fn_echo(' .');
            }
            fn_google_export_add_feature_variants($f_id, $feature_variants, $show_process);
        }
    }
}
Пример #3
0
 public function correctCompanyID(&$params)
 {
     if (fn_allowed_for('ULTIMATE')) {
         if (empty($params['company_id'])) {
             $params['company_id'] = fn_get_default_company_id();
         }
     } elseif (fn_allowed_for('MULTIVENDOR')) {
         $params['company_id'] = 0;
     }
 }
Пример #4
0
function fn_facebook_prepare_meta_data($provider_data, $params)
{
    $addon_settings = Settings::instance()->getValues('social_buttons', 'ADDON');
    if (fn_allowed_for('ULTIMATE')) {
        $company_id = Registry::ifGet('runtime.company_id', fn_get_default_company_id());
        $site_name = fn_get_company_name($company_id);
    }
    if ($params['object'] == 'products') {
        $product = Registry::get('view')->getTemplateVars('product');
        $return = array('type' => !empty($product['facebook_product_type']) ? $product['facebook_product_type'] : '', 'title' => fn_sb_format_page_title(), 'url' => fn_url('products.view?product_id=' . $params['object_id']), 'image' => !empty($product['main_pair']['detailed']['http_image_path']) ? $product['main_pair']['detailed']['http_image_path'] : '', 'site_name' => !empty($site_name) ? $site_name : Registry::get('settings.Company.company_name'), 'app_id' => !empty($addon_settings['facebook']['facebook_app_id']) ? $addon_settings['facebook']['facebook_app_id'] : '');
    } elseif ($params['object'] == 'pages') {
        $page = Registry::get('view')->getTemplateVars('page');
        $logos = fn_get_logos();
        if (fn_allowed_for('ULTIMATE')) {
            $logos = fn_get_logos($company_id);
        }
        $return = array('type' => !empty($page['facebook_obj_type']) ? $page['facebook_obj_type'] : '', 'title' => $page['page'], 'url' => !empty($page['link']) ? $page['link'] : fn_url('pages.view?product_id=' . $params['object_id']), 'image' => $logos['theme']['image']['http_image_path'], 'site_name' => !empty($site_name) ? $site_name : Registry::get('settings.Company.company_name'), 'app_id' => !empty($addon_settings['facebook']['facebook_app_id']) ? $addon_settings['facebook']['facebook_app_id'] : '');
    }
    return $return;
}
    function content_55ccecdbacf151_52396674($_smarty_tpl)
    {
        fn_preload_lang_vars(array('vendor'));
        if ($_smarty_tpl->tpl_vars['runtime']->value['company_id'] && (!$_smarty_tpl->tpl_vars['selected']->value || fn_allowed_for("MULTIVENDOR")) && !$_smarty_tpl->tpl_vars['disable_company_picker']->value) {
            ?>
    <?php 
            $_smarty_tpl->tpl_vars['selected'] = new Smarty_variable($_smarty_tpl->tpl_vars['runtime']->value['company_id'], null, 0);
        }
        ?>

<?php 
        if (!$_smarty_tpl->tpl_vars['selected']->value) {
            ?>
    <?php 
            if ($_smarty_tpl->tpl_vars['zero_company_id_name_lang_var']->value) {
                ?>
        <?php 
                $_smarty_tpl->tpl_vars['selected'] = new Smarty_variable("0", null, 0);
                ?>
    <?php 
            } else {
                ?>
        <?php 
                $_smarty_tpl->tpl_vars['selected'] = new Smarty_variable(fn_get_default_company_id(), null, 0);
                ?>
    <?php 
            }
        }
        ?>

<?php 
        if ($_smarty_tpl->tpl_vars['reload_form']->value) {
            ?>
    <?php 
            $_smarty_tpl->tpl_vars['js_action'] = new Smarty_variable("fn_reload_form(elm);", null, 0);
        }
        ?>

<?php 
        $_smarty_tpl->_capture_stack[0][] = array("c_body", null, null);
        ob_start();
        ?>
    <input type="hidden" name="<?php 
        echo htmlspecialchars($_smarty_tpl->tpl_vars['name']->value, ENT_QUOTES, 'UTF-8');
        ?>
" id="<?php 
        echo htmlspecialchars(($tmp = @$_smarty_tpl->tpl_vars['id']->value) === null || $tmp === '' ? "company_id" : $tmp, ENT_QUOTES, 'UTF-8');
        ?>
" value="<?php 
        echo htmlspecialchars($_smarty_tpl->tpl_vars['selected']->value, ENT_QUOTES, 'UTF-8');
        ?>
">
    <?php 
        if (!$_smarty_tpl->tpl_vars['runtime']->value['simple_ultimate']) {
            ?>
        <?php 
            if ($_smarty_tpl->tpl_vars['runtime']->value['company_id'] || $_smarty_tpl->tpl_vars['disable_company_picker']->value) {
                ?>
            <div class="text-type-value"><?php 
                echo htmlspecialchars(fn_get_company_name($_smarty_tpl->tpl_vars['selected']->value, $_smarty_tpl->tpl_vars['zero_company_id_name_lang_var']->value), ENT_QUOTES, 'UTF-8');
                ?>
</div>
        <?php 
            } else {
                ?>
            <div class="text-type-value ajax-select-wrap <?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['meta']->value, ENT_QUOTES, 'UTF-8');
                ?>
">
                <?php 
                if ($_smarty_tpl->tpl_vars['zero_company_id_name_lang_var']->value) {
                    ?>
                    <?php 
                    $_smarty_tpl->tpl_vars['url_extra'] = new Smarty_variable("&show_all=Y&default_label=" . (string) $_smarty_tpl->tpl_vars['zero_company_id_name_lang_var']->value, null, 0);
                    ?>
                <?php 
                }
                ?>
                <?php 
                echo $_smarty_tpl->getSubTemplate("common/ajax_select_object.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('data_url' => "companies.get_companies_list?onclick=" . (string) $_smarty_tpl->tpl_vars['onclick']->value . (string) $_smarty_tpl->tpl_vars['url_extra']->value, 'text' => fn_get_company_name($_smarty_tpl->tpl_vars['selected']->value, $_smarty_tpl->tpl_vars['zero_company_id_name_lang_var']->value), 'result_elm' => ($tmp = @$_smarty_tpl->tpl_vars['id']->value) === null || $tmp === '' ? "company_id" : $tmp, 'id' => (string) $_smarty_tpl->tpl_vars['id']->value . "_selector", 'js_action' => $_smarty_tpl->tpl_vars['js_action']->value), 0);
                ?>

            </div>
        <?php 
            }
            ?>
    <?php 
        }
        list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);
        if (!empty($_capture_buffer)) {
            if (isset($_capture_assign)) {
                $_smarty_tpl->assign($_capture_assign, ob_get_contents());
            }
            if (isset($_capture_append)) {
                $_smarty_tpl->append($_capture_append, ob_get_contents());
            }
            Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean();
        } else {
            $_smarty_tpl->capture_error();
        }
        ?>

<?php 
        if (!$_smarty_tpl->tpl_vars['runtime']->value['simple_ultimate']) {
            ?>
    <?php 
            if (!$_smarty_tpl->tpl_vars['no_wrap']->value) {
                ?>
        <div class="control-group">
            <label class="control-label" for="<?php 
                echo htmlspecialchars(($tmp = @$_smarty_tpl->tpl_vars['id']->value) === null || $tmp === '' ? "company_id" : $tmp, ENT_QUOTES, 'UTF-8');
                ?>
"><?php 
                echo $_smarty_tpl->__("vendor");
                if ($_smarty_tpl->tpl_vars['tooltip']->value) {
                    ?>
 <?php 
                    $_smarty_tpl->_capture_stack[0][] = array("tooltip", null, null);
                    ob_start();
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['tooltip']->value, ENT_QUOTES, 'UTF-8');
                    list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);
                    if (!empty($_capture_buffer)) {
                        if (isset($_capture_assign)) {
                            $_smarty_tpl->assign($_capture_assign, ob_get_contents());
                        }
                        if (isset($_capture_append)) {
                            $_smarty_tpl->append($_capture_append, ob_get_contents());
                        }
                        Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean();
                    } else {
                        $_smarty_tpl->capture_error();
                    }
                    echo $_smarty_tpl->getSubTemplate("common/tooltip.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('tooltip' => Smarty::$_smarty_vars['capture']['tooltip']), 0);
                }
                ?>
</label>
            <div class="controls">
                <?php 
                echo Smarty::$_smarty_vars['capture']['c_body'];
                ?>

            </div>
        </div>
    <?php 
            } else {
                ?>
        <?php 
                echo Smarty::$_smarty_vars['capture']['c_body'];
                ?>

    <?php 
            }
        } else {
            ?>
    <?php 
            echo Smarty::$_smarty_vars['capture']['c_body'];
            ?>

<?php 
        }
    }
Пример #6
0
function fn_get_sb_providers_meta_data($params)
{
    $addon_settings = Settings::instance()->getValues('social_buttons', 'ADDON');
    $providers_meta_data = array();
    if (fn_allowed_for('ULTIMATE')) {
        $company_id = Registry::ifGet('runtime.company_id', fn_get_default_company_id());
        $site_name = fn_get_company_name($company_id);
    }
    if ($params['object'] == 'products') {
        $product = Tygh::$app['view']->getTemplateVars('product');
        $providers_meta_data['all'] = array('title' => fn_sb_format_page_title(), 'url' => fn_url('products.view?product_id=' . $params['object_id']), 'image' => !empty($product['main_pair']['detailed']['http_image_path']) ? $product['main_pair']['detailed']['http_image_path'] : '', 'image:width' => !empty($product['main_pair']['detailed']['image_x']) ? $product['main_pair']['detailed']['image_x'] : '', 'image:height' => !empty($product['main_pair']['detailed']['image_y']) ? $product['main_pair']['detailed']['image_y'] : '', 'site_name' => !empty($site_name) ? $site_name : Registry::get('settings.Company.company_name'));
    } elseif ($params['object'] == 'pages') {
        $page = Tygh::$app['view']->getTemplateVars('page');
        $logos = fn_get_logos();
        if (fn_allowed_for('ULTIMATE')) {
            $logos = fn_get_logos($company_id);
        }
        $providers_meta_data['all'] = array('title' => $page['page'], 'url' => !empty($page['link']) ? $page['link'] : fn_url('pages.view?product_id=' . $params['object_id']), 'image' => !empty($logos['theme']['image']['http_image_path']) ? $logos['theme']['image']['http_image_path'] : '', 'image:width' => !empty($logos['theme']['image']['image_x']) ? $logos['theme']['image']['image_x'] : '', 'image:height' => !empty($logos['theme']['image']['image_y']) ? $logos['theme']['image']['image_y'] : '', 'site_name' => !empty($site_name) ? $site_name : Registry::get('settings.Company.company_name'));
    }
    if (!empty($addon_settings)) {
        foreach ($addon_settings as $provider_name => $provider_data) {
            $func_name = 'fn_' . $provider_name . '_prepare_meta_data';
            if (is_callable($func_name)) {
                $providers_meta_data[$provider_name] = call_user_func($func_name, $provider_data, $params);
            }
        }
    }
    return $providers_meta_data;
}
Пример #7
0
/**
 * Adds or updates product
 *
 * @param array $product_data Product data
 * @param int $product_id Product identifier
 * @param string $lang_code Two-letter language code (e.g. 'en', 'ru', etc.)
 * @return mixed ID of created/updated product or false in case of error
 */
function fn_update_product($product_data, $product_id = 0, $lang_code = CART_LANGUAGE)
{
    $can_update = true;
    /**
     * Update product data (running before fn_update_product() function)
     *
     * @param array   $product_data Product data
     * @param int     $product_id   Product identifier
     * @param string  $lang_code    Two-letter language code (e.g. 'en', 'ru', etc.)
     * @param boolean $can_update   Flag, allows addon to forbid to create/update product
     */
    fn_set_hook('update_product_pre', $product_data, $product_id, $lang_code, $can_update);
    if ($can_update == false) {
        return false;
    }
    if (fn_allowed_for('ULTIMATE')) {
        // check that product owner was not changed by store administrator
        if (Registry::get('runtime.company_id') || empty($product_data['company_id'])) {
            $product_company_id = db_get_field('SELECT company_id FROM ?:products WHERE product_id = ?i', $product_id);
            if (!empty($product_company_id)) {
                $product_data['company_id'] = $product_company_id;
            } else {
                if (Registry::get('runtime.company_id')) {
                    $product_company_id = $product_data['company_id'] = Registry::get('runtime.company_id');
                } else {
                    $product_company_id = $product_data['company_id'] = fn_get_default_company_id();
                }
            }
        } else {
            $product_company_id = $product_data['company_id'];
        }
        if (!empty($product_data['category_ids']) && !fn_check_owner_categories($product_company_id, $product_data['category_ids'])) {
            fn_set_notification('E', __('error'), __('product_must_have_owner_category'));
            return false;
        }
        if (fn_ult_is_shared_product($product_id) == 'Y') {
            $_product_id = fn_ult_update_shared_product($product_data, $product_id, Registry::ifGet('runtime.company_id', $product_company_id), $lang_code);
        }
    }
    if (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id') && !empty($product_company_id) && Registry::get('runtime.company_id') != $product_company_id && !empty($_product_id)) {
        $product_id = $_product_id;
        $create = false;
    } else {
        $product_data['updated_timestamp'] = time();
        $_data = $product_data;
        if (!empty($product_data['timestamp'])) {
            $_data['timestamp'] = fn_parse_date($product_data['timestamp']);
            // Minimal data for product record
        } elseif (empty($product_id) || isset($product_data['timestamp'])) {
            $_data['timestamp'] = time();
        }
        if (empty($product_id) && Registry::get('runtime.company_id')) {
            $_data['company_id'] = Registry::get('runtime.company_id');
        }
        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']) ? '0' : implode(',', $_data['usergroup_ids']);
        }
        if (!empty($product_data['list_qty_count']) && $product_data['list_qty_count'] < 0) {
            $_data['list_qty_count'] = 0;
        }
        if (!empty($product_data['qty_step']) && $product_data['qty_step'] < 0) {
            $_data['qty_step'] = 0;
        }
        if (!empty($product_data['min_qty'])) {
            $_data['min_qty'] = fn_ceil_to_step(abs($product_data['min_qty']), $_data['qty_step']);
        }
        if (!empty($product_data['max_qty'])) {
            $_data['max_qty'] = fn_ceil_to_step(abs($product_data['max_qty']), $_data['qty_step']);
        }
        if (Registry::get('settings.General.inventory_tracking') == "N" && isset($_data['tracking'])) {
            unset($_data['tracking']);
        }
        if (Registry::get('settings.General.allow_negative_amount') == 'N' && isset($_data['amount'])) {
            $_data['amount'] = abs($_data['amount']);
        }
        $shipping_params = array();
        if (!empty($product_id)) {
            $shipping_params = db_get_field('SELECT shipping_params FROM ?:products WHERE product_id = ?i', $product_id);
            if (!empty($shipping_params)) {
                $shipping_params = unserialize($shipping_params);
            }
        }
        // Save the product shipping params
        $_shipping_params = array('min_items_in_box' => isset($_data['min_items_in_box']) ? intval($_data['min_items_in_box']) : (!empty($shipping_params['min_items_in_box']) ? $shipping_params['min_items_in_box'] : 0), 'max_items_in_box' => isset($_data['max_items_in_box']) ? intval($_data['max_items_in_box']) : (!empty($shipping_params['max_items_in_box']) ? $shipping_params['max_items_in_box'] : 0), 'box_length' => isset($_data['box_length']) ? intval($_data['box_length']) : (!empty($shipping_params['box_length']) ? $shipping_params['box_length'] : 0), 'box_width' => isset($_data['box_width']) ? intval($_data['box_width']) : (!empty($shipping_params['box_width']) ? $shipping_params['box_width'] : 0), 'box_height' => isset($_data['box_height']) ? intval($_data['box_height']) : (!empty($shipping_params['box_height']) ? $shipping_params['box_height'] : 0));
        $_data['shipping_params'] = serialize($_shipping_params);
        unset($_shipping_params);
        // add new product
        if (empty($product_id)) {
            $create = true;
            $product_data['create'] = true;
            // product title can't be empty and not set product_id
            if (empty($product_data['product']) || !empty($product_data['product_id'])) {
                fn_set_notification('E', __('error'), __('need_product_name'));
                return false;
            }
            $product_id = db_query("INSERT INTO ?:products ?e", $_data);
            if (empty($product_id)) {
                $product_id = false;
            }
            //
            // Adding same product descriptions for all cart languages
            //
            $_data = $product_data;
            $_data['product_id'] = $product_id;
            $_data['product'] = trim($_data['product'], " -");
            foreach (fn_get_translation_languages() as $_data['lang_code'] => $_v) {
                db_query("INSERT INTO ?:product_descriptions ?e", $_data);
            }
            // update product
        } else {
            $create = false;
            if (isset($product_data['product']) && empty($product_data['product'])) {
                unset($product_data['product']);
            }
            $old_product_data = fn_get_product_data($product_id, $auth, $lang_code, '', false, false, false, false);
            if (isset($old_product_data['amount']) && isset($_data['amount']) && $old_product_data['amount'] <= 0 && $_data['amount'] > 0) {
                fn_send_product_notifications($product_id);
            }
            $arow = 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);
            if ($arow === false) {
                fn_set_notification('E', __('error'), __('object_not_found', array('[object]' => __('product'))), '', '404');
                $product_id = false;
            }
        }
        if ($product_id) {
            // Log product add/update
            fn_log_event('products', !empty($create) ? 'create' : 'update', array('product_id' => $product_id));
            // Update product features value
            $product_data['product_features'] = !empty($product_data['product_features']) ? $product_data['product_features'] : array();
            $product_data['add_new_variant'] = !empty($product_data['add_new_variant']) ? $product_data['add_new_variant'] : array();
            fn_update_product_features_value($product_id, $product_data['product_features'], $product_data['add_new_variant'], $lang_code);
            fn_attach_image_pairs('p_feature_var_extra', 'p_feature_var_extra', 0, $lang_code);
            // Update product prices
            $product_data = fn_update_product_prices($product_id, $product_data);
            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_update_product_categories($product_id, $product_data);
            // Update main images pair
            fn_attach_image_pairs('product_main', 'product', $product_id, $lang_code);
            // Update additional images
            fn_attach_image_pairs('product_additional', 'product', $product_id, $lang_code);
            // Adding new additional images
            fn_attach_image_pairs('product_add_additional', 'product', $product_id, $lang_code);
            if (fn_allowed_for('ULTIMATE')) {
                fn_check_and_update_product_sharing($product_id);
            }
        }
    }
    /**
     * Update product data (running after fn_update_product() function)
     *
     * @param array   $product_data Product data
     * @param int     $product_id   Product integer identifier
     * @param string  $lang_code    Two-letter language code (e.g. 'en', 'ru', etc.)
     * @param boolean $create       Flag determines if product was created (true) or just updated (false).
     */
    fn_set_hook('update_product_post', $product_data, $product_id, $lang_code, $create);
    return (int) $product_id;
}
Пример #8
0
function fn_get_payment_templates($payment = array())
{
    $templates = array();
    $company_id = null;
    if (fn_allowed_for('ULTIMATE')) {
        if (!empty($payment['company_id'])) {
            $company_id = $payment['company_id'];
        } else {
            $company_id = Registry::ifGet('runtime.company_id', fn_get_default_company_id());
        }
    }
    $theme_path = fn_get_theme_path('[themes]/[theme]', 'C', $company_id);
    $_templates = fn_get_dir_contents($theme_path . '/templates/views/orders/components/payments/', false, true, '.tpl');
    foreach ($_templates as $template) {
        $templates[$template] = 'views/orders/components/payments/' . $template;
    }
    // Get addons templates as well
    $path = 'addons/[addon]/views/orders/components/payments/';
    $addons = Registry::get('addons');
    foreach ($addons as $addon_id => $addon) {
        $addon_path = str_replace('[addon]', $addon_id, $path);
        $addon_templates = fn_get_dir_contents($theme_path . '/templates/' . $addon_path, false, true, '.tpl');
        if (!empty($addon_templates)) {
            foreach ($addon_templates as $template) {
                $templates[$template] = $addon_path . $template;
            }
        }
    }
    return $templates;
}
Пример #9
0
            Session::setName($areas[$area]);
            $sess_id = Session::regenerateId();
            Session::save($sess_id, $sess_data, $area);
            Session::setName(ACCOUNT_TYPE);
            Session::setId($old_sess_id, false);
        } else {
            // Save unique key for session
            $key = fn_crc32(microtime()) . fn_crc32(microtime() + 1);
            fn_set_storage_data('session_' . $key . '_data', serialize($sess_data));
            if (fn_allowed_for('ULTIMATE')) {
                $company_id_in_url = fn_get_company_id_from_uri($redirect_url);
                if (Registry::get('runtime.company_id') || !empty($user_data['company_id']) || Registry::get('runtime.simple_ultimate') || !empty($company_id_in_url)) {
                    // Redirect to the personal frontend
                    $company_id = !empty($user_data['company_id']) ? $user_data['company_id'] : Registry::get('runtime.company_id');
                    if (!$company_id && Registry::get('runtime.simple_ultimate')) {
                        $company_id = fn_get_default_company_id();
                    } elseif (!$company_id) {
                        $company_id = $company_id_in_url;
                    }
                    $url = $area == 'C' ? fn_link_attach($redirect_url, 'skey=' . $key . '&company_id=' . $company_id) : $redirect_url;
                    return array(CONTROLLER_STATUS_REDIRECT, fn_url($url, $area), true);
                }
            } else {
                $url = fn_link_attach($redirect_url, 'skey=' . $key);
                return array(CONTROLLER_STATUS_REDIRECT, fn_url($url, $area), true);
            }
        }
        return array(CONTROLLER_STATUS_REDIRECT, fn_url($redirect_url, $area));
    }
} elseif ($mode == 'picker') {
    $params = $_REQUEST;
Пример #10
0
function fn_mailru_put_header($filename)
{
    $_SESSION['mailru_export_count'] = 0;
    $shop_name = Registry::get('addons.rus_tovary_mailru.shop_name');
    if (empty($shop_name)) {
        if (fn_allowed_for('ULTIMATE')) {
            $company_id = Registry::ifGet('runtime.company_id', fn_get_default_company_id());
            $shop_name = fn_get_company_name($company_id);
        } else {
            $shop_name = Registry::get('settings.Company.company_name');
        }
    }
    $shop_name = strip_tags($shop_name);
    $yml_header = array('<?xml version="1.0" encoding="' . Registry::get('addons.rus_tovary_mailru.export_encoding') . '"?>', '<torg_price date="' . date('Y-m-d G:i') . '">', '<shop>');
    $yml = array('shopname' => $shop_name, 'company' => Registry::get('settings.Company.company_name'), 'url' => Registry::get('config.http_location'));
    $currencies = Registry::get('currencies');
    if (CART_PRIMARY_CURRENCY != "RUB") {
        $rub_coefficient = !empty($currencies['RUB']) ? $currencies['RUB']['coefficient'] : 1;
        $primary_coefficient = $currencies[CART_PRIMARY_CURRENCY]['coefficient'];
        foreach ($currencies as $cur) {
            if (fn_mailru_check_currencies($cur['currency_code']) && $cur['status'] == 'A') {
                if ($cur['currency_code'] == "RUB") {
                    $coefficient = '1.0000';
                    $yml['currencies']['currency@id=' . $cur['currency_code'] . '@rate=' . $coefficient] = '';
                } else {
                    $coefficient = $cur['coefficient'] * $primary_coefficient / $rub_coefficient;
                    $yml['currencies']['currency@id=' . $cur['currency_code'] . '@rate=' . $coefficient] = '';
                }
            }
        }
    } else {
        foreach ($currencies as $cur) {
            if (fn_mailru_check_currencies($cur['currency_code']) && $cur['status'] == 'A') {
                $yml['currencies']['currency@id=' . $cur['currency_code'] . '@rate=' . $cur['coefficient']] = '';
            }
        }
    }
    $params = array('simple' => false, 'plain' => true);
    if (fn_allowed_for('ULTIMATE') && is_numeric($shop_name)) {
        $params['company_ids'] = $shop_name;
    }
    list($categories_tree, ) = fn_get_categories($params);
    foreach ($categories_tree as $cat) {
        if (isset($cat['category_id'])) {
            $yml['categories']['category@id=' . $cat['category_id'] . '@parentId=' . $cat['parent_id']] = htmlspecialchars($cat['category']);
        }
    }
    $yml_data = implode("\n", $yml_header) . "\n" . fn_mailru_array_to_yml($yml) . "<offers>\n";
    fn_mailru_write_yml($filename, 'w+', $yml_data);
}
Пример #11
0
 public function correctCompanyID(&$params)
 {
     if (fn_allowed_for('ULTIMATE')) {
         if (empty($params['company_id'])) {
             $params['company_id'] = fn_get_default_company_id();
         }
     } elseif (fn_allowed_for('MULTIVENDOR')) {
         $runtime_company_id = Registry::get('runtime.company_id');
         // Root admin can set any company ID to the object
         // Vendor admin can't handle company ID
         if ($runtime_company_id != 0 || !isset($params['company_id'])) {
             $params['company_id'] = $runtime_company_id;
         }
     }
 }
Пример #12
0
/**
 * Add/update user
 *
 * @param int $user_id - user ID to update (empty for new user)
 * @param array $user_data - user data
 * @param array $auth - authentication information
 * @param bool $ship_to_another - flag indicates that shipping and billing fields are different
 * @param bool $notify_user - flag indicates that user should be notified
 * @return array with user ID and profile ID if success, false otherwise
 */
function fn_update_user($user_id, $user_data, &$auth, $ship_to_another, $notify_user)
{
    /**
     * Actions before updating user
     *
     * @param int   $user_id         User ID to update (empty for new user)
     * @param array $user_data       User data
     * @param array $auth            Authentication information
     * @param bool  $ship_to_another Flag indicates that shipping and billing fields are different
     * @param bool  $notify_user     Flag indicates that user should be notified
     */
    fn_set_hook('update_user_pre', $user_id, $user_data, $auth, $ship_to_another, $notify_user);
    array_walk($user_data, 'fn_trim_helper');
    $register_at_checkout = isset($user_data['register_at_checkout']) && $user_data['register_at_checkout'] == 'Y' ? true : false;
    if (fn_allowed_for('ULTIMATE')) {
        if (AREA == 'A' && !empty($user_data['user_type']) && $user_data['user_type'] == 'C' && (empty($user_data['company_id']) || Registry::get('runtime.company_id') && $user_data['company_id'] != Registry::get('runtime.company_id'))) {
            fn_set_notification('W', __('warning'), __('access_denied'));
            return false;
        }
    }
    if (!empty($user_id)) {
        $current_user_data = db_get_row("SELECT user_id, company_id, is_root, status, user_type, user_login, lang_code, password, salt, last_passwords FROM ?:users WHERE user_id = ?i", $user_id);
        if (empty($current_user_data)) {
            fn_set_notification('E', __('error'), __('object_not_found', array('[object]' => __('user'))), '', '404');
            return false;
        }
        if (!fn_check_editable_permissions($auth, $current_user_data)) {
            fn_set_notification('E', __('error'), __('access_denied'));
            return false;
        }
        if (!empty($user_data['profile_id']) && AREA != 'A') {
            $profile_ids = db_get_fields("SELECT profile_id FROM ?:user_profiles WHERE user_id = ?i", $user_id);
            if (!in_array($user_data['profile_id'], $profile_ids)) {
                fn_set_notification('W', __('warning'), __('access_denied'));
                return false;
            }
        }
        if (fn_allowed_for('ULTIMATE')) {
            if (AREA != 'A' || empty($user_data['company_id'])) {
                //we should set company_id for the frontdend, in the backend company_id received from form
                if ($current_user_data['user_type'] == 'A') {
                    if (!isset($user_data['company_id']) || AREA != 'A' || Registry::get('runtime.company_id')) {
                        // reset administrator's company if it was not set to root
                        $user_data['company_id'] = $current_user_data['company_id'];
                    }
                } elseif (Registry::get('settings.Stores.share_users') == 'Y') {
                    $user_data['company_id'] = $current_user_data['company_id'];
                } else {
                    $user_data['company_id'] = Registry::ifGet('runtime.company_id', 1);
                }
            }
        }
        if (fn_allowed_for('MULTIVENDOR')) {
            if (AREA != 'A') {
                //we should set company_id for the frontend
                $user_data['company_id'] = $current_user_data['company_id'];
            }
        }
        $action = 'update';
    } else {
        $current_user_data = array('status' => AREA != 'A' && Registry::get('settings.General.approve_user_profiles') == 'Y' ? 'D' : (!empty($user_data['status']) ? $user_data['status'] : 'A'), 'user_type' => 'C');
        if (fn_allowed_for('ULTIMATE')) {
            if (!empty($user_data['company_id']) || Registry::get('runtime.company_id') || AREA == 'A') {
                //company_id can be received when we create user account from the backend
                $company_id = !empty($user_data['company_id']) ? $user_data['company_id'] : Registry::get('runtime.company_id');
                if (empty($company_id)) {
                    $company_id = fn_check_user_type_admin_area($user_data['user_type']) ? $user_data['company_id'] : fn_get_default_company_id();
                }
                $user_data['company_id'] = $current_user_data['company_id'] = $company_id;
            } else {
                fn_set_notification('W', __('warning'), __('access_denied'));
                return false;
            }
        }
        $action = 'add';
        $user_data['lang_code'] = !empty($user_data['lang_code']) ? $user_data['lang_code'] : CART_LANGUAGE;
        $user_data['timestamp'] = TIME;
    }
    $original_password = '';
    $current_user_data['password'] = !empty($current_user_data['password']) ? $current_user_data['password'] : '';
    $current_user_data['salt'] = !empty($current_user_data['salt']) ? $current_user_data['salt'] : '';
    // Set the user type
    $user_data['user_type'] = fn_check_user_type($user_data, $current_user_data);
    if (Registry::get('runtime.company_id') && !fn_allowed_for('ULTIMATE') && (!fn_check_user_type_admin_area($user_data['user_type']) || isset($current_user_data['company_id']) && $current_user_data['company_id'] != Registry::get('runtime.company_id'))) {
        fn_set_notification('W', __('warning'), __('access_denied'));
        return false;
    }
    // Check if this user needs login/password
    if (fn_user_need_login($user_data['user_type'])) {
        // Check if user_login already exists
        // FIXME
        if (!isset($user_data['email'])) {
            $user_data['email'] = db_get_field("SELECT email FROM ?:users WHERE user_id = ?i", $user_id);
        }
        $is_exist = fn_is_user_exists($user_id, $user_data);
        if ($is_exist) {
            fn_set_notification('E', __('error'), __('error_user_exists'), '', 'user_exist');
            return false;
        }
        // Check the passwords
        if (!empty($user_data['password1']) || !empty($user_data['password2'])) {
            $original_password = trim($user_data['password1']);
            $user_data['password1'] = !empty($user_data['password1']) ? trim($user_data['password1']) : '';
            $user_data['password2'] = !empty($user_data['password2']) ? trim($user_data['password2']) : '';
        }
        // if the passwords are not set and this is not a forced password check
        // we will not update password, otherwise let's check password
        if (!empty($_SESSION['auth']['forced_password_change']) || !empty($user_data['password1']) || !empty($user_data['password2'])) {
            $valid_passwords = true;
            if ($user_data['password1'] != $user_data['password2']) {
                $valid_passwords = false;
                fn_set_notification('E', __('error'), __('error_passwords_dont_match'));
            }
            // PCI DSS Compliance
            if (fn_check_user_type_admin_area($user_data['user_type'])) {
                $msg = array();
                // Check password length
                $min_length = Registry::get('settings.Security.min_admin_password_length');
                if (strlen($user_data['password1']) < $min_length || strlen($user_data['password2']) < $min_length) {
                    $valid_passwords = false;
                    $msg[] = str_replace("[number]", $min_length, __('error_password_min_symbols'));
                }
                // Check password content
                if (Registry::get('settings.Security.admin_passwords_must_contain_mix') == 'Y') {
                    $tmp_result = preg_match('/\\d+/', $user_data['password1']) && preg_match('/\\D+/', $user_data['password1']) && preg_match('/\\d+/', $user_data['password2']) && preg_match('/\\D+/', $user_data['password2']);
                    if (!$tmp_result) {
                        $valid_passwords = false;
                        $msg[] = __('error_password_content');
                    }
                }
                if ($msg) {
                    fn_set_notification('E', __('error'), implode('<br />', $msg));
                }
                // Check last 4 passwords
                if (!empty($user_id)) {
                    $prev_passwords = !empty($current_user_data['last_passwords']) ? explode(',', $current_user_data['last_passwords']) : array();
                    if (!empty($_SESSION['auth']['forced_password_change'])) {
                        // if forced password change - new password can't be equal to current password.
                        $prev_passwords[] = $current_user_data['password'];
                    }
                    if (in_array(fn_generate_salted_password($user_data['password1'], $current_user_data['salt']), $prev_passwords)) {
                        $valid_passwords = false;
                        fn_set_notification('E', __('error'), __('error_password_was_used'));
                    } else {
                        if (count($prev_passwords) >= 5) {
                            array_shift($prev_passwords);
                        }
                        $user_data['last_passwords'] = implode(',', $prev_passwords);
                    }
                }
            }
            // PCI DSS Compliance
            if (!$valid_passwords) {
                return false;
            }
            $user_data['salt'] = fn_generate_salt();
            $user_data['password'] = fn_generate_salted_password($user_data['password1'], $user_data['salt']);
            if ($user_data['password'] != $current_user_data['password'] && !empty($user_id)) {
                // if user set current password - there is no necessity to update password_change_timestamp
                $user_data['password_change_timestamp'] = $_SESSION['auth']['password_change_timestamp'] = TIME;
            }
            unset($_SESSION['auth']['forced_password_change']);
            fn_delete_notification('password_expire');
        }
    }
    $user_data['status'] = AREA != 'A' || empty($user_data['status']) ? $current_user_data['status'] : $user_data['status'];
    // only administrator can change user status
    // Fill the firstname, lastname and phone from the billing address if the profile was created or updated through the admin area.
    if (AREA == 'A' || Registry::get('settings.Checkout.address_position') == 'billing_first') {
        $main_address_zone = BILLING_ADDRESS_PREFIX;
        $alt_address_zone = SHIPPING_ADDRESS_PREFIX;
    } else {
        $main_address_zone = SHIPPING_ADDRESS_PREFIX;
        $alt_address_zone = BILLING_ADDRESS_PREFIX;
    }
    $user_data = fn_fill_contact_info_from_address($user_data, $main_address_zone, $alt_address_zone);
    if (!fn_allowed_for('ULTIMATE')) {
        //for ult company_id was set before
        fn_set_company_id($user_data);
    }
    if (!empty($current_user_data['is_root']) && $current_user_data['is_root'] == 'Y') {
        $user_data['is_root'] = 'Y';
    } else {
        $user_data['is_root'] = 'N';
    }
    // check if it is a root admin
    $is_root_admin_exists = db_get_field("SELECT user_id FROM ?:users WHERE company_id = ?i AND is_root = 'Y' AND user_id != ?i", $user_data['company_id'], !empty($user_id) ? $user_id : 0);
    $user_data['is_root'] = empty($is_root_admin_exists) && $user_data['user_type'] !== 'C' ? 'Y' : 'N';
    unset($user_data['user_id']);
    if (!empty($user_id)) {
        db_query("UPDATE ?:users SET ?u WHERE user_id = ?i", $user_data, $user_id);
        fn_clean_usergroup_links($user_id, $current_user_data['user_type'], $user_data['user_type']);
        fn_log_event('users', 'update', array('user_id' => $user_id));
    } else {
        if (!isset($user_data['password_change_timestamp'])) {
            $user_data['password_change_timestamp'] = 1;
        }
        $user_id = db_query("INSERT INTO ?:users ?e", $user_data);
        fn_log_event('users', 'create', array('user_id' => $user_id));
    }
    $user_data['user_id'] = $user_id;
    // Set/delete insecure password notification
    if (AREA == 'A' && Registry::get('config.demo_mode') != true && !empty($user_data['password1'])) {
        if (!fn_compare_login_password($user_data, $user_data['password1'])) {
            fn_delete_notification('insecure_password');
        } else {
            $lang_var = 'warning_insecure_password_email';
            fn_set_notification('E', __('warning'), __($lang_var, array('[link]' => fn_url("profiles.update?user_id=" . $user_id))), 'K', 'insecure_password');
        }
    }
    if (empty($user_data['user_login'])) {
        // if we're using email as login or user type does not require login, fill login field
        db_query("UPDATE ?:users SET user_login = '******' WHERE user_id = ?i AND user_login = ''", $user_id, $user_id);
    }
    // Fill shipping info with billing if needed
    if (empty($ship_to_another)) {
        $profile_fields = fn_get_profile_fields($user_data['user_type']);
        $use_default = AREA == 'A' ? true : false;
        fn_fill_address($user_data, $profile_fields, $use_default);
    }
    $user_data['profile_id'] = fn_update_user_profile($user_id, $user_data, $action);
    $user_data = fn_get_user_info($user_id, true, $user_data['profile_id']);
    if ($register_at_checkout) {
        $user_data['register_at_checkout'] = 'Y';
    }
    $lang_code = AREA == 'A' && !empty($user_data['lang_code']) ? $user_data['lang_code'] : CART_LANGUAGE;
    if (!fn_allowed_for('ULTIMATE:FREE')) {
        $user_data['usergroups'] = db_get_hash_array("SELECT lnk.link_id, lnk.usergroup_id, lnk.status, a.type, b.usergroup" . " FROM ?:usergroup_links as lnk" . " INNER JOIN ?:usergroups as a ON a.usergroup_id = lnk.usergroup_id AND a.status != 'D'" . " LEFT JOIN ?:usergroup_descriptions as b ON b.usergroup_id = a.usergroup_id AND b.lang_code = ?s" . " WHERE a.status = 'A' AND lnk.user_id = ?i AND lnk.status != 'D' AND lnk.status != 'F'", 'usergroup_id', $lang_code, $user_id);
    }
    // Send notifications to customer
    if (!empty($notify_user)) {
        $from = 'company_users_department';
        if (fn_allowed_for('MULTIVENDOR')) {
            // Vendor administrator's notification
            // is sent from root users department
            if ($user_data['user_type'] == 'V') {
                $from = 'default_company_users_department';
            }
        }
        // Notify customer about profile activation (when update profile only)
        if ($action == 'update' && $current_user_data['status'] === 'D' && $user_data['status'] === 'A') {
            Mailer::sendMail(array('to' => $user_data['email'], 'from' => $from, 'data' => array('user_data' => $user_data), 'tpl' => 'profiles/profile_activated.tpl', 'company_id' => $user_data['company_id']), fn_check_user_type_admin_area($user_data['user_type']) ? 'A' : 'C', $lang_code);
        }
        // Notify customer about profile add/update
        $prefix = $action == 'add' ? 'create' : 'update';
        // Send password to user only if it was created by admin or vendor
        if (AREA != 'C' && $auth['user_id'] != $user_id) {
            $password = $original_password;
        } else {
            $password = null;
        }
        Mailer::sendMail(array('to' => $user_data['email'], 'from' => $from, 'data' => array('password' => $password, 'user_data' => $user_data), 'tpl' => 'profiles/' . $prefix . '_profile.tpl', 'company_id' => $user_data['company_id']), fn_check_user_type_admin_area($user_data['user_type']) ? 'A' : 'C', $lang_code);
    }
    if ($action == 'add') {
        if (AREA != 'A') {
            if (Registry::get('settings.General.approve_user_profiles') == 'Y') {
                fn_set_notification('W', __('important'), __('text_profile_should_be_approved'));
                // Notify administrator about new profile
                Mailer::sendMail(array('to' => 'company_users_department', 'from' => 'company_users_department', 'reply_to' => $user_data['email'], 'data' => array('user_data' => $user_data), 'tpl' => 'profiles/activate_profile.tpl', 'company_id' => $user_data['company_id']), 'A', Registry::get('settings.Appearance.backend_default_language'));
            } else {
                fn_set_notification('N', __('information'), __('text_profile_is_created'));
            }
        }
        if (!is_null($auth)) {
            if (!empty($auth['order_ids'])) {
                db_query("UPDATE ?:orders SET user_id = ?i WHERE order_id IN (?n)", $user_id, $auth['order_ids']);
            }
        }
    } else {
        if (AREA == 'C') {
            fn_set_notification('N', __('information'), __('text_profile_is_updated'));
        }
    }
    fn_set_hook('update_profile', $action, $user_data, $current_user_data);
    return array($user_id, !empty($user_data['profile_id']) ? $user_data['profile_id'] : false);
}
Пример #13
0
/**
 * Get default supplier id
 *
 * @param int $company_id Supplier company_id
 * @return int Default supplier id
 */
function fn_get_default_supplier_id($company_id = 0)
{
    if (empty($company_id)) {
        $company_id = Registry::ifGet('runtime.company_id', fn_get_default_company_id());
    }
    return db_get_field("SELECT supplier_id FROM ?:suppliers WHERE status = 'A' AND company_id = ?i ORDER BY supplier_id LIMIT 1", $company_id);
}
Пример #14
0
function fn_update_ebay_template($data, $template_id = 0, $lang_code = CART_LANGUAGE)
{
    if (empty($data['name'])) {
        return false;
    }
    unset($data['template_id']);
    if (fn_allowed_for('ULTIMATE')) {
        // check that template owner was not changed by store administrator
        if (Registry::get('runtime.company_id') || empty($data['company_id'])) {
            $template_company_id = db_get_field('SELECT company_id FROM ?:ebay_templates WHERE template_id = ?i', $template_id);
            if (!empty($template_company_id)) {
                $data['company_id'] = $template_company_id;
            } else {
                if (Registry::get('runtime.company_id')) {
                    $template_company_id = $data['company_id'] = Registry::get('runtime.company_id');
                } else {
                    $template_company_id = $data['company_id'] = fn_get_default_company_id();
                }
            }
        } else {
            $template_company_id = $data['company_id'];
        }
    } else {
        if (Registry::get('runtime.company_id')) {
            $template_company_id = Registry::get('runtime.company_id');
        } else {
            $template_company_id = $data['company_id'];
        }
    }
    if (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id') && !empty($template_company_id) && Registry::get('runtime.company_id') != $template_company_id) {
        $create = false;
    } else {
        if (isset($data['payment_methods']) && is_array($data['payment_methods'])) {
            $data['payment_methods'] = implode(',', $data['payment_methods']);
        }
        if (empty($data['root_sec_category'])) {
            $data['sec_category'] = '';
        }
        if (!empty($template_id)) {
            db_query('UPDATE ?:ebay_templates SET ?u WHERE template_id = ?i', $data, $template_id);
            db_query('UPDATE ?:ebay_template_descriptions SET ?u WHERE template_id = ?i AND lang_code = ?s', $data, $template_id, $lang_code);
            if (isset($_REQUEST['share_objects']) && isset($_REQUEST['share_objects']['ebay_templates']) && isset($_REQUEST['share_objects']['ebay_templates'][$template_id])) {
                $_products = db_get_fields("SELECT product_id FROM ?:products WHERE company_id NOT IN (?a) AND ebay_template_id = ?i", $_REQUEST['share_objects']['ebay_templates'][$template_id], $template_id);
                if (!empty($_products)) {
                    db_query("UPDATE ?:products SET ebay_template_id = 0 WHERE product_id IN (?a)", $_products);
                }
            }
        } else {
            $data['template_id'] = $template_id = db_query("INSERT INTO ?:ebay_templates ?e", $data);
            if (isset($data['name']) && empty($data['name'])) {
                unset($data['name']);
            }
            if (!empty($data['name'])) {
                foreach (fn_get_translation_languages() as $data['lang_code'] => $_v) {
                    db_query("INSERT INTO ?:ebay_template_descriptions ?e", $data);
                }
            }
        }
        if ($data['use_as_default'] == 'Y') {
            db_query('UPDATE ?:ebay_templates SET use_as_default = ?s WHERE company_id = ?i AND NOT template_id = ?i', 'N', $template_company_id, $template_id);
        }
    }
    return $template_id;
}