db=Zend_Registry::get('db'); $this->view->config = Zend_Registry::get('config'); $this->messenger=$this->_helper->getHelper('FlashMessenger'); $this->view->messages = $this->messenger->getMessages(); } function postDispatch() { $this->view->messages = $this->messenger->getMessages(); } function indexAction() { $News = new Archive($this->db); $sql = "SELECT count(id) as c FROM ".$News->tbl_archives; $rs = $this->db->query($sql); $row = $rs->fetch(); $this->view->totle = $row; $sql = "SELECT count(id) as c FROM ".$News->tbl_categorys; $rs = $this->db->query($sql); $row = $rs->fetch(); $this->view->typec = $row; }//indexAction 首页 function newslistAction(){ $News = new Archive($this->db); $type = $this->_request->getParam('type'); if(!empty($type)) { $sql = "select n.*,c.id as typeid,c.title as catlog,c.code from ".$News->tbl_archives." n left join ".$News->tbl_catalog." ct on ct.aid=n.id left join ".$News->tbl_categorys." c on c.id = ct.cid LEFT JOIN users u ON n.userid=u.id WHERE c.id='$type' AND n.title IS NOT NULL order by n.ts_created desc"; }else { $sql = "select n.id,n.title,n.userid,n.ts_published,n.is_pub from ".$News->tbl_archives." n left join ".$News->tbl_catalog." ct on ct.aid=n.id left join ".$News->tbl_categorys." c on c.id = ct.cid LEFT JOIN users u ON n.userid=u.id WHERE n.title IS NOT NULL GROUP BY n.id ORDER BY n.ts_created desc "; } $rs = $this->db->query($sql); $rows = $rs->fetchAll(); foreach($rows as $k=>$v) { if(empty($v['typeid'])) { $ev = $News->getArchiveUrlByCid($v['id']); }else{ $ev = $News->getArchiveUrlByCid($v['id'],$v['typeid']); } $rows[$k]['type_title'] = $ev['type_title']; $rows[$k]['type_url'] = $ev['type_url']; $rows[$k]['url'] = $ev['archive_url']; } $paginator = Zend_Paginator::factory($rows); $paginator->setCurrentPageNumber($this->_getParam('page')); $paginator->setItemCountPerPage($this->view->config->page->max); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); $this->view->paginator=$paginator; $category = new ArchiveCategory($this->db); $this->view->types= $category->GetFullCategory(); $this->view->type = $type; $this->view->deepField = $category->DeepTitle; }//newslistAction 新闻列表 function catlogAction() { $add = $this->_request->getParam('add'); $submit = $this->_request->getParam('submit'); $delete = $this->_request->getParam('delete'); $edit = $this->_request->getParam('edit'); $News = new Archive($this->db); if($add) { $this->view->ptype = $News->ptype; $this->_helper->viewRenderer('category-add'); $category = new ArchiveCategory($this->db); $catlogs = $category->GetFullCategory(); $this->view->categories=$catlogs; $this->view->deepField = $category->DeepTitle; if(empty($submit)){ //$this->_helper->viewRenderer('category-add'); }else{ $data = array(); $data['title'] = $this->_request->getParam('ctitle'); $data['code'] = $this->_request->getParam('code'); $data['fid'] = $this->_request->getParam('fid'); $data['ptype'] = $this->_request->getParam('ptype'); $data['is_pub'] = 1; $this->view->info = $data; if(empty($data['title'])) { $this->view->error = "请输入标题"; return true; } if(empty($data['code'])) { $this->view->error = "请输入栏目连接,如http://westdc.westgis.ac.cn/news/notice,则只需要输入notice"; return true; } if(!preg_match("/^[a-z]+$/",$data['code'])) { $this->view->error = "url格式不正确,仅允许26个小写字母"; return true; } $LftRgt = $category->Insert($data['fid']); $data['tid'] = $data['fid']; $data['lft'] = $LftRgt['left']; $data['rgt'] = $LftRgt['right']; unset($data['fid']); if($this->db->insert($category->CategoryTable,$data)) { $this->view->msg = '提示信息:栏目添加成功!'; $this->view->jump_url = '/admin/news/catlog'; return true; }else{ $this->view->error = "添加失败,请重试"; return true; } } }//栏目添加 if($delete>0) { $sql = "delete from ".$News->tbl_categorys." where id='$delete'"; if($this->db->exec($sql)>0) { $this->messenger->addMessage('提示信息:栏目删除成功!'); $this->_redirect('/admin/news/catlog'); } }//栏目删除 if($edit>0) { $submit = $this->_getParam('submit'); $this->_helper->viewRenderer('category-edit'); $this->view->ptype = $News->ptype; $category = new ArchiveCategory($this->db); $this->view->info = $category->GetOne($edit); $this->view->categories = $category->GetFullCategory(); $this->view->deepField = $category->DeepTitle; if(!empty($submit)) { $data = array(); $data['title'] = $this->_request->getParam('ctitle'); $data['code'] = $this->_request->getParam('code'); //$data['fid'] = $this->_request->getParam('fid'); $data['ptype'] = $this->_request->getParam('ptype'); $data['is_pub'] = $this->_request->getParam('is_pub'); $this->view->info = $data; if(empty($data['title'])) { $this->view->error = "请输入标题"; return true; } if(empty($data['code'])) { $this->view->error = "请输入栏目连接,如http://westdc.westgis.ac.cn/news/notice,则只需要输入notice"; return true; } if(!preg_match("/^[a-z]+$/",$data['code'])) { $this->view->error = "url格式不正确,仅允许26个小写字母"; return true; } if($this->db->update($News->tbl_categorys,$data,"id=$edit")) { $this->view->msg = '提示信息:栏目添加成功!'; $this->view->jump_url = '/admin/news/catlog'; return true; }else{ $this->view->error = "添加失败,请重试"; return true; } } }//栏目编辑 else { $category = new ArchiveCategory($this->db); $News = new Archive($this->db); $catlogs = $category->GetFullCategory(); $ptype = $News->ptype; foreach($catlogs as $k=>$v) { $url_parts = array( "ptype"=>$v['ptype'], "type_code"=>$v['code'] ); $catlogs[$k]['url'] = $News->makeCategoryUrl($url_parts); foreach($ptype as $kk=>$vv) { if($catlogs[$k]['ptype'] == $vv) { $catlogs[$k]['ptype'] = $kk; } } } $this->view->catlogs=$catlogs; $this->view->deepField = $category->DeepTitle; }//栏目列表 }//栏目管理 function getSubCategory($fid) { $sql = "SELECT * FROM news_category WHERE fid=?"; $sth = $this->db->prepare($sql); $sth->execute(array($fid)); $rows = $sth->fetchAll(); if(empty($rows) || count($rows)<1) { return 0; }else{ return $rows; } } function getCategory($id) { $sql = "SELECT * FROM news_category WHERE id=?"; $sth = $this->db->prepare($sql); $sth->execute(array($id)); $rows = $sth->fetch(); return $rows; } function getAllcategory($id=0) { $_addon = ''; if(!empty($id)) { $_addon = "WHERE id not in ($id)"; } $sql = "SELECT * FROM ar_category $_addon ORDER BY id DESC"; $sth = $this->db->prepare($sql); $sth->execute(); return $sth->fetchAll(); } //新闻添加页面 function newsaddAction() { $category = new ArchiveCategory($this->db); $catlogs = $category->GetFullCategory(); $this->view->types=$catlogs; $this->view->deepField = $category->DeepTitle; }//newsadd 新闻添加 //文档编辑 function newseditAction() { $News = new Archive($this->db); $id = $this->_request->getParam('id'); $sql = "SELECT * FROM ar_catalog WHERE aid=$id"; $sth = $this->db->query($sql); $rows = $sth->fetchAll(); $types = array(); foreach($rows as $k=>$v) { $types[$v['id']] = $v['cid']; } $this->view->typeid = $types; $sql = "select arc.*,ct.cid as typeid from ".$News->tbl_archives." arc LEFT JOIN ".$News->tbl_catalog." ct ON arc.id=ct.aid where arc.id=$id"; $rs = $this->db->query($sql); $row = $rs->fetch(); $this->view->ev = $row; if(!empty($row['image'])) { $sql = "SELECT * FROM attachments WHERE filename='".str_replace("/upload/",'',$row['image'])."'"; $rs = $this->db->query($sql); $row = $rs->fetch(); $this->view->att = $row; } $this->view->keywords = join(",",$News->GetTags($id)); $category = new ArchiveCategory($this->db); $catlogs = $category->GetFullCategory(); $this->view->types=$catlogs; $this->view->deepField = $category->DeepTitle; } //文档编辑或者添加 function archivesaddAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $News = new Archive($this->db); $auth = Zend_Auth::getInstance(); if($auth->hasIdentity()) { $user = $auth->getIdentity(); $uid = $user->id; } $datavar = array( 'title', '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(mb_strlen($title)>200) $msg[]="标题长度不能超过200个字符"; if(mb_strlen($keyword)>200) $msg[] = "关键词长度不能超过200个字符,现在输入了".strlen($keyword)."个字符"; if(mb_strlen($description)>400) $msg[] = "内容描述不能超过200个字符,现在输入了".strlen($description)."个字符"; if(empty($body)) $msg[]="请填写内容"; if(empty($typeid)) $msg[]="请选择栏目"; if(!is_array($typeid) || count($typeid)<1) { $msg[]="请选择栏目"; } if(count($msg)>0) { echo '