<?php
require_once("../check.php");
require_once("../../config.php");

isset($_GET['wd'])?$wd=$_GET['wd']:$wd=null;//当前关键词
$where = null;
$fy = null;
if($wd!=null){
    
    $where = "where title like('%$wd%')";
    $fy = "&wd=".$wd;
    
}

$m="10";//每页显示的记录数
isset($_GET['page'])?$page=$_GET['page']:$page="1";//当前页数
$numsql = "select count(id) as num from dunling_article $where";
$numery = mysql_query($numsql,$config);
$numery = mysql_fetch_array($numery);
$zongjilushu = $numery['num'];//总记录数
$zy = (int)(($zongjilushu-1)/$m)+1;//总页数
$one = (int)($page-1)*$m;//当前页的首条记录
$articlesql = "select * from dunling_article $where order by id desc limit $one,$m";
$articleery = mysql_query($articlesql,$config);
?>
<!DOCTYPE HTML>
<html>
<head>
<title>内容管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="../js/jquery-1.11.1.min.js"></script>
</head>
<body>
<script>
$(function(){
    $("img").hover(function(e){
    var xxx = e.pageX + 35;
    var yyy = e.pageY - 20;
    $("#yulanimg").css("left",xxx + "px");
    $("#yulanimg").css("top",yyy + "px");
    var imgurl = $(this).parent().parent().find(".imgurl").text();
    $("#yulanimg").html('<img border="0" src=../../' + imgurl + '>');
    $("#yulanimg").show();
    },function(){
        $("#yulanimg").hide();
    });

    
    $(".tuijian").click(function(){
    var id = $(this).parent().parent().find(".id").text();
    var pr = prompt('请输入推送权重!\n\n权重值为1至4的任意值!');
    if(pr==false){
        alert('请输入推送权重值!');
        return false;
    }
    var pr = parseInt(pr);
    if(pr<'1' || pr >'4'){
        alert('值只能输入1至4的任意值!');
        return false;
    }else{
        $.get("../core/tuijian.php?id=" + id + "&pr=" + pr,function(tuia,tuib){
            if(tuia=="ok"){
             $(".id:contains('" + id + "')").parent().find(".tui").text("已推送");
             location.reload();
            }else{
                alert('推送系统出错!');
                return false;
            }
        });
    }
    

        
    });
    
    $(".del").click(function(){
    var id = $(this).parent().parent().find(".id").text();
    var title = $(this).parent().parent().find(".title").text();
    var ok = confirm('确定删除《' + title + '》吗?');
    if(ok){
        $.get("../core/del_article.php?id=" + id,function(a,b){
        if(a=="ok"){
        alert('删除成功!');
        $(".id:contains(" + id + ")").parent().remove();
        return false;
        }else{
        alert('删除数据出现失败!');
        return false;    
        }
        });
    }else{
        return false;
    }
    });

});

</script>
<style>
body{
    margin:0;
    padding:0;
    text-align:left;
}
#table{
    margin-left:20px;
    width:auto;
    max-width:1000px;
    min-height:35px;
    height:auto;
    display: table;
    line-height:35px;
    text-align:left;
    color: #505050;
    border-bottom:1px dashed #C9C9C9;
    font-size:14px;
}
#table:hover{
    background-color: #DDEEFF;
}
#table .id{
    width:100px;
    height:35px;
    line-height:35px;
    text-align:center;
    float:left;
}
#table .title{
    width:480px;
    height:35px;
    line-height:35px;
    text-align:left;
    float:left;
}
#table .date{
    width:80px;
    height:35px;
    line-height:35px;
    text-align:center;
    float:left;
}
#table .fenlei{
    width:100px;
    height:35px;
    line-height:35px;
    text-align:center;
    float:left;
}
#table .imgurl{
    display:none;
}


#table .shenhe{
    width:80px;
    height:35px;
    line-height:35px;
    text-align:center;
    float:left;
}
#table .ylimg{
    width:80px;
    height:35px;
    line-height:35px;
    text-align:center;
    float:left;
}

#table .tui{
    width:80px;
    height:35px;
    line-height:35px;
    text-align:center;
    float:left;
}
#table .caozuo{
    width:100px;
    height:35px;
    line-height:35px;
    text-align:center;
    float:left;
}
.update a{
    text-decoration:none;
    color: #00791F;
}
.update a:hover{
    text-decoration:none;
    color: #FF4646;
}
.del{
    color: #00791F;
}
.del:hover{
    color: #FF4646;
    cursor:pointer;
}
.tuijian{
    color: #00791F;
}
.tuijian:hover{
    color: #FF4646;
    cursor:pointer;
}
#p{
    margin-top:25px;
    margin-left:20px;
    width:auto;
    max-width:950px;
    min-height:50px;
    height:auto;
    display: table;
    line-height:50px;
    text-align:left;
    color: #505050;
    font-size:14px;
}
#p .page{
    width:950px;
    height:50px;
    line-height:50px;
    text-align:right;
}

