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

$m="14";//每页显示的记录数
isset($_GET['page'])?$page=$_GET['page']:$page="1";//当前页数
$numsql = "select count(id) as num from dunling_article";
$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 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(){
    $(".del").click(function(){
    var id = $(this).parent().parent().find(".id").text();
    var title = $(this).parent().parent().find(".W650").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{
    width:auto;
    width:100%;
    height:auto;
    min-height: 45px;
    display: table;
    text-align:center;
    color: #505050;

    font-size:14px;
}
#table:hover{
    background-color: #DDEEFF;

}
#table .W50{
    width:50px;
    height:40px;
    line-height:40px;
    text-align:left;
    float:left;
}
#table .W100{
    width:100px;
    height:40px;
    line-height:40px;
    text-align:left;
    float:left;
}

#table .W150{
    width:150px;
    height:40px;
    line-height:40px;
    text-align:left;
    float:left;
}

#table .W200{
    width:200px;
    height:40px;
    line-height:40px;
    text-align:center;
    float:left;
}

#table .W250{
    width:250px;
    height:40px;
    line-height:40px;
    text-align:left;
    float:left;
}
#table .W300{
    width:300px;
    height:40px;
    line-height:40px;
    text-align:left;
    float:left;
}
#table .W350{
    width:350px;
    height:40px;
    line-height:40px;
    text-align:left;
    float:left;
}

#table .W650{
    width:650px;
    height:40px;
    line-height:40px;
    text-align:left;
    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;
}
#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;
}


#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;
}
</style>

<div id="table">
<div class="W200"><strong>发布时间</strong></div>
<div class="W650"><strong>公告标题</strong></div>
<div class="W150"><strong>操作</strong></div>
</div>
<?php
ini_set("date.timezone","PRC");
while($list = mysql_fetch_array($articleery)){
$id = $list['id'];
$title = mb_substr($list['title'],0,32,'UTF-8');
$datetime = $list['datetime'];
$datetime = date("m-d H:i",$datetime);

?>
<div id="table">
<div style="display: none;" class="id"><?php echo $list['id'];?></div>
<div class="W200"><?php echo $datetime;?></div>
<div class="W650"><?php echo $title;?></div>
<div class="W150"><span class="update"><a href="article_update.php?id=<?php echo $id;?>">修改</a></span> | <span class="del">删除</span></div>
</div>
<?php
}
?>
<div id="p">
<div class="page">
<?php
$shangyiye = $page-1;
$xiayiye = $page+1;
if($page>"1"){
        echo '<li><a href="?page='.$shangyiye.'">上一页</a></li>';
        echo '<li><a href="?page=1">1</a></li>';
}
if($page>="6"){
for($pagea=$page-4;$pagea<=$page-1;$pagea++){
        echo '<li><a href="?page='.$pagea.'">'.$pagea.'</a></li>';
}
}
echo '<li class="dangqianye"><a href="?page='.$page.'">'.$page.'</a></li>';

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

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

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