configure_plugin.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. use \ChamiloSession as Session;
  9. $cidReset = true;
  10. require_once '../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. global $_configuration;
  21. $message = null;
  22. $content = null;
  23. $currentUrl = api_get_self() . "?name=$pluginName";
  24. if (isset($pluginInfo['settings_form'])) {
  25. $form = $pluginInfo['settings_form'];
  26. if (isset($form)) {
  27. //We override the form attributes
  28. $attributes = array('action' => $currentUrl, 'method' => 'POST');
  29. $form->updateAttributes($attributes);
  30. $content = Display::page_header($pluginInfo['title']);
  31. $content .= $form->toHtml();
  32. }
  33. } else {
  34. $message = Display::return_message(get_lang('NoConfigurationSettingsForThisPlugin'), 'warning');
  35. }
  36. if (isset($form)) {
  37. if ($form->validate()) {
  38. $values = $form->exportValues();
  39. //api_delete_category_settings_by_subkey($pluginName);
  40. $accessUrlId = api_get_current_access_url_id();
  41. api_delete_settings_params(
  42. array(
  43. 'category = ? AND access_url = ? AND subkey = ? AND type = ? and variable <> ?' => array(
  44. 'Plugins',
  45. $accessUrlId,
  46. $pluginName,
  47. 'setting',
  48. "status"
  49. )
  50. )
  51. );
  52. foreach ($values as $key => $value) {
  53. api_add_setting(
  54. $value, Database::escape_string($pluginName . '_' . $key),
  55. $pluginName,
  56. 'setting',
  57. 'Plugins',
  58. $pluginName,
  59. null,
  60. null,
  61. null,
  62. $_configuration['access_url'],
  63. 1
  64. );
  65. }
  66. if (isset($values['show_main_menu_tab'])) {
  67. $objPlugin = $pluginInfo['plugin_class']::create();
  68. $objPlugin->manageTab($values['show_main_menu_tab']);
  69. }
  70. $message = Display::return_message(get_lang('Updated'), 'success');
  71. Session::write('message', $message);
  72. header("Location: $currentUrl");
  73. exit;
  74. } else {
  75. foreach ($form->_errors as $error) {
  76. $message .= Display::return_message($error, 'error');
  77. }
  78. }
  79. }
  80. if (Session::has('message')) {
  81. $message = Session::read('message');
  82. }
  83. $interbreadcrumb[] = array(
  84. 'url' => api_get_path(WEB_CODE_PATH) . 'admin/index.php',
  85. 'name' => get_lang('PlatformAdmin')
  86. );
  87. $interbreadcrumb[] = array(
  88. 'url' => api_get_path(WEB_CODE_PATH) . 'admin/settings.php?category=Plugins',
  89. 'name' => get_lang('Plugins')
  90. );
  91. $tpl = new Template($pluginName, true, true, false, true, false);
  92. $tpl->assign('message', $message);
  93. $tpl->assign('content', $content);
  94. $tpl->display_one_col_template();
  95. Session::erase('message');