<?php
session_start();
include "header.html";
require_once "../MessageBox.php";
include "../datasource.inc.php";
include "../Function.php";
$Message = new MessageBox;
if ( empty($_SESSION["usernumber"]) and $_SESSION["userjs"] != "1") {
    $Message->setMessage("对不起，您没有权限进入后台管理!","logout.php");
    $Message->showMessage();
}
$page = $_REQUEST['page'];
if ($_REQUEST['action'] == 'update') {
	$sql  = "update member set username='$_REQUEST[username]',sex='$_REQUEST[sex]',company='$_REQUEST[company]',address='$_REQUEST[address]',code='$_REQUEST[code]',phone='$_REQUEST[phone]',fax='$_REQUEST[fax]',email='$_REQUEST[email]' where id='$_REQUEST[id]'";
    $result  = mysql_query($sql);
    $Message->setMessage("编辑成功!","member.php?id=$_REQUEST[id]");
    $Message->showMessage();
}
?>
<table width="700" border="0" cellspacing="0" cellpadding="0">
        <tr>
         <TD vAlign=top><FONT color=#565656><IMG height=14
      src="../images/closedfold.gif" width=14>&nbsp;&nbsp;您当前的位置<BR><IMG
      height=15 src="../images/bar.gif" width=15><IMG height=14
      src="../images/openfold.gif" width=14>&nbsp;&nbsp;会员料资管理</FONT></TD>
        </tr>
