control.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. /**
  3. * The control file of company 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 company
  9. * @version $Id: control.php 5100 2013-07-12 00:25:23Z zhujinyonging@gmail.com $
  10. * @link https://www.zentao.net
  11. */
  12. class company extends control
  13. {
  14. /**
  15. * 初始化函数,自动加载dept模块。
  16. * Construct function, load dept model auto.
  17. *
  18. * @access public
  19. * @return void
  20. */
  21. public function __construct($moduleName = '', $methodName = '')
  22. {
  23. parent::__construct($moduleName, $methodName);
  24. $this->loadModel('dept');
  25. }
  26. /**
  27. * 首页,跳转到公司部门和人员浏览页面。
  28. * Index page, header to browse.
  29. *
  30. * @access public
  31. * @return void
  32. */
  33. public function index()
  34. {
  35. $this->locate(inlink('browse'));
  36. }
  37. /**
  38. * 浏览公司部门和人员。
  39. * Browse departments and users of a company.
  40. *
  41. * @param string $browseType
  42. * @param string|int $param
  43. * @param string $type
  44. * @param string $orderBy
  45. * @param int $recTotal
  46. * @param int $recPerPage
  47. * @param int $pageID
  48. * @access public
  49. * @return void
  50. */
  51. public function browse($browseType = 'inside', $param = 0, $type = 'bydept', $orderBy = 'id_asc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
  52. {
  53. $deptID = $type == 'bydept' ? (int)$param : 0;
  54. /* Save session. */
  55. $this->session->set('userList', $this->app->getURI(true), 'admin');
  56. /* Set the pager. */
  57. $this->app->loadClass('pager', true);
  58. $pager = pager::init($recTotal, $recPerPage, $pageID);
  59. /* Append id for second sort. */
  60. $sort = common::appendOrder($orderBy);
  61. /* Build the search form. */
  62. $queryID = $type == 'bydept' ? 0 : (int)$param;
  63. $actionURL = inlink('browse', "browseType=all&param=myQueryID&type=bysearch");
  64. $this->company->buildSearchForm($queryID, $actionURL);
  65. /* Get users. */
  66. $users = $this->company->getUsers($browseType, $type, $queryID, $deptID, $sort, $pager);
  67. $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'user');
  68. $this->view->title = $this->lang->company->index . $this->lang->hyphen . $this->lang->dept->common;
  69. $this->view->users = array_map(function($user){unset($user->password);return $user;}, $users);
  70. $this->view->deptTree = $this->dept->getTreeMenu(0, array('deptModel', 'createMemberLink'));
  71. $this->view->userPairs = $this->loadModel('user')->getPairs('noletter|noclosed');
  72. $this->view->orderBy = $orderBy;
  73. $this->view->deptID = $deptID;
  74. $this->view->pager = $pager;
  75. $this->view->param = $param;
  76. $this->view->type = $type;
  77. $this->view->browseType = $browseType;
  78. $this->display();
  79. }
  80. /**
  81. * 编辑公司信息。
  82. * Edit a company.
  83. *
  84. * @access public
  85. * @return void
  86. */
  87. public function edit()
  88. {
  89. if(!empty($_POST))
  90. {
  91. $company = form::data($this->config->company->form->edit)
  92. ->stripTags('name')
  93. ->setIF($this->post->website == 'http://', 'website', '')
  94. ->setIF($this->post->backyard == 'http://', 'backyard', '')
  95. ->get();
  96. if(!$this->company->update($this->app->company->id, $company)) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  97. /* Reset company in session. */
  98. $this->session->set('company', $this->company->getFirst());
  99. return $this->sendSuccess(array('load' => true));
  100. }
  101. $this->view->title = $this->lang->company->common . $this->lang->hyphen . $this->lang->company->edit;
  102. $this->view->company = $this->company->getByID($this->app->company->id);
  103. $this->display();
  104. }
  105. /**
  106. * 访问公司主页。
  107. * View a company.
  108. *
  109. * @access public
  110. * @return void
  111. */
  112. public function view()
  113. {
  114. $this->view->title = $this->lang->company->common . $this->lang->hyphen . $this->lang->company->view;
  115. $this->view->company = $this->company->getByID($this->app->company->id);
  116. $this->display();
  117. }
  118. /**
  119. * 公司动态。
  120. * Company dynamic.
  121. *
  122. * @param string $browseType
  123. * @param string $param
  124. * @param int $recTotal
  125. * @param string $date
  126. * @param string $direction next|pre
  127. * @param int $userID
  128. * @param string|int $productID
  129. * @param string|int $projectID
  130. * @param string|int $executionID
  131. * @access public
  132. * @return void
  133. */
  134. public function dynamic($browseType = 'today', $param = '', $recTotal = 0, $date = '', $direction = 'next', $userID = 0, $productID = 0, $projectID = 0, $executionID = 0)
  135. {
  136. $this->loadModel('action');
  137. /* Save session.*/
  138. $this->companyZen->saveUriIntoSession();
  139. /* Append id for second sort. */
  140. $orderBy = 'date_desc';
  141. if($direction == 'pre') $orderBy = 'date_asc';
  142. $queryID = ($browseType == 'bysearch') ? (int)$param : 0;
  143. $date = empty($date) ? '' : date('Y-m-d', $date);
  144. /* Set product, project, execution and user. */
  145. $account = $this->companyZen->loadAllSearchModule($userID, $queryID);
  146. if($browseType != 'bysearch')
  147. {
  148. $actions = $this->action->getDynamic($account, $browseType, $orderBy, 50, $productID, $projectID, $executionID, $date, $direction);
  149. }
  150. else
  151. {
  152. $actions = $this->action->getDynamicBySearch($queryID, $orderBy, 50, $date, $direction);
  153. }
  154. /* 根据日期补充动态数据。*/
  155. /* Supplement action by date.*/
  156. $dateGroups = $this->action->buildDateGroup($actions, $direction, $orderBy);
  157. if(empty($recTotal) && $dateGroups && $browseType != 'bysearch') $recTotal = $this->action->getDynamicCount($browseType);
  158. /* Assign.*/
  159. $this->view->title = $this->lang->company->common . $this->lang->hyphen . $this->lang->company->dynamic;
  160. $this->view->recTotal = $recTotal;
  161. $this->view->browseType = $browseType;
  162. $this->view->account = $account;
  163. $this->view->productID = $productID;
  164. $this->view->projectID = $projectID;
  165. $this->view->executionID = $executionID;
  166. $this->view->queryID = $queryID;
  167. $this->view->orderBy = $orderBy;
  168. $this->view->userID = $userID;
  169. $this->view->param = $param;
  170. $this->view->dateGroups = $dateGroups;
  171. $this->view->direction = $direction;
  172. $this->display();
  173. }
  174. /**
  175. * Ajax获取外部公司。
  176. * Ajax get outside company.
  177. *
  178. * @access public
  179. * @return void
  180. */
  181. public function ajaxGetOutsideCompany()
  182. {
  183. $companies = $this->company->getOutsideCompanies();
  184. $items = array();
  185. foreach($companies as $companyID => $companyName) $items[] = array('text' => $companyName, 'value' => $companyID, 'keys' => $companyName);
  186. return print(json_encode($items));
  187. }
  188. }