完善新闻中心后台功能

This commit is contained in:
Li Jianxuan 2011-12-20 10:00:13 +00:00
parent c5bea060f7
commit 92b264e474
4 changed files with 433 additions and 43 deletions

View File

@ -15,13 +15,24 @@ class Admin_NewsController extends Zend_Controller_Action
}
function indexAction()
{
$sql = "select n.*,c.title as catlog from news_archives n left join news_catlog c on n.typeid=c.id order by n.writetime desc limit 10";
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
$this->view->news = $rows;
}//indexAction 首页
function newslistAction(){
$sql = "select n.*,c.title as catlog from news_archives n left join news_catlog c on n.typeid=c.id";
$type = $this->_request->getParam('type');
if(!empty($type))
{
$sql = "select n.*,c.title as catlog from news_archives n left join news_catlog c on n.typeid=c.id WHERE n.typeid='$type' order by n.writetime desc";
}else
{
$sql = "select n.*,c.title as catlog from news_archives n left join news_catlog c on n.typeid=c.id order by n.writetime desc";
}
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
@ -238,16 +249,158 @@ class Admin_NewsController extends Zend_Controller_Action
<li>'.$e->getMessage().'</li>
</ol>
</div>';
}
}
}// 文章发布
function newseditAction()
{
$id = $this->_request->getParam('id');
$sql = "select * from news_archives arc
left join news_archivesaddon addon on addon.id=arc.id
where arc.id=$id
";
$rs = $this->db->query($sql);
$row = $rs->fetch();
$this->view->ev = $row;
$sql="select * from news_catlog order by displayorder desc";
$re = $this->db->query($sql);
$types = $re->fetchAll();
$this->view->types=$types;
}
function archiveseditAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$id = $this->_request->getParam('id');
if(empty($id))
{
echo '<div class="box box-error">发布失败:</div>
<div class="box box-error-msg">
<ol>';
echo '<li>参数错误</li>'.
'</ol>
</div>
';
}
$datavar = array(
'title','writer','source','image','body','typeid','pub','pubtimer','pubtime','description','keyword'
);
foreach($_POST as $k=>$v)
{
if(in_array($k,$datavar))
{
$$k=$v;
}
}
$msg=array();
if(empty($title)) $msg[]="标题不能为空";
if(strlen($title)>40) $msg[]="标题长度不能超过40个字符";
if(strlen($writer)>50) $msg[]="作者长度不能超过50个字符";
if(strlen($keyword)>200) $msg[] = "关键词长度不能超过200个字符现在输入了".strlen($keyword)."个字符";
if(strlen($description)>200) $msg[] = "内容描述不能超过200个字符现在输入了".strlen($description)."个字符";
if(empty($body)) $msg[]="请填写内容";
if($typeid==0) $msg[]="请选择栏目";
if(count($msg)>0)
{
echo '<div class="box box-error">发布失败:</div>
<div class="box box-error-msg">
<ol>';
foreach ($msg as $v)
{
echo '<li>'.$v.'</li>';
}
echo'</ol>
</div>
';
}
else
{
if(!empty($pubtimer))
{
$pubtime = strtotime($pubtime);
}
else
{
$pubtime = time();
}
$date=array(
'title' => $title,
'writer' => $writer,
'keyword' => $keyword,
'description'=> $description,
'image' => $image,
'writetime' => time(),
'pubtime' => $pubtime,
'source' => $source,
'typeid' => $typeid,
'pub' => $pub,
'body' => $body
);
$sql = "UPDATE news_archives SET
title='{$date['title']}',
writer='{$date['writer']}',
keyword='{$date['keyword']}',
description='{$date['description']}',
image='{$date['image']}',
pubtime='{$date['pubtime']}',
source='{$date['source']}',
typeid='{$date['typeid']}',
pub='{$date['pub']}'
WHERE id='$id'
";
try{
$sth = $this->db->prepare($sql);
if($sth->execute())
{
$sql = "UPDATE news_archivesaddon SET body='".$date['body']."' WHERE id='$id'";
if($this->db->exec($sql)>0)
{
echo '<div class="box box-success">发布成功!</div><script>
setTimeout("self.location=\'/admin/news/newsadd/id/'.$id.'\'",500);
</script>';
}
else
{
$sql = "delete from news_archives where id='$id'";
$this->db->exec($sql);
echo '<div class="box box-success">发布失败!写入附加表出错,请联系管理员</div>';
}
}
}catch(Exception $e){
echo '<div class="box box-error">文章发布失败:</div>
<div class="box box-error-msg">
<ol>
<li>'.$e->getMessage().'</li>
</ol>
</div>';
}
}
/*
}// 文章编辑
/*
<div class="box box-info">Info box sample</div>
<div class="box box-warning">Warning box sample</div>
@ -261,8 +414,6 @@ class Admin_NewsController extends Zend_Controller_Action
<div class="box box-success">Success box sample</div>
*/
}
}

