+ add the feature of upload.

This commit is contained in:
wangchunsheng
2009-11-16 09:45:13 +00:00
parent 583b65c82b
commit 2dbe450c78
10 changed files with 238 additions and 38 deletions

View File

@@ -49,6 +49,9 @@ $config->default->module = 'index'; // Ĭ
$config->default->method = 'index'; // Ĭ<>ϵķ<CFB5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ø÷<C3B8><C3B7><EFBFBD><EFBFBD><EFBFBD>
$config->default->domain = 'pms.easysoft.com'; // Ĭ<>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ж<EFBFBD>Ӧ<EFBFBD>ļ<EFBFBD>¼ʱ<C2BC><CAB1>ʹ<EFBFBD>ô<EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>Ĺ<EFBFBD>˾<EFBFBD><CBBE>Ϣ<EFBFBD><CFA2>
$config->file->dangers = 'php,jsp,py,rb,asp,'; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD>
$config->file->maxSize = 1024 * 1024; // <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>λΪ<CEBB>ֽڡ<D6BD>
$config->db->errorMode = PDO::ERRMODE_EXCEPTION; // PDO<44>Ĵ<EFBFBD><C4B4><EFBFBD>ģʽ: PDO::ERRMODE_SILENT|PDO::ERRMODE_WARNING|PDO::ERRMODE_EXCEPTION
$config->db->persistant = false; // <20>Ƿ<EFBFBD><C7B7>򿪳־<F2BFAAB3><D6BE><EFBFBD><EFBFBD>ӡ<EFBFBD>
$config->db->driver = 'mysql'; // pdo<64><6F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>Ŀǰ<C4BF><C7B0>ʱֻ֧<D6BB><D6A7>mysql<71><6C>

View File

@@ -156,10 +156,14 @@ class bug extends control
{
$changes = $this->bug->update($bugID);
if(dao::isError()) die(js::error(dao::getError()));
if($this->post->comment != '' or !empty($changes))
$this->loadModel('file');
$files = $this->file->saveUpload('files', 'bug', $bugID);
if($this->post->comment != '' or !empty($changes) or !empty($files))
{
$action = !empty($changes) ? 'Edited' : 'Commented';
$actionID = $this->action->create('bug', $bugID, $action, $this->post->comment);
$fileAction = '';
if(!empty($files)) $fileAction = "Add Files " . join(',', $files) . "\n" ;
$actionID = $this->action->create('bug', $bugID, $action, $fileAction . $this->post->comment);
$this->action->logHistory($actionID, $changes);
}
die(js::locate($this->createLink('bug', 'view', "bugID=$bugID"), 'parent'));
@@ -231,6 +235,8 @@ class bug extends control
{
$this->bug->activate($bugID);
if(dao::isError()) die(js::error(dao::getError()));
$this->loadModel('file');
$files = $this->file->saveUpload('files', 'bug', $bugID);
$this->action->create('bug', $bugID, 'Activated', $this->post->comment);
die(js::locate($this->createLink('bug', 'view', "bugID=$bugID"), 'parent'));
}

View File

@@ -40,7 +40,14 @@ class bugModel extends model
->join('mailto', ',')
->get();
$this->dao->insert(TABLE_BUG)->data($bug)->autoCheck()->check('title', 'notempty')->exec();
return $this->dao->lastInsertID();
if(!dao::isError())
{
$bugID = $this->dao->lastInsertID();
$this->loadModel('file');
$this->file->saveUpload('files', 'bug', $bugID);
return $bugID;
}
return false;
}
/* 获得某一个产品某一个模块下面的所有bug。*/
@@ -63,6 +70,9 @@ 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);
return $bug;
}

View File

@@ -23,7 +23,7 @@
*/
?>
<?php include '../../common/header.html.php';?>
<form method='post' target='hiddenwin'>
<form method='post' enctype='multipart/form-data' target='hiddenwin'>
<div class='yui-d0'>
<table class='table-1'>
<caption><?php echo $bug->title;?></caption>
@@ -35,6 +35,13 @@
<td class='rowhead'><?php echo $lang->comment;?></td>
<td><textarea name='comment' rows='6' class='area-1'></textarea></td>
</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>
</tr>
<tr>
<td colspan='2' class='a-center'>
<?php echo html::submitButton();?>

View File

