group_edit.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $cidReset = true;
  7. require_once '../inc/global.inc.php';
  8. $this_section = SECTION_PLATFORM_ADMIN;
  9. api_protect_admin_script();
  10. $libpath = api_get_path(LIBRARY_PATH);
  11. $group_id = isset($_GET['id']) ? intval($_GET['id']) : intval($_POST['id']);
  12. $tool_name = get_lang('GroupEdit');
  13. $interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  14. $interbreadcrumb[] = array('url' => 'group_list.php','name' => get_lang('GroupList'));
  15. $table_group = Database::get_main_table(TABLE_MAIN_GROUP);
  16. $htmlHeadXtra[] = '<script type="text/javascript">
  17. textarea = "";
  18. num_characters_permited = 255;
  19. function text_longitud(){
  20. num_characters = document.forms[0].description.value.length;
  21. if (num_characters > num_characters_permited){
  22. document.forms[0].description.value = textarea;
  23. }else{
  24. textarea = document.forms[0].description.value;
  25. }
  26. }
  27. </script>';
  28. $sql = "SELECT * FROM $table_group WHERE id = '".$group_id."'";
  29. $res = Database::query($sql);
  30. if (Database::num_rows($res) != 1) {
  31. header('Location: group_list.php');
  32. exit;
  33. }
  34. $group_data = Database::fetch_array($res, 'ASSOC');
  35. // Create the form
  36. $form = new FormValidator('group_edit', 'post', '', '', array('style' => 'width: 60%; float: '.($text_dir == 'rtl' ? 'right;' : 'left;')));
  37. $form->addElement('header', '', $tool_name);
  38. $form->addElement('hidden', 'id', $group_id);
  39. // name
  40. $form->addElement('text', 'name', get_lang('Name'), array('size'=>60, 'maxlength'=>120));
  41. $form->applyFilter('name', 'html_filter');
  42. $form->applyFilter('name', 'trim');
  43. $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
  44. // Description
  45. $form->addElement(
  46. 'textarea',
  47. 'description',
  48. get_lang('Description'),
  49. array(
  50. 'rows' => 3,
  51. 'cols' => 58,
  52. 'onKeyDown' => "text_longitud()",
  53. 'onKeyUp' => "text_longitud()",
  54. )
  55. );
  56. $form->applyFilter('description', 'html_filter');
  57. $form->applyFilter('description', 'trim');
  58. // url
  59. $form->addElement('text', 'url', get_lang('URL'), array('size' => 35));
  60. $form->applyFilter('url', 'html_filter');
  61. $form->applyFilter('url', 'trim');
  62. // Picture
  63. $form->addElement('file', 'picture', get_lang('AddPicture'));
  64. $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
  65. $form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
  66. if (strlen($group_data['picture_uri']) > 0) {
  67. $form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage'));
  68. }
  69. // Group parent
  70. $groups = array();
  71. $groups = GroupPortalManager::get_groups_list($group_id);
  72. $groups[0] = get_lang('NoParentship');
  73. $group_data['parent_group'] = GroupPortalManager::get_parent_group($group_id);
  74. $form->addElement('select', 'parent_group', get_lang('GroupParentship'), $groups, array());
  75. // Status
  76. $status = array();
  77. $status[GROUP_PERMISSION_OPEN] = get_lang('Open');
  78. $status[GROUP_PERMISSION_CLOSED] = get_lang('Closed');
  79. $form->addElement('select', 'visibility', get_lang('GroupPermissions'), $status, array());
  80. // Submit button
  81. $form->addButtonUpdate(get_lang('ModifyInformation'));
  82. // Set default values
  83. $form->setDefaults($group_data);
  84. // Validate form
  85. if ( $form->validate()) {
  86. $group = $form->exportValues();
  87. $picture_element = $form->getElement('picture');
  88. $picture = $picture_element->getValue();
  89. $picture_uri = $group_data['picture_uri'];
  90. if ($group['delete_picture']) {
  91. $picture_uri = GroupPortalManager::delete_group_picture($group_id);
  92. }
  93. elseif (!empty($picture['name'])) {
  94. $picture_uri = GroupPortalManager::update_group_picture(
  95. $group_id,
  96. $_FILES['picture']['name'],
  97. $_FILES['picture']['tmp_name']
  98. );
  99. }
  100. $name = $group['name'];
  101. $description = $group['description'];
  102. $url = $group['url'];
  103. $status = intval($group['visibility']);
  104. $parent_group_id = intval($group['parent_group']);
  105. GroupPortalManager::update(
  106. $group_id,
  107. $name,
  108. $description,
  109. $url,
  110. $status,
  111. $picture_uri
  112. );
  113. GroupPortalManager::set_parent_group($group_id, $parent_group_id);
  114. $tok = Security::get_token();
  115. header('Location: group_list.php?action=show_message&message='.urlencode(get_lang('GroupUpdated')).'&sec_token='.$tok);
  116. exit();
  117. }
  118. Display::display_header($tool_name);
  119. // Group picture
  120. $image_path = GroupPortalManager::get_group_picture_path_by_id($group_id, 'web');
  121. $image_dir = $image_path['dir'];
  122. $image = $image_path['file'];
  123. $image_file = ($image != '' ? $image_dir.$image : api_get_path(WEB_CODE_PATH).'img/unknown_group.jpg');
  124. $image_size = api_getimagesize($image_file);
  125. $img_attributes = 'src="'.$image_file.'?rand='.time().'" '
  126. .'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; padding:5px;" ';
  127. if ($image_size['width'] > 300) {
  128. // limit display width to 300px
  129. $img_attributes .= 'width="300" ';
  130. }
  131. // get the path,width and height from original picture
  132. $big_image = $image_dir.'big_'.$image;
  133. $big_image_size = api_getimagesize($big_image);
  134. $big_image_width = $big_image_size['width'];
  135. $big_image_height = $big_image_size['height'];
  136. $url_big_image = $big_image.'?rnd='.time();
  137. if ($image == '') {
  138. echo '<img '.$img_attributes.' />';
  139. } else {
  140. echo '<input type="image" '.$img_attributes.' onclick="javascript: return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/>';
  141. }
  142. // Display form
  143. $form->display();
  144. // Footer
  145. Display::display_footer();