<?php
include_once("htui_header.php");

$scuser_id=$_SESSION["a_uid"];
if ($_GET['listid']!='' && $_GET['sp']==''){
   
	if (check_permission($scuser_id,'Errorlist.php',3)){
		$listid = flc_request($_GET['listid']);
		$sql = "delete from {$tablepre}urlerror where id in(".$listid.")";
		$db->exec($sql);
		$response_arr = array("status" => 1,"message"  => '操作成功');
	}else{
        $response_arr = array("status" => -1,"message"  => '对不起,您无权限操作!');
	}

    echo json_encode($response_arr);
    exit;
}

if ($_GET['listid']!='' && $_GET['sp']==1){

	if (check_permission($scuser_id,'Errorlist.php',4)){
		$listid = flc_request($_GET['listid']);
		$flag = intval($_GET['flag']);
		$sql = "update {$tablepre}urlerror set flag='".$flag."' where id in(".$listid.")";
		$db->exec($sql);
		$response_arr = array("status" => 1,"message"  => '操作成功');
	}else{
        $response_arr = array("status" => -1,"message"  => '对不起,您无权限操作!');
	}

    echo json_encode($response_arr);
    exit;
}

$page=intval($_GET["page"]);
if ($page==0) $page=1;
  
$where = "";
if ($_POST["kw"]!=""){
   $kw=flc_request(trim($_POST["kw"]));
   $where = " AND m.msg_title like '%".$kw."%'";
}elseif ($_GET["kw"]!=""){
   $kw=flc_request(trim($_GET["kw"]));
   $where = " AND m.msg_title like '%".$kw."%'";
}

$sql="select r.id,m.msg_id,m.msg_title,r.addtime,r.scuser_id,r.flag from {$tablepre}urlerror r
      inner join {$tablepre}message m on m.msg_id=r.msg_id where 1=1 ".$where." order by r.id desc"; 
$p       = new htui_page;
$myrow   = $db->get_all($sql);
$numrows = count($myrow);

$p->setvar(array("kw" => $kw)); 
$p->set($site_admin_num,$numrows,$psize); 
$ListArray = $db -> get_all($sql." limit ".$p->limit());


if(!empty($ListArray) && is_array($ListArray)){
     foreach($ListArray as $k => $v){
		$sql = "select * from {$tablepre}scuser where ID='".$v['scuser_id']."'";
        $row = $db->get_row($sql);
		$ListArray[$k]['UserName'] = $row['UserName'];
     }
}
?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta id="scale" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>用户反馈错误列表 - 飞天素材网</title>
<meta name="author" content="ftsucai.com">
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/fonts.css" rel="stylesheet">
<link href="../css/htstyle.css" rel="stylesheet">
<link href="../css/jquery-confirm.min.css" rel="stylesheet">
</head>
  
<body>
    <!--页面主要内容-->
    <main class="ftdms-layout-content">
      
      <div class="container-fluid" style="margin-bottom:90px;">
        
        <div class="row" style="margin-top:15px;">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-toolbar clearfix">
                <form class="pull-right search-bar" method="post" action="" role="form" id="search">
                  <div class="input-group">
                    <input type="text" class="form-control" value="" name="kw" placeholder="<?php echo $kw;?>">
                  </div>
                </form>

                <div class="toolbar-btn-action">
				  <a id="del" class="btn btn-default submenuitem"> 批量删除</a>
				  <a id="sh" class="btn btn-default submenuitem"> 批量审核</a>
                </div>

              </div>
              <div class="card-body">
                
                <div class="table-responsive">
                  <table class="table table-bordered">
                    <thead>
                      <tr>
                        <th width="3%">
                          <label class="ftdms-checkbox checkbox-success">
                            <input type="checkbox" id="check-all"><span></span>
                          </label>
                        </th>
                        <th>标题</th>
						<th>下载地址</th>
                        <th>反馈用户</th>
						<th>反馈日期</th>
                        <th>处理状态</th>
                        <th>操作</th>
                      </tr>
                    </thead>
                    <tbody>
					  <?php
					  foreach ($ListArray as $k=>$v){
						  $flag=1; $msg = '';
						  if ($v['flag']==1){
                             $flag = 0;
							 $msg  = 'checked';
						  }

					  ?>
                      <tr>
                        <td>
                          <label class="ftdms-checkbox checkbox-success">
                            <input type="checkbox" name="ids" value="<?php echo $v['id']?>" data_id="<?php echo $v['id']?>"><span></span>
                          </label>
                        </td>
                        <td><font color="<?php echo $v['msg_titlecolor']?>"><a href="../view.php?id=<?php echo $v['msg_id']?>"><?php echo $v['msg_title']?></a></font></td>
						<td><a href="../down.php?id=<?php echo $v['msg_id']?>">下载资源</a></font></td>
                        <td><?php echo $v['UserName']?></td>
						<td><?php echo $v['addtime']?></td>
                        <td>
						   <label class="ftdms-switch switch-solid switch-success">
                             <input type="checkbox" value="<?php echo $flag;?>" name="flag" <?php echo $msg;?> onclick="chkbox(<?php echo $v['id']?>,<?php echo $flag;?>,1);">
                             <span></span>
                           </label>
						</td>
                        <td>
                          <div class="btn-group">
                            <a class="btn btn-xs btn-default submenuitem del" title="删除" data-toggle="tooltip" onclick="del_data(<?php echo $v['id']?>)"><i class="ftsucai-del"></i></a>
                          </div>
                        </td>
                      </tr>
					  <?php
					  }
					  ?>
                    </tbody>
                  </table>
				  <nav>
                    <ul class="pagination no-border">
                     <?php echo $pager=$p->output(1);?>
                    </ul>
                  </nav>
                </div>	
       
              </div>
            </div>
          </div>
          
        </div>
        
      </div>
      
    </main>
    <!--End 页面主要内容-->