View File

@ -2,6 +2,7 @@
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->headScript()->appendFile('/static/js/jquery.dataTables.min.js');
?>
<!-- Page title -->
<div id="pagetitle">
@ -29,10 +30,56 @@
<h3>最新发布的新闻</h3>
<hr/>
<table id="report" class="stylized full" style="">
<thead>
<tr>
<th width="50%">新闻标题</th>
<th width="25%">所属栏目</th>
<th width="25%">新闻管理</th>
</tr>
</thead>
<tbody>
<?php
if(count($this->news))
{
foreach ($this->news as $v)
{
echo '
<tr>
<td class="title">
<div id="paddiv'.$v['id'].'">
<a id="titlebtn'.$v['id'].'"><b>'.$v['title'].'</b></a>
<div class="listingDetails">
<div class="pad">
<b>详细信息</b>
<p>作者:'.$v['writer'].'</p>
<p>关键词:'.$v['keyword'].'</p>
<p>描述:'.$v['description'].'</p>
<p>添加时间:'.date("Y-m-d H:i",$v['writetime']).'</p>
<p>发布时间:'.date("Y-m-d H:i",$v['pubtime']).'</p>
<p>来源:'.$v['source'].'</p>
<p>点击:'.$v['click'].'</p>
</div>
</div></div>
</td>
<td>'.$v['catlog'].'</td>
<td>
<a href="/admin/news/newsedit/id/'.$v['id'].'"><b>编辑</b></a>
<a href="/admin/news/catlog/delete/'.$v['id'].'" onclick="return confirm(\'是否确定删除该栏目\')">删除</a></td>
</tr>
';
}
}
else
{
echo '
<tr><td>暂无数据</td><td></td></tr>
';
}
?>
</tbody>
</table>
<div class="clear">&nbsp;</div>
</section>
@ -49,35 +96,11 @@
<script type="text/javascript">
$(document).ready(function(){
/* setup navigation, content boxes, etc... */
Administry.setup();
/* progress bar animations - setting initial values */
Administry.progress("#progress1", 1, 5);
Administry.progress("#progress2", 2, 5);
Administry.progress("#progress3", 2, 5);
/* flot graphs */
var sales = [{
label: 'Total Paid',
data: [[1, 0],[2,0],[3,0],[4,0],[5,0],[6,0],[7,900],[8,0],[9,0],[10,0],[11,0],[12,0]]
},{
label: 'Total Due',
data: [[1, 0],[2,0],[3,0],[4,0],[5,0],[6,422.10],[7,0],[8,0],[9,0],[10,0],[11,0],[12,0]]
}
];
var plot = $.plot($("#placeholder"), sales, {
bars: { show: true, lineWidth: 1 },
legend: { position: "nw" },
xaxis: { ticks: [[1, "Jan"], [2, "Feb"], [3, "Mar"], [4, "Apr"], [5, "May"], [6, "Jun"], [7, "Jul"], [8, "Aug"], [9, "Sep"], [10, "Oct"], [11, "Nov"], [12, "Dec"]] },
yaxis: { min: 0, max: 1000 },
grid: { color: "#666" },
colors: ["#0a0", "#f00"]
});
Administry.expandableRows();
});
function showpad(id){
$('#titlebtn'+id).click();
}
$('#nav_news').addClass("current");
</script>

