control.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <?php
  2. /**
  3. * The control file of group module 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 group
  9. * @version $Id: control.php 4648 2013-04-15 02:45:49Z chencongzhi520@gmail.com $
  10. * @link https://www.zentao.net
  11. */
  12. class group extends control
  13. {
  14. /**
  15. * 构造方法,将所有resource追加到package里。
  16. * Construct function.
  17. *
  18. * @param $moduleName
  19. * @param $methodName
  20. * @access public
  21. * @return void
  22. * @param string $moduleName
  23. * @param string $methodName
  24. */
  25. public function __construct($moduleName = '', $methodName = '')
  26. {
  27. parent::__construct($moduleName, $methodName);
  28. $this->appendResourcePackages();
  29. }
  30. /**
  31. * 权限分组列表页面。
  32. * Browse groups.
  33. *
  34. * @access public
  35. * @return void
  36. */
  37. public function browse()
  38. {
  39. $groups = $this->group->getList();
  40. $groupUsers = $this->group->getAllGroupMembers();
  41. foreach($groups as $group)
  42. {
  43. $group->actions = array();
  44. $group->users = implode(',', zget($groupUsers, $group->id, array()));
  45. }
  46. $this->view->title = $this->lang->company->orgView . $this->lang->hyphen . $this->lang->group->browse;
  47. $this->view->groups = $groups;
  48. $this->display();
  49. }
  50. /**
  51. * 创建权限分组。
  52. * Create a group.
  53. *
  54. * @access public
  55. * @return void
  56. */
  57. public function create()
  58. {
  59. if(!empty($_POST))
  60. {
  61. $group = form::data($this->config->group->form->create)->get();
  62. if($this->post->limited) $group->role = 'limited';
  63. $this->group->create($group);
  64. if(dao::isError()) return $this->sendError(dao::getError());
  65. return $this->sendSuccess(array('load' => true));
  66. }
  67. $this->view->title = $this->lang->company->orgView . $this->lang->hyphen . $this->lang->group->create;
  68. $this->display();
  69. }
  70. /**
  71. * 编辑权限分组。
  72. * Edit a group.
  73. *
  74. * @param int $groupID
  75. * @access public
  76. * @return void
  77. */
  78. public function edit($groupID)
  79. {
  80. if(!empty($_POST))
  81. {
  82. $group = form::data($this->config->group->form->edit)->get();
  83. $this->group->update($groupID, $group);
  84. if(dao::isError()) return $this->sendError(dao::getError());
  85. return $this->sendSuccess(array('load' => true, 'closeModal' => true));
  86. }
  87. $this->view->title = $this->lang->company->orgView . $this->lang->hyphen . $this->lang->group->edit;
  88. $this->view->group = $this->group->getByID($groupID);
  89. $this->display();
  90. }
  91. /**
  92. * 复制权限分组。
  93. * Copy a group.
  94. *
  95. * @param int $groupID
  96. * @access public
  97. * @return void
  98. */
  99. public function copy($groupID)
  100. {
  101. if(!empty($_POST))
  102. {
  103. $group = form::data($this->config->group->form->copy)->get();
  104. $this->group->copy($groupID, $group, (array)$this->post->options);
  105. if(dao::isError()) return $this->sendError(dao::getError());
  106. return $this->sendSuccess(array('load' => true));
  107. }
  108. $this->view->title = $this->lang->company->orgView . $this->lang->hyphen . $this->lang->group->copy;
  109. $this->view->group = $this->group->getById($groupID);
  110. $this->display();
  111. }
  112. /**
  113. * 视野维护。
  114. * Manage view.
  115. *
  116. * @param int $groupID
  117. * @access public
  118. * @return void
  119. */
  120. public function manageView($groupID)
  121. {
  122. if($_SERVER['REQUEST_METHOD'] == 'POST')
  123. {
  124. $formData = $this->buildUpdateViewForm();
  125. $this->group->updateView($groupID, $formData);
  126. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  127. $link = isInModal() ? 'parent' : $this->createLink('group', 'browse');
  128. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => $link));
  129. }
  130. /* Get the group data by id. */
  131. $group = $this->group->getByID($groupID);
  132. $this->view->title = $this->lang->company->common . $this->lang->hyphen . $group->name . $this->lang->hyphen . $this->lang->group->manageView;
  133. /* Get the list of data sets under administrator permission. */
  134. if(!$this->app->user->admin)
  135. {
  136. $this->app->user->admin = true;
  137. $changeAdmin = true;
  138. }
  139. $executionProject = $this->dao->select('t1.id, t2.name')->from(TABLE_EXECUTION)->alias('t1')
  140. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id')
  141. ->where('t1.deleted')->eq('0')
  142. ->andWhere('t1.id')->in($this->app->user->view->sprints)
  143. ->fetchPairs();
  144. $executions = $this->loadModel('execution')->getPairs(0, 'all', 'all');
  145. foreach($executions as $id => $name)
  146. {
  147. if(isset($executionProject[$id])) $executions[$id] = $executionProject[$id] . ' / ' . trim($name, '/');
  148. }
  149. $this->app->loadLang('action');
  150. $this->view->group = $group;
  151. $this->view->programs = $this->loadModel('program')->getParentPairs('', '', false);
  152. $this->view->projects = $this->loadModel('project')->getPairsByProgram(0, 'all', true, 'order_desc');
  153. $this->view->executions = $executions;
  154. $this->view->products = $this->loadModel('product')->getPairs();
  155. if(!empty($changeAdmin)) $this->app->user->admin = false;
  156. $this->view->navGroup = $this->getNavGroup();
  157. $this->display();
  158. }
  159. /**
  160. * 分配分组权限。
  161. * Manage privleges of a group.
  162. *
  163. * @param string $type byPackage|byGroup|byModule
  164. * @param int $param
  165. * @param string $nav
  166. * @param string $version
  167. * @access public
  168. * @return void
  169. */
  170. public function managePriv($type = 'byPackage', $param = 0, $nav = '', $version = '')
  171. {
  172. if($type == 'byGroup' or $type == 'byPackage') $groupID = $param;
  173. $this->view->type = $type;
  174. if(!empty($_POST))
  175. {
  176. if($type == 'byGroup' || $type == 'byPackage') $result = $this->group->updatePrivByGroup($groupID, $nav, $version);
  177. if($type == 'byModule') $result = $this->group->updatePrivByModule();
  178. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  179. if($type == 'byGroup' or $type == 'byPackage') return $this->send(array('result' => 'success', 'message' => ($result ? $this->lang->group->dependPrivsSaveTip : $this->lang->saveSuccess), 'load' => true));
  180. if($type == 'byModule') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true, 'closeModal' => true));
  181. }
  182. if($this->config->inCompose) $this->groupZen->setDevOpsPrivInCompose();
  183. if($type == 'byGroup' || $type == 'byPackage') $this->groupZen->managePrivByGroup($groupID, $nav, $version);
  184. if($type == 'byModule') $this->groupZen->managePrivByModule();
  185. $this->display();
  186. }
  187. /**
  188. * 维护分组成员。
  189. * Manage members of a group.
  190. *
  191. * @param int $groupID
  192. * @param int $deptID
  193. * @access public
  194. * @return void
  195. */
  196. public function manageMember($groupID, $deptID = 0)
  197. {
  198. if($this->server->request_method == 'POST')
  199. {
  200. $this->group->updateUser($groupID);
  201. return $this->send(array('result' => 'success', 'load' => true, 'closeModal' => true));
  202. }
  203. $group = $this->group->getById($groupID);
  204. $groupUsers = $this->group->getUserPairs($groupID);
  205. $allUsers = $this->loadModel('dept')->getDeptUserPairs($deptID);
  206. $otherUsers = array_diff_assoc($allUsers, $groupUsers);
  207. $outsideUsers = $this->loadModel('user')->getPairs('outside|noclosed|noletter|noempty');
  208. $this->view->title = $this->lang->company->common . $this->lang->hyphen . $group->name . $this->lang->hyphen . $this->lang->group->manageMember;
  209. $this->view->group = $group;
  210. $this->view->deptTree = $this->loadModel('dept')->getTreeMenu($rooteDeptID = 0, array('deptModel', 'createGroupManageMemberLink'), $groupID);
  211. $this->view->groupUsers = $groupUsers;
  212. $this->view->otherUsers = $otherUsers;
  213. $this->view->outsideUsers = array_diff_assoc($outsideUsers, $groupUsers);
  214. $this->view->deptID = $deptID;
  215. $this->view->noUsers = empty($groupUsers) && empty($otherUsers);
  216. $this->display();
  217. }
  218. /**
  219. * 维护项目管理员。
  220. * Manage members of a group.
  221. *
  222. * @param int $groupID
  223. * @param int $deptID
  224. * @access public
  225. * @return void
  226. */
  227. public function manageProjectAdmin($groupID, $deptID = 0)
  228. {
  229. if(!empty($_POST))
  230. {
  231. $this->group->updateProjectAdmin($this->buildProjectAdminForm());
  232. return $this->sendSuccess(array('load' => true));
  233. }
  234. list($programs, $projects, $products, $executions) = $this->group->getObjectForAdminGroup();
  235. $group = $this->group->getById($groupID);
  236. $groupUsers = $this->dao->select('t1.account, t2.realname')->from(TABLE_PROJECTADMIN)->alias('t1')->leftJoin(TABLE_USER)->alias('t2')->on('t1.account = t2.account')->fetchPairs();
  237. $this->view->title = $this->lang->company->common . $this->lang->hyphen . $group->name . $this->lang->hyphen . $this->lang->group->manageMember;
  238. $this->view->allUsers = $groupUsers + $this->loadModel('dept')->getDeptUserPairs($deptID);
  239. $this->view->groupID = $groupID;
  240. $this->view->deptID = $deptID;
  241. $this->view->deptName = $deptID ? $this->dao->findById($deptID)->from(TABLE_DEPT)->fetch('name') : '';
  242. $this->view->programs = $programs;
  243. $this->view->projects = $projects;
  244. $this->view->products = $products;
  245. $this->view->executions = $executions;
  246. $this->view->deptTree = $this->loadModel('dept')->getTreeMenu($rooteDeptID = 0, array('deptModel', 'createManageProjectAdminLink'), $groupID);
  247. $this->view->projectAdmins = $this->group->getProjectAdmins();
  248. $this->display();
  249. }
  250. /**
  251. * 删除一个分组。
  252. * Delete a group.
  253. *
  254. * @param int $groupID
  255. * @access public
  256. * @return void
  257. */
  258. public function delete($groupID)
  259. {
  260. $group = $this->group->getByID($groupID);
  261. $this->group->remove($groupID);
  262. /* if ajax request, send result. */
  263. if(dao::isError())
  264. {
  265. $response['result'] = 'fail';
  266. $response['message'] = dao::getError();
  267. }
  268. else
  269. {
  270. $response['result'] = 'success';
  271. $response['message'] = '';
  272. $response['load'] = $this->app->tab == 'project' ? $this->createLink('project', 'group', "projectID={$group->project}"): inLink('browse');
  273. }
  274. return $this->send($response);
  275. }
  276. /**
  277. * AJAX: Get privs by parents.
  278. *
  279. * @param string $selectedSubset
  280. * @param string $selectedPackages
  281. * @access public
  282. * @return bool
  283. */
  284. public function ajaxGetPrivByParents($selectedSubset, $selectedPackages)
  285. {
  286. $privs = $this->group->getPrivsByParents($selectedSubset, $selectedPackages);
  287. return print(html::select('actions[]', $privs, '', "multiple='multiple' class='form-control'"));
  288. }
  289. /**
  290. * AJAX: Get priv's related priv list.
  291. *
  292. * @access public
  293. * @return int
  294. */
  295. public function ajaxGetRelatedPrivs()
  296. {
  297. $allPrivList = zget($_POST, 'allPrivList');
  298. $selectedPrivList = zget($_POST, 'selectPrivList');
  299. $recommendSelect = zget($_POST, 'recommendSelect');
  300. $relatedPrivData = $this->group->getRelatedPrivs(explode(',', $allPrivList), explode(',', $selectedPrivList), explode(',', $recommendSelect));
  301. $recommendList = array();
  302. foreach($relatedPrivData['recommend'] as $privs)
  303. {
  304. $children = array();
  305. $checkedChildrenCount = 0;
  306. foreach($privs['children'] as $child)
  307. {
  308. if($recommendSelect && strpos(",{$recommendSelect},", ",{$child['id']},") !== false)
  309. {
  310. $child['checked'] = true;
  311. $checkedChildrenCount ++;
  312. }
  313. $children[] = $child;
  314. }
  315. $privs['checked'] = false;
  316. $privs['labelClass'] = '';
  317. if($checkedChildrenCount == count($children)) $privs['checked'] = true;
  318. if($checkedChildrenCount > 0 && $checkedChildrenCount < count($children)) $privs['labelClass'] = 'checkbox-indeterminate-block';
  319. $privs['children'] = $children;
  320. $recommendList[] = $privs;
  321. }
  322. $relatedPrivData['recommend'] = $recommendList;
  323. $this->view->relatedPrivData = $relatedPrivData;
  324. $this->display();
  325. }
  326. }