group_edit.php 5.3 KB

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