为文献添加功能增加了附件上传功能,修改了之前的bug

This commit is contained in:
Li Jianxuan 2012-05-17 10:00:27 +00:00
parent 5888f81ba2
commit 6b2edc0adc
6 changed files with 234 additions and 52 deletions

View File

@ -2414,6 +2414,9 @@ class AuthorController extends Zend_Controller_Action
//添加文献信息
else if($ac == "add")
{
$submit = $this->_request->getParam('submit');
if(!empty($submit))
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
@ -2423,6 +2426,7 @@ class AuthorController extends Zend_Controller_Action
$uuid = $this->_request->getParam('uuid');
$ref=$this->_request->getParam('ref');
$reftype=$this->_request->getParam('reftype');
$url = $this->_request->getParam('url');
if(empty($uuid) || empty($ref) || !is_numeric($reftype))
{
$data = array("error"=>"参数错误");
@ -2449,7 +2453,7 @@ class AuthorController extends Zend_Controller_Action
{
$sql="insert into reference (reference,link) values(?,?)";
$sth = $this->db->prepare($sql);
$sth->execute(array(trim($ref),''));
$sth->execute(array(trim($ref),$url));
$sql="select id from reference where reference=?";
$sth = $this->db->prepare($sql);
$sth->execute(array(trim($ref)));
@ -2477,6 +2481,11 @@ class AuthorController extends Zend_Controller_Action
$this->jsonexit($data);
return true;
}
}else{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer('literature-add');
$this->view->uuid = $this->_request->getParam('uuid');
}
}//添加文献
//删除某个文献
@ -2521,8 +2530,59 @@ class AuthorController extends Zend_Controller_Action
return true;
}
}
//文献附件上传
else if($ac=='upload')
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$uuid = $this->_getParam('uuid');
try{
$files=new files();
$msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],'md');
if(empty($msg['error']))
{
$msg['error']="";
$filename = $msg['db_path'];
$filesize = $msg['file_size'];
$filedesc = $this->_request->getParam('filedesc');
$filetype = $msg['file_type'];
$realname = $msg['realname'];
$sql = "insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values ('$filename','$filetype','$filedesc','$u_id','$filesize','$realname') RETURNING id";
$sth = $this->db->prepare($sql);
$sth->execute();
$att = $sth->fetch(PDO::FETCH_ASSOC);
$msg['attid'] = $attid = $att['id'];
$msg['html'] = $realname.'['. round($filesize/1024,2) .' kb]<input type="hidden" name="url" value="'.$filename.'" /><div class="cancel"><a href="javascript:;" id="deletebtn_'.$attid.'" title="删除该文件"><img border="0" src="/static/js/uploadify/cancel.png" /></a></div>';
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 documentAction(){

View File

@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>数据上传</title>
<link rel="stylesheet" type="text/css" media="screen" href="/static/css/default.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/css/default.css" />
<script src='/static/js/jquery-1.7.2.min.js' type="text/javascript"></script>
<script type="text/javascript" src="/static/js/uploadify/swfobject.js"></script>
<script type="text/javascript" src="/static/js/uploadify/jquery.uploadify.v2.1.4.min.js"></script>
@ -111,7 +111,7 @@ function Submit(){
function deleteatt(attid){
$.ajax({
type:"POST",
url:'/submit/upload/ac/del/id/'+attid,
url:'/service/delreviewatt/id/'+attid,
data:'',
success:function(html){
$('#uploadedItem_'+attid).remove();

View File

@ -0,0 +1,133 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>数据上传</title>
<link rel="stylesheet" type="text/css" media="screen" href="/css/default.css" />
<script src='/static/js/jquery-1.7.2.min.js' type="text/javascript"></script>
<script type="text/javascript" src="/static/js/uploadify/swfobject.js"></script>
<script type="text/javascript" src="/static/js/uploadify/jquery.uploadify.v2.1.4.min.js"></script>
<script type="text/javascript" src="/js/jquery.colorbox-min.js"></script>
<link href="/css/author.css" media="screen" rel="stylesheet" type="text/css"/>
<link href="/static/js/uploadify/uploadify.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/css/colorbox.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<!-- 页面内容 -->
<div id="page">
<div id="wapper full">
<div id="addform">
<form id="literature-add">
<p>
<label>文献引用信息:</label><br />
<textarea class="full" style="height:40px;" id="ref" name="ref"></textarea><br />
<input type="hidden" name="uuid" value="<?php echo $this->uuid;?>" />
<input type="radio" id="reftype" name="reftype" value="0" checked />数据作者的文献
<input type="radio" id="reftype" name="reftype" value="1" />数据用户的文献<br />
<label>数据上传:</label>
<div><input id="file_upload" name="Filedata" type="file" /></div>
<div id="datalist"></div>
<input type="button" class="btn btn-small" onclick="return checksize();" value="上传" />
</p>
<p id="tips">
</p>
<p>
<br />
<input type="button" onclick="Submit()" id="commit_submit" class="btn btn-green big" value="提交"/>
</p>
</form>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('#file_upload').uploadify({
'uploader' : '/static/js/uploadify/uploadify.swf',
'scriptData': {'PHPSESSID' : '<?php echo session_id(); ?>','uuid':'<?php echo $this->uuid;?>','submit':'1'},
'script' : '/author/literature/ac/upload',
'cancelImg' : '/static/js/uploadify/cancel.png',
'folder' : '/uploads',
'sizeLimit' : 52428800,
'queueSizeLimit' : 1,
'multi' : false,
'auto' : false,
'displayData' : 'speed',
'buttonImg' : '/static/js/uploadify/selectfile.gif',
'onComplete' : function(event, ID, fileObj, response, data) {
var obj = jQuery.parseJSON(response);
if(obj.error=='')
{
html = obj.html;
}
else{html=uploadError(obj.error,obj.attid);}
$('<li/>', {
"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 checksize(){
if($("#datalist").has("li").length)
{
$('#tips').html('只能上传一个文档,如果需要更换,请先删除原来的文档');
}else{
$('#file_upload').uploadifyUpload();
}
}
function Submit(){
$.ajax({
'type':"POST",
'url':'/author/literature/ac/add',
'data':'submit=submit&'+$('#literature-add').serialize(),
'success':function(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{$.colorbox({'innerWidth':'50%','html':data.error});}
if(typeof(data.commited)!='undefined')
{$('#addform').html('添加成功!');setTimeout('parent.$.fn.colorbox.close();',2000);}
}
else{
$.colorbox({'innerWidth':'50%','html':'<img src="/images/alert_big_warning.png" /><h4>出现错误,请稍候再试</h4>'});
}
},
'timeout': 30000,
'error': function(){
$.colorbox({'innerWidth':'50%','html':'<img src="/images/alert_big_error.png" /><h4>处理中出现错误,请刷新页面后重试</h4>'});
}
});
}
function deleteatt(attid){
$.ajax({
type:"POST",
url:'/service/delreviewatt/id/'+attid,
data:'',
success:function(html){
$('#uploadedItem_'+attid).remove();
},
beforeSend:function(){
$('#deletebtn_'+attid).html('<img src="/images/11887177066.gif" />');
}
});
}
function uploadError(msg,id){
var html = msg+'<div class="cancel"><a href="javascript:;" id="deletebtn_'+id+'"><img border="0" src="/static/js/uploadify/cancel.png" /></a></div>';
return html;
}
</script>
</body>
</html>

View File

@ -44,7 +44,7 @@ $this->breadcrumb()->setSeparator(' > ');
<p><a href="/data/<?php echo $item['uuid'];?>" target="_blank"><?php echo $item['title'];?></a></p>
<p>共有数据文献<?php echo $item['c'];?>篇。
<a href="/author/literature/uuid/<?php echo $item['uuid'];?>">查看详细</a>
| <a onclick="$('#commit_submit').attr('onclick','commit(\'<?php echo $item['uuid'];?>\');');" href="#addform" class="more inline">添加文献</a>
| <a href="/author/literature/ac/add/uuid/<?php echo $item['uuid'];?>" class="more iframe">添加文献</a>
</p>
</li>
<?php endforeach;
@ -81,23 +81,13 @@ function action(ac,uuid){
}
});
}
$(".iframe").colorbox({iframe:true, width:"60%", height:"80%"});
$(".inline").colorbox({inline:true, width:"50%"});
function commit(id){
action('add&ref='+$('#ref').val()+'&reftype='+$('#reftype').val(),id);
}
</script>
<div class="colorbox" style="display:none;">
<div id="addform">
<form>
<p>
<label>文献引用信息:</label><br />
<textarea class="full" style="height:40px;" id="ref"></textarea>
<input type="radio" id="reftype" name="reftype" value="0" checked />数据作者的文献
<input type="radio" id="reftype" name="reftype" value="1" />数据用户的文献
</p>
<input type="button" onclick="" id="commit_submit" class="btn btn-green big" value="提交"/>
</form>
</div>
<div class="error"><img src="/images/alert_big_error.png" /><span></span></div>
<div class="ok"><img src="/images/alert_big_ok.png" /><span></span></div>
<div class="warning"><img src="/images/alert_big_warning.png" /><span></span></div>

View File

@ -4,6 +4,9 @@ $this->headTitle($this->config->title->author);
$this->headTitle()->setSeparator(' - ');
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
$this->headScript()->appendFile('/js/jquery.colorbox-min.js');
$this->headScript()->appendFile('/static/js/uploadify/swfobject.js');
$this->headScript()->appendFile('/static/js/uploadify/jquery.uploadify.v2.1.4.min.js');
$this->headLink()->appendStylesheet('/static/js/uploadify/uploadify.css');
$this->headLink()->appendStylesheet('/css/author.css');
$this->headLink()->appendStylesheet('/css/colorbox.css');
$this->breadcrumb('<a href="/">首页</a>');
@ -44,7 +47,7 @@ $this->breadcrumb()->setSeparator(' > ');
<p><a href="/data/<?php echo $item['uuid'];?>" target="_blank"><?php echo $item['title'];?></a>
<a href="/author/literature/uuid/<?php echo $item['uuid'];?>">查看详细</a>
|
<a onclick="$('#commit_submit').attr('onclick','commit(\'<?php echo $item['uuid'];?>\');');" href="#addform" class="more inline">添加文献</a>
<a href="/author/literature/ac/add/uuid/<?php echo $item['uuid'];?>" class="more iframe">添加文献</a>
</p>
</p>
<p><?php echo $item['reference'];?>
@ -62,6 +65,8 @@ $this->breadcrumb()->setSeparator(' > ');
<!-- //页面内容 -->
<script>
$('#wapper').width($('body').width()-300);
function action(ac,uuid){
$.ajax({
'type':"POST",
@ -87,23 +92,13 @@ function action(ac,uuid){
}
});
}
$(".iframe").colorbox({iframe:true, width:"60%", height:"80%"});
$(".inline").colorbox({inline:true, width:"50%"});
function commit(id){
action('add&ref='+$('#ref').val()+'&reftype='+$('#reftype').val(),id);
}
</script>
<div class="colorbox" style="display:none;">
<div id="addform">
<form>
<p>
<label>文献引用信息:</label><br />
<textarea class="full" style="height:40px;" id="ref"></textarea>
<input type="radio" id="reftype" name="reftype" value="0" checked />数据作者的文献
<input type="radio" id="reftype" name="reftype" value="1" />数据用户的文献
</p>
<input type="button" onclick="" id="commit_submit" class="btn btn-green big" value="提交"/>
</form>
</div>
<div class="error"><img src="/images/alert_big_error.png" /><span></span></div>
<div class="ok"><img src="/images/alert_big_ok.png" /><span></span></div>
<div class="warning"><img src="/images/alert_big_warning.png" /><span></span></div>

4
htdocs/static/js/jquery-1.7.2.min.js vendored Normal file

File diff suppressed because one or more lines are too long