group_edit.php 5.6 KB

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