<?

require("datafile/superadmin.php");
require("datafile/config.php");
require("datafile/style.php");
require("global.php");
require("vibcode.lib");
include("datafile/usertitle.php");

if (file_exists("datafile/admin.php")) {
	$adminlist=file("datafile/admin.php");
	$count=count($adminlist);
	for ($i=0; $i<$count; $i++) {
		$detail=explode("|", trim($adminlist[$i]));
		$forum_admin[]=$detail[1];
	}
}
$add_title="信息管理程式";
if (empty($job)) { $job="modify"; }

if ($job=="show") {
	include("header.php");
	navi_bar("你正处在<br>VIB 论坛<br>的PROFILE程式中","信息资料");
	if (!$target || strrpos($target,'/')!==false || $target=="." || ereg("\.\.",$target) || !file_exists("$id_unique/$target")) {
		msg_box('PROFILE程式','<br>状态：发生错误，您所指定的用户不存在<br><ul><li><a href="javascript:history.back(1)">返回前页</a></li></ul>');
	}
	else show_member();
	include("footer.php");
	exit;
}

if ($job=="modify") {
	include("header.php");
	navi_bar("你正处在<br>VIB论坛<br>的PROFILE程式中","信息资料");
	if ($login_status==0) {
		msg_box('PROFILE程式','<br>状态：发生错误，您还没有登录<br><ul><li><a href="javascript:history.back(1)">返回前页</a></li><br><li><a href="viblogin.php">现在登录</li></ul>');
		include("footer.php");
		exit;
	}
	if (empty($step)) {
		show_form();
		include("footer.php");
		exit;
	} elseif($step==2) {

//-----------check---------
$check=1;
list($name,$pwd,$icon,$email,$oicq,$regdate,$sign,$page,$area,$comment,$honor,$lastpost,$postamount,$pe,$receive)=get_user_info($username);
if (!empty($addpassword)) $pwd=stripslashes($addpassword);
if (!empty($addemail)) $email=$addemail;
if (!empty($oicqnumber)) $oicq=$oicqnumber;
if (!empty($signature)) $sign=stripslashes($signature);
if (!empty($usericon)) $icon=$usericon;
if (!empty($homepage)) $page=$homepage;
if (!empty($fromwhere)) $area=stripslashes($fromwhere);
if (!empty($addcomment)) $comment=stripslashes($addcomment);
if (!empty($newhonor) || $postamount>=$use_honor) $honor=stripslashes($newhonor);

$pwd=str_replace("\t","",$pwd); $pwd=str_replace("\r","",$pwd); $pwd=str_replace("\n","",$pwd);
if (strrpos($pwd,"|")!==false || strrpos($pwd,"<")!==false || strrpos($pwd,">")!==false) {$reason="密码包含不可接受字符，请使用英文和数字"; $check=0;}
if (!ereg("^[-a-zA-Z0-9_\.]+\@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,3}$",$email)) {$reason="信箱不符合检查标准，请确认没有错误(拜托，假的也要像一点)"; $check=0;}
if (!empty($publicmail) && $publicmail=="yes") $publicmail=1; else $publicmail=0;
if (!ereg("^[0-9]{0,}$",$oicq)) {$reason="OICQ号码不正确"; $check=0;}
if (strlen($comment)>200) {$reason="自我介绍太长，请删掉一些，控制在100个字以内"; $check=0;}
if (strlen($sign)>$max_sign_length) {$reason="签名档太长，请删掉一些，控制在100个字以内"; $check=0;}

$page	=	safe_convert($page);
$comment=	safe_convert($comment);
$sign	=	safe_convert($sign);
$area	=	safe_convert($area);

if (empty($receivemail)) $receivemail="text";
elseif ($receivemail=="html") $receivemail="html";
elseif ($receivemail=="none") $receivemail="none";
else $receivemail="text";
$receive=$receivemail;
if (!empty($publicemail)) $pe=1;
else $pe=0;
	if ($own_portait[0]) {
	  if (!ereg("^[0-9]{1,2}$",$own_portait[1]) && $own_portait[1]!=100) {$reason="自定义头像宽度不正确"; $check=0;}
	  if (!ereg("^[0-9]{1,2}$",$own_portait[2]) && $own_portait[2]!=100) {$reason="自定义头像高度不正确"; $check=0;}
	  $own_portait[0]=safe_convert($own_portait[0]);
	  if (strrpos($own_portait[0],'%')!==false) {$reason="自定义头像包含不可接受字符，请使用正常URL"; $check=0;}
	}

//--------------check complete---------
		if ($check==0) {
			msg_box('PROFILE程式',"<br>状态：发生错误，$reason<br><ul><li><a href=\"javascript:history.back(1)\">返回前页</a></li></ul>");
		}
		else {
			if ($own_portait) $icon.="%$own_portait[0]%$own_portait[1]%$own_portait[2]";
			$newline=array($name,$pwd,$icon,$email,$oicq,$regdate,$sign,$page,$area,$comment,$honor,$lastpost,$postamount,$pe,$receive);
			writetofile("$id_unique/$username",implode("|",$newline));

			msg_box('PROFILE程式',"<br>状态：操作成功，您已经成功修改了您的信息<br><ul><li><a href=\"viboard.php\">返回论坛</a></li><br><li><a href=\"vibprofile.php?job=testsign\">测试签名</a></li></ul>");
		}
		include("footer.php");
		exit;
	}
}

