configure_plugin.php 3.2 KB

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