configure_plugin.php 3.4 KB

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