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

/www/include/options/oreon/widgets/list.php

https://gitlab.com/florianocomercial/centreon
PHP | 134 lines | 88 code | 12 blank | 34 comment | 23 complexity | 436e5283e493067a427eb3a197d30a31 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. require_once _CENTREON_PATH_ . "www/class/centreonWidget.class.php";
  39. require_once _CENTREON_PATH_ . "www/class/centreonUtils.class.php";
  40. $tpl = new Smarty();
  41. $tpl = initSmartyTpl($path, $tpl);
  42. $widgetObj = new CentreonWidget($centreon, $pearDB);
  43. $labels = array();
  44. $labels['title'] = _("Title");
  45. $labels['description'] = _("Description");
  46. $labels['version'] = _("Version");
  47. $labels['author'] = _("Author");
  48. $labels['actions'] = _("Actions");
  49. $handle = opendir(_CENTREON_PATH_ . 'www/widgets/');
  50. $widgets = array();
  51. # Retrive widget directories
  52. $widgetDirs = array();
  53. while (($currentDir = readdir($handle)) != false){
  54. if ($currentDir != "." && $currentDir != ".." && $currentDir != ".SVN" && $currentDir != ".svn" && $currentDir != ".CSV") {
  55. $widgetDirs[] = $currentDir;
  56. }
  57. }
  58. sort($widgetDirs);
  59. foreach ($widgetDirs as $currentDir) {
  60. $configFile = _CENTREON_PATH_ . 'www/widgets/' . $currentDir . '/configs.xml';
  61. if (is_file($configFile)) {
  62. $tab = $widgetObj->readConfigFile($configFile);
  63. $dbTab = $widgetObj->getWidgetInfoByDirectory($currentDir);
  64. if (isset($dbTab)) {
  65. $dbTab['is_installed'] = 1;
  66. if ($dbTab['version'] != $tab['version']) {
  67. $dbTab['upgrade'] = 1;
  68. }
  69. $widgets[] = $dbTab;
  70. } else {
  71. $tab['is_installed'] = 0;
  72. $tab['install'] = 1;
  73. $tab['directory'] = $currentDir;
  74. $widgets[] = $tab;
  75. }
  76. }
  77. }
  78. $tpl->assign('widgets', $widgets);
  79. $tpl->assign('labels', $labels);
  80. $tpl->display("list.ihtml");
  81. ?>
  82. <script type='text/javascript'>
  83. var installConfirmMsg = '<?php echo _('Would you like to install this widget?');?>';
  84. var uninstallConfirmMsg = '<?php echo _('Are you sure you want to uninstall this widget?');?>';
  85. var upgradeConfirmMsg = '<?php echo _('Would you like to upgrade this widget?');?>';
  86. var p = '<?php echo $p;?>';
  87. jQuery(function() {
  88. jQuery('.installBtn').click(function() {
  89. forwardAction(installConfirmMsg, 'install', jQuery(this).parent('td').attr('id'));
  90. });
  91. jQuery('.upgradeBtn').click(function() {
  92. forwardAction(upgradeConfirmMsg, 'upgrade', jQuery(this).parent('td').attr('id'));
  93. });
  94. jQuery('.uninstallBtn').click(function() {
  95. forwardAction(uninstallConfirmMsg, 'uninstall', jQuery(this).parent('td').attr('id'));
  96. });
  97. });
  98. function forwardAction(confirmMsg, action, data)
  99. {
  100. var tab = data.split('widget_');
  101. if (typeof(tab[1]) != 'undefined') {
  102. var directory = tab[1];
  103. if (confirm(confirmMsg)) {
  104. jQuery.ajax({
  105. type : "POST",
  106. dataType: "xml",
  107. url : "./include/options/oreon/widgets/action.php",
  108. data : {
  109. action : action,
  110. directory : directory
  111. },
  112. success : function(response) {
  113. var result = response.getElementsByTagName('result');
  114. if (typeof(result) != 'undefined') {
  115. window.location = './main.php?p='+p;
  116. }
  117. }
  118. });
  119. }
  120. }
  121. }
  122. </script>