group_edit.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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' => 'home.php', 'name' => get_lang('Social'));
  22. $interbreadcrumb[] = array('url' => 'groups.php', 'name' => get_lang('Groups'));
  23. $usergroup = new UserGroup();
  24. $group_data = $usergroup->get($group_id);
  25. if (empty($group_data)) {
  26. header('Location: groups.php?id='.$group_id);
  27. exit;
  28. }
  29. //only group admins can edit the group
  30. if (!$usergroup->is_group_admin($group_id)) {
  31. api_not_allowed();
  32. }
  33. // Create the form
  34. $form = new FormValidator('group_edit', 'post', '', '');
  35. $form->addElement('hidden', 'id', $group_id);
  36. $usergroup->setGroupType($usergroup::SOCIAL_CLASS);
  37. $usergroup->setForm($form, 'edit', $group_data);
  38. // Set default values
  39. $form->setDefaults($group_data);
  40. // Validate form
  41. if ($form->validate()) {
  42. $group = $form->exportValues();
  43. $group['id'] = $group_id;
  44. $group['type'] = $usergroup::SOCIAL_CLASS;
  45. $usergroup->update($group);
  46. $tok = Security::get_token();
  47. header(
  48. 'Location: groups.php?id='.$group_id.'&action=show_message&message='.urlencode(
  49. get_lang('GroupUpdated')
  50. ).'&sec_token='.$tok
  51. );
  52. exit();
  53. }
  54. $social_left_content = SocialManager::show_social_menu('group_edit', $group_id);
  55. $social_right_content = '<div class="span9">';
  56. $social_right_content .= $form->return_form();
  57. $social_right_content .= '</div>';
  58. $app['title'] = $tool_name;
  59. $tpl = $app['template'];
  60. $tpl->setHelp('Groups');
  61. $tpl->assign('social_left_content', $social_left_content);
  62. $tpl->assign('social_right_content', $social_right_content);
  63. $social_layout = $tpl->get_template('layout/social_layout.tpl');
  64. $tpl->display($social_layout);