#p .page li{
    text-align:center;
    display:inline;
    margin:0 5px 0 0px;
    float:left;
    height:50px;
}

#yulanimg{
    display:none;
    width:150px;
    height:150px;
    position: fixed;
    top:0;
    left:0;
}

#p .page li a{
    border-radius:3px;
    text-decoration: none;
    font-size:14px;
    color:#08246B;
    display: block;
    line-height: 30px;
    height:30px;
    padding-left: 12px;
    padding-right:12px;
    border:1px solid #08246B;
    box-shadow:0px 0px 3px 3px #DFDFDF;
}
#p .page li a:hover{
    border-radius:3px;
    width:auto;
    text-decoration: none;
    font-size:14px;
    color:#FFFFFF;
    display:table;
    line-height: 30px;
    height:30px;
    padding-left: 12px;
    padding-right:12px;
    background-color:#08246B;
}
#p .page li.dangqianye a{
    border-radius:3px;
    text-decoration: none;
    font-size:14px;
    color:#FFFFFF;
    display: block;
    line-height: 30px;
    height:30px;
    width:auto;
    padding-left: 12px;
    padding-right:12px;
    border:1px solid #08246B;
    background-color: #08246B;
}
#so{
    height:30px;
    line-height:30px;
    font-size:14px;
    color: red;
    margin-left:20px;
}
#form{
    margin:0;
    padding:0;
}
</style>


<div id="so"><form method="GET" action="article_admin.php">输入标题(支持模糊搜索): <input name="wd" type="text" style="width:200px;" /><input type="submit" value="搜索" /></form></div>

<div id="yulanimg"></div>
<div id="table">
<div class="id"><strong>ID</strong></div>
<div class="title"><strong>内容</strong></div>
<div class="ylimg"><strong>图片预览</strong></div>
<div class="date"><strong>发布日期</strong></div>
<div class="fenlei"><strong>分类ID</strong></div>
<div class="caozuo"><strong>操作</strong></div>
</div>
<?php
while($list = mysql_fetch_array($articleery)){
$title = strip_tags($list['title']);
$title = mb_substr($title,0,20,'UTF-8');
$id = $list['id'];
$shenhe = $list['shenhe'];
if($shenhe=="1"){
    $shenhe='<span style="color:green;">已审</span>';
}else{
    $shenhe='<span style="color:red;">未审核</span>';
}
$date = $list['datetime'];
$date = date("m-d",$date);
$urlid  = $list['urlid'];
$fenlei = $list['fenlei'];
$tuijians = $list['tuijian'];
isset($list['img'])?$img=$list['img']:$img=null;
if($img!=null){
    $imgico = '<img src="../images/png/ylimg.png" border="0" width="30" height="30"  />';
}else{
    $imgico = null;
}
?>
<div id="table">
<div class="imgurl"><?php echo $img;?></div>
<div class="id"><?php echo $id;?></div>
<div class="title"><?php echo $title;?></div>
<div class="ylimg"><?php echo $imgico;?></div>
<div class="date"><?php echo $date;?></div>
<div class="fenlei"><?php echo $fenlei;?></div>
<div class="caozuo"><span class="update"><a href="update_article.php?id=<?php echo $id;?>">修改</a></span> | <span class="del">删除</span></div>
</div>
<?
}
?>
<div id="p">
<div class="page">
<?php
$shangyiye = $page-1;
$xiayiye = $page+1;
if($page>"1"){
        echo '<li><a href="?page='.$shangyiye.$fy.'">上一页</a></li>';
        echo '<li><a href="?page=1'.$fy.'">1</a></li>';
}
if($page>="6"){
for($pagea=$page-4;$pagea<=$page-1;$pagea++){
        echo '<li><a href="?page='.$pagea.$fy.'">'.$pagea.'</a></li>';
}
}
echo '<li class="dangqianye"><a href="?page='.$page.$fy.'">'.$page.'</a></li>';

     
if(($zy-$page)>="5"){
for($pageb=$page+1;$pageb<=$page+4;$pageb++){
        echo '<li><a href="?page='.$pageb.$fy.'">'.$pageb.'</a></li>';
}
}

if("5">=($zy-$page)){
for($pagec=$page+1;$pagec<=$zy-1;$pagec++){
        echo '<li><a href="?page='.$pagec.$fy.'">'.$pagec.'</a></li>';
}
}

if($page<$zy){
        echo '<li><a href="?page='.$zy.'">..'.$zy.'</a></li>';
        echo '<li><a href="?page='.$xiayiye.$fy.'">下一页</a></li>';
}
?>
</div>
</div>
</body>