<?php 
session_start(); 
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/check.php');
	$opendb=new mydb();
	
	$ls=$_GET['ls'];
	$id=$_GET['id'];
	$modiid=$_POST['modiid'];
	$userName=trim($_POST['userName']);
	$userRealName=$_POST['userRealName'];
	$userPwd=$_POST['userPwd'];
	$userEmail=strtolower(trim($_POST['userEmail']));
	$userMemo=$_POST['userMemo'];	
	$userTime=$_POST['userTime'];
	$userNum=$_POST['userNum'];
	$userMSN=strtolower(trim($_POST['userMSN']));

	$nowusernum=$_GET['userNum'];

	$ls_msg="客户管理操作";
	
	
	
	
	switch ($ls)
	{
		case "up":
			$down=$nowusernum-1;
			$down_sql="update ls_users set userNum=".$nowusernum." where userNum=".$down." ";
			$down_sql2="update ls_users set userNum=userNum-1 where id=".$id." ";
			//echo $down_sql;
			$down_query=$opendb->query($down_sql);
			$down_query=$opendb->query($down_sql2);
			$ls_msg="上移操作成功！";
			break;
		case "down":
			$up=$nowusernum+1;
			$up_sql="update ls_users set userNum=".$nowusernum." where userNum=".$up."  ";
			$up_sql2="update ls_users set userNum=userNum+1 where id=".$id." ";
			
			//echo $up_sql;
			$up_query=$opendb->query($up_sql);
			$up_query=$opendb->query($up_sql2);

			$ls_msg="下移操作成功！";

			break;
		case "insert":
			$select_sql2="select * from ls_users where userName='".$userName."' ";
			$select_query2=$opendb->query($select_sql2);
			$select_rows2=mysql_num_rows($select_query2); //总数
			if($select_rows2>0)
			{ $ls_msg="用户名已经存在，请重新选择";}
			else{

				$select_sql2="select * from ls_users ";
				$select_query2=$opendb->query($select_sql2);
				$select_rows2=mysql_num_rows($select_query2); //总数

				$insert_sql="insert into ls_users(userName,userRealName,userPwd,userEmail,userMSN,userTime,userMemo,userNum,enable) values ('".$userName."','".$userRealName."','".$userPwd."','".$userEmail."','".$userMSN."','".date('Y-m-d')."','".$userMemo."',".($select_rows2+1).",1)";
				//echo $insert_sql;
				$insert_query=$opendb->query($insert_sql);
				$ls_msg="添加操作成功！";
			}
			break;
		case "modi":
			$modi_sql="update ls_users set userName='".$userName."', userRealName='".$userRealName."', userPwd='".$userPwd."', userEmail='".$userEmail."', userMSN='".$userMSN."', userMemo='".$userMemo."',userTime='".$userTime."', userNum='".$userNum."' where id=".$modiid." ";
			//echo $modi_sql;
			$modi_query=$opendb->query($modi_sql);
			$ls_msg="修改操作成功！";
			break;
		case "del":
			$user_sql2="select * from ls_users where id=".$id." ";
			$user_query2=$opendb->query($user_sql2);
			$user_rows2=mysql_fetch_assoc($user_query2);
			$num_sql2="update ls_users set userNum=userNum-1 where userNum>".$user_rows2['userNum']." ";//all order number-1
			$down_query=$opendb->query($num_sql2);
		
			$del_sql="delete from ls_users where id=".$id." ";
			//echo $del_sql;
			$del_query=$opendb->query($del_sql);
			$ls_msg="删除操作成功！";
			break;
		case "unenable":
			$unenable_sql="update ls_users set enable=0 where id=".$id." ";
			//echo $unenable_sql;
			$unenable_query=$opendb->query($unenable_sql);
			$ls_msg="禁止操作成功！";
			echo "<script>window.open(\"menu.php\",   \"leftFrame\")   </script>";
			break;
		case "enable":
			$enable_sql="update ls_users set enable=1 where id=".$id." ";
			//echo $enable_sql;
			$enable_query=$opendb->query($enable_sql);
			$ls_msg="允许操作成功！";
			echo "<script>window.open(\"menu.php\",   \"leftFrame\")   </script>";
			break;
	}
	
	$user_sql="select * from ls_users order by userNum asc";
	$user_query=$opendb->query($user_sql);
	$user_num=mysql_num_rows($user_query);	
	
