Exemplo n.º 1
0
function fn_get_seo_redirects($params = array(), $items_per_page = 0, $lang_code = DESCR_SL)
{
    // Init filter
    $params = LastView::instance()->update('seo_redirects', $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    $condition = '';
    if (isset($params['src']) && fn_string_not_empty($params['src'])) {
        $condition .= db_quote(" AND src LIKE ?l", "%" . trim($params['src']) . "%");
    }
    if (!empty($params['type'])) {
        $condition .= db_quote(" AND type = ?s", $params['type']);
    }
    if (!empty($params['lang_code'])) {
        $condition .= db_quote(" AND lang_code = ?s", $params['lang_code']);
    }
    $condition .= fn_get_seo_company_condition('?:seo_redirects.company_id');
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:seo_redirects WHERE 1 ?p", $condition);
        $limit = db_paginate($params['page'], $params['items_per_page']);
    }
    $seo_redirects = db_get_hash_array("SELECT * FROM ?:seo_redirects WHERE 1 ?p ORDER BY src {$limit}", 'redirect_id', $condition);
    if (!empty($seo_redirects)) {
        foreach ($seo_redirects as $key => $seo_redirect) {
            $seo_redirects[$key]['parsed_url'] = fn_generate_seo_url_from_schema($seo_redirect);
        }
    }
    return array($seo_redirects, $params);
}
Exemplo n.º 2
0
function fn_add_bean_bag_filling_apply_option_modifiers_post($product_options, &$base_value, $type, $orig_options, $orig_value, $fields, $extra)
{
    if (AREA == 'A') {
        return;
        //var_dump($_REQUEST); die();
        //var_dump($product_options, $base_value, $type, $orig_options, $orig_value, $fields, $extra); die();
        if (!empty($product_options) && $type == 'P') {
            $opt = array_pop($product_options);
            if ($opt == "346") {
                $bean_bag_150 = Registry::get('addons.add_bean_bag_filling.bean_bag_filling_150');
                $bean_bag_300 = Registry::get('addons.add_bean_bag_filling.bean_bag_filling_300');
                $exist_bean_bag_150 = db_get_field("SELECT product_id FROM ?:products WHERE product_id = ?i", $bean_bag_150);
                $exist_bean_bag_300 = db_get_field("SELECT product_id FROM ?:products WHERE product_id = ?i", $bean_bag_300);
                $p_prices = db_get_hash_array("SELECT price, product_id FROM ?:product_prices WHERE product_id in (?n)", 'product_id', array($exist_bean_bag_150, $exist_bean_bag_300));
                $p_data = db_get_row("SELECT bean_bag_filling_150, bean_bag_filling_300, bean_bag_quantity_150, bean_bag_quantity_300 FROM ?:products WHERE product_id = ?i", $extra['product_data']['product_id']);
                $mod_ = 0;
                //fn_write_die($p_data);
                $price_ = 0;
                if (!empty($p_data['bean_bag_quantity_150']) && $p_data['bean_bag_filling_150'] == 'Y' && !empty($exist_bean_bag_150)) {
                    $mod_ += $p_data['bean_bag_quantity_150'] * $p_prices[$exist_bean_bag_150]['price'];
                    $price_ += $mod_;
                }
                if (!empty($p_data['bean_bag_quantity_300']) && $p_data['bean_bag_filling_300'] == 'Y' && !empty($exist_bean_bag_300)) {
                    $mod_ += $p_data['bean_bag_quantity_300'] * $p_prices[$exist_bean_bag_300]['price'];
                    $price_ += $mod_;
                }
            }
            $base_value += $price_;
        }
        return $base_value;
    }
    //var_dump($base_value); die();
}
Exemplo n.º 3
0
/**
 * Get product/category/global earned points list
 *
 * @param integer $object_id Object ID
 * @param string $object_type Object type (see constants in the config.php file)
 * @param array $usergroup_ids Array with usergroup IDs
 * @param integer $company_id Company ID
 * @return array
 */
