* adjust the file module.

This commit is contained in:
wangchunsheng
2010-01-13 06:34:46 +00:00
parent 8abc2a5b12
commit f0f1cf4945
9 changed files with 29 additions and 29 deletions

View File

@@ -201,8 +201,7 @@ class bug extends control
{
$changes = $this->bug->update($bugID);
if(dao::isError()) die(js::error(dao::getError()));
$this->loadModel('file');
$files = $this->file->saveUpload('files', 'bug', $bugID);
$files = $this->loadModel('file')->saveUpload('bug', $bugID);
if($this->post->comment != '' or !empty($changes) or !empty($files))
{
$action = !empty($changes) ? 'Edited' : 'Commented';

View File

@@ -47,13 +47,13 @@ class bugModel extends model
->cleanInt('product, module, severity')
->specialChars('steps')
->join('mailto', ',')
->remove('files, labels')
->get();
$this->dao->insert(TABLE_BUG)->data($bug)->autoCheck()->batchCheck('title,type', 'notempty')->exec();
if(!dao::isError())
{
$bugID = $this->dao->lastInsertID();
$this->loadModel('file');
$this->file->saveUpload('files', 'bug', $bugID);
$this->loadModel('file')->saveUpload('bug', $bugID);
return $bugID;
}
return false;
@@ -79,9 +79,7 @@ class bugModel extends model
foreach($bug as $key => $value) if(strpos($key, 'Date') !== false and !(int)substr($value, 0, 4)) $bug->$key = '';
$bug->mailto = ltrim(trim($bug->mailto), ',');
if($bug->duplicateBug) $bug->duplicateBugTitle = $this->dao->findById($bug->duplicateBug)->from(TABLE_BUG)->fields('title')->fetch('title');
$this->loadModel('file');
$bug->files = $this->file->getByObject('bug', $bugID);
$bug->files = $this->loadModel('file')->getByObject('bug', $bugID);
return $bug;
}
@@ -94,7 +92,7 @@ class bugModel extends model
->cleanInt('product,module,severity,project,story,task')
->stripTags('title')
->specialChars('steps')
->remove('comment')
->remove('comment,fiels,labels')
->setDefault('project,module,project,story,task,duplicateBug', 0)
->add('lastEditedBy', $this->app->user->account)
->add('lastEditedDate', $now)

View File

@@ -153,10 +153,7 @@ function loadProjectStories(projectID)
</tr>
<tr>
<th class='rowhead'><?php echo $lang->bug->files;?></th>
<td class='a-left'>
<input type='file' name='files[]' class='text-4' />
<input type='file' name='files[]' class='text-4' />
</td>
<td class='a-left'><?php echo $this->fetch('file', 'buildform');?></td>
</tr>
<tr>
<td colspan='2'>

View File

@@ -195,8 +195,8 @@ function setDuplicate(resolution)
<tr>
<td class='rowhead'></td>
<td>
<?php echo $this->fetch('file', 'buildform', 'filecount=2');?>
<?php foreach($bug->files as $file) echo html::a($file->fullPath, $file->title);?>
<input type='file' name='files' />
</td>
</tr>
</table>

View File

@@ -46,6 +46,10 @@
<legend><?php echo $lang->bug->legendSteps;?></legend>
<div class='content'><?php echo nl2br($bug->steps);?></div>
</fieldset>
<fieldset>
<legend><?php echo $lang->bug->legendAttatch;?></legend>
<div><?php foreach($bug->files as $file) echo html::a($file->fullPath, $file->title, '_blank');?></div>
</fieldset>
<?php include '../../common/action.html.php';?>
<fieldset>
<legend><?php echo $lang->bug->legendAction;?></legend>
@@ -165,16 +169,6 @@
<div><?php $mailto = explode(',', $bug->mailto); foreach($mailto as $account) echo ' ' . $users[$account]; ?></div>
</fieldset>
<fieldset>
<legend><?php echo $lang->bug->legendAttatch;?></legend>
<div>
<?php
foreach($bug->files as $file) echo html::a($file->fullPath, $file->title, '_blank');
?>
</div>
</fieldset>
<fieldset>
<legend><?php echo $lang->bug->legendLinkBugs;?></legend>
<div>&nbsp;</div>
@@ -185,7 +179,6 @@
<div>&nbsp;</div>
</fieldset>
</div>
</div>

View File

@@ -23,4 +23,10 @@
*/
class file extends control
{
/* 生成文件上传的表单。*/
public function buildForm($fileCount = 2)
{
$this->view->fileCount = $fileCount;
$this->display();
}
}

View File

@@ -22,3 +22,4 @@
* @link http://www.zentao.cn
*/
$lang->file->common = '附件';
$lang->file->label = '标题:';

View File

@@ -28,6 +28,7 @@ class fileModel extends model
public $savePath = '';
public $webPath = '';
/* 构造函数。*/
public function __construct()
{
parent::__construct();
@@ -35,6 +36,7 @@ class fileModel extends model
$this->setWebPath();
}
/* 通过对象类型获取文件列表。*/
public function getByObject($objectType, $objectID)
{
$files = array();
@@ -48,11 +50,11 @@ class fileModel extends model
}
/* 保存上传的文件。*/
public function saveUpload($htmlTagName = 'files', $objectType = '', $objectID = '')
public function saveUpload($objectType = '', $objectID = '')
{
$fileTitles = array();
$now = date('Y-m-d H:i:s');
$files = $this->getUpload($htmlTagName);
$files = $this->getUpload();
foreach($files as $id => $file)
{
@@ -70,7 +72,7 @@ class fileModel extends model
}
/* 获取上传的文件信息。*/
private function getUpload($htmlTagName)
private function getUpload($htmlTagName = 'files')
{
$files = array();
if(!isset($_FILES[$htmlTagName])) return $files;
@@ -84,7 +86,7 @@ class fileModel extends model
if(empty($filename)) continue;
$file['extension'] = $this->getExtension($filename);
$file['pathname'] = $this->setPathName($id, $file['extension']);
$file['title'] = pathinfo($filename, PATHINFO_FILENAME);
$file['title'] = isset($_POST['labels'][$id]) ? htmlspecialchars($_POST['labels'][$id]) : pathinfo($filename, PATHINFO_FILENAME);
$file['size'] = $size[$id];
$file['tmpname'] = $tmp_name[$id];
$files[] = $file;
@@ -96,7 +98,7 @@ class fileModel extends model
extract($_FILES[$htmlTagName]);
$file['extension'] = $this->getExtension($name);
$file['pathname'] = $this->setPathName(0, $file['extension']);
$file['title'] = pathinfo($name, PATHINFO_FILENAME);
$file['title'] = isset($_POST['labels'][0]) ? htmlspecialchars($_POST['labels'][0]) : pathinfo($filename, PATHINFO_FILENAME);
$file['size'] = $size;
$file['tmpname'] = $tmp_name;
return array($file);

View File

@@ -0,0 +1,4 @@
<?php for($i = 0; $i < $fileCount; $i ++):?>
<input type='file' name='files[]' />
<?php echo $lang->file->label;?><input type='text' name='labels[]' class='text-3' /><br />
<?php endfor;?>