@@ -91,7 +91,7 @@ function loadProjectStories(projectID)
</script>
<div class='yui-doc3'>
<form method='post' target='hiddenwin'>
<form method='post' enctype='multipart/form-data' target='hiddenwin'>
<table align='center' class='table-1'>
<caption><?php echo $lang->bug->create;?></caption>
<tr>
@@ -122,38 +122,17 @@ function loadProjectStories(projectID)
</tr>
-->
<tr>
<th class='rowhead'><?php echo $lang->bug->labTypeAndSeverity;?></th>
<td class='a-left'>
<?php echo html::select('type', (array)$lang->bug->typeList, '', 'class=select-2');?>
<?php echo html::select('severity', (array)$lang->bug->severityList, '', 'class=select-2');?>
</td>
</tr>
<tr>
<th class='rowhead'><nobr><?php echo $lang->bug->labSystemBrowserAndHardware;?></nobr></th>
<td class='a-left'>
<?php echo html::select('os', (array)$lang->bug->osList, '', 'class=select-2');?>
<?php echo html::select('browser', (array)$lang->bug->browserList, '', 'class=select-2');?>
</td>
</tr>
<tr>
<th class='rowhead'><nobr><?php echo $lang->bug->labAssignedTo;?></nobr></th>
<td class='a-left'>
<?php echo html::select('assignedTo', $users, '', 'class=select-3');?>
</td>
</tr>
<tr>
<th class='rowhead'><nobr><?php echo $lang->bug->labMailto;?></nobr></th>
<td class='a-left'>
<?php echo html::select('mailto[]', $users, '', 'class=select-3 size=5 multiple=multiple');?>
</td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->bug->title;?></th>
<td class='a-left'><input type='text' name='title' class='text-1' /></td>
</tr>
<th class='rowhead'><?php echo $lang->bug->labTypeAndSeverity;?></th> <td class='a-left'> <?php echo html::select('type', (array)$lang->bug->typeList, '', 'class=select-2');?> <?php echo html::select('severity', (array)$lang->bug->severityList, '', 'class=select-2');?> </td> </tr> <tr> <th class='rowhead'><nobr><?php echo $lang->bug->labSystemBrowserAndHardware;?></nobr></th> <td class='a-left'> <?php echo html::select('os', (array)$lang->bug->osList, '', 'class=select-2');?> <?php echo html::select('browser', (array)$lang->bug->browserList, '', 'class=select-2');?> </td> </tr> <tr> <th class='rowhead'><nobr><?php echo $lang->bug->labAssignedTo;?></nobr></th> <td class='a-left'> <?php echo html::select('assignedTo', $users, '', 'class=select-3');?> </td> </tr> <tr> <th class='rowhead'><nobr><?php echo $lang->bug->labMailto;?></nobr></th> <td class='a-left'> <?php echo html::select('mailto[]', $users, '', 'class=select-3 size=5 multiple=multiple');?> </td> </tr> <tr> <th class='rowhead'><?php echo $lang->bug->title;?></th> <td class='a-left'><input type='text' name='title' class='text-1' /></td> </tr>
<tr>
<th class='rowhead'><?php echo $lang->bug->steps;?></th>
<td class='a-left'><textarea name='steps' class='area-1' rows='8'></textarea></td>
<td class='a-left'><textarea name='steps' class='area-1' rows='6'></textarea></td>
</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>
</tr>
<tr>
<td colspan='2'>

View File

@@ -111,7 +111,7 @@ function setDuplicate(resolution)
}
}
</script>
<form method='post' target='hiddenwin'>
<form method='post' target='hiddenwin' enctype='multipart/form-data'>
<div class='yui-d0'>
<div id='titlebar'>
<div id='main'>
@@ -191,7 +191,15 @@ function setDuplicate(resolution)
<fieldset>
<legend><?php echo $lang->bug->legendAttatch;?></legend>
<div>&nbsp;</div>
<table class='table-1 a-left'>
<tr>
<td class='rowhead'></td>
<td>
<?php foreach($bug->files as $file) echo html::a($file->fullPath, $file->title);?>
<input type='file' name='files' />
</td>
</tr>
</table>
</fieldset>
</div>

View File

@@ -120,7 +120,11 @@
<fieldset>
<legend><?php echo $lang->bug->legendAttatch;?></legend>
<div>&nbsp;</div>
<div>
<?php
foreach($bug->files as $file) echo html::a($file->fullPath, $file->title, '_blank');
?>
</div>
</fieldset>
</div>

