group_edit.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.social
  5. *
  6. * @author Julio Montoya <gugli100@gmail.com>
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. api_block_anonymous_users();
  11. if (api_get_setting('allow_social_tool') !== 'true') {
  12. api_not_allowed();
  13. }
  14. $this_section = SECTION_SOCIAL;
  15. $group_id = isset($_GET['id']) ? intval($_GET['id']) : intval($_POST['id']);
  16. $tool_name = get_lang('GroupEdit');
  17. $usergroup = new UserGroup();
  18. $group_data = $usergroup->get($group_id);
  19. if (empty($group_data)) {
  20. header('Location: group_view.php?id='.$group_id);
  21. exit;
  22. }
  23. $interbreadcrumb[] = ['url' => 'groups.php', 'name' => get_lang('Groups')];
  24. $interbreadcrumb[] = ['url' => 'group_view.php?id='.$group_id, 'name' => $group_data['name']];
  25. // only group admins can edit the group
  26. if (!$usergroup->is_group_admin($group_id)) {
  27. api_not_allowed();
  28. }
  29. // Create the form
  30. $form = new FormValidator('group_edit', 'post', '', '');
  31. $form->addElement('hidden', 'id', $group_id);
  32. $usergroup->setGroupType($usergroup::SOCIAL_CLASS);
  33. $usergroup->setForm($form, 'edit', $group_data);
  34. // Set default values
  35. $form->setDefaults($group_data);
  36. // Validate form
  37. if ($form->validate()) {
  38. $group = $form->exportValues();
  39. $group['id'] = $group_id;
  40. $group['group_type'] = $usergroup::SOCIAL_CLASS;
  41. $usergroup->update($group);
  42. Display::addFlash(Display::return_message(get_lang('GroupUpdated')));
  43. header('Location: group_view.php?id='.$group_id);
  44. exit();
  45. }
  46. $social_left_content = SocialManager::show_social_menu('group_edit', $group_id);
  47. $social_right_content = $form->returnForm();
  48. $tpl = new Template(get_lang('Edit'));
  49. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'groups', $group_id);
  50. $tpl->setHelp('Groups');
  51. $tpl->assign('social_menu_block', $social_left_content);
  52. $tpl->assign('social_right_content', $social_right_content);
  53. $social_layout = $tpl->get_template('social/add_groups.tpl');
  54. $tpl->display($social_layout);