示例#1
0
function fn_get_seo_rules($params = array(), $items_per_page = 0, $lang_code = DESCR_SL)
{
    $condition = fn_get_seo_company_condition('?:seo_names.company_id');
    $lang_code = fn_get_corrected_seo_lang_code($lang_code);
    $global_total = db_get_fields("SELECT dispatch FROM ?:seo_names WHERE object_id = '0' AND type = 's' ?p GROUP BY dispatch", $condition);
    $local_total = db_get_fields("SELECT dispatch FROM ?:seo_names WHERE object_id = '0' AND type = 's' AND lang_code = ?s ?p", $lang_code, $condition);
    if ($diff = array_diff($global_total, $local_total)) {
        foreach ($diff as $disp) {
            fn_create_seo_name(0, 's', str_replace('.', '-', $disp), 0, $disp, '', DESCR_SL);
        }
    }
    // Init filter
    $params = LastView::instance()->update('seo_rules', $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    if (isset($params['name']) && fn_string_not_empty($params['name'])) {
        $condition .= db_quote(" AND name LIKE ?l", "%" . trim($params['name']) . "%");
    }
    if (isset($params['rule_params']) && fn_string_not_empty($params['rule_params'])) {
        $condition .= db_quote(" AND dispatch LIKE ?l", "%" . trim($params['rule_params']) . "%");
    }
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:seo_names WHERE object_id = '0' AND type = 's' AND lang_code = ?s ?p", $lang_code, $condition);
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $seo_data = db_get_array("SELECT name, dispatch FROM ?:seo_names WHERE object_id = '0' AND type = 's' AND lang_code = ?s ?p ORDER BY dispatch {$limit}", $lang_code, $condition);
    return array($seo_data, $params);
}
示例#2
0
文件: func.php 项目: askzap/ultimate
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);
}
示例#3
0
function fn_rus_sdek_get_status($params = array(), $items_per_page = 0)
{
    $condition = '';
    $_view = 'sdek_status';
    $params = LastView::instance()->update($_view, $params);
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    if (!empty($params['time_from'])) {
        $condition = db_quote(" WHERE timestamp >= ?i ", strtotime($params['time_from']));
        if (!empty($params['time_to'])) {
            $condition .= db_quote(" AND timestamp < ?i ", strtotime($params['time_to']));
        }
    }
    $join = db_quote(" LEFT JOIN ?:rus_cities_sdek as b ON a.city_code = b.city_code ");
    $join .= db_quote(" LEFT JOIN ?:rus_city_sdek_descriptions as c ON b.city_id = c.city_id ");
    $sort_by = !empty($params['sort_by']) ? $params['sort_by'] : 'order_id';
    $sort = 'asc';
    if (!empty($params['sort_order'])) {
        $sort = $params['sort_order'];
        $params['sort_order'] = $params['sort_order'] == 'asc' ? 'desc' : 'asc';
        $params['sort_order_rev'] = $params['sort_order'];
    } else {
        $params['sort_order'] = 'asc';
        $params['sort_order_rev'] = 'asc';
    }
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:rus_sdek_status ?p", $condition);
        $limit = db_paginate($params['page'], $params['items_per_page']);
    }
    $data_status = db_get_array("SELECT a.*, c.city FROM ?:rus_sdek_status as a ?p ?p ORDER BY ?p {$sort} {$limit}", $join, $condition, $sort_by);
    return array($data_status, $params);
}
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);
}
示例#5
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);
}
示例#6
0
function fn_get_discussions($params, $items_per_page)
{
    // Init filter
    $params = LastView::instance()->update('discussion', $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    // Define fields that should be retrieved
    $fields = array('?:discussion_posts.*', '?:discussion_messages.message', '?:discussion_rating.rating_value', '?:discussion.*');
    // Define sort fields
    $sortings = array('object' => "?:discussion.object_type", 'name' => "?:discussion_posts.name", 'ip_address' => "?:discussion_posts.ip_address", 'timestamp' => "?:discussion_posts.timestamp", 'status' => "?:discussion_posts.status", 'date' => "?:orders.timestamp", 'total' => "?:orders.total");
    $sorting = db_sort($params, $sortings, 'timestamp', 'desc');
    $condition = $join = '';
    if (isset($params['name']) && fn_string_not_empty($params['name'])) {
        $condition .= db_quote(" AND ?:discussion_posts.name LIKE ?l", "%" . trim($params['name']) . "%");
    }
    if (isset($params['message']) && fn_string_not_empty($params['message'])) {
        $condition .= db_quote(" AND ?:discussion_messages.message LIKE ?l", "%" . trim($params['message']) . "%");
    }
    if (!empty($params['type'])) {
        $condition .= db_quote(" AND ?:discussion.type = ?s", $params['type']);
    }
    if (!empty($params['status'])) {
        $condition .= db_quote(" AND ?:discussion_posts.status = ?s", $params['status']);
    }
    if (!empty($params['post_id'])) {
        $condition .= db_quote(" AND ?:discussion_posts.post_id = ?i", $params['post_id']);
    }
    if (isset($params['ip_address']) && fn_string_not_empty($params['ip_address'])) {
        $condition .= db_quote(" AND ?:discussion_posts.ip_address = ?s", fn_ip_to_db(trim($params['ip_address'])));
    }
    if (!empty($params['rating_value'])) {
        $condition .= db_quote(" AND ?:discussion_rating.rating_value = ?i", $params['rating_value']);
    }
    if (!empty($params['object_type'])) {
        $condition .= db_quote(" AND ?:discussion.object_type = ?s", $params['object_type']);
    }
    $condition .= fn_get_discussion_company_condition('?:discussion.company_id');
    if (!empty($params['period']) && $params['period'] != 'A') {
        list($params['time_from'], $params['time_to']) = fn_create_periods($params);
        $condition .= db_quote(" AND (?:discussion_posts.timestamp >= ?i AND ?:discussion_posts.timestamp <= ?i)", $params['time_from'], $params['time_to']);
    }
    $join .= " INNER JOIN ?:discussion ON ?:discussion.thread_id = ?:discussion_posts.thread_id";
    $join .= " INNER JOIN ?:discussion_messages ON ?:discussion_messages.post_id = ?:discussion_posts.post_id";
    $join .= " INNER JOIN ?:discussion_rating ON ?:discussion_rating.post_id = ?:discussion_posts.post_id";
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:discussion_posts {$join} WHERE 1 {$condition}");
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $posts = db_get_array("SELECT " . implode(',', $fields) . " FROM ?:discussion_posts {$join} WHERE 1 {$condition} {$sorting} {$limit}");
    foreach ($posts as $k => $post) {
        if (isset($post['ip_address'])) {
            $posts[$k]['ip_address'] = fn_ip_from_db($post['ip_address']);
        }
    }
    return array($posts, $params);
}
示例#7
0
function fn_get_spsr_address($params, $items_per_page, $addr_list)
{
    $params = LastView::instance()->update('address', $params);
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = count($addr_list);
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $limit = str_replace("LIMIT ", "", $limit);
    $offset = explode(",", $limit);
    if (!empty($addr_list)) {
        $addr_list = array_slice($addr_list, (int) $offset[0], (int) $offset[1]);
    }
    return array($addr_list, $params);
}
示例#8
0
function fn_get_feedbacks($params, $items_per_page, $lang_code = CART_LANGUAGE)
{
    $params = LastView::instance()->update('feedbacks', $params);
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    $fields = array("?:orders_feedback.feedback_id", "?:orders_feedback.statuses", "?:orders_feedback.subject", "?:orders_feedback.remind_in", "?:orders_feedback.status", "?:orders_feedback.lang_code");
    $sortings = array('feedback_id' => "?:orders_feedback.feedback_id", 'subject' => "?:orders_feedback.subject", 'statuses' => "?:orders_feedback.statuses", 'remind_in' => "?:orders_feedback.remind_in");
    $condition = $_condition = $join = $group = '';
    /*conditions*/
    $condition .= db_quote(' AND lang_code = ?s', $lang_code);
    /*conditions*/
    $sorting = db_sort($params, $sortings, 'feedback_id', 'desc');
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(?:orders_feedback.feedback_id) FROM ?:orders_feedback {$join} WHERE 1 {$condition}");
        $limit = db_paginate($params['page'], $params['items_per_page']);
    }
    $feedbacks = db_get_array('SELECT ' . implode(', ', $fields) . " FROM ?:orders_feedback {$join} WHERE 1 {$condition} {$group} {$sorting} {$limit}");
    LastView::instance()->processResults('feedbacks', $feedbacks, $params);
    return array($feedbacks, $params);
}
示例#9
0
/**
 * Gets addons list
 *
 * @param array $params search params
 * @param int $items_per_page items per page for pagination
 * @param string $lang_code language code
 * @return array addons list and filtered search params
 */
function fn_get_addons($params, $items_per_page = 0, $lang_code = CART_LANGUAGE)
{
    $params = LastView::instance()->update('addons', $params);
    $default_params = array('type' => 'any');
    $params = array_merge($default_params, $params);
    $addons = array();
    $sections = Settings::instance()->getAddons();
    $all_addons = fn_get_dir_contents(Registry::get('config.dir.addons'), true, false);
    $installed_addons = db_get_hash_array('SELECT a.addon, a.status, b.name as name, b.description as description, a.separate, a.unmanaged, a.has_icon ' . 'FROM ?:addons as a LEFT JOIN ?:addon_descriptions as b ON b.addon = a.addon AND b.lang_code = ?s' . 'ORDER BY b.name ASC', 'addon', $lang_code);
    foreach ($installed_addons as $key => $addon) {
        $installed_addons[$key]['has_sections'] = Settings::instance()->sectionExists($sections, $addon['addon']);
        $installed_addons[$key]['has_options'] = $installed_addons[$key]['has_sections'] ? Settings::instance()->optionsExists($addon['addon'], 'ADDON') : false;
        // Check add-on snaphot
        if (!fn_check_addon_snapshot($key)) {
            $installed_addons[$key]['status'] = 'D';
            $installed_addons[$key]['snapshot_correct'] = false;
        } else {
            $installed_addons[$key]['snapshot_correct'] = true;
        }
    }
    foreach ($all_addons as $addon) {
        $addon_scheme = SchemesManager::getScheme($addon);
        if (in_array($params['type'], array('any', 'installed', 'active', 'disabled'))) {
            $search_status = $params['type'] == 'active' ? 'A' : ($params['type'] == 'disabled' ? 'D' : '');
            if (!empty($installed_addons[$addon])) {
                // exclude unmanaged addons from the list
                if ($installed_addons[$addon]['unmanaged'] == true) {
                    continue;
                }
                if (!empty($search_status) && $installed_addons[$addon]['status'] != $search_status) {
                    continue;
                }
                $addons[$addon] = $installed_addons[$addon];
                if ($addon_scheme != false && !$addon_scheme->getUnmanaged()) {
                    $addons[$addon]['originals'] = $addon_scheme->getOriginals();
                }
                fn_update_lang_objects('installed_addon', $addons[$addon]);
                // Generate custom description
                $func = 'fn_addon_dynamic_description_' . $addon;
                if (function_exists($func)) {
                    $addons[$addon]['description'] = $func($addons[$addon]['description']);
                }
            }
        }
        if (empty($installed_addons[$addon]) && empty($params['for_company']) && in_array($params['type'], array('any', 'not_installed'))) {
            if ($addon_scheme != false && !$addon_scheme->getUnmanaged()) {
                $addons[$addon] = array('status' => 'N', 'name' => $addon_scheme->getName(), 'snapshot_correct' => fn_check_addon_snapshot($addon), 'description' => $addon_scheme->getDescription(), 'has_icon' => $addon_scheme->hasIcon());
            }
        }
    }
    if (!empty($params['q'])) {
        foreach ($addons as $addon => $addon_data) {
            if (!preg_match('/' . preg_quote($params['q'], '/') . '/ui', $addon_data['name'], $m)) {
                unset($addons[$addon]);
            }
        }
    }
    $addons = fn_sort_array_by_key($addons, 'name', SORT_ASC);
    return array($addons, $params);
}
示例#10
0
/**
 * Returns list of pages
 * <i>$params</i> - Array of various parameters used for element selection:
 * <ul>
 *      <li>page_id - If defined and not zero, get data for the page with this id; otherwise get data for all pages</li>
 *      <li>item_ids - A comma-delimited page identifiers list; if defined, get data for the pages with these ids; otherwise get data for all pages</li>
 *      <li>except_id - Identifier of the page to be excluded from the result</li>
 *   	<li>parent_id - If defined and not zero, get data for the pages with this parent page id</li>
 *   	<li>active_page_id - Identifier of the page being currently shown</li>
 *   	<li>current_page_id - The same as <i>active_page_id</i></li>
 *
 *   	<li>add_root - If defined, additionally returns root element data</li>
 *  	<li>subpages - If defined, additionally returns subpages</li>
 *  	<li>get_tree - If defined, pages will be returned as tree; otherwise as list. Possible value: <i>plain</i></li>
 *  	<li>visible - For pages tree: show visible branch only</li>
 *
 *  	<li>page - Number of the current page for pagination</li>
 *
 *  	<li>pdescr - If defined, additionally returns descriptions.  Possible value: <i>Y</i></li>
 *
 *   	<li>vendor_pages - If defined, try to return pages for the company defined by <i>company_id</i></li>
 *   	<li>company_id - If <i>vendor_pages</i> is defined: if defined, get data for the company with this id</li>
 *
 *   	<li>neighbours - If defined, try to return neighbor pages for the page with the id <i>neighbours_page_id</i></li>
 *   	<li>neighbours_page_id -  If <i>neighbours</i> is defined: if defined, get neighbor pages for the page with this id</li>
 *
 *   	<li>limit - If defined, used to limit your MySQL query results by this value</li>
 *   	<li>sort_by - Table field to sort by, default is position</li>
 *   	<li>sort_order - Sorting direction, ascending or descending; Possible values: <i>asc</i> or <i>desc</i>, default is <i>asc</i></li>
 *
 *   	<li>status - If defined, returns pages only with this status. Can be comma delimited statuses list</li>
 *
 *  	<li>period - If defined, get pages by time period. Time period is generated by ::fn_create_periods</li>
 *   	<li>time_from - Returns pages created earlier than this time</li>
 *   	<li>time_to - Returns pages created later than this time</li>
 *
 *   	<li>parent_page_id - Deprecated, <i>parent_id</i> used instead</li>
 *   	<li>from_page_id - Deprecated, <i>parent_id</i> used instead</li>
 * </ul>
 * @param array $params Array of params
 * @param int $items_per_page  Limit items per page
 * @param string $lang_code 2-letter language code
 * @return array List of pages, params
 */
