<?php
include_once("../includes/global.php");
$script_tmp = explode('/', $_SERVER['SCRIPT_NAME']);
$sctiptName = array_pop($script_tmp);
include_once("auth.php");
include_once("../lang/$langs/company_type_config.php");
//==================================
if(!empty($_POST["action"]))
{
	$_POST['rank']=empty($_POST['rank'])?0:$_POST['rank'];
	$_POST['tj']=empty($_POST['tj'])?0:$_POST['tj'];
	$_POST['stime']=strtotime($_POST['stime']);
	$_POST['etime']=strtotime($_POST['etime']);
	$sql="select userid,email,user from ".ALLUSER." where userid='$_GET[userid]' ";
	$db->query($sql);
	$uid=$db->fetchRow();
	if(!empty($_POST['password'])) 
	{
		$sql="update ".ALLUSER." set password='".md5($_POST['password'])."' where userid='$_GET[userid]'";
		$db->query($sql);
	}
	$sql="update ".ALLUSER." set 
	statu='$_POST[statu]',point='$_POST[point]',regtime='$_POST[regtime]',email='$_POST[email]',invite='$_POST[invite]'
	where userid='$_GET[userid]'";
	$db->query($sql);
	
	//-------------邮件发送-----------
	if(!empty($_POST['send_mail']))
	{
		$ar1=array('[username]','[weburl]');
		$ar2=array($uid['user'],$config['weburl']);
		$con=str_replace($ar1,$ar2,$_POST['mail_con']);
		send_mail($uid['email'],$ue['user'],$_POST['mail_title'],$con);
	}
	//-------------------------------
	
	unset($_GET['id']);
	msg("member.php?".implode('&',convert($_GET)));
}
//=====================================================
$sql="select * from ".ALLUSER." where userid='$_GET[userid]'";
$db->query($sql);
$re=$db->fetchRow();
$ip=$re['ip'];
$lastLoginTime=empty($re['lastLoginTime'])?time():$re['lastLoginTime'];
$regtime=empty($re['regtime'])?date("Y-m-d",$lastLoginTime):$re['regtime'];
$statu=$re['statu'];
$point=$re['point'];
$invite=$re['invite'];

//========================================
function convertip($ip, $ipdatafile)
{
	static $fp = NULL, $offset = array(), $index = NULL;
	$ipdot = explode('.', $ip);
	$ip    = pack('N', ip2long($ip));
	$ipdot[0] = (int)$ipdot[0];
	$ipdot[1] = (int)$ipdot[1];
	if($fp === NULL && $fp = @fopen($ipdatafile, 'rb')) {
		$offset = unpack('Nlen', fread($fp, 4));
		$index  = fread($fp, $offset['len'] - 4);
	} elseif($fp == FALSE) {
		return  '- Invalid IP data file';
	}
	$length = $offset['len'] - 1028;
	$start  = unpack('Vlen', $index[$ipdot[0] * 4] . $index[$ipdot[0] * 4 + 1] . $index[$ipdot[0] * 4 + 2] . $index[$ipdot[0] * 4 + 3]);

	for ($start = $start['len'] * 8 + 1024; $start < $length; $start += 8) {

		if ($index{$start} . $index{$start + 1} . $index{$start + 2} . $index{$start + 3} >= $ip) {
			$index_offset = unpack('Vlen', $index{$start + 4} . $index{$start + 5} . $index{$start + 6} . "\x0");
			$index_length = unpack('Clen', $index{$start + 7});
			break;
		}
	}
	fseek($fp, $offset['len'] + $index_offset['len'] - 1024);
	if($index_length['len']) {
		return '- '.fread($fp, $index_length['len']);
	} else {
		return '- Unknown';
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="main.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="../script/Calendar.js"></script>
</head>
<body>
<div class="bigbox">
  <div class="bigboxhead"><?php echo lang_show('mem_modify_info');?></div>
  <div class="bigboxbody">
    <form method="post" action=""  name=cityform enctype="multipart/form-data">
      <table width='98%' border='0' cellspacing='0' cellpadding='0' align="center" class="menu">
        <tr>
          <td align="left"><?php echo lang_show('regip');?></td>
          <td><?php 
			if($ip)
			{	
				echo $ip;
				$ipfile="../lib/tinyipdata.dat";
				echo $from = convertip($ip, $ipfile);
			}
			?>
          </td>
        </tr>
        <tr>
          <td align="left"><?php echo lang_show('last_login_time');?></td>
          <td><?php echo date("Y-m-d H:i:s",$lastLoginTime) ;?></td>
        </tr>
        <tr>
          <td align="left"><?php echo lang_show('assign_admin');?></td>
          <td><select class="select" name="invite">
              <option value=""><?php echo lang_show('noassign');?></option>
            <?php
		  	$sql="select name from ".ADMIN." where name!='' order by name";
			$db->query($sql);
			$invites=$db->getRows();
			foreach($invites as $v)
			{
		  ?>
              <option value="<?php echo $v['name']; ?>" <?php if($invite==$v['name']) echo "selected"; ?>><?php echo $v['name']; ?></option>
              <?php
			 }
			?>
            </select></td>
        </tr>
        <tr>
          <td width='15%' align="left"><?php echo lang_show('statu');?></td>
          <td width='92%'><select class="select" name="statu">
              <?php
				foreach($member_group as $key=>$v)
				{
				?>
              <option value="<?php echo $key; ?>" <?php if($statu==$key) echo "selected"; ?>><?php echo $v; ?></option>
              <?php
				 }
				?>
            </select>
          </td>
        </tr>
        <tr>
          <td align="left"><?php echo lang_show('mod_password');?></td>
          <td><input class="text" type="text" name="password" id="password"></td>
        </tr>
        <tr>
          <td align="left"><?php echo lang_show('reg_mail');?></td>
          <td><input class="text"  name="email" type="text" value="<?php echo $re['email'];?>" /></td>
        </tr>
        <tr>
          <td width='15%' align="left"><?php echo lang_show('mem_credit');?></td>
          <td width='92%'><input class="text"  name="point" type="text" value="<?php if(!empty($point)) echo $point; else echo 0;?>">
          </td>
        </tr>
        <tr>
          <td align="left"><?php echo lang_show('reg_time');?></td>
          <td><input class="text"  type="text" name="regtime" id="regtime" value="<?php echo "$regtime"; ?>"></td>
        </tr>
        <tr>
          <td><?php echo lang_show('mail_notic');?></td>
          <td><input class="text" value="<?php $mail_temp=get_mail_template('review_user'); echo $mail_temp['subject']; ?>" name="mail_title" />
            <br />
            <textarea style="margin-top:5px;" name="mail_con" class="text" cols="" rows="8"><?php echo $mail_temp['message'];?></textarea>
            <br />
            <input type="checkbox" class="checkbox" name="send_mail" value="1" />
            <span class="bz"><?php echo lang_show('send_mail_to');?></span> </td>
        </tr>
        <tr>
          <td width='15%'>&nbsp;</td>
          <td width='92%'><input class="btn" style="width:50px;" type='submit' name='submit' value='<?php echo lang_show('submit');?>'>
            <input name="action" type="hidden" id="action" value="submit">
          </td>
        </tr>
      </table>
    </form>
  </div>
</div>
</body>
</html>
