<?php

/*
	[SupeSite/X-Space] (C)2001-2006 Comsenz Inc.
	查看用戶資料

	$RCSfile: viewpro.php,v $
	$Revision: 1.36 $
	$Date: 2006/10/27 01:24:52 $
*/

if(!defined('IN_SUPESITE')) {
	exit('Access Denied');
}

$perpage = 20;

$uid = empty($_SGET['uid'])?0:intval($_SGET['uid']);
if(empty($uid)) messagebox('error', 'not_found', S_URL);

if(!empty($_SCONFIG['htmlviewspace'])) {
	$_SHTML['uid'] = $uid;
	$_SHTML['action'] = 'viewpro';
	if(!empty($_SGET['showpro'])) $_SHTML['showpro'] = 1;
	ehtml('get', $_SHTML, $_SCONFIG['htmlviewspacetime']);
	$_SCONFIG['debug'] = 0;
}

include_once(S_ROOT.'./include/common.inc.php');

$space = getuserspace($uid);
if(empty($space)) messagebox('error', 'not_found', S_URL);
if($space['islock']) messagebox('error', 'space_lock', S_URL);
$space['showcp'] = 0;

$tplfile = maketplfile($space);
getcookie();
if(!empty($_SGET['showpro'])) {
	$choicearr = $userfield = $profieldarr = array();
	$profield = '';
	$invisible = ($_SGLOBAL['supe_uid'] != $uid) ? ' AND invisible>0' : '';
	$titlearr = array(
		'nickname' => '暱稱',
		'sex' => '性別',
		'birth' => '生日',
		'marriage' => '婚戀狀況',
		'star' => '星座',
		'folk' => '民族',
		'bloodtype' => '血型',
		'tall' => '身高',
		'weight' => '體重',
		'native' => '性格特徵',
		'figure' => '體型',
		'email' => '常用E-Mail',
		'email2' => '備用E-Mail',
		'email3' => '備用E-Mail2',
		'qq' => 'QQ號碼',
		'msn' => 'MSN帳號',
		'phone' => '電話',
		'mobile' => '手機',
		'address' => '工作單位',
		'postalcode' => '身份證號',
		'edu' => '教育水平',
		'school' => '畢業學校',
		'job' => '職業',
		'position' => '職業頭銜',
		'income' => '收入水平',
		'housing' => '住房條件',
		'smoke' => '是否吸煙',
		'drink' => '是否喝酒',
		'interest' => '興趣愛好'
	);
	$query = $_SGLOBAL['db']->query("SELECT proid, title, selective, choices FROM ".tname('userprofile')." WHERE available>0 ".$invisible." ORDER BY displayorder");
	while ($fields = $_SGLOBAL['db']->fetch_array($query)) {
		$profieldarr['profile_'.$fields['proid']] = $fields['title'];
		$proidarr[] = $fields['proid'];
		if ($fields['selective']) {
			foreach (explode("\n", $fields['choices']) as $item) {
				list($index, $choice) = explode('=', $item);
				$choicearr['profile_'.$fields['proid']][$index] = $choice;
			}
		}
	}
	$titlearr = array_merge($profieldarr, $titlearr);
	if (!empty($proidarr)) {
		$profield = implode(', profile_', $proidarr);
		$profield = 'profile_'.$profield.', ';
	}
	$query = $_SGLOBAL['db']->query("SELECT ".$profield."nickname, sex, CONCAT_WS('-', birthyear, birthmonth, birthday) AS birth, marriage, star, folk, bloodtype, tall, weight, native,
	figure, email, email2, email3, qq, msn, phone, mobile, address, postalcode, edu, school, job, position, income, housing, smoke, drink, interest FROM ".tname('userfields')." WHERE uid='$uid'");
	$userfields['field'] = $_SGLOBAL['db']->fetch_array($query);
	if ($userfields['field']) {
		$userfields['field']['weight'] = ($userfields['field']['weight'] !=0) ? $userfields['field']['weight'].'KG' : '';
		$userfields['title'] = $titlearr;
		foreach ($choicearr as $key => $choice) {
			$userfields['field'][$key] = $choice[$userfields['field'][$key]];
		}
	}
	$space = array_merge($space, $userfields);
}

$guestbooks = array();
$query = $_SGLOBAL['db']->query("SELECT u.*, g.* FROM ".tname('guestbooks')." g LEFT JOIN ".tname('userspaces')." u ON u.uid=g.authorid WHERE g.uid='$uid' ORDER BY g.dateline DESC LIMIT 0,$perpage");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
	$value['photo'] = getphoto($value['authorid'], $value['photo']);
	if($value['isprivate']) {
		$value['message'] = "<a href=\"javascript:showguestbook(1);\">".$lang['isprivate']."</a>";
	} else {
		$value['message'] = snl2br($value['message']);
	}
	$guestbooks[] = $value;
}

$showtplfile = 'styles/space/viewpro.html.php';

$title = $space['spacename'].'_'.$_SCONFIG['sitename'];

$leftarr = $rightarr = array();
if($space['showside']) $leftarr = array('calendar');
include_once(S_ROOT.'./include/space_template.inc.php');

if(!empty($_SCONFIG['htmlviewspace'])) {
	ehtml('make');
} else {
	maketplblocknames($tplfile, 'spacecache', 1);
	maketplblockvalue('spacecache');
}

?>