<?php
/*
'**************************************************************************************************
' 软件名称: 盘锦DJ舞曲网CMS Content Management PjRen.Net
' 版本编号: Version 2.5
' 盘锦舞曲: http://www.pj57.com
' 官方网站: http://www.pjren.net
' 小说网站: http://www.hx39.com
' 0427DJ网: http://www.0427dj.net
' 官方论坛: http://www.tianjiazhen.com
' 版权所有: 盘锦舞曲开发团队    盘锦人(QQ:814006710)
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、盘锦网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "../include/conn.php";
include "../include/function.php";
include "admin_version.php";
include "admin_loginstate.php";
?>
<!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=gb2312" />
<link  href="images/style.css" rel="stylesheet" type="text/css" />
<title>管理员管理</title>
<script type="text/javascript" language="javascript">var tentpath='<?php echo S_SitePath?>';</script>
<script src="js/jquery.js"></script>
<script language="javascript" src="js/alerts.js"></script>
<link type="text/css" href="images/alerts.css" rel="stylesheet" media="screen">
<script language="javascript">
 $(document).ready(function(){
	$("#ChkAll").click(function(){
		if($(this).attr("checked")==true){
			$("input[id='S_ID']").each(function(){
				$(this).attr("checked",true);									 
			})							
		}else{
			$("input[id='S_ID']").each(function(){
				$(this).attr("checked",false);									 
			})							
		}
	})	
	
	$("#checkadmin").click(function(){
		var S_AdminUserName=$("#S_AdminUserName").val();
		var S_AdminPassWord=$("#S_AdminPassWord").val();
		var AdminPassWord1=$("#AdminPassWord1").val();
		var a = S_AdminUserName.length;
		var S_AdminTel=$("#S_AdminTel").val();
		$("#S_AdminUserName").css("border-color","#666 #ccc #ccc #666");
		$("#SAdminUserName").text("");
		$("#SAdminPassWord").text("");
		$("#S_AdminPassWord").css("border-color","#666 #ccc #ccc #666");
		$("#SAdminPassWord1").text("");
		$("#S_AdminPassWord").css("border-color","#666 #ccc #ccc #666");
		$("#AdminPassWord1").css("border-color","#666 #ccc #ccc #666");
		if((a < 3)||(a > 16)){
			$("#S_AdminUserName").css("border","1px solid red");
			$("#SAdminUserName").text("用户名字长为3-16个字符！").css("color","red");
			return false;
			}
		else if(S_AdminPassWord==""){
			$("#SAdminPassWord").text("请填写用户密码！").css("color","red");
			$("#S_AdminPassWord").css("border","1px solid red");
			return false;
			}
		else if(S_AdminPassWord.length < 3){
			$("#SAdminPassWord").text("密码字长不能低于3个字符！").css("color","red");
			$("#S_AdminPassWord").css("border","1px solid red");return false;
			}
		else if(AdminPassWord1!=S_AdminPassWord){
			$("#SAdminPassWord1").text("两次密码输入不一致！").css("color","red");
			$("#S_AdminPassWord").css("border","1px solid red");
			$("#AdminPassWord1").css("border","1px solid red");
			return false;
			}
		else if(S_AdminTel.length > 49){
			$("#SAdminRealName").text("联系电话不能超过50个字符！").css("color","red");
			$("#S_AdminTel").css("border","1px solid red");
			return false;
			}
	})
	
	$("#btn_delall").click(function(){
		jConfirm('您确定要删除所选的管理员帐号吗?', '操作提示', function(r) {
				if(r==true){
					form2.submit();
					}
				});
	 })
	


	
})

function del(id){
	jConfirm('确定删除这个的管理员帐号吗?', '操作提示', function(r) {
		if(r==true){
			window.location='?action=del&S_ID='+id;
			}
				});
		
		}
</script>

</head>

<body>

<?php
echo SystemPer(15);
class ui_admin{
	public function editdata($Arr,$url){
					$name=$Arr[0];
					$pass=$Arr[1];
					$real=$Arr[2];
					$tel=$Arr[3];
					$perm=$Arr[4];
					$remark=$Arr[5];
					$lock=$Arr[6];
?>
<div class="r_main">
	<div class="r_content">
		<div class="r_content_1">
	               <table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style" >
                    <form name="form1" method="post" action="<?php echo $url?>" >
                      <tr>
                        <td  height="30" align="left"  colspan="2" class="td_title">&nbsp;<?php echo $name?>管理员&nbsp;&nbsp;<font color="#FF0000">编辑管理员资料后，重新登录后生效</font></td>
                      </tr>
                      <tr>
                        <td  height="30" align="right" width="25%" class="td_border" >&nbsp;用户帐号：</td>
                        <td width="75%"  class="td_border" >&nbsp;<input name="S_AdminUserName" type="text" id="S_AdminUserName" value="<?php echo $name?>" size="20" class="inp1" onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>
                            <font color="#FF0000">＊</font>
                        <label id="SAdminUserName"></label></td>
                      </tr>
                      <tr>
                        <td width="25%" height="30" align="right" class="td_border" >&nbsp;用户密码：</td>
                        <td  class="td_border">&nbsp;<input name="S_AdminPassWord" type="password" id="S_AdminPassWord" value="<?php echo $pass?>" size="20"   class="inp1" />
                            <font color="#FF0000">＊<label id="SAdminPassWord"></label></font></td>
                      </tr>
                      <tr>
                        <td width="25%" height="30" align="right" class="td_border" >&nbsp;确认密码：</td>
                        <td class="td_border" >&nbsp;<input name="AdminPassWord1" type="password" id="AdminPassWord1" value="<?php echo $pass?>" size="20"  class="inp1" />
                            <font color="#FF0000">＊<label id="SAdminPassWord1"></label></font></td>
                      </tr>
                      
                      <tr>
                        <td width="25%" height="30" align="right"  valign="middle" class="td_border">&nbsp;真实姓名：</td>
                        <td class="td_border">&nbsp;<input name="S_AdminRealName" type="text" id="S_AdminRealName" value="<?php echo $real?>" size="20" class="inp1"  />
                              </td>
                      </tr>
                      <tr>
                        <td width="25%" height="30" align="right" class="td_border" >&nbsp;联系电话：</td>
                        <td class="td_border" >&nbsp;<input name="S_AdminTel" type="text" id="S_AdminTel" value="<?php echo $tel?>" size="20"  class="inp1" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/></td>
                      </tr>
                      <tr>
                        <td width="25%" height="30" align="right" class="td_border">&nbsp;管理权限：</td>
                        <td  class="td_border"><input type="checkbox" name="S_Permission[]" <?php if(checkpermission($perm,1)=="1"){echo "checked";}?> value="1"  class="checkbox" />
                            系统配置
                            &nbsp;
                            <input type="checkbox" id="S_Permission" name="S_Permission[]" <?php if(checkpermission($perm,2)=="1"){echo "checked";}?> value="2" class="checkbox"/>
                            舞曲管理
                            &nbsp;
                            <input type="checkbox" id="S_Permission" name="S_Permission[]" <?php if(checkpermission($perm,3)=="1"){echo "checked";}?> value="3" class="checkbox"/>
                            新闻管理
                            &nbsp;
                            <input type="checkbox" id="S_Permission" name="S_Permission[]" <?php if(checkpermission($perm,4)=="1"){echo "checked";}?>  value="4" class="checkbox"/>
                            专题管理
                            <input type="checkbox" id="S_Permission" name="S_Permission[]" <?php if(checkpermission($perm,5)=="1"){echo "checked";}?> value="5" class="checkbox"/>
                            采集管理
                            <input type="checkbox" id="S_Permission" name="S_Permission[]" <?php if(checkpermission($perm,6)=="1"){echo "checked";}?> value="6"  class="checkbox"/>
                            友情链接
                            &nbsp;
                            <input type="checkbox" id="S_Permission" name="S_Permission[]" <?php if(checkpermission($perm,7)=="1"){echo "checked";}?> value="7" class="checkbox"/>
                            广告管理<br />
                            <input type="checkbox" id="S_Permission" name="S_Permission[]" <?php if(checkpermission($perm,8)=="1"){echo "checked";}?> value="8" class="checkbox"/>
                            模板管理
                            &nbsp;
                            <input type="checkbox" id="S_Permission" name="S_Permission[]" <?php if(checkpermission($perm,10)=="1"){echo "checked";}?> value="10" class="checkbox"/>
                            高级工具
                             <input type="checkbox" id="S_Permission" name="S_Permission[]" <?php if(checkpermission($perm,11)=="1"){echo "checked";}?> value="11" class="checkbox"/>
                            生成管理
                            &nbsp;
                             <input type="checkbox" id="S_Permission" name="S_Permission[]" <?php if(checkpermission($perm,12)=="1"){echo "checked";}?> value="12" class="checkbox"/>
                            评论管理
                            &nbsp;
                            <input type="checkbox" id="S_Permission" name="S_Permission[]" <?php if(checkpermission($perm,9)=="1"){echo "checked";}?> value="9"  class="checkbox"/>
                            用户管理
                            &nbsp;
                            <input type="checkbox" id="S_Permission" name="S_Permission[]" <?php if(checkpermission($perm,15)=="1"){echo "checked";}?> value="15"  class="checkbox"/>
                            <label id="SPermission">管理员管理</label></td>
                      </tr>
                      
                      <tr>
                        <td width="25%" height="27" align="right" class="td_border"  >&nbsp;管理描述：</td>
                        <td  class="td_border">&nbsp;<textarea name="S_AdminInfo" cols="40" rows="4"><?php echo $remark?></textarea></td>
                      </tr>
                      <tr>
                        <td width="25%" height="27" align="right"  class="td_border" >&nbsp;是否开启：</td>
                        <td class="td_border" >
                          <input type="radio" name="S_IsLock" id="S_IsLock"  class="checkbox" value="0" <?php if($lock=="0"){echo "checked";}?>/>
                            开启                	&nbsp;&nbsp;
                          <input type="radio" name="S_IsLock" id="S_IsLock"  class="checkbox"  value="1" <?php if($lock=="1"){echo "checked";}?>/>
                            关闭</td>
                      </tr>
                      <tr>
                        <td width="25%" height="30" align="right" class="td_border" >&nbsp;</td>
                        <td class="td_border" > &nbsp;
                          <input type="submit" name="Submit" value="确定提交" class="rb1" id="checkadmin"/>
                          &nbsp;&nbsp; <input type="reset" name="Submit2" value="清除重置" class="rb1" /></td>
                      </tr>
                    </form>  
</table>
		</div>
	</div>
</div>
<?php
	}
	public function main(){
		global $db;
		$Arr=getpagerow("select * from s_admin",20);//sql,每页显示条数
		$result=$db->query($Arr[2]);
		$adminnum=$db->num_rows($result);
?>
 <div class="r_main">
	<div class="r_content">
		<div class="r_content_1">
                    <form name="form2" action="?action=delall" method="post">
                        <table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">
                        <tr>
                          <td class="td_title" colspan="7">&nbsp;管理员管理</td>
                        </tr>
                            <tr >
                                <td width="67" height="28" class="td_border">&nbsp;&nbsp;编号</td>
                                <td width="131" align="center" class="td_border">用户帐号</td>
                                <td width="126" align="center"  class="td_border">&nbsp;真实姓名</td>
                                <td width="177" align="center" class="td_border">上次登陆时间</td>
                                <td width="87" align="center" class="td_border" >登录次数</td>
                                 <td width="73" align="center" class="td_border">开启</td>
                                 <td width="79" align="center"  class="td_border">操 作</td>
                          </tr>
                       <?php
					   if($adminnum==0) echo "
							<tr>
                            	<td colspan=\"8\" class=\"td_border\" height=\"30\" align=center><b>暂无管理员,请添加<b/>！</td>
                            </tr>";						   
                       if($result){
						   while ($row = $db ->fetch_array($result)){

					   ?>   
                          <tr >
 								<td width="67" height="30" class="td_border">&nbsp;<input type="checkbox" name="S_ID[]" id="S_ID" class="checkbox" value="<?php echo $row['S_ID']?>"/><?php echo $row['S_ID']?>、</td>
                                <td width="131" align="center"class="td_border"><a href="?action=edit"><?php echo $row['S_AdminUserName']?></a></td>
                                <td width="126" align="center"class="td_border">&nbsp;<?php echo $row['S_AdminRealName']?></td>
                                <td width="177" align="center" class="td_border"><font color="#FF0000"><?php echo $row['S_LastLogin']?></font></td>
                                <td width="87" align="center" class="td_border"><?php echo $row['S_LoginNum']?></td>
                                <td width="73" align="center" class="td_border"><?php if($row['S_IsLock']==0){echo "<a style='cursor:pointer;' onclick=window.location='?action=changelock&islock=1&id=".$row['S_ID']."'><img src='../images/common/yes.gif'/></a>";}else{echo "<a style='cursor:pointer;' onclick=window.location='?action=changelock&islock=0&id=".$row['S_ID']."'><img src='../images/common/no.gif'/></a>";}?></td>
                                 <td width="79" align="center" class="td_border"><a href="?action=editdata&S_ID=<?php echo $row['S_ID']?>">编辑</a> &nbsp;&nbsp;<a style="cursor:pointer;"  onclick="del(<?php echo $row['S_ID']?>)">删除</a></td>
                          </tr>
                         <?php
                         							   
							   }
					   }
?> 
							 <tr >
                                  <td height="30" colspan="7" class="td_border">&nbsp;<input type="checkbox" name="ChkAll"  id="ChkAll" class="checkbox"/>全选&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="button" name="Input" value="删除所选管理"  id="btn_delall" class="rb1"  /> 
                                  &nbsp;
                                  <input type="button" value="添加管理员" class="rb1" onclick="window.location='?action=add'"></td>
                             </tr>
 		 <tr>
           <td height="30" nowrap="nowrap" colspan="7" class="td_border" align="right" ><?php echo $Arr[0];?>&nbsp;</td>
          </tr>
       </table>
                  </form>       
		</div>
	</div>
</div>
<?php
	}
		
	}//end class
?>

<?php
	$ui=new ui_admin;
	$action=SafeRequest("action","get");
	switch ($action){
		case 'main':
			$ui->main();
			break;
		case 'editdata':
			editdata();
			break;
		case 'saveedit':
			saveedit();
			break;
		case 'add':
			add();
			break;
		case 'saveadd':
			saveadd();
			break;
		case 'del':
			del();
			break;
		case 'delall':
			delall();
			break;
		case 'changelock':
			changelock();
			break;
		default:
			$ui->main();
		}
	
	function changelock(){
		global $db;
		$islock=SafeRequest("islock","get");
		$id=SafeRequest("id","get");
		if(!IsNum($islock)) $islock=0;
		if(!IsNum($id)) die("<script>jAlert('id传输错误?','操作提示',function(R){history.back();})</script>");
		$sql="update s_admin set S_IsLock=$islock where S_ID=$id";
		if($db->query($sql)){
			die("<script>window.location='admin_admin.php';</script>");
			}
		else{
			die("<script>jAlert('未知错误!','操作提示',function(R){history.back();})</script>");
			}	
		}
	function delall(){
		global $db;
		$S_ID=RequestBox("S_ID");
		$sql="delete from s_admin where S_ID in ($S_ID)";
		if($S_ID=="0"){
			die("<script>jAlert('请选择要删除的管理员?','操作提示',function(R){history.back();})</script>");
			}
		else{
			if($db->query($sql)){
				die("<script>jAlert('恭喜你！操作成功了！','成功提示',function(R){window.location='admin_admin.php';})</script>");
				}
			}	
		}

	function del(){
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		$sql="delete from s_admin where S_ID='".$S_ID."'";
		if($db->query($sql)){
			echo "<script>window.location='admin_admin.php';</script>";
			}
		}

	function add(){
		global $ui;
		$Arr=array("","","","","","",0);
		$ui->editdata($Arr,"?action=saveadd");
		}
	
	function saveadd(){
		global $db;
		$S_AdminName=SafeRequest("S_AdminUserName","post");
		$S_AdminPass=SafeRequest("S_AdminPassWord","post");
		$S_RealName=SafeRequest("S_AdminRealName","post");
		$S_Premission=RequestBox('S_Permission');
		$S_Remark=SafeRequest("S_AdminInfo","post");
		$S_AdminTel=SafeRequest("S_AdminTel","post");
		$S_IsLock=SafeRequest("S_IsLock","post");
		$AdminID=$db->getOne("select S_ID from s_admin where S_AdminUserName='".$S_AdminName."'");
		if($AdminID){
			die("<script>jAlert('该管理员帐号已经存在!','操作提示',function(R){if(R==true){history.go(-1);}})</script>");
			}
		else{	
		$sql="Insert s_admin  (S_AdminUserName,S_AdminPassWord,S_AdminRealName,S_AdminTel,S_Permission,S_AdminInfo,S_IsLock) values ('".$S_AdminName."',md5('".$S_AdminPass."'),'".$S_RealName."','".$S_AdminTel."','".$S_Premission."','".$S_Remark."',".$S_IsLock.")";
		$db->query($sql);
		echo "<script>window.location='admin_admin.php';</script>";
		}
	}

	function saveedit(){
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		$S_AdminName=SafeRequest("S_AdminUserName","post");
		$S_AdminPass=SafeRequest("S_AdminPassWord","post");
		$S_RealName=SafeRequest("S_AdminRealName","post");
		$S_Premission=RequestBox("S_Permission");
		$S_Remark=SafeRequest("S_AdminInfo","post");
		$S_AdminTel=SafeRequest("S_AdminTel","post");
		$S_IsLock=SafeRequest("S_IsLock","post");
		//判断密码是否修改
		$sqlstr="select S_ID from s_admin where S_AdminPassWord='".$S_AdminPass."'";
		$result= $db->Getone($sqlstr);
		if($result){
			$sql="update s_admin set S_AdminUserName='".$S_AdminName."',S_AdminRealName='".$S_RealName."',S_AdminTel='".$S_AdminTel."',S_Permission='".$S_Premission."',S_AdminInfo='".$S_Remark."',S_IsLock=".$S_IsLock." where S_ID=".$S_ID."";
			}
		else{
			$sql="update s_admin set S_AdminUserName='".$S_AdminName."',S_AdminPassWord=md5('".$S_AdminPass."'),S_AdminRealName='".$S_RealName."',S_AdminTel='".$S_AdminTel."',S_Permission='".$S_Premission."',S_AdminInfo='".$S_Remark."',S_IsLock=".$S_IsLock." where S_ID=".$S_ID."";
			}	
		
		$db->query($sql);
		echo "<script>window.location='admin_admin.php';</script>";
		}

	function editdata(){
		global $db;
		global $ui;
		$S_ID=SafeRequest("S_ID","get");
		if(IsNum($S_ID)){
			$sql="SELECT * FROM `s_admin` Where S_ID='".$S_ID."'";
			$row=$db->Getrow($sql);
				if($row){
					$Arr=array($row['S_AdminUserName'],$row['S_AdminPassWord'],$row['S_AdminRealName'],$row['S_AdminTel'],$row['S_Permission'],$row['S_AdminInfo'],$row['S_IsLock']);
					}
				$ui->editdata($Arr,"?action=saveedit&S_ID=".$S_ID."");
			}
		}
		
	function checkpermission($perm,$value){
		$permarr=explode(',',$perm);
		for($i=0;$i<count($permarr);$i++){
			if($permarr[$i]==$value){
				return "1";
				break;
				}
			}
		}

?>
<?php include "admin_bottom.php"; ?>

</body>
</html>