PageRenderTime 22ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/www/include/configuration/configObject/command/listCommand.php

https://gitlab.com/florianocomercial/centreon
PHP | 232 lines | 138 code | 33 blank | 61 comment | 48 complexity | 3446236eeda9717e71ec410e3dfc4e10 MD5 | raw file
  1. <?php
  2. /*
  3. * Copyright 2005-2015 Centreon
  4. * Centreon is developped by : Julien Mathis and Romain Le Merlus under
  5. * GPL Licence 2.0.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU General Public License as published by the Free Software
  9. * Foundation ; either version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT ANY
  12. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  13. * PARTICULAR PURPOSE. See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; if not, see <http://www.gnu.org/licenses>.
  17. *
  18. * Linking this program statically or dynamically with other modules is making a
  19. * combined work based on this program. Thus, the terms and conditions of the GNU
  20. * General Public License cover the whole combination.
  21. *
  22. * As a special exception, the copyright holders of this program give Centreon
  23. * permission to link this program with independent modules to produce an executable,
  24. * regardless of the license terms of these independent modules, and to copy and
  25. * distribute the resulting executable under terms of Centreon choice, provided that
  26. * Centreon also meet, for each linked independent module, the terms and conditions
  27. * of the license of that module. An independent module is a module which is not
  28. * derived from this program. If you modify this program, you may extend this
  29. * exception to your version of the program, but you are not obliged to do so. If you
  30. * do not wish to do so, delete this exception statement from your version.
  31. *
  32. * For more information : contact@centreon.com
  33. *
  34. */
  35. if (!isset($centreon)) {
  36. exit();
  37. }
  38. include_once("./class/centreonUtils.class.php");
  39. include_once "./include/common/autoNumLimit.php";
  40. if ($type) {
  41. $type_str = " `command_type` = $type";
  42. } else {
  43. $type_str = "";
  44. }
  45. $search = '';
  46. if (isset($_POST['searchC'])){
  47. $search = $_POST['searchC'];
  48. $oreon->command_search = $search;
  49. if ($type_str) {
  50. $type_str = " AND " . $type_str;
  51. }
  52. $req = "SELECT COUNT(*) FROM `command` WHERE `command_name` LIKE '%".htmlentities($search, ENT_QUOTES, "UTF-8")."%' $type_str";
  53. } else {
  54. if (isset($oreon->command_search)) {
  55. $search = $oreon->command_search;
  56. }
  57. if (isset($search) && $search) {
  58. $req = "SELECT COUNT(*) FROM `command` WHERE `command_name` LIKE '%".htmlentities($search, ENT_QUOTES, "UTF-8")."%'";
  59. } else if ($type) {
  60. $req = "SELECT COUNT(*) FROM `command` WHERE $type_str";
  61. } else {
  62. $req ="SELECT COUNT(*) FROM `command`";
  63. }
  64. if ($type_str) {
  65. $type_str = " AND " . $type_str;
  66. }
  67. }
  68. $DBRESULT = $pearDB->query($req);
  69. $tmp = $DBRESULT->fetchRow();
  70. $rows = $tmp["COUNT(*)"];
  71. include_once "./include/common/checkPagination.php";
  72. /*
  73. * Smarty template Init
  74. */
  75. set_magic_quotes_runtime(0);
  76. $tpl = new Smarty();
  77. $tpl = initSmartyTpl($path, $tpl);
  78. /* Access level */
  79. ($centreon->user->access->page($p) == 1) ? $lvl_access = 'w' : $lvl_access = 'r';
  80. $tpl->assign('mode_access', $lvl_access);
  81. /*
  82. * start header menu
  83. */
  84. $tpl->assign("headerMenu_icone", "<img src='./img/icones/16x16/pin_red.gif'>");
  85. $tpl->assign("headerMenu_name", _("Name"));
  86. $tpl->assign("headerMenu_desc", _("Command Line"));
  87. $tpl->assign("headerMenu_type", _("Type"));
  88. $tpl->assign("headerMenu_huse", _("Host Uses"));
  89. $tpl->assign("headerMenu_suse", _("Services Uses"));
  90. $tpl->assign("headerMenu_options", _("Options"));
  91. /*
  92. * List of elements - Depends on different criteria
  93. */
  94. if (isset($search) && $search) {
  95. $rq = "SELECT `command_id`, `command_name`, `command_line`, `command_type` FROM `command` WHERE `command_name` LIKE '%".htmlentities($search, ENT_QUOTES, "UTF-8")."%' $type_str ORDER BY `command_name` LIMIT ".$num * $limit.", ".$limit;
  96. } else if ($type) {
  97. $rq = "SELECT `command_id`, `command_name`, `command_line`, `command_type` FROM `command` WHERE `command_type` = '".$type."' ORDER BY command_name LIMIT ".$num * $limit.", ".$limit;
  98. } else {
  99. $rq = "SELECT `command_id`, `command_name`, `command_line`, `command_type` FROM `command` ORDER BY `command_name` LIMIT ".$num * $limit.", ".$limit;
  100. }
  101. $search = tidySearchKey($search, $advanced_search);
  102. $DBRESULT = $pearDB->query($rq);
  103. $form = new HTML_QuickForm('form', 'POST', "?p=".$p);
  104. /*
  105. * Different style between each lines
  106. */
  107. $style = "one";
  108. /*
  109. * Define command Type table
  110. */
  111. $commandType = array("1" => _("Notification"), "2" => _("Check"), "3" => _("Miscellaneous"), "4" => _("Discovery"));
  112. /*
  113. * Fill a tab with a mutlidimensionnal Array we put in $tpl
  114. */
  115. $elemArr = array();
  116. for ($i = 0; $cmd = $DBRESULT->fetchRow(); $i++) {
  117. $moptions = "";
  118. $selectedElements = $form->addElement('checkbox', "select[".$cmd['command_id']."]");
  119. if (isset($lockedElements[$cmd['command_id']])) {
  120. $selectedElements->setAttribute('disabled', 'disabled');
  121. } else {
  122. $moptions = "&nbsp;<input onKeypress=\"if(event.keyCode > 31 && (event.keyCode < 45 || event.keyCode > 57)) event.returnValue = false; if(event.which > 31 && (event.which < 45 || event.which > 57)) return false;\" maxlength=\"3\" size=\"3\" value='1' style=\"margin-bottom:0px;\" name='dupNbr[".$cmd['command_id']."]'></input>";
  123. }
  124. $elemArr[$i] = array(
  125. "MenuClass" => "list_".$style,
  126. "RowMenu_select" => $selectedElements->toHtml(),
  127. "RowMenu_name" => $cmd["command_name"],
  128. "RowMenu_link" => "?p=".$p."&o=c&command_id=".$cmd['command_id']."&type=".$cmd['command_type'],
  129. "RowMenu_desc" => CentreonUtils::escapeSecure(substr(myDecodeCommand($cmd["command_line"]), 0, 50)) . "...",
  130. "RowMenu_type" => $commandType[$cmd["command_type"]],
  131. "RowMenu_huse" => "<a name='#' title='"._("Host links (host template links)")."'>".getHostNumberUse($cmd['command_id']) . " (".getHostTPLNumberUse($cmd['command_id']).")</a>",
  132. "RowMenu_suse" => "<a name='#' title='"._("Service links (service template links)")."'>".getServiceNumberUse($cmd['command_id']) . " (".getServiceTPLNumberUse($cmd['command_id']).")</a>",
  133. "RowMenu_options" => $moptions);
  134. $style != "two" ? $style = "two" : $style = "one";
  135. }
  136. $tpl->assign("elemArr", $elemArr);
  137. /*
  138. * Different messages we put in the template
  139. */
  140. if (isset($_GET['type']) && $_GET['type'] != "") {
  141. $type = htmlentities($_GET['type'], ENT_QUOTES, "UTF-8");
  142. } else if (!isset($_GET['type'])) {
  143. $type = 2;
  144. }
  145. $tpl->assign('msg', array ("addL"=>"?p=".$p."&o=a&type=".$type, "addT"=>_("Add"), "delConfirm"=>_("Do you confirm the deletion ?")));
  146. $redirectType = $form->addElement('hidden', 'type');
  147. $redirectType->setValue($type);
  148. /*
  149. * Toolbar select
  150. */
  151. $attrs1 = array(
  152. 'onchange'=>"javascript: " .
  153. " var bChecked = isChecked(); ".
  154. " if (this.form.elements['o1'].selectedIndex != 0 && !bChecked) {".
  155. " alert('"._("Please select one or more items")."'); return false;} " .
  156. "if (this.form.elements['o1'].selectedIndex == 1 && confirm('"._("Do you confirm the duplication ?")."')) {" .
  157. " setO(this.form.elements['o1'].value); submit();} " .
  158. "else if (this.form.elements['o1'].selectedIndex == 2 && confirm('"._("Do you confirm the deletion ?")."')) {" .
  159. " setO(this.form.elements['o1'].value); submit();} " .
  160. "else if (this.form.elements['o1'].selectedIndex == 3) {" .
  161. " setO(this.form.elements['o1'].value); submit();} " .
  162. "this.form.elements['o1'].selectedIndex = 0");
  163. $form->addElement('select', 'o1', NULL, array(NULL=>_("More actions..."), "m"=>_("Duplicate"), "d"=>_("Delete")), $attrs1);
  164. $form->setDefaults(array('o1' => NULL));
  165. $attrs2 = array(
  166. 'onchange'=>"javascript: " .
  167. " var bChecked = isChecked(); ".
  168. " if (this.form.elements['o2'].selectedIndex != 0 && !bChecked) {".
  169. " alert('"._("Please select one or more items")."'); return false;} " .
  170. "if (this.form.elements['o2'].selectedIndex == 1 && confirm('"._("Do you confirm the duplication ?")."')) {" .
  171. " setO(this.form.elements['o2'].value); submit();} " .
  172. "else if (this.form.elements['o2'].selectedIndex == 2 && confirm('"._("Do you confirm the deletion ?")."')) {" .
  173. " setO(this.form.elements['o2'].value); submit();} " .
  174. "else if (this.form.elements['o2'].selectedIndex == 3) {" .
  175. " setO(this.form.elements['o2'].value); submit();} " .
  176. "this.form.elements['o2'].selectedIndex = 0");
  177. $form->addElement('select', 'o2', NULL, array(NULL=>_("More actions..."), "m"=>_("Duplicate"), "d"=>_("Delete")), $attrs2);
  178. $form->setDefaults(array('o2' => NULL));
  179. $o1 = $form->getElement('o1');
  180. $o1->setValue(NULL);
  181. $o1->setSelected(NULL);
  182. $o2 = $form->getElement('o2');
  183. $o2->setValue(NULL);
  184. $o2->setSelected(NULL);
  185. ?><script type="text/javascript">
  186. function setO(_i) {
  187. document.forms['form'].elements['o'].value = _i;
  188. }
  189. </script><?php
  190. /*
  191. * Apply a template definition
  192. */
  193. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
  194. $form->accept($renderer);
  195. $tpl->assign('form', $renderer->toArray());
  196. $tpl->assign('limit', $limit);
  197. $tpl->assign('type', $type);
  198. $tpl->assign('searchC', $search);
  199. $tpl->display("listCommand.ihtml");