</table>
<?php
switch ($page)
{
       case "update":
	     $sql     = "select * from zht_member where id='$_REQUEST[id]'";
         $result  = mysql_query($sql);
         $row     = mysql_fetch_array($result);
         $body    = str_replace("<BR>", "\n", $row['address']);
?>
<p align="center">&nbsp;<b><font size="3">修改会员资料</font></b></p>
<form action="member.php" enctype="multipart/form-data" method=post name=form onsubmit="return check_input()">
<table width="680"  border=0 cellpadding=0 cellspacing=1 bgcolor=#333333>
  <tr height=24>
    <td width="20%" bgColor=#E6E6E6><center><b>用户名</center></b></td>
    <td width="80%" bgColor=#ffffff><? echo $row['userid']?></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#E6E6E6><center><b>姓名</center></b></td>
    <td width="80%" bgColor=#ffffff><input type=text size="10" name="username" value="<? echo $row['username']?>"></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#E6E6E6><center><b>性别</center></b></td>
    <td width="80%" bgColor=#ffffff><input type=text size="4" name="sex" value="<? echo $row['sex']?>"></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#E6E6E6><center><b>公司</center></b></td>
    <td width="80%" bgColor=#ffffff><input type=text size="40" name="company" value="<? echo $row['company']?>"></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#E6E6E6><center><b>联系地址</b></center></td>
    <td width="80%" bgColor=#ffffff><input type=text size="40" name="address" value="<? echo $row['address']?>"></td>  
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#E6E6E6><center><b>邮政编码</center></b></td>
    <td width="80%" bgColor=#ffffff><input type=text size="10" name="code" value="<? echo $row['code']?>"></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#E6E6E6><center><b>联系电话</center></b></td>
    <td width="80%" bgColor=#ffffff><input type=text size="15" name="phone" value="<? echo $row['phone']?>"></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#E6E6E6><center><b>传真</center></b></td>
      <td width="80%" bgColor=#ffffff><input type=text size="15" name="fax" value="<? echo $row['fax']?>"></td>
	</td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#E6E6E6><center><b>E_mail</center></b></td>
      <td width="80%" bgColor=#ffffff><input type=text size="20" name="email" value="<? echo $row['email']?>"></td>
	</td>
  </tr>
</table><br>
<?php echo "<input type=hidden name=\"id\" value=\"$row[id]\">";?>
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input type="hidden" value="update" name="action">
<input type="submit" value="编 辑" >&nbsp;&nbsp;<input type="reset"  value="取 消">
</form>
<?php
  break;
    case "delete":
		$query     = "delete from zht_member where id='$_REQUEST[id]'";
		mysql_query($query);
		$Message->setMessage("删除成功!","javascript:history.go(-1);");
		$Message->showMessage();
		break;
   case "text":
	   $sql    = "select * from zht_member where id='$_REQUEST[id]'";
	   $result = mysql_query($sql);
	   $row    = mysql_fetch_array($result);
	   $imagetype = substr($row['picpath'],-3);
	   if ( $imagetype=="gif" or $imagetype=="GIF" or $imagetype=="jpg" or $imagetype=="JPG" or $imagetype=="png" or $imagetype=="PNG" or $imagetype=="bmp" or $imagetype=="BMP" ) {
	      $size      = getimagesize ("../upload-images/$row[picpath]");
	      $arr       = imgspec( 300, $size[0], $size[1]);
	      $halfw     = ($size[0]);
	      $halfh     = ($size[1]);
	      $imgwidth  = ($arr[0]);
	      $imgheight = ($arr[1]);
	   }
//	   echo "<br><table border=0 cellpadding=0 cellspacing=1 bgcolor=#333333 width=\"$imgwidth+1\" height=\"$imgheight+1\">";
//	   echo "<tr height=22><td width=80% bgColor=#ffffff><img src=../upload-images/$row[picpath] width=$imgwidth height=$imgheight border=0></td></tr></table>";
?>
<br>
<p align="center"><b><font size="3">会员详细资料</font></b></p>
<table border=0 cellpadding=0 cellspacing=1 bgcolor=#333333 width=500 height=60 align="center">
  <tr height=22>
    <td width="30%" bgColor=#E6E6E6><center><b>用户名：</b></center></td>
    <td width="70%" bgColor=#ffffff><?php echo $row['userid']?></td>
  </tr>
  <tr height=22>
    <td width="30%" bgColor=#E6E6E6><center><b>姓名：</b></center></td>
    <td width="70%" bgColor=#ffffff><?php echo $row['username']?></td>
  </tr>
  <tr height=22>
    <td width="30%" bgColor=#E6E6E6><center><b>性别：</b></center></td>
    <td width="70%" bgColor=#ffffff><?php echo $row['sex']?></td>
  </tr>
  <tr height=22>
    <td width="30%" bgColor=#E6E6E6><center><b>公司：</b></center></td>
    <td width="70%" bgColor=#ffffff><?php echo $row['company']?></td>
  </tr>
  <tr height=22>
    <td width="30%" bgColor=#E6E6E6><center><b>联系地址：</b></center></td>
    <td width="70%" bgColor=#ffffff><?php echo $row['address']?></td>
  </tr>
  <tr height=22>
    <td width="30%" bgColor=#E6E6E6><center><b>邮政编码：</b></center></td>
    <td width="70%" bgColor=#ffffff><?php echo $row['code']?></td>
  </tr>
  <tr height=22>
    <td width="30%" bgColor=#E6E6E6><center><b>联系电话：</b></center></td>
    <td width="70%" bgColor=#ffffff><?php echo $row['phone']?></td>
  </tr>
  <tr height=22>
    <td width="30%" bgColor=#E6E6E6><center><b>传真：</b></center></td>
    <td width="70%" bgColor=#ffffff><?php echo $row['fax']?></td>
  </tr>
  <tr height=22>
    <td width="30%" bgColor=#E6E6E6><center><b>E-mail：</b></center></td>
    <td width="70%" bgColor=#ffffff><?php echo $row['email']?></td>
  </tr>
</table>
<br><p align="center"><a href="javascript:history.go(-1);">返回</a></p>
</center>
<?php
	break;
default:
    echo "<center>";
	echo "<form action=member.php method=post>";
    echo "<table border=0 width=560>";
    echo "<tr>";
    echo "<td width=40% bgColor=#ffffff>";
	echo "按帐号查询：<input type=text size=20 name=\"search\" maxlength=20>";
    echo "&nbsp;<input type=submit value=搜索>";
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    echo "</form>";
	echo "<br>";
	if($_REQUEST['search']){
	      $sql    = "select * from zht_member where userid like '%$_REQUEST[search]%' order by id desc";
	}else{
	      $sql    = "select * from zht_member order by id desc";
	}
	$result  = mysql_query($sql);
	$num    = mysql_num_rows($result);
	$display="40";
    pagination($display,$num,$url);
	if($page!=0){
	   mysql_data_seek($result,($page-1)*40);
    }
		echo "<table border=0 cellpadding=0 cellspacing=1 bgcolor=#333333 width=560>";
		echo "<tr>";
		echo "<td width=120 height=18 bgColor=#E6E6E6><div align=center><b>用户名</b></div></td>";
		echo "<td width=120 height=18 bgColor=#E6E6E6><div align=center><b>姓名</b></div></td>";
		echo "<td width=120 height=18 bgColor=#E6E6E6><div align=center><b>电话</b></div></td>";
		echo "<td width=80 height=18 bgColor=#E6E6E6><div align=center><b>注册时间</b></div></td>";
		echo "<td width=80 height=18 bgColor=#E6E6E6><div align=center><b>查看</b></div></td>";
		echo "<td width=40 height=18 bgColor=#E6E6E6><div align=center><b>修改</b></div></td>";
		echo "<td width=40 height=18 bgColor=#E6E6E6><div align=center><b>删除</b></div></td>";
		echo "</tr>";
		for ( $i=0;$i<40;$i++ ) {
			$row     = mysql_fetch_array($result);
			if ( $row['id']) 
			{
				echo "<tr bgColor=#ffffff>";
				echo "<td width=120 height=18 bgColor=#ffffff><div align=center>$row[userid]</div></td>";
				echo "<td width=120 height=18 bgColor=#ffffff><div align=center>$row[username]</div></td>";
				echo "<td width=120 height=18 bgColor=#ffffff><div align=center>$row[phone]</div></td>";
				echo "<td width=80 height=18 bgColor=#ffffff><div align=center>$row[date]</div></td>";
				echo "<td width=80 height=18 bgColor=#ffffff><div align=center><a href=member.php?page=text&id=$row[id]>详细信息</a></div></td>";
				echo "<td width=40 height=18 bgColor=#ffffff><div align=center><a title=点击修改本条记录 href=member.php?page=update&id=$row[id] ><img src=../images/editicon.gif border=0></a></div></td>";
				echo "<td width=40 height=18 bgColor=#ffffff><div align=center><a title=点击删除本条记录 href=member.php?page=delete&id=$row[id] onclick=\"return confirm('确定要删除吗？')\"><img src=../images/clearicon.gif border=0></a></div></td>";
				echo "</tr>";
			}
		}
		echo "</table><br>";
		echo "<table width=500 border=0 cellspacing=0 cellpadding=0 height=24>";
        echo "<tr><td align=center>".$pagenav."</td></tr>";
		echo "</table><br>";
		echo "</center>";
	    break;
}
?>