control.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. /**
  3. * The control file of transfer module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Chunsheng Wang <chunsheng@cnezsoft.com>
  8. * @package transfer
  9. * @link https://www.zentao.net
  10. */
  11. class transfer extends control
  12. {
  13. /**
  14. * 导出数据
  15. * Export datas.
  16. *
  17. * @param string $module
  18. * @access public
  19. * @return void
  20. */
  21. public function export($module = '')
  22. {
  23. if(!empty($_POST))
  24. {
  25. $this->transfer->export($module);
  26. $this->fetch('file', 'export2' . $_POST['fileType'], $_POST);
  27. }
  28. }
  29. /**
  30. * 导出模板
  31. * Export Template.
  32. *
  33. * @param string $module
  34. * @param string $params
  35. * @access public
  36. * @return void
  37. */
  38. public function exportTemplate($module, $params = '')
  39. {
  40. if(!empty($_POST))
  41. {
  42. $this->loadModel($module);
  43. /* 获取工作流字段。*/
  44. /* Get workflow fields by module. */
  45. if($this->config->edition != 'open')
  46. {
  47. $groupID = $this->loadModel('workflowgroup')->getGroupIDByData($module, null);
  48. $action = $this->loadModel('workflowaction')->getByModuleAndAction($module, 'exportTemplate', $groupID);
  49. if(!empty($action->extensionType) && $action->extensionType == 'extend')
  50. {
  51. $appendFields = $this->loadModel('workflowaction')->getPageFields($module, 'exportTemplate', true, null, 0, $groupID);
  52. foreach($appendFields as $appendField)
  53. {
  54. $this->lang->$module->{$appendField->field} = $appendField->name;
  55. $this->config->$module->templateFields .= ',' . $appendField->field;
  56. }
  57. }
  58. }
  59. /* 将参数转成变量并存到SESSION中。*/
  60. /* Set SESSION. */
  61. $params = $this->transferZen->saveSession($module, $params);
  62. extract($params);
  63. /* 获取系统内置字段列表. */
  64. /* Get system built-in field list. */
  65. $this->config->transfer->sysDataList = $this->transfer->initSysDataFields();
  66. /* 获取导出模板字段。*/
  67. /* Get export template fields. */
  68. $fields = $this->config->$module->templateFields;
  69. if($module == 'task' and isset($executionID)) $fields = $this->transferZen->processTaskTemplateFields((int)$executionID, $fields);
  70. /* 初始化字段列表并拼接下拉菜单数据。*/
  71. /* Init field list and append dropdown menu data. */
  72. $this->transferZen->initTemplateFields($module, $fields);
  73. $this->fetch('file', 'export2' . $this->post->fileType, $_POST);
  74. }
  75. $this->display();
  76. }
  77. /**
  78. * 导入数据。
  79. * Import.
  80. *
  81. * @param string $module
  82. * @param string $locate
  83. * @access public
  84. * @return void
  85. */
  86. public function import($module, $locate = '')
  87. {
  88. $locate = $locate ? $locate : $this->session->showImportURL;
  89. if($this->server->request_method == 'POST')
  90. {
  91. $file = $this->loadModel('file')->getUpload('file');
  92. if(empty($_FILES)) return $this->send(array('result' => 'fail', 'message' => $this->lang->file->errorFileFormat));
  93. if(empty($file[0])) return $this->send(array('result' => 'fail', 'message' => $this->lang->testcase->errorFileNotEmpty));
  94. if(!empty($file['error'])) return $this->send(array('result' => 'fail', 'message' => $this->lang->file->uploadError[$file['error']]));
  95. $file = $file[0];
  96. if(!in_array(strtolower($file['extension']), array('xls', 'xlsx'))) return $this->send(array('result' => 'fail', 'message' => $this->lang->excel->canNotRead));
  97. $shortName = $this->file->getSaveName($file['pathname']);
  98. if(empty($shortName)) return $this->send(array('result' => 'fail', 'message' => $this->lang->excel->emptyFileName));
  99. /* 将文件从临时目录移动到保存目录。 */
  100. /* Move file from temp dir to save dir. */
  101. $extension = $file['extension'];
  102. $fileName = $this->file->savePath . $shortName;
  103. move_uploaded_file($file['tmpname'], $fileName);
  104. /* 读取Excel文件。*/
  105. /* Read Excel file. */
  106. $this->app->loadClass('phpexcel', true);
  107. if(!phpExcel::canRead($fileName))
  108. {
  109. unlink($fileName);
  110. return $this->send(array('result' => 'fail', 'message' => $this->lang->excel->canNotRead));
  111. }
  112. /* 将文件目录和后缀信息保存到SESSION。*/
  113. /* Save file directory and extension info to session. */
  114. $this->session->set('fileImportFileName', $fileName);
  115. $this->session->set('fileImportExtension', $extension);
  116. return $this->send(array('result' => 'success', 'load' => $locate, 'closeModal' => true));
  117. }
  118. /* 项目和执行中的需求导入时应选择需求类型. */
  119. if($module == 'story')
  120. {
  121. $this->app->loadLang('story');
  122. $storyType = '';
  123. if($this->app->tab == 'project')
  124. {
  125. $project = $this->loadModel('project')->fetchByID($this->session->project);
  126. $storyType = $project->storyType;
  127. }
  128. if($storyType)
  129. {
  130. foreach($this->lang->story->typeList as $key => $value)
  131. {
  132. if(strpos(",$storyType,", ",$key,") === false) unset($this->lang->story->typeList[$key]);
  133. }
  134. }
  135. $this->view->isProjectStory = $this->app->tab == 'project';
  136. $this->view->typeList = $this->lang->story->typeList;
  137. }
  138. $this->view->title = $this->lang->transfer->importCase;
  139. $this->display();
  140. }
  141. /**
  142. * Ajax get Tbody.
  143. *
  144. * @param string $module
  145. * @param int $lastID
  146. * @param int $pagerID
  147. * @access public
  148. * @return void
  149. */
  150. public function ajaxGetTbody($module = '', $lastID = 0, $pagerID = 1)
  151. {
  152. $filter = '';
  153. if($module == 'task') $filter = 'estimate';
  154. if($module == 'story' and $this->session->storyType == 'requirement') $this->loadModel('story')->replaceUserRequirementLang();
  155. /* 获取该模块导入字段数据。*/
  156. /* Get the import field data of the module. */
  157. $this->loadModel($module);
  158. $importFields = !empty($_SESSION[$module . 'TemplateFields']) ? $_SESSION[$module . 'TemplateFields'] : $this->config->$module->templateFields;
  159. if($module == 'testcase' and !empty($_SESSION[$module . 'TemplateFields']) and is_array($importFields))
  160. {
  161. $this->config->$module->templateFields = implode(',', $importFields);
  162. $this->config->testcase->datatable->fieldList['branch']['dataSource']['params'] = '$productID&active';
  163. }
  164. /* 初始化字段列表。*/
  165. /* Init field list. */
  166. $fields = $this->transfer->initFieldList($module, $importFields, false);
  167. $formatDatas = $this->transfer->format($module, $filter);
  168. $datas = $this->transfer->getPageDatas($formatDatas, $pagerID);
  169. $fields = $this->transferZen->formatFields($module, $fields);
  170. /* 处理任务统计列的数据。*/
  171. /* Process task statistics column data. */
  172. if($module == 'task') $datas = $this->task->processDatas4Task($datas);
  173. /* 构建导入表单。*/
  174. /* Build import form. */
  175. $html = $this->transfer->buildNextList($datas->datas, $lastID, $fields, $pagerID, $module);
  176. return print($html);
  177. }
  178. /**
  179. * Ajax 获取某个字段下拉菜单。
  180. * Ajax Get Options.
  181. *
  182. * @param string $module
  183. * @param string $field
  184. * @param string $value
  185. * @param string $index
  186. * @access public
  187. * @return void
  188. */
  189. public function ajaxGetOptions($module = '', $field = '', $value = '', $index = '')
  190. {
  191. $this->loadModel($module);
  192. $fields = $this->config->$module->templateFields;
  193. /* 如果是付费版,拼接工作流字符。*/
  194. /* If it is paid version, append workflow field. */
  195. if($this->config->edition != 'open')
  196. {
  197. $appendFields = $this->loadModel('workflowaction')->getFields($module, 'showimport', false);
  198. foreach($appendFields as $appendField) $fields .= ',' . $appendField->field;
  199. }
  200. $fieldList = $this->transfer->initFieldList($module, $fields, false);
  201. if(empty($fieldList[$field]['values'])) $fieldList[$field]['values'] = array('' => '');
  202. if(!in_array($field, $this->config->transfer->requiredFields)) $fieldList[$field]['values'][''] = '';
  203. /* 如果字段是多选下拉则字段名称为$field[$index][]。*/
  204. /* If the field is multiple select, the field name is $field[$index][]. */
  205. $multiple = $fieldList[$field]['control'] == 'multiple' ? 'multiple' : '';
  206. $name = $field . "[$index]";
  207. if($multiple == 'multiple') $name .= "[]";
  208. return print(html::select($name, $fieldList[$field]['values'], $value, "class='form-control picker-select' data-field='$field' data-index='$index' $multiple"));
  209. }
  210. }