merge qinghaihu branch, 引入文档管理功能

This commit is contained in:
wlx 2012-05-04 16:37:28 +00:00
parent ead99cf535
commit e01020a9ac
4 changed files with 542 additions and 1 deletions

View File

@ -2515,7 +2515,252 @@ class AuthorController extends Zend_Controller_Action
}
}
}
//文档管理
function documentAction(){
$ac = $this->_request->getParam('ac');
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$u_id = $user->id;
}
if(empty($ac) || $ac == 'list' || $ac=='search')
{
$wheresql = "";
$keyword = $this->_request->getParam('q');
if($ac=='search' && !empty($keyword))
{
$this->view->q = $keyword;
$search = new Search($keyword);
$wheresql = $search->sql_expr(array("md.title"));
}
if(!empty($wheresql))
{
$wheresql = " AND ".$wheresql;
}
$sql = "select count(att.id) as aid,md.title,md.uuid from metadata md
LEFT JOIN mdauthor a ON a.uuid=md.uuid
LEFT JOIN mdattach att ON att.uuid=md.uuid
WHERE a.status>=1 AND a.userid=? $wheresql
GROUP BY md.title,md.uuid";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
if($ac=='view')
{
$uuid = $this->_request->getParam('uuid');
if(empty($uuid) || !preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
$this->view->error = "参数有误!";
return true;
}
$sql = "SELECT att.*,md.title,md.uuid FROM mdattach mda
LEFT JOIN attachments att ON mda.id=att.id
LEFT JOIN metadata md ON mda.uuid=md.uuid
LEFT JOIN users u ON att.userid=u.id";
$sth = $this->db->prepare($sql);
$sth->execute(array());
$rows = $sth->fetchAll();
$this->view->info=$rows;
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
$this->_helper->viewRenderer('document-view');
}
if($ac == 'del')
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
(int)$id = $this->_request->getParam('id');
$uuid = $this->_request->getParam('uuid');
if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
exit();
}
$info = $this->getFileinfo($id);
$filepath = $dataFilePath.$info['filename'];
try{
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$userid = $user->id;
$sql_mdattach = "delete from mdattach where uuid='$uuid' and id='$id'";
$sql = "delete from attachments where id='$id' and userid='$userid'";
if($this->db->exec($sql_mdattach)>0 && $this->db->exec($sql)>0)
{
@unlink($filepath);
echo "ok";
}
}
}catch(Exception $e){}
//不输出任何错误
}//删除
if($ac=='upload')
{
$submit = $this->_request->getParam('submit');
if(empty($submit))
{
$uuid = $this->_request->getParam('uuid');
$this->view->uuid=$uuid;
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer('document-upload');
return true;
}
else
{
$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'];
$sql = "insert into mdattach (uuid,id) values ('$uuid','$attid')";
if($this->db->exec($sql))
{
$msg['html'] = $realname.'['. round($filesize/1024,2) .' kb]<input type="hidden" name="atts[]" value="'.$attid.'" /><div class="cancel"><a href="javascript:;" id="deletebtn_'.$attid.'"><img border="0" src="/static/js/uploadify/cancel.png" /></a></div>';
echo Zend_Json::encode($msg);
exit();
}else{
$msg['error'] = '附件上传失败:写入附件表出错';
@unlink($filename);
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();
}
}
}//文件上传
if($ac == 'download')
{
(int)$id = $this->_request->getParam('id');
$sql = "select * from attachments where id='$id'";
$re = $this->db->query($sql);
$row = $re->fetch();
$file = new files();
$fullPath = $this->view->config->upload.$row['filename'];
// Parse Info / Get Extension
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
// Determine Content Type
switch ($ext) {
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
$content=file_get_contents($fullPath);
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$this->getResponse()->setHeader('Content-Type', 'application/octet-stream')
->setHeader('Content-Disposition','attachment; filename="'.basename($fullPath).'"')
->setHeader('Content-Length', $fsize)
->setHeader('Content-Type','application/force-download')
->setHeader('Content-Type','application/download')
->setHeader('Content-Type',$ctype)
->setHeader('Content-Description','File Transfer')
->setHeader('Content-Transfer-Encoding','binary')
->setHeader('Expires',0)
->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0')
->setHeader('Pragma','public')
->setBody($content);
}//文件下载
}//文档管理
public function getFileinfo($id){
$sql = "select * from attachments where id='$id'";
$re= $this->db->query($sql);
$row= $re->fetch();
return $row;
}
//成为作者后的后继处理工作
private function author_first($uuid,$author)
{

View File

@ -0,0 +1,134 @@
<!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="/static/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="wapper">
<form id='datafiles'>
<?php if(!empty($this->uuid))
{
?>
<input type="hidden" name="uuid" value="<?php echo $this->uuid;?>" />
<p>
<label>数据上传:</label>
<div><input id="file_upload" name="Filedata" type="file" /></div>
<input type="button" class="btn btn-small" onclick="$('#file_upload').uploadifyUpload();" value="上传" />
<div id="datalist"></div>
</p>
文件上传后会自动保存,不需要重复提交
<?php }else{
echo "参数错误!";
}?>
</form>
</div>
<!-- //页面内容 -->
<script>
<?php if(!empty($this->uuid))
{
?>
$(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/document/ac/upload',
'cancelImg' : '/static/js/uploadify/cancel.png',
'folder' : '/uploads',
'sizeLimit' : 52428800,
'queueSizeLimit' : 10,
'multi' : true,
'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 Submit(){
$.ajax({
'type':"POST",
'url':'/submit/upload/',
'data':'ac=submit&'+$('#datafiles').serialize(),
'success':function(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{$.colorbox({'innerWidth':'50%','html':data.error});}
if(typeof(data.deleted)!='undefined')
{$('#list_'+data.deleted).fadeOut("slow",function(){$(this).remove();});}
if(typeof(data.commited)!='undefined')
{$('#changelog').val('');$('#commit_submit').attr('onclick','');}
}
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:'/submit/upload/ac/del/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;
}
<?php } ?>
$('#wapper').width($('.body').width()-$('#sidebar').width()-20);
</script>
</body>
</html>

View File

@ -0,0 +1,107 @@
<?php
$this->headTitle($this->config->title->site);
$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->headLink()->appendStylesheet('/css/author.css');
$this->headLink()->appendStylesheet('/css/colorbox.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/author">数据作者</a>');
$this->breadcrumb('我的数据');
$this->breadcrumb()->setSeparator(' > ');
?>
<!-- 左侧导航 -->
<div id='sidebar'>
<div id='leftnavi'>
<?= $this->partial('author/navi.phtml'); ?>
</div>
</div>
<!-- //左侧导航 -->
<!-- 页面内容 -->
<div id="wapper">
<?php
if(!empty($this->error))
{
echo $this->error;
}
?>
<div class="pagetitle">
<?php echo $this->info[0]['title'] ;?> (共 <?php echo count($this->info);?> 个文档)
</div>
<div id="datalist">
<?php
if (count($this->paginator)):
echo "<ul>";
$autoindex=0;
foreach ($this->paginator as $item):
$autoindex++;?>
<li id="data_<?php echo $item['id'];?>">
<p><input type="text" readonly="readonly" value="<?php echo $item['realname']; ?>" id="file_<?php echo $item['id'];?>" class="half" />
<button type="button" id="btn_<?php echo $item['id'];?>" onclick="Submit(<?php echo $item['id'];?>)" disabled="disabled" style="display:none;">提交</button>
(<?php echo round($item['filesize']/1024,2)?>KB)</p>
<p><a href="javascript:;" onclick="del(<?php echo $item['id'];?>)">删除</a> |
<a href="javascript:;" onclick="edit(<?php echo $item['id'];?>)">改名</a> |
<a href="/author/document/ac/download/id/<?php echo $item['id'];?>" target="_blank">下载</a></p>
</li>
<?php endforeach;
echo "</ul>";
endif; ?>
<div class="pagenavi"><?= $this->paginator; ?></div>
</div>
</div>
<!-- //页面内容 -->
<script>
function edit(id){
$('#file_'+id).removeAttr('readonly');
$('#btn_'+id).removeAttr('disabled');
$('#btn_'+id).fadeIn();
}
function Submit(id){
$.ajax({
'type':"POST",
'url':'/submit/files/ac/editname',
'data':'id='+id+'&name='+$('#file_'+id).val(),
'datatype':'json',
'success':function(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{$.colorbox({'innerWidth':'50%','html':data.error});}
if(typeof(data.success)!='undefined' && data.success==1)
{
$.colorbox({'innerWidth':'50%','html':'修改成功'});
$('#btn_'+id).fadeOut();
$('#file_'+id).attr('readonly','readonly');
}
}
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 del(id){
$.ajax({
type:"POST",
url:'/author/document/ac/del/uuid/<?php echo $this->info[0]['uuid']; ?>/id/'+id,
data:'',
success:function(html){
$('#data_'+id).fadeOut();
},
timeout:10000,
error:function(){
alert('删除失败,请重试');
}
});
}
</script>

View File

@ -0,0 +1,55 @@
<?php
$this->headTitle($this->config->title->site);
$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->headLink()->appendStylesheet('/css/author.css');
$this->headLink()->appendStylesheet('/css/colorbox.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/author">数据作者</a>');
$this->breadcrumb('我的数据');
$this->breadcrumb()->setSeparator(' > ');
?>
<!-- 左侧导航 -->
<div id='sidebar'>
<div id='leftnavi'>
<?= $this->partial('author/navi.phtml'); ?>
</div>
</div>
<!-- //左侧导航 -->
<!-- 页面内容 -->
<div id="wapper">
<form id="datasearch" class="search_form" action="/author/document/ac/search">
<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 id="datalist">
<?php
if (count($this->paginator)):
echo "<ul>";
$autoindex=0;
foreach ($this->paginator as $item):
$autoindex++;?>
<li>
<p><a href="/data/<?php echo $item['uuid'];?>" target="_blank"><?php echo $item['title'];?></a></p>
<p>文档数: <?php echo $item['aid'];?>
<a href="/author/document/ac/view/uuid/<?php echo $item['uuid'];?>">查看详细</a> |
<a class="iframe" href="/author/document/ac/upload/uuid/<?php echo $item['uuid']; ?>">文件上传</a> |
<a href="/service/attach/zip/<?php echo $item['uuid'];?>">打包下载</a>
</p>
</li>
<?php endforeach;
echo "</ul>";
endif; ?>
<div class="pagenavi"><?= $this->paginator; ?></div>
</div>
</div>
<!-- //页面内容 -->
<script>
$(".iframe").colorbox({iframe:true, width:"80%", height:"80%"});
</script>