<?php
/**
* @author moufer<moufer@163.com>
* @copyright www.modoer.com
* @version $Id 2 2008-09-08 11:36 $
*/
!defined('IN_MUDDER') && exit('Access Denied');

if(!validKey($shopid)) redirect('无效的商铺ID。');
$item = $db->get_one("SELECT * FROM {$dbpre}shops WHERE sid='$shopid'");
if(empty($item)) redirect('对不起，认领对象不存在，无法认领。');
$panelcfg =& $_panel_config[substr($item['classcode'],0,2)];
if(!$panelcfg['itemapply']) redirect('对不起，管理员未开启商铺认领功能。');
if(validKey($item['ownerid'])) redirect('对不起，商铺已被认领，无法再次认领。');
$applied = $db->get_one("SELECT * FROM {$dbpre}itemapply WHERE shopid='$shopid' AND uid='$user->uid'");
if($applied['status']==2) redirect('您已经提交了认领请求，请等待管理员处理。');

if(!check_submit('mysubmit')) {

    if(!function_exists('getItem')) {
        require_once(MUDDER_ROOT.'./'.$_modules['shop']['directory'].'/include/fun_item.php');
    }
    $item = getItem($shopid);
    if(empty($item)) redirect('商铺不存在或已删除。');

} else {

    $post = array();
    $post['shopid'] = $shopid;
    $post['uid'] = $user->uid;
    $post['username'] = $user->username;
    $post['applyname'] = $applyname;
    $post['contact'] = $contact;
    $post['content'] = $content;
    $post['dateline'] = $timestamp;
    $post['status'] = 2; // 未处理标记
    $post['returned'] = '';

    if(!function_exists('postItemApply')) {
        require_once(MUDDER_ROOT.'./'.$_modules['shop']['directory'].'/include/fun_item.php');
    }
    postItemApply($post);
    redirect('商铺认领已提交，请等待管理员审核。',$_modules['shop']['url'].'shop.php?shopid='.$shopid);
}
?>