2011-11-03 09:52:47 +00:00
|
|
|
<?php
|
|
|
|
class UploadController extends Zend_Controller_Action {
|
|
|
|
function preDispatch()
|
|
|
|
{
|
|
|
|
$this->db=Zend_Registry::get('db');
|
|
|
|
$this->view->config = Zend_Registry::get('config');
|
|
|
|
}
|
|
|
|
|
|
|
|
function indexAction() {
|
|
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
$this->_helper->viewRenderer->setNoRender();
|
2011-11-04 08:01:27 +00:00
|
|
|
|
2011-11-03 09:52:47 +00:00
|
|
|
try{
|
|
|
|
$auth = Zend_Auth::getInstance();
|
|
|
|
if($auth->hasIdentity())
|
|
|
|
{
|
|
|
|
$user = $auth->getIdentity();
|
|
|
|
$userid = $user->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(empty($userid)||!is_numeric($userid)){
|
2011-11-04 08:01:27 +00:00
|
|
|
$msg['error'] = "请先登录";
|
|
|
|
echo Zend_Json::encode($msg);
|
2011-11-03 09:52:47 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
$files=new files();
|
|
|
|
$msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],'reviewatt');
|
|
|
|
|
|
|
|
if(empty($msg['error']))
|
|
|
|
{
|
2011-11-04 08:01:27 +00:00
|
|
|
$msg['error']="";
|
2011-11-03 09:52:47 +00:00
|
|
|
$filename = $msg['db_path'];
|
|
|
|
$filesize = $msg['file_size'];
|
|
|
|
$filedesc = $this->_request->getParam('filedesc');
|
|
|
|
$filetype = $this->_request->getParam('dir');
|
|
|
|
$realname = $msg['realname'];
|
|
|
|
|
2011-11-04 08:01:27 +00:00
|
|
|
|
2011-11-03 09:52:47 +00:00
|
|
|
$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'];
|
2011-11-04 08:01:27 +00:00
|
|
|
$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>';
|
2011-11-03 09:52:47 +00:00
|
|
|
echo Zend_Json::encode($msg);
|
|
|
|
exit();
|
|
|
|
}else{
|
2011-11-04 08:01:27 +00:00
|
|
|
$msg['error'] = '附件上传失败:'.$msg['error'];
|
2011-11-03 09:52:47 +00:00
|
|
|
@unlink($filename);
|
2011-11-04 08:01:27 +00:00
|
|
|
echo Zend_Json::encode($msg);
|
|
|
|
exit();
|
2011-11-03 09:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}catch(Exception $e){
|
2011-11-04 08:01:27 +00:00
|
|
|
$msg['error'] = "错误:".$e->getMessage();
|
|
|
|
echo Zend_Json::encode($msg);
|
2011-11-03 09:52:47 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2011-11-04 08:01:27 +00:00
|
|
|
}//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;
|
|
|
|
}
|
2011-11-09 08:03:01 +00:00
|
|
|
|
2011-11-04 08:01:27 +00:00
|
|
|
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'";
|
2011-11-09 08:03:01 +00:00
|
|
|
if($this->db->exec($sql)>0)
|
2011-11-04 08:01:27 +00:00
|
|
|
{
|
|
|
|
@unlink($filepath);
|
|
|
|
}
|
|
|
|
}
|
2011-11-09 08:03:01 +00:00
|
|
|
|
2011-11-04 08:01:27 +00:00
|
|
|
}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();
|
|
|
|
}
|
|
|
|
//不输出错误
|
|
|
|
}//获取附件
|
2011-11-03 09:52:47 +00:00
|
|
|
|
|
|
|
}
|