<?php
define('THIS_SCRIPT', 'dispuser');
require_once 'global.php';
$lang = load_lang($lang, 'dispuser' );
$UserName = trim($name);
if( is_numeric($id) ){
	$showUserID = intval($id);
} else{
	if( $UserName == '' ){
		$ErrCodes = $lang['UrlArgError'];
	}
}
if( intval($groupsetting[1]) == 0 ){
	$ErrCodes = "{$lang['template.strings1']}";
}
PageLoad();
footer();

function PageLoad(){
	global $ErrCodes,$imgurl;
	if( $ErrCodes == '' ){
		MainFunc();
	} else{
		head();
		showmsg($ErrCodes);
	}
}//end function PageLoad()

function MainFunc(){
	global $userid,$showUserID,$UserName,$membername,$db,$boardid,$fsetting,$lang,$dv,$stats,$superboardmaster,$groupsetting,$_DCACHE,$boardmaster,$suppermaster,$master,$imgurl;
	$updStmt = "UPDATE {$dv}user SET UserViews=UserViews+1";
	$stmt = "SELECT userid,username,userpassword,useremail,userpost,usertopic,usersign,usersex,userface,userwidth,userheight,userim,joindate,lastlogin,userlogins,userviews,lockuser,userclass,usergroup,userwealth,userep,usercp,usertitle,userbirthday,userquesion,useranswer,userlastip,userphoto,userfav,userpower,userdel,userisbest,userinfo,usersetting,usergroupid,titlepic,userhidden,usermsg,ischallenge,usermobile FROM {$dv}user ";
	if( empty($showUserID) ){
		$updStmt .= " WHERE UserName='{$UserName}' ";
		$stmt .= " WHERE UserName='{$UserName}' ";
		$onstat = " WHERE UserName='{$UserName}' ";
	} else{
		$updStmt .= " WHERE UserID={$showUserID} ";
		$stmt .= " WHERE UserID={$showUserID} ";
		$onstat = " WHERE UserID={$showUserID} ";
	}
	if( $query = $db->query($stmt) ){
		$db->query($updStmt);
		$UserInfo =& $db->fetch_array($query);
		$db->free_result($query);
		$showUserID = intval($UserInfo['userid']);
		$stats = str_replace('{$MemberName}',$UserInfo['username'],$lang['template.strings0']);
		$arrNavMenu = array(
				 0=>array('linktitle'=>$stats)
			);
		head(1,0,0,$arrNavMenu);
		$UserName = $UserInfo['username'];
		if( $boardmaster || $suppermaster || $master ){
			$stmt = '';
		} else{
			$stmt = "SELECT stats,startime FROM {$dv}online ".$onstat."";
		}
		if( $query = $db->query($stmt) ){
			$result =& $db->fetch_array($query);
			$db->free_result($query);
			$userStatus = $result['stats'];
			$UserOnTime = str_replace('{$UserOnTime}', intval(dateDiff('MINUTE',$result['startime'],TIME_NOW)), $lang['template.strings3']);
		} else{
			$userStatus = $lang['template.strings4'];
			$UserOnTime = $lang['template.strings4'];
		}
		if($userStatus==''){
			$userStatus = $lang['template.strings4'];
			$UserOnTime= "[".$lang['template.strings4'].$lang['tpl.str76'].$lang['template.strings4']."]";
		}
		$userSetting = explode('|||',$UserInfo['usersetting']);
		if( count($userSetting) > 0 ){
			$setUserInfo = is_numeric($userSetting[0]) ? intval($userSetting[0]) : 1;
			$setUserTrue = is_numeric($userSetting[1]) ?  1: intval($userSetting[1]);//adwer edit 2006-8-5;
		} else{
			$setUserInfo = 1;
			$setUserTrue = 0;
		}
		//魔法表情部分
		$arrMagicFace = explode('|',$UserInfo['userface']);
		if( count($arrMagicFace) == 2 ){
			$UserInfo['userface'] = $arrMagicFace[1];
			$foundUseMagic = intval($arrMagicFace[0]);
		} else{
		}
		$TableWidth = $_DCACHE['stylecss'][1];
		$UserFace = Dv_FilterJS($UserInfo['userface']);
		$WhereUser =& $userStatus;
		$Pic_Stats =& $imgurl.$lang['template.pic0'];
		$UserStats = LockUser($UserInfo['lockuser']);

		//基本资料部分
		if( $setUserInfo == 1 || $showUserID == $userid ){
			$UserBirthday =& gmdate('Y-m-d',$UserInfo['userbirthday'] + getUserTimeZoneOffset());//edit by adwer;
			$UserName =& $UserInfo['username'];
			$UserPhoto =& $UserInfo['userphoto'];
			$Sexs = explode(',',$lang['template.strings5']);
			$UserSex =  ($UserInfo['usersex'] == 1 ? $Sexs[1] : $Sexs[0]);
			$Pic_Star = astro($UserInfo['userbirthday']);
			$UserEmail =& $UserInfo['useremail'];
			$UserIM = explode('|||',htmlspecialchars($UserInfo['userim']));
			$UserHomePage =& $UserIM[0];
			$UserOicq =& $UserIM[1];
			$UserIcq =& $UserIM[2];
			$UserMsn =& $UserIM[3];
			$UserAIM =& $UserIM[4];
			$UserYahoo =& $UserIM[5];
			$UserUC =& $UserIM[6];
			$UserMobile =& $UserInfo['usermobile'];
			$UserID = $showUserID;
		}

		//详细资料部分adwer edit 2006-8-5;
		if( $setUserTrue == 1 || $showUserid == $userid ){
			$UserTrueInFo = explode('|||',htmlspecialchars($UserInfo['userinfo']));
			$UserRealName =& $UserTrueInFo[0]."123";
			$UserCharacter =& $UserTrueInFo[1];
			$User_Personal =& $UserTrueInFo[2];
			$UserCountry =& $UserTrueInFo[3];
			$UserProvince =& $UserTrueInFo[4];
			$UserCity =& $UserTrueInFo[5];
			$UserShengXiao =& $UserTrueInFo[6];
			$UserBlood =& $UserTrueInFo[7];
			$UserBelief =& $UserTrueInFo[8];
			$UserOccupation =& $UserTrueInFo[9];
			$UserMarital =& $UserTrueInFo[10];
			$UserEducation =& $UserTrueInFo[11];
			$UserCollege =& $UserTrueInFo[12];
			$UserPhone =& $UserTrueInFo[13];
			$UserAddress =& $UserTrueInFo[14];
		}

		//论坛属性部分
		$color =& $_DCACHE['stylecss'][19];
		if( is_null($UserInfo['userpost']) || !is_numeric($UserInfo['userpost']) ){
			$UserInfo['userpost'] = 0;
		}
		$UserPost =& $UserInfo['userpost'];
		$UserJoinDate =& gmdate("Y-m-d H:i:s",$UserInfo['joindate']+getUserTimeZoneOffset());
		$UserLastLogin =& gmdate("Y-m-d H:i:s",$UserInfo['lastlogin']+getUserTimeZoneOffset());
		$UserLogins =& $UserInfo['userlogins'];
		$UserClass =& $UserInfo['userclass'];
		$UserGroup =& $UserInfo['usergroup'];
		$UserWealth =& $UserInfo['userwealth'];
		$UserEP =& $UserInfo['userep'];
		$UserCP =& $UserInfo['usercp'];
		$UserPower =& $UserInfo['userpower'];
		if( $UserInfo['userpost'] != 0 || $UserInfo['userdel']*(-1) != 0 ){
			$UserDelPC = round(abs($UserInfo['userdel']) / (abs($UserInfo['userpost']) + abs($UserInfo['userdel'])) * 100, 0).'%';
		} else{
			$UserDelPC = $UserInfo['userdel'];
		}
		$UserDel = & abs($UserInfo['userdel']);
		$UserBest =& $UserInfo['userisbest'];
		$UserStock = 0;
		$UserBank = 0;
		$UserAssets =& $UserInfo['userwealth'];
		$UserAdmin = GetAdminBoard($UserInfo['usergroupid'], $UserName);

		//快捷管理选项部分
		if( $superboardmaster || $master || ( $groupsetting[43] == 1 && $groupsetting[28] == 1 && $groupsetting[29] == 1 ) ){
			$UserIP =& $UserInfo['userlastip'];
			$UseTable = UseTableFunc();
		}

	} else{
		showmsg('');
		return false;
	}
	if (count($UserInfo) >1){
		require_once printout('dispuser');
	}
}

