Example #1
0
function main_prd($params)
{
    global $tpl, $template, $twig, $SYSTEM_FLAGS, $config, $userROW, $mysql, $twigLoader;
    $results = array();
    $params = arrayCharsetConvert(1, $params);
    $number = $params['number'];
    $mode = $params['mode'];
    $cat = $params['cat'];
    $overrideTemplateName = $params['template'];
    $prd_per_page = $number;
    $page = $params['page'];
    switch ($params['action']) {
        // **** ADD NEW ITEM INTO compare ****
        case 'show':
            $conditions = array();
            if (isset($cat) && !empty($cat)) {
                array_push($conditions, "c.id IN (" . $cat . ") ");
            }
            array_push($conditions, "p.active = 1");
            if ($number < 1 || $number > 100) {
                $number = 5;
            }
            switch ($mode) {
                case 'view':
                    $orderby = " ORDER BY p.view DESC ";
                    break;
                case 'last':
                    $orderby = " ORDER BY p.editdate DESC ";
                    break;
                case 'stocked':
                    array_push($conditions, "p.stocked = 1");
                    $orderby = " ORDER BY p.editdate DESC ";
                    break;
                case 'featured':
                    array_push($conditions, "p.featured = 1");
                    $orderby = " ORDER BY p.editdate DESC ";
                    break;
                case 'rnd':
                    $cacheDisabled = true;
                    $orderby = " ORDER BY RAND() DESC ";
                    break;
                default:
                    $mode = 'last';
                    $orderby = " ORDER BY p.editdate DESC ";
                    break;
            }
            $fSort = " " . $orderby;
            $sqlQPart = "FROM " . prefix . "_eshop_products p LEFT JOIN " . prefix . "_eshop_products_categories pc ON p.id = pc.product_id LEFT JOIN " . prefix . "_eshop_categories c ON pc.category_id = c.id " . (count($conditions) ? "WHERE " . implode(" AND ", $conditions) : '') . $fSort;
            $sqlQCount = "SELECT COUNT(p.id) " . $sqlQPart;
            $sqlQ = "SELECT p.id AS id, p.url as url, p.code AS code, p.name AS name, p.annotation AS annotation, p.body AS body, p.active AS active, p.featured AS featured, p.stocked AS stocked, p.position AS position, p.meta_title AS meta_title, p.meta_keywords AS meta_keywords, p.meta_description AS meta_description, p.date AS date, p.editdate AS editdate, p.views AS views, c.id AS cid, c.url as curl, c.name AS category " . $sqlQPart;
            $entries = array();
            $pageNo = intval($page) ? $page : 0;
            if ($pageNo < 1) {
                $pageNo = 1;
            }
            if (!$start_from) {
                $start_from = ($pageNo - 1) * $prd_per_page;
            }
            $count = $mysql->result($sqlQCount);
            $countPages = ceil($count / $prd_per_page);
            $cmp_array = array();
            foreach ($SYSTEM_FLAGS["eshop"]["compare"]["entries"] as $cmp_row) {
                $cmp_array[] = $cmp_row['linked_fld'];
            }
            foreach ($mysql->select($sqlQ . ' LIMIT ' . $start_from . ', ' . $prd_per_page) as $row) {
                $fulllink = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $row['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $row['url']));
                $catlink = checkLinkAvailable('eshop', '') ? generateLink('eshop', '', array('alt' => $row['curl'])) : generateLink('core', 'plugin', array('plugin' => 'eshop'), array('alt' => $row['curl']));
                $cmp_flag = in_array($row['id'], $cmp_array);
                $entries[$row['id']] = array('id' => $row['id'], 'code' => $row['code'], 'name' => $row['name'], 'annotation' => $row['annotation'], 'body' => $row['body'], 'active' => $row['active'], 'featured' => $row['featured'], 'meta_title' => $row['meta_title'], 'meta_keywords' => $row['meta_keywords'], 'meta_description' => $row['meta_description'], 'fulllink' => $fulllink, 'date' => empty($row['date']) ? '' : $row['date'], 'editdate' => empty($row['editdate']) ? '' : $row['editdate'], 'views' => $row['views'], 'cat_name' => $row['category'], 'cid' => $row['cid'], 'catlink' => $catlink, 'compare' => $cmp_flag, 'home' => home, 'tpl_url' => home . '/templates/' . $config['theme']);
            }
            $entries_array_ids = array_keys($entries);
            if (isset($entries_array_ids) && !empty($entries_array_ids)) {
                $entries_string_ids = implode(',', $entries_array_ids);
                foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_images i WHERE i.product_id IN (' . $entries_string_ids . ') ORDER BY i.position, i.id') as $irow) {
                    $entries[$irow['product_id']]['images'][] = $irow;
                }
                foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_variants v WHERE v.product_id IN (' . $entries_string_ids . ') ORDER BY v.position, v.id') as $vrow) {
                    $entries[$vrow['product_id']]['variants'][] = $vrow;
                }
            }
            $tVars = array('info' => isset($info) ? $info : '', 'entries' => isset($entries) ? $entries : '', 'tpl_url' => home . '/templates/' . $config['theme'], 'tpl_home' => admin_url);
            if ($overrideTemplateName) {
                $templateName = 'block/' . $overrideTemplateName;
            } else {
                $templateName = 'block/main_block_eshop';
            }
            // Determine paths for all template files
            $tpath = locatePluginTemplates(array($templateName), 'eshop', pluginGetVariable('eshop', 'localsource'));
            // Preload template configuration variables
            @templateLoadVariables();
            $tVars['mode'] = $mode;
            $tVars['number'] = $number;
            $tVars['tpl_url'] = tpl_url;
            $tVars['home'] = home;
            $tVars['pagesss'] = generateLP(array('current' => $pageNo, 'count' => $countPages, 'url' => '#', 'tpl' => $templateName . '_pages'));
            $xt = $twig->loadTemplate($tpath[$templateName] . $templateName . '.tpl');
            if (empty($row)) {
                $results = array('prd_main' => 2, 'prd_main_text' => iconv('Windows-1251', 'UTF-8', 'Нет продукции!'), 'prd_main_pages_text' => iconv('Windows-1251', 'UTF-8', ''));
            } else {
                $results = array('prd_main' => 100, 'prd_main_text' => iconv('Windows-1251', 'UTF-8', $xt->render($tVars)), 'prd_main_pages_text' => iconv('Windows-1251', 'UTF-8', $tVars['pagesss']));
            }
            break;
    }
    return array('status' => 1, 'errorCode' => 0, 'data' => $results);
}
Example #2
0
/**
 * 转换数组中所有元素的字符集
 * @param array $array 源数组
 * @param string $to 目标字符集
 * @param string $from 源字符集
 */
