<?php
define('THIS_SCRIPT', 'mymodify');
require_once 'global.php';
$lang = load_lang($lang, 'usermanager' );
PageLoad();
LoadFooter();

function PageLoad(){
	global $membername,$action,$groupsetting,$userid,$lang,$db,$_GET,$stats,$master,$superboardmaster,$supermaster,$upface_disable;
	if( intval($userid) == 0 ){
		$arrNavMenu = array(
			 0=>array('linktitle'=>$lang['HeaderTitle1'],'linkurl'=>'usermain.php')
			,1=>array('linktitle'=>$lang['ErrorPrompt'])
		);
		LoadStyleJs();
		showmsg($lang['MustLogin']);
	} elseif( intval($groupsetting[16]) == 0 ){
		$arrNavMenu = array(
			 0=>array('linktitle'=>$lang['HeaderTitle1'],'linkurl'=>'usermain.php')
			,1=>array('linktitle'=>$lang['ErrorPrompt'])
		);
		LoadStyleJs();
		showmsg($lang['PermissionDesc1']);
	}
	if( $_GET['t'] == '1' ){//密码修改
		$stats = $lang['PwdHeaderTitle'];
		if( $action == 'update_pwd' ){
			$arrNavMenu = array(
				 0=>array('linktitle'=>$lang['HeaderTitle1'],'linkurl'=>'usermain.php')
				,1=>array('linktitle'=>$stats)
			);
			LoadStyleJs();
			UpdatePassword();
		}else{
			$arrNavMenu = array(
				 0=>array('linktitle'=>$lang['HeaderTitle1'],'linkurl'=>'usermain.php')
				,1=>array('linktitle'=>$stats)
			);
			LoadStyleJs();
			PasswordInfo();
		}
	} elseif( $_GET['t'] == '2' ){//联系资料修改
		$stats = $lang['ContactHeaderTitle'];
		if( $action == 'update_contact' ){
			$arrNavMenu = array(
				 0=>array('linktitle'=>$lang['HeaderTitle1'],'linkurl'=>'usermain.php')
				,1=>array('linktitle'=>$stats)
			);
			LoadStyleJs();
			UpdateContact();
		}else{
			$arrNavMenu = array(
				 0=>array('linktitle'=>$lang['HeaderTitle1'],'linkurl'=>'usermain.php')
				,1=>array('linktitle'=>$stats)
			);
			LoadStyleJs();
			ContactInfo();
		}
	} else{
		$stats = $lang['HeaderTitle2'];
		if ($action === 'update_userinfo') {
			$arrNavMenu = array(
				 0=>array('linktitle'=>$lang['HeaderTitle1'],'linkurl'=>'usermain.php')
				,1=>array('linktitle'=>$stats)
			);
			LoadStyleJs();
			UpdateUserInfo();
		} else{
			$arrNavMenu = array(
				 0=>array('linktitle'=>$lang['HeaderTitle1'],'linkurl'=>'usermain.php')
				,1=>array('linktitle'=>$stats)
			);
			LoadStyleJs();
			Userinfo();
		}
	}
}//end function PageLoad