//用户状态验证
function LockUser($str){
	global $dvbbs;
	if( !is_numeric($str) ){
		return;
	}
	switch(intval($str)){
		case 1:
			return $lang["LockUserStatus1"];
		case 1:
			return $lang["LockUserStatus2"];
		default:
			return $lang["LockUserStatus3"];
	}
}//end function LockUser

//日期转换星座函数
//白羊座,金牛座,双子座,巨蟹座,狮子座,处女座,天秤座,天蝎座,射手座,魔羯座,水瓶座,双鱼座
function astro($birth){
	global $lang;
	if (empty($birth) OR !is_numeric($birth)) {
		$birth = TIME_NOW;
	}
	$Star_name = explode(',',$lang['template.strings6']);
	$birthday = gmdate('j', $birth+getUserTimeZoneOffset());
	$birthmonth = gmdate('n', $birth+getUserTimeZoneOffset());
	$src = '';
	$alt = '';
	switch($birthmonth){
		case 1:
			if( $birthday >= 21 ){
				$src = $lang['template.pic11'];
				$alt = $Star_name[10].$birth;
			} else{
				$src = $lang['template.pic10'];
				$alt = $Star_name[9].$birth;
			}
			break;
		case 2:
			if( $birthday >= 20 ){
				$src = $lang['template.pic12'];
				$alt = $Star_name[11].$birth;
			} else{
				$src = $lang['template.pic10'];
				$alt = $Star_name[10].$birth;
			}
			break;
		case 3:
			if( $birthday >= 21 ){
				$src = $lang['template.pic1'];
				$alt = $Star_name[0].$birth;
			} else{
				$src = $lang['template.pic12'];
				$alt = $Star_name[11].$birth;
			}
			break;
		case 4:
			if( $birthday >= 21 ){
				$src = $lang['template.pic2'];
				$alt = $Star_name[1].$birth;
			} else{
				$src = $lang['template.pic1'];
				$alt = $Star_name[0].$birth;
			}
			break;
		case 5:
			if( $birthday >= 22 ){
				$src = $lang['template.pic3'];
				$alt = $Star_name[2].$birth;
			} else{
				$src = $lang['template.pic2'];
				$alt = $Star_name[1].$birth;
			}
			break;
		case 6:
			if( $birthday >= 22 ){
				$src = $lang['template.pic4'];
				$alt = $Star_name[3].$birth;
			} else{
				$src = $lang['template.pic3'];
				$alt = $Star_name[2].$birth;
			}
			break;
		case 7:
			if( $birthday >= 23 ){
				$src = $lang['template.pic5'];
				$alt = $Star_name[4].$birth;
			} else{
				$src = $lang['template.pic4'];
				$alt = $Star_name[3].$birth;
			}
			break;
		case 8:
			if( $birthday >= 24 ){
				$src = $lang['template.pic6'];
				$alt = $Star_name[5].$birth;
			} else{
				$src = $lang['template.pic5'];
				$alt = $Star_name[4].$birth;
			}
			break;
		case 9:
			if( $birthday >= 24 ){
				$src = $lang['template.pic7'];
				$alt = $Star_name[6].$birth;
			} else{
				$src = $lang['template.pic6'];
				$alt = $Star_name[5].$birth;
			}
			break;
		case 10:
			if( $birthday >= 24 ){
				$src = $lang['template.pic8'];
				$alt = $Star_name[7].$birth;
			} else{
				$src = $lang['template.pic7'];
				$alt = $Star_name[6].$birth;
			}
			break;
		case 11:
			if( $birthday >= 21 ){
				$src = $lang['template.pic9'];
				$alt = $Star_name[8].$birth;
			} else{
				$src = $lang['template.pic8'];
				$alt = $Star_name[7].$birth;
			}
			break;
		case 12:
			if( $birthday >= 21 ){
				$src = $lang['template.pic10'];
				$alt = $Star_name[9].$birth;
			} else{
				$src = $lang['template.pic9'];
				$alt = $Star_name[8].$birth;
			}
			break;
		default:
			return '';
	}
	return "<img src=\"{$src}\" alt=\"{$alt}\">";
}//end function astro