View File

@ -0,0 +1,214 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->headScript()->appendFile('/static/js/jquery.tagInput.min.js');
$this->headScript()->appendFile('/static/js/kindeditor-min.js');
$this->headScript()->appendFile('/static/js/kindlang/zh_CN.js');
$this->headLink()->appendStylesheet('/static/css/kindskin/default/default.css');
?>
<?php
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$uname=$user->username;
$realname = $user->realname;
}
?>
<script type="text/javascript">
/* sample tags */
var tags=[
{tag:"冻土",freq:30},{tag:"寒旱所",freq:25}, {tag:"大气",freq:10},{tag:"高原",freq:4},
{tag:"西部",freq:3},{tag:"地理",freq:8}, {tag:"环境",freq:3},{tag:"地质",freq:20}
];
$(document).ready(function(){
/* setup navigation, content boxes, etc... */
Administry.setup();
KindEditor.ready(function(K) {
editor=K.create('textarea[name="body"]', {
cssPath : '/static/js/plugins/code/prettify.css',
uploadJson : '/plugins/upload_json.php',
fileManagerJson : '/plugins/file_manager_json.php',
allowFileManager : true
});
});
/* tag input field */
$("#keyword").tagInput({
tags:tags,
//jsonUrl:"tags.json",
sortBy:"frequency",
suggestedTags:["冻土", "寒旱所", "大气", "高原", "西部", "环境"],
tagSeparator:",",
autoFilter:true,
autoStart:false,
//suggestedTagsPlaceHolder:$("#suggested"),
boldify:true
});
});
</script>
<!-- Page title -->
<div id="pagetitle">
<div class="wrapper">
<h1>新闻中心</h1>
<!-- Quick search box -->
<form action="" method="get"><input class="" type="text" id="q" name="q" /></form>
</div>
</div>
<!-- End of Page title -->
<!-- Page content -->
<div id="page">
<!-- Wrapper -->
<div class="wrapper">
<!-- Right column/section -->
<aside class="column width2 first">
<?= $this->partial('news/left.phtml'); ?>
<div class="content-box">
<header>
<h3>新闻标签</h3>
</header>
<section>
输入Tag标签多个用半角逗号 “ , ”隔开每个Tag标签长度小于6个汉字
<p><textarea id="keyword" class="small full" name="keyword"><?php echo $this->ev['keyword']; ?></textarea></p>
</section>
</div>
</aside>
<!-- End of Right column/section -->
<!-- Left column/section -->
<section class="column width6">
<h3>发布新闻</h3>
<form name="form" id="archivesadd" method="post" action="#">
<fieldset>
<legend>新闻信息</legend>
<input type="hidden" id="image" class="half title" value="" name="image"/>
<p>
<label class="required" for="producttitle">标题</label><br/>
<input type="text" id="producttitle" class="half title" value="<?php echo $this->ev['title']; ?>" name="title"/>
</p>
<p>
<label class="required" for="writer">作者</label><br/>
<input type="text" id="writer" class="half title" value="<?php echo $this->ev['writer']; ?>" name="writer"/>
</p>
<p>
<label for="source" class="required">来源</label><br/>
<input type="text" id="source" class="half title" value="<?php echo $this->ev['source']; ?>" name="source"/>
</p>
<p>
<label for="description">内容简介(描述)</label><br/>
<textarea id="description" class="small half" name="description"><?php echo $this->ev['description']; ?></textarea>
</p>
<p>
<label for="body">新闻内容</label><br/>
<textarea id="body" class="large full" name="body"><?php echo $this->ev['body']; ?></textarea>
</p>
<div class="clearfix leading">
<div class="column width3 first">
<p>
<label for="type" class="required">新闻栏目</label><br/>
<select id="type" class="full" name="typeid">
<option value="0">请选择栏目</option>
<?php
foreach($this->types as $v)
{
if($this->ev['typeid']==$v['id'])
echo '<option value="'.$v['id'].'" selected="selected">'.$v['title'].'</option>';
else
echo '<option value="'.$v['id'].'">'.$v['title'].'</option>';
}
?>
</select>
<small>e.g. 研究成果</small>
</p>
<p><a href="/admin/news/catlog/add/1" target="_blank">+ 添加新栏目</a></p>
<p>
<select id="pub" class="full" name="pub">
<option value="1" <?php if($this->ev['pub']>=1) echo 'selected="selected"'; ?>>立即发布</option>
<option value="0" <?php if($this->ev['pub']==0) echo 'selected="selected"'; ?>>存草稿</option>
<option value="-1" <?php if($this->ev['pub']<0) echo 'selected="selected"'; ?>>不发布</option>
</select>
</p>
</div>
<div class="column width3">
<p>
<input type="checkbox" id="pubtimeturn" name="pubtimer" value="1" /><label id="pubtimelable" for="productcat">定时发布?</label><br/>
<input type="text" name="pubtime" id="pubtime" value="<?php echo date("Y-m-d H:i",$this->ev['pubtime']);?>" readonly="readonly" />
<small>e.g. 2011-10-28 9:35 or 2011-10-28 21:35</small>
</p>
</div>
</div>
<div id="return"></div>
<p class="box"><input type="button" onclick="addon();" id="submit" class="btn btn-green big" value="提交"/> or <input type="reset" class="btn" value="重置"/></p>
</fieldset>
</form>
</section>
<!-- End of Left column/section -->
</div>
<!-- End of Wrapper -->
</div>
<!-- End of Page content -->
<script type="text/javascript">
$(function(){
$('#nav_news').addClass("current");
$("#pubtimeturn").click( function () {
if($(this).is(":checked"))
{
$('#pubtimelable').html('定时发布时间');
$('#pubtime').removeAttr('readonly');
}
else
{
$('#pubtimelable').html('定时发布?');
$('#pubtime').attr("readonly","readonly");
}
});
});
function addon(){
editor.sync();
var url = "/admin/news/archivesedit/id/<?php echo $this->ev['id']; ?>";
var data = $("#archivesadd").serialize()+'&keyword='+$('#keyword').val();
$.ajax({
type: "POST",
url: url,
data: data,
success: function(html){
$('#return').html(html);
},
beforeSend:function(){
$('#submit').val('正在提交...');
$('#submit').attr("disabled","disabled");
},
complete:function(){
$('#submit').val('提交');
$('#submit').removeAttr('disabled');
}
});
}
</script>

View File

@ -33,7 +33,10 @@
<hr/>
<div>
<a href="/admin/news/newslist">新闻列表</a>
<a href="javascript:;">按栏目查看</a>
&nbsp;
<a href="/admin/news/newslist">所有新闻列表</a>
</div>
<?php if ($this->msg or $this->messages) :?>
@ -81,9 +84,9 @@
</div>
</div></div>
</td>
<td>'.$v['catlog'].'</td>
<td><a href="/admin/news/newslist/type/'.$v['typeid'].'">'.$v['catlog'].'</a></td>
<td>
<a href="javascript:showpad('.$v['id'].');"><b>编辑</b></a>
<a href="/admin/news/newsedit/id/'.$v['id'].'"><b>编辑</b></a>
<a href="/admin/news/catlog/delete/'.$v['id'].'" onclick="return confirm(\'是否确定删除该栏目\')">删除</a></td>
</tr>
';
@ -124,5 +127,4 @@ $(document).ready(function(){
function showpad(id){
$('#titlebtn'+id).click();
}
</script>