后台添加文献管理界面,添加了单篇文献添加和编辑功能

This commit is contained in:
Li Jianxuan 2013-09-26 08:26:29 +00:00
parent cd2c1c831e
commit d7d7037a24
8 changed files with 673 additions and 0 deletions

View File

@ -1,4 +1,7 @@
<?php
use Helpers\View as view;
use Reference\Reference;
class Admin_DataController extends Zend_Controller_Action
{
function preDispatch()
@ -1113,6 +1116,81 @@ class Admin_DataController extends Zend_Controller_Action
}//列表
}
//文献管理
public function refAction()
{
$this->view->ac = $ac = $this->_getParam('ac');
$submit = $this->_getParam('submit');
$reference = new Reference();
//文献首页
if(empty($ac))
{
view::addPaginator($reference->fetchReferences(),$this,10);
return true;
}
//添加
if($ac == "add")
{
$this->_helper->viewRenderer('ref-add');
$id = $this->_getParam('id');
if(!empty($submit))
{
if(empty($id) || !is_numeric($id))
{
$status = $reference->reference();
}else{
$status = $reference->reference($id);
}
if($status !== true)
{
$this->view->error = view::Error($status);
}else{
if(!empty($id))
{
$msg = "文献修改成功!";
}else{
$msg = "文献添加成功!";
}
view::Post($this,$msg,"/admin/data/ref/ac/add");
}
}else{
if(!empty($id) && is_numeric($id))
{
$this->view->data = $reference->getOneReferenceData($id);
}
}
return true;
}
//上传pdf
if($ac == "pdfupload")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$statu = $reference->uploadReferencePdf($_FILES['Filedata']);
$this->jsonexit($statu);
return true;
}
//删除已上传的文件
if($ac == "delete")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$statu = $reference->deleteReferenceAttchment($this->_getParam('attid'));
$this->jsonexit($statu);
return true;
}
}//文献管理 refAction()
/*
* 删除元数据,删除前有确认
*/

View File