function fn_get_pages($params = array(), $items_per_page = 0, $lang_code = CART_LANGUAGE)
{
    /**
     * Changes params for selecting pages
     *
     * @param array  $params         Pages search params
     * @param int    $items_per_page Items per page
     * @param string $lang_code      Two-letter language code (e.g. 'en', 'ru', etc.)
     */
    fn_set_hook('get_pages_pre', $params, $items_per_page, $lang_code);
    $view_type = 'pages';
    if (!empty($params['page_type']) && fn_is_exclusive_page_type($params['page_type'])) {
        $view_type .= '_' . $params['page_type'];
    }
    // Init filter
    $params = LastView::instance()->update($view_type, $params);
    $default_params = array('page_id' => 0, 'page' => 1, 'visible' => false, 'get_tree' => '', 'pdescr' => '', 'subpages' => '', 'match' => '', 'page_type' => '', 'items_per_page' => $items_per_page);
    if (is_array($params)) {
        $params = array_merge($default_params, $params);
    } else {
        $params = $default_params;
    }
    if (empty($params['pname']) && empty($params['pdescr']) && empty($params['subpages'])) {
        $params['pname'] = 'Y';
    }
    $fields = array('?:pages.*');
    if (!empty($params['simple'])) {
        $fields[] = '?:page_descriptions.page';
    } else {
        $fields[] = '?:page_descriptions.*';
    }
    // Define sort fields
    $sortings = array('position' => array('?:pages.position', '?:page_descriptions.page'), 'name' => '?:page_descriptions.page', 'timestamp' => '?:pages.timestamp', 'type' => '?:pages.page_type', 'multi_level' => array('?:pages.parent_id', '?:pages.position', '?:page_descriptions.page'));
    $auth =& $_SESSION['auth'];
    $condition = '1';
    $join = $limit = $group_by = '';
    if (isset($params['q']) && fn_string_not_empty($params['q'])) {
        $params['q'] = trim($params['q']);
        if ($params['match'] == 'any') {
            $pieces = fn_explode(' ', $params['q']);
            $search_type = ' OR ';
        } elseif ($params['match'] == 'all') {
            $pieces = fn_explode(' ', $params['q']);
            $search_type = ' AND ';
        } else {
            $pieces = array($params['q']);
            $search_type = '';
        }
        $_condition = array();
        foreach ($pieces as $piece) {
            if (strlen($piece) == 0) {
                continue;
            }
            $tmp = array();
            if (!empty($params['pname']) && $params['pname'] == 'Y') {
                $tmp[] = db_quote("?:page_descriptions.page LIKE ?l", "%{$piece}%");
                // check search words
            }
            if ($params['pdescr'] == 'Y') {
                $tmp[] = db_quote("?:page_descriptions.description LIKE ?l", "%{$piece}%");
            }
            if (!empty($tmp)) {
                $_condition[] = '(' . implode(' OR ', $tmp) . ')';
            }
        }
        if (!empty($_condition)) {
            $condition .= ' AND (' . implode($search_type, $_condition) . ')';
        }
    }
    $condition .= fn_get_company_condition('?:pages.company_id');
    if (isset($params['parent_id']) && $params['parent_id'] !== '') {
        $p_ids = array();
        if ($params['subpages'] == 'Y') {
            $p_ids = db_get_fields("SELECT a.page_id FROM ?:pages as a LEFT JOIN ?:pages as b ON b.page_id = ?i WHERE a.id_path LIKE CONCAT(b.id_path, '/%')", $params['parent_id']);
        }
        $p_ids[] = $params['parent_id'];
        $condition .= db_quote(" AND ?:pages.parent_id IN (?n)", $p_ids);
    }
    if (isset($params['parent_page_id'])) {
        // set parent id, that was set in block properties
        $params['from_page_id'] = $params['parent_page_id'];
    }
    if (!empty($params['from_page_id'])) {
        $from_id_path = db_get_field("SELECT id_path FROM ?:pages WHERE page_id = ?i", $params['from_page_id']);
        $condition .= db_quote(" AND ?:pages.id_path LIKE ?l", "{$from_id_path}/%");
    }
    if (!empty($params['status'])) {
        $condition .= db_quote(" AND ?:pages.status IN (?a)", $params['status']);
    }
    if (!empty($params['vendor_pages']) && empty($params['company_id'])) {
        return array(array(), $params);
    } elseif (!empty($params['company_id'])) {
        $condition .= db_quote(" AND ?:pages.company_id = ?i", $params['company_id']);
    }
    if (empty($params['full_search'])) {
        $condition .= db_quote(" AND ?:pages.page_type IN (?a)", array_keys(fn_get_page_type_filter($params['page_type'])));
    }
    if (!empty($params['visible'])) {
        // for pages tree: show visible branch only
        $page_ids = array();
        if (!empty($params['current_page_id'])) {
            $cur_id_path = db_get_field("SELECT id_path FROM ?:pages WHERE page_id = ?i", $params['current_page_id']);
            if (!empty($cur_id_path)) {
                $page_ids = explode('/', $cur_id_path);
            }
        }
        if (!empty($from_id_path)) {
            $_page_ids = explode('/', $from_id_path);
            $page_ids = array_merge($page_ids, $_page_ids);
            $page_ids = array_unique($page_ids);
        }
        $page_ids[] = $params['page_id'];
        $condition .= db_quote(" AND ?:pages.parent_id IN (?n)", $page_ids);
    }
    if (!empty($params['period']) && $params['period'] != 'A') {
        list($params['time_from'], $params['time_to']) = fn_create_periods($params);
        $condition .= db_quote(" AND (?:pages.timestamp >= ?i AND ?:pages.timestamp <= ?i)", $params['time_from'], $params['time_to']);
    }
    if (!empty($params['item_ids'])) {
        // get only defined pages
        $condition .= db_quote(" AND ?:pages.page_id IN (?n)", explode(',', $params['item_ids']));
    }
    if (!empty($params['except_id']) && (empty($params['item_ids']) || !empty($params['item_ids']) && !in_array($params['except_id'], explode(',', $params['item_ids'])))) {
        $condition .= db_quote(' AND ?:pages.page_id != ?i AND ?:pages.parent_id != ?i', $params['except_id'], $params['except_id']);
    }
    if (AREA != 'A') {
        $condition .= " AND (" . fn_find_array_in_set($auth['usergroup_ids'], '?:pages.usergroup_ids', true) . ")";
        $condition .= fn_get_localizations_condition('?:pages.localization', true);
        $condition .= db_quote(" AND (use_avail_period = ?s OR (use_avail_period = ?s AND avail_from_timestamp <= ?i AND avail_till_timestamp >= ?i))", 'N', 'Y', TIME, TIME);
    }
    $join = db_quote('LEFT JOIN ?:page_descriptions ON ?:pages.page_id = ?:page_descriptions.page_id AND ?:page_descriptions.lang_code = ?s', $lang_code);
    if (!empty($params['limit'])) {
        $limit = db_quote(" LIMIT 0, ?i", $params['limit']);
    }
    if (!empty($params['neighbours'])) {
        $parent_ids = array();
        if (!empty($params['neighbours_page_id'])) {
            $id_path = db_get_field("SELECT id_path FROM ?:pages WHERE page_id = ?i", $params['neighbours_page_id']);
            $parent_ids = explode('/', $id_path);
            if (count($parent_ids) == 1) {
                array_unshift($parent_ids, 0);
            }
            $params['root_id'] = $parent_ids[0];
        } else {
            $parent_ids[] = 0;
        }
        $condition .= db_quote(" AND ?:pages.parent_id IN (?n)", array_unique($parent_ids));
    }
    fn_set_hook('get_pages', $params, $join, $condition, $fields, $group_by, $sortings, $lang_code);
    if (!empty($params['get_tree'])) {
        $params['sort_by'] = 'multi_level';
    }
    $sorting = db_sort($params, $sortings, 'position', 'asc');
    if (!empty($group_by)) {
        $group_by = ' GROUP BY ' . $group_by;
    }
    // Get search conditions
    if (!empty($params['get_conditions'])) {
        return array($fields, $join, $condition);
    }
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(DISTINCT(?:pages.page_id)) FROM ?:pages ?p WHERE ?p ?p ?p", $join, $condition, $group_by, $sorting);
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $pages = db_get_hash_array("SELECT " . implode(', ', $fields) . " FROM ?:pages ?p WHERE ?p ?p ?p ?p", 'page_id', $join, $condition, $group_by, $sorting, $limit);
    if (!empty($params['active_page_id']) && !empty($pages[$params['active_page_id']])) {
        $pages[$params['active_page_id']]['active'] = true;
        Registry::set('runtime.active_page_ids', explode('/', $pages[$params['active_page_id']]['id_path']));
    }
    if (!empty($pages)) {
        foreach ($pages as $k => $v) {
            $pages[$k]['level'] = substr_count($v['id_path'], '/');
        }
        if (!empty($params['get_tree'])) {
            $delete_keys = array();
            foreach ($pages as $k => $v) {
                if (!empty($v['parent_id']) && !empty($pages[$v['parent_id']])) {
                    $pages[$v['parent_id']]['subpages'][$v['page_id']] =& $pages[$k];
                    $delete_keys[] = $k;
                }
                if (!empty($v['parent_id']) && (!isset($params['root_id']) && empty($pages[$v['parent_id']]) || isset($params['root_id']) && $v['parent_id'] != $params['root_id']) && (empty($params['from_page_id']) || $params['from_page_id'] != $v['parent_id'])) {
                    // delete pages that don't have parent. FIXME: should be done on database layer
                    $delete_keys[] = $k;
                }
            }
            foreach ($delete_keys as $k) {
                unset($pages[$k]);
            }
        } elseif (!empty($params['item_ids'])) {
            $pages = fn_sort_by_ids($pages, explode(',', $params['item_ids']), 'page_id');
        }
        if ($params['get_tree'] == 'plain') {
            $pages = fn_multi_level_to_plain($pages, 'subpages');
        }
        if (!empty($params['get_children_count'])) {
            $where_condition = !empty($params['except_id']) ? db_quote(' AND page_id != ?i', $params['except_id']) : '';
            if ($params['get_tree'] == 'plain') {
                $_page_ids = array();
                foreach ($pages as $_p) {
                    $_page_ids[] = $_p['page_id'];
                }
            } else {
                $_page_ids = array_keys($pages);
            }
            $children = db_get_hash_single_array("SELECT parent_id, COUNT(page_id) as children FROM ?:pages WHERE parent_id IN (?n) ?p GROUP BY parent_id", array('parent_id', 'children'), $_page_ids, $where_condition);
            if (!empty($children)) {
                if ($params['get_tree'] == 'plain') {
                    foreach ($pages as $_id => $_p) {
                        if (!empty($children[$_p['page_id']])) {
                            $pages[$_id]['has_children'] = true;
                        }
                    }
                } else {
                    foreach ($children as $k => $v) {
                        $pages[$k]['has_children'] = !empty($v);
                    }
                }
            }
        }
    }
    if (!empty($params['add_root'])) {
        array_unshift($pages, array('page_id' => '', 'page' => $params['add_root']));
    }
    fn_dropdown_appearance_cut_second_third_levels($pages, 'subpages', $params);
    fn_set_hook('post_get_pages', $pages, $params, $lang_code);
    LastView::instance()->processResults($view_type, $pages, $params);
    return array($pages, $params);
}
示例#11
0
function fn_get_call_requests($params = array(), $lang_code = CART_LANGUAGE)
{
    // Init filter
    $params = LastView::instance()->update('call_requests', $params);
    $params = array_merge(array('items_per_page' => 0, 'page' => 1), $params);
    $fields = array('r.*', 'o.status as order_status', 'd.product');
    $joins = array(db_quote("LEFT JOIN ?:users u USING(user_id)"), db_quote("LEFT JOIN ?:orders o USING(order_id)"), db_quote("LEFT JOIN ?:product_descriptions d ON d.product_id = r.product_id AND d.lang_code = ?s", $lang_code));
    $sortings = array('id' => 'r.request_id', 'date' => 'r.timestamp', 'status' => 'r.status', 'name' => 'r.name', 'phone' => 'r.phone', 'user_id' => 'r.user_id', 'user' => array('u.lastname', 'u.firstname'), 'order' => 'r.order_id', 'order_status' => 'o.status');
    $condition = array();
    if (isset($params['id']) && fn_string_not_empty($params['id'])) {
        $params['id'] = trim($params['id']);
        $condition[] = db_quote("r.request_id = ?i", $params['id']);
    }
    if (isset($params['name']) && fn_string_not_empty($params['name'])) {
        $params['name'] = trim($params['name']);
        $condition[] = db_quote("r.name LIKE ?l", '%' . $params['name'] . '%');
    }
    if (isset($params['phone']) && fn_string_not_empty($params['phone'])) {
        $params['phone'] = trim($params['phone']);
        $condition[] = db_quote("r.phone LIKE ?l", '%' . $params['phone'] . '%');
    }
    if (!empty($params['status'])) {
        $condition[] = db_quote("r.status = ?s", $params['status']);
    }
    if (!empty($params['order_status'])) {
        $condition[] = db_quote("o.status = ?s", $params['order_status']);
    }
    if (!empty($params['user_id'])) {
        $condition[] = db_quote("r.user_id = ?s", $params['user_id']);
    }
    if (!empty($params['order_exists'])) {
        $sign = $params['order_exists'] == 'Y' ? '<>' : '=';
        $condition[] = db_quote("r.order_id ?p 0", $sign);
    }
    $fields_str = implode(', ', $fields);
    $joins_str = ' ' . implode(' ', $joins);
    $condition_str = $condition ? ' WHERE ' . implode(' AND ', $condition) : '';
    $sorting_str = db_sort($params, $sortings, 'date', 'desc');
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(r.request_id) FROM ?:call_requests r" . $joins_str . $condition_str);
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $items = db_get_array("SELECT " . $fields_str . " FROM ?:call_requests r" . $joins_str . $condition_str . $sorting_str . $limit);
    if (!empty($items)) {
        $cart_product_ids = array();
        foreach ($items as &$item) {
            if (!empty($item['cart_products'])) {
                $item['cart_products'] = unserialize($item['cart_products']);
                foreach ($item['cart_products'] as $cart_product) {
                    $cart_product_ids[] = $cart_product['product_id'];
                }
            }
        }
        $cart_product_names = db_get_hash_single_array("SELECT product_id, product FROM ?:product_descriptions WHERE product_id IN(?n) AND lang_code = ?s", array('product_id', 'product'), array_unique($cart_product_ids), $lang_code);
        foreach ($items as &$item) {
            if (!empty($item['cart_products'])) {
                foreach ($item['cart_products'] as &$cart_product) {
                    if (!empty($cart_product_names[$cart_product['product_id']])) {
                        $cart_product['product'] = $cart_product_names[$cart_product['product_id']];
                    }
                }
            }
        }
    }
    return array($items, $params);
}
示例#12
0
/**
 * Getting users list
 *
 * @param  array  $params          Params list
 * @param  array  $auth            Auth
 * @param  int    $items_per_page  Items per page
 * @param  str    $custom_view     Custom view
 * @return array
 */
