<?php
# Name: PHP版程氏音乐CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/
include_once("../../lib/cs_conn.php");
include_once("../../lib/cs_common.php");
include_once("../loginstate.php");
SystemPer('0_1');
?>
<!doctype html>
<html>
<head>
<meta charset="gbk">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>chshdjcms management</title>
<link href="../res/css/admin_style.css" rel="stylesheet" />
<script type="text/javascript" src="../res/js/ajax.js"></script>
<script language="javascript" src="../res/js/jquery.js"></script>
<script type="text/javascript">
function del(_id){ 
  if (confirm("确定删除这个的管理员帐号吗？")){
    window.location='?ac=del&id='+_id;
    return true;
  }else{
     return false;
  }		
}
</script>
</head>
<body>
<div class="wrap">
<?php 	$action=CS_Request("ac");
	switch ($action){
		case 'main':
			main();
			break;
		case 'editdata':
			editdata();
			break;
		case 'del':
			del();
			break;
		case 'delall':
			delall();
			break;
		case '':
			main();
			break;
		}
 function main(){
		global $db;
		$Arr=getpagerow("select * from ".Getdbname('admin')."",20);//sql,每页显示条数
		$result=$db->query($Arr[2]);
		$adminnum=$db->num_rows($result);
?>
<!--用户后台权限: 列表  -->
<div class="nav">
	<ul class="cc">
		<li class="current"><a href="config_admin.php">后台用户</a></li>
		<li><a href="config_admin.php?ac=add">填加用户</a></li>
	</ul>
</div>
<div class="h_a">后台用户列表</div>
<div class="table_list">
<?php
	if($adminnum==0){
                echo "<table width=\"100%\">
				<tbody>
					<tr><td class=\"tac\">啊哦，没有符合条件的内容！</td></tr>
				</tbody>
		</table>";

        }else{
                echo "<table width=\"100%\">
		<thead>
			<tr>
				<td width=\"140\">用户名</td>
				<td width=\"100\">登入次数</td>
				<td width=\"180\">最后登入IP</td>
				<td width=\"200\">最后登入时间</td>
				<td>操作</td>
			</tr>
		</thead>";
        }
        if($result){
	     while ($row = $db ->fetch_array($result)){
                  echo "<tr>
				<td width=\"140\">".$row['CS_AdminName']."</td>
				<td width=\"100\">".$row['CS_LoginNum']."</td>
				<td width=\"180\">".$row['CS_LoginIP']."</td>
				<td width=\"200\">".$row['CS_LoginTime']."</td>
				<td><a href=\"?ac=edit&id=".$row['CS_ID']."\">编辑</a> &nbsp;&nbsp;<a style=\"cursor:pointer;\"  onclick=\"del(".$row['CS_ID'].")\">删除</a></td>
			</tr>";
             }
        }
?>
	</table>
			<div class="p10">
				<div class="pages">
				     <?php if($adminnum>20) echo $Arr[0];?>
                                </div>
			</div>
</div>
<?php
   }
   //修改\增加
   if($action=='edit' || $action=='add'){
        global $db;
   	$op=CS_Request("op");
   	$CS_ID=CS_Request("id");
        if($CS_ID){
	   $row=$db->getrow("SELECT * FROM ".Getdbname('admin')." Where CS_ID='".$CS_ID."'");
	   if($row){
		$Arr=array($row['CS_AdminName'],$row['CS_AdminPass'],$row['CS_Quanx']);
                $title="编辑用户";
	   }
        }else{
		$Arr=array('','','');
                $title="填加新用户";
        }
?>
<div class="nav">
	<ul class="cc">
		<li><a href="config_admin.php">后台用户</a></li>
		<li class="current"><a href="config_admin.php?ac=add"><?php echo $title?></a></li>
	</ul>
</div>
<form class="J_ajaxForm" data-role="list" action="config_admin.php?ac=<?php echo $action?>&op=data" method="post">
<div class="h_a"><?php echo $title?></div>
<div class="table_full">
	<table width="100%" class="J_check_wrap">
		<col class="th" />
		<col width="400" />
		<col />
		<tr><input name="id" type="hidden" value="<?php echo $CS_ID?>" />
			<th>用户名称</th>
			<td>
				<input name="admin_name" value="<?php echo $Arr[0]?>" type="text" class="input input_hd length_5">
			</td>
			<td><div class="fun_tips"></div></td>
		</tr>
		<tr>
			<th>用户密码</th>
			<td>
				<input name="admin_pass" value="<?php echo $Arr[1]?>" type="password" class="input input_hd length_5">
			</td>
			<td><div class="fun_tips"></div></td>
		</tr>
		<tr>
			<th>管理员</th>
			<td>
				<ul data-name="custom" class="three_list cc J_ul_check">
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'0_1')=="1"){echo "checked";}?> type="checkbox" value="0_1">管理员操作</label></li>
				</ul>
			</td>
			<td><div class="fun_tips"></div></td>
		</tr>
		<tr>
			<th>全局</th>
			<td>
				<ul data-name="config" class="three_list cc J_ul_check">
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'1_1')=="1"){echo "checked";}?>  type="checkbox" value="1_1">系统设置</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'1_2')=="1"){echo "checked";}?>  type="checkbox" value="1_2">会员设置</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'1_3')=="1"){echo "checked";}?>  type="checkbox" value="1_3">QQ登录设置</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'1_4')=="1"){echo "checked";}?>  type="checkbox" value="1_4">友情链接管理</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'1_5')=="1"){echo "checked";}?>  type="checkbox" value="1_5">Tags标签管理</label></li>
				</ul>
			</td>
			<td><div class="fun_tips"></div></td>
		</tr>
		<tr>
			<th>音乐</th>
			<td>
				<ul data-name="custom" class="three_list cc J_ul_check">
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'2_1')=="1"){echo "checked";}?>  type="checkbox" value="2_1">歌曲管理操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'2_2')=="1"){echo "checked";}?>  type="checkbox" value="2_2">歌曲分类操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'2_3')=="1"){echo "checked";}?>  type="checkbox" value="2_3">歌曲本地扫描</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'2_4')=="1"){echo "checked";}?>  type="checkbox" value="2_4">歌曲远程扫描</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'2_5')=="1"){echo "checked";}?>  type="checkbox" value="2_5">歌曲批量操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'2_6')=="1"){echo "checked";}?>  type="checkbox" value="2_6">歌曲专集操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'2_7')=="1"){echo "checked";}?>  type="checkbox" value="2_7">歌曲采集操作</label></li>
				</ul>
			</td>
			<td><div class="fun_tips"></div></td>
		</tr>
		<tr>
			<th>文章</th>
			<td>
				<ul data-name="custom" class="three_list cc J_ul_check">
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'3_1')=="1"){echo "checked";}?>  type="checkbox" value="3_1">文章管理操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'3_2')=="1"){echo "checked";}?>  type="checkbox" value="3_2">文章分类操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'3_3')=="1"){echo "checked";}?>  type="checkbox" value="3_3">文章专集操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'3_4')=="1"){echo "checked";}?>  type="checkbox" value="3_4">文章采集操作</label></li>
				</ul>
			</td>
			<td><div class="fun_tips"></div></td>
		</tr>
		<tr>
			<th>会员</th>
			<td>
				<ul data-name="custom" class="three_list cc J_ul_check">
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'4_1')=="1"){echo "checked";}?>  type="checkbox" value="4_1">会员管理操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'4_2')=="1"){echo "checked";}?>  type="checkbox" value="4_2">会员消息操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'4_3')=="1"){echo "checked";}?>  type="checkbox" value="4_3">会员邮件操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'4_4')=="1"){echo "checked";}?>  type="checkbox" value="4_4">会员相册操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'4_5')=="1"){echo "checked";}?>  type="checkbox" value="4_5">会员微薄操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'4_6')=="1"){echo "checked";}?>  type="checkbox" value="4_6">会员下载操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'4_7')=="1"){echo "checked";}?>  type="checkbox" value="4_7">会员充值操作</label></li>
				</ul>
			</td>
			<td><div class="fun_tips"></div></td>
		</tr>
		<tr>
			<th>工具</th>
			<td>
				<ul data-name="custom" class="three_list cc J_ul_check">
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'5_1')=="1"){echo "checked";}?>  type="checkbox" value="5_1">数据批量操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'5_2')=="1"){echo "checked";}?>  type="checkbox" value="5_2">数据备份还原</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'5_3')=="1"){echo "checked";}?>  type="checkbox" value="5_3">SQL语句执行</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'5_4')=="1"){echo "checked";}?>  type="checkbox" value="5_4">快捷菜单设置</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'5_5')=="1"){echo "checked";}?>  type="checkbox" value="5_5">图片数据管理</label></li>
				</ul>
			</td>
			<td><div class="fun_tips"></div></td>
		</tr>
		<tr>
			<th>评论</th>
			<td>
				<ul data-name="custom" class="three_list cc J_ul_check">
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'6_1')=="1"){echo "checked";}?>  type="checkbox" value="6_1">评论操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'6_2')=="1"){echo "checked";}?>  type="checkbox" value="6_2">留言操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'6_3')=="1"){echo "checked";}?>  type="checkbox" value="6_3">歌曲报错</label></li>
				</ul>
			</td>
			<td><div class="fun_tips"></div></td>
		</tr>
		<tr>
			<th>模版</th>
			<td>
				<ul data-name="custom" class="three_list cc J_ul_check">
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'7_1')=="1"){echo "checked";}?>  type="checkbox" value="7_1">模版操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'7_2')=="1"){echo "checked";}?>  type="checkbox" value="7_2">自定义模版</label></li>
				</ul>
			</td>
			<td><div class="fun_tips"></div></td>
		</tr>
		<tr>
			<th>生成</th>
			<td>
				<ul data-name="custom" class="three_list cc J_ul_check">
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'8_1')=="1"){echo "checked";}?>  type="checkbox" value="8_1">生成选项操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'8_2')=="1"){echo "checked";}?>  type="checkbox" value="8_2">生成歌曲操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'8_3')=="1"){echo "checked";}?>  type="checkbox" value="8_3">生成文章操作</label></li>
					<li><label><input name="qx[]" class="J_check" <?php if(checkpermission($Arr[2],'8_4')=="1"){echo "checked";}?>  type="checkbox" value="8_4">生成专集操作</label></li>
				</ul>
			</td>
			<td><div class="fun_tips"></div></td>
		</tr>
