修改了reviewAction,使用ajax表单优化用户操作,新增了uploadcontroller用于ajax上传文件处理
This commit is contained in:
parent
85fabbd5b0
commit
a8809be07d
|
@ -143,153 +143,6 @@ class ReviewController extends Zend_Controller_Action
|
|||
$row = $rs->fetch();
|
||||
$this->view->review = $row;
|
||||
}
|
||||
|
||||
$submit = $this->_request->getParam('submit');
|
||||
|
||||
$conclusion = $this->_request->getParam('conclusion');
|
||||
$mdcomment = $this->replace(trim($this->_request->getParam('mdcomment')));
|
||||
$datacomment = $this->replace(trim($this->_request->getParam('datacomment')));
|
||||
$editorcomment = $this->replace(trim($this->_request->getParam('editorcomment')));
|
||||
|
||||
if(!empty($submit)){
|
||||
|
||||
$redirectlink='/review/review/uuid/'.$uuid.'/';
|
||||
|
||||
if($md['status']>4)
|
||||
{
|
||||
$this->messenger->addMessage('该数据已经通过评审,不能再发表评审意见,如需提交问题,请联系数据管理员');
|
||||
$this->_redirect($redirectlink);
|
||||
}
|
||||
if($md['status']<1)
|
||||
{
|
||||
$this->messenger->addMessage('已被数据中心接收的数据才可以进行评审');
|
||||
$this->_redirect($redirectlink);
|
||||
}
|
||||
|
||||
$auth = Zend_Auth::getInstance();
|
||||
if($auth->hasIdentity())
|
||||
{
|
||||
$user = $auth->getIdentity();
|
||||
$userid = $user->id;
|
||||
$sql = "select id,userid,status from mdreview where userid='$userid' and uuid='$uuid'";
|
||||
$rs = $this->db->query($sql);
|
||||
$row = $rs->fetch();
|
||||
if($row['id']!='' && $row['status']>-1)
|
||||
{
|
||||
$this->messenger->addMessage('您已经对该元数据发表过评审了');
|
||||
$this->_redirect($redirectlink);
|
||||
}
|
||||
}else{
|
||||
$this->messenger->addMessage('读取用户信息失败,请刷新页面后重试 :(');
|
||||
$this->_redirect($redirectlink);
|
||||
}
|
||||
|
||||
if(empty($conclusion))
|
||||
{
|
||||
$this->messenger->addMessage('请选择评审意见');
|
||||
$this->_redirect($redirectlink);
|
||||
}
|
||||
if( !is_numeric($conclusion) || !in_array($conclusion,array(-1,1,2,3)) )
|
||||
{
|
||||
$this->messenger->addMessage('参数有误,请刷新页面 :(');
|
||||
$this->_redirect($redirectlink);
|
||||
}
|
||||
if(empty($mdcomment) )
|
||||
{
|
||||
$this->messenger->addMessage('请填写元数据意见后再发布 :(');
|
||||
$this->_redirect($redirectlink);
|
||||
}
|
||||
if(!empty($_FILES['Filedata']['name']))
|
||||
{
|
||||
$files=new files();
|
||||
$msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],'reviewatt');
|
||||
|
||||
if(empty($msg['error']))
|
||||
{
|
||||
$filename = $msg['db_path'];
|
||||
$filesize = $msg['file_size'];
|
||||
$filedesc = $this->_request->getParam('filedesc');
|
||||
$filetype = $this->_request->getParam('dir');
|
||||
|
||||
$sql = "insert into attachments (filename,filetype,filedesc,userid,filesize) values ('$filename','reviewatt','$filedesc','$userid','$filesize') RETURNING id";
|
||||
$sth = $this->db->prepare($sql);
|
||||
$sth->execute();
|
||||
$att = $sth->fetch(PDO::FETCH_ASSOC);
|
||||
$attid = $att['id'];
|
||||
|
||||
}else{
|
||||
$this->messenger->addMessage('附件上传失败:'.$msg['error']);
|
||||
@unlink($filename);
|
||||
$this->_redirect($redirectlink);
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
|
||||
if($row['status']<0)
|
||||
{
|
||||
$sql = "delete from mdreview where id='{$row['id']}'";
|
||||
if($this->db->exec($sql)<1)
|
||||
{
|
||||
$this->messenger->addMessage('处理出错,请重试');
|
||||
@unlink($filename);
|
||||
$this->_redirect($redirectlink);
|
||||
}
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'userid' => $userid,
|
||||
'uuid' => $uuid,
|
||||
'mdcomment' => $mdcomment,
|
||||
'ts_created' => 'now()',
|
||||
'datacomment' => $datacomment,
|
||||
'editorcomment' => $editorcomment,
|
||||
'conclusion' => $conclusion
|
||||
);
|
||||
|
||||
|
||||
$sql = "select id from mdexpertreview where id='$userid' and uuid='$uuid'";
|
||||
$rs = $this->db->query($sql);
|
||||
$row = $rs->fetch();
|
||||
|
||||
if($row['id']!='')
|
||||
{
|
||||
$data['is_expert'] = 'true';
|
||||
}
|
||||
|
||||
$keys = array();
|
||||
$values = array();
|
||||
foreach ($data as $k=>$v)
|
||||
{
|
||||
$keys[]=$k;
|
||||
$values[]=$v;
|
||||
}
|
||||
|
||||
$keys = join(",",$keys);
|
||||
$values = "'".join("','",$values)."'";
|
||||
|
||||
$sql = "insert into mdreview ($keys) values ($values) RETURNING id";
|
||||
$sth = $this->db->prepare($sql);
|
||||
$sth->execute();
|
||||
$review = $sth->fetch(PDO::FETCH_ASSOC);
|
||||
$reviewid=$review['id'];
|
||||
|
||||
if(!empty($_FILES['Filedata']['name']))
|
||||
{
|
||||
$sql = "insert into mdreviewattach (attachid,reviewid) values ('$attid','$reviewid')";
|
||||
$this->db->exec($sql);
|
||||
}
|
||||
|
||||
$this->messenger->addMessage('提交成功');
|
||||
$this->_redirect($redirectlink);
|
||||
|
||||
}catch (Exception $e){
|
||||
|
||||
$this->messenger->addMessage('提交失败,请重试'.$sql.'aa'.$review['id'].$e->getMessage());
|
||||
$this->_redirect($redirectlink);
|
||||
|
||||
}
|
||||
}
|
||||
}//reviewAction()
|
||||
|
||||
function allreviewAction(){
|
||||
|
@ -340,6 +193,7 @@ class ReviewController extends Zend_Controller_Action
|
|||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
$do = $this->_request->getParam('do');
|
||||
$conclusion = $this->_request->getParam('conclusion');
|
||||
$mdcomment = $this->replace(trim($this->_request->getParam('mdcomment')));
|
||||
$datacomment = $this->replace(trim($this->_request->getParam('datacomment')));
|
||||
|
@ -392,7 +246,7 @@ class ReviewController extends Zend_Controller_Action
|
|||
}
|
||||
if(empty($mdcomment) )
|
||||
{
|
||||
echo '<div class="box box-info">请填写元数据意见后再存草稿 :(</div>';
|
||||
echo '<div class="box box-info">请填写元数据意见 :(</div>';
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -419,6 +273,11 @@ class ReviewController extends Zend_Controller_Action
|
|||
'status' => -1
|
||||
);
|
||||
|
||||
if($do=='submit')
|
||||
{
|
||||
$data['status'] = 0;
|
||||
}
|
||||
|
||||
|
||||
$sql = "select id from mdexpertreview where id='$userid' and uuid='$uuid'";
|
||||
$rs = $this->db->query($sql);
|
||||
|
@ -444,8 +303,29 @@ class ReviewController extends Zend_Controller_Action
|
|||
$sth = $this->db->prepare($sql);
|
||||
if($sth->execute())
|
||||
{
|
||||
echo '<div class="box box-success">保存成功!</div>';
|
||||
if($_POST['atts'])
|
||||
{
|
||||
$review = $sth->fetch(PDO::FETCH_ASSOC);
|
||||
$reviewid=$review['id'];
|
||||
try{
|
||||
foreach($_POST['atts'] as $v)
|
||||
{
|
||||
$sql = "insert into mdreviewattach (attachid,reviewid) values ('$v','$reviewid')";
|
||||
$this->db->exec($sql);
|
||||
}
|
||||
echo '<div class="box box-success">保存成功!';
|
||||
if($data['status']>=0)
|
||||
{
|
||||
echo '<script>$("#postcomment").remove();</script>';
|
||||
}
|
||||
echo "</div>";
|
||||
exit();
|
||||
}catch(Exception $e){
|
||||
echo '<div class="box box-error">保存草稿出错,请稍后再试!</div>';
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
echo '<div class="box box-error">保存草稿出错,请稍后再试!</div>';
|
||||
exit();
|
||||
|
|
|
@ -9,9 +9,9 @@ class UploadController extends Zend_Controller_Action {
|
|||
function indexAction() {
|
||||
$this->_helper->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
try{
|
||||
$auth = Zend_Auth::getInstance();
|
||||
|
||||
if($auth->hasIdentity())
|
||||
{
|
||||
$user = $auth->getIdentity();
|
||||
|
@ -19,7 +19,8 @@ class UploadController extends Zend_Controller_Action {
|
|||
}
|
||||
|
||||
if(empty($userid)||!is_numeric($userid)){
|
||||
echo "请先登录";
|
||||
$msg['error'] = "请先登录";
|
||||
echo Zend_Json::encode($msg);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -28,30 +29,106 @@ class UploadController extends Zend_Controller_Action {
|
|||
|
||||
if(empty($msg['error']))
|
||||
{
|
||||
$msg['error']="";
|
||||
$filename = $msg['db_path'];
|
||||
$filesize = $msg['file_size'];
|
||||
$filedesc = $this->_request->getParam('filedesc');
|
||||
$filetype = $this->_request->getParam('dir');
|
||||
$realname = $msg['realname'];
|
||||
|
||||
|
||||
$sql = "insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values ('$filename','reviewatt','$filedesc','$userid','$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.'[已完成]<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{
|
||||
$this->messenger->addMessage('附件上传失败:'.$msg['error']);
|
||||
$msg['error'] = '附件上传失败:'.$msg['error'];
|
||||
@unlink($filename);
|
||||
$this->_redirect($redirectlink);
|
||||
}
|
||||
|
||||
}catch(Exception $e){
|
||||
echo "错误:".$e->getMessage();
|
||||
echo Zend_Json::encode($msg);
|
||||
exit();
|
||||
}
|
||||
|
||||
}catch(Exception $e){
|
||||
$msg['error'] = "错误:".$e->getMessage();
|
||||
echo Zend_Json::encode($msg);
|
||||
exit();
|
||||
}
|
||||
|
||||
}//indexAction()
|
||||
|
||||
/*
|
||||
获得单个文件的信息
|
||||
return array row
|
||||
*/
|
||||
public function getFileinfo($id){
|
||||
$sql = "select * from attachments where id='$id'";
|
||||
$re= $this->db->query($sql);
|
||||
$row= $re->fetch();
|
||||
return $row;
|
||||
}
|
||||
|
||||
function delreviewattAction(){
|
||||
$this->_helper->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
$id = $this->_request->getParam('id');
|
||||
$basepath = $this->view->config->upload;
|
||||
$info = $this->getFileinfo($id);
|
||||
$filepath = $basepath.$info['filename'];
|
||||
|
||||
try{
|
||||
$auth = Zend_Auth::getInstance();
|
||||
if($auth->hasIdentity())
|
||||
{
|
||||
$user = $auth->getIdentity();
|
||||
$userid = $user->id;
|
||||
$sql = "delete from attachments where id='$id' and userid='$userid'";
|
||||
if($this->db->exec($sql))
|
||||
{
|
||||
@unlink($filepath);
|
||||
}
|
||||
}
|
||||
}catch(Exception $e){}
|
||||
//不输出任何错误
|
||||
}//删除评审附件
|
||||
|
||||
function getattsAction(){
|
||||
|
||||
$this->_helper->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
$id = $this->_request->getParam('id');
|
||||
|
||||
if($id!='')
|
||||
{
|
||||
$auth = Zend_Auth::getInstance();
|
||||
if($auth->hasIdentity())
|
||||
{
|
||||
$user = $auth->getIdentity();
|
||||
$userid = $user->id;
|
||||
$sql = "select att.realname,att.id from attachments att
|
||||
left join mdreviewattach ratt on att.id=ratt.attachid
|
||||
where ratt.reviewid=$id and att.userid=$userid";
|
||||
$rs = $this->db->query($sql);
|
||||
$atts = $rs->fetchAll();
|
||||
foreach($atts as $k=>$v)
|
||||
{
|
||||
$atts[$k]['html']=$v['realname'].'[已完成]<input type="hidden" name="atts[]" value="'.$v['id'].'" /><div class="cancel"><a href="javascript:;" id="deletebtn_'.$v['id'].'"><img border="0" src="/static/js/uploadify/cancel.png" /></a></div>';
|
||||
}
|
||||
echo Zend_Json::encode($atts);
|
||||
exit();
|
||||
}else
|
||||
{
|
||||
exit();
|
||||
}
|
||||
}else{
|
||||
exit();
|
||||
}
|
||||
//不输出错误
|
||||
}//获取附件
|
||||
|
||||
}
|
|
@ -4,8 +4,10 @@
|
|||
$this->headTitle('数据查看');
|
||||
$this->headTitle()->setSeparator(' - ');
|
||||
$this->headLink()->appendStylesheet('/css/mdreview.css');
|
||||
$this->headLink()->appendStylesheet('/static/js/uploadify/uploadify.css');
|
||||
$this->headScript()->appendFile('/js/jquery-1.6.4.min.js');
|
||||
$this->headScript()->appendFile('/js/pubfunc.js');
|
||||
$this->headScript()->appendFile('/static/js/uploadify/swfobject.js');
|
||||
$this->headScript()->appendFile('/static/js/uploadify/jquery.uploadify.v2.1.4.min.js');
|
||||
$this->breadcrumb('<a href="/">首页</a>');
|
||||
$this->breadcrumb('<a href="/review">'.$this->config->title->review.'</a>');
|
||||
$this->breadcrumb('评审元数据');
|
||||
|
@ -73,17 +75,24 @@
|
|||
<textarea id="editorcomment" class="small full" name="editorcomment"><?php echo $this->review['editorcomment'];?></textarea>
|
||||
</p>
|
||||
<p>
|
||||
评审附件:<br/>
|
||||
<input type="file" name="Filedata" class="half" autocomplete="on" /><br />
|
||||
评审附件:
|
||||
<ul id="datalist">
|
||||
</ul>
|
||||
<input id="file_upload" name="Filedata" type="file" />
|
||||
<input type="button" class="btn btn-small" onclick="$('#file_upload').uploadifyUpload()" value="上传" />
|
||||
<a href="javascript:void(0);" onclick="$('#showexts').toggle()">查看可上传的附件类型</a>
|
||||
<div id='showexts' style="display:none;">'doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2','gif', 'jpg', 'jpeg', 'png', 'bmp', 'pdf'</div>
|
||||
</p>
|
||||
<br />
|
||||
<p>
|
||||
<button class="btn btn-green" type="submit" onclick="return confirm('是否确定提交评审意见?')">提交</button>
|
||||
<button class="btn btn-green" type="button" id="submit" onclick="return confirm('是否确定提交评审意见?')">提交</button>
|
||||
<button class="btn btn-small" type="button" id="save">存草稿</button>
|
||||
<button class="btn btn-small" type="reset" id="reset" onclick="return confirm('是否确定重置已经填写的意见?')">重置</button>
|
||||
</p>
|
||||
<p id="infobox">
|
||||
<p>
|
||||
<label>注:评审意见提交之后不可更改,存草稿功能不能保存附件,请妥善保存附件。</label>
|
||||
</p>
|
||||
<p>
|
||||
<?php
|
||||
if($this->review['status']<0)
|
||||
{
|
||||
|
@ -91,10 +100,11 @@
|
|||
}
|
||||
?>
|
||||
</p>
|
||||
<p>
|
||||
<label>注:评审意见提交之后不可更改,存草稿功能不能保存附件,请妥善保存附件。</label>
|
||||
</p>
|
||||
</form>
|
||||
<p id="infobox">
|
||||
|
||||
</p>
|
||||
|
||||
<?php
|
||||
}
|
||||
}else
|
||||
|
@ -126,8 +136,68 @@
|
|||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" language="javascript">
|
||||
$(document).ready(function() {
|
||||
$('#file_upload').uploadify({
|
||||
'uploader' : '/static/js/uploadify/uploadify.swf',
|
||||
'scriptData' : {'PHPSESSID' : '<?php echo session_id(); ?>'},
|
||||
'script' : '/upload',
|
||||
'cancelImg' : '/static/js/uploadify/cancel.png',
|
||||
'folder' : '/uploads',
|
||||
'multi' : false,
|
||||
'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;
|
||||
}
|
||||
$('<li/>', {
|
||||
id:'uploadedItem_'+obj.attid,
|
||||
class:'uploadifyQueueItem',
|
||||
html: html
|
||||
}).appendTo('#datalist');
|
||||
$('#deletebtn_'+obj.attid).bind('click', function() {
|
||||
deleteatt(obj.attid);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function deleteatt(attid){
|
||||
$.ajax({
|
||||
type:"POST",
|
||||
url:'/upload/delreviewatt/id/'+attid,
|
||||
data:'',
|
||||
success:function(html){
|
||||
$('#uploadedItem_'+attid).remove();
|
||||
},
|
||||
beforeSend:function(){
|
||||
$('#deletebtn_'+attid).html('<img src="/images/11887177066.gif" />');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$.getJSON("/upload/getatts/id/<?php echo $this->review['id'];?>", function(data) {
|
||||
if(data.length>0)
|
||||
{
|
||||
$.each(data, function(key, val) {
|
||||
$('<li/>', {
|
||||
id:'uploadedItem_'+val['id'],
|
||||
class:'uploadifyQueueItem',
|
||||
html: val['html']
|
||||
}).appendTo('#datalist');
|
||||
$('#deletebtn_'+val['id']).bind('click', function() {
|
||||
deleteatt(val['id']);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
loadmdcomment(1);
|
||||
function loadmdcomment(page){var url="/review/allreview/uuid/<?php echo $md['uuid'];?>/";if(page!=''){url+='page/'+page;}
|
||||
$.ajax({type:"POST",url:url,data:'',success:function(html){$('#allcomments').html(html);},beforeSend:function(){$('#allcomments').html('<img src="/images/loading.gif" />正在加载...');}});}
|
||||
|
@ -140,12 +210,21 @@ $('.slideabletbox .title').click(
|
|||
$(this).prev('.title').find(".slidebtn").html('<img src="/images/slideup.png" />');
|
||||
;})
|
||||
});
|
||||
$('#save').click(function(){
|
||||
savereview();
|
||||
|
||||
$('#submit').click(function(){
|
||||
savereview(1);
|
||||
});
|
||||
|
||||
function savereview(){
|
||||
var url="/review/save/uuid/<?php echo $md['uuid'];?>/";
|
||||
$('#save').click(function(){
|
||||
savereview(0);
|
||||
});
|
||||
|
||||
function savereview(save){
|
||||
var url="/review/save/uuid/<?php echo $md['uuid'];?>";
|
||||
if(save>0)
|
||||
{
|
||||
url += "/do/submit";
|
||||
}
|
||||
var date = $('#postcomment').serialize();
|
||||
$.ajax({
|
||||
type:"POST",
|
||||
|
@ -154,7 +233,8 @@ function savereview(){
|
|||
success:function(html){
|
||||
$('#infobox').html(html);
|
||||
$('#save').html('存草稿');
|
||||
setTimeout("$('#save').removeAttr('disabled');$('.box').remove();",3000)
|
||||
setTimeout("$('#save').removeAttr('disabled');$('.box').remove();",3000);
|
||||
loadmdcomment(1);
|
||||
},
|
||||
beforeSend:function(){
|
||||
$('#save').attr('disabled','disabled');
|
||||
|
@ -162,6 +242,7 @@ function savereview(){
|
|||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php else: ?>
|
||||
|
|
Loading…
Reference in New Issue