function fn_get_reward_points($object_id, $object_type = PRODUCT_REWARD_POINTS, $usergroup_ids = array(), $company_id = 0)
{
    $op_suffix = Registry::get('addons.reward_points.consider_zero_values') == 'Y' ? '=' : '';
    if (fn_allowed_for('ULTIMATE')) {
        if ($object_type == GLOBAL_REWARD_POINTS) {
            if (empty($company_id) && Registry::get('runtime.company_id')) {
                $company_id = Registry::get('runtime.company_id');
            } elseif (!Registry::get('runtime.company_id')) {
                return array();
            }
        }
    }
    if (!empty($usergroup_ids)) {
        if (Registry::get('addons.reward_points.several_points_action') == 'minimal_absolute') {
            $order_by = 'amount_type ASC, amount ASC';
        } elseif (Registry::get('addons.reward_points.several_points_action') == 'minimal_percentage') {
            $order_by = 'amount_type DESC, amount ASC';
        } elseif (Registry::get('addons.reward_points.several_points_action') == 'maximal_absolute') {
            $order_by = 'amount_type ASC, amount DESC';
        } elseif (Registry::get('addons.reward_points.several_points_action') == 'maximal_percentage') {
            $order_by = 'amount_type DESC, amount DESC';
        }
        return db_get_row("SELECT *, amount AS pure_amount FROM ?:reward_points" . " WHERE object_id = ?i AND object_type = ?s AND company_id = ?i" . " AND amount >{$op_suffix} 0 AND usergroup_id IN(?n)" . " ORDER BY ?p LIMIT 1", $object_id, $object_type, $company_id, $usergroup_ids, $order_by);
    } else {
        return db_get_hash_array("SELECT *, amount AS pure_amount FROM ?:reward_points" . " WHERE object_id = ?i AND object_type = ?s AND company_id = ?i AND amount >{$op_suffix} 0" . " ORDER BY usergroup_id", 'usergroup_id', $object_id, $object_type, $company_id);
    }
}
Exemplo n.º 4
0
function fn_get_tags($params = array(), $items_per_page = 0)
{
    // Init filter
    $params = LastView::instance()->update('tags', $params);
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    // Define sort fields
    $sortings = array('tag' => '?:tags.tag', 'status' => '?:tags.status', 'popularity' => 'popularity', 'users' => 'users');
    $conditions = fn_tags_build_conditions($params);
    $sorting = db_sort($params, $sortings, 'tag', 'asc');
    $limit = '';
    if (!empty($params['limit'])) {
        $limit = db_quote(' LIMIT 0, ?i', $params['limit']);
    } elseif (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(DISTINCT(?:tags.tag_id)) FROM ?:tags LEFT JOIN ?:tag_links ON ?:tags.tag_id = ?:tag_links.tag_id WHERE 1 ?p", $conditions);
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $tags = db_get_hash_array("SELECT ?:tags.tag_id, ?:tag_links.object_id, ?:tag_links.object_type, ?:tags.tag, ?:tags.status, COUNT(?:tag_links.tag_id) as popularity " . "FROM ?:tags LEFT JOIN ?:tag_links ON ?:tag_links.tag_id = ?:tags.tag_id WHERE 1 ?p GROUP BY ?:tags.tag_id {$sorting} {$limit}", 'tag_id', $conditions);
    if (!empty($params['count_objects'])) {
        $objs = db_get_array("SELECT tag_id, COUNT(DISTINCT(object_id)) as count, object_type " . "FROM ?:tag_links WHERE tag_id IN (?n) GROUP BY tag_id, object_type", array_keys($tags));
        foreach ($objs as $v) {
            $tags[$v['tag_id']]['objects_count'][$v['object_type']] = $v['count'];
        }
    }
    // Generate popularity level
    foreach ($tags as $k => $v) {
        $level = ceil(log($v['popularity']));
        $tags[$k]['level'] = $level > TAGS_MAX_LEVEL ? TAGS_MAX_LEVEL : $level;
    }
    if (!empty($params['sort_popular'])) {
        $tags = fn_sort_array_by_key($tags, 'tag', SORT_ASC);
    }
    return array($tags, $params);
}
Exemplo n.º 5
0
function fn_get_banners($params = array(), $lang_code = CART_LANGUAGE)
{
    $default_params = array('items_per_page' => 0);
    $params = array_merge($default_params, $params);
    $sortings = array('position' => '?:banners.position', 'timestamp' => '?:banners.timestamp', 'name' => '?:banner_descriptions.banner');
    $condition = $limit = '';
    if (!empty($params['limit'])) {
        $limit = db_quote(' LIMIT 0, ?i', $params['limit']);
    }
    $sorting = db_sort($params, $sortings, 'name', 'asc');
    $condition = AREA == 'A' ? '' : " AND ?:banners.status = 'A' ";
    $condition .= fn_get_localizations_condition('?:banners.localization');
    $condition .= AREA == 'A' ? '' : " AND (?:banners.type != 'G' OR ?:banner_images.banner_image_id IS NOT NULL) ";
    if (!empty($params['item_ids'])) {
        $condition .= db_quote(' AND ?:banners.banner_id IN (?n)', explode(',', $params['item_ids']));
    }
    if (!empty($params['period']) && $params['period'] != 'A') {
        list($params['time_from'], $params['time_to']) = fn_create_periods($params);
        $condition .= db_quote(" AND (?:banners.timestamp >= ?i AND ?:banners.timestamp <= ?i)", $params['time_from'], $params['time_to']);
    }
    fn_set_hook('get_banners', $params, $condition, $sorting, $limit, $lang_code);
    $fields = array('?:banners.banner_id', '?:banners.type', '?:banners.target', '?:banners.status', '?:banners.position', '?:banner_descriptions.banner', '?:banner_descriptions.description', '?:banner_descriptions.url', '?:banner_images.banner_image_id');
    if (fn_allowed_for('ULTIMATE')) {
        $fields[] = '?:banners.company_id';
    }
    $banners = db_get_hash_array("SELECT ?p FROM ?:banners " . "LEFT JOIN ?:banner_descriptions ON ?:banner_descriptions.banner_id = ?:banners.banner_id AND ?:banner_descriptions.lang_code = ?s" . "LEFT JOIN ?:banner_images ON ?:banner_images.banner_id = ?:banners.banner_id AND ?:banner_images.lang_code = ?s" . "WHERE 1 ?p ?p ?p", 'banner_id', implode(", ", $fields), $lang_code, $lang_code, $condition, $sorting, $limit);
    $banner_image_ids = fn_array_column($banners, 'banner_image_id');
    $images = fn_get_image_pairs($banner_image_ids, 'promo', 'M', true, false, $lang_code);
    foreach ($banners as $banner_id => $banner) {
        $banners[$banner_id]['main_pair'] = !empty($images[$banner['banner_image_id']]) ? reset($images[$banner['banner_image_id']]) : array();
    }
    fn_set_hook('get_banners_post', $banners, $params);
    return array($banners, $params);
}
Exemplo n.º 6
0
/**
 * Get promotions
 *
 * @param array $params array with search params
 * @param int $items_per_page
 * @param string $lang_code
 * @return array list of promotions in first element, filtered parameters in second
 */
function fn_get_promotions($params, $items_per_page = 0, $lang_code = CART_LANGUAGE)
{
    // Init filter
    $params = LastView::instance()->update('promotions', $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page, 'get_hidden' => true);
    $params = array_merge($default_params, $params);
    // Define fields that should be retrieved
    $fields = array("?:promotions.*", "?:promotion_descriptions.name", "?:promotion_descriptions.detailed_description", "?:promotion_descriptions.short_description");
    // Define sort fields
    $sortings = array('name' => "?:promotion_descriptions.name", 'priority' => "?:promotions.priority", 'zone' => "?:promotions.zone", 'status' => "?:promotions.status");
    $condition = $join = $group = '';
    $condition .= fn_get_company_condition('?:promotions.company_id');
    $statuses = array('A');
    if (!empty($params['get_hidden'])) {
        $statuses[] = 'H';
    }
    if (!empty($params['promotion_id'])) {
        $condition .= db_quote(' AND ?:promotions.promotion_id IN (?n)', $params['promotion_id']);
    }
    if (!empty($params['active'])) {
        $condition .= db_quote(" AND IF(from_date, from_date <= ?i, 1) AND IF(to_date, to_date >= ?i, 1) AND status IN (?a)", TIME, TIME, $statuses);
    }
    if (fn_allowed_for('ULTIMATE:FREE')) {
        $params['zone'] = 'catalog';
    }
    if (!empty($params['zone'])) {
        $condition .= db_quote(" AND ?:promotions.zone = ?s", $params['zone']);
    }
    if (!empty($params['coupon_code'])) {
        $condition .= db_quote(" AND (CONCAT(LOWER(?:promotions.conditions_hash), ';') LIKE ?l OR CONCAT(LOWER(?:promotions.conditions_hash), ';') LIKE ?l)", "%coupon_code={$params['coupon_code']};%", "%auto_coupons={$params['coupon_code']};%");
    }
    if (!empty($params['coupons'])) {
        $condition .= db_quote(" AND ?:promotions.conditions_hash LIKE ?l", "%coupon_code=%");
    }
    if (!empty($params['auto_coupons'])) {
        $condition .= db_quote(" AND ?:promotions.conditions_hash LIKE ?l", "%auto_coupons=%");
    }
    $join .= db_quote(" LEFT JOIN ?:promotion_descriptions ON ?:promotion_descriptions.promotion_id = ?:promotions.promotion_id AND ?:promotion_descriptions.lang_code = ?s", $lang_code);
    fn_set_hook('get_promotions', $params, $fields, $sortings, $condition, $join);
    $sorting = db_sort($params, $sortings, 'name', 'desc');
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:promotions {$join} WHERE 1 {$condition} {$group}");
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    if (!empty($params['simple'])) {
        return db_get_hash_single_array("SELECT ?:promotions.promotion_id, ?:promotion_descriptions.name FROM ?:promotions {$join} WHERE 1 {$condition} {$group} {$sorting} {$limit}", array('promotion_id', 'name'));
    } else {
        $promotions = db_get_hash_array('SELECT ' . implode(', ', $fields) . " FROM ?:promotions {$join} WHERE 1 {$condition} {$group} {$sorting} {$limit}", 'promotion_id');
    }
    if (!empty($params['expand'])) {
        foreach ($promotions as $k => $v) {
            $promotions[$k]['conditions'] = !empty($v['conditions']) ? unserialize($v['conditions']) : array();
            $promotions[$k]['bonuses'] = !empty($v['bonuses']) ? unserialize($v['bonuses']) : array();
        }
    }
    return array($promotions, $params);
}
Exemplo n.º 7
0
function fn_get_reward_points($object_id, $object_type = PRODUCT_REWARD_POINTS, $usergroup_ids = array())
{
    $op_suffix = Registry::get('addons.reward_points.consider_zero_values') == 'Y' ? '=' : '';
    if (!empty($usergroup_ids)) {
        $order_by = 'amount_type ' . (POINTS_FOR_USERGROUP_BY_AMOUNT_TYPE == 'A' ? 'ASC' : 'DESC') . ', amount ' . (Registry::get('addons.reward_points.several_points_action') == 'min' ? 'ASC' : 'DESC');
        return db_get_row("SELECT *, amount AS pure_amount FROM ?:reward_points WHERE object_id = ?i AND object_type = ?s AND amount >{$op_suffix} 0 AND usergroup_id IN(?n) ORDER BY ?p LIMIT 1", $object_id, $object_type, $usergroup_ids, $order_by);
    } else {
        return db_get_hash_array("SELECT *, amount AS pure_amount FROM ?:reward_points WHERE object_id = ?i AND object_type = ?s AND amount >{$op_suffix} 0 ORDER BY usergroup_id", 'usergroup_id', $object_id, $object_type);
    }
}
Exemplo n.º 8
0
 /**
  * Gets layouts list
  *
  * @param $array input params
  * @return array layouts list
  */
 public function getList($params = array())
 {
     $condition = '';
     if (fn_allowed_for('ULTIMATE')) {
         $condition = $this->getCompanyCondition('?:bm_layouts.company_id');
     }
     if (!empty($params['theme_name'])) {
         $condition .= db_quote(" AND theme_name = ?s", $params['theme_name']);
     }
     return db_get_hash_array("SELECT * FROM ?:bm_layouts WHERE 1 ?p", 'layout_id', $condition);
 }
Exemplo n.º 9
0
 function fn_exim_set_product_categories($product_id, $link_type, $data, $category_delimiter, $lang_code = CART_LANGUAGE)
 {
     if (empty($data)) {
         return false;
     }
     $set_delimiter = ';';
     $paths = array();
     $updated_categories = array();
     // Check if array is provided
     if (strpos($data, $set_delimiter) !== false) {
         $paths = explode($set_delimiter, $data);
         array_walk($paths, 'fn_trim_helper');
     } else {
         $paths[] = $data;
     }
     if (!fn_is_empty($paths)) {
         $old_data = db_get_hash_array("SELECT * FROM ?:products_categories WHERE product_id= ?i", 'category_id', $product_id);
         foreach ($old_data as $k => $v) {
             if ($v['link_type'] == $link_type) {
                 $updated_categories[] = $k;
             }
         }
         db_query("DELETE FROM ?:products_categories WHERE product_id = ?i AND link_type = ?s", $product_id, $link_type);
     }
     foreach ($paths as $category) {
         $categories = strpos($category, $category_delimiter) !== false ? explode($category_delimiter, $category) : array($category);
         if (!empty($categories)) {
             $parent_id = '0';
             foreach ($categories as $cat) {
                 $category_id = db_get_field("SELECT ?:categories.category_id FROM ?:category_descriptions INNER JOIN ?:categories ON ?:categories.category_id = ?:category_descriptions.category_id WHERE ?:category_descriptions.category = ?s AND lang_code = ?s AND parent_id = ?i", $cat, $lang_code, $parent_id);
                 if (!empty($category_id)) {
                     $parent_id = $category_id;
                 } else {
                     $category_data = array('parent_id' => $parent_id, 'category' => $cat);
                     $category_id = fn_update_category($category_data);
                     $parent_id = $category_id;
                 }
             }
             $data = array('product_id' => $product_id, 'category_id' => $category_id, 'link_type' => $link_type);
             if (!empty($old_data) && !empty($old_data[$category_id])) {
                 $data = fn_array_merge($old_data[$category_id], $data);
             }
             db_query("REPLACE INTO ?:products_categories ?e", $data);
             $updated_categories[] = $category_id;
         }
     }
     if (!empty($updated_categories)) {
         fn_update_product_count($updated_categories);
         return true;
     }
     return false;
 }
Exemplo n.º 10
0
function fn_get_store_locations($params, $items_per_page = 0, $lang_code = CART_LANGUAGE)
{
    $default_params = array('page' => 1, 'q' => '', 'match' => 'any', 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    $fields = array('?:store_locations.*', '?:store_location_descriptions.*', '?:country_descriptions.country as country_title');
    $join = db_quote(" LEFT JOIN ?:store_location_descriptions ON ?:store_locations.store_location_id = ?:store_location_descriptions.store_location_id AND ?:store_location_descriptions.lang_code = ?s", $lang_code);
    $join .= db_quote(" LEFT JOIN ?:country_descriptions ON ?:store_locations.country = ?:country_descriptions.code AND ?:country_descriptions.lang_code = ?s", $lang_code);
    $condition = 1;
    if (AREA == 'C') {
        $condition .= " AND status = 'A'";
    }
    // Search string condition for SQL query
    if (!empty($params['q'])) {
        if ($params['match'] == 'any') {
            $pieces = explode(' ', $params['q']);
            $search_type = ' OR ';
        } elseif ($params['match'] == 'all') {
            $pieces = explode(' ', $params['q']);
            $search_type = ' AND ';
        } else {
            $pieces = array($params['q']);
            $search_type = '';
        }
        $_condition = array();
        foreach ($pieces as $piece) {
            $tmp = db_quote("?:store_location_descriptions.name LIKE ?l", "%{$piece}%");
            // check search words
            $tmp .= db_quote(" OR ?:store_location_descriptions.description LIKE ?l", "%{$piece}%");
            $tmp .= db_quote(" OR ?:store_location_descriptions.city LIKE ?l", "%{$piece}%");
            $tmp .= db_quote(" OR ?:country_descriptions.country LIKE ?l", "%{$piece}%");
            $_condition[] = '(' . $tmp . ')';
        }
        $_cond = implode($search_type, $_condition);
        if (!empty($_condition)) {
            $condition .= ' AND (' . $_cond . ') ';
        }
        unset($_condition);
    }
    $condition .= AREA == 'C' && defined('CART_LOCALIZATION') ? fn_get_localizations_condition('?:store_locations.localization') : '';
    $sorting = "?:store_locations.position, ?:store_location_descriptions.name";
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(?:store_locations.store_location_id) FROM ?:store_locations ?p WHERE ?p", $join, $condition);
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $data = db_get_hash_array('SELECT ?p FROM ?:store_locations ?p WHERE ?p GROUP BY ?:store_locations.store_location_id ORDER BY ?p ?p', 'store_location_id', implode(', ', $fields), $join, $condition, $sorting, $limit);
    return array($data, $params);
}
Exemplo n.º 11
0
 /**
  * Return list of product menus
  * @static
  * @param  string $condition SQL condition
  * @param  string $lang_code
  * @return array  List of product menus sorted by position by menu_id
  */
 public static function getList($condition = '', $lang_code = CART_LANGUAGE)
 {
     /**
      * Prepare params for sql query before get menus list
      * @param string $lang_code
      */
     fn_set_hook('get_menus_pre', $join, $condition, $lang_code);
     $menus = db_get_hash_array("SELECT * FROM ?:menus " . "LEFT JOIN ?:menus_descriptions " . "ON ?:menus.menu_id = ?:menus_descriptions.menu_id " . "?p " . "WHERE ?:menus_descriptions.lang_code = ?s ?p ?p", 'menu_id', $join, $lang_code, fn_get_company_condition('?:menus.company_id'), $condition);
     /**
      * Process menus list after sql query
      * @param array $menus Array of menus data
      * @param string $lang_code
      */
     fn_set_hook('get_menus_post', $menus, $lang_code);
     return $menus;
 }
Exemplo n.º 12
0
function fn_get_all_cities($avail_only = true, $lang_code = CART_LANGUAGE)
{
    $avail_cond = $avail_only == true ? " WHERE a.status = 'A' AND b.status = 'A'" : '';
    //return db_get_hash_multi_array("SELECT a.country_code, a.code, b.state FROM ?:states as a LEFT JOIN ?:state_descriptions as b ON b.state_id = a.state_id AND b.lang_code = ?s $avail_cond ORDER BY a.country_code, b.state", array('country_code'), $lang_code);
    $countries = db_get_hash_multi_array("SELECT a.country_code, a.code as state_id, b.code, c.city, b.city_id FROM ?:states as a " . "LEFT JOIN ?:rus_cities as b ON b.state_id = a.state_id " . "LEFT JOIN ?:rus_city_descriptions as c ON c.city_id = b.city_id AND c.lang_code = ?s " . "{$avail_cond} ORDER BY a.country_code, b.code, c.city", array('country_code'), $lang_code);
    $rus_countries = db_get_hash_array("SELECT city_id, city FROM ?:rus_city_descriptions WHERE lang_code = ?s", 'city_id', 'ru');
    $cities = array();
    foreach ($countries as $c_code => $states) {
        foreach ($states as $city) {
            if (!empty($city['city_id'])) {
                $cities[$c_code][$city['state_id']][] = array('code' => $city['code'], 'city' => empty($city['city']) ? $rus_countries[$city['city_id']]['city'] : $city['city']);
            }
        }
    }
    return $cities;
}
Exemplo n.º 13
0
 /**
  * Gets list of containers
  *
  * @param  array $params input params
  * @return array Array of containers data as position => data
  */
 public static function getList($params = array())
 {
     $fields = array('c.*');
     $join = $condition = '';
     if (!empty($params['location_id'])) {
         $condition .= db_quote(" AND c.location_id = ?i", $params['location_id']);
     }
     if (!empty($params['container_id'])) {
         $condition .= db_quote(" AND c.container_id = ?i", $params['container_id']);
     }
     if (!empty($params['default_location'])) {
         $layout_id = db_get_field("SELECT layout_id FROM ?:bm_locations WHERE location_id = ?i", $params['default_location']);
         $join .= db_quote(" INNER JOIN ?:bm_locations as l ON c.location_id = l.location_id AND l.is_default = 1 AND l.layout_id = ?i", $layout_id);
         $condition .= db_quote(" AND c.position IN ('TOP_PANEL', 'HEADER', 'FOOTER')");
         $fields[] = db_quote('IF (c.location_id != ?i, 0, 1) as `default`', $params['default_location']);
     }
     $containers = db_get_hash_array("SELECT " . implode(', ', $fields) . " FROM ?:bm_containers as c ?p WHERE 1 ?p", 'position', $join, $condition);
     return $containers;
 }
Exemplo n.º 14
0
 /**
  * Return list of product tabs
  *
  * @param  string $condition  Query condition; it is treated as a WHERE clause
  * @param  int    $product_id Product identifier
  * @param  string $lang_code  2 letter language code
  * @return array  Array of product tabs sorted by position and tab_id
  */
 public function getList($condition = '', $product_id = 0, $lang_code = DESCR_SL)
 {
     $join = '';
     $fields = array('*');
     /**
      * Prepares params for SQL query before getting product tabs
      * @param array $fields array of table column names to be returned
      * @param string $condition Query condition; it is treated as a WHERE clause
      * @param string $lang_code 2 letter language code
      */
     fn_set_hook('get_product_tabs_pre', $fields, $join, $condition, $lang_code);
     $fields = array_merge($fields, array('?:product_tabs.status as status', '?:product_tabs.block_id as block_id', '?:product_tabs.company_id as company_id', '?:product_tabs_descriptions.name as name '));
     $tabs = db_get_hash_array("SELECT ?p FROM ?:product_tabs " . "LEFT JOIN ?:product_tabs_descriptions " . "ON ?:product_tabs.tab_id = ?:product_tabs_descriptions.tab_id " . "LEFT JOIN ?:bm_blocks " . "ON ?:bm_blocks.block_id = ?:product_tabs.block_id " . "?p " . "WHERE ?:product_tabs_descriptions.lang_code = ?s ?p ?p ORDER BY position", 'tab_id', implode(',', $fields), $join, $lang_code, $this->getCompanyCondition('?:product_tabs.company_id'), $condition);
     foreach ($tabs as $tab_id => $tab) {
         if (!empty($tab['addon'])) {
             $addons = Registry::get('addons');
             if ($addons[$tab['addon']]['status'] != 'A') {
                 unset($tabs[$tab_id]);
                 continue;
             }
         }
         $tabs[$tab_id]['items_ids'] = explode(',', $tab['product_ids']);
         $tabs[$tab_id]['items_count'] = count($tabs[$tab_id]['items_ids']);
         if ($product_id > 0) {
             if (array_search($product_id, $tabs[$tab_id]['items_ids']) !== false) {
                 if ($tab['status'] == 'A') {
                     $tabs[$tab_id]['status'] = 'D';
                 } else {
                     $tabs[$tab_id]['status'] = 'A';
                 }
             }
         }
     }
     /**
      * Processes product tabs list after getting it
      * @param array $tabs Array of product tabs data
      * @param string $lang_code 2 letter language code
      */
     fn_set_hook('get_product_tabs_post', $tabs, $lang_code);
     return $tabs;
 }
Exemplo n.º 15
0
function fn_paypal_user_login($checkout_details)
{
    $s_firstname = $s_lastname = '';
    if (!empty($checkout_details['SHIPTONAME'])) {
        $name = explode(' ', $checkout_details['SHIPTONAME']);
        $s_firstname = $name[0];
        unset($name[0]);
        $s_lastname = !empty($name[1]) ? implode(' ', $name) : '';
    }
    $s_state = $checkout_details['SHIPTOSTATE'];
    $s_state_codes = db_get_hash_array("SELECT ?:states.code, lang_code FROM ?:states LEFT JOIN ?:state_descriptions ON ?:state_descriptions.state_id = ?:states.state_id WHERE ?:states.country_code = ?s AND ?:state_descriptions.state = ?s", 'lang_code', $checkout_details['SHIPTOCOUNTRYCODE'], $s_state);
    if (!empty($s_state_codes[CART_LANGUAGE])) {
        $s_state = $s_state_codes[CART_LANGUAGE]['code'];
    } elseif (!empty($s_state_codes)) {
        $s_state = array_pop($s_state_codes);
        $s_state = $s_state['code'];
    }
    $address = array('s_firstname' => $s_firstname, 's_lastname' => $s_lastname, 's_address' => $checkout_details['SHIPTOSTREET'], 's_address_2' => !empty($checkout_details['SHIPTOSTREET2']) ? $checkout_details['SHIPTOSTREET2'] : '', 's_city' => $checkout_details['SHIPTOCITY'], 's_state' => $s_state, 's_country' => $checkout_details['SHIPTOCOUNTRYCODE'], 's_zipcode' => $checkout_details['SHIPTOZIP']);
    $_SESSION['auth'] = empty($_SESSION['auth']) ? array() : $_SESSION['auth'];
    $auth =& $_SESSION['auth'];
    // Update profile info if customer is registered user
    if (!empty($auth['user_id']) && $auth['area'] == 'C') {
        foreach ($address as $k => $v) {
            $_SESSION['cart']['user_data'][$k] = $v;
        }
        $profile_id = !empty($_SESSION['cart']['profile_id']) ? $_SESSION['cart']['profile_id'] : db_get_field("SELECT profile_id FROM ?:user_profiles WHERE user_id = ?i AND profile_type='P'", $auth['user_id']);
        db_query('UPDATE ?:user_profiles SET ?u WHERE profile_id = ?i', $_SESSION['cart']['user_data'], $profile_id);
        // Or jyst update info in the cart
    } else {
        // fill customer info
        $_SESSION['cart']['user_data'] = array('firstname' => $checkout_details['FIRSTNAME'], 'lastname' => $checkout_details['LASTNAME'], 'email' => $checkout_details['EMAIL'], 'company' => '', 'phone' => '', 'fax' => '');
        foreach ($address as $k => $v) {
            $_SESSION['cart']['user_data'][$k] = $v;
            $_SESSION['cart']['user_data']['b_' . substr($k, 2)] = $v;
        }
    }
    return true;
}
Exemplo n.º 16
0
function fn_get_order_reports($view = false, $report_id = 0)
{
    $status = empty($view) ? "" : "AND status = 'A'";
    $data = db_get_hash_array("SELECT a.*, b.description FROM ?:sales_reports as a LEFT JOIN ?:sales_reports_descriptions as b ON a.report_id = b.report_id AND lang_code = ?s WHERE type = 'O' {$status} ORDER BY position", 'report_id', CART_LANGUAGE);
    if (empty($data)) {
        return array();
    }
    // If we manage reports we need only it's name
    if (empty($view)) {
        return $data;
    }
    $k = $report_id;
    list($data[$k]['time_from'], $data[$k]['time_to']) = fn_create_periods($data[$k]);
    $data[$k]['tables'] = db_get_hash_array("SELECT a.*, b.description FROM ?:sales_reports_tables as a LEFT JOIN ?:sales_reports_table_descriptions as b ON a.table_id = b.table_id AND lang_code = ?s WHERE a.report_id = ?i ORDER BY position", 'table_id', CART_LANGUAGE, $report_id);
    foreach ($data[$k]['tables'] as $key => $value) {
        $data[$k]['tables'][$key]['time_from'] = $data[$k]['time_from'];
        $data[$k]['tables'][$key]['time_to'] = $data[$k]['time_to'];
        $elements = db_get_array("SELECT a.*, c.code FROM ?:sales_reports_table_elements as a LEFT JOIN ?:sales_reports_elements as c ON a.element_id = c.element_id WHERE a.table_id = ?i ORDER BY a.position", $value['table_id']);
        $data[$k]['tables'][$key]['interval_id'] = $value['interval_id'];
        $data[$k]['tables'][$key]['elements'] = fn_check_elements($elements, $data[$k]['tables'][$key]['time_from'], $data[$k]['tables'][$key]['time_to'], $value);
        $data[$k]['tables'][$key]['intervals'] = fn_check_intervals($data[$k]['tables'][$key]['interval_id'], $data[$k]['tables'][$key]['time_from'], $data[$k]['tables'][$key]['time_to']);
    }
    return $data;
}
Exemplo n.º 17
0
             fn_set_notification('E', __('error'), __('cant_create_backup_file'));
         }
     } else {
         fn_set_notification('E', __('error'), __('cant_upload_file'));
     }
 }
 if ($mode == 'optimize') {
     // Log database optimization
     fn_log_event('database', 'optimize');
     $all_tables = db_get_fields("SHOW TABLES");
     fn_set_progress('parts', sizeof($all_tables));
     foreach ($all_tables as $table) {
         fn_set_progress('echo', __('optimizing_table') . "&nbsp;<b>{$table}</b>...<br />");
         db_query("OPTIMIZE TABLE {$table}");
         db_query("ANALYZE TABLE {$table}");
         $fields = db_get_hash_array("SHOW COLUMNS FROM {$table}", 'Field');
         if (!empty($fields['is_global'])) {
             // Sort table by is_global field
             fn_echo('.');
             db_query("ALTER TABLE {$table} ORDER BY is_global DESC");
         } elseif (!empty($fields['position'])) {
             // Sort table by position field
             fn_echo('.');
             db_query("ALTER TABLE {$table} ORDER BY position");
         }
     }
     fn_set_notification('N', __('notice'), __('done'));
 }
 if ($mode == 'delete') {
     if (!empty($_REQUEST['backup_file'])) {
         fn_rm(Registry::get('config.dir.backups') . fn_basename($_REQUEST['backup_file']));
Exemplo n.º 18
0
 private static function _getFromDB()
 {
     $settings = db_get_hash_single_array('SELECT * FROM ?:twigmo_settings', array('name', 'value'));
     $store_sql = 'SELECT * FROM ?:twigmo_stores WHERE type = ?s';
     $settings['admin_connection'] = db_get_row($store_sql, 'A');
     $settings['customer_connections'] = db_get_hash_array($store_sql, 'company_id', 'C');
     return $settings;
 }
Exemplo n.º 19
0
if ($_SERVER['REQUEST_METHOD'] == "POST") {
    if ($mode == 'place_order' || $mode == 'subscribe_customer') {
        $subscriber = db_get_row("SELECT * FROM ?:subscribers WHERE email = ?s", $_SESSION['cart']['user_data']['email']);
        if (!empty($_REQUEST['mailing_lists']) && !fn_is_empty($_REQUEST['mailing_lists'])) {
            if (empty($subscriber)) {
                $_data = array('email' => $_SESSION['cart']['user_data']['email'], 'timestamp' => TIME);
                $subscriber_id = db_query("INSERT INTO ?:subscribers ?e", $_data);
            } else {
                $subscriber_id = $subscriber['subscriber_id'];
            }
            fn_update_subscriptions($subscriber_id, $_REQUEST['mailing_lists'], NULL, fn_get_notification_rules(true));
        } elseif (isset($_REQUEST['mailing_lists'])) {
            if (!empty($subscriber)) {
                fn_delete_subscribers($subscriber['subscriber_id']);
            }
        }
    }
    if ($mode == 'subscribe_customer') {
        return array(CONTROLLER_STATUS_REDIRECT, 'onestepcheckout.checkout');
    }
}
if ($mode == 'checkout') {
    $email = db_get_field("SELECT email FROM ?:users WHERE user_id = ?i", $_SESSION['auth']['user_id']);
    if ((empty($email) || $_SESSION['auth']['user_id'] == 0) && !empty($_SESSION['cart']['user_data']['email'])) {
        $email = $_SESSION['cart']['user_data']['email'];
    }
    $mailing_lists = db_get_hash_array("SELECT * FROM ?:subscribers INNER JOIN ?:user_mailing_lists ON ?:subscribers.subscriber_id = ?:user_mailing_lists.subscriber_id WHERE ?:subscribers.email = ?s", 'list_id', $email);
    Registry::get('view')->assign('user_mailing_lists', $mailing_lists);
    list($page_mailing_lists) = fn_get_mailing_lists();
    Registry::get('view')->assign('page_mailing_lists', $page_mailing_lists);
}
Exemplo n.º 20
0
function fn_get_rating_list($object_type, $parent_object_id = '')
{
    $object2parent_links = array('P' => array('table' => '?:categories', 'field' => 'category_id', 'join' => array('?:products_categories' => "?:discussion.object_id=?:products_categories.product_id AND ?:products_categories.link_type='M'", '?:categories' => "?:products_categories.category_id=?:categories.category_id")));
    $query = db_quote(" object_type = ?s AND ?:discussion.type IN ('R', 'B') AND !(?:discussion_rating.rating_value IS NULL) ", $object_type);
    $join = array();
    if (isset($object2parent_links[$object_type]) && !empty($parent_object_id)) {
        $path = db_get_field("SELECT id_path FROM {$object2parent_links[$object_type]['table']} WHERE {$object2parent_links[$object_type]['field']} = ?i", $parent_object_id);
        $parent_object_ids = db_get_fields("SELECT {$object2parent_links[$object_type]['field']} FROM {$object2parent_links[$object_type]['table']} WHERE id_path LIKE ?l", "{$path}/%");
        $parent_object_ids[] = $parent_object_id;
        $query .= " AND {$object2parent_links[$object_type]['table']}.{$object2parent_links[$object_type]['field']} IN ('" . implode("','", $parent_object_ids) . "') AND {$object2parent_links[$object_type]['table']}.status='A'";
        $join = $object2parent_links[$object_type]['join'];
    }
    if ($object_type == 'P') {
        // Adding condition for the "Show out of stock products" setting
        if (Registry::get('settings.General.inventory_tracking') == 'Y' && Registry::get('settings.General.show_out_of_stock_products') == 'N' && AREA == 'C') {
            $join["?:product_options_inventory AS inventory"] = "inventory.product_id=?:discussion.object_id";
            $join['?:products'] = "?:products.product_id=?:discussion.object_id";
            $query .= " AND IF(?:products.tracking='O', inventory.amount>0, ?:products.amount>0)";
        }
    }
    $join_conditions = '';
    foreach ($join as $table => $j_cond) {
        $join_conditions .= " LEFT JOIN {$table} ON {$j_cond} ";
    }
    return db_get_hash_array("SELECT object_id, avg(rating_value) AS rating FROM ?:discussion " . "LEFT JOIN ?:discussion_rating ON ?:discussion.thread_id=?:discussion_rating.thread_id {$join_conditions} " . "WHERE ?p GROUP BY ?:discussion.thread_id ORDER BY rating DESC", 'object_id', $query . fn_get_discussion_company_condition('?:discussion.company_id'));
}
Exemplo n.º 21
0
function fn_se_get_products_additionals(&$products, $company_id, $lang_code)
{
    $product_ids = fn_se_get_ids($products, 'product_id');
    if (fn_allowed_for('ULTIMATE')) {
        $shared_prices = db_get_hash_multi_array('SELECT product_id, (IF(percentage_discount = 0, price, price - (price * percentage_discount)/100)) as price, usergroup_id FROM ?:ult_product_prices WHERE company_id = ?i AND product_id IN (?n) AND lower_limit = 1', array('product_id', 'usergroup_id'), $company_id, $product_ids);
        $prices = db_get_hash_multi_array('SELECT product_id, (IF(percentage_discount = 0, price, price - (price * percentage_discount)/100)) as price, usergroup_id FROM ?:product_prices WHERE product_id IN (?n) AND lower_limit = 1', array('product_id', 'usergroup_id'), $product_ids);
        $product_categories = db_get_hash_multi_array("SELECT pc.product_id, c.category_id, c.usergroup_ids, c.status FROM ?:categories AS c LEFT JOIN ?:products_categories AS pc ON c.category_id = pc.category_id WHERE c.company_id = ?i AND product_id IN (?n) AND c.status IN ('A', 'H')", array('product_id', 'category_id'), $company_id, $product_ids);
        $shared_descriptions = db_get_hash_array("SELECT product_id, full_description FROM ?:ult_product_descriptions WHERE company_id = ?i AND product_id IN (?n) AND lang_code = ?s", 'product_id', $company_id, $product_ids, $lang_code);
    } else {
        $prices = db_get_hash_multi_array('SELECT product_id, (IF(percentage_discount = 0, price, price - (price * percentage_discount)/100)) as price, usergroup_id FROM ?:product_prices WHERE product_id IN (?n) AND lower_limit = 1', array('product_id', 'usergroup_id'), $product_ids);
        $product_categories = db_get_hash_multi_array("SELECT pc.product_id, c.category_id, c.usergroup_ids, c.status FROM ?:categories AS c LEFT JOIN ?:products_categories AS pc ON c.category_id = pc.category_id WHERE product_id IN (?n) AND c.status IN ('A', 'H')", array('product_id', 'category_id'), $product_ids);
    }
    if (Registry::get('settings.General.inventory_tracking') == 'Y' && Registry::get('settings.General.show_out_of_stock_products') == 'N') {
        $product_options = db_get_hash_single_array("SELECT product_id, max(amount) as amount FROM ?:product_options_inventory WHERE product_id IN (?n) GROUP BY product_id", array('product_id', 'amount'), $product_ids);
    }
    $descriptions = db_get_hash_array("SELECT product_id, full_description FROM ?:product_descriptions WHERE 1 AND product_id IN (?n) AND lang_code = ?s", 'product_id', $product_ids, $lang_code);
    foreach ($products as &$product) {
        $product_id = $product['product_id'];
        if (isset($shared_prices[$product_id])) {
            $product['se_prices'] = $shared_prices[$product_id];
        } elseif (isset($prices[$product_id])) {
            $product['se_prices'] = $prices[$product_id];
        } else {
            $product['se_prices'] = array('0' => array('price' => 0));
        }
        if ($product['tracking'] == ProductTracking::TRACK_WITH_OPTIONS && isset($product_options[$product_id])) {
            $product['amount'] = $product_options[$product_id];
        }
        if (!empty($shared_descriptions[$product_id]['full_description'])) {
            $product['se_full_description'] = $shared_descriptions[$product_id]['full_description'];
        } elseif (!empty($descriptions[$product_id]['full_description'])) {
            $product['se_full_description'] = $descriptions[$product_id]['full_description'];
        }
        $product['category_ids'] = array();
        $product['category_usergroup_ids'] = array();
        if (!empty($product_categories[$product_id])) {
            foreach ($product_categories[$product_id] as $pc) {
                $product['category_ids'][] = $pc['category_id'];
                $product['category_usergroup_ids'] = array_merge($product['category_usergroup_ids'], explode(',', $pc['usergroup_ids']));
            }
        }
        $product['empty_categories'] = empty($product['category_ids']) ? 'Y' : 'N';
    }
}
Exemplo n.º 22
0
function fn_gift_certificates_extract_cart(&$cart, &$user_id, &$type, &$user_type)
{
    if (!empty($user_id)) {
        $_cart_gift_cert = db_get_hash_array("SELECT * FROM ?:user_session_products WHERE user_id = ?i AND type = ?s AND item_type = 'G' AND user_type = ?s", 'item_id', $user_id, $type, $user_type);
        if (!empty($cart['gift_certificates']) && fn_allowed_for('MULTIVENDOR')) {
            foreach ($cart['products'] as $cart_id => $product) {
                if (empty($product['extra']['parent']['certificate'])) {
                    fn_delete_cart_product($cart, $cart_id);
                    fn_set_notification('W', 'Warning', __('gift_cert_with_products'));
                }
            }
        }
        if (!empty($_cart_gift_cert) && is_array($_cart_gift_cert)) {
            $other_products = false;
            foreach ($cart['products'] as $product) {
                if (empty($product['extra']['parent']['certificate'])) {
                    $other_products = true;
                    break;
                }
            }
            if (fn_allowed_for('MULTIVENDOR') && $other_products) {
                fn_set_notification('W', 'Warning', __('gift_cert_with_products'));
                foreach ($_cart_gift_cert as $_item_id => $_gift_cert) {
                    fn_delete_cart_gift_certificate($cart, $_item_id);
                }
            } else {
                $cart['gift_certificates'] = empty($cart['gift_certificates']) ? array() : $cart['gift_certificates'];
                foreach ($_cart_gift_cert as $_item_id => $_gift_cert) {
                    $_gift_cert_extra = unserialize($_gift_cert['extra']);
                    unset($_gift_cert['extra']);
                    $cart['gift_certificates'][$_item_id] = empty($cart['gift_certificates'][$_item_id]) ? fn_array_merge($_gift_cert, $_gift_cert_extra, true) : $cart['gift_certificates'][$_item_id];
                }
            }
        }
    }
}
Exemplo n.º 23
0
    if ($old_status != $new_status) {
        $func = 'fn_settings_actions_addons_' . $_REQUEST['id'];
        if (function_exists($func)) {
            $func($new_status, $old_status);
        }
        if ($old_status != $new_status) {
            db_query("UPDATE ?:addons SET status = ?s WHERE addon = ?s", $_REQUEST['status'], $_REQUEST['id']);
            fn_set_notification('N', fn_get_lang_var('notice'), fn_get_lang_var('status_changed'));
        } else {
            $ajax->assign('return_status', $old_status);
        }
    }
    exit;
} elseif ($mode == 'manage') {
    $all_addons = fn_get_dir_contents(DIR_ADDONS, true, false);
    $installed_addons = db_get_hash_array("SELECT a.addon, a.status, d.description as name, b.description, LENGTH(a.options) as has_options, d.object_id, d.object_type FROM ?:addons as a LEFT JOIN ?:addon_descriptions as d ON d.addon = a.addon AND d.object_id = '' AND d.object_type = 'A' AND d.lang_code = ?s LEFT JOIN ?:addon_descriptions as b ON b.addon = a.addon AND b.object_id = '' AND b.object_type = 'D' AND b.lang_code = ?s ORDER BY d.description ASC", 'addon', CART_LANGUAGE, CART_LANGUAGE);
    fn_update_lang_objects('installed_addons', $installed_addons);
    $addons_list = array();
    foreach ($all_addons as $addon) {
        if (!empty($installed_addons[$addon])) {
            $addons_list[$addon] = $installed_addons[$addon];
        } else {
            if (file_exists(DIR_ADDONS . $addon . '/addon.xml')) {
                $xml = simplexml_load_file(DIR_ADDONS . $addon . '/addon.xml');
                $addons_list[$addon] = array('status' => 'N', 'name' => (string) $xml->name);
            }
        }
    }
    $view->assign('addons_list', fn_sort_array_by_key($addons_list, 'name', SORT_ASC));
}
/**
Exemplo n.º 24
0
function fn_get_groups($links_to = array('C', 'P', 'U'), $is_avail = false, $page = 1, $lang_code = CART_LANGUAGE)
{
    $condition = '';
    if (!empty($links_to)) {
        $condition .= db_quote(" AND ?:aff_groups.link_to IN (?a)", $links_to);
    }
    if (!empty($is_avail)) {
        $condition .= " AND ?:status = 'A'";
    }
    $limit = '';
    if (!empty($page)) {
        $total_items = db_get_field("SELECT COUNT(*) FROM ?:aff_groups LEFT JOIN ?:aff_group_descriptions ON ?:aff_group_descriptions.group_id = ?:aff_groups.group_id AND ?:aff_group_descriptions.lang_code = ?s WHERE 1 ?p ORDER BY ?:aff_group_descriptions.name", $lang_code, $condition);
        if (!empty($total_items)) {
            $items_per_page = AREA == 'A' ? Registry::get('settings.Appearance.admin_elements_per_page') : Registry::get('settings.Appearance.elements_per_page');
            $limit = fn_paginate($page, $total_items, $items_per_page);
        }
    }
    $groups = db_get_hash_array("SELECT * FROM ?:aff_groups LEFT JOIN ?:aff_group_descriptions ON ?:aff_group_descriptions.group_id = ?:aff_groups.group_id AND ?:aff_group_descriptions.lang_code = ?s WHERE 1 ?p ORDER BY ?:aff_group_descriptions.name {$limit}", 'group_id', $lang_code, $condition);
    if (!empty($groups) && is_array($groups)) {
        foreach ($groups as $group_id => $group_data) {
            $groups[$group_id] = fn_convert_group_data($group_data);
        }
    }
    return !empty($groups) ? $groups : false;
}
Exemplo n.º 25
0
 /**
  * Creates database and imports dump there
  * @param  string  $db_name db name
  * @return boolean true on success, false - otherwise
  */
 public static function createDb($db_name = '')
 {
     $snapshot_dir = Registry::get('config.dir.snapshots');
     $dbdump_filename = empty($db_name) ? 'cmp_current.sql' : 'cmp_release.sql';
     if (!fn_mkdir($snapshot_dir)) {
         fn_set_notification('E', __('error'), __('text_cannot_create_directory', array('[directory]' => fn_get_rel_dir($snapshot_dir))));
         return false;
     }
     $dump_file = $snapshot_dir . $dbdump_filename;
     if (is_file($dump_file)) {
         if (!is_writable($dump_file)) {
             fn_set_notification('E', __('error'), __('dump_file_not_writable'));
             return false;
         }
     }
     $fd = @fopen($snapshot_dir . $dbdump_filename, 'w');
     if (!$fd) {
         fn_set_notification('E', __('error'), __('dump_cant_create_file'));
         return false;
     }
     if (!empty($db_name)) {
         Database::changeDb($db_name);
     }
     // set export format
     db_query("SET @SQL_MODE = 'MYSQL323'");
     fn_start_scroller();
     $create_statements = array();
     $insert_statements = array();
     $status_data = db_get_array("SHOW TABLE STATUS");
     $dbdump_tables = array();
     foreach ($status_data as $k => $v) {
         $dbdump_tables[] = $v['Name'];
     }
     // get status data
     $t_status = db_get_hash_array("SHOW TABLE STATUS", 'Name');
     foreach ($dbdump_tables as $k => $table) {
         fn_echo('<br />' . __('backupping_data') . ': <b>' . $table . '</b>&nbsp;&nbsp;');
         $total_rows = db_get_field("SELECT COUNT(*) FROM {$table}");
         $index = db_get_array("SHOW INDEX FROM {$table}");
         $order_by = array();
         foreach ($index as $kk => $vv) {
             if ($vv['Key_name'] == 'PRIMARY') {
                 $order_by[] = '`' . $vv['Column_name'] . '`';
             }
         }
         if (!empty($order_by)) {
             $order_by = 'ORDER BY ' . implode(',', $order_by);
         } else {
             $order_by = '';
         }
         // Define iterator
         if (!empty($t_status[$table]) && $t_status[$table]['Avg_row_length'] < DB_MAX_ROW_SIZE) {
             $it = DB_ROWS_PER_PASS;
         } else {
             $it = 1;
         }
         for ($i = 0; $i < $total_rows; $i = $i + $it) {
             $table_data = db_get_array("SELECT * FROM {$table} {$order_by} LIMIT {$i}, {$it}");
             foreach ($table_data as $_tdata) {
                 $_tdata = fn_add_slashes($_tdata, true);
                 $values = array();
                 foreach ($_tdata as $v) {
                     $values[] = $v !== null ? "'{$v}'" : 'NULL';
                 }
                 fwrite($fd, "INSERT INTO {$table} (`" . implode('`, `', array_keys($_tdata)) . "`) VALUES (" . implode(', ', $values) . ");\n");
             }
             fn_echo(' .');
         }
     }
     fn_stop_scroller();
     if (!empty($db_name)) {
         Settings::instance()->reloadSections();
     }
     if (fn_allowed_for('ULTIMATE')) {
         $companies = fn_get_short_companies();
         asort($companies);
         $settings['company_root'] = Settings::instance()->getList();
         foreach ($companies as $k => $v) {
             $settings['company_' . $k] = Settings::instance()->getList(0, 0, false, $k);
         }
     } else {
         $settings['company_root'] = Settings::instance()->getList();
     }
     if (!empty($db_name)) {
         Database::changeDb(Registry::get('config.db_name'));
     }
     $settings = self::processSettings($settings, '');
     $settings = self::formatSettings($settings['data']);
     ksort($settings);
     $data = print_r($settings, true);
     fwrite($fd, $data);
     fclose($fd);
     @chmod($snapshot_dir . $dbdump_filename, DEFAULT_FILE_PERMISSIONS);
     return true;
 }
Exemplo n.º 26
0
 public static function getOrdersAsApiList($orders, $lang_code)
 {
     $order_ids = array();
     foreach ($orders as $order) {
         $order_ids[] = $order['order_id'];
     }
     if (!empty($order_ids)) {
         $payment_names = db_get_hash_array("SELECT order_id, payment\n                 FROM ?:orders, ?:payment_descriptions\n                 WHERE ?:payment_descriptions.payment_id = ?:orders.payment_id\n                 AND ?:payment_descriptions.lang_code = ?s\n                 AND ?:orders.order_id IN (?a)", 'order_id', $lang_code, $order_ids);
         $shippings = db_get_hash_array("SELECT order_id, data\n                 FROM ?:order_data\n                 WHERE type = ?s\n                 AND order_id IN (?a)", 'order_id', 'L', $order_ids);
     } else {
         $payment_names = array();
         $shippings = array();
     }
     foreach ($orders as $k => $v) {
         $orders[$k]['payment'] = !empty($payment_names[$v['order_id']]['payment']) ? $payment_names[$v['order_id']]['payment'] : '';
         $orders[$k]['shippings'] = array();
         if (!empty($shippings[$v['order_id']]['data'])) {
             $shippings = unserialize($shippings[$v['order_id']]['data']);
             if (empty($shippings)) {
                 continue;
             }
             foreach ($shippings as $shipping) {
                 $orders[$k]['shippings'][] = array('carrier' => !empty($shipping['carrier']) ? $shipping['carrier'] : '', 'shipping' => !empty($shipping['shipping']) ? $shipping['shipping'] : '');
             }
         }
     }
     $fields = array('order_id', 'user_id', 'total', 'timestamp', 'status', 'date', 'status_info', 'firstname', 'lastname', 'email', 'payment_name', 'shippings');
     return Api::getAsList('orders', $orders, $fields);
 }
Exemplo n.º 27
0
function fn_clone_image_pairs($target_object_id, $object_id, $object_type, $lang_code = CART_LANGUAGE)
{
    // Get all pairs
    $pair_data = db_get_hash_array("SELECT pair_id, image_id, detailed_id, type FROM ?:images_links WHERE object_id = ?i AND object_type = ?s", 'pair_id', $object_id, $object_type);
    if (empty($pair_data)) {
        return false;
    }
    $icons = $detailed = $pairs_data = array();
    foreach ($pair_data as $pair_id => $p_data) {
        if (!empty($p_data['image_id'])) {
            $icons[$pair_id] = fn_get_image($p_data['image_id'], $object_type, $lang_code, true);
            if (!empty($icons[$pair_id])) {
                $p_data['image_alt'] = empty($icons[$pair_id]['alt']) ? '' : $icons[$pair_id]['alt'];
                $tmp_name = fn_create_temp_file();
                Storage::instance('images')->export($icons[$pair_id]['relative_path'], $tmp_name);
                $name = fn_basename($icons[$pair_id]['image_path']);
                $icons[$pair_id] = array('path' => $tmp_name, 'size' => filesize($tmp_name), 'error' => 0, 'name' => $name);
            }
        }
        if (!empty($p_data['detailed_id'])) {
            $detailed[$pair_id] = fn_get_image($p_data['detailed_id'], 'detailed', $lang_code, true);
            if (!empty($detailed[$pair_id])) {
                $p_data['detailed_alt'] = empty($detailed[$pair_id]['alt']) ? '' : $detailed[$pair_id]['alt'];
                $tmp_name = fn_create_temp_file();
                Storage::instance('images')->export($detailed[$pair_id]['relative_path'], $tmp_name);
                $name = fn_basename($detailed[$pair_id]['image_path']);
                $detailed[$pair_id] = array('path' => $tmp_name, 'size' => filesize($tmp_name), 'error' => 0, 'name' => $name);
            }
        }
        $pairs_data = array($pair_id => array('type' => $p_data['type'], 'image_alt' => !empty($p_data['image_alt']) ? $p_data['image_alt'] : '', 'detailed_alt' => !empty($p_data['detailed_alt']) ? $p_data['detailed_alt'] : ''));
        fn_update_image_pairs($icons, $detailed, $pairs_data, $target_object_id, $object_type, array(), true, $lang_code);
    }
}
Exemplo n.º 28
0
 if (!empty($_REQUEST['returns'])) {
     $order_id = intval($_REQUEST['order_id']);
     $oder_lang_code = db_get_field("SELECT lang_code FROM ?:orders WHERE order_id = ?i", $order_id);
     $returns = (array) $_REQUEST['returns'];
     $user_id = intval($_REQUEST['user_id']);
     $action = $_REQUEST['action'];
     $comment = $_REQUEST['comment'];
     $total_amount = 0;
     foreach ($returns as $k => $v) {
         if (isset($v['chosen']) && $v['chosen'] == 'Y') {
             $total_amount += $v['amount'];
         }
     }
     $_data = array('order_id' => $order_id, 'user_id' => $user_id, 'action' => $action, 'timestamp' => TIME, 'status' => RMA_DEFAULT_STATUS, 'total_amount' => $total_amount, 'comment' => $comment);
     $return_id = db_query('INSERT INTO ?:rma_returns ?e', $_data);
     $order_items = db_get_hash_array("SELECT item_id, order_id, extra, price, amount FROM ?:order_details WHERE order_id = ?i", 'item_id', $order_id);
     foreach ($returns as $item_id => $v) {
         if (isset($v['chosen']) && $v['chosen'] == 'Y') {
             if (true == fn_rma_declined_product_correction($order_id, $k, $v['available_amount'], $v['amount'])) {
                 $_item = $order_items[$item_id];
                 $extra = @unserialize($_item['extra']);
                 $_data = array('return_id' => $return_id, 'item_id' => $item_id, 'product_id' => $v['product_id'], 'reason' => !empty($v['reason']) ? $v['reason'] : '', 'amount' => $v['amount'], 'product_options' => !empty($extra['product_options_value']) ? serialize($extra['product_options_value']) : '', 'price' => fn_format_price((!isset($extra['exclude_from_calculate']) ? $_item['price'] : 0) * $_item['amount'] / $_item['amount']), 'product' => !empty($extra['product']) ? $extra['product'] : fn_get_product_name($v['product_id'], $oder_lang_code));
                 db_query('INSERT INTO ?:rma_return_products ?e', $_data);
                 if (!isset($extra['returns'])) {
                     $extra['returns'] = array();
                 }
                 $extra['returns'][$return_id] = array('amount' => $v['amount'], 'status' => RMA_DEFAULT_STATUS);
                 db_query('UPDATE ?:order_details SET ?u WHERE item_id = ?i AND order_id = ?i', array('extra' => serialize($extra)), $item_id, $order_id);
             }
         }
     }
Exemplo n.º 29
0
function fn_rma_recalculate_order($order_id, $recalculate_type, $return_id, $is_refund, $ex_data)
{
    if (empty($recalculate_type) || empty($return_id) || empty($order_id) || !is_array($ex_data) || $recalculate_type == 'M' && !isset($ex_data['total'])) {
        return false;
    }
    $order = db_get_row("SELECT total, subtotal, discount, shipping_cost, status FROM ?:orders WHERE order_id = ?i", $order_id);
    $order_items = db_get_hash_array("SELECT * FROM ?:order_details WHERE ?:order_details.order_id = ?i", 'item_id', $order_id);
    $additional_data = db_get_hash_single_array("SELECT type, data FROM ?:order_data WHERE order_id = ?i", array('type', 'data'), $order_id);
    $order_return_info = @unserialize(@$additional_data[ORDER_DATA_RETURN]);
    $order_tax_info = @unserialize(@$additional_data['T']);
    $status_order = $order['status'];
    unset($order['status']);
    if ($recalculate_type == 'R') {
        $product_groups = @unserialize(@$additional_data['G']);
        if ($is_refund == 'Y') {
            $sign = $ex_data['inventory_to'] == 'I' ? -1 : 1;
            // What for is this section ???
            if (!empty($order_return_info['returned_products'])) {
                foreach ($order_return_info['returned_products'] as $item_id => $item) {
                    if (isset($item['extra']['returns'][$return_id])) {
                        $r_item = $o_item = $item;
                        unset($r_item['extra']['returns'][$return_id]);
                        $r_item['amount'] = $item['amount'] - $item['extra']['returns'][$return_id]['amount'];
                        fn_rma_recalculate_order_routine($order, $r_item, $item, 'O-', $ex_data);
                        if (empty($r_item['amount'])) {
                            unset($order_return_info['returned_products'][$item_id]);
                        } else {
                            $order_return_info['returned_products'][$item_id] = $r_item;
                        }
                        $o_item['primordial_amount'] = (isset($order_items[$item_id]) ? $order_items[$item_id]['amount'] : 0) + $item['extra']['returns'][$return_id]['amount'];
                        $o_item['primordial_discount'] = @$o_item['extra']['discount'];
                        fn_rma_recalculate_order_routine($order, $o_item, $item, 'M+', $ex_data);
                        $o_item['amount'] = (isset($order_items[$item_id]) ? $order_items[$item_id]['amount'] : 0) + $item['extra']['returns'][$return_id]['amount'];
                        if (isset($order_items[$item_id]['extra'])) {
                            $o_item['extra'] = @unserialize($order_items[$item_id]['extra']);
                        }
                        $o_item['extra']['returns'][$return_id] = $item['extra']['returns'][$return_id];
                        $o_item['extra'] = serialize($o_item['extra']);
                        if (!isset($order_items[$item_id])) {
                            db_query("REPLACE INTO ?:order_details ?e", $o_item);
                        } else {
                            db_query("UPDATE ?:order_details SET ?u WHERE item_id = ?i AND order_id = ?i", $o_item, $item_id, $order_id);
                        }
                    }
                }
            }
            // Check all the products and update their amount and cost.
            foreach ($order_items as $item_id => $item) {
                $item['extra'] = @unserialize($item['extra']);
                if (isset($item['extra']['returns'][$return_id])) {
                    $o_item = $item;
                    $o_item['amount'] = $o_item['amount'] + $sign * $item['extra']['returns'][$return_id]['amount'];
                    unset($o_item['extra']['returns'][$return_id]);
                    if (empty($o_item['extra']['returns'])) {
                        unset($o_item['extra']['returns']);
                    }
                    fn_rma_recalculate_order_routine($order, $o_item, $item, '', $ex_data);
                    if (empty($o_item['amount'])) {
                        db_query("DELETE FROM ?:order_details WHERE item_id = ?i AND order_id = ?i", $item_id, $order_id);
                    } else {
                        $o_item['extra'] = serialize($o_item['extra']);
                        db_query("UPDATE ?:order_details SET ?u WHERE item_id = ?i AND order_id = ?i", $o_item, $item_id, $order_id);
                    }
                    if (!isset($order_return_info['returned_products'][$item_id])) {
                        $r_item = $item;
                        unset($r_item['extra']['returns']);
                        $r_item['amount'] = $item['extra']['returns'][$return_id]['amount'];
                    } else {
                        $r_item = $order_return_info['returned_products'][$item_id];
                        $r_item['amount'] = $r_item['amount'] + $item['extra']['returns'][$return_id]['amount'];
                    }
                    fn_rma_recalculate_order_routine($order, $r_item, $item, 'M-O+', $ex_data);
                    $r_item['extra']['returns'][$return_id] = $item['extra']['returns'][$return_id];
                    $order_return_info['returned_products'][$item_id] = $r_item;
                    fn_rma_update_order_taxes($order_tax_info, $item_id, $item['amount'], $o_item['amount'], $order);
                }
            }
            $_ori_data = array('order_id' => $order_id, 'type' => ORDER_DATA_RETURN, 'data' => $order_return_info);
        }
        $shipping_info = array();
        if ($product_groups) {
            $_total = 0;
            foreach ($product_groups as $key_group => $group) {
                if (isset($group['chosen_shippings'])) {
                    foreach ($group['chosen_shippings'] as $key_shipping => $shipping) {
                        $_total += $shipping['rate'];
                    }
                }
            }
            foreach ($product_groups as $key_group => $group) {
                if (isset($group['chosen_shippings'])) {
                    foreach ((array) $ex_data['shipping_costs'] as $shipping_id => $cost) {
                        foreach ($group['chosen_shippings'] as $key_shipping => $shipping) {
                            $shipping_id = $shipping['shipping_id'];
                            $product_groups[$key_group]['chosen_shippings'][$key_shipping]['rate'] = fn_format_price($_total ? $shipping['rate'] / $_total * $cost : $cost / count($product_groups));
                            $product_groups[$key_group]['shippings'][$shipping_id]['rate'] = fn_format_price($_total ? $shipping['rate'] / $_total * $cost : $cost / count($product_groups));
                            if (empty($shipping_info[$shipping_id])) {
                                $shipping_info[$shipping_id] = $product_groups[$key_group]['shippings'][$shipping_id];
                            }
                            $shipping_info[$shipping_id]['rates'][$key_group] = $product_groups[$key_group]['shippings'][$shipping_id]['rate'];
                        }
                    }
                }
            }
            db_query("UPDATE ?:order_data SET ?u WHERE order_id = ?i AND type = 'G'", array('data' => serialize($product_groups)), $order_id);
            fn_update_shipping_taxes($order_tax_info, $shipping_info, $order);
        }
        $order['total'] -= $order['shipping_cost'];
        $order['shipping_cost'] = isset($ex_data['shipping_costs']) ? array_sum($ex_data['shipping_costs']) : $order['shipping_cost'];
        $order['total'] += $order['shipping_cost'];
        $order['total'] = $order['total'] < 0 ? 0 : $order['total'];
        if (!empty($order_tax_info)) {
            db_query("UPDATE ?:order_data SET ?u WHERE order_id = ?i AND type = 'T'", array('data' => serialize($order_tax_info)), $order_id);
        }
    } elseif ($recalculate_type == 'M') {
        $order['total'] = $order['total'] + $ex_data['total'];
        $_ori_data = array('order_id' => $order_id, 'type' => ORDER_DATA_RETURN, 'data' => array('return' => fn_format_price((isset($order_return_info['return']) ? $order_return_info['return'] : 0) - $ex_data['total']), 'returned_products' => isset($order_return_info['returned_products']) ? $order_return_info['returned_products'] : ''));
        $return_products = db_get_hash_array("SELECT * FROM ?:rma_return_products WHERE return_id = ?i AND type = ?s", 'item_id', $return_id, RETURN_PRODUCT_ACCEPTED);
        foreach ((array) $return_products as $item_id => $v) {
            $v['extra']['product_options'] = @unserialize($v['extra']['product_options']);
            if ($ex_data['inventory_to'] == 'D' || $ex_data['status_to'] == RMA_DEFAULT_STATUS) {
                fn_update_product_amount($v['product_id'], $v['amount'], @$v['extra']['product_options'], '-');
            } elseif ($ex_data['inventory_to'] == 'I') {
                fn_update_product_amount($v['product_id'], $v['amount'], $v['extra']['product_options'], '+');
            }
        }
    }
    if ($is_refund == 'Y') {
        if (isset($_ori_data['data']['return']) && floatval($_ori_data['data']['return']) == 0) {
            unset($_ori_data['data']['return']);
        }
        if (empty($_ori_data['data']['returned_products'])) {
            unset($_ori_data['data']['returned_products']);
        }
        if (!empty($_ori_data['data'])) {
            $_ori_data['data'] = serialize($_ori_data['data']);
            db_query("REPLACE INTO ?:order_data ?e", $_ori_data);
        } else {
            db_query("DELETE FROM ?:order_data WHERE order_id = ?i AND type = ?s", $order_id, ORDER_DATA_RETURN);
        }
    }
    foreach ($order as $k => $v) {
        $order[$k] = fn_format_price($v);
    }
    db_query("UPDATE ?:orders SET ?u WHERE order_id = ?i", $order, $order_id);
    if (fn_allowed_for('MULTIVENDOR')) {
        $_SESSION['cart'] = isset($_SESSION['cart']) ? $_SESSION['cart'] : array();
        $cart =& $_SESSION['cart'];
        $action = 'save';
        fn_mve_place_order($order_id, $action, $status_order, $cart);
    }
}
Exemplo n.º 30
0
 public static function getOriginalValues($context)
 {
     return db_get_hash_array('SELECT * FROM ?:original_values WHERE msgctxt LIKE ?l', 'msgctxt', $context . ':%');
 }