<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.js"></script>
<script type="text/javascript" src="../js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="../js/main.min.js"></script>
<script type="text/javascript" src="../js/jquery-confirm.min.js"></script>
<script type="text/javascript" src="../js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="../js/tips.js"></script>

<script type="text/javascript">

$(document).keyup(function(event){
  if(event.keyCode ==13){
    $("#search").trigger("click");
  }
});

$('#del').on('click', function(){
	//post字段
	var params =[]; var id='';
    $('input[name="ids"]:checked').each(function(){ 
    	//params.push($(this).val());
    	id += ','+this.value;
    });

    //alert(JSON.stringify(params));
    var listid=id.substr(1);
    //if (params.length==0){
    if (listid==''){
        tips.notify('你还没有选择任何内容！', 'danger', 1000);
		return false;
	}else{
		$.alert({
	        title: '你确定要删除吗？',
	        content: '',
			buttons: {
				confirm: {
					text: '确认',
					btnClass: 'btn-primary',
					action: function(){
			        	tips.loading('show');
			            //php端可用$_GET,$_post,file_get_contents("php://input")方式获取提交的数据
			    		$.post('Errorlist.php?listid='+listid, function(data) {
			                try {
			    				var ret = eval('('+data+')');
			    				if (ret.status == 1) {
			    					//alert(ret.msg);
			    					tips.loading('hide');
			    					tips.notify('操作成功，页面即将自动跳转~', 'success', 3000);
			    					window.location.reload();  //刷新当前页面
			    					//parent.location.reload();  //刷新父亲对象
			    				}else {
			    					tips.notify('操作失败！', 'danger', 1000);
			    				}
			    			} catch (e) {
			    				tips.notify('网络异常,操作失败！', 'danger', 1000);
			    			}
			    		});
					}
				},
				cancel: {
					text: '取消',
					action: function () {
	                    //$.alert('你点击了取消!');
					}
				}
			}
	    });
	}
	
});

function del_data(id) {

	$('input[data_id^=' + id + ']').attr("checked","true");

	$.alert({
		title: '你确定要删除吗？',
		content: '',
		buttons: {
			confirm: {
				text: '确认',
				btnClass: 'btn-primary',
				action: function(){
					tips.loading('show');
					$.post('Errorlist.php?listid='+id, function(data) {
						try {
							var ret = eval('('+data+')');
							if (ret.status == 1) {
								tips.loading('hide');
								//tips.notify('操作成功，页面即将自动跳转~', 'success', 3000);
								window.location.reload();  //刷新当前页面
								//parent.location.reload();  //刷新父亲对象
							}else {
								tips.loading('hide');
								tips.notify(ret.message, 'danger', 600);
							}
						} catch (e) {
							tips.loading('hide');
							tips.notify('网络异常,操作失败！', 'danger', 1000);
						}
					});
				}
			},
			cancel: {
				text: '取消',
				action: function () {
					//$.alert('你点击了取消!');
				}
			}
		}
	});
}

$('#sh').on('click', function(){

	var id='';
    $('input[name="ids"]:checked').each(function(){ 
    	id += ','+this.value;
    });

    var listid=id.substr(1);
    if (listid==''){
        tips.notify('你还没有选择任何内容！', 'danger', 1000);
		return false;
	}else{

		$.post('Errorlist.php?sp=1&flag=1&listid='+listid, function(data) {
			try {
				var ret = eval('('+data+')');
				if (ret.status == 1) {
					window.location.reload();  //刷新当前页面
					//parent.location.reload();  //刷新父亲对象
				}else {
					tips.notify(ret.message, 'danger', 1000);
				}
			} catch (e) {
				tips.notify('网络异常,操作失败！', 'danger', 1000);
			}
		});

	}
	
});

function chkbox(id,flag,sp) {
	var id;
	var flag;
	var sp;
	$.post('Errorlist.php?sp='+sp+'&listid='+id+'&flag='+flag, function(data) {
		try {
			var ret = eval('('+data+')');
			if (ret.status == 1) {
				//tips.notify(ret.message, 'success', 1000);
				window.location.reload();
			}else {
				tips.notify(ret.message, 'danger', 1000);
			}
		} catch (e) {
			tips.notify('网络异常,操作失败！', 'danger', 1000);
		}
	});
}
</script>
</body>
</html>