if ($job=="kill") {
	include("header.php");
	navi_bar("你正处在<br>VIB论坛 <br>的PROFILE程式中","信息资料");
	if ($login_status==0) {
		msg_box('PROFILE程式','<br>状态：发生错误，您还没有登录
		<br><ul><li><a href="javascript:history.back(1)">返回前页</a>
		</li><br><li><a href="viblogin.php">现在登录</li></ul>');
		include("footer.php");
		exit;
	}
	if (empty($step)) {
		print_confirm();
	} elseif($step==2) {
		unlink("$id_unique/$username");
		if (file_exists("$id_unique/$username.rec")) unlink("$id_unique/$username.rec");
		if (file_exists("$id_unique/$username.snd")) unlink("$id_unique/$username.snd");
		msg_box('PROFILE程式','<br>哎<br><br>又<b>死</b>了一个.........<ul><li><a href="viboard.php">返回论坛首页</a></li></ul>');
	}
	include("footer.php");
	exit;
}
if ($job=="testsign") {
	include("header.php");
	navi_bar("你正处在<br>VIB论坛 <br>的PROFILE程式中","信息资料");
	if ($login_status==0) {
		msg_box('PROFILE程式','<br>状态：发生错误，您还没有登录<br><ul><li><a href="javascript:history.back(1)">返回前页</a></li><br><li><a href="viblogin.php">现在登录</li></ul>');
	}
	else {
		$temp=get_user_info($username);
		$sign=$temp[6];
		msg_box('PROFILE程式',"<br>状态：查看签名，下面是您的签名<br><hr width=340 size=1><table width=340 align=center><tr><td>".vibconvert($sign)."</td></tr></table><br><hr width=340 size=1><ul><li><a href='javascript:history.back(1)'>返回前页</a></li></ul>");
	}
	include("footer.php");
	exit;
}
function print_confirm() {
msg_box('PROFILE程式',"<br>
            不会吧，真的要自杀？<br>
            <br><center>
            <input type=button value=\"   想想也是，干吗那么轻生呢，回吧          \" onClick=\"location.href='javascript:history.back(1)'\" style=\"height:20px; background-color:#f3f3f3; border:1 solid black;\" onMouseOver =\"this.style.backgroundColor='#FFC864'\" onMouseOut =\"this.style.backgroundColor='#f3f3f3'\">
            <br>
            <br>
            <input type=button value=\"   哎，我决定了，别拦我了，反正和Vieky无关  \" onClick=\"location.href='vibprofile.php?job=kill&step=2'\" style=\"height:20px; background-color:#f3f3f3; border:1 solid black;\" onMouseOver =\"this.style.backgroundColor='#FFC864'\" onMouseOut =\"this.style.backgroundColor='#f3f3f3'\">
            <br></center>
            <br>
            千万想好了呀............<br>
            <br>");
}

function show_form() {
global $username,$use_honor,$bordercolor,$subcolor,$admin_name,$titlecolor,$tablewidth,$sign_use_vibcode,$vibcode_sign,
$use_own_portait;

list($name,$pwd,$usericon,$email,$oicq,$regdate,$sign,$homepage,$area,$comment,$honor,$lastpost,$postamount,$pe)=get_user_info($username);
$usericon=explode('%',$usericon);
$sign=str_replace("<br>","\r\n",$sign);
if ($pe) $pe="checked";
$style="style=\"background-color:#ffffff; color:#333366; border: 1 double #B4B4B4\"";
$style2="style=\"background-color:#ffffff; color:#666666; border: 1 double #B4B4B4\"";

print <<<EOT
<br>
<table width=$tablewidth border=0 cellspacing=0 cellpadding=0 align=center bgcolor=$bordercolor>
  <form action=vibprofile.php method=post name="creator">
  <tr>
    <td>
<table width=100% border=0 cellpadding=3 cellspacing=1>
  <tr bgcolor=$titlecolor> 
    <td colspan=2 background=images/style/catbg.gif>信息管理程式</td>
  </tr>
  <tr bgcolor=FFFFFF> 
    <td align=center colspan=2><b>查看/修改个人信息 </b> </td>
  </tr>
  <tr bgcolor=eeeeee> 
    <td width=30% valign=middle>&nbsp;新的密码：<br>
      &nbsp;(如果为空,则不做修改,下同) </td>
    <td width=70%> 
      <input type=password size=20 maxlength=75 name="addpassword" value="" style="background-color:#ffffff; color:#0000ff; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''">
      (最好是英文字母或数字等)</td>
  </tr>
  <tr bgcolor=FFFFFF> 
    <td valign=middle>&nbsp;您的E-MAIL：<br>
      &nbsp;(您可以选择不公开 )</td>
    <td><b> 
      <input type="text" size="20" maxlength="75" name="addemail" value="$email" $style onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''">
      </b>(很重要，用于寄送密码<font color="#000000">)<br>
      </font> 
      <input type="checkbox" name="publicemail" value="1" $pe>
      <font color=#000000>公开邮箱 </font></td>
  </tr>
  <tr bgcolor=FFFFFF> 
    <td>&nbsp;您的OICQ号码：</td>
    <td><input type="text" size="20" maxlength="14" name="oicqnumber" value="$oicq" $style onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''"></td>
  </tr>
  <tr bgcolor=eeeeee>
    <td>&nbsp;如果您有个人主页：</td>
    <td><input type="text" size="20" maxlength="75" name="homepage" value="$homepage" $style onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''"></td>
  </tr>
  <tr bgcolor=FFFFFF> 
    <td>&nbsp;个性化签名：<br>
&nbsp;将附在每篇文章后 <br>
&nbsp;<font face=verdana><a href="javascript:openScript('vibfaq.php',700,500)">VIB Code</a>
EOT;

if ($sign_use_vibcode) {
	echo ' 开启'; 
echo '<br>&nbsp;[img] &nbsp; -';
if ($vibcode_sign['pic']) echo " 开启"; else echo " 关闭";
echo '<br>&nbsp;[flash] -';
if ($vibcode_sign['flash']) echo " 开启"; else echo " 关闭";
echo '<br>&nbsp;[size]&nbsp; -';
if ($vibcode_sign['fontsize']) echo " 开启"; else echo " 关闭";
} else echo ' 关闭';

print <<<EOT
</font>
</td>
<td><textarea cols=50 name="signature" $style2 onMouseOver="this.style.backgroundColor = '#E5F0FF'" onMouseOut="this.style.backgroundColor = ''" rows="4">$sign</textarea></td>
  </tr>
  <tr bgcolor=eeeeee> 
    <td>&nbsp;来自：</td>
    <td><input type=text value="$area" size="20" maxlength="20" name="fromwhere" $style2 onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''"></td>
  </tr>
  <tr bgcolor=FFFFFF> 
    <td>&nbsp;自我简介：<br>&nbsp;限一百字以内</td>
    <td><textarea name="addcomment" rows="4" cols="50" $style2 onMouseOver = "this.style.backgroundColor = '#f3f3f3'" onMouseOut = "this.style.backgroundColor = ''">$comment</textarea></td>
  </tr>
EOT;

if ($postamount>=$use_honor || $username==$admin_name ) {
print <<<EOT
  <tr bgcolor=FFFFFF>
  <td>&nbsp;荣誉头衔：</td>
    <td><input name="newhonor" value="$honor" type="text" size="20" maxlength="20" $style2 onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''"></td>
  </tr>
EOT;
}
echo '<tr align=left bgcolor=FFFFFF>
	<td align=left valign="middle">&nbsp;选择您的头像：<br>&nbsp;点<a href="javascript:openScript(\'listpic.php?dir=face\',700,500)"><b>这里</b></a>看所有图<br>
	<br>&nbsp;<b>自定义头像：</b><br>';
if (!$use_own_portait) echo '&nbsp;- 被管理员关闭';
else echo '&nbsp;- 被管理员打开<br>你也可以在这里给出你自定义头像的 URL 地址，头像的高度和宽度(像素)。 如果不想要自定义头像，请将各选项留空';
echo '</td>
	<td valign=top>
<script language="javascript">
   function showimage(){
     document.images.useravatars.src="images/face/"+document.creator.usericon.options[document.creator.usericon.selectedIndex].value;}
</script>
	 <table width=100% border=0 cellspacing=0 cellpadding=0>
	  <tr>
	   <td width=22% align=center valign=middle> 
		<select name="usericon" onChange="showimage()">';
$dh=opendir("images/face");
while ($imagefile=readdir($dh)) {
	if (($imagefile!=".") && ($imagefile!="..") && ($imagefile!=""))
	  if ($imagefile==$usericon[0]) echo "<option selected value=\"$imagefile\">$imagefile</option>";
	    else echo "<option value=\"$imagefile\">$imagefile</option>";
}
closedir($dh);
echo "</select>
	    </td>
	    <td width=78% align=center valign=middle><img src='images/face/$usericon[0]' name=useravatars border=0></td>
	   </tr>
	</table>
<br>";

if ($use_own_portait) {
print <<<EOT
图像位置：<input value="$usericon[1]" type=text size=35 name=own_portait[0] style="background-color:#ffffff; color:#666666; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''">输入完整的 URL 路径。<br>
图像宽度：<input value="$usericon[2]" type=text size=2 maxlength=3 name=own_portait[1] style="background-color:#ffffff; color:#666666; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''">必须是 20 -- 100 之间的一个整数。<br>
图像高度：<input value="$usericon[3]" type=text size=2 maxlength=3 name=own_portait[2] style="background-color:#ffffff; color:#666666; border: 1 double #B4B4B4" onMouseOver = "this.style.backgroundColor = '#E5F0FF'" onMouseOut = "this.style.backgroundColor = ''">必须是 20 -- 100 之间的一个整数。
EOT;
}
echo '</td>
    </tr>';

print <<<EOT
<tr bgcolor=EEEEEE> 
<td valign=top colspan=2>&nbsp;是否接受邮件： 
<input type=radio name="receivemail" value="text" checked>
接收文本邮件 
<input type=radio name="receivemail" value="html">
接收HTML邮件 
<input type=radio name="receivemail" value="none">
不接收邮件 </td>
</tr>
<tr bgcolor=$subcolor> 
<td align="center" colspan=2> 
<input type="button" value="论坛首页" onClick="location.href='viboard.php'" style="height:20px; background-color:#f3f3f3; border:1 solid black;" onMouseOver ="this.style.backgroundColor='#FFC864'" onMouseOut ="this.style.backgroundColor='#f3f3f3'">
<input onClick="javascript:history.back(1)" type="button" value="返回前页" style="height:20px;background-color:#f3f3f3; border:1 solid black" onMouseOver ="this.style.backgroundColor='#FFC864'" onMouseOut ="this.style.backgroundColor='#f3f3f3'">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<input type=submit value="确认修改" style="height:20px;background-color:#f3f3f3;border:1 solid black" onMouseOver ="this.style.backgroundColor='#FFC864'" onMouseOut ="this.style.backgroundColor='#f3f3f3'">
<input type=hidden value="2" name="step">
<input type=reset value="清除重写" style="height:20px;background-color:#f3f3f3;border:1 solid black" onMouseOver ="this.style.backgroundColor='#FFC864'" onMouseOut ="this.style.backgroundColor='#f3f3f3'" name="reset">
</td></tr>
<TABLE style=BORDER-COLLAPSE: collapse borderColor=#111111 cellSpacing=0 cellPadding=0 width=100% align=center border=0><TBODY><tr>
  <td background=images/style/bottombg.gif><P align=left><IMG height=18 src=images/style/bottomleft.gif width=2 border=0></P></td>
  <td background=images/style/bottombg.gif><P align=right><IMG height=18 src=images/style/bottomright.gif width=2 border=0></P></td>
</TBODY></tr>
</TABLE>
</table>
</td>
</tr>
</form>
</table>
EOT;
}
//------------------------------------------------------------------------------------------
//+--------------------show another member's information-----------------
function show_member() {
global $target,$bordercolor,$subcolor,$titlecolor,$tablewidth,$login_status;

list($name,$pwd,$usericon,$email,$oicq,$regdate,$sign,$homepage,$area,$comment,$honor,$lastpost,$postamount,$pe)=get_user_info($target);
$usericon=get_user_portait($usericon);
if ($homepage && strpos($homepage,"://")===false) $homepage="http://$homepage";
$level=getUserLevel($postamount,$name);
if ($pe) {
	$email="<a href='sendmail.php?target=$target'>$email</a>";
	$sendaction="<a href='sendmail.php?target=$target'><img src='images/style/email.gif' border=0 alt=给该用户发一封邮件></a>";
	}
	else {
	$email="用户不愿公开";
	$sendaction="";
	}

print <<<EOT
<br>
<table width=$tablewidth border=0 cellspacing=0 cellpadding=0 align=center bgcolor=$bordercolor>
 <tr>
  <td>
   <table width=100% border=0 cellspacing=1 cellpadding=4>
    <tr bgcolor=$titlecolor> 
     <td colspan=2 background=images/style/catbg.gif>信息管理程式</td>
    </tr>
    <tr align=center> 
     <td colspan=2 bgcolor=FFFFFF><b>查看用户资料</b></td>
    </tr>
<!------User Information--------->
<tr bgcolor=FFFFFF> 
  <td width=20%>&nbsp;<b>用户名：</b></td>
  <td width=80%><TABLE style='FILTER: glow(color=#FFFF99,strength=4)'><FONT color=#000066>&nbsp;<B>$name</B></FONT></TABLE></td>
</tr>
<tr bgcolor=eeeeee>
  <td>&nbsp;等级：</td>
  <td>&nbsp;$level</td>
</tr>
<tr bgcolor=FFFFFF>
  <td>&nbsp;EMAIL：</td>
  <td>&nbsp;$email</td>
</tr>
<tr valign=top bgcolor=EEEEEE>
  <td>&nbsp;头像：</td>
  <td>&nbsp;$usericon</td>
</tr>
EOT;

if ($oicq) print ("
<tr bgcolor=FFFFFF>
  <td>&nbsp;OICQ：</td>
  <td style=\"font-family:verdana\">&nbsp;$oicq</td>
</tr>");

if ($homepage) print (
"<tr bgcolor=#EEEEEE>
<td>&nbsp;主页：</td>
<td>&nbsp;<a href='$homepage' target=_blank>$homepage</a></td>
</tr>");

$sign=vibconvert($sign);
print <<<EOT
<tr valign=top bgcolor=FFFFFF>
  <td>&nbsp;签名：</td>
  <td>&nbsp;$sign</td>
</tr>

<tr bgcolor=EEEEEE>
  <td align=left>&nbsp;来自：</td>
  <td>&nbsp;$area</td>
</tr>

<tr valign=top bgcolor=FFFFFF>
  <td>&nbsp;自我简介：</td>
  <td>&nbsp;$comment</td>
</tr>

<tr bgcolor=EEEEEE> 
  <td>&nbsp;发表文章：</td>
  <td>&nbsp;$postamount</td>
</tr>
EOT;

if ($honor) print(
"<tr bgcolor=#FFFFFF> 
<td>&nbsp;头衔：</td>
<td>&nbsp;$honor</td>
</tr>");

$regdate=get_date_chi($regdate)." ".get_time($regdate);

print <<<EOT
<tr bgcolor=FFFFFF>
<td>&nbsp;注册时间：</td>
<td>&nbsp;$regdate</td>
</tr>
EOT;
if ($login_status) {
print <<<EOT
<tr bgcolor=EEEEEE>
<td>&nbsp;相关动作：</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;<a onclick='Show(messanger);' href='messanger.php?job=write&target=$name' target=msg><img src="images/style/message.gif" border=0 alt=给该用户发短讯></a>&nbsp;&nbsp;&nbsp;
$sendaction
</td>
</tr>
EOT;
}
print <<<EOT
<tr align=center> 
<td colspan=2 bgcolor=$subcolor>
<input type="button" value="论坛首页" onClick="location.href='viboard.php'" style="height:20px; background-color:#f3f3f3; border:1 solid black;" onMouseOver ="this.style.backgroundColor='#FFC864'" onMouseOut ="this.style.backgroundColor='#f3f3f3'">
<input onClick="javascript:history.back(1)" type="button" value="返回前页" style="height:20px;background-color:#f3f3f3; border:1 solid black" onMouseOver ="this.style.backgroundColor='#FFC864'" onMouseOut ="this.style.backgroundColor='#f3f3f3'">
<input onClick="location.href='sendmail.php?target=<?=$target?>'" type="button" value="发送邮件" style="height:20px;background-color:#f3f3f3;border:1 solid black" onMouseOver ="this.style.backgroundColor='#FFC864'" onMouseOut ="this.style.backgroundColor='#f3f3f3'">
</td>
</tr>
<TABLE style=BORDER-COLLAPSE: collapse borderColor=#111111 cellSpacing=0 cellPadding=0 width=100% align=center border=0><TBODY><tr>
  <td background=images/style/bottombg.gif><P align=left><IMG height=18 src=images/style/bottomleft.gif width=2 border=0></P></td>
  <td background=images/style/bottombg.gif><P align=right><IMG height=18 src=images/style/bottomright.gif width=2 border=0></P></td>
</TBODY></tr>
</TABLE>
</table>
</td>
</tr>
</table>
EOT;
}
