From 92b264e474cdc4068d07d9b908e3448fa42075db Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Tue, 20 Dec 2011 10:00:13 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=96=B0=E9=97=BB=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=E5=90=8E=E5=8F=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/NewsController.php | 165 +++++++++++++- .../admin/views/scripts/news/index.phtml | 87 ++++--- .../admin/views/scripts/news/newsedit.phtml | 214 ++++++++++++++++++ .../admin/views/scripts/news/newslist.phtml | 10 +- 4 files changed, 433 insertions(+), 43 deletions(-) create mode 100644 application/admin/views/scripts/news/newsedit.phtml diff --git a/application/admin/controllers/NewsController.php b/application/admin/controllers/NewsController.php index e98b3640..b3781959 100644 --- a/application/admin/controllers/NewsController.php +++ b/application/admin/controllers/NewsController.php @@ -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
  • '.$e->getMessage().'
  • '; + } + } + }// 文章发布 + + 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 '
    发布失败:
    +
    +
      '; + echo '
    1. 参数错误
    2. '. + '
    +
    + '; + } + + $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 '
    发布失败:
    +
    +
      '; + foreach ($msg as $v) + { + echo '
    1. '.$v.'
    2. '; + } + echo'
    +
    + '; + } + 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 '
    发布成功!
    '; + } + else + { + $sql = "delete from news_archives where id='$id'"; + $this->db->exec($sql); + echo '
    发布失败!写入附加表出错,请联系管理员
    '; + } + } + + }catch(Exception $e){ + echo '
    文章发布失败:
    +
    +
      +
    1. '.$e->getMessage().'
    2. +
    +
    '; + } } - /* + }// 文章编辑 + + + + /*
    Info box sample
    Warning box sample
    @@ -261,8 +414,6 @@ class Admin_NewsController extends Zend_Controller_Action
    Success box sample
    */ - - } } diff --git a/application/admin/views/scripts/news/index.phtml b/application/admin/views/scripts/news/index.phtml index 0a51f11a..80a043a3 100644 --- a/application/admin/views/scripts/news/index.phtml +++ b/application/admin/views/scripts/news/index.phtml @@ -2,6 +2,7 @@ $this->headTitle($this->config->title->site); $this->headTitle('后台管理'); $this->headTitle()->setSeparator(' - '); + $this->headScript()->appendFile('/static/js/jquery.dataTables.min.js'); ?>
    @@ -29,10 +30,56 @@

    最新发布的新闻


    - - - - + + + + + + + + + + news)) + { + foreach ($this->news as $v) + { + echo ' + + + + + + '; + } + } + else + { + echo ' + + '; + } + ?> + + +
    新闻标题所属栏目新闻管理
    +
    + '.$v['title'].' +
    +
    + 详细信息 +

    作者:'.$v['writer'].'

    +

    关键词:'.$v['keyword'].'

    +

    描述:'.$v['description'].'

    +

    添加时间:'.date("Y-m-d H:i",$v['writetime']).'

    +

    发布时间:'.date("Y-m-d H:i",$v['pubtime']).'

    +

    来源:'.$v['source'].'

    +

    点击:'.$v['click'].'

    +
    +
    +
    '.$v['catlog'].' + 编辑 + 删除
    暂无数据
     
    @@ -49,35 +96,11 @@ \ No newline at end of file diff --git a/application/admin/views/scripts/news/newsedit.phtml b/application/admin/views/scripts/news/newsedit.phtml new file mode 100644 index 00000000..d560c38b --- /dev/null +++ b/application/admin/views/scripts/news/newsedit.phtml @@ -0,0 +1,214 @@ +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'); +?> +hasIdentity()) + { + $user = $auth->getIdentity(); + $uname=$user->username; + $realname = $user->realname; + } +?> + + +
    +
    +

    新闻中心

    + +
    +
    +
    + + + +
    + +
    + + + + + + +
    + +

    发布新闻

    + +
    + +
    + 新闻信息 + +

    +
    + +

    + +

    +
    + +

    + +

    +
    + +

    + +

    +
    + +

    + +

    +
    + +

    + + + +
    +
    +

    +
    + + e.g. 研究成果 +

    +

    + 添加新栏目

    + +

    + +

    +
    + +
    +

    +
    + ev['pubtime']);?>" readonly="readonly" /> + e.g. 2011-10-28 9:35 or 2011-10-28 21:35 +

    +
    +
    + +
    + +

    or

    + +
    + +
    +
    + + + + +
    + +
    + + \ No newline at end of file diff --git a/application/admin/views/scripts/news/newslist.phtml b/application/admin/views/scripts/news/newslist.phtml index 448c8eea..d8070196 100644 --- a/application/admin/views/scripts/news/newslist.phtml +++ b/application/admin/views/scripts/news/newslist.phtml @@ -33,7 +33,10 @@
    - 新闻列表 + 按栏目查看 +   + 所有新闻列表 +
    msg or $this->messages) :?> @@ -81,9 +84,9 @@
    - '.$v['catlog'].' + '.$v['catlog'].' - 编辑 + 编辑 删除 '; @@ -124,5 +127,4 @@ $(document).ready(function(){ function showpad(id){ $('#titlebtn'+id).click(); } - \ No newline at end of file