group_edit.php 6.2 KB

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