group_edit.php 6.4 KB

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