function Userinfo(){
	global $cookieprename,$userid,$dv,$db,$lang,$fsetting,$groupsetting,$_DCACHE,$master,$superboardmaster,$userinfo,$upface_disable;
	include_once CACHE_PATH.'forum_face.php';
	$FoundUseMagic = false;
	$MyCookies = get_cookie('usercookies');
	$CanUseTitle = false;
	$CanUseTitle1 = false;
	$CanUseTitle2 = false;
	$CanUserInfo = false;

	$iMagicFace =  explode('|',$userinfo['userface']);
	if(!empty($iMagicFace[1])){
		$UserFace = "<img src=\"".Dv_FilterJS($iMagicFace[1])."\" width=\"".$userinfo['userwidth']."\" height=\"".$userinfo['userheight']."\" alt=\"\">";
	}
	elseif(!empty($iMagicFace[0])){
		$UserFace = "<img src=\"".Dv_FilterJS($iMagicFace[0])."\" width=\"".$userinfo['userwidth']."\" height=\"".$userinfo['userheight']."\" alt=\"\">";
	}
	else{
		$UserFace = "<img src=\"".$userinfo['userface']."\" width=\"".$userinfo['userwidth']."\" height=\"".$userinfo['userheight']."\" alt=\"\">";			
	}
	$TableWidth =& $_DCACHE['stylecss'][1];
	$color =& $_DCACHE['stylecss'][19];
	$user_Article =& $userinfo['userpost'];
	$user_Group =& $userinfo['userclass'];
	$user_Face_left = $UserFace;
	$user_Title =& $userinfo['usertitle'];
	$user_Wealth =& $userinfo['userwealth'];
	$user_EP =& $userinfo['userep'];
	$user_CP =& $userinfo['usercp'];
	$user_Money =& $userinfo['usermoney'];
	$user_Ticket =& $userinfo['userticket'];
	$user_IsBest =& $userinfo['userisbest'];
	$user_AddDate =& $userinfo['joindate'];
	$user_Logins =& $userinfo['userlogins'];
	$username =& $userinfo['username'];
	$msg_newincept = intval($userinfo['uermsg']);

	$stmt = "SELECT userid,username,useremail,userpost,usersign,usersex,userface,userwidth,userheight,joindate,usergroup,usertitle,userbirthday,userphoto,userinfo,usersetting FROM {$dv}user WHERE userid={$userid}";
	if( $query = $db->query($stmt,array('absolutePage'=>1,'pageSize'=>1)) ){
		$_UserInfo =& $db->fetch_array($query);
		if( !empty($_UserInfo) && is_array($_UserInfo) ){
			$db->free_result($query);
			if( intval($fsetting['usertitle']) == 1 ){
				$CanUseTitle = true;
			}
			$postLimited = intval($fsetting['usertitlelimited_post']);
			if( $CanUseTitle && $postLimited > 0 && intval($_UserInfo['userpost']) > $postLimited ){
				$CanUseTitle1 = true;
			} elseif( $CanUseTitle && $postLimited == 0 ){
				$CanUseTitle1 = true;
			} else{
				$CanUseTitle1 = false;
			}
			$dayLimited = intval($fsetting['usertitlelimited_day']);
			if( $CanUseTitle && $dayLimited > 0 && dateDiff('DAY',$_UserInfo['joindate'],TIME_NOW) > $dayLimited ){
				$CanUseTitle2 = true;
			} elseif( $CanUseTitle && $dayLimited == 0 ){
				$CanUseTitle2 = true;
			} else{
				$CanUseTitle2 = false;
			}
			$twoLimited = intval($fsetting['usertitlelimited_two']);
			if( $CanUseTitle && $twoLimited == 1 ){
				if( $CanUseTitle1 && $CanUseTitle2 ){
					$CanUseTitle = true;
				} else{
					$CanUseTitle = false;
				}
			} elseif( $CanUseTitle && ( $CanUseTitle1 || $CanUseTitle2 ) ){
				$CanUseTitle = true;
			} else{
				$CanUseTitle = false;
			}
			$signtrue = $_UserInfo['usersign'];
			if( $_UserInfo['userinfo'] != '' ){
				$ShowUserInfo = explode('|||',$_UserInfo['userinfo']);
				if( count($ShowUserInfo) == 15 ){
					$CanUserInfo = true;
				}
			}
			$UseRsetting = explode('|||',$_UserInfo['usersetting']);
			if( count($UseRsetting) == 3 ){
				if( is_numeric($UseRsetting[0]) ){
					$Setuserinfo = intval($UseRsetting[0]);
				} else{
					$Setuserinfo = 1;
				}
				if( is_numeric($UseRsetting[1]) ){
					$Setusertrue = intval($UseRsetting[1]);
				} else{
					$Setusertrue = 0;
				}
				if( is_numeric($UseRsetting[2]) ){
					$ShowRe = intval($UseRsetting[2]);
				} else{
					$ShowRe = 0;
				}
			} else{
				$Setuserinfo = 1;
				$Setusertrue = 0;
				$ShowRe = 0;
			}
			//魔法头像部分
			$iMagicFace = explode("|",$_UserInfo['userface']);
			if( count($iMagicFace) == 2 ){
				$_UserInfo['userface'] = $iMagicFace[1];
				if( $fsetting['plus_magicface'] == 1 ){
					if( $query = $db->query("SELECT imoney,iticket FROM {$dv}plus_tools_magicface WHERE magicface_s={$iMagicFace[0]}") ){
						if( $result =& $db->fetch_row($query) ){
							$db->free_result($query);
							$FoundUseMagic = true;
							$iMagicMoney = $result[0];
							$iMagicTicket = $result[1];
						}
					}
				}
			}
			if( $fsetting['plus_magicface'] == '1' ){
				if( $FoundUseMagic ){
					$isselect = ' checked ';
					$firstmagicface = $iMagicFace[0];
					$magicmoney = $iMagicMoney;
					$magicticket = $iMagicTicket;
				} else{
					$isselect = '';
					if( $query = $db->query("SELECT magicface_s,imoney,iticket FROM {$dv}plus_tools_magicface ORDER BY id",array('absolutePage'=>1,'pageSize'=>1) ) ){
						if( $result =& $db->fetch_row($query) ){
							$db->free_result($query);
							$firstmagicface = $result[0];
							$magicmoney = $result[1];
							$magicticket = $result[2];
						} else{
							$firstmagicface = 0;
							$magicmoney = 0;
							$magicticket = 0;
						}
					} else{
							$firstmagicface = 0;
							$magicmoney = 0;
							$magicticket = 0;
					}
				}
			}
			$firstmagicface=($firstmagicface==0)?1:$firstmagicface;
			//魔法头像部分
			//管理员与超版自定义头像不受发帖数限制
			$myFacePostLimited = intval($fsetting['myfacepostlimited']);
			if( ($master || $superboardmaster) && intval($_UserInfo['userpost']) < $myFacePostLimited ){
				$_UserInfo['userpost'] = $myFacePostLimited;
			}
			//用$_UserInfo['userpost']判断是否有自定义头像权限，更新page_usermanager模板界面(5)、(7)
			$Forum_UploadSetting = explode('|',$fsetting['uploadsetting']);
			$Forum_userface = explode('|||',$lang['Dvbbs.Forum_userface']);
			$uploadSetting0 = intval($Forum_UploadSetting[0]);
			$face = $_UserInfo['userface'];
			$user_FaceWidth = $_UserInfo['userwidth'];
			$user_FaceHeight = $_UserInfo['userheight'];
			$mypostnum = $_UserInfo['userpost'];
			$Forum_userface = explode('|||',$lang['Dvbbs.Forum_userface']);
			$color = $_DCACHE['stylecss'][19];
			$user_Face = Dv_FilterJS($face);
			$forum_Mwidth = $fsetting['userfacemaxsize'];
			$forum_Mheight = $fsetting['userfacemaxsize'];
			$facepostnum = $fsetting['myfacepostlimited'];
			if($master || $superboardmaster || $supermaster){
				$upface_disable=true;
			}
			else{
				$upface_disable=($mypostnum < $facepostnum)?false:true;
			}
			if( intval($fsetting['ismenpai']) == 1 ){
				//用户门派输出
				if( $query = $db->query("SELECT groupname FROM {$dv}groupname") ){
					$_MenpaiList = array();
					while( $result =& $db->fetch_array($query) ){
						$_MenpaiList[] =& $result;
					}
					if( !empty($_MenpaiList) ) $db->free_result($query);
				} else{
					$SetGroup_info = '';
				}
			} else{
				$SetGroup_info = '';
			}
			$signlength = intval($groupsetting[56]);
			$user_Id = intval($_UserInfo['userid']);
			$checked_sex = $_UserInfo['usersex'];
			$user_Birthday = $_UserInfo['userbirthday'];
			$user_Photo = $_UserInfo['userphoto'];
			$user_Signature = $signtrue;
			$showRe =& $ShowRe;
			$user_Cookies = $MyCookies;
			$user_Setuserinfo = $Setuserinfo;
			$user_Setusertrue = $Setusertrue;
			if( $CanUserInfo == true ){
				$user_Realname = $ShowUserInfo[0];
				$user_character = Chk_KidneyType("character",$ShowUserInfo[1],$lang['template.strings15']);
				$user_Personal = $ShowUserInfo[2];
				$user_Country = $ShowUserInfo[3];
				$user_Province = $ShowUserInfo[4];
				$user_City = $ShowUserInfo[5];
				$user_College = $ShowUserInfo[12];
				$user_Phone = $ShowUserInfo[13];
				$user_Address = $ShowUserInfo[14];
				$user_shengxiao = chk_select($ShowUserInfo[6],$lang['template.strings11']);
				$user_blood = chk_select($ShowUserInfo[7],'A,B,AB,O');
				$user_belief = chk_select($ShowUserInfo[8],$lang['template.strings16']);
				$user_occupation = chk_select($ShowUserInfo[9],$lang['template.strings12']);
				$user_marital = chk_select($ShowUserInfo[10],$lang['template.strings13']);
				$user_education = chk_select($ShowUserInfo[11],$lang['template.strings14']);
			} else{
				$user_Realname = '';
				$user_character = Chk_KidneyType("character","",$lang['template.strings15']);
				$user_Personal = '';
				$user_Country = '';
				$user_Phone = '';
				$user_Address = '';
				$user_Province = '';
				$user_City = '';
				$user_Cartype = '';
				$user_College = '';
				$user_shengxiao = chk_select('',$lang['template.strings11']);
				$user_blood = chk_select('','A,B,AB,O');
				$user_belief = chk_select("",$lang['template.strings16']);
				$user_occupation = chk_select("",$lang['template.strings12']);
				$user_marital = chk_select("",$lang['template.strings13']);
				$user_education = chk_select("",$lang['template.strings14']);
			}
			require_once printout('usermanager.mymodify');
		}
	} else{
		showmsg('ErrCode 32');
	}
}//end function Userinfo

