代码拉取完成,页面将自动刷新
<?php
if (!session_id()) session_start();
if(!isset($_SESSION['valid_user'])) {
header("Location: login.php");
exit;
}
?>
<?php
require_once('page.class.php'); //分页类
require_once('header.php');
require_once('nav.php');
require_once('side_nav.php');
require_once('bg_fns.php');
$showrow = 20; //一页显示的行数
$curpage = empty($_GET['page']) ? 1 : $_GET['page']; //当前的页,还应该处理非数字的情况
$url = "?page={page}"; //分页地址,如果有检索条件 ="?page={page}&q=".$_GET['q']
//省略了链接mysql的代码,测试时自行添加
$query = "select * from ".$articles." order by id desc";
//$sql = "SELECT id,content,addtime FROM wishing_wall";
$conn = db_connect();
$conn->query("set names utf8");
$result = $conn->query($query);
$total=$result->num_rows;//记录总条数
//$total = mysql_num_rows(mysql_query($sql));
if (!empty($_GET['page']) && $total != 0 && $curpage > ceil($total / $showrow))
$curpage = ceil($total / $showrow); //当前页数大于最后页数,取最后一页
//获取数据
$query .= " LIMIT " . ($curpage - 1) * $showrow . ",$showrow;";
$result = $conn->query($query);
?>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<!-- Begin page content -->
<div class="page-header">
<h1>新闻管理<small>查看、修改新闻</small></h1>
</div>
<div class="btn-group admin-create-bt" role="group" data-toggle="modal" data-target="#publish_news_Modal">
<button type="button" class="btn btn-default btn-primary">+ 新建文章</button>
</div>
<div class="row">
<div class="col-md-12 table-containter text-center" id="table-containter">
<?php
$str="";
$str.="<table class='table admin-table'><thead><tr><th>文章标题</th><th>分类</th><th>作者</th><th>发表日期</th><th>操作</th></tr></thead><tbody id='admin-pagination'>";
while ($row = $result->fetch_assoc()) {
$str.="<tr><th>".$row['title']."</th><th>".$news_type[$row['class']]."</th><th>".$row['author']."</th><th>".$row['date']."</th><th style='font-weight:bold;color:#d9534f'><button type='button' class='btn btn-primary delete-admin-bt' value='".$row['id']."' onclick='edit_news(this)'>编辑</button> <button type='button' class='btn btn-danger delete-admin-bt' value='".$row['id']."' onclick='delete_news(this)'>删除</button></th></tr>";
}
$str.="</tbody></table>";
echo $str;
?>
<!-- <div class="btn-group" role="group" aria-label="First group">
<button type="button" class="btn btn-default">1</button>
<button type="button" class="btn btn-default">2</button>
<button type="button" class="btn btn-default">3</button>
<button type="button" class="btn btn-default">4</button>
</div>-->
</div>
<!---->
<div class="buycar-pages">
<?php
//显示分页
$page = new page($total, $showrow, $curpage, $url, 2);
echo $page->myde_write();
?>
</div>
</div>
</div>
</div>
<!--模态对话框-->
<div class="modal fade" id="publish_news_Modal" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static" >
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">新建文章</h4>
</div>
<div class="modal-body">
<form class="form-horizontal">
<div class="form-group">
<label for="create-title" class="col-sm-3 control-label">文章标题:</label>
<div class="col-sm-6">
<input type="email" class="form-control" id="create-title" placeholder="请输入文章标题" name="username">
</div>
</div>
<div class="form-group">
<label for="create-class" class="col-sm-3 control-label">文章分类:</label>
<div class="col-sm-6">
<select class="form-control" id="create-class">
<option value="0">新闻中心</option>
<!-- <option value="1">行业动态</option>-->
<!--<option value="3">仁泽新闻</option>
<option value="4">子公司动态</option>
<option value="5">专题报道</option>-->
<option value="6">企业公告</option>
</select>
</div>
</div>
<!--ckeditor-->
<div class="form-group">
<div class="col-sm-11 news-container">
<textarea name="news-editor" class="news-editor" id="news-editor">
<p>请在这里输入正文内容</p>
</textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" style="width:100px;" onClick="post_news();return false" id="create-admin-bt">提交</button>
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!--修改新闻模态对话框-->
<div class="modal fade" id="edit_news_Modal" data-backdrop="static" >
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel-1">编辑文章</h4>
</div>
<div class="modal-body">
<form class="form-horizontal">
<div class="form-group">
<label for="edit-title" class="col-sm-3 control-label">文章标题:</label>
<div class="col-sm-6">
<input type="email" class="form-control" id="edit-title" placeholder="请输入文章标题" name="username">
</div>
</div>
<div class="form-group">
<label for="edit-class" class="col-sm-3 control-label">文章分类:</label>
<div class="col-sm-6">
<select class="form-control" id="edit-class">
<option value="0">新闻中心</option>
<!-- <option value="1">行业动态</option>-->
<!--<option value="3">仁泽新闻</option>
<option value="4">子公司动态</option>
<option value="5">专题报道</option>-->
<option value="6">企业公告</option>
</select>
</div>
</div>
<!--ckeditor-->
<div class="form-group">
<div class="col-sm-11 news-container">
<textarea name="news-editor1" class="news-editor1" id="news-editor1">
<p>请在这里输入正文内容</p>
</textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" style="width:100px;" onclick="change_news(this);" id="edit-admin-bt">提交</button>
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php
if (!session_id()) session_start();
?>
<script type="text/javascript">
CKEDITOR.replace('news-editor',{
filebrowserBrowseUrl :'ckfinder/ckfinder.html',
filebrowserImageBrowseUrl :'ckfinder/ckfinder.html?Type=Images',
filebrowserFlashBrowseUrl :'ckfinder/ckfinder.html?Type=Flash',
filebrowserUploadUrl:'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
filebrowserImageUploadUrl:'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
filebrowserFlashUploadUrl: 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
});
CKEDITOR.editorConfig = function( config ) {
config.language = 'es';
config.uiColor = '#F7B42C';
config.height = 300;
config.toolbarCanCollapse = true;
};
CKEDITOR.replace('news-editor1',{
filebrowserBrowseUrl :'ckfinder/ckfinder.html',
filebrowserImageBrowseUrl :'ckfinder/ckfinder.html?Type=Images',
filebrowserFlashBrowseUrl :'ckfinder/ckfinder.html?Type=Flash',
filebrowserUploadUrl:'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
filebrowserImageUploadUrl:'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
filebrowserFlashUploadUrl: 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
});
CKEDITOR.editorConfig = function( config ) {
config.language = 'es';
config.uiColor = '#F7B42C';
config.height = 300;
config.toolbarCanCollapse = true;
};
//分页
//$(document).ready(function(){
// changepage(1);
// });
// function changepage(page){
//
// $.ajax({
// type:"POST",
// url:"news_pagination.php",
// cache:false,
// data:{
// "page":page,
// },
// success:function(data){
// $("#table-containter").html(data);
// },
// });
// }
//提交新闻
function post_news(){
var data_tc = CKEDITOR.instances['news-editor'].getData();
$.ajax({
type:"POST",
url:"create_news.php",
cache:false,
data:{
"title":$("#create-title").val(),
"category":$('#create-class option:selected') .val(),
"content":data_tc,
},
beforeSend:function(){
$("#create-admin-bt").html("正在提交...").attr('disabled',"true");
},
success:function(data){
if(data=="1") {
alert("提交成功");
window.location.href='publish_news.php';
}
else if(data=="0"){
alert("提交失败,请重新提交");
$("#create-admin-bt").html("创建").removeAttr("disabled");
}
},
error:function(){
alert("请求超时,请重新登录");
$("#create-admin-bt").html("创建").removeAttr("disabled");
},
});
}
//删除新闻
function delete_news(delete_bt){
var news_id = $(delete_bt).val();
$.ajax({
type:"POST",
url:"delete_news.php",
cache:false,
data:{"news_id":news_id},
beforeSend:function(){
var r = confirm("确定删除文章?");
if(r == false) {
exit;
}
else {
$(delete_bt).html("删除中...").attr('disabled',"true");
}
},
success:function(data) {
if(data==1) {
alert("删除成功");
window.location.href='publish_news.php';
}
else {
alert("删除失败,请刷新页面后重新删除");
delete_bt.html("删除").removeAttr("disabled");
}
},
error:function(){
alert("请求超时");
delete_bt.html("删除").removeAttr("disabled");
},
});
};
//编辑新闻
function edit_news(delete_bt){
var news_id = $(delete_bt).val();
$("#edit-admin-bt").val(news_id);
$.ajax({
type:"POST",
url:"edit_news.php",
cache:false,
dataType:"json",
data:{"news_id":news_id},
beforeSend:function(){
$(delete_bt).html("加载中...").attr('disabled',"true");
},
success:function(data){
if(!data)
window.location.href='publish_news.php';
else {
//对json数组each遍历
//手动弹出模态对话框
$("#edit-title").val(data[1]);
if(data[2]==="0") {
$("#edit-class option:eq(0)").attr('selected','selected');
}
else if(data[2]==="3") {
$("#edit-class option:eq(1)").attr('selected','selected');
}
else if(data[2]==="4") {
$("#edit-class option:eq(2)").attr('selected','selected');
}
else if(data[2]==="5") {
$("#edit-class option:eq(3)").attr('selected','selected');
}
else if(data[2]==="6") {
$("#edit-class option:eq(4)").attr('selected','selected');
}
$("#edit_news_Modal").modal('show');
CKEDITOR.instances['news-editor1'].setData(data[3]);
$(delete_bt).html("编辑").removeAttr("disabled");
}
},
error:function(){
alert("请求超时");
delete_bt.html("编辑").removeAttr("disabled");
},
});
};
//提交修改后的文章
function change_news(change_bt){
var data_tc = CKEDITOR.instances['news-editor1'].getData();
var news_id = $(change_bt).val();
$.ajax({
type:"POST",
url:"change_news.php",
cache:false,
data:{
"news_id":news_id,
"title":$("#edit-title").val(),
"category":$('#edit-class option:selected') .val(),
"content":data_tc,
},
beforeSend:function(){
$("#create-admin-bt").html("正在提交...").attr('disabled',"true");
},
success:function(data){
if(data=="1") {
alert("修改成功");
window.location.href='publish_news.php';
}
else if(data=="0"){
alert("提交失败,请重新提交");
$("#create-admin-bt").html("创建").removeAttr("disabled");
}
},
error:function(){
alert("请求超时,请重新登录");
$("#create-admin-bt").html("创建").removeAttr("disabled");
},
});
}
</script>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。