group_edit.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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.'mail.lib.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. $group_id = isset($_GET['id']) ? intval($_GET['id']) : intval($_POST['id']);
  37. $tool_name = get_lang('GroupEdit');
  38. $interbreadcrumb[] = array('url' => 'home.php','name' => get_lang('Social'));
  39. $interbreadcrumb[] = array('url' => 'groups.php','name' => get_lang('Groups'));
  40. $table_group = Database::get_main_table(TABLE_MAIN_GROUP);
  41. $sql = "SELECT * FROM $table_group WHERE id = '".$group_id."'";
  42. $res = Database::query($sql);
  43. if (Database::num_rows($res) != 1) {
  44. header('Location: groups.php?id='.$group_id);
  45. exit;
  46. }
  47. //only group admins can edit the group
  48. if (!GroupPortalManager::is_group_admin($group_id)) {
  49. api_not_allowed();
  50. }
  51. $group_data = Database::fetch_array($res, 'ASSOC');
  52. // Create the form
  53. $form = new FormValidator('group_edit', 'post', '', '', array('style' => 'width: 100%; float: '.($text_dir == 'rtl' ? 'right;' : 'left;')));
  54. $form->addElement('hidden', 'id', $group_id);
  55. // name
  56. $form->addElement('text', 'name', get_lang('Name'), array('size'=>60, 'maxlength'=>120));
  57. $form->applyFilter('name', 'html_filter');
  58. $form->applyFilter('name', 'trim');
  59. $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
  60. // Description
  61. $form->addElement('textarea', 'description', get_lang('Description'), array('rows'=>3, 'cols'=>58, onKeyDown => "textarea_maxlength()", onKeyUp => "textarea_maxlength()"));
  62. $form->applyFilter('description', 'html_filter');
  63. $form->applyFilter('description', 'trim');
  64. $form->addRule('name', '', 'maxlength',255);
  65. // url
  66. $form->addElement('text', 'url', get_lang('URL'), array('size'=>35));
  67. $form->applyFilter('url', 'html_filter');
  68. $form->applyFilter('url', 'trim');
  69. // Picture
  70. $form->addElement('file', 'picture', get_lang('AddPicture'));
  71. $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
  72. $form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
  73. if (strlen($group_data['picture_uri']) > 0) {
  74. $form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage'));
  75. }
  76. // Status
  77. $status = array();
  78. $status[GROUP_PERMISSION_OPEN] = get_lang('Open');
  79. $status[GROUP_PERMISSION_CLOSED] = get_lang('Closed');
  80. $form->addElement('select', 'visibility', get_lang('GroupPermissions'), $status, array());
  81. // Submit button
  82. $form->addElement('style_submit_button', 'submit', get_lang('ModifyInformation'), 'class="save"');
  83. // Set default values
  84. $form->setDefaults($group_data);
  85. // Validate form
  86. if ( $form->validate()) {
  87. $group = $form->exportValues();
  88. $picture_element = & $form->getElement('picture');
  89. $picture = $picture_element->getValue();
  90. $picture_uri = $group_data['picture_uri'];
  91. if ($group['delete_picture']) {
  92. $picture_uri = GroupPortalManager::delete_group_picture($group_id);
  93. }
  94. elseif (!empty($picture['name'])) {
  95. $picture_uri = GroupPortalManager::update_group_picture($group_id, $_FILES['picture']['name'], $_FILES['picture']['tmp_name']);
  96. }
  97. $name = $group['name'];
  98. $description = $group['description'];
  99. $url = $group['url'];
  100. $status = intval($group['visibility']);
  101. GroupPortalManager::update($group_id, $name, $description, $url, $status, $picture_uri);
  102. $tok = Security::get_token();
  103. header('Location: groups.php?id='.$group_id.'&action=show_message&message='.urlencode(get_lang('GroupUpdated')).'&sec_token='.$tok);
  104. exit();
  105. }
  106. // Group picture
  107. $image_path = GroupPortalManager::get_group_picture_path_by_id($group_id,'web');
  108. $image_dir = $image_path['dir'];
  109. $image = $image_path['file'];
  110. $image_file = ($image != '' ? $image_dir.$image : api_get_path(WEB_CODE_PATH).'img/unknown_group.jpg');
  111. $image_size = api_getimagesize($image_file);
  112. // get the path,width and height from original picture
  113. $big_image = $image_dir.'big_'.$image;
  114. $big_image_size = api_getimagesize($big_image);
  115. $big_image_width = $big_image_size['width'];
  116. $big_image_height = $big_image_size['height'];
  117. $url_big_image = $big_image.'?rnd='.time();
  118. $social_left_content = SocialManager::show_social_menu('group_edit',$group_id);
  119. $social_right_content = $form->return_form();
  120. $tpl = new Template($tool_name);
  121. $tpl->set_help('Groups');
  122. $tpl->assign('social_left_content', $social_left_content);
  123. $tpl->assign('social_left_menu', $social_left_menu);
  124. $tpl->assign('social_right_content', $social_right_content);
  125. $social_layout = $tpl->get_template('layout/social_layout.tpl');
  126. $content = $tpl->fetch($social_layout);
  127. $tpl->assign('actions', $actions);
  128. $tpl->assign('message', $show_message);
  129. $tpl->assign('content', $content);
  130. $tpl->display_one_col_template();