PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/www/include/options/oreon/modules/formModule.php

https://gitlab.com/florianocomercial/centreon
PHP | 224 lines | 145 code | 15 blank | 64 comment | 32 complexity | 766e5fb249b541e44ca062e1b9c549bf 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. }
  41. /*
  42. * Smarty template Init
  43. */
  44. $tpl = new Smarty();
  45. $tpl = initSmartyTpl($path, $tpl);
  46. $tpl->assign("headerMenu_title", _("Module Information"));
  47. $tpl->assign("headerMenu_title2", _("Upgrade Information"));
  48. $tpl->assign("headerMenu_rname", _("Real name"));
  49. $tpl->assign("headerMenu_release", _("Release"));
  50. $tpl->assign("headerMenu_release_from", _("Base release"));
  51. $tpl->assign("headerMenu_release_to", _("Final release"));
  52. $tpl->assign("headerMenu_author", _("Author"));
  53. $tpl->assign("headerMenu_infos", _("Additional Information"));
  54. $tpl->assign("headerMenu_isinstalled", _("Installed"));
  55. $tpl->assign("headerMenu_isvalid", _("Valid for an upgrade"));
  56. /*
  57. * "Name" case, it's not a module which is installed
  58. */
  59. if ($operationType === 'install') {
  60. $flag = false;
  61. include_once(_CENTREON_PATH_ . "www/modules/".$name."/conf.php");
  62. $tpl->assign("module_rname", $module_conf[$name]["rname"]);
  63. $tpl->assign("module_release", $module_conf[$name]["mod_release"]);
  64. $tpl->assign("module_author", $module_conf[$name]["author"]);
  65. $tpl->assign("module_infos", $module_conf[$name]["infos"]);
  66. if (is_dir(_CENTREON_PATH_ . "www/modules/".$name."/infos") && is_file("./modules/".$name."/infos/infos.txt")) {
  67. $infos_streams = file(_CENTREON_PATH_ . "www/modules/".$name."/infos/infos.txt");
  68. $infos_streams = implode("<br />", $infos_streams);
  69. $tpl->assign("module_infosTxt", $infos_streams);
  70. } else {
  71. $tpl->assign("module_infosTxt", false);
  72. }
  73. $form1 = new HTML_QuickForm('Form', 'post', "?p=".$p);
  74. if ($form1->validate()) {
  75. /*
  76. * Insert Module in DB
  77. */
  78. $insert_ok = insertModuleInDB($name, $module_conf[$name]);
  79. if ($insert_ok) {
  80. $tpl->assign("output1", _("Module installed and registered"));
  81. /*
  82. * SQL insert if need
  83. */
  84. $sql_file = "install.sql";
  85. $sql_file_path = "./modules/".$name."/sql/";
  86. if ($module_conf[$name]["sql_files"] && file_exists($sql_file_path.$sql_file)) {
  87. $tpl->assign("output2", _("SQL file included"));
  88. execute_sql_file($sql_file, $sql_file_path);
  89. }
  90. /*
  91. * PHP execution if need
  92. */
  93. $php_file = "install.php";
  94. $php_file_path = _CENTREON_PATH_ . "www/modules/".$name."/php/".$php_file;
  95. if ($module_conf[$name]["php_files"] && file_exists($php_file_path)) {
  96. $tpl->assign("output3", _("PHP file included"));
  97. include_once($php_file_path);
  98. }
  99. /*
  100. * Rebuilds modules in oreon object
  101. */
  102. $oreon->creatModuleList($pearDB);
  103. $oreon->user->access->updateTopologyStr();
  104. } else {
  105. $tpl->assign("output4", _("Unable to install module"));
  106. }
  107. } else {
  108. $form1->addElement('submit', 'install', _("Install Module"), array("class" => "btc bt_success"));
  109. $redirect = $form1->addElement('hidden', 'o');
  110. $redirect->setValue("i");
  111. }
  112. $form1->addElement('submit', 'list', _("Back"), array("class" => "btc bt_default"));
  113. $hid_name = $form1->addElement('hidden', 'name');
  114. $hid_name->setValue($name);
  115. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
  116. $form1->accept($renderer);
  117. $tpl->assign('form1', $renderer->toArray());
  118. } elseif ($operationType === 'upgrade') {
  119. /*
  120. * "ID" case, it's an installed module
  121. */
  122. $moduleinfo = getModuleInfoInDB(NULL, $id);
  123. $elemArr = array();
  124. $form = new HTML_QuickForm('Form', 'post', "?p=".$p);
  125. $form->addElement('submit', 'list', _("Back"));
  126. if (is_dir(_CENTREON_PATH_ . "www/modules/".$moduleinfo["name"]."/UPGRADE")) {
  127. $handle = opendir(_CENTREON_PATH_ . "www/modules/".$moduleinfo["name"]."/UPGRADE");
  128. $i = 0;
  129. $elemArr = array();
  130. while (false !== ($filename = readdir($handle))) {
  131. if (substr($filename, 0, 1) != "." && strstr($filename, $moduleinfo["name"]."-")) {
  132. include_once(_CENTREON_PATH_ . "www/modules/".$moduleinfo["name"]."/UPGRADE/".$filename."/conf.php");
  133. if ($moduleinfo["mod_release"] == $upgrade_conf[$moduleinfo["name"]]["release_from"]) {
  134. $upgrade_ok = false;
  135. # Upgrade
  136. if ($form->validate()) {
  137. # DB Upgrade
  138. $upgrade_ok = upgradeModuleInDB($id, $upgrade_conf[$moduleinfo["name"]]);
  139. if ($upgrade_ok) {
  140. $tpl->assign("output1", _("Module installed and registered"));
  141. # SQL update if need
  142. $sql_file = "upgrade.sql";
  143. $sql_file_path = _CENTREON_PATH_ . "www/modules/".$moduleinfo["name"]."/UPGRADE/".$filename."/sql/";
  144. if ($upgrade_conf[$moduleinfo["name"]]["sql_files"] && file_exists($sql_file_path.$sql_file)) {
  145. $tpl->assign("output2", _("SQL file included"));
  146. execute_sql_file($sql_file, $sql_file_path);
  147. }
  148. # PHP update if need
  149. $php_file = "upgrade.php";
  150. $php_file_path = _CENTREON_PATH_ . "www/modules/".$moduleinfo["name"]."/UPGRADE/".$filename."/php/".$php_file;
  151. if ($upgrade_conf[$moduleinfo["name"]]["php_files"] && file_exists($php_file_path)) {
  152. $tpl->assign("output3", _("PHP file included"));
  153. include_once($php_file_path);
  154. }
  155. $oreon->creatModuleList($pearDB);
  156. $oreon->user->access->updateTopologyStr();
  157. } else {
  158. $tpl->assign("output4", _("Unable to install module"));
  159. }
  160. }
  161. if (!$upgrade_ok) {
  162. $form->addElement('submit', 'upgrade', _("Upgrade"), array("class" => "btc bt_success"));
  163. $redirect = $form->addElement('hidden', 'o');
  164. $redirect->setValue("u");
  165. }
  166. if (is_dir(_CENTREON_PATH_ . "www/modules/".$moduleinfo["name"]."/UPGRADE/".$filename."/infos") && is_file("./modules/".$moduleinfo["name"]."/UPGRADE/".$filename."/infos/infos.txt")) {
  167. $infos_streams = file(_CENTREON_PATH_ . "www/modules/".$moduleinfo["name"]."/UPGRADE/".$filename."/infos/infos.txt");
  168. $infos_streams = implode("<br />", $infos_streams);
  169. $upgrade_infosTxt = $infos_streams;
  170. } else {
  171. $upgrade_infosTxt = false;
  172. }
  173. $elemArr[$i] = array(
  174. "upgrade_rname" => $upgrade_conf[$moduleinfo["name"]]["rname"],
  175. "upgrade_release_from" => $upgrade_conf[$moduleinfo["name"]]["release_from"],
  176. "upgrade_release_to" => $upgrade_conf[$moduleinfo["name"]]["release_to"],
  177. "upgrade_author" => $upgrade_conf[$moduleinfo["name"]]["author"],
  178. "upgrade_infos" => $upgrade_conf[$moduleinfo["name"]]["infos"],
  179. "upgrade_infosTxt" => $upgrade_infosTxt,
  180. "upgrade_is_validUp" => $moduleinfo["mod_release"] === $upgrade_conf[$moduleinfo["name"]]["release_from"] ? _("Yes") : _("No"),
  181. "upgrade_choice" => $moduleinfo["mod_release"] === $upgrade_conf[$moduleinfo["name"]]["release_from"] ? true : false
  182. );
  183. $i++;
  184. $hid_id = $form->addElement('hidden', 'id');
  185. $hid_id->setValue($id);
  186. $up_name = $form->addElement('hidden', 'filename');
  187. $up_name->setValue($filename);
  188. }
  189. }
  190. }
  191. closedir($handle);
  192. }
  193. $moduleinfo = array();
  194. $moduleinfo = getModuleInfoInDB(NULL, $id);
  195. $tpl->assign("module_rname", $moduleinfo["rname"]);
  196. $tpl->assign("module_release", $moduleinfo["mod_release"]);
  197. $tpl->assign("module_author", $moduleinfo["author"]);
  198. $tpl->assign("module_infos", $moduleinfo["infos"]);
  199. $tpl->assign("module_isinstalled", _("Yes"));
  200. $tpl->assign("elemArr", $elemArr);
  201. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
  202. $form->accept($renderer);
  203. $tpl->assign('form', $renderer->toArray());
  204. }
  205. /**
  206. * Display form
  207. */
  208. $tpl->display("formModule.ihtml");
  209. ?>