diff --git a/module/bug/control.php b/module/bug/control.php
index 7245ee065c..c06faa5778 100644
--- a/module/bug/control.php
+++ b/module/bug/control.php
@@ -381,6 +381,21 @@ class bug extends control
$stories = $this->story->getProductStoryPairs($productID);
}
+ if($this->session->bugImagesFile)
+ {
+ $extractPath = $this->session->bugImagesFile;
+ if(is_dir($extractPath))
+ {
+ $titles = array();
+ foreach(glob($extractPath . '/*') as $fileName)
+ {
+ $fileName = basename($fileName);
+ $titles[$fileName] = preg_replace('/^\d+_/', '', pathinfo($fileName, PATHINFO_FILENAME));
+ }
+ $this->view->titles = $titles;
+ }
+ }
+
/* Remove the unused types. */
unset($this->lang->bug->typeList['designchange']);
unset($this->lang->bug->typeList['newfeature']);
diff --git a/module/bug/model.php b/module/bug/model.php
index 73461ea179..7eddc501b3 100644
--- a/module/bug/model.php
+++ b/module/bug/model.php
@@ -117,6 +117,7 @@ class bugModel extends model
$data->browsers[$i] = $browser;
}
+ if(isset($data->uploadImage)) $this->loadModel('file');
for($i = 0; $i < $batchNum; $i++)
{
if(empty($data->title[$i])) continue;
@@ -135,6 +136,35 @@ class bugModel extends model
$bug->os = $data->oses[$i];
$bug->browser = $data->browsers[$i];
+ if(!empty($data->uploadImage[$i]))
+ {
+ $fileName = htmlspecialchars_decode($data->uploadImage[$i]);
+ $realPath = $this->session->bugImagesFile . $fileName;
+
+ $file = array();
+ $file['extension'] = $this->file->getExtension($fileName);
+ $file['pathname'] = $this->file->setPathName($i, $file['extension']);
+ $file['title'] = str_replace(".{$file['extension']}", '', $fileName);
+ $file['size'] = filesize($realPath);
+ if(rename($realPath, $this->file->savePath . $file['pathname']))
+ {
+ if(in_array($file['extension'], $this->config->file->imageExtensions))
+ {
+ $file['addedBy'] = $this->app->user->account;
+ $file['addedDate'] = $now;
+ $this->dao->insert(TABLE_FILE)->data($file)->exec();
+
+ $url = $this->file->webPath . $file['pathname'];
+ $bug->steps .= '';
+ unset($file);
+ }
+ }
+ else
+ {
+ unset($file);
+ }
+ }
+
if(!empty($moduleOwners[$bug->module]))
{
$bug->assignedTo = $moduleOwners[$bug->module];
@@ -144,9 +174,28 @@ class bugModel extends model
$this->dao->insert(TABLE_BUG)->data($bug)->autoCheck()->batchCheck($this->config->bug->create->requiredFields, 'notempty')->exec();
$bugID = $this->dao->lastInsertID();
+ if(!empty($data->uploadImage[$i]) and !empty($file))
+ {
+ $file['objectType'] = 'bug';
+ $file['objectID'] = $bugID;
+ $file['addedBy'] = $this->app->user->account;
+ $file['addedDate'] = $now;
+ $this->dao->insert(TABLE_FILE)->data($file)->exec();
+ unset($file);
+ }
+
if(dao::isError()) die(js::error('bug#' . ($i+1) . dao::getError(true)));
$actions[$bugID] = $this->action->create('bug', $bugID, 'Opened');
}
+
+ /* Remove upload image file and session. */
+ if(!empty($data->uploadImage) and $this->session->bugImagesFile)
+ {
+ $classFile = $this->app->loadClass('zfile');
+ if(is_dir($this->session->bugImagesFile)) $classFile->removeDir($this->session->bugImagesFile);
+ unset($_SESSION['bugImagesFile']);
+ }
+
return $actions;
}
diff --git a/module/bug/view/batchcreate.html.php b/module/bug/view/batchcreate.html.php
index 12fe2fc6bf..14b8268219 100644
--- a/module/bug/view/batchcreate.html.php
+++ b/module/bug/view/batchcreate.html.php
@@ -16,7 +16,10 @@
2. if the file name at the beginning contains 'digital+underline', generation of title will they ignore, for example: '01_test', the title is 'test'.
+EOD; diff --git a/module/file/lang/zh-cn.php b/module/file/lang/zh-cn.php index 7ef3c190dd..a967b8931d 100644 --- a/module/file/lang/zh-cn.php +++ b/module/file/lang/zh-cn.php @@ -25,3 +25,9 @@ $lang->file->errorCanNotWrite = "文件夹 '%s' 不可写,请 $lang->file->confirmDelete = " 您确定删除该附件吗?"; $lang->file->errorFileSize = " 文件大小已经超过限制,可能不能成功上传!"; $lang->file->errorFileUpload = " 文件上传失败,文件大小可能超出限制"; +$lang->file->errorSuffix = '压缩包格式错误,只能上传zip压缩包!'; +$lang->file->errorExtract = '解压缩失败!可能文件已经损坏'; +$lang->file->uploadImagesExplain = <<2、如果文件名开头含有 数字+下划线,生成的标题会将他们忽略,例如:01_测试,生成的标题名是“测试”。
+EOD; diff --git a/module/file/model.php b/module/file/model.php index 860fc56333..70861f78fb 100644 --- a/module/file/model.php +++ b/module/file/model.php @@ -384,4 +384,27 @@ class fileModel extends model { return str_replace('""', '"', $matchs[1]) . str_replace(',', ',', $matchs[2]); } + + /** + * Extract zip. + * + * @param string $zipFile + * @access public + * @return string + */ + public function extractZip($zipFile) + { + $classFile = $this->app->loadClass('zfile'); + $parentPath = $this->app->getCacheRoot() . 'uploadimages/'; + if(!is_dir($parentPath)) mkdir($parentPath, 0777, true); + + $filePath = $parentPath . str_replace('.zip', '', basename($zipFile)) . '/'; + if(is_dir($filePath)) $classFile->removeDir($filePath); + + $this->app->loadClass('pclzip', true); + $zip = new pclzip($zipFile); + $files = $zip->listContent(); + if($zip->extract(PCLZIP_OPT_PATH, $filePath) == 0) return false; + return $filePath; + } } diff --git a/module/file/view/uploadimages.html.php b/module/file/view/uploadimages.html.php new file mode 100644 index 0000000000..6058c37445 --- /dev/null +++ b/module/file/view/uploadimages.html.php @@ -0,0 +1,23 @@ + + * @package file + * @version $Id$ + * @link http://www.zentao.net + */ +?> + + + diff --git a/module/story/control.php b/module/story/control.php index 59de841e33..3bde39b232 100644 --- a/module/story/control.php +++ b/module/story/control.php @@ -222,6 +222,22 @@ class story extends control $title = ''; $spec = ''; + /* Process upload images. */ + if($this->session->storyImagesFile) + { + $extractPath = $this->session->storyImagesFile; + if(is_dir($extractPath)) + { + $titles = array(); + foreach(glob($extractPath . '/*') as $fileName) + { + $fileName = basename($fileName); + $titles[$fileName] = preg_replace('/^\d+_/', '', pathinfo($fileName, PATHINFO_FILENAME)); + } + $this->view->titles = $titles; + } + } + $moduleOptionMenu['same'] = $this->lang->story->same; $plans = $this->loadModel('productplan')->getPairs($productID, 'unexpired'); $plans['same'] = $this->lang->story->same; diff --git a/module/story/model.php b/module/story/model.php index 45311dadbb..f0034c6640 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -230,25 +230,24 @@ class storyModel extends model $stories->pri[$i] = (int)$pri; } + if(isset($stories->uploadImage)) $this->loadModel('file'); for($i = 0; $i < $batchNum; $i++) { if($stories->title[$i] != '') { - $data[$i] = new stdclass(); - $data[$i]->module = $stories->module[$i]; - $data[$i]->plan = $stories->plan[$i]; - $data[$i]->title = $stories->title[$i]; - $data[$i]->pri = $stories->pri[$i] != '' ? $stories->pri[$i] : 0; - $data[$i]->estimate = $stories->estimate[$i] != '' ? $stories->estimate[$i] : 0; - $data[$i]->status = $stories->needReview[$i] == 0 ? 'active' : 'draft'; - $data[$i]->product = $productID; - $data[$i]->openedBy = $this->app->user->account; - $data[$i]->openedDate = $now; - $data[$i]->version = 1; + $data = new stdclass(); + $data->module = $stories->module[$i]; + $data->plan = $stories->plan[$i]; + $data->title = $stories->title[$i]; + $data->pri = $stories->pri[$i] != '' ? $stories->pri[$i] : 0; + $data->estimate = $stories->estimate[$i] != '' ? $stories->estimate[$i] : 0; + $data->status = $stories->needReview[$i] == 0 ? 'active' : 'draft'; + $data->product = $productID; + $data->openedBy = $this->app->user->account; + $data->openedDate = $now; + $data->version = 1; - $this->dao->insert(TABLE_STORY) - ->data($data[$i]) - ->autoCheck() + $this->dao->insert(TABLE_STORY)->data($data)->autoCheck() ->batchCheck($this->config->story->create->requiredFields, 'notempty') ->exec(); if(dao::isError()) @@ -260,12 +259,43 @@ class storyModel extends model $storyID = $this->dao->lastInsertID(); $this->setStage($storyID); - $specData[$i] = new stdclass(); - $specData[$i]->story = $storyID; - $specData[$i]->version = 1; - $specData[$i]->title = $stories->title[$i]; - if($stories->spec[$i] != '') $specData[$i]->spec = nl2br($stories->spec[$i]); - $this->dao->insert(TABLE_STORYSPEC)->data($specData[$i])->exec(); + $specData = new stdclass(); + $specData->story = $storyID; + $specData->version = 1; + $specData->title = $stories->title[$i]; + if($stories->spec[$i] != '') $specData->spec = nl2br($stories->spec[$i]); + + if(!empty($stories->uploadImage[$i])) + { + $fileName = htmlspecialchars_decode($stories->uploadImage[$i]); + $realPath = $this->session->storyImagesFile . $fileName; + + $file = array(); + $file['extension'] = $this->file->getExtension($fileName); + $file['pathname'] = $this->file->setPathName($i, $file['extension']); + $file['title'] = str_replace(".{$file['extension']}", '', $fileName); + $file['size'] = filesize($realPath); + if(rename($realPath, $this->file->savePath . $file['pathname'])) + { + $file['addedBy'] = $this->app->user->account; + $file['addedDate'] = $now; + if(in_array($file['extension'], $this->config->file->imageExtensions)) + { + $this->dao->insert(TABLE_FILE)->data($file)->exec(); + + $url = $this->file->webPath . $file['pathname']; + $specData->spec .= '