//(用户组ID，用户名)
function GetAdminBoard($UserGroupID,$username){
	global $dv,$db,$lang,$fsetting;
	$ii = 0;
	$returnVal = "<font color=gray>{$lang['GetAdminBoard.strings0']}</font>";
	if( $UserGroupID == 1 ){
		$returnVal = $lang['GetAdminBoard.strings1'];
	} elseif( $UserGroupID <= 3 ){
		$returnVal = '';
		if( $query = $db->query("SELECT boardmaster,boardid,boardtype FROM {$dv}board WHERE boardmaster<>'' ORDER BY rootid,orders") ){
			while( $result =& $db->fetch_array($query) ){
				$MyBoardMaster = "|".trim($result['boardmaster'])."|";
				if( strpos($MyBoardMaster,"|{$username}|") !== false ){
					$ii++;
					$returnVal .= "{$ii}: <a href=\"list.php?boardid={$result['boardid']}\">{$result['boardtype']}</a>{$lang['GetAdminBoard.strings2']}<br/>";
				}
			}
			$db->free_result($query);
		}
	}
	if( $returnVal == '' ){
		$returnVal = "<font color=gray>{$lang['GetAdminBoard.strings0']}</font>";
	}
	return $returnVal;
}//end function GetAdminBoard

function UseTableFunc(){
	global $dv,$db,$dvbbs,$nowusebbs;
	$returnVal = '';
	if( $query = $db->query(" SELECT tablename,tabletype FROM {$dv}tablelist") ){
		while( $result =& $db->fetch_array($query) ){
			$returnVal .= "<option value=\"{$result['tablename']}\" ".( $nowusebbs == $result['tablename'] ? ' selected ' : '' ).">{$result['tabletype']}</option>";
		}
		$db->free_result($query);
	}
	return $returnVal;
}//end function UseTableFunc

?>