?>
<!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="css/admin.css" rel="stylesheet" type="text/css">
		<script language="JavaScript" src="js/ls.js"></script>
		<title>无标题文档</title>
	</head>

	<body>
		<table width="96%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#6396d6">
			<tr>
				<td height="18" background="images/admin_bg.gif"><div align="center"><font color="#ffffff"><strong>客户管理</strong></font></div>
				</td>
			</tr>
			
			<tr>
				<td height="213" valign="top" bgcolor="#dee7ff"><br>
					<table border="0" width="94%" align="center">
<tr>
							<td>提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
						</tr>
					</table>
					
		   <table width="94%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
					 
					 <tr bgcolor="#B9DAFF"> 
						<td align="center" width="30" height="28">序号</td>
						<td align="center" width="84" height="28">用户名</td>
					   <td align="center" width="82">密码</td>
					   <td width="106" align="center">客户姓名</td>
					   <td width="87" align="center">日期</td>
					   <td width="127" align="center">email</td>
					   <td width="125" align="center">MSN</td>
						<td colspan="2"align="center">排序</td>
						<td width="59" align="center" >操作</td>
						<td width="60" align="center" >删除</td>
						<td align="center" width="46">允许</td>
					  </tr>
					 <?php 
					 $i=1;
					  while ($user_rows=mysql_fetch_assoc($user_query))
					  {
					  ?>
						<tbody id='ZH_<?=$user_rows['ID']?>' >
						<tr bgcolor='#f4f4f4' onMouseOver="this.style.backgroundColor='#CCFFCC'"
						onMouseOut="this.style.backgroundColor='#f4f4f4' ">
							<td align='left' style='padding-left:10px;' height='25' >
					  	<?=$user_rows['userNum'] ?>
							</td>
							<td align='left' style='padding-left:10px;' height='25' >
					  	<?=$user_rows['userName'] ?>
							</td>
							<td align='left' style='padding-left:10px;' height='25'>
					  	******
							</td>
							<td align='left' style='padding-left:10px;' height='25'>
					  	<?=$user_rows['userRealName'] ?>
							</td>
							<td align='left' style='padding-left:5px;' height='25'>
					  	<?=trim($user_rows['userTime'])?>
							</td>
							<td align='left' style='padding-left:10px;' height='25'>
					  			<a href="mailto:<?=$user_rows['userEmail']?>"><?=$user_rows['userEmail']?></a>
							</td>
							<td align='left' style='padding-left:10px;' height='25'>
					  			<a href="msnto:<?=$user_rows['userMSN']?>"><?=$user_rows['userMSN']?></a>
							</td>
							<td align='center'> 
						   <?
						if($i!=1)// not start up
						{						
							echo "	<a href='?id=".$user_rows['ID']."&userNum=".$user_rows['userNum']."&ls=up' title='向上移动'><img src='images/up.gif' border='0'></a>";
						}
						?>
						  </td>
							<td align='center'> 
							<?
						if($i!=$user_num)// not end down
						{
							echo "	 <a href='?id=".$user_rows['ID']."&userNum=".$user_rows['userNum']."&ls=down' title='向下移动'><img src='images/down.gif' border='0'></a>";
						}
						?>
						  </td>
							<td align='center'> 
							<a href='javascript:secBoard(<?=$user_rows['ID']?>)' title='编辑'><img src='images/b_edit.png' border='0'></a>
						  </td>
							<td align='center'> 
						<?
						if($user_rows['userAdmin']==1)
						{
						
							echo "	<img src='images/b_undrop.png' border='0'>";
						}
						if($user_rows['userAdmin']==0)
						{
						
							echo "		<a href='?id=".$user_rows['ID']."&ls=del' onclick='return ConfirmDel();' title='删除'><img src='images/b_drop.png' border='0'></a>";
						 }?>
						  </td>
							<td align='center'>
						<?  
						  if($user_rows['enable']==1)
							{
								echo "<a href='?id=".$user_rows['ID']."&ls=unenable' title='显示'><img src='images/enable.gif' border='0'></a>";
							}
						  if($user_rows['enable']==0)
						  	{
								echo "<a href='?id=".$user_rows['ID']."&ls=enable' title='不显示'><img src='images/unenable.gif' border='0'></a>";
							}
							?>						
							</td>
						</tr>
						</tbody>
						
						<tbody id='Z_<?=$user_rows['ID']?>' style='display:none;'>
						 <form name='fm_user' action='?ls=modi' method='post'> 
							<tr bgcolor='#CCCCCC'>
							<td align='left' style='padding-left:10px;' height='25' >
					  	<?=$user_rows['userNum'] ?>
							</td>
								<td style='padding-left:5px;'>
									<input type='text' value='<?=$user_rows['userName']?>' name='userName' class='inp'><input type='hidden' value='<?=$user_rows['userNum'] ?>' name='userNum'> 
						 		</td>
								<td style='padding-left:5px;'>
									<input type='password' value='<?=$user_rows['userPwd'] ?>' name='userPwd' class='inp'> 
						 		</td>
							<td align='left' style='padding-left:5px;' height='25'>
					  				<input type='text' value='<?=$user_rows['userRealName'] ?>' name='userRealName' class='inp'> 
							</td>
							<td align='left' style='padding-left:5px;' height='25'>
					  				<input type='text' value='<?=trim($user_rows['userTime']) ?>' name='userTime' class='inp'> 
							</td>
							<td align='left' style='padding-left:5px;' height='25'>
					  				<input type='text' value='<?=$user_rows['userEmail'] ?>' name='userEmail' class='inp'> 
							</td>
							<td align='left' style='padding-left:5px;' height='25'>
					  				<input type='text' value='<?=$user_rows['userMSN'] ?>' name='userMSN' class='inp'> 
							</td>
								<td colspan='5' align='center'>
									<input value='<?=$user_rows['ID'] ?>' name='modiid' type='hidden'>
									<input type='submit' value='确定修改'> &nbsp; 
									<input type='button' onclick='javascript:secBoard2(<?=$user_rows['ID'] ?>)' value='放弃修改'>
						 		</td>
							</tr>
						 </form>
						</tbody>
					   <?
						$i++;
					  }
					 ?> 
					</table>
					
					
