configure_plugin.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Julio Montoya <gugli100@gmail.com> BeezNest 2012
  5. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  6. *
  7. * @package chamilo.admin
  8. */
  9. $cidReset = true;
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. // Access restrictions
  12. api_protect_admin_script();
  13. $pluginName = $_GET['name'];
  14. $appPlugin = new AppPlugin();
  15. $installedPlugins = $appPlugin->get_installed_plugins();
  16. $pluginInfo = $appPlugin->getPluginInfo($pluginName, true);
  17. if (!in_array($pluginName, $installedPlugins) || empty($pluginInfo)) {
  18. api_not_allowed(true);
  19. }
  20. $content = '';
  21. $currentUrl = api_get_self()."?name=$pluginName";
  22. if (isset($pluginInfo['settings_form'])) {
  23. /** @var FormValidator $form */
  24. $form = $pluginInfo['settings_form'];
  25. if (isset($form)) {
  26. // We override the form attributes
  27. $attributes = ['action' => $currentUrl, 'method' => 'POST'];
  28. $form->updateAttributes($attributes);
  29. if (isset($pluginInfo['settings'])) {
  30. $form->setDefaults($pluginInfo['settings']);
  31. }
  32. $content = Display::page_header($pluginInfo['title']);
  33. $content .= $form->toHtml();
  34. }
  35. } else {
  36. Display::addFlash(
  37. Display::return_message(get_lang('NoConfigurationSettingsForThisPlugin'), 'warning')
  38. );
  39. }
  40. if (isset($form)) {
  41. if ($form->validate()) {
  42. $values = $form->getSubmitValues();
  43. // Fix only for bbb
  44. if ($pluginName == 'bbb') {
  45. if (!isset($values['global_conference_allow_roles'])) {
  46. $values['global_conference_allow_roles'] = [];
  47. }
  48. }
  49. $accessUrlId = api_get_current_access_url_id();
  50. api_delete_settings_params(
  51. [
  52. 'category = ? AND access_url = ? AND subkey = ? AND type = ? and variable <> ?' => [
  53. 'Plugins',
  54. $accessUrlId,
  55. $pluginName,
  56. 'setting',
  57. 'status',
  58. ],
  59. ]
  60. );
  61. foreach ($values as $key => $value) {
  62. api_add_setting(
  63. $value,
  64. Database::escape_string($pluginName.'_'.$key),
  65. $pluginName,
  66. 'setting',
  67. 'Plugins',
  68. $pluginName,
  69. '',
  70. '',
  71. '',
  72. api_get_current_access_url_id(),
  73. 1
  74. );
  75. }
  76. /** @var \Plugin $objPlugin */
  77. $objPlugin = $pluginInfo['plugin_class']::create();
  78. $objPlugin->get_settings(true);
  79. $objPlugin->performActionsAfterConfigure();
  80. if (isset($values['show_main_menu_tab'])) {
  81. $objPlugin->manageTab($values['show_main_menu_tab']);
  82. }
  83. Display::addFlash(Display::return_message(get_lang('Updated'), 'success'));
  84. header("Location: $currentUrl");
  85. exit;
  86. } else {
  87. foreach ($form->_errors as $error) {
  88. Display::addFlash(Display::return_message($error, 'error'));
  89. }
  90. }
  91. }
  92. $interbreadcrumb[] = [
  93. 'url' => api_get_path(WEB_CODE_PATH).'admin/index.php',
  94. 'name' => get_lang('PlatformAdmin'),
  95. ];
  96. $interbreadcrumb[] = [
  97. 'url' => api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Plugins',
  98. 'name' => get_lang('Plugins'),
  99. ];
  100. $tpl = new Template($pluginName, true, true, false, true, false);
  101. $tpl->assign('content', $content);
  102. $tpl->display_one_col_template();