PageRenderTime 38ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/www/include/configuration/configObject/service_template_model/listServiceTemplateModel.php

https://gitlab.com/florianocomercial/centreon
PHP | 277 lines | 202 code | 23 blank | 52 comment | 46 complexity | dcec6010c8801226c53c675529a30fb6 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. /*
  40. * Object init
  41. */
  42. $mediaObj = new CentreonMedia($pearDB);
  43. include("./include/common/autoNumLimit.php");
  44. $o = "";
  45. $search = '';
  46. if (isset($_POST['searchST']) && $_POST['searchST']) {
  47. $search = $_POST['searchST'];
  48. $search = str_replace('/', "#S#", $search);
  49. $search = str_replace('\\', "#BS#", $search);
  50. $_SESSION['searchST'] = $search;
  51. } else if (isset($_POST['searchST']) && $_POST['searchST'] === '') {
  52. $_SESSION['searchST'] = '';
  53. $search = '';
  54. } else if (isset($_SESSION['searchST']) && $_SESSION['searchST']) {
  55. $search = $_SESSION['searchST'];
  56. }
  57. if($search != ''){
  58. $DBRESULT = $pearDB->query("SELECT COUNT(*) FROM service sv WHERE (sv.service_description LIKE '%".htmlentities($search, ENT_QUOTES, "UTF-8")."%' OR sv.service_alias LIKE '%".htmlentities($search, ENT_QUOTES, "UTF-8")."%') AND sv.service_register = '0'");
  59. }else{
  60. $DBRESULT = $pearDB->query("SELECT COUNT(*) FROM service sv WHERE service_register = '0'");
  61. }
  62. $tmp = $DBRESULT->fetchRow();
  63. $rows = $tmp["COUNT(*)"];
  64. include("./include/common/checkPagination.php");
  65. /*
  66. * Smarty template Init
  67. */
  68. $tpl = new Smarty();
  69. $tpl = initSmartyTpl($path, $tpl);
  70. /* Access level */
  71. ($centreon->user->access->page($p) == 1) ? $lvl_access = 'w' : $lvl_access = 'r';
  72. $tpl->assign('mode_access', $lvl_access);
  73. /*
  74. * start header menu
  75. */
  76. $tpl->assign("headerMenu_icone", "<img src='./img/icones/16x16/pin_red.gif'>");
  77. $tpl->assign("headerMenu_desc", _("Service Templates names"));
  78. $tpl->assign("headerMenu_alias", _("Alias"));
  79. $tpl->assign("headerMenu_retry", _("Scheduling"));
  80. $tpl->assign("headerMenu_parent", _("Parent Templates"));
  81. $tpl->assign("headerMenu_status", _("Status"));
  82. $tpl->assign("headerMenu_options", _("Options"));
  83. /*
  84. * Service Template Model list
  85. */
  86. if ($search)
  87. $rq = "SELECT sv.service_id, sv.service_description, sv.service_alias, sv.service_activate, sv.service_template_model_stm_id FROM service sv WHERE (sv.service_description LIKE '%".htmlentities($search, ENT_QUOTES, "UTF-8")."%' OR sv.service_alias LIKE '%".htmlentities($search, ENT_QUOTES, "UTF-8")."%') AND sv.service_register = '0' ORDER BY service_description LIMIT ".$num * $limit.", ".$limit;
  88. else
  89. $rq = "SELECT sv.service_id, sv.service_description, sv.service_alias, sv.service_activate, sv.service_template_model_stm_id FROM service sv WHERE sv.service_register = '0' ORDER BY service_description LIMIT ".$num * $limit.", ".$limit;
  90. $DBRESULT = $pearDB->query($rq);
  91. $search = tidySearchKey($search, $advanced_search);
  92. $form = new HTML_QuickForm('select_form', 'POST', "?p=".$p);
  93. /*
  94. * Different style between each lines
  95. */
  96. $style = "one";
  97. /*
  98. * Fill a tab with a mutlidimensionnal Array we put in $tpl
  99. */
  100. $elemArr = array();
  101. $interval_length = $oreon->optGen['interval_length'];
  102. $search = str_replace('#S#', "/", $search);
  103. $search = str_replace('#BS#', "\\", $search);
  104. for ($i = 0; $service = $DBRESULT->fetchRow(); $i++) {
  105. $moptions = "";
  106. $selectedElements = $form->addElement('checkbox', "select[".$service['service_id']."]");
  107. if (isset($lockedElements[$service['service_id']])) {
  108. $selectedElements->setAttribute('disabled', 'disabled');
  109. } else {
  110. if ($service["service_activate"]) {
  111. $moptions .= "<a href='main.php?p=".$p."&service_id=".$service['service_id']."&o=u&limit=".$limit."&num=".$num."&search=".$search."'><img src='img/icons/disabled.png' class='ico-14 margin_right' border='0' alt='"._("Disabled")."'></a>&nbsp;&nbsp;";
  112. } else {
  113. $moptions .= "<a href='main.php?p=".$p."&service_id=".$service['service_id']."&o=s&limit=".$limit."&num=".$num."&search=".$search."'><img src='img/icons/enabled.png' class='ico-14 margin_right' border='0' alt='"._("Enabled")."'></a>&nbsp;&nbsp;";
  114. }
  115. $moptions .= "&nbsp;";
  116. $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[".$service['service_id']."]'></input>";
  117. }
  118. /*
  119. * If the description of our Service Model is in the Template definition, we have to catch it, whatever the level of it :-)
  120. */
  121. if (!$service["service_description"]) {
  122. $service["service_description"] = getMyServiceName($service['service_template_model_stm_id']);
  123. }
  124. /*
  125. * TPL List
  126. */
  127. $tplArr = array();
  128. $tplStr = "";
  129. $tplArr = getMyServiceTemplateModels($service["service_template_model_stm_id"]);
  130. if (count($tplArr)) {
  131. foreach($tplArr as $key =>$value) {
  132. $value = str_replace('#S#', "/", $value);
  133. $value = str_replace('#BS#', "\\", $value);
  134. $tplStr .= "&nbsp;->&nbsp;<a href='main.php?p=60206&o=c&service_id=".$key."'>".$value."</a>";
  135. }
  136. }
  137. $service["service_description"] = str_replace("#BR#", "\n", $service["service_description"]);
  138. $service["service_description"] = str_replace("#T#", "\t", $service["service_description"]);
  139. $service["service_description"] = str_replace("#R#", "\r", $service["service_description"]);
  140. $service["service_description"] = str_replace("#S#", '/', $service["service_description"]);
  141. $service["service_description"] = str_replace("#BS#", '\\', $service["service_description"]);
  142. $service["service_alias"] = str_replace("#BR#", "\n", $service["service_alias"]);
  143. $service["service_alias"] = str_replace("#T#", "\t", $service["service_alias"]);
  144. $service["service_alias"] = str_replace("#R#", "\r", $service["service_alias"]);
  145. $service["service_alias"] = str_replace("#S#", '/', $service["service_alias"]);
  146. $service["service_alias"] = str_replace("#BS#", '\\', $service["service_alias"]);
  147. # Get service intervals in seconds
  148. $normal_check_interval = getMyServiceField($service['service_id'], "service_normal_check_interval") * $interval_length;
  149. $retry_check_interval = getMyServiceField($service['service_id'], "service_retry_check_interval") * $interval_length;
  150. if ($normal_check_interval % 60 == 0) {
  151. $normal_units = "min";
  152. $normal_check_interval = $normal_check_interval / 60;
  153. } else {
  154. $normal_units = "sec";
  155. }
  156. if ($retry_check_interval % 60 == 0) {
  157. $retry_units = "min";
  158. $retry_check_interval = $retry_check_interval / 60;
  159. } else {
  160. $retry_units = "sec";
  161. }
  162. if (isset($service['esi_icon_image']) && $service['esi_icon_image']) {
  163. $svc_icon = "./img/media/" . $mediaObj->getFilename($service['esi_icon_image']);
  164. } elseif ($icone = $mediaObj->getFilename(getMyServiceExtendedInfoField($service["service_id"], "esi_icon_image"))) {
  165. $svc_icon = "./img/media/" . $icone;
  166. } else {
  167. $svc_icon = "./img/icons/service.png";
  168. }
  169. $elemArr[$i] = array(
  170. "MenuClass" => "list_".$style,
  171. "RowMenu_select" => $selectedElements->toHtml(),
  172. "RowMenu_desc" => CentreonUtils::escapeSecure($service["service_description"]),
  173. "RowMenu_alias" => CentreonUtils::escapeSecure($service["service_alias"]),
  174. "RowMenu_parent" => CentreonUtils::escapeSecure($tplStr),
  175. "RowMenu_icon" => $svc_icon,
  176. "RowMenu_retry" => CentreonUtils::escapeSecure("$normal_check_interval $normal_units / $retry_check_interval $retry_units"),
  177. "RowMenu_attempts" => getMyServiceField($service['service_id'], "service_max_check_attempts"),
  178. "RowMenu_link" => "?p=".$p."&o=c&service_id=".$service['service_id'],
  179. "RowMenu_status" => $service["service_activate"] ? _("Enabled") : _("Disabled"),
  180. "RowMenu_options" => $moptions
  181. );
  182. $style != "two" ? $style = "two" : $style = "one";
  183. }
  184. $tpl->assign("elemArr", $elemArr);
  185. /*
  186. * Different messages we put in the template
  187. */
  188. $tpl->assign('msg', array ("addL"=>"?p=".$p."&o=a", "addT"=>_("Add"), "delConfirm"=>_("Do you confirm the deletion ?")));
  189. /*
  190. * Toolbar select lgd_more_actions
  191. */
  192. ?>
  193. <script type="text/javascript">
  194. function setO(_i) {
  195. document.forms['form'].elements['o'].value = _i;
  196. }
  197. </SCRIPT>
  198. <?php
  199. $attrs1 = array(
  200. 'onchange'=>"javascript: " .
  201. " var bChecked = isChecked(); ".
  202. " if (this.form.elements['o1'].selectedIndex != 0 && !bChecked) {".
  203. " alert('"._("Please select one or more items")."'); return false;} " .
  204. "if (this.form.elements['o1'].selectedIndex == 1 && confirm('"._("Do you confirm the duplication ?")."')) {" .
  205. " setO(this.form.elements['o1'].value); submit();} " .
  206. "else if (this.form.elements['o1'].selectedIndex == 2 && confirm('"._("Do you confirm the deletion ?")."')) {" .
  207. " setO(this.form.elements['o1'].value); submit();} " .
  208. "else if (this.form.elements['o1'].selectedIndex == 3 || this.form.elements['o1'].selectedIndex == 4 ||this.form.elements['o1'].selectedIndex == 5){" .
  209. " setO(this.form.elements['o1'].value); submit();} " .
  210. "this.form.elements['o1'].selectedIndex = 0");
  211. $form->addElement('select', 'o1', NULL, array(NULL=>_("More actions..."), "m"=>_("Duplicate"), "d"=>_("Delete"), "mc"=>_("Massive Change"), "ms"=>_("Enable"), "mu"=>_("Disable")), $attrs1);
  212. $form->setDefaults(array('o1' => NULL));
  213. $attrs2 = array(
  214. 'onchange'=>"javascript: " .
  215. " var bChecked = isChecked(); ".
  216. " if (this.form.elements['o2'].selectedIndex != 0 && !bChecked) {".
  217. " alert('"._("Please select one or more items")."'); return false;} " .
  218. "if (this.form.elements['o2'].selectedIndex == 1 && confirm('"._("Do you confirm the duplication ?")."')) {" .
  219. " setO(this.form.elements['o2'].value); submit();} " .
  220. "else if (this.form.elements['o2'].selectedIndex == 2 && confirm('"._("Do you confirm the deletion ?")."')) {" .
  221. " setO(this.form.elements['o2'].value); submit();} " .
  222. "else if (this.form.elements['o2'].selectedIndex == 3 || this.form.elements['o2'].selectedIndex == 4 ||this.form.elements['o2'].selectedIndex == 5){" .
  223. " setO(this.form.elements['o2'].value); submit();} " .
  224. "this.form.elements['o1'].selectedIndex = 0");
  225. $form->addElement('select', 'o2', NULL, array(NULL=>_("More actions..."), "m"=>_("Duplicate"), "d"=>_("Delete"), "mc"=>_("Massive Change"), "ms"=>_("Enable"), "mu"=>_("Disable")), $attrs2);
  226. $form->setDefaults(array('o2' => NULL));
  227. $o1 = $form->getElement('o1');
  228. $o1->setValue(NULL);
  229. $o1->setSelected(NULL);
  230. $o2 = $form->getElement('o2');
  231. $o2->setValue(NULL);
  232. $o2->setSelected(NULL);
  233. $tpl->assign('limit', $limit);
  234. $tpl->assign('searchST', $search);
  235. /*
  236. * Apply a template definition
  237. */
  238. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
  239. $form->accept($renderer);
  240. $tpl->assign('form', $renderer->toArray());
  241. $tpl->display("listServiceTemplateModel.ihtml");
  242. ?>