control.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * The control file of entry 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 Gang Liu <liugang@cnezsoft.com>
  8. * @package entry
  9. * @version $Id$
  10. * @link https://www.zentao.net
  11. */
  12. class entry extends control
  13. {
  14. /**
  15. * 接入禅道列表页面。
  16. * Browse entries.
  17. *
  18. * @param string $orderBy
  19. * @param int $recTotal
  20. * @param int $recPerPage
  21. * @param int $pageID
  22. * @access public
  23. * @return void
  24. */
  25. public function browse($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 10, $pageID = 1)
  26. {
  27. $this->app->loadClass('pager', true);
  28. $pager = new pager($recTotal, $recPerPage, $pageID);
  29. $this->view->title = $this->lang->entry->common . $this->lang->hyphen . $this->lang->entry->list;
  30. $this->view->entries = $this->entry->getList($orderBy, $pager);
  31. $this->view->orderBy = $orderBy;
  32. $this->view->pager = $pager;
  33. $this->display();
  34. }
  35. /**
  36. * 添加应用接入禅道。
  37. * Create an entry.
  38. *
  39. * @access public
  40. * @return void
  41. */
  42. public function create()
  43. {
  44. if($_POST)
  45. {
  46. if($this->post->freePasswd) unset($this->config->entry->form->create['account']);
  47. $entry = form::data($this->config->entry->form->create)
  48. ->setIF($this->post->allIP === 'on', 'ip', '*')
  49. ->add('createdBy', $this->app->user->account)
  50. ->add('createdDate', helper::now())
  51. ->remove('allIP')
  52. ->get();
  53. $id = $this->entry->create($entry);
  54. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  55. $this->loadModel('action')->create('entry', $id, 'created');
  56. if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $id));
  57. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
  58. }
  59. $this->view->title = $this->lang->entry->common . $this->lang->hyphen . $this->lang->entry->create;
  60. $this->view->users = $this->loadModel('user')->getPairs('nodeleted|noclosed');
  61. $this->display();
  62. }
  63. /**
  64. * 编辑应用。
  65. * Edit an entry.
  66. *
  67. * @param int $id
  68. * @access public
  69. * @return void
  70. */
  71. public function edit($id)
  72. {
  73. if($_POST)
  74. {
  75. if($this->post->freePasswd) unset($this->config->entry->form->edit['account']);
  76. $entry = form::data($this->config->entry->form->edit)
  77. ->setIF($this->post->allIP === 'on', 'ip', '*')
  78. ->add('editedBy', $this->app->user->account)
  79. ->add('editedDate', helper::now())
  80. ->remove('allIP')
  81. ->get();
  82. $changes = $this->entry->update($id, $entry);
  83. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  84. if($changes)
  85. {
  86. $actionID = $this->loadModel('action')->create('entry', $id, 'edited');
  87. $this->action->logHistory($actionID, $changes);
  88. }
  89. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
  90. }
  91. $entry = $this->entry->getById($id);
  92. $this->view->title = $this->lang->entry->edit . $this->lang->hyphen . $entry->name;
  93. $this->view->users = $this->loadModel('user')->getPairs('nodeleted|noclosed');
  94. $this->view->entry = $entry;
  95. $this->display();
  96. }
  97. /**
  98. * 删除应用。
  99. * Delete an entry.
  100. *
  101. * @param int $id
  102. * @access public
  103. * @return void
  104. */
  105. public function delete($id)
  106. {
  107. $this->entry->delete(TABLE_ENTRY, $id);
  108. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  109. return $this->send(array('result' => 'success', 'load' => true));
  110. }
  111. /**
  112. * 浏览日志。
  113. * Browse logs of an entry.
  114. *
  115. * @param int $id
  116. * @param string $orderBy
  117. * @param int $recTotal
  118. * @param int $recPerPage
  119. * @param int $pageID
  120. * @access public
  121. * @return void
  122. */
  123. public function log($id, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
  124. {
  125. $this->app->loadClass('pager', true);
  126. $pager = new pager($recTotal, $recPerPage, $pageID);
  127. $entry = $this->entry->getByID($id);
  128. $this->view->title = $this->lang->entry->log . $this->lang->hyphen . $entry->name;
  129. $this->view->logs = $this->entry->getLogs($id, $orderBy, $pager);
  130. $this->view->entry = $entry;
  131. $this->view->orderBy = $orderBy;
  132. $this->view->pager = $pager;
  133. $this->display();
  134. }
  135. }