diff --git a/module/bug/control.php b/module/bug/control.php index a066f431d5..535ff0973a 100644 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -416,19 +416,14 @@ class bug extends control if($this->session->bugImagesFile) { - $extractPath = $this->session->bugImagesFile; - if(is_dir($extractPath)) + $files = $this->session->bugImagesFile; + foreach($files as $fileName => $file) { - $titles = array(); - $files = glob($extractPath . '/*'); - sort($files); - foreach($files as $fileName) - { - $fileName = basename($fileName); - $titles[$fileName] = preg_replace('/^\d+_/', '', pathinfo($fileName, PATHINFO_FILENAME)); - } - $this->view->titles = $titles; + $title = $file['title']; + $titles[$title] = $fileName; } + krsort($titles); + $this->view->titles = $titles; } $this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->bug->batchCreate; diff --git a/module/bug/model.php b/module/bug/model.php index 98e183ed37..f4b87e71f1 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -140,14 +140,11 @@ class bugModel extends model if(!empty($data->uploadImage[$i])) { - $fileName = htmlspecialchars_decode($data->uploadImage[$i]); - $realPath = $this->session->bugImagesFile . $fileName; + $fileName = $data->uploadImage[$i]; + $file = $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); + $realPath = $file['realpath']; + unset($file['realpath']); if(rename($realPath, $this->file->savePath . $file['pathname'])) { if(in_array($file['extension'], $this->config->file->imageExtensions)) @@ -194,7 +191,9 @@ class bugModel extends model if(!empty($data->uploadImage) and $this->session->bugImagesFile) { $classFile = $this->app->loadClass('zfile'); - if(is_dir($this->session->bugImagesFile)) $classFile->removeDir($this->session->bugImagesFile); + $file = current($_SESSION['bugImagesFile']); + $realPath = dirname($file['realpath']); + if(is_dir($realPath)) $classFile->removeDir($realPath); unset($_SESSION['bugImagesFile']); } diff --git a/module/bug/view/batchcreate.html.php b/module/bug/view/batchcreate.html.php index 850bb0ba8e..826ad893ed 100644 --- a/module/bug/view/batchcreate.html.php +++ b/module/bug/view/batchcreate.html.php @@ -57,7 +57,7 @@ ?> - $bugTitle):?> + $fileName):?> file->savePath . $file['pathname'])) { - $zipFile = $this->file->savePath . $file['pathname']; - $filePath = $this->file->extractZip($zipFile); + $zipFile = $this->file->savePath . $file['pathname']; + $files = $this->file->extractZip($zipFile); unlink($zipFile); - if(!$filePath) die(js::alert($this->lang->file->errorExtract)); + if(!$files) die(js::alert($this->lang->file->errorExtract)); - $this->session->set($module . 'ImagesFile', $filePath); + $this->session->set($module . 'ImagesFile', $files); die(js::locate($this->createLink($module, 'batchCreate', helper::safe64Decode($params)), 'parent.parent')); } } diff --git a/module/file/model.php b/module/file/model.php index 119027d996..b3cdace637 100644 --- a/module/file/model.php +++ b/module/file/model.php @@ -413,18 +413,38 @@ class fileModel extends model $filePath = $parentPath . str_replace('.zip', '', basename($zipFile)) . '/'; if(is_dir($filePath)) $classFile->removeDir($filePath); + mkdir($filePath); $this->app->loadClass('pclzip', true); $zip = new pclzip($zipFile); $files = $zip->listContent(); - foreach($files as $uploadFile) + foreach($files as $i => $uploadFile) { $extension = strtolower(substr(strrchr($uploadFile['filename'], '.'), 1)); if(empty($extension) or !in_array($extension, $this->config->file->imageExtensions)) return false; } - if($zip->extract(PCLZIP_OPT_PATH, $filePath) == 0) return false; - return $filePath; + $extractedFiles = array(); + foreach($files as $i => $uploadFile) + { + $fileName = mb_convert_encoding($uploadFile['filename'], 'UTF-8', 'gb2312'); + + $file = array(); + $file['extension'] = $this->getExtension($fileName); + $file['pathname'] = $this->setPathName($i, $file['extension']); + $file['title'] = str_replace(".{$file['extension']}", '', $fileName); + $file['size'] = $uploadFile['size']; + + $fileName = basename($file['pathname']); + $file['realpath'] = $filePath . $fileName; + $list = $zip->extract(PCLZIP_OPT_BY_NAME, $uploadFile['filename'], PCLZIP_OPT_EXTRACT_AS_STRING); + if($list) + { + file_put_contents($file['realpath'], $list[0]['content']); + $extractedFiles[$fileName] = $file; + } + } + return $extractedFiles; } /** diff --git a/module/story/control.php b/module/story/control.php index 17a3684026..51f7c6616f 100644 --- a/module/story/control.php +++ b/module/story/control.php @@ -201,10 +201,7 @@ class story extends control $mails = $this->story->batchCreate($productID, $branch); if(dao::isError()) die(js::error(dao::getError())); - foreach($mails as $mail) - { - $this->sendmail($mail->storyID, $mail->actionID); - } + foreach($mails as $mail) $this->sendmail($mail->storyID, $mail->actionID); die(js::locate($this->createLink('product', 'browse', "productID=$productID&branch=$branch"), 'parent')); } @@ -226,19 +223,14 @@ class story extends control /* Process upload images. */ if($this->session->storyImagesFile) { - $extractPath = $this->session->storyImagesFile; - if(is_dir($extractPath)) + $files = $this->session->storyImagesFile; + foreach($files as $fileName => $file) { - $titles = array(); - $files = glob($extractPath . '/*'); - sort($files); - foreach($files as $fileName) - { - $fileName = basename($fileName); - $titles[$fileName] = preg_replace('/^\d+_/', '', pathinfo($fileName, PATHINFO_FILENAME)); - } - $this->view->titles = $titles; + $title = $file['title']; + $titles[$title] = $fileName; } + krsort($titles); + $this->view->titles = $titles; } $moduleOptionMenu['same'] = $this->lang->story->same; diff --git a/module/story/model.php b/module/story/model.php index 002a1202b4..343787f7b4 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -222,6 +222,7 @@ class storyModel extends model public function batchCreate($productID = 0, $branch = 0) { $now = helper::now(); + $mails = array(); $stories = fixer::input('post')->get(); $batchNum = count(reset($stories)); @@ -242,9 +243,10 @@ class storyModel extends model } if(isset($stories->uploadImage)) $this->loadModel('file'); + for($i = 0; $i < $batchNum; $i++) { - if($stories->title[$i] != '') + if(!empty($stories->title[$i])) { $data = new stdclass(); $data->module = $stories->module[$i]; @@ -275,18 +277,17 @@ class storyModel extends model $specData->story = $storyID; $specData->version = 1; $specData->title = $stories->title[$i]; - if($stories->spec[$i] != '') $specData->spec = nl2br($stories->spec[$i]); + $specData->spec = ''; + if(!empty($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; + $fileName = $stories->uploadImage[$i]; + $file = $this->session->storyImagesFile[$fileName]; + + $realPath = $file['realpath']; + unset($file['realpath']); - $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; @@ -321,7 +322,9 @@ class storyModel extends model if(!empty($stories->uploadImage) and $this->session->storyImagesFile) { $classFile = $this->app->loadClass('zfile'); - if(is_dir($this->session->storyImagesFile)) $classFile->removeDir($this->session->storyImagesFile); + $file = current($_SESSION['storyImagesFile']); + $realPath = dirname($file['realpath']); + if(is_dir($realPath)) $classFile->removeDir($realPath); unset($_SESSION['storyImagesFile']); } diff --git a/module/story/view/batchcreate.html.php b/module/story/view/batchcreate.html.php index 5defcff287..1f38bb12b4 100644 --- a/module/story/view/batchcreate.html.php +++ b/module/story/view/batchcreate.html.php @@ -41,7 +41,7 @@ - $storyTitle):?> + $fileName):?>