control.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. /**
  3. * The control file of host 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 Jiangxiu Peng <pengjiangxiu@cnezsoft.com>
  8. * @package host
  9. * @version $Id$
  10. * @link https://www.zentao.net
  11. */
  12. class host extends control
  13. {
  14. /**
  15. * 主机列表页面。
  16. * Browse host.
  17. *
  18. * @param string $browseType
  19. * @param int $param
  20. * @param string $orderBy
  21. * @param int $recTotal
  22. * @param int $recPerPage
  23. * @param int $pageID
  24. * @access public
  25. * @return void
  26. */
  27. public function browse($browseType = 'all', $param = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
  28. {
  29. $this->app->session->set('hostList', $this->app->getURI(true));
  30. $this->app->loadClass('pager', true);
  31. $pager = pager::init($recTotal, $recPerPage, $pageID);
  32. $rooms = $this->loadModel('serverroom')->getPairs();
  33. $groups = $this->loadModel('tree')->getOptionMenu(0, 'host');
  34. /* Build the search form. */
  35. $param = (int)$param;
  36. $actionURL = $this->createLink('host', 'browse', "browseType=bySearch&queryID=myQueryID");
  37. $this->config->host->search['actionURL'] = $actionURL;
  38. $this->config->host->search['queryID'] = $param;
  39. $this->config->host->search['onMenuBar'] = 'no';
  40. $this->config->host->search['params']['serverRoom']['values'] = $rooms;
  41. $this->config->host->search['params']['group']['values'] = $groups;
  42. $this->loadModel('search')->setSearchParams($this->config->host->search);
  43. $this->view->title = $this->lang->host->common;
  44. $this->view->hostList = $this->host->getList($browseType, $param, $orderBy, $pager);
  45. $this->view->rooms = $rooms;
  46. $this->view->param = $param;
  47. $this->view->browseType = $browseType;
  48. $this->view->orderBy = $orderBy;
  49. $this->view->pager = $pager;
  50. $this->view->moduleTree = $this->tree->getHostTreeMenu();
  51. $this->view->optionMenu = $groups;
  52. $this->display();
  53. }
  54. /**
  55. * 创建主机。
  56. * Create host.
  57. *
  58. * @param string $osName
  59. * @access public
  60. * @return void
  61. */
  62. public function create()
  63. {
  64. if($_POST)
  65. {
  66. $formData = form::data($this->config->host->form->create)->add('createdBy', $this->app->user->account)->add('createdDate', helper::now())->skipSpecial('name,desc')->get();
  67. $this->hostZen->checkFormData($formData);
  68. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  69. $this->host->create($formData);
  70. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  71. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse')));
  72. }
  73. $this->view->title = $this->lang->host->create;
  74. $this->view->rooms = $this->loadModel('serverroom')->getPairs();
  75. $this->view->optionMenu = $this->loadModel('tree')->getOptionMenu(0, 'host');
  76. $this->display();
  77. }
  78. /**
  79. * 编辑主机。
  80. * Edit host.
  81. *
  82. * @param int $id
  83. * @param string $osName
  84. * @access public
  85. * @return void
  86. */
  87. public function edit($id)
  88. {
  89. if($_POST)
  90. {
  91. $formData = form::data($this->config->host->form->edit)->add('id', $id)->add('editedBy', $this->app->user->account)->add('editedDate', helper::now())->skipSpecial('name,desc')->get();
  92. $this->hostZen->checkFormData($formData);
  93. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  94. $this->host->update($formData);
  95. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  96. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => inlink('browse')));
  97. }
  98. $this->view->title = $this->lang->host->edit;
  99. $this->view->host = $this->host->fetchByID($id);
  100. $this->view->rooms = $this->loadModel('serverroom')->getPairs();
  101. $this->view->optionMenu = $this->loadModel('tree')->getOptionMenu(0, 'host');
  102. $this->display();
  103. }
  104. /**
  105. * 主机详情页面。
  106. * View a host.
  107. *
  108. * @param int $id
  109. * @access public
  110. * @return void
  111. */
  112. public function view($id)
  113. {
  114. $this->view->title = $this->lang->host->view;
  115. $this->view->host = $this->host->fetchByID($id);
  116. $this->view->rooms = $this->loadModel('serverroom')->getPairs();
  117. $this->view->optionMenu = $this->loadModel('tree')->getOptionMenu(0, 'host');
  118. $this->view->actions = $this->loadModel('action')->getList('host', $id);
  119. $this->display();
  120. }
  121. /**
  122. * 删除主机。
  123. * Delete a host.
  124. *
  125. * @param int $id
  126. * @access public
  127. * @return void
  128. */
  129. public function delete($id)
  130. {
  131. $this->host->delete(TABLE_HOST, $id);
  132. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  133. return $this->send(array('result' => 'success', 'message' => $this->lang->host->deletedSuccess, 'load' => inlink('browse'), 'closeModal' => true));
  134. }
  135. /**
  136. * 上架或者下架主机。
  137. * Change host status.
  138. *
  139. * @param int $id
  140. * @param string $status offline|online
  141. * @access public
  142. * @return void
  143. */
  144. public function changeStatus($id, $status = 'online')
  145. {
  146. $this->lang->host->reason = zget($this->lang->host, $status . 'Reason', $this->lang->host->reason);
  147. if($_POST)
  148. {
  149. $formData = form::data($this->config->host->form->changeStatus)->add('id', $id)->add('status', $status)->get();
  150. $this->host->updateStatus($formData);
  151. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  152. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'load' => true));
  153. }
  154. $this->view->title = zget($this->lang->host, $status);
  155. $this->display();
  156. }
  157. /**
  158. * 展示物理拓扑图和分组拓扑图。
  159. * Show host treemap.
  160. *
  161. * @param string $type
  162. * @access public
  163. * @return void
  164. */
  165. public function treemap($type = 'serverroom')
  166. {
  167. $func = 'get' . ucfirst($type) . 'Treemap';
  168. $this->view->title = $this->lang->host->featureBar['browse'][$type];
  169. $this->view->treemap = $this->host->$func();
  170. $this->view->type = $type;
  171. $this->display();
  172. }
  173. /**
  174. * Js获取所有的操作系统列表。
  175. * Get all os list.
  176. *
  177. * @param string $type
  178. * @access public
  179. * @return void
  180. */
  181. public function ajaxGetOS($type)
  182. {
  183. $type .= 'List';
  184. $osList = $this->lang->host->{$type};
  185. if(empty($osList)) return '';
  186. $osItems = array();
  187. foreach($osList as $version => $os) $osItems[] = array('text' => $os, 'value' => $version);
  188. return print(json_encode($osItems));
  189. }
  190. }