configure_plugin.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. global $_configuration;
  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 = array('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->exportValues();
  43. $accessUrlId = api_get_current_access_url_id();
  44. api_delete_settings_params(
  45. array(
  46. 'category = ? AND access_url = ? AND subkey = ? AND type = ? and variable <> ?' => array(
  47. 'Plugins',
  48. $accessUrlId,
  49. $pluginName,
  50. 'setting',
  51. "status"
  52. )
  53. )
  54. );
  55. foreach ($values as $key => $value) {
  56. $value = trim($value);
  57. api_add_setting(
  58. $value,
  59. Database::escape_string($pluginName.'_'.$key),
  60. $pluginName,
  61. 'setting',
  62. 'Plugins',
  63. $pluginName,
  64. null,
  65. null,
  66. null,
  67. $_configuration['access_url'],
  68. 1
  69. );
  70. }
  71. if (isset($values['show_main_menu_tab'])) {
  72. $objPlugin = $pluginInfo['plugin_class']::create();
  73. $objPlugin->manageTab($values['show_main_menu_tab']);
  74. }
  75. Display::addFlash(Display::return_message(get_lang('Updated'), 'success'));
  76. header("Location: $currentUrl");
  77. exit;
  78. } else {
  79. foreach ($form->_errors as $error) {
  80. Display::addFlash(Display::return_message($error, 'error'));
  81. }
  82. }
  83. }
  84. $interbreadcrumb[] = array(
  85. 'url' => api_get_path(WEB_CODE_PATH).'admin/index.php',
  86. 'name' => get_lang('PlatformAdmin')
  87. );
  88. $interbreadcrumb[] = array(
  89. 'url' => api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Plugins',
  90. 'name' => get_lang('Plugins')
  91. );
  92. $tpl = new Template($pluginName, true, true, false, true, false);
  93. $tpl->assign('content', $content);
  94. $tpl->display_one_col_template();