function UpdateUserInfo(){
	global $ErrCodes,$width,$height,$myface,$mypostnum,$showRe,$sex,$userid,$dv,$db,$lang,$fsetting,$groupsetting,$tmp_uploadface,$userinfo,$master,$supermaster;
	$CanUseTitle = false;
	$CanUseTitle1 = false;
	$CanUseTitle2 = false;
	$ErrCodes = '';
	($myface = trim($myface)) AND ($myface = str_filter_xss($myface));	//	XSS处理
	if( is_numeric($sex) ){
		$sex = intval($sex);
	} else{
		$ErrCodes .= 'ErrCode18';
	}
	if( is_numeric($showRe) ){
		$showRe = intval($showRe);
	} else{
		$ErrCodes .= 'ErrCode18';
	}
	//Start 用户自定义头像上传处理部分
	if (!empty($tmp_uploadface)) {echo 'Start 用户自定义头像上传处理部分';
		$uploadsetting = explode('|', $fsetting['uploadsetting']);
		if ($uploadsetting[0] <= 0) {	//	系统未开通头像上传功能！
			showmsg($lang['upuserface.err.str0']);
			exit;
		}
		$upbasedir = $fsetting['forumuploadname'];
		$len = strlen($upbasedir);
		($len > 0) AND ('/' !== $upbasedir{$len - 1}) AND ($upbasedir .= '/');
		$tmpfile = $upbasedir.'tempimage/'.$tmp_uploadface;
		if (!is_file($tmpfile)) {	//	找不到临时上传文件{$TPL_tmpfile}，它可能已被删除！
			showmsg(str_replace('{$TPL_tmpfile}', $tmpfile, $lang['upuserface.err.str1']));
			exit;
		}
		$destfile = $upbasedir.'/faces/'.$tmp_uploadface;
		if (!@rename($tmpfile, $destfile)) {	//	无法移动临时文件{$TPL_tmpfile}到{$TPL_destfile}
			showmsg(str_replace(array('{$TPL_tmpfile}', '{$TPL_destfile}'), array($tmpfile, $destfile), $lang['upuserface.err.str2']));
			exit;
		}
		$myface = str_replace("'","",$myface);
		$db->query("UPDATE {$dv}user SET userface='$myface' WHERE userid={$userid}");
		$GLOBALS['face']=$myface;
	}
	//End 用户自定义头像上传处理部分
	//管理员与超版自定义头像不受发帖数限制
	$myfacepostlimited = intval($fsetting['myfacepostlimited']);
	if( ( $master || $supermaster ) && $mypostnum < $myfacepostlimited ) $mypostnum = $myfacepostlimited;
	if( $myface != '' && ( ($myfacepostlimited > 0 && $mypostnum > $myfacepostlimited) || $myfacepostlimited == 0 ) && strpos(strtolower($myface),'.php') === false ){
		if( $width == '' || $height == '' ){
			$ErrCodes .= "<li>{$lang['template.strings18']}</li>";
		} elseif( !is_numeric($width) || !is_numeric($height) ){
			$ErrCodes .= 'ErrCode18';
		} elseif( $width > intval($fsetting['userfacemaxsize']) ){
			$ErrCodes .= "<li>{$lang['template.strings19']}</li>";
		} elseif( $height > intval($fsetting['userfacemaxsize']) ){
			$ErrCodes .= "<li>{$lang['template.strings20']}</li>";
		} else{
			if( intval($fsetting['httpuserface']) == 0 ){
				if( strpos(strtolower($myface),'"http://"') !== false || strpos(strtolower($myface),'"www."') !== false ){
					$ErrCodes .= "<li>{$lang['template.strings21']}</li>";
				}
			}
			$face = $myface;
		}
	} else{
		$Forum_userface = explode('|||',$lang['Dvbbs.Forum_userface']);
		if( $GLOBALS['face'] == '' ){
			$face =$Forum_userface[0].$Forum_userface[1];
		} else{
			$face = $GLOBALS['face'];
		}
	}
	$face=Dv_FilterJS(str_replace(array("'", '"'), '', $face));
	$face=str_replace(array('..', '\\', '^', '#', '%', '|'), array('', '/', '', '', '', ''),$face);
	$face=substr($face,0,250);
	//魔法表情检查部分
	$tMagicFace = intval($GLOBALS['tmagicface']);
	$iMagicFace = intval($GLOBALS['imagicface']);
	if( $tMagicFace == 1 && $iMagicFace > 0 && $fsetting['plus_magicface'] == 1) {
		if( $query = $db->query("SELECT imoney,iticket,magicsetting FROM {$dv}plus_tools_magicface WHERE magicface_s={$iMagicFace}") ){
			if( $result =& $db->fetch_array($query) ){
				$db->free_result($query);
				$userticket = php_cCur($userinfo['userticket']);
				$usermoney = php_cCur($userinfo['usermoney']);
				if($userticket  < $result['iticket'] || $usermoney < $result['imoney']) {
					showmsg($lang['MagicTest.strings1']);
				}
				$iMagicSetting = explode("|",$result['magicsetting']);
				if( php_cCur($iMagicSetting[0]) > php_cCur($mypostnum) ){
					showmsg($lang['MagicTest.strings2']);
				}
				if( php_cCur($iMagicSetting[1]) > php_cCur($userinfo['userwealth'])) {
					showmsg(urlencode($lang['MagicTest.strings3']));
				}
				if( php_cCur($iMagicSetting[2]) > php_cCur($userinfo['userep'])) {
					showmsg($lang['MagicTest.strings4']);
				}
				if( php_cCur($iMagicSetting[3]) > php_cCur($userinfo['usercp'])) {
					showmsg($lang['MagicTest.strings5']);
				}
				if( php_cCur($iMagicSetting[4]) > php_cCur($userinfo['userpower'])) {
					showmsg($lang['MagicTest.strings6']);
				}
				$face = "{$iMagicFace}|{$face}";
				$tMagicMoney = $result['imoney'];
				$tMagicTicket = $result['iticket'];
				$FoundUseMagic = true;
			} else{
				$face = "0|{$face}";
				$tMagicMoney = 0;
				$tMagicTicket = 0;
			}
		} else{
			$face = "0|{$face}";
		}
	} else{
		$face = "0|{$face}";
	}
	if( $width == '' || $height == '' ){
		$width = $fsetting['userfacewidth'];
		$height = $fsetting['userfaceheight'];
	}
	if( Dv_StrLength($GLOBALS['Signature']) > 250 ){
			$ErrCodes .= $lang['template.strings23'];
	} elseif( Dv_StrLength($GLOBALS['Signature']) > intval($groupsetting[56]) && intval($groupsetting[56]) > 0 ){
			$ErrCodes .= str_replace('250',$groupsetting[56],$lang['template.strings23']);
	}
	$birthday = trim($GLOBALS['birthday']);
	if( !isDate($birthday) ) {
		$birthday = '';
	} else {
		$birthday = dv_gmtimestamp($birthday) - getUserTimeZoneOffset();
	}
	$character = is_array($GLOBALS['character']) ? implode(',',checkreal($GLOBALS['character'])) : '' ;
	$userinfo = checkreal($GLOBALS['realname']).'|||'.$character.'|||'.checkreal($GLOBALS['personal']).'|||'.checkreal($GLOBALS['country']).'|||'.checkreal($GLOBALS['province']).'|||'.checkreal($GLOBALS['city']).'|||'.checkreal($GLOBALS['shengxiao']).'|||'.checkreal($GLOBALS['blood']).'|||'.checkreal($GLOBALS['belief']).'|||'.checkreal($GLOBALS['occupation']).'|||'.checkreal($GLOBALS['marital']).'|||'.checkreal($GLOBALS['education']).'|||'.checkreal($GLOBALS['college']).'|||'.checkreal($GLOBALS['userphone']).'|||'.checkreal($GLOBALS['address']);
	$userinfo = htmlspecialchars($userinfo);
	$usersetting = htmlspecialchars($GLOBALS['setuserinfo'].'|||'.$GLOBALS['setusertrue'].'|||'.$showRe);
	if( $ErrCodes != '' ){
		showmsg($ErrCodes);
		return false;
	}
	if( $query = $db->query("SELECT userid,username,userpassword,useremail,userpost,usertopic,usersign,usersex,userface,userwidth,userheight,userim,joindate,lastlogin,userlogins,userviews,lockuser,userclass,usergroup,userwealth,userep,usercp,userpower,userdel,userisbest,usertitle,userbirthday,userquesion,useranswer,userlastip,userphoto,userfav,userinfo,usersetting,usergroupid,userhidden,titlepic,usermsg,ischallenge,usermobile,truepassword,usertoday,userisava,useravasetting,usermoney,userticket,followmsgid,vip_startime,vip_endtime,passport FROM {$dv}user WHERE userid={$userid}") ){
		set_magic_quotes_runtime(1);
		if( $result =& $db->fetch_array($query) ){
			$db->free_result($query);
			$iFace = explode('|',$result['userface']);
			if( count($iFace) == 2 && $fsetting['plus_magicface'] == 1 ){
				$tmpArr = explode('|',$face);
				if( $iFace[0] != $tmpArr[0] ){
					if( php_cCur(get_cookie('usermoney')) > $tMagicMoney ){
						$result['usermoney'] -= $tMagicMoney;
						ToolsLog(-88,1,$tMagicMoney,0,1,$lang['page.strings1'],$userinfo['usermoney'].'|'.$userinfo['userticket']);
					} else{
						$result['userticket'] -= $tMagicTicket;
						ToolsLog(-88,1,0,$tMagicTicket,1,$lang['page.strings2'],$userinfo['usermoney'].'|'.$userinfo['userticket']);
					}
				}
			}
			$result['userface'] = $face;
			$result['userwidth'] = str_replace('|','',$width);
			$result['userheight'] = str_replace('|','',$height);
			$result['usersex'] = $sex;
			$result['usersign'] = str_replace('|','',$GLOBALS['Signature']);
			if($GLOBALS['userphoto']=='' or empty($GLOBALS['userphoto'])){//adwer edit 2006-8-5;
				$result['userphoto'] = $result['userphoto'] ;
			}
			else{
				$result['userphoto'] = str_replace('|','',$GLOBALS['userphoto']);
			}
			if( $fsetting['ismenpai'] == 1 && IsTrueGroupName($GLOBALS['GroupName']) ){
				$result['usergroup'] = str_replace('|','',htmlspecialchars($GLOBALS['GroupName']));
			} else{
				$result['usergroup'] = '';
			}
			//判断是否允许提交头衔
			if( $fsetting['usertitle'] == 1 ){
				$CanUseTitle = true;
			}
			$usertitlelimited_post = intval($fsetting['usertitlelimited_post']);
			if( $CanUseTitle && $usertitlelimited_post > 0 && $result['userpost'] > $usertitlelimited_post ){
				$CanUseTitle1 = true;
			} elseif( $CanUseTitle && $usertitlelimited_post == 0 ){
				$CanUseTitle1 = true;
			} else{
				$CanUseTitle1 = false;
			}
			$usertitlelimited_day = intval($fsetting['usertitlelimited_day']);
			if( $CanUseTitle && $usertitlelimited_day > 0 && dateDiff('DAY',$result['joindate'],TIME_NOW) > $usertitlelimited_day ){
				$CanUseTitle2 = true;
			} elseif( $CanUseTitle && $usertitlelimited_day == 0 ){
				$CanUseTitle2 = true;
			} else{
				$CanUseTitle2 = false;
			}
			$usertitlelimited_two = intval($fsetting['usertitlelimited_two']);
			if( $CanUseTitle && $usertitlelimited_two == 1 ){
				if( $CanUseTitle1 && $CanUseTitle2 ){
					$CanUseTitle = true;
				} else{
					$CanUseTitle = false;
				}
			} elseif( $CanUseTitle && ( $CanUseTitle1 || $CanUseTitle2 ) ){
				$CanUseTitle = true;
			} else{
				$CanUseTitle = false;
			}
			$usertitle = str_replace('|','',$GLOBALS['title']);
			if( $CanUseTitle ){
				if( trim($fsetting['usertitlelimited_word'])  != '' ){
					$SplitUserTitle = explode('|',$fsetting['usertitlelimited_word']);
					if( !empty($SplitUserTitle) && is_array($SplitUserTitle) ){
						foreach( $SplitUserTitle as $val ){
							if( strpos($usertitle,$val) !== false ){
								$ErrCodes .= $lang['template.strings24'];
								break;
							}
						}
					}
				}
				if( Dv_StrLength($usertitle) > intval($fsetting['usertitlelength']) ){
					$ErrCodes .= str_replace('{$MaxTitleLen}',$fsetting['usertitlelength'],$lang['template.strings25']);
				}
				$result['usertitle'] = $usertitle;
			}
			if( $birthday != '' ) $result['userbirthday'] = $birthday;
			$result['userinfo'] = $userinfo;
			$result['usersetting'] = trim($usersetting);
			$updStmt = 'UPDATE '.$dv.'user SET ';
			$currUserID = $result['userid'];
			unset($result['userid'],$result['userpassword'],$result['truepassword']);
			$comma = '';
			foreach( $result as $key => $val ){
				$updStmt .= " {$comma}{$key}='".iHtmlencode($val)."'";
				$comma = ',';
			}
			$updStmt .= " WHERE userid={$currUserID}";
			$db->query($updStmt);
			set_magic_quotes_runtime(0);
			global $_POST;
			$usercookies = $_POST['usercookies'];
			if( is_numeric($usercookies) ){
				$usercookies = intval($usercookies);
			} else{
				$usercookies = 0;
			}
			switch($usercookies){
				case 0:
					set_cookie('usercookies', $usercookies, 0);
					break;
				case 1:
					set_cookie('usercookies', $usercookies, 1*24*60*60);
					break;
				case 2:
					set_cookie('usercookies', $usercookies, 31*24*60*60);
					break;
				case 3:
					set_cookie('usercookies', $usercookies, 365*24*60*60);
					break;
			}
		} else{
			$ErrCodes .= 'ErrCodes 12';
		}
	} else{
		$ErrCodes .= 'ErrCodes 12';
	}
	showmsg("{$lang['template.strings26']}",1,'mymodify.php');
}//end function Update

