PageRenderTime 37ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/www/menu/xml/menuXML.php

https://gitlab.com/florianocomercial/centreon
PHP | 160 lines | 90 code | 24 blank | 46 comment | 9 complexity | 75fb9b959eee0f9117b8edd1d416ed56 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. require_once "../../../config/centreon.config.php";
  36. require_once _CENTREON_PATH_."/www/include/common/common-Func.php";
  37. require_once _CENTREON_PATH_."/www/class/centreonDB.class.php";
  38. require_once _CENTREON_PATH_."/www/class/centreonXML.class.php";
  39. require_once _CENTREON_PATH_."/www/class/centreonACL.class.php";
  40. require_once _CENTREON_PATH_."/www/class/centreon.class.php";
  41. require_once _CENTREON_PATH_."/www/class/centreonSession.class.php";
  42. require_once _CENTREON_PATH_."/www/class/centreonLang.class.php";
  43. require_once _CENTREON_PATH_."/www/class/centreonMenu.class.php";
  44. if (!isset($_SESSION)) {
  45. session_start();
  46. }
  47. $sid = session_id();
  48. if (!isset($sid) || !isset($_GET["menu"])) {
  49. exit();
  50. }
  51. /*
  52. * Create MySQL connector
  53. */
  54. $pearDB = new CentreonDB();
  55. global $pearDB;
  56. /*
  57. * Check Session existence
  58. */
  59. $session = $pearDB->query("SELECT user_id FROM `session` WHERE session_id = '".$pearDB->escape($sid)."'");
  60. if (!$session->numRows()) {
  61. $buffer = new CentreonXML();
  62. $buffer->startElement("root");
  63. $buffer->endElement();
  64. header('Content-Type: text/xml');
  65. header('Cache-Control: no-cache');
  66. $buffer->output();
  67. exit;
  68. }
  69. $centreon = $_SESSION['centreon'];
  70. $centreonLang = new CentreonLang(_CENTREON_PATH_, $centreon);
  71. $centreonLang->bindLang();
  72. $centreonMenu = new CentreonMenu($centreonLang);
  73. /*
  74. * Init XML class
  75. */
  76. $buffer = new CentreonXML();
  77. $user_id = getUserIdFromSID($sid);
  78. if (!$user_id) {
  79. exit();
  80. }
  81. $is_admin = isUserAdmin($sid);
  82. $access = new CentreonACL($user_id, $is_admin);
  83. $topoStr = $access->getTopologyString();
  84. /*
  85. * Get CSS
  86. */
  87. $DBRESULT2 = $pearDB->query("SELECT css_name FROM `css_color_menu` WHERE menu_nb = '".$pearDB->escape($_GET["menu"])."' LIMIT 1");
  88. $menu_style = $DBRESULT2->fetchRow();
  89. ob_start();
  90. if (isset($menu_style['css_name'])){
  91. require_once _CENTREON_PATH_ . "/www/Themes/Centreon-2/Color/" . $menu_style['css_name'];
  92. }
  93. ob_end_clean();
  94. $buffer->startElement("root");
  95. $buffer->writeElement("Menu1ID", $menu1_bgcolor);
  96. $buffer->writeElement("Menu2ID", $menu2_bgcolor);
  97. $buffer->writeElement("Menu1Color", "menu_1");
  98. $buffer->writeElement("Menu2Color", "menu_2");
  99. $rq = "SELECT topology_name, topology_page, topology_url_opt, topology_modules, topology_popup, topology_url FROM topology WHERE topology_parent IS NULL ".$access->queryBuilder("AND", "topology_page", $topoStr) . " AND topology_show = '1' ORDER BY topology_order";
  100. $DBRESULT = $pearDB->query($rq);
  101. $buffer->startElement("level_1");
  102. while ($elem = $DBRESULT->fetchRow()) {
  103. $buffer->startElement("Menu1");
  104. $buffer->writeElement("Menu1Page", $elem["topology_page"]);
  105. $buffer->writeElement("Menu1ClassImg", $_GET["menu"] == $elem["topology_page"] ? $menu1_bgimg : "");
  106. $buffer->writeElement("Menu1Url", "main.php?p=".$elem["topology_page"].$elem["topology_url_opt"]);
  107. $buffer->writeElement("Menu1UrlPopup", $elem["topology_popup"]);
  108. $buffer->writeElement("Menu1UrlPopupOpen", $elem["topology_url"]);
  109. $buffer->writeElement("Menu1Name", $centreonMenu->translate($elem['topology_modules'], $elem['topology_url'], $elem["topology_name"]), 0);
  110. $buffer->writeElement("Menu1Popup", $elem["topology_popup"] ? "true" : "false");
  111. $buffer->endElement();
  112. }
  113. $buffer->endElement();
  114. $rq = "SELECT * FROM topology WHERE topology_parent = '".$pearDB->escape($_GET["menu"])."' " .$access->queryBuilder("AND", "topology_page", $topoStr) .
  115. "AND topology_show = '1' " .
  116. "ORDER BY topology_group, topology_order";
  117. $DBRESULT = $pearDB->query($rq);
  118. $sep = "&nbsp;";
  119. $buffer->startElement("level_2");
  120. while ($elem = $DBRESULT->fetchRow()) {
  121. $buffer->startElement("Menu2");
  122. $buffer->writeElement("Menu2Sep", $sep);
  123. $buffer->writeElement("Menu2Url", "main.php?p=".$elem["topology_page"].$elem["topology_url_opt"]);
  124. $buffer->writeElement("Menu2UrlPopup", $elem["topology_popup"]);
  125. $buffer->writeElement("Menu2UrlPopupOpen", $elem["topology_url"]);
  126. $buffer->writeElement("Menu2Name", $centreonMenu->translate($elem['topology_modules'], $elem['topology_url'], $elem["topology_name"]), 0);
  127. $buffer->writeElement("Menu2Popup", $elem["topology_popup"] ? "true" : "false");
  128. $buffer->endElement();
  129. $sep = "";
  130. }
  131. $buffer->endElement();
  132. $buffer->endElement();
  133. // Send Headers
  134. header('Content-Type: text/xml');
  135. header('Cache-Control: no-cache');
  136. $buffer->output();