<?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'];
	$adminName=trim($_POST['adminName']);
	$adminPwd=$_POST['adminPwd'];
	$adminPwd2=$_POST['adminPwd2'];
	$adminTime=$_POST['adminTime'];


	$ls_msg="管理员管理操作";
	
	
	
	
	switch ($ls)
	{
		case "up":
			$down=$nowusernum-1;
			$down_sql="update ls_admin set userNum=".$nowusernum." where userNum=".$down." ";
			$down_sql2="update ls_admin 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_admin set userNum=".$nowusernum." where userNum=".$up."  ";
			$up_sql2="update ls_admin 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":
			if($adminPwd!=$adminPwd2)
			{ $ls_msg="两次输入密码不一致，请重输...";break;}

			$select_sql2="select * from ls_admin where adminName='".$adminName."' ";
			$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_admin ";
				$select_query2=$opendb->query($select_sql2);
				$select_rows2=mysql_num_rows($select_query2); //总数

				$insert_sql="insert into ls_admin(adminName,adminPwd,adminTime) values ('".$adminName."','".md5($adminPwd)."','".date('Y-m-d')."')";
				//echo $insert_sql;
				$insert_query=$opendb->query($insert_sql);
				$ls_msg="添加操作成功！";
			}
			break;
		case "modi":
			if($adminPwd!=$adminPwd2)
			{ $ls_msg="两次输入密码不一致，请重输...";break;}

			$modi_sql="update ls_admin set adminName='".$adminName."', adminPwd='".md5($adminPwd)."',adminTime='".$adminTime."' where id=".$modiid." ";
			//echo $modi_sql;
			$modi_query=$opendb->query($modi_sql);
			$ls_msg="修改操作成功！";
			break;
		case "del":
		
			$del_sql="delete from ls_admin where id=".$id." ";
			//echo $del_sql;
			$del_query=$opendb->query($del_sql);
			$ls_msg="删除操作成功！";
			break;
		case "unenable":
			$unenable_sql="update ls_admin 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_admin 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;
	}
	
	$admin_sql="select * from ls_admin order by ID asc";
	$admin_query=$opendb->query($admin_sql);
	$admin_num=mysql_num_rows($admin_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>
		<style type="text/css">
<!--
.STYLE1 {
	color: #FFFFFF;
	font-weight: bold;
}
-->
		</style>
</head>

	<body>
		<table width="96%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#6396d6">
			<tr>
				<td width="91%" height="18" background="images/admin_bg.gif"><div align="center"><font color="#ffffff"><strong>管理员管理</strong></font></div>			  </td>
				<td width="9%" background="images/admin_bg.gif"><a href="loginout.php"><span class="STYLE1">退出</span></a></td>
			</tr>
			
			<tr>
				<td height="213" colspan="2" valign="top" bgcolor="#dee7ff"><br>
					<table border="0" width="95%" align="center">
						<tr>
							<td>提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
						</tr>
					</table>
					
					<table width="95%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
					 
					 <tr bgcolor="#B9DAFF"> 
						<td align="center" width="59" height="28">序号</td>
						<td align="center" width="125" height="28">用户名</td>
					   <td align="center" width="229">密码</td>
					   <td width="175" align="center">日期</td>
						<td width="59" align="center" >操作</td>
						<td width="60" align="center" >删除</td>
					  </tr>
					 <?php 
					 $i=1;
					  while ($admin_rows=mysql_fetch_assoc($admin_query))
					  {
						echo "<tbody id='ZH_".$admin_rows['ID']."' >";	
						echo "<tr bgcolor='#f4f4f4'";
						echo "onMouseOver=";
						echo " 	this.style.backgroundColor='#CCFFCC' ";
						echo "onMouseOut=";
						echo " 	this.style.backgroundColor='#f4f4f4' ";
						echo ">";	
						echo "	<td align='left' style='padding-left:10px;' height='25' >";
					  	echo 		$admin_rows['ID'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:10px;' height='25' >";
					  	echo 		$admin_rows['adminName'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:10px;' height='25'>";
					  	echo 		"******";
						echo "	</td>";
						echo "	<td align='left' style='padding-left:5px;' height='25'>";
					  	echo 		trim($admin_rows['adminTime']);
						echo "	</td>";
						echo "	<td align='center'> ";
						echo "	<a href='javascript:secBoard(".$admin_rows['ID'].")' title='编辑'><img src='images/b_edit.png' border='0'></a>";
						echo "  </td>";
						echo "	<td align='center'> ";
						if($admin_rows['userAdmin']==1)
						{
							echo "	<img src='images/b_undrop.png' border='0'>";
						}
						if($admin_rows['adminName']!="admin" && $admin_rows['adminName']!="adlans")
						{
							echo "		<a href='?id=".$admin_rows['ID']."&ls=del' onclick='return ConfirmDel();' title='删除'><img src='images/b_drop.png' border='0'></a>";
						}
						echo "  </td>";

						echo "</tr>";
						echo "</tbody>";
						
						echo "<tbody id='Z_".$admin_rows['ID']."' style='display:none;'>";
						echo " <form name='fm_user' action='?ls=modi' method='post'> ";
						echo "	<tr bgcolor='#CCCCCC'>";
						echo "	<td align='left' style='padding-left:10px;' height='25' >";
					  	echo 		$admin_rows['ID'];
						echo "	</td>";
						echo "		<td style='padding-left:5px;'>";
						echo "			<input type='text' value='".$admin_rows['adminName']."' name='adminName' class='inp'><input type='hidden' value='".$admin_rows['userNum']."' name='userNum'> ";
						echo " 		</td>";
						echo "		<td style='padding-left:5px;'>";
						echo "			<input type='password'  value='      ' name='adminPwd' class='inp'> ";
						echo "			<input type='password'  value='      ' name='adminPwd2' class='inp'> ";
						echo " 		</td>";
						echo "	<td align='left' style='padding-left:5px;' height='25'>";
					  	echo "			<input type='text' value='".trim($admin_rows['adminTime'])."' name='adminTime' class='inp'> ";
						echo "	</td>";
						echo "		<td colspan='2' align='center'>";
						echo "			<input value='".$admin_rows['ID']."' name='modiid' type='hidden'>";
						echo "			<input type='submit' value='确定修改'> &nbsp; ";
						echo "			<input type='button' onclick='javascript:secBoard2(".$admin_rows['ID'].")' value='放弃修改'>";
						echo " 		</td>";
						echo "	</tr>";
						echo " </form>";
						echo "</tbody>";
						$i++;
					  }
					 ?> 
					</table>
		          <br />
<form name="fmadduser" action="?ls=insert" method="post" onSubmit="return checkSubmitForm('adminPwd2,adminPwd,adminNameAdd','密码重输,密码,用户名');">
					 <table width="95%" border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#FFFFFF">
						 <tr bgcolor="#B9DAFF">
						   <td width="27%" height="45" style='padding-left:20px;'>用户名:&nbsp;&nbsp;
							 <input type="text" name="adminName" id="adminNameAdd">
*</td>
						   <td width="24%" style='padding-left:20px;'>密码:&nbsp;
                             <input type="password" name="adminPwd" id="adminPwd" />
*</td>
						   <td width="30%" align="center"><span style="padding-left:20px;">密码重输:&nbsp;
                               <input type="password" name="adminPwd2" id="adminPwd2" />
*</span></td>
						   <td width="19%" align="center">备注:
                           <input type="text" name="userName" /></td>
				       </tr>
						 <tr bgcolor="#B9DAFF"> 
							<td height="28" colspan="4" align="center" style='padding-left:20px;'><input type="submit" value="添加管理员"  />
							  <label>
						      <input type="reset" name="button" id="button" value="重置" />
					        </label></td>
					   </tr>
			    </table>
			  </form>				<br /></td>
			</tr>
		</table>
</body>
</html>