function PasswordInfo(){
	global $dv,$db,$lang,$userid,$_DCACHE,$userinfo;
	if( $query = $db->query("SELECT userid,useranswer,userquesion FROM {$dv}user WHERE userid={$userid}") ){
		if( $result =& $db->fetch_array($query) ){
			$db->free_result($query);
			$user_id = intval($result['userid']);
			$user_answer = $result['useranswer'];
			$user_quesion =& $result['userquesion'];
			$iMagicFace =  explode('|',$userinfo['userface']);
			if(!empty($iMagicFace[1])){
				$UserFace = "<img src=\"".Dv_FilterJS($iMagicFace[1])."\" width=\"".$userinfo['userwidth']."\" height=\"".$userinfo['userheight']."\" alt=\"\">";
			}
			elseif(!empty($iMagicFace[0])){
				$UserFace = "<img src=\"".Dv_FilterJS($iMagicFace[0])."\" width=\"".$userinfo['userwidth']."\" height=\"".$userinfo['userheight']."\" alt=\"\">";
			}
			else{
				$UserFace = "<img src=\"".$userinfo['userface']."\" width=\"".$userinfo['userwidth']."\" height=\"".$userinfo['userheight']."\" alt=\"\">";			
			}
			$TableWidth =& $_DCACHE['stylecss'][1];
			$color =& $_DCACHE['stylecss'][19];
			$user_Article =& $userinfo['userpost'];
			$user_Group =& $userinfo['userclass'];
			$user_Face_left = $UserFace;
			$user_Title =& $userinfo['usertitle'];
			$user_Wealth =& $userinfo['userwealth'];
			$user_EP =& $userinfo['userep'];
			$user_CP =& $userinfo['usercp'];
			$user_Money =& $userinfo['usermoney'];
			$user_Ticket =& $userinfo['userticket'];
			$user_IsBest =& $userinfo['userisbest'];
			$user_AddDate =& $userinfo['joindate'];
			$user_Logins =& $userinfo['userlogins'];
			$username =& $userinfo['username'];
			$msg_newincept = intval($userinfo['uermsg']);

			require_once printout('usermanager.chgpwd');
		}
	} else{
		showmsg($lang['chgpwd.error.strings1']);
	}
}//end function PasswordInfo
function UpdatePassword(){
	global $dv,$db,$lang,$userid,$_POST;
	if( $GLOBALS['oldpsw'] == '' ){
		showmsg($lang['template.strings27']);
		return false;
	}
	if( $GLOBALS['quesion'] == '' ){
		showmsg($lang['template.strings29']);
		return false;
	} else{
		$question = $GLOBALS['quesion'];
	}
	if( $GLOBALS['answer'] == '' ){
		showmsg($lang['template.strings30']);
		return false;
	} elseif( $GLOBALS['answer'] == $GLOBALS['oldanswer'] ){
		$answer = $GLOBALS['oldanswer'];
	} else{
		$answer = dv_md5($GLOBALS['answer']);
	}
	if( $query = $db->query("SELECT userpassword FROM {$dv}user WHERE userid={$userid}") ){
		if( $result =& $db->fetch_array($query) ){
			$db->free_result($query);
			if( dv_md5($_POST['oldpsw']) != $result['userpassword'] ){
				showmsg($lang['template.strings28']);
				return false;
			} else{
				$oldpassword = $GLOBALS['oldpsw'];
			}
			if( $GLOBALS['psw'] != '' ){
				$password = dv_md5($GLOBALS['psw']);
			} else{
				$password = $result['userpassword'];
			}
			$rv = $db->query("UPDATE {$dv}user SET userpassword='$password',useranswer='$answer',userquesion='$question' WHERE userid={$userid}");
			showmsg("<li>{$lang['template.strings26']}</li>",1,'mymodify.php?t=1');
			return $rv;
		}
	}
	return false;
}//end function UpdatePassword

