group_edit.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. $libpath = api_get_path(LIBRARY_PATH);
  17. require_once $libpath.'fileManage.lib.php';
  18. require_once $libpath.'fileUpload.lib.php';
  19. require_once $libpath.'group_portal_manager.lib.php';
  20. require_once $libpath.'mail.lib.inc.php';
  21. $htmlHeadXtra[] = '<script type="text/javascript">
  22. var textarea = "";
  23. var num_characters_permited = 255;
  24. function textarea_maxlength(){
  25. num_characters = document.forms[0].description.value.length;
  26. if (num_characters > num_characters_permited){
  27. document.forms[0].description.value = textarea;
  28. }else{
  29. textarea = document.forms[0].description.value;
  30. }
  31. }
  32. </script>';
  33. $group_id = isset($_GET['id']) ? intval($_GET['id']) : intval($_POST['id']);
  34. $tool_name = get_lang('GroupEdit');
  35. $interbreadcrumb[] = array('url' => 'home.php','name' => get_lang('Social'));
  36. $interbreadcrumb[] = array('url' => 'groups.php','name' => get_lang('Groups'));
  37. $table_group = Database::get_main_table(TABLE_MAIN_GROUP);
  38. $group_data = GroupPortalManager::get_group_data($group_id);
  39. if (empty($group_data)) {
  40. api_not_allowed();
  41. }
  42. //only group admins can edit the group
  43. if (!GroupPortalManager::is_group_admin($group_id)) {
  44. api_not_allowed();
  45. }
  46. // Create the form
  47. $form = new FormValidator('group_edit', 'post', '', '');
  48. $form->addElement('hidden', 'id', $group_id);
  49. $form = GroupPortalManager::setGroupForm($form, $group_data);
  50. // Submit button
  51. $form->addElement('style_submit_button', 'submit', get_lang('ModifyInformation'), 'class="save"');
  52. // Validate form
  53. if ($form->validate()) {
  54. $group = $form->exportValues();
  55. $picture_element = $form->getElement('picture');
  56. $picture = $picture_element->getValue();
  57. $picture_uri = $group_data['picture_uri'];
  58. if ($group['delete_picture']) {
  59. $picture_uri = GroupPortalManager::delete_group_picture($group_id);
  60. } elseif (!empty($picture['name'])) {
  61. $picture_uri = GroupPortalManager::update_group_picture($group_id, $_FILES['picture']['name'], $_FILES['picture']['tmp_name']);
  62. }
  63. $name = $group['name'];
  64. $description = $group['description'];
  65. $url = $group['url'];
  66. $status = intval($group['visibility']);
  67. $allowMemberGroupToLeave = null;
  68. if (GroupPortalManager::canLeaveFeatureEnabled($group_data)) {
  69. $allowMemberGroupToLeave = isset($group['allow_members_leave_group']) ? true : false;
  70. }
  71. GroupPortalManager::update($group_id, $name, $description, $url, $status, $picture_uri, $allowMemberGroupToLeave);
  72. $tok = Security::get_token();
  73. header('Location: groups.php?id='.$group_id.'&action=show_message&message='.urlencode(get_lang('GroupUpdated')).'&sec_token='.$tok);
  74. exit();
  75. }
  76. // Group picture
  77. $image_path = GroupPortalManager::get_group_picture_path_by_id($group_id, 'web');
  78. $image_dir = $image_path['dir'];
  79. $image = $image_path['file'];
  80. $image_file = ($image != '' ? $image_dir.$image : api_get_path(WEB_CODE_PATH).'img/unknown_group.jpg');
  81. $image_size = api_getimagesize($image_file);
  82. // get the path,width and height from original picture
  83. $big_image = $image_dir.'big_'.$image;
  84. $big_image_size = api_getimagesize($big_image);
  85. $big_image_width = $big_image_size['width'];
  86. $big_image_height = $big_image_size['height'];
  87. $url_big_image = $big_image.'?rnd='.time();
  88. $social_avatar_block = SocialManager::show_social_avatar_block('group_edit', $group_id);
  89. $social_menu_block = SocialManager::show_social_menu('group_edit', $group_id);
  90. $social_right_content = $form->return_form();
  91. $tpl = new Template($tool_name);
  92. $tpl->set_help('Groups');
  93. $tpl->assign('social_avatar_block', $social_avatar_block);
  94. $tpl->assign('social_menu_block', $social_menu_block);
  95. $tpl->assign('social_right_content', $social_right_content);
  96. $social_layout = $tpl->get_template('layout/social_layout.tpl');
  97. $tpl->display($social_layout);