control.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. /**
  3. * The control file of personnel 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 personnel
  9. * @version $Id$
  10. * @link https://www.zentao.net
  11. */
  12. class personnel extends control
  13. {
  14. /**
  15. * 获取可访问人员列表。
  16. * Get a list of people who can be accessed.
  17. *
  18. * @param int $programID
  19. * @param int $deptID
  20. * @param string $browseType
  21. * @param int $param
  22. * @param int $recTotal
  23. * @param int $recPerPage
  24. * @param int $pageID
  25. * @access public
  26. * @return void
  27. */
  28. public function accessible($programID = 0, $deptID = 0, $browseType = 'browse', $param = 0, $recTotal = 0, $recPerPage = 15, $pageID = 1)
  29. {
  30. common::setMenuVars('program', $programID);
  31. $this->app->loadLang('user');
  32. $program = $this->loadMOdel('program')->getByID($programID);
  33. /* Build the search form. */
  34. $queryID = $browseType == 'bysearch' ? (int)$param : 0;
  35. $actionURL = $this->createLink('personnel', 'accessible', "pargramID={$programID}&deptID={$deptID}&browseType=bysearch&quertID=myQueryID");
  36. $this->config->personnel->accessible->search['params']['role']['values'] = $this->lang->user->roleList;
  37. $this->config->personnel->accessible->search['params']['gender']['values'] = $this->lang->user->genderList;
  38. $this->personnel->buildSearchForm($queryID, $actionURL);
  39. /* Get personnel list. */
  40. $personnelList = $this->personnel->getAccessiblePersonnel($programID, $deptID, $browseType, $queryID);
  41. /* Set the pager. */
  42. $this->app->loadClass('pager', true);
  43. $recTotal = count($personnelList);
  44. $pager = new pager($recTotal, $recPerPage, $pageID);
  45. $personnelList = array_chunk($personnelList, $pager->recPerPage);
  46. $this->view->title = $this->lang->personnel->accessible;
  47. $this->view->deptID = $deptID;
  48. $this->view->programID = $programID;
  49. $this->view->acl = $program->acl;
  50. $this->view->recTotal = $recTotal;
  51. $this->view->recPerPage = $recPerPage;
  52. $this->view->pageID = $pageID;
  53. $this->view->pager = $pager;
  54. $this->view->param = $param;
  55. $this->view->browseType = $browseType;
  56. $this->view->personnelList = empty($personnelList) ? $personnelList : $personnelList[$pageID - 1];
  57. $this->view->deptList = $this->loadModel('dept')->getOptionMenu();
  58. $this->view->dept = $this->dept->getByID($deptID);
  59. $this->view->deptTree = $this->dept->getTreeMenu(0, array(new personnelModel, 'createMemberLink'), $programID);
  60. $this->display();
  61. }
  62. /**
  63. * 投入人员列表。
  64. * Access to investable personnel.
  65. *
  66. * @param int $browseType
  67. * @access public
  68. * @return void
  69. * @param int $programID
  70. */
  71. public function invest($programID = 0)
  72. {
  73. common::setMenuVars('program', $programID);
  74. $this->app->loadLang('user');
  75. $this->view->title = $this->lang->personnel->invest;
  76. $this->view->investList = $this->personnel->getInvest($programID);
  77. $this->view->programID = $programID;
  78. $this->display();
  79. }
  80. /**
  81. * 白名单人员列表。
  82. * White list personnel.
  83. *
  84. * @param int $objectID
  85. * @param string $module personnel|program|project|product
  86. * @param string $objectType program|project|product|sprint
  87. * @param string $orderby
  88. * @param int $recTotal
  89. * @param int $recPerPage
  90. * @param int $pageID
  91. * @param int $programID
  92. * @param string $from project|program|programproject
  93. * @access public
  94. * @return void
  95. * @param string $orderBy
  96. */
  97. public function whitelist($objectID = 0, $module = 'personnel', $objectType = 'program', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1, $programID = 0, $from = '')
  98. {
  99. if($this->app->tab == 'program') common::setMenuVars('program', $objectID);
  100. /* Load lang and set session. */
  101. $this->app->loadLang('user');
  102. $this->app->session->set('whitelistList', $this->app->getURI(true), $this->app->tab);
  103. /* Load pager. */
  104. $this->app->loadClass('pager', true);
  105. $pager = pager::init($recTotal, $recPerPage, $pageID);
  106. /* Set back link. */
  107. $goback = $this->session->projectList ? $this->session->projectList : $this->createLink('program', 'whitelist', "projectID=$objectID");
  108. if($from == 'program') $goback = $this->createLink('program', 'browse');
  109. if($from == 'programproject') $goback = $this->session->programProject ? $this->session->programProject : $this->createLink('program', 'project', "programID={$programID}");
  110. $this->view->title = $this->lang->personnel->whitelist;
  111. $this->view->pager = $pager;
  112. $this->view->objectID = $objectID;
  113. $this->view->objectType = $objectType;
  114. $this->view->whitelist = $this->personnel->getWhitelist($objectID, $objectType, $orderBy, $pager);
  115. $this->view->depts = $this->loadModel('dept')->getOptionMenu();
  116. $this->view->module = $module;
  117. $this->view->goback = $goback;
  118. $this->view->from = $from;
  119. /* Set object. */
  120. if($this->app->tab == 'execution') $objectType = 'execution';
  121. $dropMenuObjectID = $objectType . 'ID';
  122. $this->view->{$dropMenuObjectID} = $objectID;
  123. $this->view->projectProgramID = $programID;
  124. $this->display();
  125. }
  126. /**
  127. * 增加人员到白名单。
  128. * Adding users to the white list.
  129. *
  130. * @param int $objectID
  131. * @param int $deptID
  132. * @param int $copyID
  133. * @param string $objectType program|project|product|sprint
  134. * @param string $module
  135. * @param int $programID
  136. * @param string $from project|program|programproject
  137. * @access public
  138. * @return void
  139. */
  140. public function addWhitelist($objectID = 0, $deptID = 0, $copyID = 0, $objectType = 'program', $module = 'personnel', $programID = 0, $from = '')
  141. {
  142. if($this->app->tab == 'program') common::setMenuVars('program', $objectID);
  143. if($_POST)
  144. {
  145. $formData = form::batchData($this->config->personnel->form->addWhitelist)->get();
  146. $whitelist = array();
  147. foreach($formData as $object) $whitelist[] = $object->account;
  148. $this->personnel->updateWhitelist($whitelist, $objectType, $objectID);
  149. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => $this->getError()));
  150. if($objectType == 'project')
  151. {
  152. $shadowProduct = $this->loadModel('product')->getShadowProductByProject($objectID);
  153. if($shadowProduct) $this->personnel->updateWhitelist($whitelist, 'product', $shadowProduct->id);
  154. }
  155. $this->loadModel('action')->create('whitelist', $objectID, 'managedWhitelist', '', $objectType);
  156. $locateLink = $this->createLink($module, 'whitelist', "objectID=$objectID");
  157. $tab = $module == 'program' ? ($from == 'project' || $from == 'my' ? '#open=project' : '#open=program') : '';
  158. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $locateLink . $tab));
  159. }
  160. $this->loadModel('dept');
  161. $deptUsers = empty($deptID) ? array() : $this->dept->getDeptUserPairs($deptID);
  162. $copyObjectType = $objectType;
  163. if($copyObjectType == 'sprint')
  164. {
  165. $object = $this->loadModel('project')->getByID($copyID);
  166. if(!empty($object->type) && $object->type == 'project') $copyObjectType = 'project';
  167. }
  168. $copyUsers = empty($copyID) ? array() : $this->personnel->getWhitelistAccount($copyID, $copyObjectType);
  169. $appendUsers = array_unique($deptUsers + $copyUsers);
  170. $this->personnelZen->setSelectObjectTips($objectID, $objectType, $module);
  171. $this->view->title = $this->lang->personnel->addWhitelist;
  172. $this->view->objectID = $objectID;
  173. $this->view->objectType = $objectType;
  174. $this->view->objects = $this->personnel->getCopiedObjects($objectID, $objectType);
  175. $this->view->module = $module;
  176. $this->view->deptID = $deptID;
  177. $this->view->appendUsers = $appendUsers;
  178. $this->view->whitelist = $this->personnel->getWhitelist($objectID, $objectType);
  179. $this->view->depts = $this->dept->getOptionMenu();
  180. $this->view->users = $this->loadModel('user')->getPairs('noclosed|nodeleted');
  181. $this->view->dept = $this->dept->getByID($deptID);
  182. $this->view->programID = $programID;
  183. $this->view->from = $from;
  184. $this->view->copyID = $copyID;
  185. $this->display();
  186. }
  187. /*
  188. * 从白名单中移除人员。
  189. * Removing users from the white list.
  190. *
  191. * @param int $id
  192. * @access public
  193. * @return void
  194. */
  195. /**
  196. * @param int $id
  197. */
  198. public function unbindWhitelist($id = 0)
  199. {
  200. $acl = $this->dao->select('*')->from(TABLE_ACL)->where('id')->eq($id)->fetch();
  201. if(empty($acl)) return $this->send(array('result' => 'success', 'load' => true));
  202. $this->personnel->unbindWhitelist($acl);
  203. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => $this->getError()));
  204. /* Delete program and project white list. */
  205. if($acl->objectType == 'product')
  206. {
  207. $product = $this->loadModel('product')->getByID($acl->objectID);
  208. if($product->program) $this->personnel->deleteProgramWhitelist($product->program, $acl->account);
  209. }
  210. if($acl->objectType == 'sprint') $this->personnel->deleteProjectWhitelist($acl->objectID, $acl->account);
  211. /* Update user view, and log actions. */
  212. $this->loadModel('user')->updateUserView(array($acl->objectID), $acl->objectType, array($acl->account));
  213. $this->loadModel('action')->create('whitelist', $acl->objectID, 'managedWhitelist', '', $acl->objectType);
  214. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true));
  215. }
  216. }