<?php
/**
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
*/
(!defined('IN_ADMIN') || !defined('IN_MUDDER')) && exit('Access Denied');
if(!$dosubmit) {

    if($op == 'itemupdate') {

        if(!is_numeric($upid) || $upid < 0) cpmsg('ID无效。','stop');
        $shop = $db->get_one("SELECT a.uid,a.username,a.upcontent,a.disposal,a.upremark,a.disposaltime,b.* FROM {$dbpre}upshops a JOIN {$dbpre}shops b ON(a.shopid=b.sid) WHERE upid='$upid'");
        if(!$shop) cpmsg('补充信息不存在。','stop');;
        if(preg_match('/^MarkPoint:([A-Za-z0-9\.\-]+),([A-Za-z0-9\.\-]+)\r\n/', $shop['upcontent'], $mappoint)) {
            $shop['upmappoint'] = $mappoint[1].','.$mappoint[2];
            $shop['upcontent'] = preg_replace('/^MarkPoint:([A-Za-z0-9\.\-]+),([A-Za-z0-9\.\-]+)\r\n/', '', $shop['upcontent']);
            unset($mappoint);
        }
        $shop['disposaltime'] = date('Y-m-d H:i', $shop['disposaltime']);
        $shopid = $shop['sid'];

    } else {

        if(!is_numeric($shopid) || $shopid < 0) cpmsg('ID无效。','stop');
        $shop = $db->get_one("SELECT a.*,b.cardsort,b.discount,b.largess,b.exception,b.available as membercard_available FROM {$dbpre}shops a LEFT JOIN {$dbpre}carddiscounts b ON(a.sid=b.shopid) WHERE a.sid='$shopid'");
        $shop['membercard'] = $shop['membercard_available'];
        if(!$shop) cpmsg('无此商铺。','stop');
    }

    $shop['areacode'] = $shop['streetcode'] ? $shop['streetcode'] : $shop['areacode'];
    $pcd = substr($shop['classcode'], 0, 2);
    $pad = substr($shop['areacode'], 0, 2);

    include cptpl('edititem', MOD_ROOT.'./admin/templates/');

} else {
    
    if($shopid && is_numeric($shopid) && $shopid > 0) {
        if(!function_exists('updateItem')) {
            require_once(MUDDER_ROOT.'./'.$_modules['shop']['directory'].'/include/fun_item.php');
        }
        $file = "itemlist";
        // 信息补充
        if($op == 'itemupdate') {
            $post = array();
            $post['uid'] = $uid;
            $post['upremark'] = $upremark;
            $post['addpoint'] = $addpoint;
            $post['disposaltime'] = $timestamp;
            checkSuppItem($upid, $post);
            $file = "itemupdate";
        } elseif($op == 'checkitem') {
            $file = "checkitems";
        }
        $post = array();
        $post['owner'] = $owner;
        $post['templateid'] = $item_styleid;
        $post['classcode'] = $classcode;
        $post['areacode'] = $areacode;
        $post['shopname'] = $shopname;
        $post['subname'] = $subname;
        $post['address'] = $address;
        $post['website'] = $website;
        $post['tel1'] = $tel1;
        $post['tel2'] = $tel2;
        $post['mobile'] = $mobile;
        $post['thumb'] = $thumb;
        $post['video'] = $video;
        $post['mappoint']	= $mappoint;
        $post['content'] = $content;
        if($action == 'auditingshop') {
            $post['status'] = 1;
        } else {
            $post['status'] = $status;
        }
        updateItem($shopid, $post);
        if($_modules['card']) {
            // 会员卡
            $post = array();
            $post = $membercard;
            $post['shopid'] = $shopid;
            if(!function_exists('postCard')) {
                require_once(MUDDER_ROOT.'./'.$_modules['card']['directory'].'/include/fun_card.php');
            }
            //pr($post);
            //exit;
            postCard($post);
        }
        /*
        $error = $editshop->checkParam(); // 检测
        $error && cpmsg($error);
        $error = $editshop->Save(); // 保存
        $error && cpmsg($error);
        */
        //$cacheclass->Read_Shops('card_addnew_shops','',TRUE);
        
        cpmsg('商铺更新完毕。',"admincp.php?action=$action&file=$file");
    } else {
        cpmsg('未选择需要编辑的商铺，请返回。');
    }

}
?>