function fn_get_users($params, &$auth, $items_per_page = 0, $custom_view = '')
{
    /**
     * Actions before getting users list
     *
     * @param array $params         Params list
     * @param array $auth           Auth data
     * @param int   $items_per_page Items per page
     * @param str   $custom_view    Custom view
     */
    fn_set_hook('get_users_pre', $params, $auth, $items_per_page, $custom_view);
    // Init filter
    $_view = !empty($custom_view) ? $custom_view : 'users';
    $params = LastView::instance()->update($_view, $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    // Define fields that should be retrieved
    $fields = array("?:users.user_id", "?:users.user_login", "?:users.is_root", "?:users.timestamp", "?:users.user_type", "?:users.status", "?:users.firstname", "?:users.lastname", "?:users.email", "?:users.company", "?:users.company_id", "?:companies.company as company_name");
    // Define sort fields
    $sortings = array('id' => "?:users.user_id", 'username' => "?:users.user_login", 'email' => "?:users.email", 'name' => array("?:users.lastname", "?:users.firstname"), 'date' => "?:users.timestamp", 'type' => "?:users.user_type", 'status' => "?:users.status", 'company' => "company_name");
    if (isset($params['compact']) && $params['compact'] == 'Y') {
        $union_condition = ' OR ';
    } else {
        $union_condition = ' AND ';
    }
    $condition = array();
    $join = $group = '';
    $group .= " GROUP BY ?:users.user_id";
    if (isset($params['company']) && fn_string_not_empty($params['company'])) {
        $condition['company'] = db_quote(" AND ?:users.company LIKE ?l", "%" . trim($params['company']) . "%");
    }
    if (isset($params['name']) && fn_string_not_empty($params['name'])) {
        $arr = fn_explode(' ', $params['name']);
        foreach ($arr as $k => $v) {
            if (!fn_string_not_empty($v)) {
                unset($arr[$k]);
            }
        }
        if (sizeof($arr) == 2) {
            $condition['name'] = db_quote(" AND (?:users.firstname LIKE ?l AND ?:users.lastname LIKE ?l)", "%" . array_shift($arr) . "%", "%" . array_shift($arr) . "%");
        } else {
            $condition['name'] = db_quote(" AND (?:users.firstname LIKE ?l OR ?:users.lastname LIKE ?l)", "%" . trim($params['name']) . "%", "%" . trim($params['name']) . "%");
        }
    }
    if (isset($params['user_login']) && fn_string_not_empty($params['user_login'])) {
        $condition['user_login'] = db_quote(" {$union_condition} ?:users.user_login LIKE ?l", "%" . trim($params['user_login']) . "%");
    }
    if (!empty($params['tax_exempt'])) {
        $condition['tax_exempt'] = db_quote(" AND ?:users.tax_exempt = ?s", $params['tax_exempt']);
    }
    if (!fn_allowed_for('ULTIMATE:FREE')) {
        if (isset($params['usergroup_id']) && $params['usergroup_id'] != ALL_USERGROUPS) {
            if (!empty($params['usergroup_id'])) {
                $join .= db_quote(" LEFT JOIN ?:usergroup_links ON ?:usergroup_links.user_id = ?:users.user_id AND ?:usergroup_links.usergroup_id = ?i", $params['usergroup_id']);
                $condition['usergroup_links'] = " AND ?:usergroup_links.status = 'A'";
            } else {
                $join .= " LEFT JOIN ?:usergroup_links ON ?:usergroup_links.user_id = ?:users.user_id AND ?:usergroup_links.status = 'A'";
                $condition['usergroup_links'] = " AND ?:usergroup_links.user_id IS NULL";
            }
        }
    }
    if (!empty($params['status'])) {
        $condition['status'] = db_quote(" AND ?:users.status = ?s", $params['status']);
    }
    if (isset($params['email']) && fn_string_not_empty($params['email'])) {
        $condition['email'] = db_quote(" {$union_condition} ?:users.email LIKE ?l", "%" . trim($params['email']) . "%");
    }
    if (isset($params['address']) && fn_string_not_empty($params['address'])) {
        $condition['address'] = db_quote(" AND (?:user_profiles.b_address LIKE ?l OR ?:user_profiles.s_address LIKE ?l)", "%" . trim($params['address']) . "%", "%" . trim($params['address']) . "%");
    }
    if (isset($params['zipcode']) && fn_string_not_empty($params['zipcode'])) {
        $condition['zipcode'] = db_quote(" AND (?:user_profiles.b_zipcode LIKE ?l OR ?:user_profiles.s_zipcode LIKE ?l)", "%" . trim($params['zipcode']) . "%", "%" . trim($params['zipcode']) . "%");
    }
    if (!empty($params['country'])) {
        $condition['country'] = db_quote(" AND (?:user_profiles.b_country LIKE ?l OR ?:user_profiles.s_country LIKE ?l)", "%{$params['country']}%", "%{$params['country']}%");
    }
    if (isset($params['state']) && fn_string_not_empty($params['state'])) {
        $condition['state'] = db_quote(" AND (?:user_profiles.b_state LIKE ?l OR ?:user_profiles.s_state LIKE ?l)", "%" . trim($params['state']) . "%", "%" . trim($params['state']) . "%");
    }
    if (isset($params['city']) && fn_string_not_empty($params['city'])) {
        $condition['city'] = db_quote(" AND (?:user_profiles.b_city LIKE ?l OR ?:user_profiles.s_city LIKE ?l)", "%" . trim($params['city']) . "%", "%" . trim($params['city']) . "%");
    }
    if (!empty($params['user_id'])) {
        $condition['user_id'] = db_quote(' AND ?:users.user_id IN (?n)', $params['user_id']);
    }
    if (!empty($params['p_ids']) || !empty($params['product_view_id'])) {
        $arr = strpos($params['p_ids'], ',') !== false || !is_array($params['p_ids']) ? explode(',', $params['p_ids']) : $params['p_ids'];
        if (empty($params['product_view_id'])) {
            $condition['order_product_id'] = db_quote(" AND ?:order_details.product_id IN (?n)", $arr);
        } else {
            $condition['order_product_id'] = db_quote(" AND ?:order_details.product_id IN (?n)", db_get_fields(fn_get_products(array('view_id' => $params['product_view_id'], 'get_query' => true))));
        }
        $join .= db_quote(" LEFT JOIN ?:orders ON ?:orders.user_id = ?:users.user_id AND ?:orders.is_parent_order != 'Y' LEFT JOIN ?:order_details ON ?:order_details.order_id = ?:orders.order_id");
    }
    if (defined('RESTRICTED_ADMIN')) {
        // FIXME: NOT GOOD
        $condition['restricted_admin'] = db_quote(" AND ((?:users.user_type != 'A' AND ?:users.user_type != 'V') OR (?:users.user_type = 'A' AND ?:users.user_id = ?i))", $auth['user_id']);
    }
    // sometimes other vendor's admins could buy products from other vendors.
    if (!empty($params['user_type']) && (!($params['user_type'] == 'C' && Registry::get('runtime.company_id')) || fn_allowed_for('ULTIMATE'))) {
        $condition['user_type'] = db_quote(' AND ?:users.user_type = ?s', $params['user_type']);
    } else {
        // Get active user types
        $user_types = array_keys(fn_get_user_types());
        // Select only necessary groups frm all available
        if (!empty($params['user_types'])) {
            $user_types = array_intersect($user_types, $params['user_types']);
        }
        if (!empty($params['exclude_user_types'])) {
            $user_types = array_diff($user_types, $params['exclude_user_types']);
        }
        $condition['user_type'] = db_quote(" AND ?:users.user_type IN(?a)", $user_types);
    }
    $join .= db_quote(" LEFT JOIN ?:user_profiles ON ?:user_profiles.user_id = ?:users.user_id");
    $join .= db_quote(" LEFT JOIN ?:companies ON ?:companies.company_id = ?:users.company_id");
    /**
     * Prepare params for getting users query
     *
     * @param array $params    Params list
     * @param array $fields    Fields list
     * @param array $sortings  Sorting variants
     * @param array $condition Conditions set
     * @param str   $join      Joins list
     * @param array $auth      Auth data
     */
    fn_set_hook('get_users', $params, $fields, $sortings, $condition, $join, $auth);
    $sorting = db_sort($params, $sortings, 'name', 'asc');
    // Used for Extended search
    if (!empty($params['get_conditions'])) {
        return array($fields, $join, $condition);
    }
    // Paginate search results
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(DISTINCT(?:users.user_id)) FROM ?:users {$join} WHERE 1 " . implode(' ', $condition));
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $users = db_get_array("SELECT " . implode(', ', $fields) . " FROM ?:users {$join} WHERE 1" . implode('', $condition) . " {$group} {$sorting} {$limit}");
    LastView::instance()->processResults('users', $users, $params);
    /**
     * Actions after getting users list
     *
     * @param array $users  Users list
     * @param array $params Params list
     * @param array $auth   Auth data
     */
    fn_set_hook('get_users_post', $users, $params, $auth);
    return array($users, $params);
}
示例#13
0
/**
 * Dispathes the execution control to correct controller
 *
 * @return nothing
 */
function fn_dispatch($controller = '', $mode = '', $action = '', $dispatch_extra = '', $area = AREA)
{
    Debugger::checkpoint('After init');
    $auth = $_SESSION['auth'];
    $controller = empty($controller) ? Registry::get('runtime.controller') : $controller;
    $mode = empty($mode) ? Registry::get('runtime.mode') : $mode;
    $action = empty($action) ? Registry::get('runtime.action') : $action;
    $dispatch_extra = empty($dispatch_extra) ? Registry::get('runtime.dispatch_extra') : $dispatch_extra;
    fn_set_hook('before_dispatch', $controller, $mode, $action, $dispatch_extra, $area);
    $view = Registry::get('view');
    $run_controllers = true;
    $external = false;
    $status = CONTROLLER_STATUS_NO_PAGE;
    // CSRF protection
    if (fn_is_csrf_protection_enabled($auth) && !fn_csrf_validate_request(array('server' => $_SERVER, 'request' => $_REQUEST, 'session' => $_SESSION, 'controller' => $controller, 'mode' => $mode, 'action' => $action, 'dispatch_extra' => $dispatch_extra, 'area' => $area, 'auth' => $auth))) {
        fn_set_notification('E', __('error'), __('text_csrf_attack'));
        fn_redirect(fn_url());
    }
    // If $config['http_host'] was different from the domain name, there was redirection to $config['http_host'] value.
    if (strtolower(Registry::get('config.current_host')) != strtolower(REAL_HOST) && $_SERVER['REQUEST_METHOD'] == 'GET' && !defined('CONSOLE')) {
        if (!empty($_SERVER['REDIRECT_URL'])) {
            $qstring = $_SERVER['REDIRECT_URL'];
        } else {
            if (!empty($_SERVER['REQUEST_URI'])) {
                $qstring = $_SERVER['REQUEST_URI'];
            } else {
                $qstring = Registry::get('config.current_url');
            }
        }
        $curent_path = Registry::get('config.current_path');
        if (!empty($curent_path) && strpos($qstring, $curent_path) === 0) {
            $qstring = substr_replace($qstring, '', 0, fn_strlen($curent_path));
        }
        fn_redirect(Registry::get('config.current_location') . $qstring, false, true);
    }
    $upload_max_filesize = Bootstrap::getIniParam('upload_max_filesize');
    $post_max_size = Bootstrap::getIniParam('post_max_size');
    if (!defined('AJAX_REQUEST') && isset($_SERVER['CONTENT_LENGTH']) && ($_SERVER['CONTENT_LENGTH'] > fn_return_bytes($upload_max_filesize) || $_SERVER['CONTENT_LENGTH'] > fn_return_bytes($post_max_size))) {
        $max_size = fn_return_bytes($upload_max_filesize) < fn_return_bytes($post_max_size) ? $upload_max_filesize : $post_max_size;
        fn_set_notification('E', __('error'), __('text_forbidden_uploaded_file_size', array('[size]' => $max_size)));
        fn_redirect($_SERVER['HTTP_REFERER']);
    }
    // If URL contains session ID, remove it
    if (!defined('AJAX_REQUEST') && !empty($_REQUEST[Session::getName()]) && $_SERVER['REQUEST_METHOD'] == 'GET') {
        fn_redirect(fn_query_remove(Registry::get('config.current_url'), Session::getName()));
    }
    // If demo mode is enabled, check permissions FIX ME - why did we need one more user login check?
    if ($area == 'A') {
        if (Registry::get('config.demo_mode') == true) {
            $run_controllers = fn_check_permissions($controller, $mode, 'demo');
            if ($run_controllers == false) {
                fn_set_notification('W', __('demo_mode'), __('demo_mode_content_text'), 'K', 'demo_mode');
                if (defined('AJAX_REQUEST')) {
                    exit;
                }
                fn_delete_notification('changes_saved');
                $status = CONTROLLER_STATUS_REDIRECT;
                $_REQUEST['redirect_url'] = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : fn_url('');
            }
        } else {
            $run_controllers = fn_check_permissions($controller, $mode, 'admin', '', $_REQUEST);
            if ($run_controllers == false) {
                if (defined('AJAX_REQUEST')) {
                    $_info = Debugger::isActive() || fn_is_development() ? ' ' . $controller . '.' . $mode : '';
                    fn_set_notification('W', __('warning'), __('access_denied') . $_info);
                    exit;
                }
                $status = CONTROLLER_STATUS_DENIED;
            }
        }
    }
    if ($_SERVER['REQUEST_METHOD'] != 'POST' && !defined('AJAX_REQUEST')) {
        if ($area == 'A' && empty($_REQUEST['keep_location']) && !defined('CONSOLE')) {
            if (!defined('HTTPS') && Registry::get('settings.Security.secure_admin') == 'Y') {
                fn_redirect(Registry::get('config.https_location') . '/' . Registry::get('config.current_url'));
            } elseif (defined('HTTPS') && Registry::get('settings.Security.secure_admin') != 'Y') {
                fn_redirect(Registry::get('config.http_location') . '/' . Registry::get('config.current_url'));
            }
        } elseif ($area == 'C') {
            $secure_controllers = fn_get_secure_controllers();
            // if we are not on https but controller is secure, redirect to https
            if (!defined('HTTPS') && (Registry::get('settings.Security.secure_storefront') == 'full' || isset($secure_controllers[$controller]) && $secure_controllers[$controller] == 'active')) {
                fn_redirect(Registry::get('config.https_location') . '/' . Registry::get('config.current_url'), false, true);
            }
            // if we are on https and the controller is insecure, redirect to http
            if (defined('HTTPS') && Registry::get('settings.Security.secure_storefront') != 'full' && !isset($secure_controllers[$controller]) && Registry::get('settings.Security.keep_https') != 'Y') {
                fn_redirect(Registry::get('config.http_location') . '/' . Registry::get('config.current_url'), false, true);
            }
        }
    }
    LastView::instance()->prepare($_REQUEST);
    $controllers_cascade = array();
    $controllers_list = array('init');
    if ($run_controllers == true) {
        $controllers_list[] = $controller;
        $controllers_list = array_unique($controllers_list);
    }
    foreach ($controllers_list as $ctrl) {
        $core_controllers = fn_init_core_controllers($ctrl);
        list($addon_controllers) = fn_init_addon_controllers($ctrl);
        if (empty($core_controllers) && empty($addon_controllers)) {
            //$controllers_cascade = array(); // FIXME: controllers_cascade contains INIT. We should not clear initiation code.
            $status = CONTROLLER_STATUS_NO_PAGE;
            $run_controllers = false;
            break;
        }
        if (count($core_controllers) + count($addon_controllers) > 1) {
            throw new DeveloperException('Duplicate controller ' . $controller . var_export(array_merge($core_controllers, $addon_controllers), true));
        }
        $core_pre_controllers = fn_init_core_controllers($ctrl, GET_PRE_CONTROLLERS);
        $core_post_controllers = fn_init_core_controllers($ctrl, GET_POST_CONTROLLERS);
        list($addon_pre_controllers) = fn_init_addon_controllers($ctrl, GET_PRE_CONTROLLERS);
        list($addon_post_controllers, $addons) = fn_init_addon_controllers($ctrl, GET_POST_CONTROLLERS);
        // we put addon post-controller to the top of post-controller cascade if current addon serves this request
        if (count($addon_controllers)) {
            $addon_post_controllers = fn_reorder_post_controllers($addon_post_controllers, $addon_controllers[0]);
        }
        $controllers_cascade = array_merge($controllers_cascade, $addon_pre_controllers, $core_pre_controllers, $core_controllers, $addon_controllers, $core_post_controllers, $addon_post_controllers);
        if (empty($controllers_cascade)) {
            throw new DeveloperException("No controllers for: {$ctrl}");
        }
    }
    if ($mode == 'add') {
        $tpl = 'update.tpl';
    } elseif (strpos($mode, 'add_') === 0) {
        $tpl = str_replace('add_', 'update_', $mode) . '.tpl';
    } else {
        $tpl = $mode . '.tpl';
    }
    $view = Registry::get('view');
    if ($view->templateExists('views/' . $controller . '/' . $tpl)) {
        // try to find template in base views
        $view->assign('content_tpl', 'views/' . $controller . '/' . $tpl);
    } elseif (defined('LOADED_ADDON_PATH') && $view->templateExists('addons/' . LOADED_ADDON_PATH . '/views/' . $controller . '/' . $tpl)) {
        // try to find template in addon views
        $view->assign('content_tpl', 'addons/' . LOADED_ADDON_PATH . '/views/' . $controller . '/' . $tpl);
    } elseif (!empty($addons)) {
        // try to find template in addon views that extend base views
        foreach ($addons as $addon => $_v) {
            if ($view->templateExists('addons/' . $addon . '/views/' . $controller . '/' . $tpl)) {
                $view->assign('content_tpl', 'addons/' . $addon . '/views/' . $controller . '/' . $tpl);
                break;
            }
        }
    }
    /**
     * Performs actions after template assignment and before controller run
     *
     * @param string $controller          controller name
     * @param string $mode                controller mode name
     * @param string $area                current working area
     * @param array  $controllers_cascade list of controllers to run
     */
    fn_set_hook('dispatch_assign_template', $controller, $mode, $area, $controllers_cascade);
    foreach ($controllers_cascade as $item) {
        $_res = fn_run_controller($item, $controller, $mode, $action, $dispatch_extra);
        // 0 - status, 1 - url
        $url = !empty($_res[1]) ? $_res[1] : '';
        $external = !empty($_res[2]) ? $_res[2] : false;
        $permanent = !empty($_res[3]) ? $_res[3] : false;
        // Status could be changed only if we allow to run controllers despite of init controller
        if ($run_controllers == true) {
            $status = !empty($_res[0]) ? $_res[0] : CONTROLLER_STATUS_OK;
        }
        if ($status == CONTROLLER_STATUS_OK && !empty($url)) {
            $redirect_url = $url;
        } elseif ($status == CONTROLLER_STATUS_REDIRECT && !empty($url)) {
            $redirect_url = $url;
            break;
        } elseif ($status == CONTROLLER_STATUS_DENIED || $status == CONTROLLER_STATUS_NO_PAGE) {
            break;
        }
    }
    LastView::instance()->init($_REQUEST);
    // In console mode, just stop here
    if (defined('CONSOLE')) {
        $notifications = fn_get_notifications();
        $exit_code = 0;
        foreach ($notifications as $n) {
            fn_echo('[' . $n['title'] . '] ' . $n['message'] . "\n");
            if ($n['type'] == 'E') {
                $exit_code = 1;
            }
        }
        exit($exit_code);
    }
    if (!empty($auth['this_login']) && Registry::ifGet($auth['this_login'], 'N') === 'Y') {
        fn_set_notification('E', __('error'), __(ACCOUNT_TYPE . LOGIN_STATUS_USER_DISABLED));
        $status = CONTROLLER_STATUS_DENIED;
    }
    // [Block manager]
    // block manager is disabled for vendors.
    if (!(fn_allowed_for('MULTIVENDOR') && Registry::get('runtime.company_id') || fn_allowed_for('ULTIMATE') && !Registry::get('runtime.company_id'))) {
        if (fn_check_permissions('block_manager', 'manage', 'admin')) {
            $dynamic_object = SchemesManager::getDynamicObject($_REQUEST['dispatch'], $area, $_REQUEST);
            if (!empty($dynamic_object)) {
                if ($area == 'A' && Registry::get('runtime.mode') != 'add' && !empty($_REQUEST[$dynamic_object['key']])) {
                    $object_id = $_REQUEST[$dynamic_object['key']];
                    $location = Location::instance()->get($dynamic_object['customer_dispatch'], $dynamic_object, CART_LANGUAGE);
                    if (!empty($location) && $location['is_default'] != 1) {
                        $params = array('dynamic_object' => array('object_type' => $dynamic_object['object_type'], 'object_id' => $object_id), $dynamic_object['key'] => $object_id, 'manage_url' => Registry::get('config.current_url'));
                        Registry::set('navigation.tabs.blocks', array('title' => __('layouts'), 'href' => 'block_manager.manage_in_tab?' . http_build_query($params), 'ajax' => true));
                    }
                }
            }
        }
    }
    // [/Block manager]
    // Redirect if controller returned successful/redirect status only
    if (in_array($status, array(CONTROLLER_STATUS_OK, CONTROLLER_STATUS_REDIRECT)) && !empty($_REQUEST['redirect_url']) && !$external) {
        $redirect_url = $_REQUEST['redirect_url'];
    }
    // If controller returns "Redirect" status, check if redirect url exists
    if ($status == CONTROLLER_STATUS_REDIRECT && empty($redirect_url)) {
        $status = CONTROLLER_STATUS_NO_PAGE;
    }
    // In backend show "changes saved" notification
    if ($area == 'A' && $_SERVER['REQUEST_METHOD'] == 'POST' && in_array($status, array(CONTROLLER_STATUS_OK, CONTROLLER_STATUS_REDIRECT))) {
        if (strpos($mode, 'update') !== false && $mode != 'update_status' && $mode != 'update_mode' && !fn_notification_exists('extra', 'demo_mode') && !fn_notification_exists('type', 'E')) {
            fn_set_notification('N', __('notice'), __('text_changes_saved'), 'I', 'changes_saved');
        }
    }
    // Attach params and redirect if needed
    if (in_array($status, array(CONTROLLER_STATUS_OK, CONTROLLER_STATUS_REDIRECT)) && !empty($redirect_url)) {
        if (!isset($_REQUEST['return_to_list'])) {
            $params = array('page', 'selected_section', 'active_tab');
            $url_params = array();
            foreach ($params as $param) {
                if (!empty($_REQUEST[$param])) {
                    $url_params[$param] = $_REQUEST[$param];
                }
            }
            if (!empty($url_params)) {
                $redirect_url = fn_link_attach($redirect_url, http_build_query($url_params));
            }
        }
        if (!isset($external)) {
            $external = false;
        }
        if (!isset($permanent)) {
            $permanent = false;
        }
        fn_redirect($redirect_url, $external, $permanent);
    }
    if (!$view->getTemplateVars('content_tpl') && $status == CONTROLLER_STATUS_OK) {
        // FIXME
        $status = CONTROLLER_STATUS_NO_PAGE;
    }
    if ($status != CONTROLLER_STATUS_OK) {
        if ($status == CONTROLLER_STATUS_NO_PAGE) {
            if ($area == 'A' && empty($auth['user_id'])) {
                // If admin is not logged in redirect to login page from not found page
                fn_set_notification('W', __('page_not_found'), __('page_not_found_text'));
                fn_redirect("auth.login_form");
            }
            header(' ', true, 404);
        }
        $view->assign('exception_status', $status);
        if ($area == 'A') {
            $view->assign('content_tpl', 'exception.tpl');
            // for backend only
        }
        if ($status == CONTROLLER_STATUS_DENIED) {
            $view->assign('page_title', __('access_denied'));
        } elseif ($status == CONTROLLER_STATUS_NO_PAGE) {
            $view->assign('page_title', __('page_not_found'));
        }
    }
    fn_set_hook('dispatch_before_display');
    Debugger::checkpoint('Before TPL');
    // Pass current URL to ajax response only if we render whole page
    if (defined('AJAX_REQUEST') && Registry::get('runtime.root_template') == 'index.tpl') {
        Registry::get('ajax')->assign('current_url', fn_url(Registry::get('config.current_url'), $area, 'current'));
    }
    Registry::get('view')->display(Registry::get('runtime.root_template'));
    Debugger::checkpoint('After TPL');
    Debugger::display();
    fn_set_hook('complete');
    if (defined('AJAX_REQUEST')) {
        // HHVM workaround. Destroy Ajax object manually if it has been created.
        $ajax = Registry::get('ajax');
        $ajax = null;
    }
    exit;
    // stop execution
}
示例#14
0
文件: func.php 项目: arpad9/bygmarket
function fn_get_gift_certificates($params, $items_per_page = 0)
{
    // Init filter
    $params = LastView::instance()->update('gift_certs', $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    // Define fields that should be retrieved
    $fields = array('?:gift_certificates.gift_cert_id', '?:gift_certificates.gift_cert_code', '?:gift_certificates.timestamp', '?:gift_certificates.amount', '?:gift_certificates.status', '?:gift_certificates.recipient', '?:gift_certificates.sender', '?:gift_certificates.send_via', '?:gift_certificates.email');
    if (fn_allowed_for('ULTIMATE')) {
        $fields[] = '?:gift_certificates.company_id';
    }
    // Define sort fields
    $sortings = array('timestamp' => "?:gift_certificates.timestamp", 'amount' => "?:gift_certificates.amount", 'recipient' => "?:gift_certificates.recipient", 'sender' => "?:gift_certificates.sender", 'status' => "?:gift_certificates.status", 'gift_cert_code' => "?:gift_certificates.gift_cert_code", 'send_via' => "?:gift_certificates.send_via");
    $sorting = db_sort($params, $sortings, 'timestamp', 'desc');
    $condition = $join = '';
    if (isset($params['sender']) && fn_string_not_empty($params['sender'])) {
        $condition .= db_quote(" AND ?:gift_certificates.sender LIKE ?l", "%" . trim($params['sender']) . "%");
    }
    if (isset($params['recipient']) && fn_string_not_empty($params['recipient'])) {
        $condition .= db_quote(" AND ?:gift_certificates.recipient LIKE ?l", "%" . trim($params['recipient']) . "%");
    }
    if (isset($params['email']) && fn_string_not_empty($params['email'])) {
        $condition .= db_quote(" AND ?:gift_certificates.email LIKE ?l", "%" . trim($params['email']) . "%");
    }
    if (!empty($params['amount_from'])) {
        $condition .= db_quote(" AND ?:gift_certificates.amount >= ?d", $params['amount_from']);
    }
    if (!empty($params['amount_to'])) {
        $condition .= db_quote(" AND ?:gift_certificates.amount <= ?d", $params['amount_to']);
    }
    if (!empty($params['gift_cert_ids'])) {
        $condition .= db_quote(" AND ?:gift_certificates.gift_cert_id IN (?n)", $params['gift_cert_ids']);
    }
    if (!empty($params['status'])) {
        $condition .= db_quote(" AND ?:gift_certificates.status IN (?a)", $params['status']);
    }
    if (isset($params['gift_cert_code']) && fn_string_not_empty($params['gift_cert_code'])) {
        $condition .= db_quote(" AND ?:gift_certificates.gift_cert_code LIKE ?l", "%" . trim($params['gift_cert_code']) . "%");
    }
    if (!empty($params['period']) && $params['period'] != 'A') {
        list($params['time_from'], $params['time_to']) = fn_create_periods($params);
        $condition .= db_quote(" AND (?:gift_certificates.timestamp >= ?i AND ?:gift_certificates.timestamp <= ?i)", $params['time_from'], $params['time_to']);
    }
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:gift_certificates WHERE 1 ?p", $condition . fn_get_gift_certificate_company_condition('?:gift_certificates.company_id'));
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $gift_certificates = db_get_array("SELECT ?p  FROM ?:gift_certificates WHERE 1 ?p ?p ?p", implode(',', $fields), $condition . fn_get_gift_certificate_company_condition('?:gift_certificates.company_id'), $sorting, $limit);
    foreach ($gift_certificates as $k => $v) {
        $debit_balance = db_get_row("SELECT debit, debit_products FROM ?:gift_certificates_log WHERE gift_cert_id = ?i ORDER BY log_id DESC", $v['gift_cert_id']);
        $gift_certificates[$k]['debit'] = empty($debit_balance) ? $v['amount'] : $debit_balance['debit'];
    }
    LastView::instance()->processResults('gift_certificates', $gift_certificates, $params);
    return array($gift_certificates, $params);
}
示例#15
0
function fn_get_ebay_templates($params, $items_per_page = 0, $lang_code = CART_LANGUAGE, $get_simple = false)
{
    // Init filter
    $params = LastView::instance()->update('ebay_templates', $params);
    $fields = array('templates.template_id', 'templates.status', 'descr.name', 'templates.company_id');
    // Define sort fields
    $sortings = array('status' => 'templates.status', 'name' => 'descr.name');
    $condition = '';
    //fn_get_company_condition('templates.company_id')
    $join = db_quote('LEFT JOIN ?:ebay_template_descriptions as descr ON templates.template_id = descr.template_id AND descr.lang_code = ?s', $lang_code);
    if (!empty($params['product_id'])) {
        if (fn_allowed_for('ULTIMATE')) {
            if (Registry::get('runtime.simple_ultimate')) {
                $condition = '';
            } else {
                $company_ids = fn_ult_get_shared_product_companies($params['product_id']);
                $tempalte_ids = db_get_fields("SELECT share_object_id FROM ?:ult_objects_sharing WHERE share_object_type = 'ebay_templates' AND share_company_id IN (?n)", $company_ids);
                $condition = db_quote(' AND templates.template_id IN (?n)', $tempalte_ids);
            }
        } elseif (fn_allowed_for('MULTIVENDOR')) {
            if (Registry::get('runtime.company_id')) {
                $condition = fn_get_company_condition('templates.company_id');
            } else {
                $company_id = db_get_field("SELECT company_id FROM ?:products WHERE product_id = ?i", $params['product_id']);
                $condition = db_quote(" AND templates.company_id = ?i", $company_id);
            }
        }
    } else {
        if (fn_allowed_for('ULTIMATE') && !Registry::get('runtime.simple_ultimate') && Registry::get('runtime.company_id')) {
            $join .= db_quote(" INNER JOIN ?:ult_objects_sharing ON (?:ult_objects_sharing.share_object_id = templates.template_id AND ?:ult_objects_sharing.share_company_id = ?i AND ?:ult_objects_sharing.share_object_type = 'ebay_templates')", Registry::get('runtime.company_id'));
        }
    }
    $limit = '';
    $group_by = 'templates.template_id';
    // -- SORTINGS --
    if (empty($params['sort_by']) || empty($sortings[$params['sort_by']])) {
        $params['sort_by'] = 'name';
    }
    if (empty($params['sort_order'])) {
        $params['sort_order'] = 'asc';
    }
    $sorting = db_sort($params, $sortings);
    if (!empty($params['limit'])) {
        $limit = db_quote(" LIMIT 0, ?i", $params['limit']);
    } elseif (!empty($params['items_per_page'])) {
        $limit = db_paginate($params['page'], $params['items_per_page']);
    }
    Registry::set('runtime.skip_sharing_selection', true);
    $templates = db_get_array("SELECT SQL_CALC_FOUND_ROWS " . implode(', ', $fields) . " FROM ?:ebay_templates as templates {$join} WHERE 1 {$condition} GROUP BY {$group_by} {$sorting} {$limit}");
    Registry::set('runtime.skip_sharing_selection', false);
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = !empty($total) ? $total : db_get_found_rows();
    } else {
        $params['total_items'] = count($templates);
    }
    if ($get_simple == true) {
        $_templates = array();
        foreach ($templates as $template) {
            $_templates[$template['template_id']] = $template['name'];
        }
        return $_templates;
    }
    return array($templates, $params);
}
示例#16
0
        $params = array('page_type' => fn_is_exclusive_page_type($page_type) ? $page_type : '');
        if (!empty($page_data['company_id'])) {
            $params['company_id'] = $page_data['company_id'];
        } elseif (Registry::get('runtime.company_id')) {
            $params['company_id'] = Registry::get('runtime.company_id');
        }
        Registry::get('view')->assign('parent_pages', fn_get_pages_plain_list($params));
    }
    //
    // 'Management' page
    //
} elseif ($mode == 'manage' || $mode == 'picker') {
    $params = $_REQUEST;
    // This needs to allow exclusive pages have their own views
    if (!empty($params['view_id'])) {
        $data = LastView::instance()->getViewParams($params['view_id']);
        $params = fn_array_merge($params, $data);
    }
    if ($mode == 'picker') {
        $params['skip_view'] = 'Y';
    }
    $page_type = !empty($params['page_type']) ? $params['page_type'] : '';
    $items_per_page = 0;
    if (!empty($params['get_tree'])) {
        // manage page, show tree
        $condition = db_quote(" AND ?:pages.page_type IN (?a)", array_keys(fn_get_page_type_filter($page_type)));
        $total = db_get_field("SELECT COUNT(*) FROM ?:pages WHERE 1 ?p", $condition);
        if ($total > PAGE_THRESHOLD) {
            $params['get_children_count'] = true;
            $params['get_tree'] = '';
            $params['parent_id'] = !empty($params['parent_id']) ? $params['parent_id'] : 0;
示例#17
0
function fn_get_product_subscribers($params, $items_per_page = 0)
{
    // Set default values to input params
    $default_params = array('page' => 1, 'email' => '', 'product_id' => 0, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    /**
     * Changes params for getting product subscribers
     *
     * @param array $params Search subscribers params
     */
    fn_set_hook('get_product_subscribers_pre', $params);
    // Init filter
    $params = LastView::instance()->update('subscribers', $params);
    $condition = '';
    $limit = '';
    if (isset($params['email']) && fn_string_not_empty($params['email'])) {
        $condition .= db_quote(" AND email LIKE ?l", "%" . trim($params['email']) . "%");
    }
    $sorting = db_sort($params, array('email' => 'email'), 'email', 'asc');
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(*) FROM ?:product_subscriptions WHERE product_id = ?i {$condition}", $params['product_id']);
        $limit = db_paginate($params['page'], $params['items_per_page']);
    }
    $subscribers = db_get_hash_array("SELECT subscription_id as subscriber_id, email FROM ?:product_subscriptions WHERE product_id = ?i {$condition} {$sorting} {$limit}", 'subscriber_id', $params['product_id']);
    /**
     * Changes product subscribers
     *
     * @param int   $product_id  Product identifier
     * @param array $params      Search subscribers params
     * @param array $subscribers Array of subscribers
     */
    fn_set_hook('get_product_subscribers_post', $params, $subscribers);
    return array($subscribers, $params);
}
示例#18
0
function fn_get_shipments_info($params, $items_per_page = 0)
{
    // Init view params
    $params = LastView::instance()->update('shipments', $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    $fields_list = array('?:shipments.shipment_id', '?:shipments.timestamp AS shipment_timestamp', '?:shipments.comments', '?:shipment_items.order_id', '?:orders.timestamp AS order_timestamp', '?:orders.s_firstname', '?:orders.s_lastname', '?:orders.user_id');
    $joins = array('LEFT JOIN ?:shipment_items ON (?:shipments.shipment_id = ?:shipment_items.shipment_id)', 'LEFT JOIN ?:orders ON (?:shipment_items.order_id = ?:orders.order_id)');
    $condition = '';
    if (Registry::get('runtime.company_id')) {
        $joins[] = 'LEFT JOIN ?:companies ON (?:companies.company_id = ?:orders.company_id)';
        $condition = db_quote(' AND ?:companies.company_id = ?i', Registry::get('runtime.company_id'));
    }
    $group = array('?:shipments.shipment_id');
    // Define sort fields
    $sortings = array('id' => "?:shipments.shipment_id", 'order_id' => "?:orders.order_id", 'shipment_date' => "?:shipments.timestamp", 'order_date' => "?:orders.timestamp", 'customer' => array("?:orders.s_lastname", "?:orders.s_firstname"));
    $sorting = db_sort($params, $sortings, 'id', 'desc');
    if (isset($params['advanced_info']) && $params['advanced_info']) {
        $fields_list[] = '?:shipments.shipping_id';
        $fields_list[] = '?:shipping_descriptions.shipping AS shipping';
        $fields_list[] = '?:shipments.tracking_number';
        $fields_list[] = '?:shipments.carrier';
        $joins[] = ' LEFT JOIN ?:shippings ON (?:shipments.shipping_id = ?:shippings.shipping_id)';
        $joins[] = db_quote(' LEFT JOIN ?:shipping_descriptions ON (?:shippings.shipping_id = ?:shipping_descriptions.shipping_id AND ?:shipping_descriptions.lang_code = ?s)', DESCR_SL);
    }
    if (!empty($params['order_id'])) {
        $condition .= db_quote(' AND ?:shipment_items.order_id = ?i', $params['order_id']);
    }
    if (!empty($params['shipment_id'])) {
        $condition .= db_quote(' AND ?:shipments.shipment_id = ?i', $params['shipment_id']);
    }
    if (isset($params['cname']) && fn_string_not_empty($params['cname'])) {
        $arr = fn_explode(' ', $params['cname']);
        foreach ($arr as $k => $v) {
            if (!fn_string_not_empty($v)) {
                unset($arr[$k]);
            }
        }
        if (sizeof($arr) == 2) {
            $condition .= db_quote(" AND ?:orders.firstname LIKE ?l AND ?:orders.lastname LIKE ?l", "%" . array_shift($arr) . "%", "%" . array_shift($arr) . "%");
        } else {
            $condition .= db_quote(" AND (?:orders.firstname LIKE ?l OR ?:orders.lastname LIKE ?l)", "%" . trim($params['cname']) . "%", "%" . trim($params['cname']) . "%");
        }
    }
    if (!empty($params['p_ids']) || !empty($params['product_view_id'])) {
        $arr = strpos($params['p_ids'], ',') !== false || !is_array($params['p_ids']) ? explode(',', $params['p_ids']) : $params['p_ids'];
        if (empty($params['product_view_id'])) {
            $condition .= db_quote(" AND ?:shipment_items.product_id IN (?n)", $arr);
        } else {
            $condition .= db_quote(" AND ?:shipment_items.product_id IN (?n)", db_get_fields(fn_get_products(array('view_id' => $params['product_view_id'], 'get_query' => true)), ','));
        }
        $joins[] = "LEFT JOIN ?:order_details ON ?:order_details.order_id = ?:orders.order_id";
    }
    if (!empty($params['shipment_period']) && $params['shipment_period'] != 'A') {
        $params['time_from'] = $params['shipment_time_from'];
        $params['time_to'] = $params['shipment_time_to'];
        $params['period'] = $params['shipment_period'];
        list($params['shipment_time_from'], $params['shipment_time_to']) = fn_create_periods($params);
        $condition .= db_quote(" AND (?:shipments.timestamp >= ?i AND ?:shipments.timestamp <= ?i)", $params['shipment_time_from'], $params['shipment_time_to']);
    }
    if (!empty($params['order_period']) && $params['order_period'] != 'A') {
        $params['time_from'] = $params['order_time_from'];
        $params['time_to'] = $params['order_time_to'];
        $params['period'] = $params['order_period'];
        list($params['order_time_from'], $params['order_time_to']) = fn_create_periods($params);
        $condition .= db_quote(" AND (?:orders.timestamp >= ?i AND ?:orders.timestamp <= ?i)", $params['order_time_from'], $params['order_time_to']);
    }
    fn_set_hook('get_shipments', $params, $fields_list, $joins, $condition, $group);
    $fields_list = implode(', ', $fields_list);
    $joins = implode(' ', $joins);
    $group = implode(', ', $group);
    if (!empty($group)) {
        $group = ' GROUP BY ' . $group;
    }
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(DISTINCT(?:shipments.shipment_id)) FROM ?:shipments {$joins} WHERE 1 {$condition}");
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $shipments = db_get_array("SELECT {$fields_list} FROM ?:shipments {$joins} WHERE 1 {$condition} {$group} {$sorting} {$limit}");
    if (isset($params['advanced_info']) && $params['advanced_info'] && !empty($shipments)) {
        $shipment = reset($shipments);
        $order_info = fn_get_order_info($shipment['order_id']);
        foreach ($shipments as $id => $shipment) {
            $items = db_get_array('SELECT item_id, amount FROM ?:shipment_items WHERE shipment_id = ?i', $shipment['shipment_id']);
            if (!empty($items)) {
                foreach ($items as $item) {
                    $shipments[$id]['products'][$item['item_id']] = $item['amount'];
                    if (!empty($order_info['products'][$item['item_id']]['extra']['group_key'])) {
                        $shipments[$id]['group_key'] = $order_info['products'][$item['item_id']]['extra']['group_key'];
                    } else {
                        $shipments[$id]['group_key'] = 0;
                    }
                }
            }
        }
        if (Settings::instance()->getValue('use_shipments', '', $order_info['company_id']) != 'Y') {
            foreach ($shipments as $id => $shipment) {
                $shipments[$id]['one_full'] = true;
                foreach ($order_info['products'] as $product_key => $product) {
                    $group_key = !empty($product['extra']['group_key']) ? $product['extra']['group_key'] : 0;
                    if ($shipment['group_key'] == $group_key) {
                        if (empty($shipment['products'][$product_key]) || $shipment['products'][$product_key] < $product['amount']) {
                            $shipments[$id]['one_full'] = false;
                            break;
                        }
                    }
                }
            }
        }
    }
    /**
     * Changes selected shipments
     *
     * @param array $shipments Array of shipments
     * @param array $params    Shipments search params
     */
    fn_set_hook('get_shipments_info_post', $shipments, $params);
    LastView::instance()->processResults('shipments_info', $shipments, $params);
    return array($shipments, $params);
}
示例#19
0
/**
 * Get supplier data
 *
 * @param array $params
 * @return array Found suppliers data
 */
function fn_get_suppliers($params = array(), $items_per_page = 0)
{
    // Init filter
    $params = LastView::instance()->update('suppliers', $params);
    $condition = fn_get_company_condition('?:suppliers.company_id');
    $join = db_quote(" JOIN ?:companies ON ?:suppliers.company_id = ?:companies.company_id");
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    // Define fields that should be retrieved
    $fields = array("?:suppliers.supplier_id", "?:suppliers.timestamp", "?:suppliers.status", "?:suppliers.name", "?:suppliers.email", "?:suppliers.company_id", "?:companies.company as company_name");
    // Define sort fields
    $sortings = array('id' => "?:suppliers.supplier_id", 'email' => "?:suppliers.email", 'name' => "?:suppliers.name", 'date' => "?:suppliers.timestamp", 'type' => "?:suppliers.supplier_type", 'status' => "?:suppliers.status", 'company' => "company_name");
    $filters = array('name' => "?:suppliers.name", 'email' => "?:suppliers.email", 'address' => "?:suppliers.address", 'zipcode' => "?:suppliers.zipcode", 'country' => "?:suppliers.country", 'state' => "?:suppliers.state", 'city' => "?:suppliers.city", 'status' => "?:suppliers.status", 'company' => "?:companies.company");
    foreach ($filters as $filter => $field) {
        if (!empty($params[$filter])) {
            $condition .= db_quote(" AND " . $field . " LIKE ?l", "%" . trim($params[$filter]) . "%");
        }
    }
    if (!empty($params['supplier_id'])) {
        $condition .= db_quote(' AND ?:suppliers.supplier_id IN (?n)', $params['supplier_id']);
    }
    $sorting = db_sort($params, $sortings, 'name', 'asc');
    // Paginate search results
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(DISTINCT(?:suppliers.supplier_id)) FROM ?:suppliers ?p WHERE 1 ?p", $join, $condition);
        $limit = db_paginate($params['page'], $params['items_per_page']);
    }
    $suppliers = db_get_array("SELECT ?p FROM ?:suppliers ?p WHERE 1 ?p GROUP BY ?:suppliers.supplier_id ?p ?p", implode(', ', $fields), $join, $condition, $sorting, $limit);
    LastView::instance()->processResults('suppliers', $suppliers, $params);
    return array($suppliers, $params);
}
示例#20
0
        if (!empty($success_orders)) {
            fn_set_notification('N', __('successful'), __('ebay_success_orders_notice', array('[SUCCESS_IDS]' => implode(', ', $success_orders))));
        } elseif (!empty($failed_orders)) {
            fn_set_notification('W', __('warning'), __('ebay_failed_orders_notice', array('[FAILED_EBAY_IDS]' => implode(', ', $failed_orders))));
        } else {
            fn_set_notification('W', __('warning'), 'no orders found');
        }
    }
    return array(CONTROLLER_STATUS_REDIRECT, 'orders.manage');
} elseif ($mode == 'product_logs') {
    $params = $_REQUEST;
    if (isset($params['product_ids'])) {
        $params['product_ids'] = array_filter(explode(',', $params['product_ids']));
    }
    // Init filter
    $params = \Tygh\Navigation\LastView::instance()->update('ebay_product_logs', $params);
    list($logs, $search) = \Ebay\ProductLogger::getList($params, Registry::get('settings.Appearance.admin_elements_per_page'));
    $types = \Ebay\ProductLogger::getTypes();
    $actions = \Ebay\ProductLogger::getActions();
    $templates = fn_get_ebay_templates(array(), 0, DESCR_SL, true);
    Tygh::$app['view']->assign('logs', $logs);
    Tygh::$app['view']->assign('ebay_types', $types);
    Tygh::$app['view']->assign('ebay_actions', $actions);
    Tygh::$app['view']->assign('ebay_templates', $templates);
    Tygh::$app['view']->assign('search', $search);
} elseif ($mode == 'categories_picker') {
    $company_id = !empty($_REQUEST['company_id']) ? $_REQUEST['company_id'] : null;
    $used_site_ids = \Ebay\Template::getUsedSiteIds($company_id);
    if (isset($_REQUEST['site_id']) && in_array($_REQUEST['site_id'], $used_site_ids)) {
        $current_site_id = $_REQUEST['site_id'];
    } else {
示例#21
0
function fn_companies_get_payouts($params = array(), $items_per_page = 0)
{
    $params = LastView::instance()->update('balance', $params);
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    $fields = array();
    $join = ' ';
    // Define sort fields
    $sortings = array('sort_vendor' => 'companies.company', 'sort_period' => 'payouts.start_date', 'sort_amount' => 'payout_amount', 'sort_date' => 'payouts.payout_date');
    $condition = $date_condition = ' 1 ';
    $join .= ' LEFT JOIN ?:orders AS orders ON (payouts.order_id = orders.order_id)';
    $join .= ' LEFT JOIN ?:companies AS companies ON (payouts.company_id = companies.company_id)';
    // If the sales period not defined, specify it as 'All'
    if (empty($params['time_from']) && empty($params['time_to'])) {
        $params['period'] = 'A';
    }
    if (empty($params['time_from']) && empty($params['period'])) {
        $params['time_from'] = mktime(0, 0, 0, date('n', TIME), 1, date('Y', time()));
    } elseif (!empty($params['time_from'])) {
        $params['time_from'] = fn_parse_date($params['time_from']);
    } else {
        $time_from = true;
    }
    if (empty($params['time_to']) && empty($params['period'])) {
        $params['time_to'] = time();
    } elseif (!empty($params['time_to'])) {
        $params['time_to'] = fn_parse_date($params['time_to']) + 24 * 60 * 60 - 1;
        //Get the day ending time
    } else {
        $time_to = true;
    }
    if (isset($time_from) || isset($time_to)) {
        $dates = db_get_row('SELECT MIN(start_date) AS time_from, MAX(end_date) AS time_to FROM ?:vendor_payouts');
        if (isset($time_from)) {
            $params['time_from'] = $dates['time_from'];
        }
        if (isset($time_to)) {
            $params['time_to'] = $dates['time_to'];
        }
    }
    // Order statuses condition
    $statuses = db_get_fields('SELECT status FROM ?:status_data WHERE `type` = ?s AND param = ?s AND `value` = ?s', 'O', 'calculate_for_payouts', 'Y');
    if (!empty($statuses)) {
        $condition .= db_quote(' AND (orders.status IN (?a) OR payouts.order_id = 0)', $statuses);
    } else {
        $condition .= db_quote(' AND payouts.order_id = 0');
    }
    $date_condition .= db_quote(' AND ((payouts.start_date >= ?i AND payouts.end_date <= ?i AND payouts.order_id != ?i) OR (payouts.order_id = ?i AND (payouts.start_date BETWEEN ?i AND ?i OR payouts.end_date BETWEEN ?i AND ?i)))', $params['time_from'], $params['time_to'], 0, 0, $params['time_from'], $params['time_to'], $params['time_from'], $params['time_to']);
    // Filter by the transaction type
    if (!empty($params['transaction_type']) && ($params['transaction_type'] == 'income' || $params['transaction_type'] == 'expenditure')) {
        if ($params['transaction_type'] == 'income') {
            $condition .= ' AND (payouts.order_id != 0 OR payouts.payout_amount > 0)';
        } else {
            $condition .= ' AND payouts.payout_amount < 0';
        }
    }
    // Filter by vendor
    if (Registry::get('runtime.company_id')) {
        $params['vendor'] = Registry::get('runtime.company_id');
    }
    if (!empty($params['vendor']) && $params['vendor'] != 'all') {
        $condition .= db_quote(' AND payouts.company_id = ?i', $params['vendor']);
    }
    if (!empty($params['payment'])) {
        $condition .= db_quote(' AND payouts.payment_method like ?l', '%' . $params['payment'] . '%');
    }
    $sorting = db_sort($params, $sortings, 'sort_vendor', 'asc');
    $limit = '';
    $items = db_get_array("SELECT SQL_CALC_FOUND_ROWS * FROM ?:vendor_payouts AS payouts {$join} WHERE {$condition} AND {$date_condition} GROUP BY payouts.payout_id {$sorting} {$limit}");
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_found_rows();
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    // Calculate balance for the selected period
    $total = array('BCF' => 0, 'NO' => 0, 'TPP' => 0, 'LPM' => 0, 'TOB' => 0);
    $bcf_query = db_quote("SELECT SUM(payouts.order_amount) - SUM(payouts.payout_amount) * (-1) - SUM(payouts.commission_amount) AS BCF FROM ?:vendor_payouts AS payouts {$join} WHERE {$condition} AND payouts.start_date < ?i", $params['time_from']);
    $current_payouts_query = db_quote("SELECT SUM(payouts.order_amount) AS NO, SUM(payouts.payout_amount) * (-1) AS TTP, SUM(payouts.order_amount) - SUM(payouts.commission_amount) + SUM(payouts.payout_amount) AS LPM FROM ?:vendor_payouts AS payouts LEFT JOIN ?:orders AS orders ON (payouts.order_id = orders.order_id) WHERE {$condition} AND {$date_condition}");
    $payouts_query = db_quote("SELECT payouts.*, companies.company, IF(payouts.order_id <> 0,orders.total,payouts.payout_amount) AS payout_amount, IF(payouts.order_id <> 0, payouts.end_date, '') AS date FROM ?:vendor_payouts AS payouts {$join} WHERE {$condition} AND {$date_condition} GROUP BY payouts.payout_id {$sorting} {$limit}");
    fn_set_hook('mve_companies_get_payouts', $bcf_query, $current_payouts_query, $payouts_query, $join, $total, $condition, $date_condition);
    $payouts = db_get_array($payouts_query);
    $total['BCF'] += db_get_field($bcf_query);
    $current_payouts = db_get_row($current_payouts_query);
    $total['NO'] = $current_payouts['NO'];
    $total['TPP'] = $current_payouts['TTP'];
    $total['LPM'] = $current_payouts['LPM'];
    $total['TOB'] += fn_format_price($total['BCF'] + $total['LPM']);
    $total['LPM'] = $total['LPM'] < 0 ? 0 : $total['LPM'];
    $total['new_period_date'] = db_get_field('SELECT MAX(end_date) FROM ?:vendor_payouts');
    return array($payouts, $params, $total);
}
示例#22
0
function fn_get_rma_returns($params, $items_per_page = 0)
{
    // Init filter
    $params = LastView::instance()->update('rma', $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    // Define fields that should be retrieved
    $fields = array('DISTINCT ?:rma_returns.return_id', '?:rma_returns.order_id', '?:rma_returns.timestamp', '?:rma_returns.status', '?:rma_returns.total_amount', '?:rma_property_descriptions.property AS action', '?:users.firstname', '?:users.lastname');
    // Define sort fields
    $sortings = array('return_id' => "?:rma_returns.return_id", 'timestamp' => "?:rma_returns.timestamp", 'order_id' => "?:rma_returns.order_id", 'status' => "?:rma_returns.status", 'amount' => "?:rma_returns.total_amount", 'action' => "?:rma_returns.action", 'customer' => "?:users.lastname");
    $sorting = db_sort($params, $sortings, 'timestamp', 'desc');
    $join = $condition = $group = '';
    if (isset($params['cname']) && fn_string_not_empty($params['cname'])) {
        $arr = fn_explode(' ', $params['cname']);
        foreach ($arr as $k => $v) {
            if (!fn_string_not_empty($v)) {
                unset($arr[$k]);
            }
        }
        if (sizeof($arr) == 2) {
            $condition .= db_quote(" AND ?:users.firstname LIKE ?l AND ?:users.lastname LIKE ?l", "%" . array_shift($arr) . "%", "%" . array_shift($arr) . "%");
        } else {
            $condition .= db_quote(" AND (?:users.firstname LIKE ?l OR ?:users.lastname LIKE ?l)", "%" . trim($params['cname']) . "%", "%" . trim($params['cname']) . "%");
        }
    }
    if (isset($params['email']) && fn_string_not_empty($params['email'])) {
        $condition .= db_quote(" AND ?:users.email LIKE ?l", "%" . trim($params['email']) . "%");
    }
    if (isset($params['rma_amount_from']) && fn_is_numeric($params['rma_amount_from'])) {
        $condition .= db_quote("AND ?:rma_returns.total_amount >= ?d", $params['rma_amount_from']);
    }
    if (isset($params['rma_amount_to']) && fn_is_numeric($params['rma_amount_to'])) {
        $condition .= db_quote("AND ?:rma_returns.total_amount <= ?d", $params['rma_amount_to']);
    }
    if (!empty($params['action'])) {
        $condition .= db_quote(" AND ?:rma_returns.action = ?s", $params['action']);
    }
    if (!empty($params['return_id'])) {
        $condition .= db_quote(" AND ?:rma_returns.return_id = ?i", $params['return_id']);
    }
    if (!empty($params['request_status'])) {
        $condition .= db_quote(" AND ?:rma_returns.status IN (?a)", $params['request_status']);
    }
    if (!empty($params['period']) && $params['period'] != 'A') {
        list($params['time_from'], $params['time_to']) = fn_create_periods($params);
        $condition .= db_quote(" AND (?:rma_returns.timestamp >= ?i AND ?:rma_returns.timestamp <= ?i)", $params['time_from'], $params['time_to']);
    }
    if (!empty($params['order_id'])) {
        $condition .= db_quote(" AND ?:rma_returns.order_id = ?i", $params['order_id']);
    }
    if (isset($params['user_id'])) {
        $condition .= db_quote(" AND ?:rma_returns.user_id = ?i", $params['user_id']);
    }
    if (!empty($params['order_status'])) {
        $condition .= db_quote(" AND ?:orders.status IN (?a)", $params['order_status']);
    }
    if (!empty($params['p_ids']) || !empty($params['product_view_id'])) {
        $arr = strpos($params['p_ids'], ',') !== false || !is_array($params['p_ids']) ? explode(',', $params['p_ids']) : $params['p_ids'];
        if (empty($params['product_view_id'])) {
            $condition .= db_quote(" AND ?:order_details.product_id IN (?n)", $arr);
        } else {
            $condition .= db_quote(" AND ?:order_details.product_id IN (?n)", db_get_fields(fn_get_products(array('view_id' => $params['product_view_id'], 'get_query' => true))));
        }
        $join .= " LEFT JOIN ?:order_details ON ?:order_details.order_id = ?:orders.order_id";
        $group .= db_quote(" GROUP BY ?:rma_returns.return_id HAVING COUNT(?:orders.order_id) >= ?i", count($arr));
    }
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(DISTINCT ?:rma_returns.return_id) FROM ?:rma_returns LEFT JOIN ?:rma_return_products ON ?:rma_return_products.return_id = ?:rma_returns.return_id LEFT JOIN ?:rma_property_descriptions ON ?:rma_property_descriptions.property_id = ?:rma_returns.action LEFT JOIN ?:users ON ?:rma_returns.user_id = ?:users.user_id LEFT JOIN ?:orders ON ?:rma_returns.order_id = ?:orders.order_id {$join} WHERE 1 {$condition} {$group}");
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $return_requests = db_get_array("SELECT " . implode(', ', $fields) . " FROM ?:rma_returns LEFT JOIN ?:rma_return_products ON ?:rma_return_products.return_id = ?:rma_returns.return_id LEFT JOIN ?:rma_property_descriptions ON (?:rma_property_descriptions.property_id = ?:rma_returns.action AND ?:rma_property_descriptions.lang_code = ?s) LEFT JOIN ?:users ON ?:rma_returns.user_id = ?:users.user_id LEFT JOIN ?:orders ON ?:rma_returns.order_id = ?:orders.order_id {$join} WHERE 1 {$condition} {$group} {$sorting} {$limit}", AREA == 'C' ? CART_LANGUAGE : DESCR_SL);
    LastView::instance()->processResults('rma_returns', $return_requests, $params);
    return array($return_requests, $params);
}
示例#23
0
/**
 * Gets company data array
 *
 * @param array $params Array of search params:
 * <ul>
 *		  <li>string company - Name of company</li>
 *		  <li>string status - Status of company</li>
 *		  <li>string email - Email of company</li>
 *		  <li>string address - Address of company</li>
 *		  <li>string zipcode - Zipcode of company</li>
 *		  <li>string country - 2-letters country code of company country</li>
 *		  <li>string state - State code of company</li>
 *		  <li>string city - City of company</li>
 *		  <li>string phone - Phone of company</li>
 *		  <li>string url - URL address of company</li>
 *		  <li>string fax - Fax number of company</li>
 *		  <li>mixed company_id - Company ID, array with company IDs or comma-separated list of company IDs.
 * If defined, data will be returned only for companies with such company IDs.</li>
 *		  <li>int exclude_company_id - Company ID, if defined,
 * result array will not include the data for company with such company ID.</li>
 *		  <li>int page - First page to displaying list of companies (if <i>$items_per_page</i> it not empty.</li>
 *		  <li>string sort_order - <i>ASC</i> or <i>DESC</i>: database query sorting order</li>
 *		  <li>string sort_by - One or list of database fields for sorting.</li>
 * </ul>
 * @param array $auth Array of user authentication data (e.g. uid, usergroup_ids, etc.)
 * @param int $items_per_page
 * @param string $lang_code 2-letter language code (e.g. 'en', 'ru', etc.)
 * @return array Array:
 * <ul>
 *		<li>0 - First element is array with companies data.</li>
 *		<li>1 - is possibly modified array with searh params (<i>$params</i>).</li>
 * </ul>
 */
function fn_get_companies($params, &$auth, $items_per_page = 0, $lang_code = CART_LANGUAGE)
{
    // Init filter
    $_view = 'companies';
    $params = LastView::instance()->update($_view, $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    // Define fields that should be retrieved
    $fields = array('?:companies.company_id', '?:companies.lang_code', '?:companies.email', '?:companies.company', '?:companies.timestamp', '?:companies.status');
    if (fn_allowed_for('ULTIMATE')) {
        $fields[] = '?:companies.storefront';
        $fields[] = '?:companies.secure_storefront';
    }
    // Define sort fields
    $sortings = array('id' => '?:companies.company_id', 'company' => '?:companies.company', 'email' => '?:companies.email', 'date' => '?:companies.timestamp', 'status' => '?:companies.status');
    if (fn_allowed_for('ULTIMATE')) {
        $sortings['storefront'] = '?:companies.storefront';
    }
    $condition = $join = $group = '';
    $condition .= fn_get_company_condition('?:companies.company_id');
    $group .= " GROUP BY ?:companies.company_id";
    if (isset($params['company']) && fn_string_not_empty($params['company'])) {
        $condition .= db_quote(" AND ?:companies.company LIKE ?l", "%" . trim($params['company']) . "%");
    }
    if (!empty($params['status'])) {
        if (is_array($params['status'])) {
            $condition .= db_quote(" AND ?:companies.status IN (?a)", $params['status']);
        } else {
            $condition .= db_quote(" AND ?:companies.status = ?s", $params['status']);
        }
    }
    if (isset($params['email']) && fn_string_not_empty($params['email'])) {
        $condition .= db_quote(" AND ?:companies.email LIKE ?l", "%" . trim($params['email']) . "%");
    }
    if (isset($params['address']) && fn_string_not_empty($params['address'])) {
        $condition .= db_quote(" AND ?:companies.address LIKE ?l", "%" . trim($params['address']) . "%");
    }
    if (isset($params['zipcode']) && fn_string_not_empty($params['zipcode'])) {
        $condition .= db_quote(" AND ?:companies.zipcode LIKE ?l", "%" . trim($params['zipcode']) . "%");
    }
    if (!empty($params['country'])) {
        $condition .= db_quote(" AND ?:companies.country = ?s", $params['country']);
    }
    if (isset($params['state']) && fn_string_not_empty($params['state'])) {
        $condition .= db_quote(" AND ?:companies.state LIKE ?l", "%" . trim($params['state']) . "%");
    }
    if (isset($params['city']) && fn_string_not_empty($params['city'])) {
        $condition .= db_quote(" AND ?:companies.city LIKE ?l", "%" . trim($params['city']) . "%");
    }
    if (isset($params['phone']) && fn_string_not_empty($params['phone'])) {
        $condition .= db_quote(" AND ?:companies.phone LIKE ?l", "%" . trim($params['phone']) . "%");
    }
    if (isset($params['url']) && fn_string_not_empty($params['url'])) {
        $condition .= db_quote(" AND ?:companies.url LIKE ?l", "%" . trim($params['url']) . "%");
    }
    if (isset($params['fax']) && fn_string_not_empty($params['fax'])) {
        $condition .= db_quote(" AND ?:companies.fax LIKE ?l", "%" . trim($params['fax']) . "%");
    }
    if (!empty($params['company_id'])) {
        $condition .= db_quote(' AND ?:companies.company_id IN (?n)', $params['company_id']);
    }
    if (!empty($params['exclude_company_id'])) {
        $condition .= db_quote(' AND ?:companies.company_id != ?i', $params['exclude_company_id']);
    }
    fn_set_hook('get_companies', $params, $fields, $sortings, $condition, $join, $auth, $lang_code, $group);
    $sorting = db_sort($params, $sortings, 'company', 'asc');
    // Paginate search results
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(DISTINCT(?:companies.company_id)) FROM ?:companies {$join} WHERE 1 {$condition}");
        $limit = db_paginate($params['page'], $params['items_per_page']);
    }
    $companies = db_get_array("SELECT " . implode(', ', $fields) . " FROM ?:companies {$join} WHERE 1 {$condition} {$group} {$sorting} {$limit}");
    return array($companies, $params);
}
示例#24
0
/**
 * Returns store logs
 *
 * @param array $params Search parameters
 * @param int $items_per_page Logs limit
 * @return array Logs with search parameters
 */
function fn_get_logs($params, $items_per_page = 0)
{
    // Init filter
    $params = LastView::instance()->update('logs', $params);
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    $sortings = array('timestamp' => array('?:logs.timestamp', '?:logs.log_id'), 'user' => array('?:users.lastname', '?:users.firstname'));
    $fields = array('?:logs.*', '?:users.firstname', '?:users.lastname');
    $sorting = db_sort($params, $sortings, 'timestamp', 'desc');
    $join = "LEFT JOIN ?:users USING(user_id)";
    $condition = '';
    if (!empty($params['period']) && $params['period'] != 'A') {
        list($time_from, $time_to) = fn_create_periods($params);
        $condition .= db_quote(" AND (?:logs.timestamp >= ?i AND ?:logs.timestamp <= ?i)", $time_from, $time_to);
    }
    if (isset($params['q_user']) && fn_string_not_empty($params['q_user'])) {
        $condition .= db_quote(" AND (?:users.lastname LIKE ?l OR ?:users.firstname LIKE ?l)", "%" . trim($params['q_user']) . "%", "%" . trim($params['q_user']) . "%");
    }
    if (!empty($params['q_type'])) {
        $condition .= db_quote(" AND ?:logs.type = ?s", $params['q_type']);
    }
    if (!empty($params['q_action'])) {
        $condition .= db_quote(" AND ?:logs.action = ?s", $params['q_action']);
    }
    if (Registry::get('runtime.company_id')) {
        $condition .= db_quote(" AND ?:logs.company_id = ?i", Registry::get('runtime.company_id'));
    }
    fn_set_hook('admin_get_logs', $params, $condition, $join, $sorting);
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(DISTINCT(?:logs.log_id)) FROM ?:logs ?p WHERE 1 ?p", $join, $condition);
        $limit = db_paginate($params['page'], $params['items_per_page']);
    }
    $data = db_get_array("SELECT " . join(', ', $fields) . " FROM ?:logs ?p WHERE 1 ?p {$sorting} {$limit}", $join, $condition);
    foreach ($data as $k => $v) {
        $data[$k]['backtrace'] = !empty($v['backtrace']) ? unserialize($v['backtrace']) : array();
        $data[$k]['content'] = !empty($v['content']) ? unserialize($v['content']) : array();
    }
    return array($data, $params);
}
示例#25
0
function fn_em_get_subscribers($params, $items_per_page = 0, $lang_code = CART_LANGUAGE)
{
    // Init filter
    $params = LastView::instance()->update('em_subscribers', $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    // Define fields that should be retrieved
    $fields = array('?:em_subscribers.subscriber_id', '?:em_subscribers.email', '?:em_subscribers.timestamp', '?:em_subscribers.name', '?:em_subscribers.unsubscribe_key', '?:em_subscribers.status');
    // Define sort fields
    $sortings = array('email' => '?:em_subscribers.email', 'name' => '?:em_subscribers.name', 'status' => '?:em_subscribers.status', 'timestamp' => '?:em_subscribers.timestamp');
    $condition = '';
    $group_by = '';
    $join = '';
    if (!empty($params['subscriber_id'])) {
        $condition .= db_quote(" AND ?:em_subscribers.subscriber_id = ?i", $params['subscriber_id']);
    }
    if (isset($params['email']) && fn_string_not_empty($params['email'])) {
        $condition .= db_quote(" AND ?:em_subscribers.email LIKE ?l", "%" . trim($params['email']) . "%");
    }
    if (!empty($params['status'])) {
        $condition .= db_quote(" AND ?:em_subscribers.status = ?s", $params['status']);
    }
    if (!empty($params['name'])) {
        $condition .= db_quote(" AND ?:em_subscribers.name LIKE ?l", "%" . $params['name'] . "%");
    }
    if (!empty($params['lang_code'])) {
        $condition .= db_quote(" AND ?:em_subscribers.lang_code = ?s", $params['lang_code']);
    }
    if (!empty($params['period']) && $params['period'] != 'A') {
        list($params['time_from'], $params['time_to']) = fn_create_periods($params);
        $condition .= db_quote(" AND (?:em_subscribers.timestamp >= ?i AND ?:em_subscribers.timestamp <= ?i)", $params['time_from'], $params['time_to']);
    }
    $condition .= fn_em_get_company_condition();
    $sorting = db_sort($params, $sortings, 'timestamp', 'desc');
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(?:em_subscribers.subscriber_id) FROM ?:em_subscribers {$join} WHERE 1 {$condition}");
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $subscribers = db_get_array('SELECT ' . implode(', ', $fields) . " FROM ?:em_subscribers {$join} WHERE 1 {$condition} {$group_by} {$sorting} {$limit}");
    return array($subscribers, $params);
}
示例#26
0
/**
 * Gets addons list
 *
 * @param array $params search params
 * @param int $items_per_page items per page for pagination
 * @param string $lang_code language code
 * @return array addons list and filtered search params
 */
function fn_get_addons($params, $items_per_page = 0, $lang_code = CART_LANGUAGE)
{
    $params = LastView::instance()->update('addons', $params);
    $addons_counter = array('installed' => 0, 'activated' => 0, 'core' => 0, 'other' => 0);
    $default_params = array('type' => 'any');
    $params = array_merge($default_params, $params);
    $addons = array();
    $sections = Settings::instance()->getAddons();
    $all_addons = fn_get_dir_contents(Registry::get('config.dir.addons'), true, false);
    $installed_addons = db_get_hash_array('SELECT a.addon, a.status, b.name as name, b.description as description, a.separate, a.unmanaged, a.has_icon, a.install_datetime ' . 'FROM ?:addons as a LEFT JOIN ?:addon_descriptions as b ON b.addon = a.addon AND b.lang_code = ?s' . 'ORDER BY b.name ASC', 'addon', $lang_code);
    $addons_counter['installed'] = count($installed_addons);
    foreach ($installed_addons as $key => $addon) {
        $installed_addons[$key]['has_sections'] = Settings::instance()->sectionExists($sections, $addon['addon']);
        $installed_addons[$key]['has_options'] = $installed_addons[$key]['has_sections'] ? Settings::instance()->optionsExists($addon['addon'], 'ADDON') : false;
        // Check add-on snaphot
        if (!fn_check_addon_snapshot($key)) {
            $installed_addons[$key]['status'] = 'D';
            $installed_addons[$key]['snapshot_correct'] = false;
        } else {
            $installed_addons[$key]['snapshot_correct'] = true;
        }
        if ($installed_addons[$key]['status'] == 'A') {
            $addons_counter['activated']++;
        }
    }
    foreach ($all_addons as $addon) {
        $addon_scheme = SchemesManager::getScheme($addon);
        // skip addons with broken or missing scheme
        if (!$addon_scheme) {
            continue;
        }
        if ($addon_scheme->isCoreAddon()) {
            $addons_counter['core']++;
        } else {
            $addons_counter['other']++;
        }
        if (in_array($params['type'], array('any', 'installed', 'active', 'disabled'))) {
            $search_status = $params['type'] == 'active' ? 'A' : ($params['type'] == 'disabled' ? 'D' : '');
            if (!empty($installed_addons[$addon])) {
                // exclude unmanaged addons from the list
                if ($installed_addons[$addon]['unmanaged'] == true) {
                    continue;
                }
                if (!empty($search_status) && $installed_addons[$addon]['status'] != $search_status) {
                    continue;
                }
                $addons[$addon] = $installed_addons[$addon];
                $addons[$addon]['supplier'] = $addon_scheme->getSupplier();
                $addons[$addon]['supplier_link'] = $addon_scheme->getSupplierLink();
                $addons[$addon]['version'] = $addon_scheme->getVersion();
                $addons[$addon]['is_core_addon'] = $addon_scheme->isCoreAddon();
                $addons[$addon]['delete_url'] = '';
                $addons[$addon]['url'] = fn_url("addons.update?addon={$addon}&return_url=" . urlencode(Registry::get('config.current_url')));
                if (!Registry::get('runtime.company_id')) {
                    $addons[$addon]['delete_url'] = fn_url("addons.uninstall?addon={$addon}&redirect_url=" . urlencode(Registry::get('config.current_url')));
                }
                if ($addon_scheme != false && !$addon_scheme->getUnmanaged()) {
                    $addons[$addon]['originals'] = $addon_scheme->getOriginals();
                }
                fn_update_lang_objects('installed_addon', $addons[$addon]);
                if (is_file(Registry::get('config.dir.addons') . $addon . '/func.php')) {
                    require_once Registry::get('config.dir.addons') . $addon . '/func.php';
                    if (is_file(Registry::get('config.dir.addons') . $addon . '/config.php')) {
                        require_once Registry::get('config.dir.addons') . $addon . '/config.php';
                    }
                    // Generate custom description
                    $func = 'fn_addon_dynamic_description_' . $addon;
                    if (function_exists($func)) {
                        $addons[$addon]['description'] = $func($addons[$addon]['description']);
                    }
                    //Generate custom url
                    $url_func = 'fn_addon_dynamic_url_' . $addon;
                    if (function_exists($url_func)) {
                        list($addons[$addon]['url'], $addons[$addon]['delete_url']) = $url_func($addons[$addon]['url'], $addons[$addon]['delete_url']);
                    }
                }
            }
        }
        if (empty($installed_addons[$addon]) && empty($params['for_company']) && in_array($params['type'], array('any', 'not_installed'))) {
            if ($addon_scheme != false && !$addon_scheme->getUnmanaged()) {
                $addons[$addon] = array('status' => 'N', 'name' => $addon_scheme->getName(), 'version' => $addon_scheme->getVersion(), 'supplier' => $addon_scheme->getSupplier(), 'supplier_link' => $addon_scheme->getSupplierLink(), 'snapshot_correct' => fn_check_addon_snapshot($addon), 'description' => $addon_scheme->getDescription(), 'has_icon' => $addon_scheme->hasIcon(), 'is_core_addon' => $addon_scheme->isCoreAddon(), 'install_datetime' => null);
            }
        }
    }
    if (!empty($params['q'])) {
        foreach ($addons as $addon => $addon_data) {
            if (!preg_match('/' . preg_quote($params['q'], '/') . '/ui', $addon_data['name'] . $addon_data['supplier'], $m)) {
                unset($addons[$addon]);
            }
        }
    }
    if (!empty($params['source'])) {
        $is_core_addon = $params['source'] == 'core';
        foreach ($addons as $addon => $addon_data) {
            if ($is_core_addon != $addon_data['is_core_addon']) {
                unset($addons[$addon]);
            }
        }
    }
    $addons = fn_sort_array_by_key($addons, 'name', SORT_ASC);
    return array($addons, $params, $addons_counter);
}
示例#27
0
文件: func.php 项目: arpad9/bygmarket
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);
    /**
     * Change parameters for getting tags
     *
     * @param array $params Params list
     * @param int $items_per_page Tags per page
     * @param array $default_params Default params
     */
    fn_set_hook('get_tags_pre', $params, $items_per_page, $default_params);
    $params = array_merge($default_params, $params);
    $fields = array('?:tags.tag_id', '?:tag_links.object_id', '?:tag_links.object_type', '?:tags.tag', '?:tags.status', 'COUNT(?:tag_links.tag_id) as popularity');
    $joins = array('LEFT JOIN ?:tag_links ON ?:tag_links.tag_id = ?:tags.tag_id');
    $conditions = fn_tags_build_conditions($params);
    // Define sort fields
    $sortings = array('tag' => '?:tags.tag', 'status' => '?:tags.status', 'popularity' => 'popularity', 'users' => 'users');
    $sorting = db_sort($params, $sortings, 'tag', 'asc');
    $group = 'GROUP BY ?:tags.tag_id';
    /**
     * Gets tags
     *
     * @param array $params Params list
     * @param int $items_per_page Tags per page
     * @param array $fields List of SQL fields to be selected in an SQL-query
     * @param array $joins List of strings with the complete JOIN information (JOIN type, tables and fields) for an SQL-query
     * @param string $conditions String containing the SQL-query conditions prepended with a logical operator (AND or OR)
     * @param string $group String containing the SQL-query GROUP BY field
     * @param string $sorting String containing the SQL-query ORDER BY field
     */
    fn_set_hook('get_tags', $params, $items_per_page, $fields, $joins, $conditions, $group, $sorting);
    $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 " . implode(', ', $fields) . " " . "FROM ?:tags " . implode(' ', $joins) . " WHERE 1 ?p {$group} {$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);
    }
    /**
     * Change tags
     *
     * @param array $params Params list
     * @param int $items_per_page Tags per page
     * @param array $tags Tags
     */
    fn_set_hook('get_tags_post', $params, $items_per_page, $tags);
    return array($tags, $params);
}
示例#28
0
function fn_get_subscribers($params, $items_per_page = 0, $lang_code = CART_LANGUAGE)
{
    // Init filter
    $params = LastView::instance()->update('subscribers', $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    // Define fields that should be retrieved
    $fields = array('?:subscribers.subscriber_id', '?:subscribers.email', '?:subscribers.timestamp', '?:subscribers.subscriber_id', "GROUP_CONCAT(?:user_mailing_lists.list_id) as list_ids");
    // Define sort fields
    $sortings = array('email' => '?:subscribers.email', 'timestamp' => '?:subscribers.timestamp');
    $condition = '';
    $group_by = "?:subscribers.subscriber_id";
    $join = db_quote(" LEFT JOIN ?:user_mailing_lists ON ?:user_mailing_lists.subscriber_id = ?:subscribers.subscriber_id");
    if (isset($params['email']) && fn_string_not_empty($params['email'])) {
        $condition .= db_quote(" AND ?:subscribers.email LIKE ?l", "%" . trim($params['email']) . "%");
    }
    if (!empty($params['list_id'])) {
        $condition .= db_quote(" AND ?:user_mailing_lists.list_id = ?i", $params['list_id']);
    }
    if (!empty($params['confirmed'])) {
        $condition .= db_quote(" AND ?:user_mailing_lists.confirmed = ?i", $params['confirmed'] == 'Y');
    }
    if (!empty($params['language'])) {
        $condition .= db_quote(" AND ?:user_mailing_lists.lang_code = ?s", $params['language']);
    }
    if (!empty($params['period']) && $params['period'] != 'A') {
        list($params['time_from'], $params['time_to']) = fn_create_periods($params);
        $condition .= db_quote(" AND (?:subscribers.timestamp >= ?i AND ?:subscribers.timestamp <= ?i)", $params['time_from'], $params['time_to']);
    }
    $sorting = db_sort($params, $sortings, 'timestamp', 'desc');
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_field("SELECT COUNT(DISTINCT(?:subscribers.subscriber_id)) FROM ?:subscribers {$join} WHERE 1 {$condition}");
        $limit = db_paginate($params['page'], $params['items_per_page'], $params['total_items']);
    }
    $subscribers = db_get_array('SELECT ' . implode(', ', $fields) . " FROM ?:subscribers {$join} WHERE 1 {$condition} GROUP BY {$group_by} {$sorting} {$limit}");
    return array($subscribers, $params);
}
示例#29
0
 public function findMany($params = array())
 {
     $this->beforeFind($params);
     $params = array_merge($this->params, $params);
     // Init filter
     if ($last_view_object_name = $this->getLastViewObjectName()) {
         $params = LastView::instance()->update($last_view_object_name, $params);
     }
     $fields = new Fields($this, $params);
     $sorting = new Sorting($this, $params);
     $joins = new Joins($this, $params);
     $condition = new Condition($this, $params, $joins);
     $this->prepareQuery($params, $fields->result, $sorting->result, $joins->result, $condition->result);
     $limit = new Limit($this, $params, $joins, $condition);
     if (!empty($params['get_count']) && isset($params['total_items'])) {
         return $params['total_items'];
     }
     $query_foundation = " FROM " . $this->getTableName() . $joins->get() . $condition->get() . $sorting->get() . $limit->get();
     if (!empty($params['get_ids'])) {
         return db_get_fields("SELECT " . $this->getTableName() . "." . $this->getPrimaryField() . $query_foundation);
     }
     $items = db_get_array("SELECT " . $fields->get() . $query_foundation);
     $this->gatherAdditionalItemsData($items, $params);
     if (!empty($params['to_array'])) {
         $models = $items;
     } else {
         $models = $this->loadMany($items, true);
     }
     if (!empty($params['return_params'])) {
         return array($models, $params);
     }
     return $models;
 }
示例#30
0
文件: cart.php 项目: askzap/ultimate
function fn_get_carts($params, $items_per_page = 0)
{
    // Init filter
    $params = LastView::instance()->update('carts', $params);
    // Set default values to input params
    $default_params = array('page' => 1, 'items_per_page' => $items_per_page);
    $params = array_merge($default_params, $params);
    // Define fields that should be retrieved
    $fields = array('?:user_session_products.user_id', '?:users.firstname', '?:users.lastname', '?:user_session_products.timestamp AS date');
    // Define sort fields
    $sortings = array('customer' => "CONCAT(?:users.lastname, ?:users.firstname)", 'date' => "?:user_session_products.timestamp");
    if (fn_allowed_for('ULTIMATE')) {
        $sortings['company_id'] = "?:user_session_products.company_id";
    }
    $sorting = db_sort($params, $sortings, 'customer', 'asc');
    $condition = $join = '';
    $group = " GROUP BY ?:user_session_products.user_id";
    $group_post = '';
    if (isset($params['cname']) && fn_string_not_empty($params['cname'])) {
        $arr = fn_explode(' ', $params['cname']);
        foreach ($arr as $k => $v) {
            if (!fn_string_not_empty($v)) {
                unset($arr[$k]);
            }
        }
        if (sizeof($arr) == 2) {
            $condition .= db_quote(" AND ?:users.firstname LIKE ?l AND ?:users.lastname LIKE ?l", "%" . array_shift($arr) . "%", "%" . array_shift($arr) . "%");
        } else {
            $condition .= db_quote(" AND (?:users.firstname LIKE ?l OR ?:users.lastname LIKE ?l)", "%" . trim($params['cname']) . "%", "%" . trim($params['cname']) . "%");
        }
    }
    if (isset($params['email']) && fn_string_not_empty($params['email'])) {
        $condition .= db_quote(" AND ?:users.email LIKE ?l", "%" . trim($params['email']) . "%");
    }
    if (!empty($params['user_id'])) {
        $condition .= db_quote(" AND ?:user_session_products.user_id = ?i", $params['user_id']);
    }
    if (!empty($params['online_only'])) {
        $sessions = Session::getOnline('C');
        if (!empty($sessions)) {
            $condition .= db_quote(" AND ?:user_session_products.session_id IN (?a)", $sessions);
        } else {
            $condition .= db_quote(" AND 0");
        }
    }
    if (!empty($params['with_info_only'])) {
        $condition .= db_quote(" AND ?:users.email != ''");
    }
    if (!empty($params['users_type'])) {
        if ($params['users_type'] == 'R') {
            $condition .= db_quote(" AND !ISNULL(?:users.user_id)");
        } elseif ($params['users_type'] == 'G') {
            $condition .= db_quote(" AND ISNULL(?:users.user_id)");
        }
    }
    if (!empty($params['total_from']) || !empty($params['total_to'])) {
        $having = '';
        if (fn_is_numeric($params['total_from'])) {
            $having .= db_quote(" AND SUM(price * amount) >= ?d", $params['total_from']);
        }
        if (fn_is_numeric($params['total_to'])) {
            $having .= db_quote(" AND SUM(price * amount) <= ?d", $params['total_to']);
        }
        if (!empty($having)) {
            $users4total = db_get_fields("SELECT user_id FROM ?:user_session_products GROUP BY user_id HAVING 1 {$having}");
            if (!empty($users4total)) {
                $condition .= db_quote(" AND (?:user_session_products.user_id IN (?n))", $users4total);
            } else {
                $condition .= " AND (?:user_session_products.user_id = 'no')";
            }
        }
    }
    if (!empty($params['period']) && $params['period'] != 'A') {
        list($params['time_from'], $params['time_to']) = fn_create_periods($params);
        $condition .= db_quote(" AND (?:user_session_products.timestamp >= ?i AND ?:user_session_products.timestamp <= ?i)", $params['time_from'], $params['time_to']);
    }
    $_condition = array();
    if (!empty($params['product_type_c'])) {
        $_condition[] = "?:user_session_products.type = 'C'";
    }
    if (!empty($params['product_type_w']) && $params['product_type_w'] == 'Y') {
        $_condition[] = "?:user_session_products.type = 'W'";
    }
    if (!empty($_condition)) {
        $condition .= " AND (" . implode(" OR ", $_condition) . ")";
    }
    if (!empty($params['p_ids']) || !empty($params['product_view_id'])) {
        $arr = strpos($params['p_ids'], ',') !== false || !is_array($params['p_ids']) ? explode(',', $params['p_ids']) : $params['p_ids'];
        if (empty($params['product_view_id'])) {
            $condition .= db_quote(" AND ?:user_session_products.product_id IN (?n)", $arr);
        } else {
            $condition .= db_quote(" AND ?:user_session_products.product_id IN (?n)", db_get_fields(fn_get_products(array('view_id' => $params['product_view_id'], 'get_query' => true))));
        }
        $group_post .= " HAVING COUNT(?:user_session_products.user_id) >= " . count($arr);
    }
    $join .= " LEFT JOIN ?:users ON ?:user_session_products.user_id = ?:users.user_id";
    // checking types for retrieving from the database
    $type_restrictions = array('C');
    fn_set_hook('get_carts', $type_restrictions, $params, $condition, $join, $fields, $group, $array_index_field);
    if (!empty($type_restrictions) && is_array($type_restrictions)) {
        $condition .= " AND ?:user_session_products.type IN ('" . implode("', '", $type_restrictions) . "')";
    }
    $carts_list = array();
    $group .= $group_post;
    $limit = '';
    if (!empty($params['items_per_page'])) {
        $limit = db_paginate($params['page'], $params['items_per_page']);
    }
    if (fn_allowed_for('ULTIMATE')) {
        $group = " GROUP BY ?:user_session_products.user_id, ?:user_session_products.company_id";
    }
    $carts_list = db_get_array("SELECT SQL_CALC_FOUND_ROWS " . implode(', ', $fields) . " FROM ?:user_session_products {$join} WHERE 1 {$condition} {$group} {$sorting} {$limit}");
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = db_get_found_rows();
    }
    unset($_SESSION['abandoned_carts']);
    return array($carts_list, $params);
}