group_edit.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. $libpath = api_get_path(LIBRARY_PATH);
  20. require_once $libpath.'fileManage.lib.php';
  21. require_once $libpath.'fileUpload.lib.php';
  22. require_once $libpath.'group_portal_manager.lib.php';
  23. require_once $libpath.'formvalidator/FormValidator.class.php';
  24. require_once $libpath.'mail.lib.inc.php';
  25. require_once $libpath.'social.lib.php';
  26. //jquery thickbox already called from main/inc/header.inc.php
  27. $htmlHeadXtra[] = '<script type="text/javascript">
  28. var textarea = "";
  29. var num_characters_permited = 255;
  30. function textarea_maxlength(){
  31. num_characters = document.forms[0].description.value.length;
  32. if (num_characters > num_characters_permited){
  33. document.forms[0].description.value = textarea;
  34. }else{
  35. textarea = document.forms[0].description.value;
  36. }
  37. }
  38. </script>
  39. <style>
  40. div.row div.label {
  41. width:15%;
  42. }
  43. div.row div.formw {
  44. width:80%;
  45. }
  46. </style>';
  47. $group_id = isset($_GET['id']) ? intval($_GET['id']) : intval($_POST['id']);
  48. $tool_name = get_lang('GroupEdit');
  49. $interbreadcrumb[] = array('url' => 'home.php','name' => get_lang('Social'));
  50. $interbreadcrumb[] = array('url' => 'groups.php','name' => get_lang('Groups'));
  51. $table_group = Database::get_main_table(TABLE_MAIN_GROUP);
  52. $sql = "SELECT * FROM $table_group WHERE id = '".$group_id."'";
  53. $res = Database::query($sql);
  54. if (Database::num_rows($res) != 1) {
  55. header('Location: groups.php?id='.$group_id);
  56. exit;
  57. }
  58. //only group admins can edit the group
  59. if (!GroupPortalManager::is_group_admin($group_id)) {
  60. api_not_allowed();
  61. }
  62. $group_data = Database::fetch_array($res, 'ASSOC');
  63. // Create the form
  64. $form = new FormValidator('group_edit', 'post', '', '', array('style' => 'width: 100%; float: '.($text_dir == 'rtl' ? 'right;' : 'left;')));
  65. $form->addElement('hidden', 'id', $group_id);
  66. // name
  67. $form->addElement('text', 'name', get_lang('Name'), array('size'=>60, 'maxlength'=>120));
  68. $form->applyFilter('name', 'html_filter');
  69. $form->applyFilter('name', 'trim');
  70. $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
  71. // Description
  72. $form->addElement('textarea', 'description', get_lang('Description'), array('rows'=>3, 'cols'=>58, onKeyDown => "textarea_maxlength()", onKeyUp => "textarea_maxlength()"));
  73. $form->applyFilter('description', 'html_filter');
  74. $form->applyFilter('description', 'trim');
  75. $form->addRule('name', '', 'maxlength',255);
  76. // url
  77. $form->addElement('text', 'url', get_lang('URL'), array('size'=>35));
  78. $form->applyFilter('url', 'html_filter');
  79. $form->applyFilter('url', 'trim');
  80. // Picture
  81. $form->addElement('file', 'picture', get_lang('AddPicture'));
  82. $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
  83. $form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
  84. if (strlen($group_data['picture_uri']) > 0) {
  85. $form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage'));
  86. }
  87. // Status
  88. $status = array();
  89. $status[GROUP_PERMISSION_OPEN] = get_lang('Open');
  90. $status[GROUP_PERMISSION_CLOSED] = get_lang('Closed');
  91. $form->addElement('select', 'visibility', get_lang('GroupPermissions'), $status, array());
  92. // Submit button
  93. $form->addElement('style_submit_button', 'submit', get_lang('ModifyInformation'), 'class="save"');
  94. // Set default values
  95. $form->setDefaults($group_data);
  96. // Validate form
  97. if ( $form->validate()) {
  98. $group = $form->exportValues();
  99. $picture_element = & $form->getElement('picture');
  100. $picture = $picture_element->getValue();
  101. $picture_uri = $group_data['picture_uri'];
  102. if ($group['delete_picture']) {
  103. $picture_uri = GroupPortalManager::delete_group_picture($group_id);
  104. }
  105. elseif (!empty($picture['name'])) {
  106. $picture_uri = GroupPortalManager::update_group_picture($group_id, $_FILES['picture']['name'], $_FILES['picture']['tmp_name']);
  107. }
  108. $name = $group['name'];
  109. $description = $group['description'];
  110. $url = $group['url'];
  111. $status = intval($group['visibility']);
  112. GroupPortalManager::update($group_id, $name, $description, $url, $status, $picture_uri);
  113. $tok = Security::get_token();
  114. header('Location: groups.php?id='.$group_id.'&action=show_message&message='.urlencode(get_lang('GroupUpdated')).'&sec_token='.$tok);
  115. exit();
  116. }
  117. Display::display_header($tool_name);
  118. // Group picture
  119. $image_path = GroupPortalManager::get_group_picture_path_by_id($group_id,'web');
  120. $image_dir = $image_path['dir'];
  121. $image = $image_path['file'];
  122. $image_file = ($image != '' ? $image_dir.$image : api_get_path(WEB_CODE_PATH).'img/unknown_group.jpg');
  123. $image_size = api_getimagesize($image_file);
  124. // get the path,width and height from original picture
  125. $big_image = $image_dir.'big_'.$image;
  126. $big_image_size = api_getimagesize($big_image);
  127. $big_image_width = $big_image_size['width'];
  128. $big_image_height = $big_image_size['height'];
  129. $url_big_image = $big_image.'?rnd='.time();
  130. //Shows left column
  131. //echo GroupPortalManager::show_group_column_information($group_id, api_get_user_id());
  132. echo '<div id="social-content">';
  133. echo '<div id="social-content-left">';
  134. //this include the social menu div
  135. SocialManager::show_social_menu('group_edit',$group_id);
  136. echo '</div>';
  137. echo '<div id="social-content-right">';
  138. echo '<table><tr><td>';
  139. // Display form
  140. $form->display();
  141. echo '</td></tr></table>';
  142. echo '</div>';
  143. echo '</div>';
  144. // Footer
  145. Display::display_footer();