View File

@@ -0,0 +1,26 @@
<?php
/**
* The control file of file module of ZenTaoMS.
*
* ZenTaoMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ZenTaoMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZenTaoMS. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright: 2009 Chunsheng Wang
* @author Chunsheng Wang <wwccss@263.net>
* @package file
* @version $Id$
* @link http://www.zentao.cn
*/
class file extends control
{
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* The file module zh-cn file of ZenTaoMS.
*
* ZenTaoMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ZenTaoMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZenTaoMS. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright: 2009 Chunsheng Wang
* @author Chunsheng Wang <wwccss@263.net>
* @package file
* @version $Id$
* @link http://www.zentao.cn
*/
$lang->file->common = '附件';

133
trunk/module/file/model.php Normal file
View File

@@ -0,0 +1,133 @@
<?php
/**
* The model file of file module of ZenTaoMS.
*
* ZenTaoMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ZenTaoMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZenTaoMS. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright: 2009 Chunsheng Wang
* @author Chunsheng Wang <wwccss@263.net>
* @package file
* @version $Id$
* @link http://www.zentao.cn
*/
?>
<?php
class fileModel extends model
{
public $savePath = '';
public $webPath = '';
public function __construct()
{
parent::__construct();
$this->setSavePath();
$this->setWebPath();
}
public function getByObject($objectType, $objectID)
{
$files = array();
$stmt = $this->dao->select('*')->from(TABLE_FILE)->where('objectType')->eq($objectType)->andWhere('objectID')->eq((int)$objectID)->query();
while($file = $stmt->fetch())
{
$file->fullPath = $this->webPath . $file->pathname;
$files[] = $file;
}
return $files;
}
/* 保存上传的文件。*/
public function saveUpload($htmlTagName = 'files', $objectType = '', $objectID = '')
{
$fileTitles = array();
$now = date('Y-m-d H:i:s');
$files = $this->getUpload($htmlTagName);
foreach($files as $id => $file)
{
move_uploaded_file($file['tmpname'], $this->savePath . $file['pathname']);
$file['company'] = $this->app->company->id;
$file['objectType'] = $objectType;
$file['objectID'] = $objectID;
$file['addedBy'] = $this->app->user->account;
$file['addedDate'] = $now;
unset($file['tmpname']);
$this->dao->insert(TABLE_FILE)->data($file)->exec();
$fileTitles[$this->dao->lastInsertId()] = $file['title'];
}
return $fileTitles;
}
/* 获取上传的文件信息。*/
private function getUpload($htmlTagName)
{
$files = array();
if(!isset($_FILES[$htmlTagName])) return $files;
/* 表单定义中的变量名是数组。*/
if(is_array($_FILES[$htmlTagName]['name']))
{
extract($_FILES[$htmlTagName]);
foreach($name as $id => $filename)
{
if(empty($filename)) continue;
$file['extension'] = $this->getExtension($filename);
$file['pathname'] = $this->setPathName($id, $file['extension']);
$file['title'] = pathinfo($filename, PATHINFO_FILENAME);
$file['size'] = $size[$id];
$file['tmpname'] = $tmp_name[$id];
$files[] = $file;
}
}
else
{
extract($_FILES[$htmlTagName]);
$file['extension'] = $this->getExtension($name);
$file['pathname'] = $this->setPathName(0, $file['extension']);
$file['title'] = pathinfo($name, PATHINFO_FILENAME);
$file['size'] = $size;
$file['tmpname'] = $tmp_name;
return array($file);
}
return $files;
}
/* 获取文件扩展名。*/
private function getExtension($filename)
{
$extension = pathinfo($filename, PATHINFO_EXTENSION);
if(empty($extension)) return 'txt';
if(strpos($this->config->file->dangers, $extension) !== false) return 'txt';
return $extension;
}
/* 设置要存储的文件名。*/
private function setPathName($fileID, $extension)
{
return date('YmdHis') . $fileID . mt_rand(0, 10000) . '.' . $extension;
}
/* 设置存储路径。*/
private function setSavePath()
{
$this->savePath = $this->app->getAppRoot() . "www/data/upload/{$this->app->company->id}/";
if(!file_exists($this->savePath)) mkdir($this->savePath);
}
/* 设置web访问路径。*/
private function setWebPath()
{
$this->webPath = $this->app->getWebRoot() . "data/upload/{$this->app->company->id}/";
}
}