#416 完善项目负责人的计划上传功能

This commit is contained in:
Li Jianxuan 2012-11-13 08:05:45 +00:00
parent 46c006ccea
commit d759c34417
2 changed files with 107 additions and 0 deletions

View File

@ -839,6 +839,11 @@ class HeiheController extends DataController
if($ac == "upload")
{
$this->_helper->layout->setLayout('layout-iframe');
$this->_helper->viewRenderer('project-upload');
$submit = $this->_getParam('submit');
$pid = $this->_getParam('pid');
if(empty($pid) || !is_numeric($pid))
@ -847,6 +852,8 @@ class HeiheController extends DataController
return true;
}
$this->view->pid = $pid;
if(empty($uid))
{
$this->view->error = "请先登录";
@ -863,6 +870,60 @@ class HeiheController extends DataController
return true;
}
if(!empty($submit) && empty($this->view->error))
{
$files=new files();
$msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],'heihe');
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'];
if(!empty($row['attachid']))
{
$sql = "SELECT * FROM attachments WHERE id={$row['attachid']}";
$sth = $this->db->query($sql);
$attach = $sth->fetch();
$this->db->exec("DELETE FROM attachments WHERE id={$row['attachid']} AND filetype='heihe'");
@unlink($this->view->config->upload.$attach['filename']);
}
$sql = " INSERT INTO attachments (filename,filetype,filedesc,userid,filesize,realname) values
('$filename','heihe','$filedesc','$uid','$filesize','$realname') RETURNING id";
$sth = $this->db->prepare($sql);
$sth->execute();
$att = $sth->fetch(PDO::FETCH_ASSOC);
$msg['attid'] = $attid = $att['id'];
$sql = "UPDATE heiheproject SET attachid=$attid WHERE id=$pid";
$sth = $this->db->exec($sql);
if($sth)
{
$this->view->message = "上传成功";
}else{
@unlink($filename);
$this->view->error = '附件上传失败:写入附件表出错';
return true;
}
}else{
@unlink($filename);
$this->view->error = "附件上传失败".$msg['error'];
return true;
}
}
$sql = "SELECT * FROM attachments WHERE id = {$row['attachid']}";
$sth = $this->db->query($sql);
$this->view->att = $sth->fetch();
return true;
}
if(!empty($invite))

View File

@ -0,0 +1,46 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('上传计划');
$this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/admin.css');
$this->breadcrumb()->setSeparator(' > ');
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
$this->headScript()->appendFile('/js/jquery.colorbox-min.js');
$this->headLink()->appendStylesheet('/css/colorbox.css');
$this->headLink()->appendStylesheet('/css/author.css');
$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');
?>
<?php
if(!empty($this->error))
{
echo $this->error;
echo "<script>setTimeout('parent.$.fn.colorbox.close();',2000);</script>";
}else{?>
<?php if(!empty($this->message))
{
echo "<p>".$this->message."</p>";
}?>
<?php
if(!empty($this->att))
{
echo '<div id="datalist">
<ul>'.
'<li>'.$this->att['realname']."(". round(($this->att['filesize'])/1024,2) .'KB) 【<a href="/service/attach/id/'.$this->att['id'].'">下载</a></li>'
.'</ul></div>';
}
?>
<div id="wapper">
<form id="fileUpdate" action="/heihe/projects/ac/upload/pid/<?= $this->pid ?>" method="post" enctype="multipart/form-data">
<p>注:只能选择一个文件,如果重新上传,将自动替换之前上传的文件<br />
<input id="file_upload" name="Filedata" type="file" />
<input type="hidden" name="submit" value="1" />
<input type="submit" class="btn btn-small btn-green" value="上传" />
</p>
</form>
</div>
<?php
}
?>