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

/www/include/configuration/configObject/traps/listTraps.php

https://gitlab.com/florianocomercial/centreon
PHP | 180 lines | 102 code | 19 blank | 59 comment | 26 complexity | 80fa14ac34175aebf99ee96b51262cfc 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. * SVN : $URL$
  35. * SVN : $Id$
  36. *
  37. */
  38. if (!isset($oreon))
  39. exit();
  40. include_once("./class/centreonUtils.class.php");
  41. include("./include/common/autoNumLimit.php");
  42. $mnftr_id = NULL;
  43. $tabStatus = array(0 => _("OK"), 1 => _("Warning"), 2 => _("Critical"), 3 => _("Unknown"), 4 => _("Pending"));
  44. $SearchTool = NULL;
  45. if (isset($_POST['searchT']) && $_POST['searchT']) {
  46. $search = $_POST['searchT'];
  47. $SearchTool = "WHERE traps_oid LIKE '%".htmlentities($search, ENT_QUOTES, "UTF-8")."%' OR traps_name LIKE '%".htmlentities($search, ENT_QUOTES, "UTF-8")."%' OR manufacturer_id IN (SELECT id FROM traps_vendor WHERE alias LIKE '%".htmlentities($search, ENT_QUOTES, "UTF-8")."%')";
  48. }
  49. $DBRESULT = $pearDB->query("SELECT COUNT(*) FROM traps $SearchTool");
  50. $tmp = $DBRESULT->fetchRow();
  51. $rows = $tmp["COUNT(*)"];
  52. include("./include/common/checkPagination.php");
  53. /*
  54. * Smarty template Init
  55. */
  56. $tpl = new Smarty();
  57. $tpl = initSmartyTpl($path, $tpl);
  58. /* Access level */
  59. ($centreon->user->access->page($p) == 1) ? $lvl_access = 'w' : $lvl_access = 'r';
  60. $tpl->assign('mode_access', $lvl_access);
  61. /*
  62. * start header menu
  63. */
  64. $tpl->assign("headerMenu_icone", "<img src='./img/icones/16x16/pin_red.gif'>");
  65. $tpl->assign("headerMenu_name", _("Name"));
  66. $tpl->assign("headerMenu_desc", _("OID"));
  67. $tpl->assign("headerMenu_status", _("Status"));
  68. $tpl->assign("headerMenu_manufacturer", _("Vendor Name"));
  69. $tpl->assign("headerMenu_args", _("Output Message"));
  70. $tpl->assign("headerMenu_options", _("Options"));
  71. /*
  72. * List of elements - Depends on different criteria
  73. */
  74. $rq = "SELECT * FROM traps $SearchTool ORDER BY manufacturer_id, traps_name LIMIT ".$num * $limit.", ".$limit;
  75. $DBRESULT = $pearDB->query($rq);
  76. $form = new HTML_QuickForm('form', 'POST', "?p=".$p);
  77. /*
  78. * Different style between each lines
  79. */
  80. $style = "one";
  81. /*
  82. * Fill a tab with a mutlidimensionnal Array we put in $tpl
  83. */
  84. $elemArr = array();
  85. for ($i = 0; $trap = $DBRESULT->fetchRow(); $i++) {
  86. $trap = array_map(array("CentreonUtils","escapeSecure"),$trap);
  87. $moptions = "";
  88. $selectedElements = $form->addElement('checkbox', "select[".$trap['traps_id']."]");
  89. $moptions .= "&nbsp;&nbsp;&nbsp;";
  90. $moptions .= "<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[".$trap['traps_id']."]'></input>";
  91. $DBRESULT2 = $pearDB->query("select alias from traps_vendor where id='".$trap['manufacturer_id']."' LIMIT 1");
  92. $mnftr = $DBRESULT2->fetchRow();
  93. $DBRESULT2->free();
  94. $elemArr[$i] = array("MenuClass" => "list_".$style,
  95. "RowMenu_select" => $selectedElements->toHtml(),
  96. "RowMenu_name" => myDecode($trap["traps_name"]),
  97. "RowMenu_link" => "?p=".$p."&o=c&traps_id=".$trap['traps_id'],
  98. "RowMenu_desc" => myDecode(substr($trap["traps_oid"], 0, 40)),
  99. "RowMenu_status" => $tabStatus[$trap["traps_status"]],
  100. "RowMenu_args" => myDecode($trap["traps_args"]),
  101. "RowMenu_manufacturer" => myDecode($mnftr["alias"]),
  102. "RowMenu_options" => $moptions);
  103. $style != "two" ? $style = "two" : $style = "one";
  104. }
  105. $tpl->assign("elemArr", $elemArr);
  106. #Different messages we put in the template
  107. $tpl->assign('msg', array ("addL"=>"?p=".$p."&o=a", "addT"=>_("Add"), "delConfirm"=>_("Do you confirm the deletion ?")));
  108. #
  109. ##Toolbar select
  110. #
  111. ?>
  112. <script type="text/javascript">
  113. function setO(_i) {
  114. document.forms['form'].elements['o'].value = _i;
  115. }
  116. </SCRIPT>
  117. <?php
  118. $attrs1 = array(
  119. 'onchange'=>"javascript: " .
  120. " var bChecked = isChecked(); ".
  121. " if (this.form.elements['o1'].selectedIndex != 0 && !bChecked) {".
  122. " alert('"._("Please select one or more items")."'); return false;} " .
  123. "if (this.form.elements['o1'].selectedIndex == 1 && confirm('"._("Do you confirm the duplication ?")."')) {" .
  124. " setO(this.form.elements['o1'].value); submit();} " .
  125. "else if (this.form.elements['o1'].selectedIndex == 2 && confirm('"._("Do you confirm the deletion ?")."')) {" .
  126. " setO(this.form.elements['o1'].value); submit();} " .
  127. "else if (this.form.elements['o1'].selectedIndex == 3) {" .
  128. " setO(this.form.elements['o1'].value); submit();} " .
  129. "");
  130. $form->addElement('select', 'o1', NULL, array(NULL=>_("More actions..."), "m"=>_("Duplicate"), "d"=>_("Delete")), $attrs1);
  131. $form->setDefaults(array('o1' => NULL));
  132. $attrs2 = array(
  133. 'onchange'=>"javascript: " .
  134. " var bChecked = isChecked(); ".
  135. " if (this.form.elements['o2'].selectedIndex != 0 && !bChecked) {".
  136. " alert('"._("Please select one or more items")."'); return false;} " .
  137. "if (this.form.elements['o2'].selectedIndex == 1 && confirm('"._("Do you confirm the duplication ?")."')) {" .
  138. " setO(this.form.elements['o2'].value); submit();} " .
  139. "else if (this.form.elements['o2'].selectedIndex == 2 && confirm('"._("Do you confirm the deletion ?")."')) {" .
  140. " setO(this.form.elements['o2'].value); submit();} " .
  141. "else if (this.form.elements['o2'].selectedIndex == 3) {" .
  142. " setO(this.form.elements['o2'].value); submit();} " .
  143. "");
  144. $form->addElement('select', 'o2', NULL, array(NULL=>_("More actions..."), "m"=>_("Duplicate"), "d"=>_("Delete")), $attrs2);
  145. $form->setDefaults(array('o2' => NULL));
  146. $o1 = $form->getElement('o1');
  147. $o1->setValue(NULL);
  148. $o1->setSelected(NULL);
  149. $o2 = $form->getElement('o2');
  150. $o2->setValue(NULL);
  151. $o2->setSelected(NULL);
  152. $tpl->assign('limit', $limit);
  153. $tpl->assign('searchT', $search);
  154. #
  155. ##Apply a template definition
  156. #
  157. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
  158. $form->accept($renderer);
  159. $tpl->assign('form', $renderer->toArray());
  160. $tpl->display("listTraps.ihtml");
  161. ?>