group_edit.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.social
  5. * @author Julio Montoya <gugli100@gmail.com>
  6. */
  7. /**
  8. * Initialization
  9. */
  10. // Language files that should be included
  11. $language_file = array('userInfo');
  12. $cidReset = true;
  13. //require_once '../inc/global.inc.php';
  14. api_block_anonymous_users();
  15. if (api_get_setting('allow_social_tool') != 'true') {
  16. api_not_allowed();
  17. }
  18. $this_section = SECTION_SOCIAL;
  19. $group_id = isset($_GET['id']) ? intval($_GET['id']) : intval($_POST['id']);
  20. $tool_name = get_lang('GroupEdit');
  21. $interbreadcrumb[] = array('url' => 'groups.php', 'name' => get_lang('Groups'));
  22. $usergroup = new UserGroup();
  23. $group_data = $usergroup->get($group_id);
  24. if (empty($group_data)) {
  25. header('Location: groups.php?id='.$group_id);
  26. exit;
  27. }
  28. //only group admins can edit the group
  29. if (!$usergroup->is_group_admin($group_id)) {
  30. api_not_allowed();
  31. }
  32. // Create the form
  33. $form = new FormValidator('group_edit', 'post', '', '');
  34. $form->addElement('hidden', 'id', $group_id);
  35. $usergroup->setGroupType($usergroup::SOCIAL_CLASS);
  36. $usergroup->setForm($form, 'edit', $group_data);
  37. // Set default values
  38. $form->setDefaults($group_data);
  39. // Validate form
  40. if ($form->validate()) {
  41. $group = $form->exportValues();
  42. $group['id'] = $group_id;
  43. $group['type'] = $usergroup::SOCIAL_CLASS;
  44. $usergroup->update($group);
  45. $tok = Security::get_token();
  46. header(
  47. 'Location: groups.php?id='.$group_id.'&action=show_message&message='.urlencode(
  48. get_lang('GroupUpdated')
  49. ).'&sec_token='.$tok
  50. );
  51. exit();
  52. }
  53. $social_left_content = SocialManager::show_social_menu('group_edit', $group_id);
  54. $social_right_content = '<div class="span9">';
  55. $social_right_content .= $form->return_form();
  56. $social_right_content .= '</div>';
  57. $app['title'] = $tool_name;
  58. $tpl = $app['template'];
  59. $tpl->setHelp('Groups');
  60. $tpl->assign('content', $social_right_content);