/**
  * nv_relates_product()
  *
  * @param mixed $block_config
  * @return
  */
 function nv_relates_product($block_config)
 {
     global $site_mods, $global_config, $lang_module, $module_config, $module_config, $module_name, $module_info, $global_array_shops_cat, $db_config, $my_head, $db, $pro_config, $money_config;
     $module = $block_config['module'];
     $mod_data = $site_mods[$module]['module_data'];
     $mod_file = $site_mods[$module]['module_file'];
     if (file_exists(NV_ROOTDIR . '/themes/' . $global_config['site_theme'] . '/modules/' . $mod_file . '/block.others_product.tpl')) {
         $block_theme = $global_config['site_theme'];
     } else {
         $block_theme = 'default';
     }
     if ($module != $module_name) {
         $sql = 'SELECT catid, parentid, lev, ' . NV_LANG_DATA . '_title AS title, ' . NV_LANG_DATA . '_alias AS alias, viewcat, numsubcat, subcatid, numlinks, ' . NV_LANG_DATA . '_description AS description, inhome, ' . NV_LANG_DATA . '_keywords AS keywords, groups_view, typeprice FROM ' . $db_config['prefix'] . '_' . $mod_data . '_catalogs ORDER BY sort ASC';
         $list = $nv_Cache->db($sql, 'catid', $module);
         foreach ($list as $row) {
             $global_array_shops_cat[$row['catid']] = array('catid' => $row['catid'], 'parentid' => $row['parentid'], 'title' => $row['title'], 'alias' => $row['alias'], 'link' => NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module . '&' . NV_OP_VARIABLE . '=' . $row['alias'], 'viewcat' => $row['viewcat'], 'numsubcat' => $row['numsubcat'], 'subcatid' => $row['subcatid'], 'numlinks' => $row['numlinks'], 'description' => $row['description'], 'inhome' => $row['inhome'], 'keywords' => $row['keywords'], 'groups_view' => $row['groups_view'], 'lev' => $row['lev'], 'typeprice' => $row['typeprice']);
         }
         unset($list, $row);
         // Css
         if (file_exists(NV_ROOTDIR . '/themes/' . $block_theme . '/css/' . $mod_file . '.css')) {
             $my_head .= '<link rel="StyleSheet" href="' . NV_BASE_SITEURL . 'themes/' . $block_theme . '/css/' . $mod_file . '.css" type="text/css" />';
         }
         // Language
         if (file_exists(NV_ROOTDIR . '/modules/' . $mod_file . '/language/' . NV_LANG_DATA . '.php')) {
             require_once NV_ROOTDIR . '/modules/' . $mod_file . '/language/' . NV_LANG_DATA . '.php';
         }
         $pro_config = $module_config[$module];
         // Lay ty gia ngoai te
         $sql = 'SELECT code, currency, exchange, round, number_format FROM ' . $db_config['prefix'] . '_' . $mod_data . '_money_' . NV_LANG_DATA;
         $cache_file = NV_LANG_DATA . '_' . md5($sql) . '_' . NV_CACHE_PREFIX . '.cache';
         if (($cache = $nv_Cache->getItem($module, $cache_file)) != false) {
             $money_config = unserialize($cache);
         } else {
             $money_config = array();
             $result = $db->query($sql);
             while ($row = $result->fetch()) {
                 $money_config[$row['code']] = array('code' => $row['code'], 'currency' => $row['currency'], 'exchange' => $row['exchange'], 'round' => $row['round'], 'number_format' => $row['number_format'], 'decimals' => $row['round'] > 1 ? $row['round'] : strlen($row['round']) - 2, 'is_config' => $row['code'] == $pro_config['money_unit'] ? 1 : 0);
             }
             $result->closeCursor();
             $cache = serialize($money_config);
             $nv_Cache->setItem($module, $cache_file, $cache);
         }
     }
     $link = NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&amp;' . NV_NAME_VARIABLE . '=' . $module . '&amp;' . NV_OP_VARIABLE . '=';
     $xtpl = new XTemplate('block.others_product.tpl', NV_ROOTDIR . '/themes/' . $block_theme . '/modules/' . $mod_file);
     $xtpl->assign('LANG', $lang_module);
     $xtpl->assign('WIDTH', $pro_config['homewidth']);
     $db->sqlreset()->select('t1.id, t1.listcatid, t1.' . NV_LANG_DATA . '_title AS title, t1.' . NV_LANG_DATA . '_alias AS alias, t1.addtime, t1.homeimgfile, t1.homeimgthumb, t1.product_price, t1.money_unit, t1.discount_id, t1.showprice')->from($db_config['prefix'] . '_' . $mod_data . '_rows t1')->join('INNER JOIN ' . $db_config['prefix'] . '_' . $mod_data . '_block t2 ON t1.id = t2.id')->where('t2.bid= ' . $block_config['blockid'] . ' AND t1.status =1')->order('t1.addtime DESC, t2.weight ASC')->limit($block_config['numrow']);
     $list = $nv_Cache->db($db->sql(), 'id', $module);
     $i = 1;
     $cut_num = $block_config['cut_num'];
     foreach ($list as $row) {
         if ($row['homeimgthumb'] == 1) {
             $src_img = NV_BASE_SITEURL . NV_FILES_DIR . '/' . $site_mods[$module]['module_upload'] . '/' . $row['homeimgfile'];
         } elseif ($row['homeimgthumb'] == 2) {
             $src_img = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $site_mods[$module]['module_upload'] . '/' . $row['homeimgfile'];
         } elseif ($row['homeimgthumb'] == 3) {
             $src_img = $row['homeimgfile'];
         } else {
             $src_img = NV_BASE_SITEURL . 'themes/' . $global_config['site_theme'] . '/images/shops/no-image.jpg';
         }
         $xtpl->assign('link', $link . $global_array_shops_cat[$row['listcatid']]['alias'] . '/' . $row['alias'] . $global_config['rewrite_exturl']);
         $xtpl->assign('title', nv_clean60($row['title'], $cut_num));
         $xtpl->assign('src_img', $src_img);
         $xtpl->assign('time', nv_date('d-m-Y h:i:s A', $row['addtime']));
         if ($pro_config['active_price'] == '1') {
             if ($row['showprice'] == '1') {
                 $price = nv_get_price_tmp($module, $mod_data, $mod_file, $row['id']);
                 //var_dump($price); die;
                 $xtpl->assign('PRICE', $price);
                 if ($row['discount_id'] and $price['discount_percent'] > 0) {
                     $xtpl->parse('main.loop.price.discounts');
                 } else {
                     $xtpl->parse('main.loop.price.no_discounts');
                 }
                 $xtpl->parse('main.loop.price');
             } else {
                 $xtpl->parse('main.loop.contact');
             }
         }
         $xtpl->parse('main.loop');
         ++$i;
     }
     $xtpl->parse('main');
     return $xtpl->text('main');
 }
 /**
  * nv_global_bxproduct_center()
  *
  * @param mixed $block_config
  * @return
  */
 function nv_global_bxproduct_center($block_config)
 {
     global $site_mods, $global_config, $module_config, $lang_module, $module_name, $global_array_shops_cat, $db_config, $my_head, $db, $pro_config, $money_config, $blockID;
     $module = $block_config['module'];
     $mod_data = $site_mods[$module]['module_data'];
     $mod_file = $site_mods[$module]['module_file'];
     $num_view = $block_config['numrow'];
     $num_get = $block_config['numget'];
     $auto = $block_config['auto'] == 1 ? 'true' : 'false';
     $mode = $block_config['mode'];
     $speed = $block_config['speed'];
     $width = $block_config['width'];
     $margin = $block_config['margin'];
     $move = $block_config['move'];
     $pager = $block_config['pager'] == 1 ? 'false' : 'true';
     $i = 1;
     $j = 1;
     $page_i = '';
     if (file_exists(NV_ROOTDIR . "/themes/" . $global_config['site_theme'] . "/modules/" . $mod_file . "/block.bxproduct_center.tpl")) {
         $block_theme = $global_config['site_theme'];
     } else {
         $block_theme = 'default';
     }
     if ($module != $module_name) {
         // Css
         if (file_exists(NV_ROOTDIR . '/themes/' . $global_config['site_theme'] . '/css/' . $mod_file . '.css')) {
             $block_css = $global_config['site_theme'];
         } else {
             $block_css = 'default';
         }
         $my_head .= '<link rel="stylesheet" href="' . NV_BASE_SITEURL . 'themes/' . $block_css . '/css/' . $mod_file . '.css' . '" type="text/css" />';
         // Language
         if (file_exists(NV_ROOTDIR . '/modules/' . $mod_file . '/language/' . NV_LANG_DATA . '.php')) {
             require_once NV_ROOTDIR . '/modules/' . $mod_file . '/language/' . NV_LANG_DATA . '.php';
         }
         $sql = 'SELECT catid, parentid, lev, ' . NV_LANG_DATA . '_title AS title, ' . NV_LANG_DATA . '_alias AS alias, viewcat, numsubcat, subcatid, numlinks, ' . NV_LANG_DATA . '_description AS description, inhome, ' . NV_LANG_DATA . '_keywords AS keywords, groups_view, typeprice FROM ' . $db_config['prefix'] . '_' . $mod_data . '_catalogs ORDER BY sort ASC';
         $list = $nv_Cache->db($sql, 'catid', $module);
         foreach ($list as $row) {
             $global_array_shops_cat[$row['catid']] = array('catid' => $row['catid'], 'parentid' => $row['parentid'], 'title' => $row['title'], 'alias' => $row['alias'], 'link' => NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&amp;' . NV_NAME_VARIABLE . '=' . $module . '&amp;' . NV_OP_VARIABLE . '=' . $row['alias'], 'viewcat' => $row['viewcat'], 'numsubcat' => $row['numsubcat'], 'subcatid' => $row['subcatid'], 'numlinks' => $row['numlinks'], 'description' => $row['description'], 'inhome' => $row['inhome'], 'keywords' => $row['keywords'], 'groups_view' => $row['groups_view'], 'lev' => $row['lev'], 'typeprice' => $row['typeprice']);
         }
         unset($list, $row);
         $pro_config = $module_config[$module];
         // Lay ty gia ngoai te
         $sql = 'SELECT code, currency, exchange, round, number_format FROM ' . $db_config['prefix'] . '_' . $mod_data . '_money_' . NV_LANG_DATA;
         $cache_file = NV_LANG_DATA . '_' . md5($sql) . '_' . NV_CACHE_PREFIX . '.cache';
         if (($cache = $nv_Cache->getItem($module, $cache_file)) != false) {
             $money_config = unserialize($cache);
         } else {
             $money_config = array();
             $result = $db->query($sql);
             while ($row = $result->fetch()) {
                 $money_config[$row['code']] = array('code' => $row['code'], 'currency' => $row['currency'], 'exchange' => $row['exchange'], 'round' => $row['round'], 'number_format' => $row['number_format'], 'decimals' => $row['round'] > 1 ? $row['round'] : strlen($row['round']) - 2, 'is_config' => $row['code'] == $pro_config['money_unit'] ? 1 : 0);
             }
             $result->closeCursor();
             $cache = serialize($money_config);
             $nv_Cache->setItem($module, $cache_file, $cache);
         }
     }
     $xtpl = new XTemplate('block.bxproduct_center.tpl', NV_ROOTDIR . '/themes/' . $block_theme . '/modules/' . $mod_file);
     $xtpl->assign('LANG', $lang_module);
     $xtpl->assign('THEME_TEM', NV_BASE_SITEURL . 'themes/' . $block_theme);
     $xtpl->assign('LIB_PATH', NV_BASE_SITEURL . 'themes/default/');
     $xtpl->assign('AUTO', $auto);
     $xtpl->assign('MODE', $mode);
     $xtpl->assign('SPEED', $speed);
     $xtpl->assign('WIDTH', $width);
     $xtpl->assign('MARGIN', $margin);
     $xtpl->assign('MOVE', $move);
     $xtpl->assign('NUMVIEW', $num_view);
     $xtpl->assign('PAGER', $pager);
     $xtpl->assign('BLOCKID', $blockID);
     //$xtpl->assign( 'WIDTH', $pro_config['homewidth'] );
     $db->sqlreset()->select('t1.id, t1.listcatid, t1.' . NV_LANG_DATA . '_title AS title, t1.' . NV_LANG_DATA . '_alias AS alias, t1.homeimgfile, t1.homeimgthumb , t1.homeimgalt, t1.showprice, t1.discount_id')->from($db_config['prefix'] . '_' . $mod_data . '_rows t1')->join('INNER JOIN ' . $db_config['prefix'] . '_' . $mod_data . '_block t2 ON t1.id = t2.id')->where('t2.bid= ' . $block_config['blockid'] . ' AND t1.status =1')->order('t1.id DESC')->limit($num_get);
     $list = $nv_Cache->db($db->sql(), '', $module);
     foreach ($list as $row) {
         $link = NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&amp;' . NV_NAME_VARIABLE . '=' . $module . '&amp;' . NV_OP_VARIABLE . '=' . $global_array_shops_cat[$row['listcatid']]['alias'] . '/' . $row['alias'] . $global_config['rewrite_exturl'];
         if ($row['homeimgthumb'] == 1) {
             $src_img = NV_BASE_SITEURL . NV_FILES_DIR . '/' . $site_mods[$module]['module_upload'] . '/' . $row['homeimgfile'];
         } elseif ($row['homeimgthumb'] == 2) {
             $src_img = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $site_mods[$module]['module_upload'] . '/' . $row['homeimgfile'];
         } elseif ($row['homeimgthumb'] == 3) {
             $src_img = $row['homeimgfile'];
         } else {
             $src_img = NV_BASE_SITEURL . 'themes/' . $global_config['site_theme'] . '/images/shops/no-image.jpg';
         }
         $xtpl->assign('LINK', $link);
         $xtpl->assign('TITLE', $row['title']);
         $xtpl->assign('TITLE0', nv_clean60($row['title'], 30));
         $xtpl->assign('SRC_IMG', $src_img);
         if ($pro_config['active_price'] == '1') {
             if ($row['showprice'] == '1') {
                 $price = nv_get_price_tmp($module, $mod_data, $mod_file, $row['id']);
                 $xtpl->assign('PRICE', $price);
                 if ($row['discount_id'] and $price['discount_percent'] > 0) {
                     $xtpl->parse('main.items.price.discounts');
                 } else {
                     $xtpl->parse('main.items.price.no_discounts');
                 }
                 $xtpl->parse('main.items.price');
             } else {
                 $xtpl->parse('main.items.contact');
             }
         }
         $xtpl->parse('main.items');
     }
     if (!defined('BXLIB')) {
         define('BXLIB', true);
         $xtpl->parse('main.lib');
     }
     $xtpl->parse('main');
     return $xtpl->text('main');
 }