diff --git a/main/inc/lib/group_portal_manager.lib.php b/main/inc/lib/group_portal_manager.lib.php index 1ef04b3f2d..fe6ad3efff 100755 --- a/main/inc/lib/group_portal_manager.lib.php +++ b/main/inc/lib/group_portal_manager.lib.php @@ -667,10 +667,10 @@ class GroupPortalManager * @param int url id * @return boolean true if success * */ - function delete_url_rel_session($session_id, $url_id) + function delete_user_rel_group($user_id, $group_id) { - $table_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); - $sql= "DELETE FROM $table_url_rel_session WHERE session_id = ".Database::escape_string($session_id)." AND access_url_id=".Database::escape_string($url_id)." "; + $table = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP); + $sql= "DELETE FROM $table WHERE user_id = ".intval($user_id)." AND group_id=".intval($group_id)." "; $result = Database::query($sql, __FILE__, __LINE__); return $result; } diff --git a/main/social/group_edit.php b/main/social/group_edit.php new file mode 100644 index 0000000000..251b6818b8 --- /dev/null +++ b/main/social/group_edit.php @@ -0,0 +1,151 @@ + 'index.php','name' => get_lang('PlatformAdmin')); +$interbreadcrumb[] = array('url' => 'group_list.php','name' => get_lang('GroupList')); + +$table_group = Database::get_main_table(TABLE_MAIN_GROUP); + +$sql = "SELECT * FROM $table_group WHERE id = '".$group_id."'"; +$res = Database::query($sql, __FILE__, __LINE__); +if (Database::num_rows($res) != 1) { + header('Location: groups.php?id='.$group_id); + exit; +} + +$group_data = Database::fetch_array($res, 'ASSOC'); + +// Create the form +$form = new FormValidator('group_edit', 'post', '', '', array('style' => 'width: 60%; float: '.($text_dir == 'rtl' ? 'right;' : 'left;'))); +$form->addElement('header', '', $tool_name); +$form->addElement('hidden', 'id', $group_id); + +// name +$form->addElement('text', 'name', get_lang('Name')); +$form->applyFilter('name', 'html_filter'); +$form->applyFilter('name', 'trim'); +$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required'); + +// Description +$form->addElement('text', 'description', get_lang('Description')); +$form->applyFilter('description', 'html_filter'); +$form->applyFilter('description', 'trim'); + +// url +$form->addElement('text', 'url', get_lang('URL')); +$form->applyFilter('url', 'html_filter'); +$form->applyFilter('url', 'trim'); + +// Picture +$form->addElement('file', 'picture', get_lang('AddPicture')); +$allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif'); +$form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types); +if (strlen($group_data['picture_uri']) > 0) { + $form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage')); +} + + +// Status +$status = array(); +$status[GROUP_PERMISSION_OPEN] = get_lang('Open'); +$status[GROUP_PERMISSION_CLOSED] = get_lang('Closed'); + +$form->addElement('select', 'visibility', get_lang('GroupPermissions'), $status, array()); + +// Submit button +$form->addElement('style_submit_button', 'submit', get_lang('ModifyInformation'), 'class="save"'); + +// Set default values +$form->setDefaults($group_data); + +// Validate form +if ( $form->validate()) { + $group = $form->exportValues(); + + $picture_element = & $form->getElement('picture'); + $picture = $picture_element->getValue(); + + $picture_uri = $group_data['picture_uri']; + if ($group['delete_picture']) { + $picture_uri = GroupPortalManager::delete_group_picture($group_id); + } + elseif (!empty($picture['name'])) { + $picture_uri = GroupPortalManager::update_group_picture($group_id, $_FILES['picture']['name'], $_FILES['picture']['tmp_name']); + } + + $name = $group['name']; + $description = $group['description']; + $url = $group['url']; + $status = intval($group['visibility']); + + GroupPortalManager::update($group_id, $name, $description, $url, $status, $picture_uri); + $tok = Security::get_token(); + header('Location: groups.php?id='.$group_id.'&action=show_message&message='.urlencode(get_lang('GroupUpdated')).'&sec_token='.$tok); + exit(); +} + +Display::display_header($tool_name); + +//show the action menu +SocialManager::show_social_menu(); +echo '
'; +echo get_lang('Groups'); +echo '
'; + + + +// Group picture +$image_path = GroupPortalManager::get_group_picture_path_by_id($group_id,'web'); +$image_dir = $image_path['dir']; +$image = $image_path['file']; +$image_file = ($image != '' ? $image_dir.$image : api_get_path(WEB_CODE_PATH).'img/unknown_group.jpg'); +$image_size = api_getimagesize($image_file); + +$img_attributes = 'src="'.$image_file.'?rand='.time().'" ' + .'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" ' + .'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; padding:5px;" '; + +if ($image_size[0] > 300) { //limit display width to 300px + $img_attributes .= 'width="300" '; +} + +// get the path,width and height from original picture +$big_image = $image_dir.'big_'.$image; +$big_image_size = api_getimagesize($big_image); +$big_image_width = $big_image_size[0]; +$big_image_height = $big_image_size[1]; +$url_big_image = $big_image.'?rnd='.time(); + +if ($image == '') { + echo ''; +} else { + echo ''; +} + +// Display form +$form->display(); + +// Footer +Display::display_footer(); diff --git a/main/social/groups.php b/main/social/groups.php index bb471bafbe..5f400be0fa 100644 --- a/main/social/groups.php +++ b/main/social/groups.php @@ -21,6 +21,17 @@ echo ''; $group_id = intval($_GET['id']); if ($group_id != 0 ) { + + if (isset($_GET['action']) && $_GET['action']=='leave') { + $user_leaved = intval($_GET['u']); + GroupPortalManager::delete_user_rel_group($user_leaved, $group_id); + } + + if (isset($_GET['action']) && $_GET['action']=='join') { + $user_join = intval($_GET['u']); + GroupPortalManager::add_user_to_group($user_join, $group_id); + } + $group_info = GroupPortalManager::get_group_data($group_id); $picture = GroupPortalManager::get_picture_group($group_id, $group_info['picture_uri'],160,'medium_'); $tags = GroupPortalManager::get_group_tags($group_id,true); @@ -73,8 +84,6 @@ if ($group_id != 0 ) { echo '
'; - - if (is_array($users[api_get_user_id()]) && count($users[api_get_user_id()]) > 0) { //im a member @@ -82,23 +91,23 @@ if ($group_id != 0 ) { if ($users[api_get_user_id()]['relation_type']!='') { $my_group_role = $users[api_get_user_id()]['relation_type']; - // just a reader + // I'm just a reader if ($my_group_role == GROUP_USER_PERMISSION_READER) { - echo 'Leave group/'; + echo ''.get_lang('LeaveGroup').''; echo 'Invite others/'; //the main admin } elseif ($my_group_role == GROUP_USER_PERMISSION_ADMIN) { echo 'Im the admin/'; - echo 'Edit group/'; + echo ''.get_lang('EditGroup').''; echo 'Invite others'; } } else { //im not a member - echo 'Join group'; + echo ''.get_lang('JoinGroup').''; } } else { //im not a member - echo 'Join group'; + echo ''.get_lang('JoinGroup').''; } echo '
';