configure_plugin.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. $content = '';
  21. $currentUrl = api_get_self() . "?name=$pluginName";
  22. if (isset($pluginInfo['settings_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. $content = Display::page_header($pluginInfo['title']);
  29. $content .= $form->toHtml();
  30. }
  31. } else {
  32. Display::addFlash(
  33. Display::return_message(get_lang('NoConfigurationSettingsForThisPlugin'), 'warning')
  34. );
  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,
  55. Database::escape_string($pluginName . '_' . $key),
  56. $pluginName,
  57. 'setting',
  58. 'Plugins',
  59. $pluginName,
  60. null,
  61. null,
  62. null,
  63. api_get_current_access_url_id(),
  64. 1
  65. );
  66. }
  67. if (isset($values['show_main_menu_tab'])) {
  68. $objPlugin = $pluginInfo['plugin_class']::create();
  69. $objPlugin->manageTab($values['show_main_menu_tab']);
  70. }
  71. Display::addFlash(Display::return_message(get_lang('Updated'), 'success'));
  72. header("Location: $currentUrl");
  73. exit;
  74. } else {
  75. foreach ($form->_errors as $error) {
  76. Display::addFlash(Display::return_message($error, 'error'));
  77. }
  78. }
  79. }
  80. $interbreadcrumb[] = array(
  81. 'url' => api_get_path(WEB_CODE_PATH) . 'admin/index.php',
  82. 'name' => get_lang('PlatformAdmin')
  83. );
  84. $interbreadcrumb[] = array(
  85. 'url' => api_get_path(WEB_CODE_PATH) . 'admin/settings.php?category=Plugins',
  86. 'name' => get_lang('Plugins')
  87. );
  88. $tpl = new Template($pluginName, true, true, false, true, false);
  89. $tpl->assign('content', $content);
  90. $tpl->display_one_col_template();