configure_plugin.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. @author Julio Montoya <gugli100@gmail.com> BeezNest 2012
  5. * @package chamilo.admin
  6. */
  7. // name of the language file that needs to be included
  8. $language_file = array ('registration','admin');
  9. $cidReset = true;
  10. require_once '../inc/global.inc.php';
  11. // Access restrictions
  12. api_protect_admin_script();
  13. $plugin_name = $_GET['name'];
  14. $plugin_obj = new AppPlugin();
  15. $plugin_info = $plugin_obj->get_plugin_info($plugin_name, true);
  16. if (empty($plugin_info)) {
  17. api_not_allowed();
  18. }
  19. $installed_plugins = $plugin_obj->get_installed_plugins();
  20. if (!in_array($plugin_name, $installed_plugins)) {
  21. api_not_allowed();
  22. }
  23. global $_configuration;
  24. $content = null;
  25. if (isset($plugin_info['settings_form'])) {
  26. $form = $plugin_info['settings_form'];
  27. if (isset($form)) {
  28. //We override the form attributes
  29. $attributes = array('action'=>api_get_self().'?name='.$plugin_name, 'method'=>'POST');
  30. $form->updateAttributes($attributes);
  31. $content = Display::page_header($plugin_info['title']);
  32. $content .= $form->toHtml();
  33. }
  34. } else {
  35. $message = Display::return_message(get_lang('NoConfigurationSettingsForThisPlugin'), 'warning');
  36. }
  37. if (isset($form)) {
  38. if ($form->validate()) {
  39. $values = $form->exportValues();
  40. //api_delete_category_settings_by_subkey($plugin_name);
  41. $access_url_id = api_get_current_access_url_id();
  42. api_delete_settings_params(array('category = ? AND access_url = ? AND subkey = ? AND type = ? and variable <> ?' =>
  43. array('Plugins', $access_url_id, $plugin_name, 'setting', "status")));
  44. foreach ($values as $key => $value) {
  45. $key = Database::escape_string($plugin_name.'_'.$key);
  46. api_add_setting($value, $key, $plugin_name, 'setting', 'Plugins', $plugin_name, null, null, null, api_get_current_access_url_id(), 1);
  47. }
  48. $message = Display::return_message(get_lang('Updated'), 'success');
  49. }
  50. }
  51. $app['title'] = $tool_name;
  52. $tpl = $app['template'];
  53. $tpl->assign('actions', $actions);
  54. $tpl->assign('message', $message);
  55. $tpl->assign('content', $content);
  56. $tpl->display_one_col_template();