control.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. <?php
  2. /**
  3. * The control file of custom of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license ZPL(http://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 custom
  9. * @version $Id$
  10. * @link https://www.zentao.net
  11. */
  12. class custom extends control
  13. {
  14. /**
  15. * Index.
  16. *
  17. * @access public
  18. * @return void
  19. */
  20. public function index()
  21. {
  22. if($this->config->vision == 'lite') return $this->locate(inlink('execution'));
  23. if(common::hasPriv('custom', 'set')) return $this->locate(inlink('set', "module=project&field=" . key($this->lang->custom->project->fields)));
  24. if(common::hasPriv('custom', 'product')) return $this->locate(inlink('product'));
  25. if(common::hasPriv('custom', 'execution')) return $this->locate(inlink('execution'));
  26. foreach($this->lang->custom->system as $sysObject)
  27. {
  28. if(common::hasPriv('custom', $sysObject)) return $this->locate(inlink($sysObject));
  29. }
  30. }
  31. /**
  32. * 设置对象字段的语言项。
  33. * Set the language items of the object fields.
  34. *
  35. * @param string $module todo|story|task|bug|testcase|testtask|user|project|block
  36. * @param string $field priList|typeList|statusList|sourceList|reasonList|stageList|reviewRules|reviewResultList|review|severityList|osList|browserList|resolutionList|longlife|resultList|roleList|contactField|deleted|unitList|closed
  37. * @param string $lang all|zh-cn|zh-tw|en|de|fr
  38. * @access public
  39. * @return void
  40. */
  41. public function set($module = 'story', $field = 'priList', $lang = '')
  42. {
  43. if(empty($lang)) $lang = $this->app->getClientLang();
  44. if($module == 'user' && $field == 'priList') $field = 'statusList';
  45. if($module == 'block' && $field == 'priList') $field = 'closed';
  46. $currentLang = $this->app->getClientLang();
  47. $this->customZen->assignVarsForSet($module, $field, $lang, $currentLang);
  48. if(strtolower($this->server->request_method) == "post")
  49. {
  50. $this->customZen->setFieldListForSet($module, $field);
  51. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  52. if($module == 'baseline' && $field == 'objectList') return $this->sendSuccess(array('load' => true));
  53. if($module == 'reviewcl') return $this->sendSuccess(array('load' => true));
  54. return $this->sendSuccess(array('load' => $this->createLink('custom', 'set', "module=$module&field=$field&lang=" . ($lang == 'all' ? $lang : ''))));
  55. }
  56. $this->view->title = $this->lang->custom->common . $this->lang->hyphen . $this->lang->$module->common;
  57. $this->view->field = $field;
  58. $this->view->module = $module;
  59. $this->view->currentLang = $currentLang;
  60. $this->view->canAdd = strpos($this->config->custom->canAdd[$module], $field) !== false;
  61. $this->display();
  62. }
  63. /**
  64. * 还原默认语言项。删除相关项。
  65. * Restore the default lang. Delete the related items.
  66. *
  67. * @param string $module
  68. * @param string $field
  69. * @access public
  70. * @return void
  71. */
  72. public function restore($module, $field)
  73. {
  74. if($module == 'user' && $field == 'contactField')
  75. {
  76. $this->loadModel('setting')->deleteItems("module={$module}&key={$field}");
  77. }
  78. else
  79. {
  80. $this->custom->deleteItems("module={$module}&section={$field}");
  81. }
  82. return $this->sendSuccess(array('load' => true));
  83. }
  84. /**
  85. * 设置表单必填字段。
  86. * Set the required fields.
  87. *
  88. * @param string $moduleName product|story|productplan|release|execution|task|bug|testcase|testsuite|testtask|testreport|caselib|doc|user|project|build
  89. * @access public
  90. * @return void
  91. */
  92. public function required($moduleName = '')
  93. {
  94. if(empty($moduleName)) $moduleName = current($this->config->custom->requiredModules);
  95. if($this->server->request_method == 'POST')
  96. {
  97. $this->custom->saveRequiredFields($moduleName, $_POST);
  98. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => inlink('required', "moduleName=$moduleName")));
  99. }
  100. foreach($this->config->custom->requiredModules as $requiredModule) $this->app->loadLang($requiredModule);
  101. /* Get this module requiredFields. */
  102. $this->loadModel($moduleName);
  103. if($moduleName == 'user') $this->app->loadModuleConfig($moduleName);
  104. $requiredFields = $this->custom->getRequiredFields($this->config->$moduleName);
  105. if($moduleName == 'doc')
  106. {
  107. unset($requiredFields['createlib']);
  108. unset($requiredFields['editlib']);
  109. }
  110. $this->view->title = $this->lang->custom->required;
  111. $this->view->requiredFields = $requiredFields;
  112. $this->view->module = $moduleName;
  113. $this->display();
  114. }
  115. /**
  116. * 时区。
  117. * Timezone.
  118. *
  119. * @access public
  120. * @return void
  121. */
  122. public function timezone()
  123. {
  124. if(strtolower($_SERVER['REQUEST_METHOD']) == "post")
  125. {
  126. $this->loadModel('setting')->setItems('system.common', $_POST);
  127. return $this->sendSuccess(array('load' => true));
  128. }
  129. unset($this->lang->admin->menu->custom['subModule']);
  130. $this->lang->admin->menu->system['subModule'] = 'custom';
  131. $this->view->title = $this->lang->custom->timezone;
  132. $this->display();
  133. }
  134. /**
  135. * 需求概念列表。
  136. * Browse story concept.
  137. *
  138. * @access public
  139. * @return void
  140. */
  141. public function browseStoryConcept()
  142. {
  143. $this->view->title = $this->lang->custom->browseStoryConcept;
  144. $this->view->URSRList = $this->custom->getURSRList();
  145. $this->view->module = 'product';
  146. $this->display();
  147. }
  148. /**
  149. * 设置需求概念。
  150. * Set story concept.
  151. *
  152. * @access public
  153. * @return void
  154. */
  155. public function setStoryConcept()
  156. {
  157. if($_POST)
  158. {
  159. $result = $this->custom->setURAndSR($_POST);
  160. if(!$result) return $this->send(array('result' => 'fail', 'message' => $this->lang->custom->notice->URSREmpty));
  161. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  162. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true, 'closeModal' => true));
  163. }
  164. if(!common::hasPriv('custom', 'setDefaultConcept')) unset($this->config->custom->browseStoryConcept->dtable->fieldList['default']);
  165. $this->view->title = $this->lang->custom->setStoryConcept;
  166. $this->display();
  167. }
  168. /**
  169. * 编辑需求概念。
  170. * Edit story concept.
  171. *
  172. * @param int $key
  173. * @access public
  174. * @return void
  175. */
  176. public function editStoryConcept($key = 0)
  177. {
  178. if($_POST)
  179. {
  180. $result = $this->custom->updateURAndSR($key, '', $_POST);
  181. if(!$result) return $this->send(array('result' => 'fail', 'message' => $this->lang->custom->notice->URSREmpty));
  182. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  183. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true, 'closeModal' => true));
  184. }
  185. $lang = $this->app->getClientLang();
  186. $URSR = $this->custom->getURSRConcept($key, $lang);
  187. $this->view->URSR = json_decode($URSR);
  188. $this->display();
  189. }
  190. /**
  191. * 设置默认需求概念。
  192. * Set story concept.
  193. *
  194. * @param int $key
  195. * @access public
  196. * @return void
  197. */
  198. public function setDefaultConcept($key = 0)
  199. {
  200. $this->loadModel('setting')->setItem('system.custom.URSR', $key);
  201. return $this->sendSuccess(array('load' => inlink('browsestoryconcept')));
  202. }
  203. /**
  204. * Delete story concept.
  205. *
  206. * @param int $key
  207. * @access public
  208. * @return void
  209. */
  210. public function deleteStoryConcept($key = 0)
  211. {
  212. $lang = $this->app->getClientLang();
  213. $this->custom->deleteItems("lang=$lang&section=URSRList&key=$key");
  214. $defaultConcept = $this->loadModel('setting')->getItem('owner=system&module=custom&key=URSR');
  215. $this->dao->update(TABLE_CONFIG)
  216. ->set('`value`')->eq($defaultConcept)
  217. ->where('module')->eq('common')
  218. ->andWhere('`key`')->eq('URSR')
  219. ->andWhere('`value`')->eq($key)
  220. ->exec();
  221. return $this->send(array('result' => 'success', 'load' => inlink('browseStoryConcept')));
  222. }
  223. /**
  224. * 项目关闭设置。
  225. * Set whether the closed project is read-only.
  226. *
  227. * @access public
  228. * @return void
  229. */
  230. public function project()
  231. {
  232. if($_POST)
  233. {
  234. $this->loadModel('setting')->setItem("system.common.CRProject@{$this->config->vision}", $this->post->project);
  235. return $this->sendSuccess(array('load' => true));
  236. }
  237. $this->view->title = $this->lang->projectCommon;
  238. $this->view->module = 'project';
  239. $this->display();
  240. }
  241. /**
  242. * 执行关闭设置。
  243. * Set whether the closed execution is read-only.
  244. *
  245. * @access public
  246. * @return void
  247. */
  248. public function execution()
  249. {
  250. if($_POST)
  251. {
  252. $this->loadModel('setting')->setItem("system.common.CRExecution@{$this->config->vision}", $this->post->execution);
  253. return $this->sendSuccess(array('load' => true));
  254. }
  255. $this->view->title = $this->lang->custom->executionCommon;
  256. $this->view->module = 'execution';
  257. $this->display();
  258. }
  259. /**
  260. * 产品关闭设置。
  261. * Set whether the closed product is read-only.
  262. *
  263. * @access public
  264. * @return void
  265. */
  266. public function product()
  267. {
  268. if($_POST)
  269. {
  270. $this->loadModel('setting')->setItem('system.common.CRProduct', $this->post->product);
  271. return $this->sendSuccess(array('load' => true));
  272. }
  273. $this->view->title = $this->lang->custom->productName;
  274. $this->view->module = 'product';
  275. $this->display();
  276. }
  277. /**
  278. * 看板关闭设置。
  279. * Set whether the kanban is read-only.
  280. *
  281. * @param string $type closedSetting|expireReminder
  282. * @access public
  283. * @return void
  284. */
  285. public function kanban($type = 'closedSetting')
  286. {
  287. $this->loadModel('kanban');
  288. if($_POST)
  289. {
  290. if($type == 'closedSetting')
  291. {
  292. $this->loadModel('setting')->setItem("system.common.CRKanban", $this->post->kanban);
  293. }
  294. else
  295. {
  296. $this->loadModel('setting')->setItem('system.kanban.reminder.expireDays', (int)$this->post->expireDays);
  297. }
  298. return $this->sendSuccess(array('load' => true));
  299. }
  300. $this->view->title = $this->lang->custom->kanban;
  301. $this->view->type = $type;
  302. $this->display();
  303. }
  304. /**
  305. * 流程设置。
  306. * Set flow.
  307. *
  308. * @access public
  309. * @return void
  310. */
  311. public function flow()
  312. {
  313. if($_POST)
  314. {
  315. $this->custom->setConcept($_POST['sprintConcept']);
  316. $this->loadModel('setting')->setItem('system.custom.hourPoint', $this->post->hourPoint);
  317. return $this->sendSuccess(array('load' => true));
  318. }
  319. $this->view->title = $this->lang->custom->flow;
  320. $this->display();
  321. }
  322. /**
  323. * 模式管理。
  324. * Mode management.
  325. *
  326. * @access public
  327. * @return void
  328. */
  329. public function mode()
  330. {
  331. $mode = zget($this->config->global, 'mode', 'light');
  332. if($this->post->mode && $this->post->mode != $mode) // If mode value change.
  333. {
  334. $mode = $this->post->mode;
  335. $program = isset($_POST['program']) ? $_POST['program'] : 0;
  336. /* Create the program to which the project in light mode belongs. */
  337. if($mode == 'light' && empty($program)) $program = $this->loadModel('program')->createDefaultProgram();
  338. $this->loadModel('setting')->setItem('system.common.global.mode', $mode);
  339. $this->setting->setItem('system.common.global.defaultProgram', $program);
  340. $this->custom->disableFeaturesByMode($mode);
  341. if($mode == 'light') $this->custom->processProjectAcl();
  342. if($mode == 'ALM')
  343. {
  344. $closedFeatures = $this->setting->getItem('owner=system&module=common&section=&key=closedFeatures');
  345. $this->loadModel('setting')->setItem('system.common.closedFeatures', $closedFeatures . ',otherOA');
  346. }
  347. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  348. return $this->sendSuccess(array('callback' => '$.apps.updateAppsMenu(true);', 'load' => true, 'closeModel' => true));
  349. }
  350. list($disabledFeatures, $enabledProjectFeatures, $disabledProjectFeatures) = $this->custom->computeFeatures();
  351. $this->view->title = $this->lang->custom->mode;
  352. $this->view->mode = $mode;
  353. $this->view->programs = $this->loadModel('program')->getTopPairs('noclosed', true);
  354. $this->view->programID = isset($this->config->global->defaultProgram) ? $this->config->global->defaultProgram : 0;
  355. $this->view->disabledFeatures = $disabledFeatures;
  356. $this->view->enabledProjectFeatures = $enabledProjectFeatures;
  357. $this->view->disabledProjectFeatures = $disabledProjectFeatures;
  358. $this->view->currentModeTips = sprintf($this->lang->custom->currentModeTips, $this->lang->custom->modeList[$mode], $this->lang->custom->modeList[$mode == 'light' ? 'ALM' : 'light']);
  359. $this->display();
  360. }
  361. /**
  362. * 保存自定义字段。
  363. * Ajax save custom fields.
  364. *
  365. * @param string $module
  366. * @param string $section
  367. * @param string $key
  368. * @access public
  369. * @return void
  370. */
  371. public function ajaxSaveCustomFields($module, $section, $key)
  372. {
  373. if(!isset($this->config->custom->customFields[$module][$section])) return;
  374. if(!in_array($key, $this->config->custom->customFields[$module][$section])) return;
  375. $this->loadModel('setting');
  376. $global = $this->post->global;
  377. $action = $this->post->action;
  378. $account = $this->app->user->account;
  379. if($global) $account = 'system';
  380. if($this->server->request_method == 'POST' && $action != 'reset')
  381. {
  382. $fields = $this->post->fields;
  383. if(is_array($fields)) $fields = implode(',', $fields);
  384. if($module == 'execution' && $section == 'custom' && $key == 'createFields' && strpos(",{$fields},", ',team,') !== false) $fields .= ',teams';
  385. $this->setting->setItem("{$account}.{$module}.{$section}.{$key}", $fields);
  386. if(in_array($module, array('story', 'task', 'testcase')) && $section == 'custom' && $key == 'batchCreateFields') return;
  387. if($module == 'bug' && $section == 'custom' && $key == 'batchCreateFields') return;
  388. }
  389. else
  390. {
  391. $this->setting->deleteItems("owner={$account}&module={$module}&section={$section}&key={$key}");
  392. }
  393. $this->loadModel('common')->loadConfigFromDB();
  394. $this->app->loadLang($module);
  395. $this->app->loadConfig($module, '', true);
  396. if($module == 'programplan' && $section == 'custom') $key = 'createFields';
  397. $customFields = zget(zget($this->config->$module, 'list', array()), $section . ucfirst($key), '');
  398. $showFields = zget(zget($this->config->$module, $section, array()), $key, '');
  399. if($module == 'marketresearch') return print(js::reload('parent'));
  400. return $this->send(array('result' => 'success', 'key' => $key, 'callback' => 'loadCurrentPage', 'customFields' => $customFields, 'showFields' => $showFields));
  401. }
  402. /**
  403. * 获取自定义列。
  404. * Ajax get custom fields.
  405. *
  406. * @param string $module
  407. * @param string $section
  408. * @param string $key
  409. * @access public
  410. * @return void
  411. */
  412. public function ajaxGetCustomFields($module, $section, $key)
  413. {
  414. return print($this->loadModel('setting')->getItem("owner={$this->app->user->account}&module={$module}&section={$section}&key={$key}"));
  415. }
  416. /**
  417. * 重置必填字段。
  418. * Reset required.
  419. *
  420. * @param string $module
  421. * @access public
  422. * @return void
  423. */
  424. public function resetRequired($module)
  425. {
  426. $this->loadModel('setting')->deleteItems("owner=system&module={$module}&key=requiredFields");
  427. return $this->send(array('result' => 'success', 'load' => true));
  428. }
  429. /**
  430. * 设置代号。
  431. * Set code.
  432. *
  433. * @access public
  434. * @return void
  435. */
  436. public function code()
  437. {
  438. if($_POST)
  439. {
  440. $this->loadModel('setting')->setItem('system.common.setCode', $this->post->code);
  441. return $this->sendSuccess(array('load' => true));
  442. }
  443. $this->view->title = $this->lang->custom->code;
  444. $this->display();
  445. }
  446. /**
  447. * 设置是否启用工作量占比。
  448. * Set whether to enable the workload percent.
  449. * @access public
  450. * @return void
  451. */
  452. public function percent()
  453. {
  454. if($_POST)
  455. {
  456. $this->loadModel('setting')->setItem('system.common.setPercent', $this->post->percent);
  457. return $this->sendSuccess(array('load' => true));
  458. }
  459. $this->view->title = $this->lang->stage->percent;
  460. $this->display();
  461. }
  462. /**
  463. * 设置每日可用工时和休息日。
  464. * Set hours and weekend
  465. *
  466. * @param string $type hours|weekend
  467. * @access public
  468. * @return void
  469. */
  470. public function hours($type = 'hours')
  471. {
  472. if($_POST)
  473. {
  474. $data = $_POST;
  475. $type = $_POST['type'];
  476. unset($data['type']);
  477. if($data['weekend'] != 1) unset($data['restDay']);
  478. if($type == 'hours' && ($data['defaultWorkhours'] < 0 || $data['defaultWorkhours'] > 24)) $this->sendError($this->lang->custom->hoursError);
  479. $this->loadModel('setting')->setItems('system.execution', $data);
  480. return $this->sendSuccess(array('load' => inLink('hours', "type={$type}")));
  481. }
  482. $this->app->loadConfig('execution');
  483. $this->view->title = $this->lang->workingHour;
  484. $this->view->type = $type;
  485. $this->view->weekend = $this->config->execution->weekend;
  486. $this->view->workhours = $this->config->execution->defaultWorkhours;
  487. $this->view->restDay = zget($this->config->execution, 'restDay', 0);
  488. $this->view->module = 'setDate';
  489. $this->display();
  490. }
  491. /**
  492. * 设置是否限制任务开始和结束时间。
  493. * Set whether the task begin and end date is limited to the execution begin and end date.
  494. *
  495. * @access public
  496. * @return void
  497. */
  498. public function limitTaskDate()
  499. {
  500. if($_POST)
  501. {
  502. $this->loadModel('setting')->setItem('system.common.limitTaskDate', $this->post->limitTaskDate);
  503. return $this->sendSuccess(array('load' => true));
  504. }
  505. $this->view->title = $this->lang->custom->beginAndEndDate;
  506. $this->view->module = 'task';
  507. $this->display();
  508. }
  509. /**
  510. * Ajax set menu
  511. *
  512. * @access public
  513. * @return void
  514. */
  515. public function ajaxSetMenu()
  516. {
  517. if($_POST)
  518. {
  519. $menu = $this->post->menu; // 导航类型,nav(左侧主导航)|$app(顶部一级导航)|$app-home(项目集、项目的首页导航)|$app-$subMenu(顶部二级导航)|admin-$menuKey(后台导航)
  520. $items = $this->post->items; // 导航项
  521. $account = $this->app->user->account;
  522. $oldMenu = isset($this->config->customMenu->{$menu}) ? $this->config->customMenu->{$menu} : '';
  523. /* 之前隐藏的导航若没开启继续保持隐藏。 */
  524. if($oldMenu)
  525. {
  526. $oldMenus = json_decode($oldMenu);
  527. $menus = json_decode($items);
  528. $menuNames = array();
  529. foreach($menus as $item) $menuNames[] = $item->name;
  530. foreach($oldMenus as $key => $item)
  531. {
  532. if(!empty($item->hidden) && !in_array($item->name, $menuNames)) $menus[] = $item;
  533. }
  534. $items = json_encode($menus);
  535. }
  536. if($menu && $items) $this->loadModel('setting')->setItem("$account.common.customMenu.$menu@{$this->config->vision}", $items);
  537. }
  538. $this->send(array('result' => 'success'));
  539. }
  540. /**
  541. * Ajax restore menu
  542. *
  543. * @access public
  544. * @return void
  545. */
  546. public function ajaxRestoreMenu()
  547. {
  548. if($_POST)
  549. {
  550. $account = $this->app->user->account;
  551. $menu = $this->post->menu;
  552. $this->loadModel('setting')->deleteItems("owner={$account}&module=common&section=customMenu&key=$menu");
  553. }
  554. $this->send(array('result' => 'success'));
  555. }
  556. }