修改了元数据附件解除关联的操作逻辑,增加了附件删除时的判断

This commit is contained in:
Li Jianxuan 2012-05-24 08:05:08 +00:00
parent 438f831468
commit 426d442bc7
3 changed files with 130 additions and 37 deletions

View File

@ -1215,6 +1215,7 @@ class Admin_DataController extends Zend_Controller_Action
$down = $this->_request->getParam('down');
$uuid = $this->_request->getParam('uuid');
$mdtitle = $this->_request->getParam('mdtitle');
$mdattdel = $this->_request->getParam('mdattdel');
if(!empty($uuid)&&!empty($mdtitle))
{
@ -1230,6 +1231,28 @@ class Admin_DataController extends Zend_Controller_Action
$this->view->uuid = $uuid;
}
}//附件添加
else if($mdattdel)
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$sql = "delete from mdattach where uuid=? AND id=?";
$sth = $this->db->prepare($sql);
$ds = $sth->execute(array($uuid,$mdattdel));
if($ds)
{
$data = array("status"=>1); //操作状态代码 : 1=>成功 2=>失败
$this->jsonexit($data);
return true;
}else{
$data = array("error"=>"处理中出现错误");
$this->jsonexit($data);
return true;
}
}
else if($delete)
{
@ -1243,6 +1266,29 @@ class Admin_DataController extends Zend_Controller_Action
$filepath = $basepath.$info['filename'];
$sql = "SELECT * FROM mdattach WHERE id=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($delete));
$rows = $sth->fetchAll();
if(count($rows)>0)
{
$this->messenger->addMessage('删除失败!该文件有对应元数据附件信息,不能直接删除');
$this->_redirect("/admin/data/attachments/");
}
$sql = "SELECT * FROM mdreviewattach WHERE attachid=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($delete));
$rows = $sth->fetchAll();
if(count($rows)>0)
{
$this->messenger->addMessage('删除失败!该文件有对应评审附件信息,不能直接删除');
$this->_redirect("/admin/data/attachments/");
}
if(unlink($filepath))
{
$sql = "delete from attachments where id='$delete'";
@ -1499,7 +1545,8 @@ class Admin_DataController extends Zend_Controller_Action
$userid = $user->id;
$sql = "select m.*,a.*,d.title from mdattach m
left join attachments a on m.id = a.id
left join metadata d on m.uuid=d.uuid where m.uuid='$uuid'";
left join metadata d on m.uuid=d.uuid where m.uuid='$uuid'
ORDER BY a.ts_created ASC";
$rs = $this->db->query($sql);
$atts = $rs->fetchAll();
@ -1539,5 +1586,17 @@ class Admin_DataController extends Zend_Controller_Action
$iso=new ISO19115();
$iso->saveDB($this->db,$xml);
}
/*
* jsonexit() 退出并返回json数据
*
* param array $data 要返回的JSON数据可以是任意数组
*
* return JSON-response
*/
public function jsonexit($data){
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK));
return true;
}//jsonexit() 退出并返回json数据
}

View File

@ -8,7 +8,9 @@
$this->breadcrumb('数据管理');
$this->breadcrumb()->setSeparator(' > ');
$this->headLink()->appendStylesheet('/static/js/uploadify/uploadify.css');
$this->headScript()->appendFile('/js/jquery-1.6.4.min.js');
$this->headScript()->appendFile('/static/js/jquery-1.7.2.min.js');
$this->headScript()->appendFile('/js/jquery.colorbox-min.js');
$this->headLink()->appendStylesheet('/css/colorbox.css');
$this->headScript()->appendFile('/static/js/uploadify/swfobject.js');
$this->headScript()->appendFile('/static/js/uploadify/jquery.uploadify.v2.1.4.min.js');
?>
@ -64,17 +66,21 @@ $('#file_upload').uploadify({
alert(errorObj.type + ' Error: ' + errorObj.info);
}
});
function deleteatt(attid){
function deleteatt(id){
$.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" />');
}
'type': "POST",
'url': "/admin/data/attachments/",
'data': 'uuid=<?php echo $this->uuid?>&mdattdel='+id,
'success': function(data){
if(data==null){Alert('遇到错误,请重试');return false;}
if(data.error!=null){Alert(data.error);return false;}
if(data.status==1){$('#uploadedItem_'+id).fadeOut("slow");}
},
'beforeSend':function(){},
'complete':function(){},
'timeout': 20000,
'dataType': 'json',
'error': function(){Alert('处理中出现问题,请重试');}
});
}
@ -94,4 +100,7 @@ $('#file_upload').uploadify({
}
});
});
function Alert(html){
$.colorbox({'innerWidth':'50%','html':'<h4>'+html+'</h4>'});
}
</script>

View File

@ -5,6 +5,9 @@
$this->headLink()->appendStylesheet('/css/admin.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin">后台首页</a>');
$this->headScript()->appendFile('/static/js/jquery-1.7.2.min.js');
$this->headScript()->appendFile('/js/jquery.colorbox-min.js');
$this->headLink()->appendStylesheet('/css/colorbox.css');
$this->breadcrumb('数据管理');
$this->breadcrumb()->setSeparator(' > ');
?>
@ -44,14 +47,14 @@
{
if($v['filesize']<1048576) $v['filesize'] = round(($v['filesize']/1024),2).'KB'; else $v['filesize'] = round(($v['filesize']/1024/1024),2).'MB';
echo '
<tr>
<tr id="att_'.$v['id'].'">
<td>'.$v['realname'].'</td>
<td>'.$v['filetype'].'</td>
<td>'.$v['filesize'].'</td>
<td>'.$v['downtimes'].'</td>
<td>'.date('Y-m-d H:i:s',strtotime($v['ts_created'])).'</td>
<td>
<a href="/admin/data/attachments/" onclick="return confirm(\'是否确定删除该附件?\')">从此元数据中移除</a>
<a href="javascript:;" onclick="delmdatt('.$v['id'].')">从此元数据中移除</a>
<a href="/service/attach/id/'.$v['id'].'">下载</a>
</td>
</tr>';
@ -59,3 +62,25 @@
?>
</tbody></table>
</div>
<script>
function delmdatt(id){
$.ajax({
'type': "POST",
'url': "/admin/data/attachments/",
'data': 'uuid=<?php echo $this->uuid?>&mdattdel='+id,
'success': function(data){
if(data==null){Alert('遇到错误,请重试');return false;}
if(data.error!=null){Alert(data.error);return false;}
if(data.status==1){$('#att_'+id).fadeOut("slow");}
},
'beforeSend':function(){},
'complete':function(){},
'timeout': 20000,
'dataType': 'json',
'error': function(){Alert('处理中出现问题,请重试');}
});
}
function Alert(html){
$.colorbox({'innerWidth':'50%','html':'<h4>'+html+'</h4>'});
}
</script>