@ -0,0 +1,156 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin/data">数据管理</a>');
$this->breadcrumb('文献管理');
$this->breadcrumb()->setSeparator(' > ');
$this->theme->AppendPlus($this,'colorbox');
$this->theme->AppendPlus($this,"uploadify");
$this->theme->AppendPlus($this,'admin_plugin');
?>
<style>
table thead tr th {background:#EBF2F6;}
</style>
<div class="row-fluid">
<div class="span2">
<?= $this->partial('data/left.phtml'); ?>
</div>
<div class="span10">
<div>
<?= $this->partial('data/ref-nav.phtml',array('ac'=>$this->ac)); ?>
</div>
<?php if(!empty($this->error)) { ?>
<?= $this->error ?>
<?php } ?>
<?php if(!empty($this->msg)) { ?>
<?= $this->msg ?>
<?php } else{ ?>
<form class="form-horizontal" method="post">
<div class="control-group">
<label class="control-label" for="inputTitle">文章标题</label>
<div class="controls">
<input type="text" name="title" id="inputTitle" class="input-block-level" value="<?= isset($this->data['title']) ? $this->data['title']:"" ?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputYear">出版年份</label>
<div class="controls">
<input type="text" name="year" id="inputYear" value="<?= isset($this->data['year']) ? $this->data['year']:"" ?>">
<select class="span2">
<?php for($i=2000;$i<=(int)date("Y");$i++) {?>
<option value="<?= $i ?>" onclick="$('#inputYear').val(this.value)"><?= $i ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputReference">引用方式(前台显示)</label>
<div class="controls">
<textarea name="reference" id="inputReference" class="input-block-level"><?= isset($this->data['reference']) ? $this->data['reference']:"" ?></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputLink">链接(自动填写请留空)</label>
<div class="controls">
<input type="text" name="link" id="inputLink" class="input-block-level" value="<?= isset($this->data['link']) ? $this->data['link']:"" ?>"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputBibtex">完整引用方式</label>
<div class="controls">
<textarea name="bibtex" id="inputBibtex" class="input-block-level"><?= isset($this->data['bibtex']) ? $this->data['bibtex']:"" ?></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">PDF</label>
<div class="controls">
<input type="file" name="Filedata" id="file_upload" />
<div id="uploadedFile"></div>
</div>
</div>
<div class="form-actions">
<input type="hidden" name="submit" value="1" />
<button type="submit" class="btn btn-primary">Save changes</button>
<button type="reset" class="btn">Cancel</button>
</div>
</form>
<?php } ?>
</div>
</div>
<!-- //页面内容 -->
<script>
var _this = {
SessionID : '<?php echo session_id(); ?>'
};
var uploader;
var param;
param = {
"PHPSESSID" : _this.SessionID,
};
$(function() {
$('#file_upload').uploadify({
'swf' : '/js/lib/uploadify/uploadify.swf',
'uploader' : '/admin/data/ref/ac/pdfupload',
'multi' : false,
'auto' : true,
'fileTypeExts' : '*.pdf',
'onUploadSuccess' : function(file, data, response) {
upload.onsuccess(file, data, response);
},
'onUploadStart' : function(file) {
$('#file_upload').uploadify('settings','formData',param);
}
});
});
var upload = {
onsuccess : function(file, data, response){
_data = $.parseJSON(data);
if(!$.isEmptyObject(_data.error))
{
alert(_data.error);
}else{
$('#uploadedFile').html(upload.makeFileHtml(_data));
}
},
makeFileHtml : function(data){
return '<div class="alert alert-success">'
+'<button type="button" class="close" data-dismiss="alert" onclick="upload.deleteFile('+data.id+')"><i class="icon-trash icon-white"></i></button>'
+ data.realname
+'<input type="hidden" name="attid" value="'+data.id+'"></input>'
+'</div>';
},
deleteFile : function(id){
$.ajax({
'type':"POST",
'url':'/admin/data/ref/ac/delete',
'data':'attid=' + id,
'success':function(data){
if(typeof(data) == 'undefined')
{
alert("数据源错误,请联系管理员");
return false;
}
if(!$.isEmptyObject(data.error))
{
alert(data.error);
return false;
}
},
'timeout': 30000,
'error': function(){
alert('附件删除出错');
}
});
}
};
</script>
<?php if(isset($this->data['attid']) && !empty($this->data['attid'])){ ?>
<input type="hidden" id="reference_file_content" value='<?= json_encode($this->data['file']) ?>' />
<script>
upload.onsuccess('',$('#reference_file_content').val(),"");
</script>
<?php } ?>

View File

@ -0,0 +1,6 @@
<ul class="nav nav-tabs">
<li <?= empty($this->ac) ? 'class="active"':"" ?>><a href="/admin/data/ref">浏览所有</a></li>
<li <?= $this->ac=="add" ? 'class="active"':"" ?>><a href="/admin/data/ref/ac/add">单篇添加</a></li>
<li <?= $this->ac=="multiupload" ? 'class="active"':"" ?>><a href="/admin/data/ref/ac/multiupload">批量上传</a></li>
<li <?= $this->ac=="files" ? 'class="active"':"" ?>><a href="/admin/data/ref/ac/files">文件管理</a></li>
</ul>

View File

@ -0,0 +1,162 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin/data">数据管理</a>');
$this->breadcrumb('文献管理');
$this->breadcrumb()->setSeparator(' > ');
$this->theme->AppendPlus($this,'colorbox');
$this->theme->AppendPlus($this,'admin_plugin');
?>
<style>
table thead tr th {background:#EBF2F6;}
</style>
<div class="row-fluid">
<div class="span2">
<?= $this->partial('data/left.phtml'); ?>
</div>
<div class="span10">
<div>
<?= $this->partial('data/ref-nav.phtml',array('ac'=>$this->ac)); ?>
</div>
<div>
<div class="input-append">
<form id="datasearch" class="search_form" action="">
<input type="text" id="keyword" name="q" value="<?php if(!empty($this->q)) echo $this->q; ?>" />
<button type="submit" class="btn" id="search_btn">搜索</button>
</form>
</div>
</div>
<?php if(!empty($this->error)) { ?>
<?= $this->error ?>
<?php } ?>
<?php if(!empty($this->msg)) { ?>
<?= $this->msg ?>
<?php } else{ ?>
<div id="datalist">
<?php if (count($this->paginator)): ?>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>标题</th>
<th>年份</th>
<th width="140">操作</th>
</tr>
</thead>
<tbody>
<?php $autoindex=0;
foreach ($this->paginator as $item):
$autoindex++;?>
<tr id="DataLine_<?= $item['id']?>">
<td><?= $item['title'] ?></td>
<td><?= $item['year'] ?></td>
<td>
<a href="/admin/data/ref/ac/add/id/<?= $item['id']?>">编辑</a>
<a href="javascript:void(0);" onclick="onedel(<?= $item['id']?>)" id="delbtn_<?= $item['id']?>">删除</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<div class="pagenavi"><?= $this->paginator; ?></div>
</div>
<?php } ?>
</div>
</div>
<!-- //页面内容 -->
<script>
var info = {
btn_prefix : "delbtn_",
item_prefix : "DataLine_",
url : "/admin/data/doi/ac/del"
}
$(document).ready(function(e) {
$('.verified_btn').click(function(e) {
$(this).ajaxmsg({
callback:function(){window.location.reload();}
});
});
});
(function( $ ){
$.fn.ajaxmsg = function( options ) {
var settings = $.extend( {
url:'',
callback : '',
}, options);
var methods = {
msg : function(id)
{
methods.submited();
},
creatWindow : function(content){
$.colorbox({
initialHeight: '0',
initialWidth: '0',
html: methods.dialog(content),
opacity: '0.3',
onComplete: function(){
$('.confirm_yes').click(function(e){
e.preventDefault();
if(typeof(settings.callback)=='function')
{
settings.callback();
}
$.colorbox.close();
});
$('.confirm_no').click(function(e){
e.preventDefault();
$.colorbox.close();
});
}
});
},
submited : function(){
$.ajax({
'type':"POST",
'url':settings.url,
'data':'',
'success':function(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{alert(data.error);}
if(typeof(data.success)!='undefined')
{
methods.creatWindow(data.success);
}
}
else{
alert('出现错误,请稍候再试');
}
},
'timeout': 30000,
'error': function(){
alert('出现错误,请刷新后重试');
}
});
},
dialog : function(content){
HTML = '<div class=""><div class="modal-header"><h3>提示信息</h3></div>'
+ '<div class="modal-body"><div class=" span5">'+content+'</div></div>'
+ '<div class="modal-footer"><a href="javascript:void(0);" class="btn btn-primary confirm_yes">确定</a></div></div>';
return HTML;
}
}
this.each(function() {
settings.url = $(this).attr('rel');
if(settings.url == '')
{
alert('参数错误');
}
methods.msg();
});
};
})( jQuery );
</script>

View File

@ -0,0 +1,10 @@
<?php
namespace Reference\Event;
interface ReferenceEvent
{
public function checkReferenceParam(\Zend_EventManager_Event $e);
public function processReferenceData(\Zend_EventManager_Event $e);
}

View File

@ -0,0 +1,61 @@
<?php
namespace Reference\Handler;
use Helpers\View as view;
use Helpers\dbh;
//事件中存在的操作
class ReferenceHandler implements \Reference\Event\ReferenceEvent
{
private $db; //传入PDO对象误
private $config; //全局配置
public $tbl_maillog = ""; //邮件日志表
function __construct($db = NULL)
{
if(empty($db))
{
$this->db = \Zend_Registry::get('db');
}else{
$this->db = $db;
}
$this->config = \Zend_Registry::get('config');
}
public function checkReferenceParam(\Zend_EventManager_Event $e)
{
$data = $e->getParam('data');
if(!is_array($data))
{
return "参数错误";
}
if(empty($data["title"]))
{
return "请输入标题";
}
if(empty($data['reference']))
{
return "请输入前台引用方式,并且唯一";
}
return true;
}
public function processReferenceData(\Zend_EventManager_Event $e)
{
$data = $e->getParam('data');
if(empty($data['attid']))
{
$data['attid'] = 0;
}
return $data;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace Reference\Listener;
use Reference\Handler\ReferenceHandler;
class ReferenceListener implements \Zend_EventManager_ListenerAggregate
{
private $event;
function __construct()
{
$this->event = new \Zend_EventManager_EventManager();
}
public function attach(\Zend_EventManager_EventCollection $events)
{
$Handler = new ReferenceHandler();
$events->attach('submit.checkParam', array($Handler, 'checkReferenceParam'), 100);
$events->attach('submit.processData', array($Handler, 'processReferenceData'), 100);
}
public function detach(\Zend_EventManager_EventCollection $events)
{
}
}

View File

@ -0,0 +1,174 @@
<?php
namespace Reference;
use \Helpers\View as view;
use \Helpers\dbh;
use \Reference\Listener\ReferenceListener;
use \Files\Files;
class Reference
{
private $db; //传入PDO对象.
private $config; //站点设置
protected $events = NULL;
public $table;
function __construct($db = NULL,$mail = NULL)
{
if(empty($db))
{
$this->db = \Zend_Registry::get('db');
}else{
$this->db = $db;
}
$this->config = \Zend_Registry::get('config');
$Listener = new ReferenceListener();
@$this->events()->attachAggregate($Listener);
$this->table = new \Helpers\Table();
}
public function events(\Zend_EventManager_EventCollection $events = NULL)
{
if ($events !== NULL) {
$this->events = $events;
} elseif ($this->events === NULL) {
$this->events = new \Zend_EventManager_EventManager(__CLASS__);
}
return $this->events;
}
public function reference($id = 0)
{
$data = $this->getReferenceParam();
$params = compact('data');
$results = $this->events()->trigger('submit.checkParam', $this, $params);
$cache_data = $results->bottom();
if($cache_data !== true)
{
return $cache_data;
}
$results = $this->events()->trigger('submit.processData', $this, $params);
$data = $results->bottom();
unset($data['submit']);
$dbh = new dbh();
if(empty($id))
{
$id = $dbh->insert($this->table->reference,$data,true);
}else{
if(!$dbh->update($this->table->reference,$data," id=$id ",true))
{
return "修改失败!请重试";
}
}
if(!empty($id) && is_numeric($id))
{
return true;
}else{
return "修改失败";
}
}
//获得参数
public function getReferenceParam(\Zend_Controller_Request_Abstract $request = NULL)
{
$request = new \Zend_Controller_Request_Http();
$data = array(
'reference'=>$request->getParam('reference'),
'link'=>$request->getParam('link'),
'publisher'=>$request->getParam('publisher'),
'year' => $request->getParam('year'),
'title' => $request->getParam('title'),
'bibtex' => $request->getParam('bibtex'),
'attid' => $request->getParam('attid')
);
return $data;
}
//上传文献PDF
public function uploadReferencePdf($file)
{
$files = new Files();
$file_info = $files->upload($file,'reference/',true);
if(isset($file_info['error']) && !empty($file_info['error']))
{
return array("error" => $file_info['error']);
}
$file_data = array(
'filename' => $file_info['file_url'],
'filetype' => 'reference',
'filedesc' => $file_info['file_mime'],
'userid' => view::User('id'),
'filesize' => $file_info['file_size'],
'realname' => $file_info['realname']
);
$dbh = new dbh();
$file_id = $dbh->insert($this->table->attachments,$file_data,true);
$file_data['id'] = $file_id;
return $file_data;
}
//删除文献文件
public function deleteReferenceAttchment($attid)
{
if(empty($attid) || !is_numeric($attid))
{
return array("error"=>"参数错误");
}
$files = new Files();
$status = $files->delete($attid);
if($status !== true)
{
return array("error"=>$status);
}else{
return array("success"=>1);
}
}
//所有文献
public function fetchReferences()
{
$sql = "SELECT * FROM {$this->table->reference} ORDER BY id DESC";
$rs = $this->db->query($sql);
return $rs->fetchAll();
}
//单条文献的信息
public function getOneReferenceData($id)
{
if(empty($id) || !is_numeric($id))
{
return false;
}
$sql = "SELECT * FROM {$this->table->reference} WHERE id=$id LIMIT 1";
$rs = $this->db->query($sql);
$row = $rs->fetch();
$files = new Files();
$attfile = $files->getOne($row['attid']);
$row['file'] = $attfile;
return $row;
}
}