control.php 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289
  1. <?php
  2. /**
  3. * The control file of user 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 user
  9. * @version $Id: control.php 5005 2013-07-03 08:39:11Z chencongzhi520@gmail.com $
  10. * @link https://www.zentao.net
  11. */
  12. class user extends control
  13. {
  14. /**
  15. * 来源地址。
  16. * Origin url.
  17. *
  18. * @var array
  19. * @access public
  20. */
  21. public $referer = '';
  22. /**
  23. * 查看用户详情。
  24. * View user details.
  25. *
  26. * @param int $userID
  27. * @access public
  28. * @return void
  29. */
  30. public function view($userID)
  31. {
  32. $this->locate($this->createLink('user', 'todo', "userID=$userID&type=all"));
  33. }
  34. /**
  35. * 查看某个用户的待办。
  36. * View user's todo.
  37. *
  38. * @param int $userID
  39. * @param string $type the todo type, all|before|future|thisWeek|thisMonth|thisYear|assignedToOther|cycle
  40. * @param string $status
  41. * @param string $orderBy
  42. * @param int $recTotal
  43. * @param int $recPerPage
  44. * @param int $pageID
  45. * @access public
  46. * @return void
  47. */
  48. public function todo($userID, $type = 'today', $status = 'all', $orderBy = 'date,status,begin', $recTotal = 0, $recPerPage = 20, $pageID = 1)
  49. {
  50. $user = $this->user->getById($userID, 'id');
  51. if(empty($user)) return $this->send(array('result' => 'fail', 'load' => array('alert' => $this->lang->notFound, 'locate' => $this->createLink('my', 'team'))));
  52. if($user->deleted) return $this->send(array('result' => 'fail', 'load' => array('alert' => $this->lang->user->noticeHasDeleted, 'locate' => array('back' => true))));
  53. /* Set this url to session. */
  54. $uri = $this->app->getURI(true);
  55. $this->session->set('todoList', $uri, 'my');
  56. /* Load 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. /* Get users and todos. */
  62. $todos = $this->loadModel('todo')->getList($type, $user->account, $status, 0, $pager, $sort);
  63. $deptID = $this->app->user->admin ? 0 : $this->app->user->dept;
  64. $users = $this->loadModel('dept')->getDeptUserPairs($deptID, 'id');
  65. if(!isset($users[$userID])) return $this->send(array('result' => 'fail', 'load' => array('alert' => $this->lang->user->error->noAccess, 'locate' => array('back' => true))));
  66. $this->view->title = $this->lang->user->common . $this->lang->hyphen . $this->lang->user->todo;
  67. $this->view->deptUsers = $users;
  68. $this->view->todos = $todos;
  69. $this->view->user = $user;
  70. $this->view->type = $type;
  71. $this->view->status = $status;
  72. $this->view->orderBy = $orderBy;
  73. $this->view->pager = $pager;
  74. $this->display();
  75. }
  76. /**
  77. * 查看某个用户的需求。
  78. * View user's stories.
  79. *
  80. * @param int $userID
  81. * @param string $storyType
  82. * @param string $type
  83. * @param string $orderBy
  84. * @param int $recTotal
  85. * @param int $recPerPage
  86. * @param int $pageID
  87. * @access public
  88. * @return void
  89. */
  90. public function story($userID, $storyType = 'story', $type = 'assignedTo', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
  91. {
  92. /* Save session. */
  93. $this->session->set('storyList', $this->app->getURI(true), 'product');
  94. /* Load pager. */
  95. $this->app->loadClass('pager', true);
  96. $pager = pager::init($recTotal, $recPerPage, $pageID);
  97. $user = $this->user->getById($userID, 'id');
  98. $deptID = $this->app->user->admin ? 0 : $this->app->user->dept;
  99. $users = $this->loadModel('dept')->getDeptUserPairs($deptID, 'id');
  100. if(!isset($users[$userID])) $users[$userID] = $user->realname;
  101. /* Append id for second sort. */
  102. $sort = common::appendOrder($orderBy);
  103. if(strpos($sort, 'Title') !== false) $sort = str_replace('Title', '', $sort);
  104. /* Modify story title. */
  105. $this->loadModel('story');
  106. if($storyType == 'requirement') $this->lang->story->title = str_replace($this->lang->SRCommon, $this->lang->URCommon, $this->lang->story->title);
  107. $gradeList = $this->loadModel('story')->getGradeList('');
  108. $gradeGroup = array();
  109. foreach($gradeList as $grade) $gradeGroup[$grade->type][$grade->grade] = $grade->name;
  110. /* Assign. */
  111. $this->view->title = $this->lang->user->common . $this->lang->hyphen . $this->lang->user->story;
  112. $this->view->stories = $this->story->getUserStories($user->account, $type, $sort, $pager, $storyType, false, 'all');
  113. $this->view->users = $this->user->getPairs('noletter');
  114. $this->view->deptUsers = $users;
  115. $this->view->user = $user;
  116. $this->view->storyType = $storyType;
  117. $this->view->type = $type;
  118. $this->view->gradeGroup = $gradeGroup;
  119. $this->view->orderBy = $orderBy;
  120. $this->view->pager = $pager;
  121. $this->display();
  122. }
  123. /**
  124. * 查看某个用户的任务。
  125. * View user's tasks.
  126. *
  127. * @param int $userID
  128. * @param string $type
  129. * @param string $orderBy
  130. * @param int $recTotal
  131. * @param int $recPerPage
  132. * @param int $pageID
  133. * @access public
  134. * @return void
  135. */
  136. public function task($userID, $type = 'assignedTo', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
  137. {
  138. /* Save the session. */
  139. $this->session->set('taskList', $this->app->getURI(true), 'execution');
  140. /* Load pager. */
  141. $this->app->loadClass('pager', true);
  142. $pager = pager::init($recTotal, $recPerPage, $pageID);
  143. $user = $this->user->getById($userID, 'id');
  144. $deptID = $this->app->user->admin ? 0 : $this->app->user->dept;
  145. $users = $this->loadModel('dept')->getDeptUserPairs($deptID, 'id');
  146. if(!isset($users[$userID])) $users[$userID] = $user->realname;
  147. /* Append id for second sort. */
  148. $sort = common::appendOrder($orderBy);
  149. if(strpos($sort, 'Label') !== false) $sort = str_replace('Label', '', $sort);
  150. /* Assign. */
  151. $this->view->title = $this->lang->user->common . $this->lang->hyphen . $this->lang->user->task;
  152. $this->view->tasks = $this->loadModel('task')->getUserTasks($user->account, $type, 0, $pager, $sort);
  153. $this->view->deptUsers = $users;
  154. $this->view->user = $user;
  155. $this->view->type = $type;
  156. $this->view->orderBy = $orderBy;
  157. $this->view->pager = $pager;
  158. $this->display();
  159. }
  160. /**
  161. * 查看某个用户的 bug。
  162. * View user's bugs.
  163. *
  164. * @param int $userID
  165. * @param string $type
  166. * @param string $orderBy
  167. * @param int $recTotal
  168. * @param int $recPerPage
  169. * @param int $pageID
  170. * @access public
  171. * @return void
  172. */
  173. public function bug($userID, $type = 'assignedTo', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
  174. {
  175. /* Save the session. */
  176. $this->session->set('bugList', $this->app->getURI(true), 'qa');
  177. /* Load pager. */
  178. $this->app->loadClass('pager', true);
  179. $pager = pager::init($recTotal, $recPerPage, $pageID);
  180. $user = $this->user->getById($userID, 'id');
  181. $deptID = $this->app->user->admin ? 0 : $this->app->user->dept;
  182. $users = $this->loadModel('dept')->getDeptUserPairs($deptID, 'id');
  183. if(!isset($users[$userID])) $users[$userID] = $user->realname;
  184. /* Load the lang of bug module. */
  185. $this->app->loadLang('bug');
  186. $this->view->title = $this->lang->user->common . $this->lang->hyphen . $this->lang->user->bug;
  187. $this->view->bugs = $this->loadModel('bug')->getUserBugs($user->account, $type, $orderBy, 0, $pager);
  188. $this->view->users = $this->user->getPairs('noletter');
  189. $this->view->deptUsers = $users;
  190. $this->view->user = $user;
  191. $this->view->type = $type;
  192. $this->view->orderBy = $orderBy;
  193. $this->view->pager = $pager;
  194. $this->display();
  195. }
  196. /**
  197. * 查看某个用户的测试单。
  198. * View user's test tasks.
  199. *
  200. * @param int $userID
  201. * @param string $orderBy
  202. * @param int $recTotal
  203. * @param int $recPerPage
  204. * @param int $pageID
  205. * @access public
  206. * @return void
  207. */
  208. public function testtask($userID, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
  209. {
  210. /* Save session. */
  211. $this->session->set('testtaskList', $this->app->getURI(true), 'qa');
  212. $this->session->set('buildList', $this->app->getURI(true), 'execution');
  213. /* Load pager. */
  214. $this->app->loadClass('pager', true);
  215. $pager = pager::init($recTotal, $recPerPage, $pageID);
  216. $user = $this->user->getById($userID, 'id');
  217. $deptID = $this->app->user->admin ? 0 : $this->app->user->dept;
  218. $users = $this->loadModel('dept')->getDeptUserPairs($deptID, 'id');
  219. if(!isset($users[$userID])) $users[$userID] = $user->realname;
  220. $this->app->loadLang('testcase');
  221. /* Append id for second sort. */
  222. $sort = common::appendOrder($orderBy);
  223. $this->view->title = $this->lang->user->common . $this->lang->hyphen . $this->lang->user->testTask;
  224. $this->view->tasks = $this->loadModel('testtask')->getByUser($user->account, $pager, $sort);
  225. $this->view->deptUsers = $users;
  226. $this->view->user = $user;
  227. $this->view->orderBy = $orderBy;
  228. $this->view->pager = $pager;
  229. $this->display();
  230. }
  231. /**
  232. * 查看某个用户的测试用例。
  233. * View user's test cases.
  234. *
  235. * @param int $userID
  236. * @param string $type
  237. * @param string $orderBy
  238. * @param int $recTotal
  239. * @param int $recPerPage
  240. * @param int $pageID
  241. * @access public
  242. * @return void
  243. */
  244. public function testcase($userID, $type = 'case2Him', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
  245. {
  246. /* Save session, load lang. */
  247. $this->session->set('caseList', $this->app->getURI(true), 'qa');
  248. $this->app->loadLang('testcase');
  249. /* Load pager. */
  250. $this->app->loadClass('pager', true);
  251. $pager = pager::init($recTotal, $recPerPage, $pageID);
  252. $user = $this->user->getById($userID, 'id');
  253. $deptID = $this->app->user->admin ? 0 : $this->app->user->dept;
  254. $users = $this->loadModel('dept')->getDeptUserPairs($deptID, 'id');
  255. if(!isset($users[$userID])) $users[$userID] = $user->realname;
  256. /* Append id for second sort. */
  257. $sort = common::appendOrder($orderBy);
  258. if(strpos($sort, 'caseID') !== false) $sort = str_replace('caseID', 'id', $sort);
  259. $cases = array();
  260. if($type == 'case2Him')
  261. {
  262. $cases = $this->loadModel('testcase')->getByAssignedTo($user->account, '', $sort, $pager);
  263. }
  264. elseif($type == 'caseByHim')
  265. {
  266. $cases = $this->loadModel('testcase')->getByOpenedBy($user->account, '', $sort, $pager);
  267. }
  268. $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'testcase', $type == 'case2Him' ? false : true);
  269. /* Process case for check story changed. */
  270. $cases = $this->loadModel('story')->checkNeedConfirm($cases);
  271. /* Assign. */
  272. $this->view->title = $this->lang->user->common . $this->lang->hyphen . $this->lang->user->testCase;
  273. $this->view->users = $this->user->getPairs('noletter');
  274. $this->view->cases = $cases;
  275. $this->view->deptUsers = $users;
  276. $this->view->user = $user;
  277. $this->view->type = $type;
  278. $this->view->orderBy = $orderBy;
  279. $this->view->pager = $pager;
  280. $this->display();
  281. }
  282. /**
  283. * 查看某个用户的执行。
  284. * View user's executions.
  285. *
  286. * @param int $userID
  287. * @param string $orderBy
  288. * @param int $recTotal
  289. * @param int $recPerPage
  290. * @param int $pageID
  291. * @access public
  292. * @return void
  293. */
  294. public function execution($userID, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
  295. {
  296. $this->session->set('executionList', $this->app->getURI(true), 'execution');
  297. $user = $this->user->getById($userID, 'id');
  298. $deptID = $this->app->user->admin ? 0 : $this->app->user->dept;
  299. $users = $this->loadModel('dept')->getDeptUserPairs($deptID, 'id');
  300. if(!isset($users[$userID])) $users[$userID] = $user->realname;
  301. /* Load pager. */
  302. $this->app->loadClass('pager', true);
  303. $pager = pager::init($recTotal, $recPerPage, $pageID);
  304. $this->view->title = $this->lang->user->common . $this->lang->hyphen . $this->lang->user->execution;
  305. $this->view->executions = $this->user->getExecutions($user->account, 'all', $orderBy, $pager);
  306. $this->view->deptUsers = $users;
  307. $this->view->user = $user;
  308. $this->view->orderBy = $orderBy;
  309. $this->view->pager = $pager;
  310. $this->display();
  311. }
  312. /**
  313. * 查看某个用户的问题。
  314. * View user's issues.
  315. *
  316. * @param int $userID
  317. * @param string $type
  318. * @param string $orderBy
  319. * @param int $recTotal
  320. * @param int $recPerPage
  321. * @param int $pageID
  322. * @access public
  323. * @return void
  324. */
  325. public function issue($userID, $type = 'assignedTo', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
  326. {
  327. $this->session->set('issueList', $this->app->getURI(true), 'project');
  328. $user = $this->user->getById($userID, 'id');
  329. $deptID = $this->app->user->admin ? 0 : $this->app->user->dept;
  330. $users = $this->loadModel('dept')->getDeptUserPairs($deptID, 'id');
  331. if(!isset($users[$userID])) $users[$userID] = $user->realname;
  332. /* Load pager. */
  333. $this->app->loadClass('pager', true);
  334. $pager = pager::init($recTotal, $recPerPage, $pageID);
  335. $this->view->title = $this->lang->user->common . $this->lang->hyphen . $this->lang->user->issue;
  336. $this->view->issues = $this->loadModel('issue')->getUserIssues($type, 0, $user->account, $orderBy, $pager);
  337. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  338. $this->view->deptUsers = $users;
  339. $this->view->user = $user;
  340. $this->view->type = $type;
  341. $this->view->orderBy = $orderBy;
  342. $this->view->pager = $pager;
  343. $this->view->userList = $this->user->setUserList($users, $userID);
  344. $this->display();
  345. }
  346. /**
  347. * 查看某个用户的风险。
  348. * View user's risks.
  349. *
  350. * @param int $userID
  351. * @param string $type
  352. * @param string $orderBy
  353. * @param int $recTotal
  354. * @param int $recPerPage
  355. * @param int $pageID
  356. * @access public
  357. * @return void
  358. */
  359. public function risk($userID, $type = 'assignedTo', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
  360. {
  361. $this->session->set('riskList', $this->app->getURI(true), 'project');
  362. $user = $this->user->getById($userID, 'id');
  363. $deptID = $this->app->user->admin ? 0 : $this->app->user->dept;
  364. $users = $this->loadModel('dept')->getDeptUserPairs($deptID, 'id');
  365. if(!isset($users[$userID])) $users[$userID] = $user->realname;
  366. /* Load pager. */
  367. $this->app->loadClass('pager', true);
  368. $pager = pager::init($recTotal, $recPerPage, $pageID);
  369. $this->view->title = $this->lang->user->common . $this->lang->hyphen . $this->lang->user->risk;
  370. $this->view->risks = $this->loadModel('risk')->getUserRisks($type, $user->account, $orderBy, $pager);
  371. $this->view->deptUsers = $users;
  372. $this->view->user = $user;
  373. $this->view->type = $type;
  374. $this->view->orderBy = $orderBy;
  375. $this->view->pager = $pager;
  376. $this->view->userList = $this->user->setUserList($users, $userID);
  377. $this->display();
  378. }
  379. /**
  380. * 查看某个用户的档案。
  381. * View user's archives.
  382. *
  383. * @param int $userID
  384. * @access public
  385. * @return void
  386. */
  387. public function profile($userID = 0)
  388. {
  389. $user = $userID ? $this->user->getById($userID, 'id') : $this->app->user;
  390. $deptID = $this->app->user->admin ? 0 : $this->app->user->dept;
  391. $users = $this->loadModel('dept')->getDeptUserPairs($deptID, 'id');
  392. if(!isset($users[$userID])) $users[$userID] = $user->realname;
  393. unset($user->password);
  394. $this->view->title = "USER #$user->id $user->account/" . $this->lang->user->profile;
  395. $this->view->groups = $this->loadModel('group')->getByAccount($user->account);
  396. $this->view->deptPath = $this->loadModel('dept')->getParents($user->dept);
  397. $this->view->deptUsers = $users;
  398. $this->view->user = $user;
  399. $this->display();
  400. }
  401. /**
  402. * 添加一个用户。
  403. * Create a user.
  404. *
  405. * @param int $deptID
  406. * @param string $type
  407. * @access public
  408. * @return void
  409. */
  410. public function create($deptID = 0, $type = 'inside')
  411. {
  412. if(!empty($_POST))
  413. {
  414. if($this->app->apiVersion == 'v2')
  415. {
  416. $_POST['password1'] = md5($_POST['password']);
  417. $_POST['password2'] = md5($_POST['password']);
  418. $_POST['passwordLength'] = strlen($_POST['password']);
  419. $_POST['passwordStrength'] = 2;
  420. $_POST['verifyPassword'] = 'PASSWORD';
  421. }
  422. $user = form::data($this->config->user->form->create)
  423. ->setIF($this->post->password1 != false, 'password', substr($this->post->password1, 0, 32))
  424. ->get();
  425. $userID = $this->user->create($user);
  426. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  427. if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $userID));
  428. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->createLink('company', 'browse')));
  429. }
  430. $this->userZen->prepareRolesAndGroups();
  431. $this->view->title = $this->lang->user->create;
  432. $this->view->companies = $this->loadModel('company')->getOutsideCompanies();
  433. $this->view->depts = $this->loadModel('dept')->getOptionMenu();
  434. $this->view->rand = updateSessionRandom();
  435. $this->view->visions = getVisions();
  436. $this->view->deptID = $deptID;
  437. $this->view->type = $type;
  438. $this->display();
  439. }
  440. /**
  441. * 批量添加用户。
  442. * Batch create users.
  443. *
  444. * @param int $deptID
  445. * @param string $type
  446. * @access public
  447. * @return void
  448. */
  449. public function batchCreate($deptID = 0, $type = 'inside')
  450. {
  451. if(!empty($_POST))
  452. {
  453. $users = form::batchData($this->config->user->form->batchCreate)->get();
  454. foreach($users as $user)
  455. {
  456. $user->password = $user->passwordfield;
  457. unset($user->passwordfield);
  458. }
  459. $userIdList = $this->user->batchCreate($users, $this->post->verifyPassword);
  460. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  461. if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'idList' => $userIdList));
  462. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => $this->createLink('company', 'browse')));
  463. }
  464. $this->userZen->prepareRolesAndGroups();
  465. $this->userZen->prepareCustomFields('batchCreate', 'create');
  466. $this->view->title = $this->lang->user->batchCreate;
  467. $this->view->companies = $this->loadModel('company')->getOutsideCompanies();
  468. $this->view->depts = $this->loadModel('dept')->getOptionMenu();
  469. $this->view->rand = updateSessionRandom();
  470. $this->view->visions = getVisions();
  471. $this->view->deptID = $deptID;
  472. $this->view->type = $type;
  473. $this->display();
  474. }
  475. /**
  476. * 编辑一个用户。
  477. * Edit a user.
  478. *
  479. * @param int $userID
  480. * @access public
  481. * @return void
  482. */
  483. public function edit($userID)
  484. {
  485. if(!empty($_POST))
  486. {
  487. if($this->app->apiVersion == 'v2')
  488. {
  489. $_POST['password1'] = isset($_POST['password']) ? md5($_POST['password']) : '';
  490. $_POST['password2'] = isset($_POST['password']) ? md5($_POST['password']) : '';
  491. $_POST['passwordLength'] = isset($_POST['password']) ? strlen($_POST['password']) : 0;
  492. $_POST['passwordStrength'] = 2;
  493. }
  494. $user = form::data($this->config->user->form->edit)
  495. ->setIF($this->post->password1 != false, 'password', substr($this->post->password1, 0, 32))
  496. ->add('id', $userID)
  497. ->get();
  498. $this->user->update($user);
  499. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  500. $link = $this->session->userList ? $this->session->userList : $this->createLink('company', 'browse');
  501. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => $link));
  502. }
  503. $user = $this->user->getById($userID, 'id');
  504. $userGroups = $this->loadModel('group')->getByAccount($user->account, true);
  505. $this->view->title = $this->lang->user->edit;
  506. $this->view->companies = $this->loadModel('company')->getOutsideCompanies();
  507. $this->view->depts = $this->loadModel('dept')->getOptionMenu();
  508. $this->view->groups = $this->user->getGroupsByVisions($user->visions);
  509. $this->view->rand = updateSessionRandom();
  510. $this->view->visions = getVisions();
  511. $this->view->userGroups = array_keys($userGroups);
  512. $this->view->user = $user;
  513. $this->display();
  514. }
  515. /**
  516. * 批量编辑用户。
  517. * Batch edit users.
  518. *
  519. * @param int $deptID
  520. * @param string $type
  521. * @access public
  522. * @return void
  523. */
  524. public function batchEdit($deptID = 0, $type = 'inside')
  525. {
  526. if($this->post->account)
  527. {
  528. $users = form::batchData($this->config->user->form->batchEdit)->get();
  529. $this->user->batchUpdate($users, $this->post->verifyPassword);
  530. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  531. $locate = $this->session->userList ? $this->session->userList : $this->createLink('company', 'browse', "deptID={$deptID}&browseType={$type}");
  532. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => $locate));
  533. }
  534. if(!$this->post->userIdList)
  535. {
  536. $locate = $this->session->userList ? $this->session->userList : $this->createLink('company', 'browse', "deptID={$deptID}&browseType={$type}");
  537. $this->locate($locate);
  538. }
  539. $this->userZen->prepareCustomFields('batchEdit', 'edit');
  540. $this->view->title = $this->lang->user->batchEdit;
  541. $this->view->companies = $this->loadModel('company')->getOutsideCompanies();
  542. $this->view->depts = $this->loadModel('dept')->getOptionMenu();
  543. $this->view->users = $this->user->getListByIdList($this->post->userIdList);
  544. $this->view->rand = updateSessionRandom();
  545. $this->view->visions = getVisions();
  546. $this->view->type = $type;
  547. $this->display();
  548. }
  549. /**
  550. * 删除一个用户。
  551. * Delete a user.
  552. *
  553. * @param int $userID
  554. * @access public
  555. * @return void
  556. */
  557. public function delete($userID)
  558. {
  559. $user = $this->user->getByID($userID, 'id');
  560. if($this->app->user->admin and $this->app->user->account == $user->account) return;
  561. if($_POST)
  562. {
  563. if(!$this->user->checkVerifyPassword($this->post->verifyPassword)) return $this->send(array('result' => 'fail', 'message' => array('verifyPassword' => $this->lang->user->error->verifyPassword)));
  564. $this->user->delete(TABLE_USER, $userID);
  565. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  566. /* if ajax request, send result. */
  567. if($this->viewType == 'json') return $this->send(array('result' => 'success'));
  568. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true, 'closeModal' => true));
  569. }
  570. $this->view->rand = updateSessionRandom();
  571. $this->view->user = $user;
  572. $this->display();
  573. }
  574. /**
  575. * 解锁一个用户。
  576. * Unlock a user.
  577. *
  578. * @param int $userID
  579. * @access public
  580. * @return void
  581. */
  582. public function unlock($userID)
  583. {
  584. $user = $this->user->getById($userID, 'id');
  585. $this->user->cleanLocked($user->account);
  586. return $this->send(array('result' => 'success', 'load' => true));
  587. }
  588. /**
  589. * 解除一个用户和 ZDOO 的绑定。
  590. * Unbind a user from ZDOO.
  591. *
  592. * @param int $userID
  593. * @access public
  594. * @return void
  595. */
  596. public function unbind($userID)
  597. {
  598. $user = $this->user->getById($userID, 'id');
  599. $this->user->unbind($user->account);
  600. return $this->send(array('result' => 'success', 'load' => true));
  601. }
  602. /**
  603. * 用户登录。
  604. * User login.
  605. *
  606. * @param string $referer
  607. * @access public
  608. * @return void
  609. */
  610. public function login($referer = '')
  611. {
  612. $viewType = $this->app->getViewType();
  613. /* 如果禅道没有SN,则设置SN。*/
  614. /* Set sn when zentao has not sn. */
  615. if(empty($this->config->global->sn)) $this->loadModel('setting')->setSN();
  616. /* 重新加载语言项。*/
  617. /* Reload lang. */
  618. if($viewType == 'json' && $this->get->lang && $this->get->lang != $this->app->getClientLang()) $this->userZen->reloadLang($this->get->lang);
  619. /* 检查缓存目录和数据目录访问权限。如果不能访问,终止程序并输出提示信息。*/
  620. /* Check the access permissions of the cache directory and data directory. If you cannot access, terminate the program and output the prompt message. */
  621. $this->userZen->checkDirPermission();
  622. /* 设置来源网址。*/
  623. /* Set referer. */
  624. $this->referer = $this->userZen->setReferer($referer);
  625. /* 预处理变量。*/
  626. /* Prepare variables. */
  627. $loginLink = inlink('login');
  628. $denyLink = inlink('deny');
  629. $locateWebRoot = $this->config->webRoot . (helper::isWithTID() ? "?tid={$this->get->tid}" : '');
  630. $locateReferer = $this->referer;
  631. if(helper::isWithTID() && strpos($locateReferer, 'tid=') === false) $locateReferer .= (strpos($locateReferer, '?') === false ? '?' : '&') . "tid={$this->get->tid}";
  632. /* 如果用户已经登录则返回相关信息。*/
  633. /* If user has logon, return related info. */
  634. if($this->user->isLogon()) return $this->send($this->userZen->responseForLogon($this->referer, $viewType, $loginLink, $denyLink, $locateReferer, $locateWebRoot));
  635. /* 处理登录逻辑。*/
  636. /* Process login. */
  637. $result = $this->userZen->login($this->referer, $viewType, $loginLink, $denyLink, $locateReferer, $locateWebRoot);
  638. if($result)
  639. {
  640. /* Clean output buffer. Remove error message. Ensure that JSON can be parsed. */
  641. $obLevel = ob_get_level();
  642. for($i = 0; $i < $obLevel; $i++) ob_end_clean();
  643. return $this->send($result);
  644. }
  645. helper::setcookie('tab', '', time());
  646. $loginExpired = !(preg_match("/(m=|\/)(index)(&f=|-)(index)(&|-|\.)?/", strtolower($this->referer), $output) || $this->referer == $this->config->webRoot || empty($this->referer) || preg_match("/\/www\/$/", strtolower($this->referer), $output));
  647. if($this->cookie->logout) $loginExpired = false;
  648. $this->view->title = $this->lang->user->login;
  649. $this->view->plugins = $this->loadModel('extension')->getExpiringPlugins(true);
  650. $this->view->unsafeSites = $this->loadModel('misc')->checkOneClickPackage();
  651. $this->view->rand = updateSessionRandom();
  652. $this->view->keepLogin = $this->cookie->keepLogin ? $this->cookie->keepLogin : 'off';
  653. $this->view->sn = zget($this->config->global, 'sn', '');
  654. $this->view->referer = $this->referer;
  655. $this->view->loginExpired = $loginExpired;
  656. $this->display();
  657. }
  658. /**
  659. * 拒绝访问页面。
  660. * Deny page.
  661. *
  662. * @param string $module
  663. * @param string $method
  664. * @param string $referer the referer of the denied page.
  665. * @access public
  666. * @return void
  667. */
  668. public function deny($module, $method, $referer = '')
  669. {
  670. $this->userZen->setReferer();
  671. $module = strtolower($module);
  672. $method = strtolower($method);
  673. $this->app->loadLang('my');
  674. $this->app->loadLang($module);
  675. /* 判断禁止访问的类型。*/
  676. /* Judge the type of deny. */
  677. $denyType = 'nopriv';
  678. $rights = $this->app->user->rights['rights'];
  679. $acls = $this->app->user->rights['acls'];
  680. if(isset($rights[$module][$method]))
  681. {
  682. $menu = isset($this->lang->navGroup->$module) ? $this->lang->navGroup->$module : $module;
  683. $menu = strtolower($menu);
  684. if(!empty($acls['views']) && !isset($acls['views'][$menu])) $denyType = 'noview';
  685. $this->view->menu = $menu;
  686. }
  687. $this->view->title = $this->lang->user->deny;
  688. $this->view->module = $module;
  689. $this->view->method = $method;
  690. $this->view->denyPage = $this->referer; // The denied page.
  691. $this->view->referer = $referer; // The referer of the denied page.
  692. $this->view->denyType = $denyType;
  693. $this->display();
  694. }
  695. /**
  696. * 退出登录。
  697. * User logout.
  698. *
  699. * @param string $referer
  700. * @access public
  701. * @return void
  702. */
  703. public function logout($referer = '')
  704. {
  705. if(!empty($this->app->user->id)) $this->loadModel('action')->create('user', (int)$this->app->user->id, 'logout');
  706. helper::setcookie('za', '', time() - 3600);
  707. helper::setcookie('zp', '', time() - 3600);
  708. helper::setcookie('tab', '', time() - 3600);
  709. helper::setcookie('logout', '1', 0);
  710. $_SESSION = array(); // Clear session in roadrunner.
  711. session_destroy();
  712. if($this->app->getViewType() == 'json') return $this->send(array('status' => 'success'));
  713. return $this->send(array('result' => 'success', 'load' => inlink('login', !empty($referer) ? "referer=$referer" : '')));
  714. }
  715. /**
  716. * 管理员重置密码。
  717. * Admin reset password.
  718. *
  719. * @access public
  720. * @return void
  721. */
  722. public function reset()
  723. {
  724. if(!isset($_SESSION['resetFileName']))
  725. {
  726. $resetFileName = $this->app->getBasePath() . 'tmp' . DIRECTORY_SEPARATOR . uniqid('reset_') . '.txt';
  727. $this->session->set('resetFileName', $resetFileName);
  728. }
  729. $resetFileName = $this->session->resetFileName;
  730. $needCreateFile = !file_exists($resetFileName) || (time() - filemtime($resetFileName)) > 60 * 2;
  731. if($_POST)
  732. {
  733. if($needCreateFile) return $this->send(array('result' => 'success', 'load' => true));
  734. $user = form::data($this->config->user->form->reset)
  735. ->setIF($this->post->password1 != false, 'password', substr($this->post->password1, 0, 32))
  736. ->get();
  737. $result = $this->user->resetPassword($user);
  738. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  739. if(!$result) return $this->send(array('result' => 'fail', 'message' => $this->lang->user->resetFail));
  740. return $this->send(array('result' => 'success', 'message' => $this->lang->user->resetSuccess, 'locate' => inlink('login')));
  741. }
  742. /* 移除真实路径以确保安全。*/
  743. /* Remove the real path to ensure security. */
  744. $filterPath = (getenv('ZENTAO_ENV') == 'zbox-windows' || getenv('ZENTAO_ENV') == 'zbox-linux') ? dirname($this->app->getBasePath(), 3) . DIRECTORY_SEPARATOR : $this->app->getBasePath();
  745. $resetFileName = str_replace($filterPath, '', $resetFileName);
  746. $this->view->title = $this->lang->user->resetPwdByAdmin;
  747. $this->view->rand = updateSessionRandom();
  748. $this->view->needCreateFile = $needCreateFile;
  749. $this->view->resetFileName = $resetFileName;
  750. $this->display();
  751. }
  752. /**
  753. * 忘记密码。
  754. * Forget password.
  755. *
  756. * @access public
  757. * @return void
  758. */
  759. public function forgetPassword()
  760. {
  761. if(!empty($_POST))
  762. {
  763. $data = form::data($this->config->user->form->forgetPassword)->get();
  764. $user = $this->dao->select('*')->from(TABLE_USER)->where('account')->eq($data->account)->fetch();
  765. if(empty($user)) return $this->send(array('result' => 'fail', 'message' => array('account' => $this->lang->user->error->noUser)));
  766. if(empty($user->email)) return $this->send(array('result' => 'fail', 'message' => array('email' => $this->lang->user->error->noEmail)));
  767. if($user->email != $data->email) return $this->send(array('result' => 'fail', 'message' => array('email' => $this->lang->user->error->errorEmail)));
  768. $this->loadModel('mail');
  769. if(!$this->config->mail->turnon) return $this->send(array('result' => 'fail', 'message' => $this->lang->user->error->emailSetting));
  770. $token = bin2hex(random_bytes(16));
  771. $expired = strtotime("+{$this->config->user->resetPasswordTimeout} minutes");
  772. $this->dao->update(TABLE_USER)->set('resetToken')->eq(md5($token))->set('resetExpired')->eq($expired)->where('account')->eq($user->account)->exec();
  773. $result = $this->mail->send($user->account, $this->lang->user->resetPWD, sprintf($this->lang->mail->forgetPassword, commonModel::getSysURL() . inlink('resetPassword', 'token=' . $token)), '', true, array(), true);
  774. if(strstr($result, 'ERROR')) return $this->send(array('result' => 'fail', 'message' => $this->lang->user->error->sendMailFail));
  775. return $this->send(array('result' => 'success', 'message' => $this->lang->user->sendEmailSuccess));
  776. }
  777. $this->view->title = $this->lang->user->resetPwdByMail;
  778. $this->display();
  779. }
  780. /**
  781. * 邮箱重置密码。
  782. * Reset password by email.
  783. *
  784. * @param string $token
  785. * @access public
  786. * @return void
  787. */
  788. public function resetPassword($token)
  789. {
  790. $account = '';
  791. if(preg_match("/^[a-z0-9]{32}$/i", $token))
  792. {
  793. $account = $this->dao->select('account')->from(TABLE_USER)->where('resetToken')->eq(md5($token))->andWhere('resetExpired')->gt(time())->fetch('account');
  794. }
  795. if(!empty($_POST))
  796. {
  797. if(empty($account)) return $this->send(array('result' => 'fail', 'message' => $this->lang->user->linkExpired));
  798. $user = form::data($this->config->user->form->resetPassword)
  799. ->add('account', $account)
  800. ->setIF($this->post->password1 != false, 'password', substr($this->post->password1, 0, 32))
  801. ->get();
  802. $this->user->resetPassword($user);
  803. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  804. $this->dao->update(TABLE_USER)->set('resetToken')->eq('')->set('resetExpired')->eq(0)->where('account')->eq($account)->exec();
  805. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => inlink('login')));
  806. }
  807. $this->view->title = $this->lang->user->resetPWD;
  808. $this->view->rand = updateSessionRandom();
  809. $this->view->expired = empty($account);
  810. $this->display();
  811. }
  812. /**
  813. * 查看某个用户的动态。
  814. * View dynamic of a user.
  815. *
  816. * @param int $userID
  817. * @param string $period
  818. * @param int $recTotal
  819. * @param int $date
  820. * @param string $direction next|pre
  821. * @access public
  822. * @return void
  823. */
  824. public function dynamic($userID, $period = 'today', $recTotal = 0, $date = 0, $direction = 'next')
  825. {
  826. $user = $this->user->getById($userID, 'id');
  827. $deptID = $this->app->user->admin ? 0 : $this->app->user->dept;
  828. $users = $this->loadModel('dept')->getDeptUserPairs($deptID, 'id');
  829. if(!isset($users[$userID])) $users[$userID] = $user->realname;
  830. /* Save session. */
  831. $uri = $this->app->getURI(true);
  832. $this->session->set('productList', $uri, 'product');
  833. $this->session->set('productPlanList', $uri, 'product');
  834. $this->session->set('releaseList', $uri, 'product');
  835. $this->session->set('storyList', $uri, 'product');
  836. $this->session->set('projectList', $uri, 'project');
  837. $this->session->set('executionList', $uri, 'execution');
  838. $this->session->set('taskList', $uri, 'execution');
  839. $this->session->set('buildList', $uri, 'execution');
  840. $this->session->set('bugList', $uri, 'qa');
  841. $this->session->set('caseList', $uri, 'qa');
  842. $this->session->set('testtaskList', $uri, 'qa');
  843. /* Append id for second sort. */
  844. $orderBy = $direction == 'next' ? 'date_desc' : 'date_asc';
  845. $date = $date ? date('Y-m-d', $date) : '';
  846. $actions = $this->loadModel('action')->getDynamicByAccount($user->account, $period, $orderBy, 50, $date, $direction);
  847. $dateGroups = $this->action->buildDateGroup($actions, $direction, $period);
  848. if(empty($recTotal) && $dateGroups) $recTotal = $this->action->getDynamicCount($period);
  849. /* Assign. */
  850. $this->view->title = $this->lang->user->common . $this->lang->hyphen . $this->lang->user->dynamic;
  851. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  852. $this->view->dateGroups = $dateGroups;
  853. $this->view->deptUsers = $users;
  854. $this->view->user = $user;
  855. $this->view->period = $period;
  856. $this->view->recTotal = $recTotal;
  857. $this->display();
  858. }
  859. /**
  860. * 裁剪头像。
  861. * Crop avatar.
  862. *
  863. * @param int $imageID
  864. * @access public
  865. * @return void
  866. */
  867. public function cropAvatar($imageID)
  868. {
  869. $image = $this->loadModel('file')->getByID($imageID);
  870. if(!empty($_POST))
  871. {
  872. $size = form::data($this->config->user->form->cropAvatar)->get();
  873. $this->file->cropImage($image->realPath, $image->realPath, $size->left, $size->top, $size->right - $size->left, $size->bottom - $size->top, $size->scaled ? $size->scaleWidth : 0, $size->scaled ? $size->scaleHeight : 0);
  874. $this->app->user->avatar = $image->webPath;
  875. $this->session->set('user', $this->app->user);
  876. $this->dao->update(TABLE_USER)->set('avatar')->eq($image->webPath)->where('account')->eq($this->app->user->account)->exec();
  877. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'callback' => "loadModal('" . $this->createLink('my', 'profile') . "', 'profile', {}, $.apps.updateUserToolbar);"));
  878. }
  879. $this->view->title = $this->lang->user->cropAvatar;
  880. $this->view->image = $image;
  881. $this->display();
  882. }
  883. /**
  884. * AJAX: get users from a contact list.
  885. *
  886. * @param int $contactListID
  887. * @param string $dropdownName mailto|whitelist
  888. * @access public
  889. * @return string
  890. */
  891. public function ajaxGetOldContactUsers($contactListID, $dropdownName = 'mailto')
  892. {
  893. $list = $contactListID ? $this->user->getContactListByID($contactListID) : '';
  894. $attr = $dropdownName == 'mailto' ? "data-placeholder='{$this->lang->chooseUsersToMail}' data-drop-direction='bottom'" : '';
  895. $users = $this->user->getPairs('devfirst|nodeleted|noclosed', $list ? $list->userList : '', $this->config->maxCount);
  896. if(isset($this->config->user->moreLink)) $this->config->moreLinks[$dropdownName . "[]"] = $this->config->user->moreLink;
  897. $defaultUsers = empty($contactListID) ? '' : $list->userList;
  898. return print(html::select($dropdownName . "[]", $users, $defaultUsers, "class='form-control chosen' multiple $attr"));
  899. }
  900. /**
  901. * AJAX: 获取某个联系人列表中包含的用户。
  902. * AJAX: Get users in a contact list.
  903. *
  904. * @param int $contactListID
  905. * @access public
  906. * @return void
  907. */
  908. public function ajaxGetContactUsers($contactListID)
  909. {
  910. if(!$contactListID) return $this->send(array());
  911. $list = $this->user->getContactListByID($contactListID);
  912. if(!$list) return $this->send(array());
  913. $accountList = array_filter(array_unique(explode(',', $list->userList)));
  914. if(!$accountList) return $this->send(array());
  915. $users = $this->user->getListByAccounts($accountList);
  916. $items = array_map(function($user){return array('text' => $user->realname, 'value' => $user->account);}, $users);
  917. return $this->send(array_values($items));
  918. }
  919. /**
  920. * Ajax: 获取当前用户可以查看的联系人列表。
  921. * Ajax: Get contact lists that current user can view.
  922. *
  923. * @access public
  924. * @return void
  925. */
  926. public function ajaxGetContactList()
  927. {
  928. $lists = $this->user->getContactLists();
  929. $items = array_map(function($id, $name){return array('text' => $name, 'value' => $id);}, array_keys($lists), $lists);
  930. return $this->send($items);
  931. }
  932. /**
  933. * Ajax get old contact list.
  934. *
  935. * @param $dropdownName mailto|whitelist
  936. * @access public
  937. * @return string
  938. * @param string $dropdownName
  939. */
  940. public function ajaxGetOldContactList($dropdownName = 'mailto')
  941. {
  942. $contactList = $this->user->getContactLists();
  943. if(empty($contactList)) return false;
  944. return print(html::select('contactListMenu', array('' => '') + $contactList, '', "class='form-control' onchange=\"setMailto('$dropdownName', this.value)\""));
  945. }
  946. /**
  947. * AJAX: 获取用户列表。
  948. * AJAX: Get users.
  949. *
  950. * @access public
  951. * @return void
  952. */
  953. public function ajaxGetItems($params = '')
  954. {
  955. $items = array();
  956. $users = $this->user->getPairs($params);
  957. foreach($users as $account => $realname)
  958. {
  959. $items[] = array('text' => $realname, 'value' => $account);
  960. }
  961. return print(json_encode($items));
  962. }
  963. /**
  964. * AJAX: 获取用户模板。
  965. * AJAX: get user templates.
  966. *
  967. * @param string $editor
  968. * @param string $type
  969. * @access public
  970. * @return void
  971. */
  972. public function ajaxGetTemplates($editor, $type)
  973. {
  974. $items = array();
  975. $templates = $this->user->getUserTemplates($type);
  976. foreach($templates as $template)
  977. {
  978. $content = html_entity_decode($template->content);
  979. $content = str_replace("\n", '', $content);
  980. $content = json_encode($content);
  981. $item = array('text' => $template->title, 'data-on' => 'click', 'data-call' => "applyTemplate('$editor', $content)");
  982. if($template->account == $this->app->user->account) $item['trailingIcon'] = array('icon' => 'close', 'data-on' => 'click', 'data-call' => "deleteTemplate($template->id)");
  983. $items[] = $item;
  984. }
  985. echo json_encode($items);
  986. }
  987. /**
  988. * AJAX: 保存一个用户模板。
  989. * AJAX: Save a user template.
  990. *
  991. * @param string $editor
  992. * @param string $type
  993. * @access public
  994. * @return void
  995. */
  996. public function ajaxSaveTemplate($editor, $type)
  997. {
  998. if($_POST)
  999. {
  1000. $template = form::data($this->config->user->form->ajaxSaveTemplate)
  1001. ->add('account', $this->app->user->account)
  1002. ->get();
  1003. $this->user->saveUserTemplate($template);
  1004. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  1005. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true));
  1006. }
  1007. $this->view->title = $this->lang->user->saveTemplate;
  1008. $this->view->editor = $editor;
  1009. $this->view->type = $type;
  1010. $this->display();
  1011. }
  1012. /**
  1013. * AJAX:删除一个用户模板。
  1014. * AJAX: Delete a user template.
  1015. *
  1016. * @param int $templateID
  1017. * @access public
  1018. * @return void
  1019. */
  1020. public function ajaxDeleteTemplate($templateID)
  1021. {
  1022. $this->dao->delete()->from(TABLE_USERTPL)
  1023. ->where('id')->eq($templateID)
  1024. ->beginIF(!$this->app->user->admin)->andWhere('account')->eq($this->app->user->account)->fi()
  1025. ->exec();
  1026. return $this->send(array('result' => 'success', 'message' => $this->lang->deleteSuccess));
  1027. }
  1028. /**
  1029. * Ajax get more user.
  1030. *
  1031. * @access public
  1032. * @return void
  1033. */
  1034. public function ajaxGetMore()
  1035. {
  1036. $params = base64_decode($this->get->params);
  1037. parse_str($params, $parsedParams);
  1038. $usersToAppended = zget($parsedParams, 'usersToAppended', '');
  1039. $users = $this->user->getPairs(zget($parsedParams, 'params', ''));
  1040. $search = $this->get->search;
  1041. $limit = $this->config->maxCount;
  1042. $index = 0;
  1043. $newUsers = array();
  1044. foreach($users as $account => $realname)
  1045. {
  1046. if($index >= $limit) break;
  1047. if($search && stripos($account, $search) === false and stripos($realname, $search) === false) continue;
  1048. if(empty($search) && $usersToAppended && strpos(",{$usersToAppended},", ",{$account},") !== false)
  1049. {
  1050. $newUsers[] = array('value' => $account, 'text' => $realname);
  1051. continue;
  1052. }
  1053. $index ++;
  1054. $newUsers[] = array('value' => $account, 'text' => $realname);
  1055. }
  1056. echo json_encode($newUsers);
  1057. }
  1058. /**
  1059. * AJAX: 根据界面类型获取权限组。
  1060. * AJAX: Get groups by vision.
  1061. *
  1062. * @param string $visions rnd|lite|rnd,lite
  1063. * @access public
  1064. * @return string
  1065. */
  1066. public function ajaxGetGroups($visions)
  1067. {
  1068. if(!$visions) $visions = array($this->config->vision);
  1069. $groups = $this->user->getGroupsByVisions($visions);
  1070. $items = array_map(function($groupID, $groupName){return array('text' => $groupName, 'value' => $groupID);}, array_keys($groups), $groups);
  1071. return $this->send($items);
  1072. }
  1073. /**
  1074. * 刷新用于登录的随机数。
  1075. * Refresh random for login.
  1076. *
  1077. * @access public
  1078. * @return void
  1079. */
  1080. public function refreshRandom()
  1081. {
  1082. $rand = updateSessionRandom();
  1083. if(!empty(ob_get_status(true))) ob_end_clean();
  1084. echo (string)$rand;
  1085. }
  1086. /**
  1087. * Ajax print templates.
  1088. *
  1089. * @param string $type
  1090. * @param string $link
  1091. * @access public
  1092. * @return void
  1093. */
  1094. public function ajaxPrintTemplates($type, $link = '')
  1095. {
  1096. $this->view->link = $link;
  1097. $this->view->type = $type;
  1098. $this->view->templates = $this->user->getUserTemplates($type);
  1099. $this->display();
  1100. }
  1101. /**
  1102. * Save current template.
  1103. *
  1104. * @param string $type
  1105. * @access public
  1106. * @return string
  1107. */
  1108. public function ajaxSaveOldTemplate($type)
  1109. {
  1110. $this->user->saveOldUserTemplate($type);
  1111. if(dao::isError()) echo js::error(dao::getError(), $full = false);
  1112. return print($this->fetch('user', 'ajaxPrintTemplates', "type=$type"));
  1113. }
  1114. }