group_edit.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. // Language files that should be included
  7. $language_file = array('admin', 'userInfo');
  8. $cidReset = true;
  9. ////require_once '../inc/global.inc.php';
  10. $this_section = SECTION_PLATFORM_ADMIN;
  11. api_protect_admin_script();
  12. $group_id = isset($_GET['id']) ? intval($_GET['id']) : intval($_POST['id']);
  13. $tool_name = get_lang('GroupEdit');
  14. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  15. $interbreadcrumb[] = array('url' => 'group_list.php', 'name' => get_lang('GroupList'));
  16. $table_group = Database::get_main_table(TABLE_MAIN_GROUP);
  17. $htmlHeadXtra[] = '<script>
  18. textarea = "";
  19. num_characters_permited = 255;
  20. function text_longitud(){
  21. num_characters = document.forms[0].description.value.length;
  22. if (num_characters > num_characters_permited){
  23. document.forms[0].description.value = textarea;
  24. }else{
  25. textarea = document.forms[0].description.value;
  26. }
  27. }
  28. </script>';
  29. $sql = "SELECT * FROM $table_group WHERE id = '".$group_id."'";
  30. $res = Database::query($sql);
  31. if (Database::num_rows($res) != 1) {
  32. header('Location: group_list.php');
  33. exit;
  34. }
  35. $group_data = Database::fetch_array($res, 'ASSOC');
  36. // Create the form
  37. $form = new FormValidator('group_edit', 'post', '', '', array('style' => 'width: 60%; float: '.($text_dir == 'rtl' ? 'right;' : 'left;')));
  38. $form->addElement('header', '', $tool_name);
  39. $form->addElement('hidden', 'id', $group_id);
  40. // name
  41. $form->addElement('text', 'name', get_lang('Name'), array('size' => 60, 'maxlength' => 120));
  42. $form->applyFilter('name', 'html_filter');
  43. $form->applyFilter('name', 'trim');
  44. $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
  45. // Description
  46. $form->addElement(
  47. 'textarea',
  48. 'description',
  49. get_lang('Description'),
  50. array('rows' => 3, 'cols' => 58, 'onKeyDown' => "text_longitud()", 'onKeyUp' => "text_longitud()")
  51. );
  52. $form->applyFilter('description', 'html_filter');
  53. $form->applyFilter('description', 'trim');
  54. // url
  55. $form->addElement('text', 'url', get_lang('URL'), array('size' => 35));
  56. $form->applyFilter('url', 'html_filter');
  57. $form->applyFilter('url', 'trim');
  58. // Picture
  59. $form->addElement('file', 'picture', get_lang('AddPicture'));
  60. $allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif');
  61. $form->addRule(
  62. 'picture',
  63. get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')',
  64. 'filetype',
  65. $allowed_picture_types
  66. );
  67. if (strlen($group_data['picture_uri']) > 0) {
  68. $form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage'));
  69. }
  70. //Group Parentship
  71. $groups = array();
  72. $groups = GroupPortalManager::get_groups_list($group_id);
  73. $groups[0] = get_lang('NoParentship');
  74. $group_data['parent_group'] = GroupPortalManager::get_parent_group($group_id);
  75. $form->addElement('select', 'parent_group', get_lang('GroupParentship'), $groups, array());
  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. } 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($group_id, $name, $description, $url, $status, $picture_uri);
  106. GroupPortalManager::set_parent_group($group_id, $parent_group_id);
  107. $tok = Security::get_token();
  108. header(
  109. 'Location: group_list.php?action=show_message&message='.urlencode(get_lang('GroupUpdated')).'&sec_token='.$tok
  110. );
  111. exit();
  112. }
  113. Display::display_header($tool_name);
  114. // Group picture
  115. $image_path = GroupPortalManager::get_group_picture_path_by_id($group_id, 'web');
  116. $image_dir = $image_path['dir'];
  117. $image = $image_path['file'];
  118. $image_file = ($image != '' ? $image_dir.$image : api_get_path(WEB_IMG_PATH).'unknown_group.jpg');
  119. $image_size = api_getimagesize($image_file);
  120. $img_attributes = 'src="'.$image_file.'?rand='.time().'" '
  121. .'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" '
  122. .'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; padding:5px;" ';
  123. if ($image_size['width'] > 300) { //limit display width to 300px
  124. $img_attributes .= 'width="300" ';
  125. }
  126. // get the path,width and height from original picture
  127. $big_image = $image_dir.'big_'.$image;
  128. $big_image_size = api_getimagesize($big_image);
  129. $big_image_width = $big_image_size['width'];
  130. $big_image_height = $big_image_size['height'];
  131. $url_big_image = $big_image.'?rnd='.time();
  132. if ($image == '') {
  133. echo '<img '.$img_attributes.' />';
  134. } else {
  135. echo '<input type="image" '.$img_attributes.' onclick="javascript: return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/>';
  136. }
  137. // Display form
  138. $form->display();
  139. // Footer
  140. Display::display_footer();