function ContactInfo(){
	global $dv,$db,$lang,$userid,$userinfo,$_DCACHE;
	if( $query = $db->query("SELECT userid,useremail,userim FROM {$dv}user WHERE userid={$userid}") ){
		if( $result =& $db->fetch_array($query) ){
			$db->free_result($query);
			$user_id = intval($result['userid']);
			$user_email =& $result['useremail'];
			if( is_null($result['userim']) || $result['userim'] == '' ){
				$user_homepage = '';
				$user_oicq = '';
				$user_icq = '';
				$user_Msn = '';
				$user_Yahoo = '';
				$user_Aim = '';
				$user_UC = '';
			} else{
				$userim = explode('|||',$result['userim']);
				$user_homepage = $userim[0];
				$user_oicq = $userim[1];
				$user_icq = $userim[2];
				$user_Msn = $userim[3];
				$user_Yahoo = $userim[4];
				$user_Aim = $userim[5];
				$user_UC = $userim[6];
			}

			$iMagicFace =  explode('|',$userinfo['userface']);
			if(!empty($iMagicFace[1])){
				$UserFace = "<img src=\"".Dv_FilterJS($iMagicFace[1])."\" width=\"".$userinfo['userwidth']."\" height=\"".$userinfo['userheight']."\" alt=\"\">";
			}
			elseif(!empty($iMagicFace[0])){
				$UserFace = "<img src=\"".Dv_FilterJS($iMagicFace[0])."\" width=\"".$userinfo['userwidth']."\" height=\"".$userinfo['userheight']."\" alt=\"\">";
			}
			else{
				$UserFace = "<img src=\"".$userinfo['userface']."\" width=\"".$userinfo['userwidth']."\" height=\"".$userinfo['userheight']."\" alt=\"\">";			
			}
			$TableWidth =& $_DCACHE['stylecss'][1];
			$color =& $_DCACHE['stylecss'][19];
			$user_Article =& $userinfo['userpost'];
			$user_Group =& $userinfo['userclass'];
			$user_Face_left = $UserFace;
			$user_Title =& $userinfo['usertitle'];
			$user_Wealth =& $userinfo['userwealth'];
			$user_EP =& $userinfo['userep'];
			$user_CP =& $userinfo['usercp'];
			$user_Money =& $userinfo['usermoney'];
			$user_Ticket =& $userinfo['userticket'];
			$user_IsBest =& $userinfo['userisbest'];
			$user_AddDate =& $userinfo['joindate'];
			$user_Logins =& $userinfo['userlogins'];
			$username =& $userinfo['username'];
			$msg_newincept = intval($userinfo['uermsg']);

			require_once printout('usermanager.chgcontact');
		}
	} else{
		showmsg($lang['chgpwd.error.strings1']);
	}
}//end function ContactInfo
function UpdateContact(){
	global $dv,$db,$lang,$userid;
	$userpassword = $GLOBALS['password'];
	if( $userpassword == '' ){
		showmsg($lang['template.strings27']);
		return false;
	} else{
		$userpassword = dv_md5($userpassword);
	}
	//校验email
	if( !TestEmail($GLOBALS['Email']) ){
		showmsg($lang['template.strings31']);
		return false;
	} elseif( !is_null($fsetting['banmail']) && $fsetting['banmail'] != '' && $fsetting['banmail'] != '0' ){
		$SplitUserEmail = explode('|',$fsetting['banmail']);
		if( !empty($SplitUserEmail) && is_array($SplitUserEmail) ){
			foreach( $SplitUserEmail as $val ){
				if( strpos($GLOBALS['Email'],$val) !== false ){
					showmsg($lang['template.strings32']);
					return false;
				}
			}
		}
	}
	$oicq = trim($GLOBALS['Oicq']);
	if( $oicq != '' ){
		if( !is_numeric($oicq) || strlen($oicq) > 12 ){
			showmsg($lang['chgcontact.error.strings2']);
			return false;
		}
	}
	$icq = trim($GLOBALS['Icq']);
	if( $icq != '' ){
		if( !is_numeric($icq) || strlen($icq) > 12 ){
			showmsg($lang['chgcontact.error.strings3']);
			return false;
		}
	}
	//校验密码
	if( $query = $db->query("SELECT userpassword FROM {$dv}user WHERE userid={$userid}") ){
		if( $result =& $db->fetch_array($query) ){
			$db->free_result($query);
			if( $result['userpassword'] != $userpassword ){
				showmsg($lang['chgcontact.error.strings1']);
				return false;
			}
			$HomePage = trim($GLOBALS['homepage']);
			if( $HomePaage != '' && strtolower(substr($HomePage,0,7)) != 'http://' ){
				$HomePage = 'http://'.$HomePage;
			}
			$NewUserIM = checkreal($HomePage).'|||'.checkreal($oicq).'|||'.checkreal($icq).'|||'.checkreal($GLOBALS['Msn']).'|||'.checkreal($GLOBALS['UserAim']).'|||'.checkreal($GLOBALS['Yahoo']).'|||'.checkreal($GLOBALS['UC']);
			$NewUserIM = htmlspecialchars($NewUserIM);
			$db->query("UPDATE {$dv}user SET useremail='{$GLOBALS['Email']}', userim='{$NewUserIM}' WHERE userid={$userid} ");
			showmsg($lang['template.strings26']);
			return true;
		} else{
			showmsg($lang['chgcontact.error.strings1']);
			return false;
		}
	} else{
		showmsg($lang['chgcontact.error.strings1']);
		return false;
	}
	return true;
}//end function UpdateContact



