PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/www/include/configuration/configObject/contact/displayNotification.php

https://gitlab.com/florianocomercial/centreon
PHP | 245 lines | 150 code | 20 blank | 75 comment | 32 complexity | da0020d89e6761fd59dfca9b93c92a99 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: http://svn.centreon.com/branches/centreon-2.3.x/www/include/options/accessLists/resourcesACL/showUsersAccess.php $
  35. * SVN : $Id: showUsersAccess.php 12517 2011-09-20 08:26:49Z shotamchay $
  36. *
  37. */
  38. if (!isset($oreon)) {
  39. exit();
  40. }
  41. require_once _CENTREON_PATH_ . 'www/class/centreonNotification.class.php';
  42. /*
  43. * Connect to Database
  44. */
  45. $broker = $oreon->broker->getBroker();
  46. if ($broker == "broker") {
  47. $pearDBNdo = new CentreonDB("centstorage");
  48. } elseif ($broker == "ndo") {
  49. $pearDBNdo = new CentreonDB("ndo");
  50. }
  51. /**
  52. * Get host icones
  53. */
  54. $ehiCache = array();
  55. $DBRESULT = $pearDB->query("SELECT ehi_icon_image, host_host_id FROM extended_host_information");
  56. while ($ehi = $DBRESULT->fetchRow()) {
  57. $ehiCache[$ehi["host_host_id"]] = $ehi["ehi_icon_image"];
  58. }
  59. $DBRESULT->free();
  60. /**
  61. * Get user list
  62. */
  63. $contact = array("" => null);
  64. $DBRESULT = $pearDB->query("SELECT contact_id, contact_alias FROM contact ORDER BY contact_alias");
  65. while ($ct = $DBRESULT->fetchRow()) {
  66. $contact[$ct["contact_id"]] = $ct["contact_alias"];
  67. }
  68. $DBRESULT->free();
  69. /*
  70. * Object init
  71. */
  72. $mediaObj = new CentreonMedia($pearDB);
  73. $host_method = new CentreonHost($pearDB);
  74. $contactObj = new CentreonContact($pearDB);
  75. /*
  76. * Smarty template Init
  77. */
  78. $tpl = new Smarty();
  79. $tpl = initSmartyTpl($path, $tpl);
  80. /*
  81. * start header menu
  82. */
  83. $tpl->assign("headerMenu_host", _("Hosts"));
  84. $tpl->assign("headerMenu_service", _("Services"));
  85. $tpl->assign("headerMenu_host_esc", _("Escalated Hosts"));
  86. $tpl->assign("headerMenu_service_esc", _("Escalated Services"));
  87. /*
  88. * Different style between each lines
  89. */
  90. $style = "one";
  91. $groups = "''";
  92. if (isset($_POST["contact"])) {
  93. $contact_id = (int)htmlentities($_POST["contact"], ENT_QUOTES, "UTF-8");
  94. } else {
  95. $contact_id = 0;
  96. $formData = array('contact' => $contact_id);
  97. }
  98. $formData = array('contact' => $contact_id);
  99. /*
  100. * Create select form
  101. */
  102. $form = new HTML_QuickForm('select_form', 'GET', "?p=".$p);
  103. $form->addElement('select', 'contact', _("Contact"), $contact, array('id'=>'contact', 'onChange'=>'submit();'));
  104. $form->setDefaults($formData);
  105. /*
  106. * Host escalations
  107. */
  108. $elemArrHostEsc = array();
  109. if ($contact_id) {
  110. $hostEscResources = $contactObj->getNotifications(2, $contact_id);
  111. }
  112. if (isset($hostEscResources)) {
  113. foreach ($hostEscResources as $hostId => $hostName) {
  114. if ((isset($ehiCache[$hostId]) && $ehiCache[$hostId])) {
  115. $host_icone = "./img/media/" . $mediaObj->getFilename($ehiCache[$hostId]);
  116. } elseif ($icone = $host_method->replaceMacroInString($hostId, getMyHostExtendedInfoImage($hostId, "ehi_icon_image", 1))) {
  117. $host_icone = "./img/media/" . $icone;
  118. } else {
  119. $host_icone = "./img/icons/host.png";
  120. }
  121. $moptions = "";
  122. $elemArrHostEsc[] = array("MenuClass" => "list_".$style,
  123. "RowMenu_hico" => $host_icone,
  124. "RowMenu_host" => myDecode($hostName));
  125. $style != "two" ? $style = "two" : $style = "one";
  126. }
  127. }
  128. $tpl->assign("elemArrHostEsc", $elemArrHostEsc);
  129. /*
  130. * Service escalations
  131. */
  132. $elemArrSvcEsc = array();
  133. if ($contact_id) {
  134. $svcEscResources = $contactObj->getNotifications(3, $contact_id);
  135. }
  136. if (isset($svcEscResources)) {
  137. foreach ($svcEscResources as $hostId => $hostTab) {
  138. foreach ($hostTab as $serviceId => $tab) {
  139. if ((isset($ehiCache[$hostId]) && $ehiCache[$hostId])) {
  140. $host_icone = "./img/media/" . $mediaObj->getFilename($ehiCache[$hostId]);
  141. } elseif ($icone = $host_method->replaceMacroInString($hostId, getMyHostExtendedInfoImage($hostId, "ehi_icon_image", 1))) {
  142. $host_icone = "./img/media/" . $icone;
  143. } else {
  144. $host_icone = "./img/icons/host.png";
  145. }
  146. $moptions = "";
  147. $elemArrSvcEsc[] = array("MenuClass" => "list_".$style,
  148. "RowMenu_hico" => $host_icone,
  149. "RowMenu_host" => myDecode($tab['host_name']),
  150. "RowMenu_service" => myDecode($tab['service_description']));
  151. $style != "two" ? $style = "two" : $style = "one";
  152. }
  153. }
  154. }
  155. $tpl->assign("elemArrSvcEsc", $elemArrSvcEsc);
  156. /*
  157. * Hosts
  158. */
  159. $elemArrHost = array();
  160. if ($contact_id) {
  161. $hostResources = $contactObj->getNotifications(0, $contact_id);
  162. }
  163. if (isset($hostResources)) {
  164. foreach ($hostResources as $hostId => $hostName) {
  165. if ((isset($ehiCache[$hostId]) && $ehiCache[$hostId])) {
  166. $host_icone = "./img/media/" . $mediaObj->getFilename($ehiCache[$hostId]);
  167. } elseif ($icone = $host_method->replaceMacroInString($hostId, getMyHostExtendedInfoImage($hostId, "ehi_icon_image", 1))) {
  168. $host_icone = "./img/media/" . $icone;
  169. } else {
  170. $host_icone = "./img/icons/host.png";
  171. }
  172. $moptions = "";
  173. $elemArrHost[] = array("MenuClass" => "list_".$style,
  174. "RowMenu_hico" => $host_icone,
  175. "RowMenu_host" => myDecode($hostName));
  176. $style != "two" ? $style = "two" : $style = "one";
  177. }
  178. }
  179. $tpl->assign("elemArrHost", $elemArrHost);
  180. /*
  181. * Services
  182. */
  183. $elemArrSvc = array();
  184. if ($contact_id) {
  185. $svcResources = $contactObj->getNotifications(1, $contact_id);
  186. }
  187. if (isset($svcResources)) {
  188. foreach ($svcResources as $hostId => $hostTab) {
  189. foreach ($hostTab as $serviceId => $tab) {
  190. if ((isset($ehiCache[$hostId]) && $ehiCache[$hostId])) {
  191. $host_icone = "./img/media/" . $mediaObj->getFilename($ehiCache[$hostId]);
  192. } elseif ($icone = $host_method->replaceMacroInString($hostId, getMyHostExtendedInfoImage($hostId, "ehi_icon_image", 1))) {
  193. $host_icone = "./img/media/" . $icone;
  194. } else {
  195. $host_icone = "./img/icons/host.png";
  196. }
  197. $moptions = "";
  198. $elemArrSvc[] = array("MenuClass" => "list_".$style,
  199. "RowMenu_hico" => $host_icone,
  200. "RowMenu_host" => myDecode($tab['host_name']),
  201. "RowMenu_service" => myDecode($tab['service_description']));
  202. $style != "two" ? $style = "two" : $style = "one";
  203. }
  204. }
  205. }
  206. $tpl->assign("elemArrSvc", $elemArrSvc);
  207. $labels = array('host_escalation' => _('Host escalations'),
  208. 'service_escalation' => _('Service escalations'),
  209. 'host_notifications' => _('Host notifications'),
  210. 'service_notifications' => _('Service notifications'));
  211. /*
  212. * Apply a template definition
  213. */
  214. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
  215. $form->accept($renderer);
  216. $tpl->assign('form', $renderer->toArray());
  217. $tpl->assign('msg', _("The selected user didn't see any resources"));
  218. $tpl->assign('msgSelect', _("Please select a user in order to view his notifications"));
  219. $tpl->assign('msgdisable', _("The selected user is not enable."));
  220. $tpl->assign('p', $p);
  221. $tpl->assign('i', $i);
  222. $tpl->assign('contact', $contact_id);
  223. $tpl->assign('labels', $labels);
  224. $tpl->display("displayNotification.ihtml");
  225. ?>