group_edit.php 2.0 KB

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