<?php
/**
* 地图显示
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
* @version $Id: map.php 2008-01-07 12:56 $
*/
define('SCRIPTNAV', 'map');
require_once './include/inc_common.php';

if($action == 'small') {

    $subtitle = '地图标注';
    $tpl_name = 'shop_mapview';
    if(count($_default_mappoints)>1) {
        $shop = $db->get_one("SELECT areacode,streetcode,mappoint FROM {$dbpre}shops WHERE sid='$shopid'");
        if($shop) {
            // 从商铺地址入手取最小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']]);
            }
        }
    }

} elseif($action == 'big') {

    $tpl_name = 'shop_mapview';

    if(is_numeric($shopid) && $shopid > 0) {
        $shop = $db->get_one("SELECT sid,shopname,subname,classcode,areacode,address,tel1,tel2,mappoint FROM {$dbpre}shops WHERE sid='$shopid'");
        if($shop) {
            $shop['mappoint'] = trim($shop['mappoint']);
            if(preg_match("/^[A-Za-z0-9\.\-]+,[A-Za-z0-9\.\-]+$/", $shop['mappoint'])) {
                $shop['map'] = true;
                $shop['mappoint'] = explode(',', $shop['mappoint']);
            } else {
                $shop['map'] = false;
            }

            if(!$shop['map']) {
                redirect('商铺未标记，您可以再商铺页面添加标注。', 'shop.php?shopid='.$shopid);
            }

            $pcd = substr($shop['classcode'], 0, 2);
            $shop['shopname'] .= $shop['subname'] ? "({$shop['subname']})" : '';
            $shop['address'] = $_areacodes[$shop['areacode']].$shop['address'];

            $subtitle = $shop['shopname'].'_地图位置';
        } else {
            redirect('商铺不存在或已删除。', NULL);
        }
    } else {

        redirect('商铺不存在。', NULL);
    }

} elseif($action == 'mark') {

    $tpl_name = 'shop_mapmark';

    $in_dialog = $extra == 'in_dialog';

    if(!$in_dialog && is_numeric($shopid) && $shopid > 0) {
        $shop = $db->get_one("SELECT sid,shopname,subname,classcode,areacode,streetcode,address,tel1,tel2,mappoint FROM {$dbpre}shops WHERE sid='$shopid'");
        if($shop) {
            $shop['mappoint'] = trim($shop['mappoint']);
            if(preg_match("/^[A-Za-z0-9\.\-]+,[A-Za-z0-9\.\-]+$/", $shop['mappoint'])) {
                redirect('改商铺已标注，无需再次标注，如果标注有误，请在商铺页面内点击“报错”链接。', 'shop.php?shopid='.$shopid);
            }
            $pcd = substr($shop['classcode'], 0, 2);
            $shop['shopname'] .= $shop['subname'] ? "({$shop['subname']})" : '';
            $shop['address'] = $_areacodes[$shop['areacode']].$shop['address'];
        } else {
            redirect('商铺不存在或已删除。', NULL);
        }

        // 从商铺地址入手取最小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']]);
        }

    } elseif(!$in_dialog) {

        redirect('商铺不存在。', NULL);
    }

    $subtitle = $shop['shopname'].'_地图标注';
}

require_once MUDDER_ROOT.'header.php';
require_once template($tpl_name);
footer();
?>
