<?php
/**
* 点评对象详细信息页面
* @author: moufer<moufer@163.com>
* @package: modoer
* @copyright: Moufer Studio(www.modoer.com)
* @version: $Id: shop.php 10 2008-08-31 13:41 $
*/
define('SCRIPTNAV', 'shop');
require_once './include/inc_common.php';

$reviewed = false;
$pcd = $panelcfg = $shop = $tags = $updatelogs = $reviewsorts = $reviews = array();

(!is_numeric($shopid) || $shopid < 0) && redirect('商铺不存在。','cate.php');
$shop = getItem($shopid);
empty($shop['shopid']) and redirect('商铺不存在或已被删除。','cate.php');
$shop['status'] == 6 and redirect('本商铺已被管理员设为不可见，无法查看。');

$pcd = $shop['panelcode'];
$panelcfg = $shop['panelcfg'];

if(!function_exists('getItemTags')) {
    require_once(MUDDER_ROOT.'./'.$_modules['shop']['directory'].'/include/fun_tag.php');
}
// 商铺标签
list($shoptags,$producttags,$suitplaces) = getItemTags($shopid);
$updatelogs = itemSupplogs($shopid);
$reviewsorts =& $panelcfg['review'];

// 兼容性
if($_config['compatible']) {
    $uplogs = &$updatelogs;
    $review_item = &$reviewsorts;
    $firstmember = array(
        'username' => $shop['firstname'],
        'uid' => $shop['firstuid'],
    );
}

if($_config['detail_allthumb_enable']) {

    if(!function_exists('getItemPictures')) {
        require_once(MOD_ROOT.'./include/fun_picture.php');
    }
    $thumb_art = $_config['detail_allthumb_sort'];
    if($shop['picturelist'] = getItemPictures($shopid, "0,{$shop['pictures']}")) {
        foreach($shop['picturelist'] as $key => $picture) {
            $picture['thumb_url'] = get_picture($picture['folder'], $picture['filename'], $thumb_art);
            $picture['thumb_alt'] = "width=\"{$_picture_thumb[$thumb_art]['width']}\" height=\"{$_picture_thumb[$thumb_art]['height']}\"";
            $picture['url'] = get_picture($picture['folder'], $picture['filename'], 'source');
            $shop['picturelist'][$key] = $picture;
        }
    }
}

// Video
$_video['width'] = $_video['width'] ? $_video['width'] : 250;
$_video['height'] = $_video['height'] ? $_video['height'] : 200;

//会员点评
if($shop['reviews'] > 0) {
    $pageOffset = $_config['dpdetail_reviewnumber'];
    $multipage = multi($shop['reviews'], $pageOffset, $page, "shop.php?shopid=$shopid&review_orderby=$review_orderby","#review");
    $order_arr = array(
        'posttime' => 'posttime DESC',
        'flower' => 'flower DESC',
        'respond' => 'respond DESC',
    );
    $orderby = $order_arr[$review_orderby];
    empty($orderby) && $orderby = 'posttime DESC';
    $limit = get_limit($page, $pageOffset);
    $reviews = getItemReviews($shopid, $orderby, $limit);
    //判断我是否发布过点评
    $reviewed = $user->isLogin && checkReviewed($user->uid, $shopid);
}
// 商铺浏览量累计
$db->update("UPDATE {$dbpre}shops SET pageviews=pageviews+1 WHERE sid='$shopid'");

// 点评坐标
if(count($_default_mappoints)>1) {
    // 从商铺地址入手取最小MAP
    if($shop['streetcode'] && $_default_mappoints[$shop['streetcode']]) {
        $_default_mappoint = explode(',',$_default_mappoints[$shop['streetcode']]);
    } elseif($_default_mappoints[$shop['areacode']]) {
        $_default_mappoint = explode(',',$_default_mappoints[$shop['areacode']]);
    }
}

$subtitle = sprintf("%s_%s", $shop['fullname'], $shop['panelname']);
if($shop['templateid'] > 0) {
    // 商户风格
    if(array_key_exists($shop['templateid'], $_templates['item'])) {
        $item_styleid = $shop['templateid'];
    } else {
        $item_styleid = $_config['item_styleid'];
    }

    if(!empty($item_styleid)) {
        $itemstyle_dir = $_templates['item'][$item_styleid]['directory'];
        substr($itemstyle_dir, -1, 1) != '/' && $itemstyle_dir .= '/';
        $itemstyle_url = $_config['siteurl'].substr($_templates['item'][$item_styleid]['directory'], 2).'/';
        if(!file_exists(MUDDER_ROOT.$itemstyle_dir)) {
            $item_styleid = 0;
        }
        $_config['item_styleid'] = $item_styleid;
    }
}
if($_config['item_styleid']) {
    require_once itemstyle('index', $item_styleid);
} else {
    // 不使用风格
    $tplname = $panelcfg['tplname_detail'] ? $panelcfg['tplname_detail'] : 'shop_index';
    require_once MUDDER_ROOT.'header.php';
    require_once template($tplname);
    footer();
}
?>