function arrayCharsetConvert(&$array, $to, $from = 'GBK')
{
    if (is_array($array)) {
        foreach ($array as $key => $item) {
            if (is_array($item)) {
                arrayCharsetConvert($array[$key], $to, $from);
            } else {
                $array[$key] = iconv($from, $to, $item);
            }
        }
    }
}
Example #3
0
function ebasket_rpc_manage($params)
{
    global $userROW, $DSlist, $mysql, $twig;
    LoadPluginLibrary('xfields', 'common');
    if (!is_array($params) || !isset($params['action'])) {
        return array('status' => 0, 'errorCode' => 1, 'errorText' => 'Activity mode is not set');
    }
    $params = arrayCharsetConvert(1, $params);
    switch ($params['action']) {
        // **** ADD NEW ITEM INTO ebasket ****
        case 'add':
            $linked_ds = intval($params['ds']);
            $linked_id = intval($params['id']);
            $count = intval($params['count']);
            // Check available DataSources
            if (!in_array($linked_ds, array($DSlist['news']))) {
                return array('status' => 0, 'errorCode' => 2, 'errorText' => 'ebasket can be used only for NEWS');
            }
            // Check available DataSources
            if ($count < 1) {
                return array('status' => 0, 'errorCode' => 2, 'errorText' => 'Count should be positive');
            }
            // Check if linked item is available
            switch ($linked_ds) {
                case $DSlist['news']:
                    $conditions = array();
                    if ($linked_id) {
                        array_push($conditions, "p.id = " . db_squote($linked_id));
                    }
                    $fSort = " GROUP BY p.id ORDER BY p.id DESC";
                    $sqlQPart = "FROM " . prefix . "_eshop_products p LEFT JOIN " . prefix . "_eshop_products_categories pc ON p.id = pc.product_id LEFT JOIN " . prefix . "_eshop_categories c ON pc.category_id = c.id LEFT JOIN (SELECT * FROM " . prefix . "_eshop_images ORDER BY position, id) i ON i.product_id = p.id LEFT JOIN " . prefix . "_eshop_variants v ON p.id = v.product_id " . (count($conditions) ? "WHERE " . implode(" AND ", $conditions) : '') . $fSort;
                    $sqlQ = "SELECT p.id AS id, p.url as url, p.code AS code, p.name AS name, p.active AS active, p.featured AS featured, p.position AS position, c.url as curl, c.name AS category, i.filepath AS image_filepath, v.price AS price, v.compare_price AS compare_price, v.stock AS stock " . $sqlQPart;
                    // Retrieve news record
                    $rec = $mysql->record($sqlQ);
                    if (!is_array($rec)) {
                        return array('status' => 0, 'errorCode' => 3, 'errorText' => 'Item [news] with ID (' . $linked_id . ') is not found');
                    }
                    $btitle = $rec['name'];
                    $price = $rec['price'];
                    $view_link = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $rec['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $rec['url']));
                    $rec['view_link'] = $view_link;
                    // Add data into basked
                    return ebasket_add_item($linked_ds, $linked_id, $btitle, $price, $count, array('item' => $rec));
                    break;
            }
            break;
        case 'update_count':
            $id = intval($params['id']);
            $linked_ds = intval($params['linked_ds']);
            $linked_id = intval($params['linked_id']);
            $count = intval($params['count']);
            return basket_update_item_count($id, $linked_ds, $linked_id, $count);
            break;
        case 'delete':
            $id = intval($params['id']);
            $linked_ds = intval($params['linked_ds']);
            $linked_id = intval($params['linked_id']);
            return basket_delete_item($id, $linked_ds, $linked_id);
            break;
        case 'add_fast':
            $linked_ds = intval($params['ds']);
            $linked_id = intval($params['id']);
            $count = intval($params['count']);
            $type = intval($params['type']);
            $order['name'] = filter_var($params['name'], FILTER_SANITIZE_STRING);
            if (empty($order['name'])) {
                return array('status' => 0, 'errorCode' => 3, 'errorText' => 'Item [news] with ID (' . $linked_id . ') is not found');
            }
            $order['email'] = "";
            $order['phone'] = filter_var($params['phone'], FILTER_SANITIZE_STRING);
            if (empty($order['phone'])) {
                return array('status' => 0, 'errorCode' => 3, 'errorText' => 'Item [news] with ID (' . $linked_id . ') is not found');
            }
            $order['address'] = filter_var($params['address'], FILTER_SANITIZE_STRING);
            if (empty($order['address'])) {
                return array('status' => 0, 'errorCode' => 3, 'errorText' => 'Item [news] with ID (' . $linked_id . ') is not found');
            }
            // Check available DataSources
            if (!in_array($linked_ds, array($DSlist['news']))) {
                return array('status' => 0, 'errorCode' => 2, 'errorText' => 'ebasket can be used only for NEWS');
            }
            // Check available DataSources
            if ($count < 1) {
                $count = 1;
            }
            $conditions = array();
            if ($linked_id) {
                array_push($conditions, "p.id = " . db_squote($linked_id));
            }
            $fSort = " GROUP BY p.id ORDER BY p.id DESC";
            $sqlQPart = "FROM " . prefix . "_eshop_products p LEFT JOIN " . prefix . "_eshop_products_categories pc ON p.id = pc.product_id LEFT JOIN " . prefix . "_eshop_categories c ON pc.category_id = c.id LEFT JOIN (SELECT * FROM " . prefix . "_eshop_images ORDER BY position, id) i ON i.product_id = p.id LEFT JOIN " . prefix . "_eshop_variants v ON p.id = v.product_id " . (count($conditions) ? "WHERE " . implode(" AND ", $conditions) : '') . $fSort;
            $sqlQ = "SELECT p.id AS id, p.url as url, p.code AS code, p.name AS name, p.active AS active, p.featured AS featured, p.position AS position, c.url as curl, c.name AS category, i.filepath AS image_filepath, v.price AS price, v.compare_price AS compare_price, v.stock AS stock " . $sqlQPart;
            // Retrieve news record
            $rec = $mysql->record($sqlQ);
            if (!is_array($rec)) {
                return array('status' => 0, 'errorCode' => 3, 'errorText' => 'Item [news] with ID (' . $linked_id . ') is not found');
            }
            $btitle = $rec['name'];
            $price = $rec['price'];
            $view_link = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $row['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $row['url']));
            $rec['view_link'] = $view_link;
            // Add data into basked
            return ebasket_add_fast_order($linked_ds, $linked_id, $btitle, $price, $count, $type, $order, array('item' => $rec));
            break;
    }
    return array('status' => 1, 'errorCode' => 0, 'data' => 'OK, ' . var_export($params, true));
}