<?php
require_once("../check.php");
require_once("../../config.php");
isset($_GET['id'])?$id=$_GET['id']:$id=null;
$sql = "select * from dunling_article where id='$id'";
$ups = mysql_query($sql,$config)or die("delerror");
$c  = mysql_fetch_array($ups)or die("error");
$leimu = $c['fenlei'];
$content = str_replace("<br/>","\n",$c['content']);
$title = $c['title'];
?>
<!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>
<link rel="stylesheet" href="/editor/themes/default/default.css" />
<script src="../../editor/kindeditor-min.js"></script>
</head>
<body>
<script>
        KindEditor.ready(function(K) {
                window.editor = K.create('#content',{
                    pasteType:1,
                    resizeType:0,
                    width:'740px',
                    height:'380px'
                });
        });
</script>
<script>
    $(function(){
    $(document).ajaxStart(function(){
    $("#loading").show();
    });
    
    $(document).ajaxStop(function(){
    setTimeout(function(){
    $("#loading").hide();
    },1000);
    });
    
    $("#form").click(function(){
    var id = $("#id").val();
    var fenlei = $("#fenlei").val();
         editor.sync();
    var content = $("#content").val();
    var title = $("#title").val();
    if((title==false) || (content==false)){
        alert('请输入必填项!\n\n必填项包含:内容标题、主要内容!');
        return false;
    }
    $.post("../core/update_article.php",{
        id:id,
        title:title,
        content:content,
        fenlei:fenlei
    },function(fabuok,fabuzt){
        if(fabuok=="ok"){
              setTimeout(function(){
              alert('保存成功!');
              location.href='update_article.php?id=' + id;
              return false;
                },1500);
            
        }else{
            alert('保存出错!');
            return false;
        }
    });
    
   });
    
   $("#length").click(function(){
    var zis = $("#content").val().length;
    alert("文章内容共有 " + zis + " 字");
   });
    
    
    
    });
</script>
<style>
body{
    margin:0;
    padding:0;
    text-align:left;
    margin-top:40px;
}
#top{
    width:100%;
    height:35px;
    background-color: #D4D4D4;
    text-align:left;
    line-height:35px;
    font-size:14px;
    color: #DB601E;
    position: fixed;
    left:0;
    top:0;
}
#top input{
border-style: groove;
height:30px;
font-size:14px;
color: #333333;
}
#button{
    margin-top:5px;
    width:700px;
    height:80px;
    line-height:80px;
    display: table;
    text-align:left;

}

#button input{
    margin-top:10px;
    margin-left:155px;
    height:35px;
    line-height:35px;
    width:150px;
    float:left;
    color: #FFFFFF;
    font-size:16px; 
    background-color:#08246B;
    border:1px solid #08246B;
    border-radius:5px;
    box-shadow:0px 0px 5px 5px #C2C2C2;   
}

#table{
    margin-top:5px;
    width:auto;
    max-width:1000px;
    min-height:30px;
    height:auto;
    display: table;
    line-height:30px;
    text-align:left;

}
#table label{
    clear:none;
    height:30px;
    line-height:30px;
    float:left;
    width:150px;
    text-align:right;
    color: #5F5F5F;
    font-size:16px;
    margin-right:5px;
}
#table input{
    border:1px solid #D8D8D8;
    border-radius:3px;
    line-height:30px;
    height:30px;
    float:left;
    font-size:14px; 
}
#table input.text{
    color: #5F5F5F;
    width:740px;  
}
#table input.xtext{
    color: #5F5F5F;
    width:100px; 
}
#table textarea.c{
    float:left;
    width:735px;
    height:350px;
    resize:none;
    border:1px solid #D8D8D8;
    border-radius:3px;
    color: #5F5F5F;
    font-size:16px;
    line-height:25px;
    letter-spacing: 1px;
}

#table input.form{
    margin-top:10px;
    margin-left:155px;
    height:35px;
    line-height:35px;
    width:150px;
    float:left;
    color: #FFFFFF;
    font-size:16px; 
    background-color:#08246B;
    border:1px solid #08246B;
    border-radius:5px;
    box-shadow:0px 0px 5px 5px #C2C2C2;   
}
#table select{

    color: #5F5F5F;
    font-size:14px;
    border:1px solid #D8D8D8;
    width: 100px;
}

#loading{
    z-index: 800;
    display:none;
    margin:0;
    padding:0;
    position: fixed;
    width:190px;
    height:14px;
    top:220px;
    left:410px;
}
input.title{
    width:735px;
}
</style>
<div id="top"><input type="button" value="&laquo;返回" onclick="location.href='article_admin.php'" /><input onclick="location.href='?id=<?php echo $id;?>'" type="button" value="刷新" /></div>
<div id="table">
<label>标题:</label><input type="text" id="title" class="title" value="<?php echo $title;?>"  />
</div>
<div id="table">
<input id="id" type="hidden" value="<?php echo $id;?>" />
<label>选择分类:</label><select id="fenlei">
<?php
$sql = "select * from dunling_menu";
$ery = mysql_query($sql,$config);
while($i = mysql_fetch_array($ery)){
    $fl = $i['menu'];
    $ids = $i['id'];
    if($ids == $leimu){
        $selected = "selected";
    }else{
        $selected =null;
    }
    
    echo '<option '.$selected.' value="'.$ids.'">';
    echo $fl;
    echo '</option>';
}
?>
</select>
</div>


<div id="table">
<label>主要内容:</label><textarea id="content" class="c"><?php echo $content;?></textarea>
</div>


<div id="button">
<input class="form" id="form" type="button" value="保存修改" />
</div>
<div id="loading"><img src="../images/png/dunling_loading.gif" /></div>
</body>