</div>
<div class="btn_wrap">
	<div class="btn_wrap_pd">
		<button type="submit" class="btn btn_submit mr10 J_ajax_submit_btn">提交</button>
                <div class="tips_error" id="Msg"></div>
	</div>
</div>
<?php
        //增加、修改
        if($op=='data'){
		global $db;
		$CS_ID=CS_Request("id");
		$CS_AdminName=CS_Request("admin_name");
		$CS_AdminPass=CS_Request("admin_pass");
		$CS_Quanx=CS_RequestBox("qx");
                $CS_NewsAdminPass=md5($CS_AdminPass);
                if($CS_AdminName=="" || $CS_AdminPass=="") exit("<script>document.getElementById('Msg').innerHTML='用户名和密码不能为空!';</script>");
		//判断增加还是修改
                if($CS_ID){
		    //判断密码是否修改
		    $sqlstr="select CS_ID from ".Getdbname('admin')." where CS_AdminPass='".$CS_AdminPass."'";
		    $result= $db->Getone($sqlstr);
		    if($result) $CS_NewsAdminPass=$CS_AdminPass;  //密码没有被修改
		   $sql="update ".Getdbname('admin')." set CS_AdminName='".$CS_AdminName."',CS_AdminPass='".$CS_NewsAdminPass."',CS_Quanx='".$CS_Quanx."' where CS_ID=".$CS_ID;
                }else{
		   $sql="Insert ".Getdbname('admin')."  (CS_AdminName,CS_AdminPass,CS_Quanx) values ('".$CS_AdminName."','".md5($CS_AdminPass)."','".$CS_Quanx."')";
                }
		if($db->query($sql)){
                    echo '<script>document.getElementById("Msg").className="tips_success";$("#Msg").text("恭喜,操作成功!").css("color","#026E12");</script>';
	            echo "<script>setTimeout(\"window.location='config_admin.php'\",2000);</script>";
		}else{
                    echo '<script>$("#Msg").text("抱歉，操作失败!").css("color","red");</script>';
	            echo "<script>setTimeout(\"window.location='javascript:history.go(-1);'\",2000);</script>";
                }
        }
   }
   //删除
   function del(){
		global $db;
		$CS_ID=CS_Request("id");
                if($_COOKIE['CS_AdminID']==$CS_ID) exit("<script>showMessage('<font color=red>抱歉，您不能删除自己！</font>', 'javascript:history.go(-1);');</script>");
		$sql="delete from ".Getdbname('admin')." where CS_ID='".$CS_ID."'";
		if($db->query($sql)){
			echo "<script>window.location='config_admin.php';</script>";
		}
   }

   //权限判断
   function checkpermission($perm,$value){
		$permarr=explode(',',$perm);
		for($i=0;$i<count($permarr);$i++){
			if($permarr[$i]==$value){
				return "1";
				break;
				}
			}
   }
?>
</div>
</body>
</html>