group_edit.php 2.0 KB

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