<?php 
session_start(); 
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/admin.class.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/check.php');
	$opendb=new mydb();
	
	
	$ls=$_GET['ls'];
	$id=$_GET['id'];
	$page = $_GET['page'];
	$keywords = $_GET['keywords'];
	$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":
				$_POST['adminTime']= date("Y-m-d");
				if($admin->addAdmin($_POST)){
						$ls_msg = "修改成功";
					}else{
						$ls_msg = $admin->error;
						}
			break;
		case "modi":

			if($_POST['adminPwd']=="******"){
				unset($_POST['adminPwd']);
			}else{
				$_POST['adminPwd']= md5($_POST['adminPwd']);	
			}
				if($admin->modiAdmin($_POST['modiid'],$_POST)){
						$ls_msg = "修改成功";
				}else{
						$ls_msg = $admin->error;	
				}
			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->keywords = $keywords;
	$adminlist = $admin->getAll($page);	
	
?>
<!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">&nbsp;</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="300">姓名</td>
                        <td align="center" width="100">部门</td>
					    <td align="center" width="300" height="28">用户名</td>
					    <td align="center" width="229">密码</td>
                        <td align="center" width="400">tel</td>
                        <td align="center" width="229">email</td>
                        <td align="center" width="229">fax</td>
                        <td align="center" width="229">skype</td>
                        <td align="center" width="229">备注</td>
					    <td width="350" align="center">角色</td>
						<td width="59" align="center" >操作</td>
                        <!--<td width="59" align="center" >删除</td>
						<td width="60" align="center" >启用</td>-->
					 </tr>
					 <?php 
					 $i=1;
					  foreach($adminlist as $admin_rows){
						
						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['userName'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:10px;' height='25' >";
					  	echo 		$admin_rows['branchName'];
						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:10px;' height='25' >";
					  	echo 		$admin_rows['tel'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:10px;' height='25' >";
					  	echo 		$admin_rows['email'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:10px;' height='25' >";
					  	echo 		$admin_rows['fax'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:10px;' height='25' >";
					  	echo 		$admin_rows['skype'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:10px;' height='25' >";
					  	echo 		$admin_rows['memo'];
						echo "	</td>";
						
						echo "	<td align='left' style='padding-left:10px;' height='25' >";
					  	echo 		$admin_rows['roleName'];
						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>";
						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 "<td>";
						if($admin_rows['enable']==1){
				echo "<a href='?id=".$admin_rows['ID']."&ls=unenable&page=".$page."' title='显示'><img src='images/enable.gif' border='0'></a>";
			}else{
				echo "<a href='?id=".$admin_rows['ID']."&ls=enable&page=".$page."' title='不显示'><img src='images/unenable.gif' 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 style='width:50px;' type='text' value='".$admin_rows['userName']."' name='userName' class='inp'><input type='hidden' value='".$admin_rows['userNum']."' name='userNum'> ";
						echo " 		</td>";
						echo "		<td style='width:100px;padding-left:5px;'>";
						
						
					$list = $admin->getAllBranch("ls_branch");							
					
					
					if($_SESSION['username']!='admin'){
						echo "
						<select name='branchID'>
							<option value='0'>无</option>
						";
	
							foreach($list as $v){
								if($v['ID']==$admin_rows['branchID']){
								echo "<option value='".$v['ID']."' selected='selected' >".$v['branchName']."</option>";
								}else{
									echo "<option value='".$v['ID']."'  >".$v['branchName']."</option>";
									}
							}
						echo "</select>";
				}
						echo "</td>";
						
						echo "		<td style='padding-left:5px;'>";
						if($_SESSION['username']!=$admin_rows['adminName']){
							echo "			<input type='adminName'  value='".$admin_rows['adminName']."' name='adminName' class='inp'> ";
							echo "</td>";
							echo "		<td style='padding-left:5px;'>";
							echo "			<input type='password'  value='******' name='adminPwd' class='inp'> ";
						}else{
							echo "			<input type='adminName'  value='".$admin_rows['adminName']."' name='adminName' class='inp' readonly> ";
							echo "</td>";
							echo "		<td style='padding-left:5px;'>";
							echo "			<input type='password'  value='******' name='adminPwd' class='inp' readonly> ";
						}
						echo " 		</td>";
						echo "	<td align='left' style='padding-left:5px;' height='25'>";
					  	echo "			<input type='text' value='".trim($admin_rows['tel'])."' name='tel' class='inp'> ";
						echo "	</td>";
						echo "	<td align='left' style='padding-left:5px;' height='25'>";
					  	echo "			<input type='text' value='".trim($admin_rows['email'])."' name='email' class='inp'> ";
						echo "	</td>";
						echo "	<td align='left' style='padding-left:5px;' height='25'>";
					  	echo "			<input type='text' value='".trim($admin_rows['fax'])."' name='fax' class='inp'> ";
						echo "	</td>";
						echo "	<td align='left' style='padding-left:5px;' height='25'>";
					  	echo "			<input type='text' value='".trim($admin_rows['skype'])."' name='skype' class='inp'> ";
						echo "	</td>";
						echo "	<td align='left' style='padding-left:5px;' height='25'>";
					  	echo "			<input type='text' value='".trim($admin_rows['memo'])."' name='memo' class='inp'> ";
						echo "	</td>";
						echo "	<td align='left' style='padding-left:5px;' height='25'>";
						if($_SESSION['username']!='admin'){
					  	echo "
						<select name='roleID'>";
							$list = $admin->getAllBranch("ls_role");
							foreach($list as $v){
								if($v['ID']==$admin_rows['roleID']){
								echo "<option value='".$v['ID']."' selected='selected' >".$v['roleName']."</option>";
								}else{
									echo "<option value='".$v['ID']."'  >".$v['roleName']."</option>";
									}
							}
						}
						echo "	</td>";

						echo "		<td colspan='3' 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++;
					  }
					 ?> 
                     <tr><td align="center" colspan="15" bgcolor="#B9DAFF" height="30"><? $admin->getPageStr($page);?></td></tr>
					</table>
		          <br />
<form name="fmadduser" action="?ls=insert" method="post" onsubmit="checkadd();" >
					 <table width="95%" border="0" align="center" cellpadding="1" cellspacing="0" >
						 <tr bgcolor="#B9DAFF">
						   <td width="27%" height="45" align="center" style='padding-left:20px;'>用户名:&nbsp;&nbsp;
							 <input type="text" name="adminName" id="adminNameAdd">
*</td>
						   <td width="24%" align="center" style='padding-left:20px;'>密码:&nbsp;
                             <input type="password" name="adminPwd" id="adminPwd" />
*</td>
<td align="center">
姓名 <input type="text" name="userName" id="userName"/>*
</td>
						   <td width="19%" align="center">备注:
                           <input type="text" name="memo" id="memo"/></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>