<?php
/**
 * 空間配置
 * 
 * @version        $Id: config_space.php 1 13:52 2010年7月9日Z tianya $
 * @package        DedeCMS.Member
 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
 * @license        http://help.dedecms.com/usersguide/license.html
 * @link           http://www.dedecms.com
 */
if(!defined('DEDEMEMBER')) exit('dedecms');

//檢查是否開放會員功能
if($cfg_mb_open=='N')
{
    ShowMsg("系統關閉了會員功能，因此你無法訪問此頁面！","javascript:;");
    exit();
}

//對uid進行過濾
if(preg_match("/'/", $uid)){
   ShowMsg("您的用戶名中含有非法字符！", "-1");
   exit();
}else{
   $uid=RemoveXSS($uid);
}


$_vars = GetUserSpaceInfos();
$_vars['bloglinks'] = $_vars['curtitle'] = '';

//---------------------------
//用戶權限檢查
//被禁言用戶
if($_vars['spacesta'] == -2)
{
    ShowMsg("用戶：{$_vars['userid']} 被禁言，因此個人空間禁止訪問！", "-1");
    exit();
}
//未審核用戶
if($_vars['spacesta'] < 0)
{
    ShowMsg("用戶：{$_vars['userid']} 的資料尚未通過審核，因此空間禁止訪問！", "-1");
    exit();
}
//是否禁止了管理員空間的訪問
if( !isset($_vars['matt']) ) $_vars['matt'] = 0;
if($_vars['matt'] == 10 && $cfg_mb_adminlock=='Y' 
&& !(isset($cfg_ml->fields) && $cfg_ml->fields['matt']==10))
{
    ShowMsg('系統設置了禁止訪問管理員的個人空間！', '-1');
    exit();
}

//---------------------------
//默認風格
if($_vars['spacestyle']=='')
{
    if($_vars['mtype']=='個人') {
        $_vars['spacestyle'] = 'person';
    }
    else if($_vars['mtype']=='企業') {
        $_vars['spacestyle'] = 'company';
    }
    else {
        $_vars['spacestyle'] = 'person';
    }
}
//找不到指定樣式文件夾的時候使用person為默認
if(!is_dir(DEDEMEMBER.'/space/'.$_vars['spacestyle']))
{
    $_vars['spacestyle'] = 'person';
}

//獲取分類數據
$mtypearr = array();
$dsql->Execute('mty', "select * from `#@__mtypes` where mid='".$_vars['mid']."'");
while($row = $dsql->GetArray('mty'))
{
    $mtypearr[] = $row;
}

//獲取欄目導航數據
$_vars['bloglinks'] = array();
$query = "SELECT tp.channeltype,ch.typename FROM `#@__arctype` tp 
      LEFT JOIN `#@__channeltype` ch on ch.id=tp.channeltype 
      WHERE (ch.usertype='' OR ch.usertype LIKE '{$_vars['mtype']}') And tp.channeltype<>1 And tp.issend=1 And tp.ishidden=0 GROUP BY tp.channeltype ORDER BY ABS(tp.channeltype) asc";
$dsql->Execute('ctc', $query);
while( $row = $dsql->GetArray('ctc') )
{
    $_vars['bloglinks'][$row['channeltype']] = $row['typename'];
}


//獲取企業用戶私有數據
if($_vars['mtype']=='企業')
{
    require_once(DEDEINC.'/enums.func.php');
    $query = "SELECT * FROM `#@__member_company` WHERE mid='".$_vars['mid']."'";
    $company = $db->GetOne($query);
    $company['vocation'] = GetEnumsValue('vocation', $company['vocation']);
    $company['cosize'] = GetEnumsValue('cosize', $company['cosize']);
    $tmpplace = GetEnumsTypes($company['place']);
    $provinceid = $tmpplace['top'];
    $provincename = (isset($em_nativeplaces[$provinceid]) ?  $em_nativeplaces[$provinceid] : '');
    $cityname = (isset($em_nativeplaces[$tmpplace['son']]) ? $em_nativeplaces[$tmpplace['son']] : '');
    $company['place'] = $provincename.' - '.$cityname;
    $_vars = array_merge($company, $_vars);
    if($action == 'infos') $action = 'introduce';
    $_vars['comface'] = empty($_vars['comface']) ? 'images/comface.png' : $_vars['comface'];
}

/**
 * 獲取空間基本信息
 *
 * @return unknown
 */
function GetUserSpaceInfos()
{
    global $dsql,$uid,$cfg_memberurl;
    $_vars = array();
    $userid = preg_replace("#[\r\n\t \*%]#", '', $uid);
    $query = "SELECT m.mid,m.mtype,m.userid,m.uname,m.sex,m.rank,m.email,m.scores,
                            m.spacesta,m.face,m.logintime,
                            s.*,t.*,m.matt,r.membername,g.msg
                  From `#@__member` m
                  LEFT JOIN `#@__member_space` s on s.mid=m.mid
                  LEFT JOIN `#@__member_tj` t on t.mid=m.mid
                  LEFT JOIN `#@__arcrank` r on r.rank=m.rank
                  LEFT JOIN `#@__member_msg` g on g.mid=m.mid
                  where m.userid like '$uid' ORDER BY g.dtime DESC ";
    $_vars = $dsql->GetOne($query);
    if(!is_array($_vars))
    {
        ShowMsg("你訪問的用戶可能已經被刪除！","javascript:;");
        exit();
    }
    if($_vars['face']=='')
    {
        $_vars['face']=($_vars['sex']=='女')? 'templets/images/dfgirl.png' : 'templets/images/dfboy.png';
    }
    $_vars['userid_e'] = urlencode($_vars['userid']);
    $_vars['userurl'] = $cfg_memberurl."/index.php?uid=".$_vars['userid_e'];
    if($_vars['membername']=='開放瀏覽') $_vars['membername'] = '限制會員';
    return $_vars;
}