control.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * The control file of dept 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 dept
  9. * @link https://www.zentao.net
  10. */
  11. class dept extends control
  12. {
  13. /**
  14. * 部门结构维护页面。
  15. * Department management page.
  16. *
  17. * @param int $deptID
  18. * @access public
  19. * @return void
  20. */
  21. public function browse($deptID = 0)
  22. {
  23. $this->view->title = $this->lang->dept->manage . $this->lang->hyphen . $this->app->company->name;
  24. $this->view->deptID = $deptID;
  25. $this->view->sons = $this->dept->getSons($deptID);
  26. $this->view->tree = $this->dept->getDataStructure();
  27. $this->view->parentDepts = $this->dept->getParents($deptID);
  28. $this->display();
  29. }
  30. /**
  31. * 部门结构排序。
  32. * Sort of departments.
  33. *
  34. * @access public
  35. * @return void
  36. */
  37. public function updateOrder()
  38. {
  39. if(!empty($_POST))
  40. {
  41. $this->dept->updateOrder(explode(',', $_POST['orders']));
  42. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true));
  43. }
  44. }
  45. /**
  46. * 修改子部门结构。
  47. * Update child departments.
  48. *
  49. * @access public
  50. * @return void
  51. */
  52. public function manageChild()
  53. {
  54. if(!empty($_POST))
  55. {
  56. $formData = form::data($this->config->dept->form->manage)->get();
  57. $deptIDList = $this->dept->manageChild($formData->parentDeptID, $formData->depts, $formData->maxOrder);
  58. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true, 'idList' => $deptIDList));
  59. }
  60. }
  61. /**
  62. * 编辑部门。
  63. * Edit a dept.
  64. *
  65. * @param int $deptID
  66. * @access public
  67. * @return void
  68. */
  69. public function edit($deptID)
  70. {
  71. if(!empty($_POST))
  72. {
  73. /* 获取表单提交内容。 */
  74. $formData = form::data($this->config->dept->form->edit)->setDefault('id', $deptID)->get();
  75. $this->dept->update($formData);
  76. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  77. return $this->send(array('result' => 'success', 'status' => 'success', 'message' => $this->lang->dept->successSave, 'closeModal' => true, 'load' => true));
  78. }
  79. /* Remove self and childs from the $optionMenu. Because it's parent can't be self or childs. */
  80. $optionMenu = $this->dept->getOptionMenu();
  81. $childs = $this->dept->getAllChildID($deptID);
  82. foreach($childs as $childModuleID) unset($optionMenu[$childModuleID]);
  83. $dept = $this->dept->fetchByID($deptID);
  84. if(!empty($this->config->user->moreLink)) $this->config->moreLinks["manager"] = $this->config->user->moreLink;
  85. $this->view->dept = $dept;
  86. $this->view->users = $this->loadModel('user')->getPairs('noletter|noclosed|nodeleted|all', $dept->manager, $this->config->maxCount);;
  87. $this->view->optionMenu = $optionMenu;
  88. $this->display();
  89. }
  90. /**
  91. * 删除部门。
  92. * Delete a department.
  93. *
  94. * @param int $deptID
  95. * @access public
  96. * @return void
  97. */
  98. public function delete($deptID)
  99. {
  100. /* 部门下有子部门的无法被删除。 */
  101. $sons = $this->dept->getSons($deptID);
  102. if($sons)
  103. {
  104. if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'fail', 'message' => $this->lang->dept->error->hasSons));
  105. return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.alert('{$this->lang->dept->error->hasSons}');"));
  106. }
  107. /* 部门下有人员的无法被删除。 */
  108. $users = $this->dept->getUsers('all', array($deptID));
  109. if($users)
  110. {
  111. if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'fail', 'message' => $this->lang->dept->error->hasUsers));
  112. return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.alert('{$this->lang->dept->error->hasUsers}');"));
  113. }
  114. $this->dept->deleteDept($deptID);
  115. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  116. return $this->send(array('result' => 'success', 'status' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true));
  117. }
  118. /**
  119. * 获取部门下的用户列表。
  120. * Ajax get dept users.
  121. *
  122. * @param int $dept
  123. * @param string $user
  124. * @param string $key id|account
  125. * @access public
  126. * @return void
  127. */
  128. public function ajaxGetUsers($dept, $user = '', $key = 'account')
  129. {
  130. $users = $this->dept->getDeptUserPairs($dept, $key);
  131. $isJsonView = $this->app->getViewType() == 'json';
  132. if(!$isJsonView) return print(html::select('user', array('' => '') + $users, $user, "class='form-control chosen'"));
  133. $items = array();
  134. foreach($users as $userID => $userName) $items[] = array('text' => $userName, 'value' => $userID);
  135. return print(json_encode($items));
  136. }
  137. }