group_edit.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php // $Id: user_edit.php 22233 2009-07-20 09:54:05Z ivantcholakov $
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. ==============================================================================
  5. * @package dokeos.admin
  6. ==============================================================================
  7. */
  8. // Language files that should be included
  9. $language_file = array('admin');
  10. $cidReset = true;
  11. include '../inc/global.inc.php';
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. api_protect_admin_script();
  14. $libpath = api_get_path(LIBRARY_PATH);
  15. require_once $libpath.'fileManage.lib.php';
  16. require_once $libpath.'fileUpload.lib.php';
  17. require_once $libpath.'group_portal_manager.lib.php';
  18. require_once $libpath.'formvalidator/FormValidator.class.php';
  19. require_once $libpath.'image.lib.php';
  20. require_once $libpath.'mail.lib.inc.php';
  21. $group_id = isset($_GET['id']) ? intval($_GET['id']) : intval($_POST['id']);
  22. $tool_name = get_lang('GroupEdit');
  23. $interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  24. $interbreadcrumb[] = array('url' => 'group_list.php','name' => get_lang('GroupList'));
  25. $table_group = Database::get_main_table(TABLE_MAIN_GROUP);
  26. $sql = "SELECT * FROM $table_group WHERE id = '".$group_id."'";
  27. $res = Database::query($sql, __FILE__, __LINE__);
  28. if (Database::num_rows($res) != 1) {
  29. header('Location: group_list.php');
  30. exit;
  31. }
  32. $group_data = Database::fetch_array($res, 'ASSOC');
  33. // Create the form
  34. $form = new FormValidator('group_edit', 'post', '', '', array('style' => 'width: 60%; float: '.($text_dir == 'rtl' ? 'right;' : 'left;')));
  35. $form->addElement('header', '', $tool_name);
  36. $form->addElement('hidden', 'id', $group_id);
  37. // name
  38. $form->addElement('text', 'name', get_lang('Name'));
  39. $form->applyFilter('name', 'html_filter');
  40. $form->applyFilter('name', 'trim');
  41. $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
  42. // Description
  43. $form->addElement('text', 'description', get_lang('Description'));
  44. $form->applyFilter('description', 'html_filter');
  45. $form->applyFilter('description', 'trim');
  46. // url
  47. $form->addElement('text', 'url', get_lang('URL'));
  48. $form->applyFilter('url', 'html_filter');
  49. $form->applyFilter('url', 'trim');
  50. // Picture
  51. $form->addElement('file', 'picture', get_lang('AddPicture'));
  52. $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
  53. $form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
  54. if (strlen($group_data['picture_uri']) > 0) {
  55. $form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage'));
  56. }
  57. // Status
  58. $status = array();
  59. $status[GROUP_PERMISSION_OPEN] = get_lang('Open');
  60. $status[GROUP_PERMISSION_CLOSED] = get_lang('Closed');
  61. $form->addElement('select', 'visibility', get_lang('GroupPermissions'), $status, array());
  62. // Submit button
  63. $form->addElement('style_submit_button', 'submit', get_lang('ModifyInformation'), 'class="save"');
  64. // Set default values
  65. $form->setDefaults($group_data);
  66. // Validate form
  67. if ( $form->validate()) {
  68. $group = $form->exportValues();
  69. $picture_element = & $form->getElement('picture');
  70. $picture = $picture_element->getValue();
  71. $picture_uri = $group_data['picture_uri'];
  72. if ($group['delete_picture']) {
  73. $picture_uri = GroupPortalManager::delete_group_picture($group_id);
  74. }
  75. elseif (!empty($picture['name'])) {
  76. $picture_uri = GroupPortalManager::update_group_picture($group_id, $_FILES['picture']['name'], $_FILES['picture']['tmp_name']);
  77. }
  78. $name = $group['name'];
  79. $description = $group['description'];
  80. $url = $group['url'];
  81. $status = intval($group['visibility']);
  82. GroupPortalManager::update($group_id, $name, $description, $url, $status, $picture_uri);
  83. $tok = Security::get_token();
  84. header('Location: group_list.php?action=show_message&message='.urlencode(get_lang('GroupUpdated')).'&sec_token='.$tok);
  85. exit();
  86. }
  87. Display::display_header($tool_name);
  88. // Group picture
  89. $image_path = GroupPortalManager::get_group_picture_path_by_id($group_id,'web');
  90. $image_dir = $image_path['dir'];
  91. $image = $image_path['file'];
  92. $image_file = ($image != '' ? $image_dir.$image : api_get_path(WEB_CODE_PATH).'img/unknown_group.jpg');
  93. $image_size = api_getimagesize($image_file);
  94. $img_attributes = 'src="'.$image_file.'?rand='.time().'" '
  95. .'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" '
  96. .'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; padding:5px;" ';
  97. if ($image_size[0] > 300) { //limit display width to 300px
  98. $img_attributes .= 'width="300" ';
  99. }
  100. // get the path,width and height from original picture
  101. $big_image = $image_dir.'big_'.$image;
  102. $big_image_size = api_getimagesize($big_image);
  103. $big_image_width = $big_image_size[0];
  104. $big_image_height = $big_image_size[1];
  105. $url_big_image = $big_image.'?rnd='.time();
  106. if ($image == '') {
  107. echo '<img '.$img_attributes.' />';
  108. } else {
  109. echo '<input type="image" '.$img_attributes.' onclick="javascript: return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/>';
  110. }
  111. // Display form
  112. $form->display();
  113. // Footer
  114. Display::display_footer();