diff --git a/trunk/config/config.php b/trunk/config/config.php index 8cefc87fa1..7c91ef5c4d 100644 --- a/trunk/config/config.php +++ b/trunk/config/config.php @@ -49,6 +49,9 @@ $config->default->module = 'index'; // 默 $config->default->method = 'index'; // 默认的方法。当请求中没有指定方法或者指定的方法不存在时,调用该方法。 $config->default->domain = 'pms.easysoft.com'; // 默认的域名,当请求中的域名没有对应的记录时,使用此默认域名对应的公司信息。 +$config->file->dangers = 'php,jsp,py,rb,asp,'; // 不允许上传的文件类型列表。 +$config->file->maxSize = 1024 * 1024; // 允许上传的文件大小,单位为字节。 + $config->db->errorMode = PDO::ERRMODE_EXCEPTION; // PDO的错误模式: PDO::ERRMODE_SILENT|PDO::ERRMODE_WARNING|PDO::ERRMODE_EXCEPTION $config->db->persistant = false; // 是否打开持久连接。 $config->db->driver = 'mysql'; // pdo的驱动类型,目前暂时只支持mysql。 diff --git a/trunk/module/bug/control.php b/trunk/module/bug/control.php index 7322557124..1401ab6778 100644 --- a/trunk/module/bug/control.php +++ b/trunk/module/bug/control.php @@ -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')); } diff --git a/trunk/module/bug/model.php b/trunk/module/bug/model.php index ccec3cf4b3..162638fbc9 100644 --- a/trunk/module/bug/model.php +++ b/trunk/module/bug/model.php @@ -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; } /* 鑾峰緱鏌愪竴涓骇鍝侊紝鏌愪竴涓ā鍧椾笅闈㈢殑鎵鏈塨ug銆*/ @@ -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; } diff --git a/trunk/module/bug/view/activate.html.php b/trunk/module/bug/view/activate.html.php index b57b9f2821..cc7e10187e 100644 --- a/trunk/module/bug/view/activate.html.php +++ b/trunk/module/bug/view/activate.html.php @@ -23,7 +23,7 @@ */ ?> -
+
@@ -35,6 +35,13 @@ + + + +
title;?>
comment;?>
bug->files;?> + + +
diff --git a/trunk/module/bug/view/create.html.php b/trunk/module/bug/view/create.html.php index 4c74152b67..2fff8737ab 100644 --- a/trunk/module/bug/view/create.html.php +++ b/trunk/module/bug/view/create.html.php @@ -91,7 +91,7 @@ function loadProjectStories(projectID)
- + @@ -122,38 +122,17 @@ function loadProjectStories(projectID) --> - - - - - - - - - - - - - - - - - - - + - + + + + +
bug->create;?>
bug->labTypeAndSeverity;?> - bug->typeList, '', 'class=select-2');?> - bug->severityList, '', 'class=select-2');?> -
bug->labSystemBrowserAndHardware;?> - bug->osList, '', 'class=select-2');?> - bug->browserList, '', 'class=select-2');?> -
bug->labAssignedTo;?> - -
bug->labMailto;?> - -
bug->title;?>
bug->labTypeAndSeverity;?> bug->typeList, '', 'class=select-2');?> bug->severityList, '', 'class=select-2');?>
bug->labSystemBrowserAndHardware;?> bug->osList, '', 'class=select-2');?> bug->browserList, '', 'class=select-2');?>
bug->labAssignedTo;?>
bug->labMailto;?>
bug->title;?>
bug->steps;?>
bug->files;?> + + +
diff --git a/trunk/module/bug/view/edit.html.php b/trunk/module/bug/view/edit.html.php index b38687aad9..3d6d87f5c0 100644 --- a/trunk/module/bug/view/edit.html.php +++ b/trunk/module/bug/view/edit.html.php @@ -111,7 +111,7 @@ function setDuplicate(resolution) } } - +
@@ -191,7 +191,15 @@ function setDuplicate(resolution)
bug->legendAttatch;?> -
 
+ + + + + +
+ files as $file) echo html::a($file->fullPath, $file->title);?> + +
diff --git a/trunk/module/bug/view/view.html.php b/trunk/module/bug/view/view.html.php index db28ff49bf..2741e7da41 100644 --- a/trunk/module/bug/view/view.html.php +++ b/trunk/module/bug/view/view.html.php @@ -120,7 +120,11 @@
bug->legendAttatch;?> -
 
+
+ files as $file) echo html::a($file->fullPath, $file->title, '_blank'); + ?> +
diff --git a/trunk/module/file/control.php b/trunk/module/file/control.php new file mode 100644 index 0000000000..643113d5bb --- /dev/null +++ b/trunk/module/file/control.php @@ -0,0 +1,26 @@ +. + * + * @copyright Copyright: 2009 Chunsheng Wang + * @author Chunsheng Wang + * @package file + * @version $Id$ + * @link http://www.zentao.cn + */ +class file extends control +{ +} diff --git a/trunk/module/file/lang/zh-cn.php b/trunk/module/file/lang/zh-cn.php new file mode 100644 index 0000000000..3a0e873e97 --- /dev/null +++ b/trunk/module/file/lang/zh-cn.php @@ -0,0 +1,24 @@ +. + * + * @copyright Copyright: 2009 Chunsheng Wang + * @author Chunsheng Wang + * @package file + * @version $Id$ + * @link http://www.zentao.cn + */ +$lang->file->common = '闄勪欢'; diff --git a/trunk/module/file/model.php b/trunk/module/file/model.php new file mode 100644 index 0000000000..a78ccb98c3 --- /dev/null +++ b/trunk/module/file/model.php @@ -0,0 +1,133 @@ +. + * + * @copyright Copyright: 2009 Chunsheng Wang + * @author Chunsheng Wang + * @package file + * @version $Id$ + * @link http://www.zentao.cn + */ +?> +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}/"; + } +}