diff --git a/application/admin/controllers/NewsController.php b/application/admin/controllers/NewsController.php index 3598f204..acd50383 100644 --- a/application/admin/controllers/NewsController.php +++ b/application/admin/controllers/NewsController.php @@ -128,9 +128,15 @@ class Admin_NewsController extends Zend_Controller_Action $keyword = $this->_request->getParam('keyword'); $description = $this->_request->getParam('description'); $displayorder = $this->_request->getParam('displayorder'); + $display = (int)$this->_request->getParam('display'); $fid = $this->_request->getParam('fid'); - $sql="update news_category set title='$title',keywords='$keyword',description='$description',displayorder='$displayorder',url='$url',fid=$fid where id=$edit"; + if(empty($displayorder)) + { + $displayorder = 0; + } + + $sql="update news_category set title='$title',keywords='$keyword',description='$description',displayorder=$displayorder,url='$url',fid=$fid,display=$display where id=$edit"; if($this->db->exec($sql)>0) { $this->messenger->addMessage('提示信息:栏目编辑成功!'); @@ -350,13 +356,20 @@ class Admin_NewsController extends Zend_Controller_Action $id = $this->_request->getParam('id'); - $sql = "select * from news_archives arc where arc.id=$id - "; + $sql = "select * from news_archives arc 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; + } + $sql="select * from news_category order by displayorder desc"; $re = $this->db->query($sql); $types = $re->fetchAll(); @@ -490,6 +503,146 @@ class Admin_NewsController extends Zend_Controller_Action $this->_redirect('/admin/news/newslist'); }//文章删除 + + + function uploadAction(){ + try{ + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $userid = $user->id; + } + + include_once('files.php'); + $files=new files(); + $msg = $files -> upload('../htdocs/upload/',$_FILES['Filedata'],'image'); + + if(empty($msg['error'])) + { + $msg['error']=""; + $filename = $msg['db_path']; + $filesize = $msg['file_size']; + $filedesc = $this->_request->getParam('filedesc'); + $filetype = 'thumb'; + $realname = $msg['realname']; + $fileurl = $msg['file_url']; + + $sql = "insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values ('$filename','$filetype','$filedesc','$userid','$filesize','$realname') RETURNING id"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $att = $sth->fetch(PDO::FETCH_ASSOC); + $msg['attid'] = $attid = $att['id']; + + $imgct = files::getImageType('../htdocs/upload/'.$filename); + + if(!isset($imgct['error'])) $preview = ''; + else $preview = ""; + + $msg['html'] = $preview.$realname.'[已完成]
'; + $msg['preview'] = "/images/".$attid; + echo Zend_Json::encode($msg); + exit(); + }else{ + $msg['error'] = '附件上传失败:'.$msg['error']; + @unlink($filename); + echo Zend_Json::encode($msg); + exit(); + } + + }catch(Exception $e){ + $msg['error'] = "错误:".$e->getMessage(); + echo Zend_Json::encode($msg); + exit(); + } + } + + function getattsAction(){ + + $this->_helper->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_request->getParam('id'); + + if($id!='') + { + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $sql = "select att.realname,att.id,att.filename from attachments att + left join archives_att ratt on att.id=ratt.attid + where ratt.arcid=$id"; + $rs = $this->db->query($sql); + $atts = $rs->fetchAll(); + + include_once('files/files.php'); + + foreach($atts as $k=>$v) + { + $imgct = files::getImageType('../htdocs/upload/'.$v['filename']); + + if(!isset($imgct['error'])) $preview = ''; + else $preview = ""; + + $atts[$k]['html']= $preview.$v['realname'].'[已完成]
'; + } + + echo Zend_Json::encode($atts); + exit(); + }else + { + exit(); + } + }else{ + exit(); + } + + } + + function delattAction(){ + $this->_helper->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_request->getParam('id'); + $aid = $this->_getParam('aid'); + $basepath = '../htdocs/upload/'; + $info = $this->getFileinfo($id); + $filepath = $basepath.$info['filename']; + try{ + if(empty($aid)) + { + $sql = "DELETE FROM attachments WHERE id=$id"; + if($this->db->exec($sql)>0) + { + @unlink($filepath); + } + }else{ + $sql = "delete from archives_att where attid='$id' and arcid='$aid'"; + if($this->db->exec($sql)>0) + { + $sql = "DELETE FROM attachments WHERE id=$id"; + if($this->db->exec($sql)>0){@unlink($filepath);} + } + } + + } + catch(Exception $e){} + } + + public function getFileinfo($id){ + $sql = "select * from attachments where id='$id'"; + $re= $this->db->query($sql); + $row= $re->fetch(); + return $row; + } + + public function jsonexit($data){ + $this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); + return true; + } + + } diff --git a/application/admin/views/scripts/news/category-edit.phtml b/application/admin/views/scripts/news/category-edit.phtml index 8b12b48e..a94be6e3 100644 --- a/application/admin/views/scripts/news/category-edit.phtml +++ b/application/admin/views/scripts/news/category-edit.phtml @@ -65,8 +65,7 @@


- - e.g. 高程,气象,地理 +

@@ -75,6 +74,14 @@ 80个汉字以内,不能使用折行

+

+
+ +

+

or

diff --git a/application/admin/views/scripts/news/newsadd.phtml b/application/admin/views/scripts/news/newsadd.phtml index e76c46b5..a1307b0b 100644 --- a/application/admin/views/scripts/news/newsadd.phtml +++ b/application/admin/views/scripts/news/newsadd.phtml @@ -7,7 +7,10 @@ $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'); + $this->headLink()->appendStylesheet('/static/css/kindskin/default/default.css'); + $this->headLink()->appendStylesheet('/static/js/uploadify/uploadify.css'); + $this->headScript()->appendFile('/static/js/uploadify/swfobject.js'); + $this->headScript()->appendFile('/static/js/uploadify/jquery.uploadify.v2.1.4.min.js'); $this->breadcrumb('首页'); $this->breadcrumb('后台首页'); $this->breadcrumb('新闻中心'); @@ -88,6 +91,14 @@ $(document).ready(function(){

+

+ 图片: +

+ + +

+


@@ -220,5 +231,56 @@ function getByteLen(val) { len += 1; } return len; -} +} +$(document).ready(function() { + $('#file_upload').uploadify({ + 'uploader' : '/static/js/uploadify/uploadify.swf', + 'scriptData': {'PHPSESSID' : ''}, + 'script' : '/admin/news/upload', + 'cancelImg' : '/static/js/uploadify/cancel.png', + 'folder' : '/uploads', + 'sizeLimit' : 2097152, + 'queueSizeLimit' : 1, + 'multi' : true, + 'auto' : false, + 'displayData' : 'speed', + 'buttonImg' : '/static/js/uploadify/selectfile.gif', + 'onComplete' : function(event, ID, fileObj, response, data) { + var obj = jQuery.parseJSON(response); + var html; + if(obj.error=='') + {html = obj.html;} + else{html = obj.error;} + $('

  • ', { + "id":'uploadedItem_'+obj.attid, + "class":'uploadifyQueueItem', + "html": html + }).appendTo('#datalist'); + $('#deletebtn_'+obj.attid).bind('click', function() { + deleteatt(obj.attid); + }); + }, + 'onError' : function (event,ID,fileObj,errorObj) { + alert(errorObj.type + ' Error: ' + errorObj.info); + } + }); +}); +function deleteatt(attid){ + $.ajax({ + type:"POST", + url:'/admin/news/delatt/', + data:'id='+attid, + success:function(html){ + $('#uploadedItem_'+attid).remove(); + }, + beforeSend:function(){ + $('#deletebtn_'+attid).html(''); + } + }); +} + +function uploadError(msg,id){ + var html = msg+'
    '; + return html; +} \ No newline at end of file diff --git a/application/admin/views/scripts/news/newsedit.phtml b/application/admin/views/scripts/news/newsedit.phtml index 8657ba27..e1806887 100644 --- a/application/admin/views/scripts/news/newsedit.phtml +++ b/application/admin/views/scripts/news/newsedit.phtml @@ -7,7 +7,10 @@ $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'); + $this->headLink()->appendStylesheet('/static/css/kindskin/default/default.css'); + $this->headLink()->appendStylesheet('/static/js/uploadify/uploadify.css'); + $this->headScript()->appendFile('/static/js/uploadify/swfobject.js'); + $this->headScript()->appendFile('/static/js/uploadify/jquery.uploadify.v2.1.4.min.js'); $this->breadcrumb('首页'); $this->breadcrumb('后台首页'); $this->breadcrumb('新闻中心'); @@ -90,6 +93,21 @@ $(document).ready(function(){

    +

    + 图片: +

    + + +

    +


    @@ -175,6 +193,13 @@ $(function(){ }); }); function addon(){ + if($('#datalist').children('li').length > 1) + { + if(confirm("如果提交的缩略图多余1个只会采用最后一个图片作为缩略图,是否继续?") === false) + { + return false; + } + } editor.sync(); var url = "/admin/news/archivesedit/id/ev['id']; ?>"; var data = $("#archivesadd").serialize()+'&keyword='+$('#keyword').val(); @@ -221,4 +246,56 @@ function getByteLen(val) { } return len; } + +$(document).ready(function() { + $('#file_upload').uploadify({ + 'uploader' : '/static/js/uploadify/uploadify.swf', + 'scriptData': {'PHPSESSID' : ''}, + 'script' : '/admin/news/upload', + 'cancelImg' : '/static/js/uploadify/cancel.png', + 'folder' : '/uploads', + 'sizeLimit' : 2097152, + 'queueSizeLimit' : 1, + 'multi' : true, + 'auto' : false, + 'displayData' : 'speed', + 'buttonImg' : '/static/js/uploadify/selectfile.gif', + 'onComplete' : function(event, ID, fileObj, response, data) { + var obj = jQuery.parseJSON(response); + var html; + if(obj.error=='') + {html = obj.html;} + else{html = obj.error;} + $('

  • ', { + "id":'uploadedItem_'+obj.attid, + "class":'uploadifyQueueItem', + "html": html + }).appendTo('#datalist'); + $('#deletebtn_'+obj.attid).bind('click', function() { + deleteatt(obj.attid); + }); + }, + 'onError' : function (event,ID,fileObj,errorObj) { + alert(errorObj.type + ' Error: ' + errorObj.info); + } + }); +}); +function deleteatt(attid){ + $.ajax({ + type:"POST", + url:'/admin/news/delatt/', + data:'id='+attid, + success:function(html){ + $('#uploadedItem_'+attid).remove(); + }, + beforeSend:function(){ + $('#deletebtn_'+attid).html(''); + } + }); +} + +function uploadError(msg,id){ + var html = msg+'
    '; + return html; +} \ No newline at end of file