function checkreal($v){
	if( !is_null($v) ){
		return str_replace('|','',$v);
	} else{
		return '';
	}
}//end function checkreal

function IsTrueGroupName($GroupName){
	global $dv,$db;
	if( $GroupName == '' ) return false;
	$query = $db->query("SELECT COUNT(1) FROM {$dv}groupname WHERE groupname='{$GroupName}'");
	$result =& $db->fetch_row($query);
	if( intval($result[0]) <= 0 ) return false;
	else return true;
}//end function IsTrueGroupName


//多项选取转换输出
function Chk_KidneyType($str0,$str1,$str2){
	$str2 = explode(',',$str2);
	$returnVal = array();
	$count = count($str2);
	for( $i = 0 ; $i < $count ; $i++ ){
		$val = trim($str2[$i]);
		$checked = ( strpos($str1,$val) !== false ? ' checked ' : '' );
		$br = ( ($i+1) % 5 == 0 ? '<br>' : '' );
		$returnVal[] = "<INPUT type=\"checkbox\" name=\"{$str0}[]\" value=\"{$val}\" {$checked} class=chkbox>{$val}{$br}";
	}
	if( empty($returnVal) ){
		return '';
	} else{
		return implode('',$returnVal);
	}
}//end function Chk_KidneyType

//下拉菜单转换输出
Function chk_select($str1,$str2){
	$returnVal = array();
	if( empty($str1) ){
		$returnVal[] = '<option value="" selected>...</option>';
	}
	$str2 = explode(',',$str2);
	if( !empty($str2) && is_array($str2) ){
		foreach( $str2 as $val ){
			$selected = ( $val == $str1 ? ' selected ' : '' );
			$returnVal[] = "<option value=\"{$val}\" {$selected}>{$val}</option>";
		}
	}
	if( empty($returnVal) ){
		return '';
	} else{
		return implode('',$returnVal);
	}
}//end function chk_select
?>