PageRenderTime 26ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/www/include/configuration/configObject/metaservice_dependency/formMetaServiceDependency.php

https://gitlab.com/florianocomercial/centreon
PHP | 253 lines | 163 code | 23 blank | 67 comment | 36 complexity | c75e25d7dc874d642eec8d6afe421773 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. #
  36. ## Database retrieve information for Dependency
  37. #
  38. $dep = array();
  39. $initialValues = array();
  40. if (($o == "c" || $o == "w") && $dep_id) {
  41. $DBRESULT = $pearDB->query("SELECT * FROM dependency WHERE dep_id = '".$dep_id."' LIMIT 1");
  42. # Set base value
  43. $dep = array_map("myDecode", $DBRESULT->fetchRow());
  44. # Set Notification Failure Criteria
  45. $dep["notification_failure_criteria"] = explode(',', $dep["notification_failure_criteria"]);
  46. foreach ($dep["notification_failure_criteria"] as $key => $value)
  47. $dep["notification_failure_criteria"][trim($value)] = 1;
  48. # Set Execution Failure Criteria
  49. $dep["execution_failure_criteria"] = explode(',', $dep["execution_failure_criteria"]);
  50. foreach ($dep["execution_failure_criteria"] as $key => $value)
  51. $dep["execution_failure_criteria"][trim($value)] = 1;
  52. $DBRESULT->free();
  53. }
  54. #
  55. ## Database retrieve information for differents elements list we need on the page
  56. #
  57. # Meta Service comes from DB -> Store in $metas Array
  58. $metas = array();
  59. $DBRESULT = $pearDB->query("SELECT meta_id, meta_name
  60. FROM meta_service ".
  61. $acl->queryBuilder('WHERE', 'meta_id', $metastr).
  62. " ORDER BY meta_name");
  63. while($meta = $DBRESULT->fetchRow())
  64. $metas[$meta["meta_id"]] = $meta["meta_name"];
  65. $DBRESULT->free();
  66. #
  67. # End of "database-retrieved" information
  68. ##########################################################
  69. ##########################################################
  70. # Var information to format the element
  71. #
  72. $attrsText = array("size"=>"30");
  73. $attrsText2 = array("size"=>"10");
  74. $attrsAdvSelect = array("style" => "width: 300px; height: 150px;");
  75. $attrsTextarea = array("rows"=>"3", "cols"=>"30");
  76. $eTemplate = '<table><tr><td><div class="ams">{label_2}</div>{unselected}</td><td align="center">{add}<br /><br /><br />{remove}</td><td><div class="ams">{label_3}</div>{selected}</td></tr></table>';
  77. $attrMetas = array(
  78. 'datasourceOrigin' => 'ajax',
  79. 'availableDatasetRoute' => './include/common/webServices/rest/internal.php?object=centreon_configuration_meta&action=list',
  80. 'multiple' => true,
  81. 'linkedObject' => 'centreonMeta'
  82. );
  83. #
  84. ## Form begin
  85. #
  86. $form = new HTML_QuickForm('Form', 'post', "?p=".$p);
  87. if ($o == "a")
  88. $form->addElement('header', 'title', _("Add a Dependency"));
  89. else if ($o == "c")
  90. $form->addElement('header', 'title', _("Modify a Dependency"));
  91. else if ($o == "w")
  92. $form->addElement('header', 'title', _("View a Dependency"));
  93. #
  94. ## Dependency basic information
  95. #
  96. $form->addElement('header', 'information', _("Information"));
  97. $form->addElement('text', 'dep_name', _("Name"), $attrsText);
  98. $form->addElement('text', 'dep_description', _("Description"), $attrsText);
  99. $tab = array();
  100. $tab[] = HTML_QuickForm::createElement('radio', 'inherits_parent', null, _("Yes"), '1');
  101. $tab[] = HTML_QuickForm::createElement('radio', 'inherits_parent', null, _("No"), '0');
  102. $form->addGroup($tab, 'inherits_parent', _("Parent relationship"), '&nbsp;');
  103. $form->setDefaults(array('inherits_parent'=>'1'));
  104. $tab = array();
  105. $tab[] = HTML_QuickForm::createElement('checkbox', 'o', '&nbsp;', _("Ok"), array('id' => 'sOk', 'onClick' => 'uncheckAllS(this);'));
  106. $tab[] = HTML_QuickForm::createElement('checkbox', 'w', '&nbsp;', _("Warning"), array('id' => 'sWarning', 'onClick' => 'uncheckAllS(this);'));
  107. $tab[] = HTML_QuickForm::createElement('checkbox', 'u', '&nbsp;', _("Unknown"), array('id' => 'sUnknown', 'onClick' => 'uncheckAllS(this);'));
  108. $tab[] = HTML_QuickForm::createElement('checkbox', 'c', '&nbsp;', _("Critical"), array('id' => 'sCritical', 'onClick' => 'uncheckAllS(this);'));
  109. $tab[] = HTML_QuickForm::createElement('checkbox', 'p', '&nbsp;', _("Pending"), array('id' => 'sPending', 'onClick' => 'uncheckAllS(this);'));
  110. $tab[] = HTML_QuickForm::createElement('checkbox', 'n', '&nbsp;', _("None"), array('id' => 'sNone', 'onClick' => 'uncheckAllS(this);'));
  111. $form->addGroup($tab, 'notification_failure_criteria', _("Notification Failure Criteria"), '&nbsp;&nbsp;');
  112. $tab = array();
  113. $tab[] = HTML_QuickForm::createElement('checkbox', 'o', '&nbsp;', _("Ok"), array('id' => 'sOk2', 'onClick' => 'uncheckAllS2(this);'));
  114. $tab[] = HTML_QuickForm::createElement('checkbox', 'w', '&nbsp;', _("Warning"), array('id' => 'sWarning2', 'onClick' => 'uncheckAllS2(this);'));
  115. $tab[] = HTML_QuickForm::createElement('checkbox', 'u', '&nbsp;', _("Unknown"), array('id' => 'sUnknown2', 'onClick' => 'uncheckAllS2(this);'));
  116. $tab[] = HTML_QuickForm::createElement('checkbox', 'c', '&nbsp;', _("Critical"), array('id' => 'sCritical2', 'onClick' => 'uncheckAllS2(this);'));
  117. $tab[] = HTML_QuickForm::createElement('checkbox', 'p', '&nbsp;', _("Pending"), array('id' => 'sPending2', 'onClick' => 'uncheckAllS2(this);'));
  118. $tab[] = HTML_QuickForm::createElement('checkbox', 'n', '&nbsp;', _("None"), array('id' => 'sNone2', 'onClick' => 'uncheckAllS2(this);'));
  119. $form->addGroup($tab, 'execution_failure_criteria', _("Execution Failure Criteria"), '&nbsp;&nbsp;');
  120. $attrMeta1 = array_merge(
  121. $attrMetas,
  122. array('defaultDatasetRoute' => './include/common/webServices/rest/internal.php?object=centreon_configuration_meta&action=defaultValues&target=dependency&field=dep_msParents&id=' . $dep_id)
  123. );
  124. $form->addElement('select2', 'dep_msParents', _("Meta Service Names"), array(), $attrMeta1);
  125. $attrMeta2 = array_merge(
  126. $attrMetas,
  127. array('defaultDatasetRoute' => './include/common/webServices/rest/internal.php?object=centreon_configuration_meta&action=defaultValues&target=dependency&field=dep_msChilds&id=' . $dep_id)
  128. );
  129. $form->addElement('select2', 'dep_msChilds', _("Dependent Meta Service Names"), array(), $attrMeta2);
  130. $form->addElement('textarea', 'dep_comment', _("Comments"), $attrsTextarea);
  131. $form->addElement('hidden', 'dep_id');
  132. $redirect = $form->addElement('hidden', 'o');
  133. $redirect->setValue($o);
  134. $init = $form->addElement('hidden', 'initialValues');
  135. $init->setValue(serialize($initialValues));
  136. #
  137. ## Form Rules
  138. #
  139. $form->applyFilter('__ALL__', 'myTrim');
  140. $form->addRule('dep_name', _("Compulsory Name"), 'required');
  141. $form->addRule('dep_description', _("Required Field"), 'required');
  142. $form->addRule('dep_msParents', _("Required Field"), 'required');
  143. $form->addRule('dep_msChilds', _("Required Field"), 'required');
  144. $form->registerRule('cycle', 'callback', 'testCycle');
  145. $form->addRule('dep_msChilds', _("Circular Definition"), 'cycle');
  146. $form->registerRule('exist', 'callback', 'testExistence');
  147. $form->addRule('dep_name', _("Name is already in use"), 'exist');
  148. $form->setRequiredNote("<font style='color: red;'>*</font>&nbsp;". _("Required fields"));
  149. #
  150. ##End of form definition
  151. #
  152. # Smarty template Init
  153. $tpl = new Smarty();
  154. $tpl = initSmartyTpl($path, $tpl);
  155. # Just watch a Dependency information
  156. if ($o == "w") {
  157. if ($centreon->user->access->page($p) != 2)
  158. $form->addElement("button", "change", _("Modify"), array("onClick"=>"javascript:window.location.href='?p=".$p."&o=c&dep_id=".$dep_id."'"));
  159. $form->setDefaults($dep);
  160. $form->freeze();
  161. }
  162. # Modify a Dependency information
  163. else if ($o == "c") {
  164. $subC = $form->addElement('submit', 'submitC', _("Save"), array("class" => "btc bt_success"));
  165. $res = $form->addElement('reset', 'reset', _("Reset"), array("class" => "btc bt_default"));
  166. $form->setDefaults($dep);
  167. }
  168. # Add a Dependency information
  169. else if ($o == "a") {
  170. $subA = $form->addElement('submit', 'submitA', _("Save"), array("class" => "btc bt_success"));
  171. $res = $form->addElement('reset', 'reset', _("Reset"), array("class" => "btc bt_default"));
  172. $form->setDefaults(array('inherits_parent', '0'));
  173. }
  174. $tpl->assign("helpattr", 'TITLE, "'._("Help").'", CLOSEBTN, true, FIX, [this, 0, 5], BGCOLOR, "#ffff99", BORDERCOLOR, "orange", TITLEFONTCOLOR, "black", TITLEBGCOLOR, "orange", CLOSEBTNCOLORS, ["","black", "white", "red"], WIDTH, -300, SHADOW, true, TEXTALIGN, "justify"' );
  175. # prepare help texts
  176. $helptext = "";
  177. include_once("include/configuration/configObject/service_dependency/help.php");
  178. foreach ($help as $key => $text) {
  179. $helptext .= '<span style="display:none" id="help:'.$key.'">'.$text.'</span>'."\n";
  180. }
  181. $tpl->assign("helptext", $helptext);
  182. $valid = false;
  183. if ($form->validate()) {
  184. $depObj = $form->getElement('dep_id');
  185. if ($form->getSubmitValue("submitA"))
  186. $depObj->setValue(insertMetaServiceDependencyInDB());
  187. else if ($form->getSubmitValue("submitC"))
  188. updateMetaServiceDependencyInDB($depObj->getValue("dep_id"));
  189. $o = NULL;
  190. $valid = true;
  191. }
  192. if ($valid)
  193. require_once("listMetaServiceDependency.php");
  194. else {
  195. #Apply a template definition
  196. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl, true);
  197. $renderer->setRequiredTemplate('{$label}&nbsp;<font color="red" size="1">*</font>');
  198. $renderer->setErrorTemplate('<font color="red">{$error}</font><br />{$html}');
  199. $form->accept($renderer);
  200. $tpl->assign('form', $renderer->toArray());
  201. $tpl->assign('o', $o);
  202. $tpl->display("formMetaServiceDependency.ihtml");
  203. }
  204. ?>
  205. <script type="text/javascript">
  206. function uncheckAllS(object) {
  207. if (object.id == "sNone" && object.checked) {
  208. document.getElementById('sOk').checked = false;
  209. document.getElementById('sWarning').checked = false;
  210. document.getElementById('sUnknown').checked = false;
  211. document.getElementById('sCritical').checked = false;
  212. document.getElementById('sRecovery').checked = false;
  213. }
  214. else {
  215. document.getElementById('sNone').checked = false;
  216. }
  217. }
  218. function uncheckAllS2(object) {
  219. if (object.id == "sNone2" && object.checked) {
  220. document.getElementById('sOk2').checked = false;
  221. document.getElementById('sWarning2').checked = false;
  222. document.getElementById('sUnknown2').checked = false;
  223. document.getElementById('sCritical2').checked = false;
  224. document.getElementById('sRecovery2').checked = false;
  225. }
  226. else {
  227. document.getElementById('sNone2').checked = false;
  228. }
  229. }
  230. </script>