增加了新闻发布的功能

This commit is contained in:
Li Jianxuan 2011-10-10 06:30:51 +00:00
parent 2470ae7e7b
commit 08b268a605
3 changed files with 183 additions and 26 deletions

View File

@ -24,6 +24,8 @@ class Admin_NewsController extends Zend_Controller_Action
}//indexAction 首页
function listAction(){
}
function catlogAction()
{
@ -94,12 +96,32 @@ class Admin_NewsController extends Zend_Controller_Action
function newsaddAction()
{
$id = $this->_request->getParam('id');
if($id>0)
{
$sql = "select id,title,pubtime,typeid from news_archives where id=$id";
$rs = $this->db->query($sql);
$rows = $rs->fetch();
if($rows['pubtime']>time())
{
$title = "{$rows['title']}》将在".date('Y-m-d H:i',$rows['pubtime'])."发布";
}
else
{
$title = "{$rows['title']}》发布成功!";
}
$this->view->title = $title;
$this->view->infos = $rows;
$this->_helper->viewRenderer('newsaddok');
}
$sql="select * from news_catlog order by displayorder desc";
$re = $this->db->query($sql);
$types = $re->fetchAll();
$this->view->types=$types;
$this->view->types=$types;
}//newsadd 新闻添加
@ -145,7 +167,11 @@ class Admin_NewsController extends Zend_Controller_Action
{
if(!empty($pubtimer))
{
$pubtime = strtotime("2011-10-09 19:03");
$pubtime = strtotime($pubtime);
}
else
{
$pubtime = time();
}
$date=array(
@ -158,23 +184,61 @@ class Admin_NewsController extends Zend_Controller_Action
'pubtime' => $pubtime,
'source' => $source,
'typeid' => $typeid,
'pub' => $pub
'pub' => $pub,
'body' => $body
);
echo '<div class="box box-success">发布成功:</div>
<div class="box box-error-msg">
<ol>';
foreach($date as $k=>$v)
{
if(in_array($k,$datavar))
$sql = "INSERT INTO news_archives (title,writer,keyword,description,image,writetime,pubtime,source,typeid,pub)
VALUES ('{$date['title']}',
'{$date['writer']}',
'{$date['keyword']}',
'{$date['description']}',
'{$date['image']}',
'{$date['writetime']}',
'{$date['pubtime']}',
'{$date['source']}',
'{$date['typeid']}',
'{$date['pub']}')
RETURNING id
";
try{
$sth = $this->db->prepare($sql);
if($sth->execute())
{
echo '<li>'.$k.'='.$v.'</li>';
$temp = $sth->fetch(PDO::FETCH_ASSOC);
$sql = "INSERT INTO news_archivesaddon (id,body) values ('{$temp['id']}','{$date['body']}')";
if($this->db->exec($sql)>0)
{
echo '<div class="box box-success">发布成功!</div><script>
setTimeout("self.location=\'/admin/news/newsadd/id/'.$temp['id'].'\'",500);
</script>';
}
else
{
$sql = "delete from news_archives where id={$temp['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>';
}
echo'</ol>
</div>
';
}
/*

View File

@ -6,8 +6,6 @@
$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();
@ -92,7 +90,7 @@ $(document).ready(function(){
<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="" name="title"/>
@ -108,12 +106,6 @@ $(document).ready(function(){
<input type="text" id="source" class="half title" value="中国西部环境与生态科学数据中心" name="source"/>
</p>
<p>
<label for="image">缩略图</label><br/>
<input type="file" class="half title" value=""/>
<input type="hidden" id="image" class="half title" value="" name="image"/>
</p>
<p>
<label for="description">内容简介(描述)</label><br/>
<textarea id="description" class="small half" name="description"></textarea>
@ -156,7 +148,7 @@ $(document).ready(function(){
<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",time()+3600);?>" disabled="disabled" />
<input type="text" name="pubtime" id="pubtime" value="<?php echo date("Y-m-d H:i",time()+3600*24);?>" readonly="readonly" />
<small>e.g. 2011-10-28 9:35 or 2011-10-28 21:35</small>
</p>
</div>
@ -186,12 +178,12 @@ $(function(){
if($(this).is(":checked"))
{
$('#pubtimelable').html('定时发布时间');
$('#pubtime').removeAttr('disabled');
$('#pubtime').removeAttr('readonly');
}
else
{
$('#pubtimelable').html('定时发布?');
$('#pubtime').attr("disabled","disabled");
$('#pubtime').attr("readonly","readonly");
}
});
});
@ -216,5 +208,4 @@ function addon(){
}
});
}
</script>

View File

@ -0,0 +1,102 @@
<?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'); ?>
</aside>
<!-- End of Right column/section -->
<!-- Left column/section -->
<section class="column width6">
<h3><?php echo $this->title;?></h3>
<ul>
<li><a href="">查看文章</a></li>
<li><a href="">返回文章列表</a></li>
<li><a href="">更改文章</a></li>
<li><a href="">发表新文章</a></li>
<li>页面将自动跳转至文章列表页</li>
</ul>
</section>
<!-- End of Left column/section -->
</div>
<!-- End of Wrapper -->
</div>
<!-- End of Page content -->
<script type="text/javascript">
$(function(){
$('#nav_news').addClass("current");
});
setTimeout("self.location='/admin/news/list/typeid/<?php echo $this->view->typeid;?>'",500);
</script>