<form name="fmadduser" action="?ls=insert" method="post" onSubmit="return Checkadduser();">
					 <table width="95%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
					 
						 <tr bgcolor="#B9DAFF">
						   <td width="33%" height="28" style='padding-left:20px;'>客户姓名:
							 <input type="text" name="userRealName"></td>
						   <td width="30%" style='padding-left:20px;'>email:
							 <input type="text" name="userEmail">
							 *</td>
						   <td width="37%" align="center"><span style="padding-left:20px;">MSN:
							   <input type="text" name="userMSN" onFocus="fmadduser.userMSN.value=fmadduser.userEmail.value">
						   </span></td>
					   </tr>
						 <tr bgcolor="#B9DAFF">
						   <td height="28" style='padding-left:20px;'>用户名:&nbsp;&nbsp;
							 <input type="text" name="userName">
*</td>
						   <td style='padding-left:20px;'>密码:&nbsp;
							 <input type="password" name="userPwd">
*</td>
						   <td align="center">备注:
							 <input type="text" name="userMemo"></td>
					   </tr>
						 <tr bgcolor="#B9DAFF"> 
							<td height="28" style='padding-left:20px;'>&nbsp;</td>
							<td style='padding-left:20px;'>&nbsp;</td>
							<td align="center"><input type="submit" value="添加客户"></td>
					   </tr>
					  </table>
				  </form>
					
					
				</td>
			</tr>
		</table>
	</body>
</html>